on_death: Fix callback number of pushed arguments (Fixes #6451)
[oweals/minetest.git] / src / dungeongen.h
1 /*
2 Minetest
3 Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #pragma once
21
22 #include "voxel.h"
23 #include "noise.h"
24 #include "mapgen.h"
25
26 #define VMANIP_FLAG_DUNGEON_INSIDE VOXELFLAG_CHECKED1
27 #define VMANIP_FLAG_DUNGEON_PRESERVE VOXELFLAG_CHECKED2
28 #define VMANIP_FLAG_DUNGEON_UNTOUCHABLE (\
29                 VMANIP_FLAG_DUNGEON_INSIDE|VMANIP_FLAG_DUNGEON_PRESERVE)
30
31 class MMVManip;
32 class INodeDefManager;
33
34 v3s16 rand_ortho_dir(PseudoRandom &random, bool diagonal_dirs);
35 v3s16 turn_xz(v3s16 olddir, int t);
36 v3s16 random_turn(PseudoRandom &random, v3s16 olddir);
37 int dir_to_facedir(v3s16 d);
38
39
40 struct DungeonParams {
41         s32 seed;
42
43         content_t c_water;
44         content_t c_river_water;
45         content_t c_wall;
46         content_t c_alt_wall;
47         content_t c_stair;
48
49         bool diagonal_dirs;
50         bool only_in_ground;
51         v3s16 holesize;
52         u16 corridor_len_min;
53         u16 corridor_len_max;
54         v3s16 room_size_min;
55         v3s16 room_size_max;
56         v3s16 room_size_large_min;
57         v3s16 room_size_large_max;
58         u16 rooms_min;
59         u16 rooms_max;
60         s16 y_min;
61         s16 y_max;
62         GenNotifyType notifytype;
63
64         NoiseParams np_density;
65         NoiseParams np_alt_wall;
66 };
67
68 class DungeonGen {
69 public:
70         MMVManip *vm;
71         INodeDefManager *ndef;
72         GenerateNotifier *gennotify;
73
74         u32 blockseed;
75         PseudoRandom random;
76         v3s16 csize;
77
78         content_t c_torch;
79         DungeonParams dp;
80
81         // RoomWalker
82         v3s16 m_pos;
83         v3s16 m_dir;
84
85         DungeonGen(INodeDefManager *ndef,
86                 GenerateNotifier *gennotify, DungeonParams *dparams);
87
88         void generate(MMVManip *vm, u32 bseed,
89                 v3s16 full_node_min, v3s16 full_node_max);
90
91         void makeDungeon(v3s16 start_padding);
92         void makeRoom(v3s16 roomsize, v3s16 roomplace);
93         void makeCorridor(v3s16 doorplace, v3s16 doordir,
94                 v3s16 &result_place, v3s16 &result_dir);
95         void makeDoor(v3s16 doorplace, v3s16 doordir);
96         void makeFill(v3s16 place, v3s16 size, u8 avoid_flags, MapNode n, u8 or_flags);
97         void makeHole(v3s16 place);
98
99         bool findPlaceForDoor(v3s16 &result_place, v3s16 &result_dir);
100         bool findPlaceForRoomDoor(v3s16 roomsize, v3s16 &result_doorplace,
101                         v3s16 &result_doordir, v3s16 &result_roomplace);
102
103         inline void randomizeDir()
104         {
105                 m_dir = rand_ortho_dir(random, dp.diagonal_dirs);
106         }
107 };
108
109 extern NoiseParams nparams_dungeon_density;
110 extern NoiseParams nparams_dungeon_alt_wall;