]> git.lizzy.rs Git - dragonfireclient.git/blob - src/mapgen/dungeongen.h
Node definition manager refactor (#7016)
[dragonfireclient.git] / src / mapgen / dungeongen.h
1 /*
2 Minetest
3 Copyright (C) 2010-2018 celeron55, Perttu Ahola <celeron55@gmail.com>
4 Copyright (C) 2015-2018 paramat
5
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.
10
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.
15
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.
19 */
20
21 #pragma once
22
23 #include "voxel.h"
24 #include "noise.h"
25 #include "mapgen.h"
26
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)
31
32 class MMVManip;
33 class NodeDefManager;
34
35 v3s16 rand_ortho_dir(PseudoRandom &random, bool diagonal_dirs);
36 v3s16 turn_xz(v3s16 olddir, int t);
37 v3s16 random_turn(PseudoRandom &random, v3s16 olddir);
38 int dir_to_facedir(v3s16 d);
39
40
41 struct DungeonParams {
42         s32 seed;
43
44         content_t c_water;
45         content_t c_river_water;
46         content_t c_wall;
47         content_t c_alt_wall;
48         content_t c_stair;
49
50         bool diagonal_dirs;
51         bool only_in_ground;
52         v3s16 holesize;
53         u16 corridor_len_min;
54         u16 corridor_len_max;
55         v3s16 room_size_min;
56         v3s16 room_size_max;
57         v3s16 room_size_large_min;
58         v3s16 room_size_large_max;
59         u16 rooms_min;
60         u16 rooms_max;
61         s16 y_min;
62         s16 y_max;
63         GenNotifyType notifytype;
64
65         NoiseParams np_density;
66         NoiseParams np_alt_wall;
67 };
68
69 class DungeonGen {
70 public:
71         MMVManip *vm;
72         const NodeDefManager *ndef;
73         GenerateNotifier *gennotify;
74
75         u32 blockseed;
76         PseudoRandom random;
77         v3s16 csize;
78
79         content_t c_torch;
80         DungeonParams dp;
81
82         // RoomWalker
83         v3s16 m_pos;
84         v3s16 m_dir;
85
86         DungeonGen(const NodeDefManager *ndef,
87                 GenerateNotifier *gennotify, DungeonParams *dparams);
88
89         void generate(MMVManip *vm, u32 bseed,
90                 v3s16 full_node_min, v3s16 full_node_max);
91
92         void makeDungeon(v3s16 start_padding);
93         void makeRoom(v3s16 roomsize, v3s16 roomplace);
94         void makeCorridor(v3s16 doorplace, v3s16 doordir,
95                 v3s16 &result_place, v3s16 &result_dir);
96         void makeDoor(v3s16 doorplace, v3s16 doordir);
97         void makeFill(v3s16 place, v3s16 size, u8 avoid_flags, MapNode n, u8 or_flags);
98         void makeHole(v3s16 place);
99
100         bool findPlaceForDoor(v3s16 &result_place, v3s16 &result_dir);
101         bool findPlaceForRoomDoor(v3s16 roomsize, v3s16 &result_doorplace,
102                         v3s16 &result_doordir, v3s16 &result_roomplace);
103
104         inline void randomizeDir()
105         {
106                 m_dir = rand_ortho_dir(random, dp.diagonal_dirs);
107         }
108 };
109
110 extern NoiseParams nparams_dungeon_density;
111 extern NoiseParams nparams_dungeon_alt_wall;