clientobject: add null checks
[waspsaliva.git] / src / mapgen / dungeongen.h
blob35e6beef5d0fba89f528eb180fa116dc4bcc98ec
1 /*
2 Minetest
3 Copyright (C) 2010-2018 celeron55, Perttu Ahola <celeron55@gmail.com>
4 Copyright (C) 2015-2018 paramat
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation; either version 2.1 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public License along
17 with this program; if not, write to the Free Software Foundation, Inc.,
18 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 #pragma once
23 #include "voxel.h"
24 #include "noise.h"
25 #include "mapgen.h"
27 #define VMANIP_FLAG_DUNGEON_INSIDE VOXELFLAG_CHECKED1
28 #define VMANIP_FLAG_DUNGEON_PRESERVE VOXELFLAG_CHECKED2
29 #define VMANIP_FLAG_DUNGEON_UNTOUCHABLE (\
30 VMANIP_FLAG_DUNGEON_INSIDE|VMANIP_FLAG_DUNGEON_PRESERVE)
32 class MMVManip;
33 class NodeDefManager;
35 v3s16 rand_ortho_dir(PseudoRandom &random, bool diagonal_dirs);
36 v3s16 turn_xz(v3s16 olddir, int t);
37 void random_turn(PseudoRandom &random, v3s16 &dir);
38 int dir_to_facedir(v3s16 d);
41 struct DungeonParams {
42 s32 seed;
44 content_t c_wall;
45 // Randomly scattered alternative wall nodes
46 content_t c_alt_wall;
47 content_t c_stair;
49 // 3D noise that determines which c_wall nodes are converted to c_alt_wall
50 NoiseParams np_alt_wall;
52 // Number of dungeons generated in mapchunk. All will use the same set of
53 // dungeonparams.
54 u16 num_dungeons;
55 // Dungeons only generate in ground
56 bool only_in_ground;
57 // Number of rooms
58 u16 num_rooms;
59 // Room size random range. Includes walls / floor / ceilng
60 v3s16 room_size_min;
61 v3s16 room_size_max;
62 // Large room size random range. Includes walls / floor / ceilng
63 v3s16 room_size_large_min;
64 v3s16 room_size_large_max;
65 // Value 0 disables large rooms.
66 // Value 1 results in 1 large room, the first generated room.
67 // Value > 1 makes the first generated room large, all other rooms have a
68 // '1 in value' chance of being large.
69 u16 large_room_chance;
70 // Dimensions of 3D 'brush' that creates corridors.
71 // Dimensions are of the empty space, not including walls / floor / ceilng.
72 // Diagonal corridors must have hole width >=2 to be passable.
73 // Currently, hole width >= 3 causes stair corridor bugs.
74 v3s16 holesize;
75 // Corridor length random range
76 u16 corridor_len_min;
77 u16 corridor_len_max;
78 // Diagonal corridors are possible, 1 in 4 corridors will be diagonal
79 bool diagonal_dirs;
80 // Usually 'GENNOTIFY_DUNGEON', but mapgen v6 uses 'GENNOTIFY_TEMPLE' for
81 // desert dungeons.
82 GenNotifyType notifytype;
85 class DungeonGen {
86 public:
87 MMVManip *vm = nullptr;
88 const NodeDefManager *ndef;
89 GenerateNotifier *gennotify;
91 u32 blockseed;
92 PseudoRandom random;
93 v3s16 csize;
95 content_t c_torch;
96 DungeonParams dp;
98 // RoomWalker
99 v3s16 m_pos;
100 v3s16 m_dir;
102 DungeonGen(const NodeDefManager *ndef,
103 GenerateNotifier *gennotify, DungeonParams *dparams);
105 void generate(MMVManip *vm, u32 bseed, v3s16 full_node_min, v3s16 full_node_max);
107 void makeDungeon(v3s16 start_padding);
108 void makeRoom(v3s16 roomsize, v3s16 roomplace);
109 void makeCorridor(v3s16 doorplace, v3s16 doordir,
110 v3s16 &result_place, v3s16 &result_dir);
111 void makeDoor(v3s16 doorplace, v3s16 doordir);
112 void makeFill(v3s16 place, v3s16 size, u8 avoid_flags, MapNode n, u8 or_flags);
113 void makeHole(v3s16 place);
115 bool findPlaceForDoor(v3s16 &result_place, v3s16 &result_dir);
116 bool findPlaceForRoomDoor(v3s16 roomsize, v3s16 &result_doorplace,
117 v3s16 &result_doordir, v3s16 &result_roomplace);
119 inline void randomizeDir()
121 m_dir = rand_ortho_dir(random, dp.diagonal_dirs);
125 extern NoiseParams nparams_dungeon_density;
126 extern NoiseParams nparams_dungeon_alt_wall;