Replace instances of height_min/height_max with y_min/y_max to remove ambiguity
[oweals/minetest.git] / src / mg_decoration.h
1 /*
2 Minetest
3 Copyright (C) 2010-2013 kwolekr, Ryan Kwolek <kwolekr@minetest.net>
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 #ifndef MG_DECORATION_HEADER
21 #define MG_DECORATION_HEADER
22
23 #include <set>
24 #include "mapgen.h"
25
26 struct NoiseParams;
27 class Mapgen;
28 class ManualMapVoxelManipulator;
29 class PseudoRandom;
30 class Schematic;
31
32 enum DecorationType {
33         DECO_SIMPLE,
34         DECO_SCHEMATIC,
35         DECO_LSYSTEM
36 };
37
38 #define DECO_PLACE_CENTER_X 0x01
39 #define DECO_PLACE_CENTER_Y 0x02
40 #define DECO_PLACE_CENTER_Z 0x04
41 #define DECO_USE_NOISE      0x08
42
43 extern FlagDesc flagdesc_deco[];
44
45
46 #if 0
47 struct CutoffData {
48         VoxelArea a;
49         Decoration *deco;
50         //v3s16 p;
51         //v3s16 size;
52         //s16 height;
53
54         CutoffData(s16 x, s16 y, s16 z, s16 h) {
55                 p = v3s16(x, y, z);
56                 height = h;
57         }
58 };
59 #endif
60
61 class Decoration : public GenElement, public NodeResolver {
62 public:
63         INodeDefManager *ndef;
64
65         u32 flags;
66         int mapseed;
67         std::vector<content_t> c_place_on;
68         s16 sidelen;
69         s16 y_min;
70         s16 y_max;
71         float fill_ratio;
72         NoiseParams np;
73
74         std::set<u8> biomes;
75         //std::list<CutoffData> cutoffs;
76         //JMutex cutoff_mutex;
77
78         Decoration();
79         virtual ~Decoration();
80
81         virtual void resolveNodeNames(NodeResolveInfo *nri);
82
83         size_t placeDeco(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax);
84         size_t placeCutoffs(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax);
85
86         virtual size_t generate(Mapgen *mg, PseudoRandom *pr, s16 max_y, v3s16 p) = 0;
87         virtual int getHeight() = 0;
88 };
89
90 class DecoSimple : public Decoration {
91 public:
92         std::vector<content_t> c_decos;
93         std::vector<content_t> c_spawnby;
94         s16 deco_height;
95         s16 deco_height_max;
96         s16 nspawnby;
97
98         virtual void resolveNodeNames(NodeResolveInfo *nri);
99
100         bool canPlaceDecoration(ManualMapVoxelManipulator *vm, v3s16 p);
101         virtual size_t generate(Mapgen *mg, PseudoRandom *pr, s16 max_y, v3s16 p);
102         virtual int getHeight();
103 };
104
105 class DecoSchematic : public Decoration {
106 public:
107         Rotation rotation;
108         Schematic *schematic;
109         std::string filename;
110
111         virtual size_t generate(Mapgen *mg, PseudoRandom *pr, s16 max_y, v3s16 p);
112         virtual int getHeight();
113 };
114
115
116 /*
117 class DecoLSystem : public Decoration {
118 public:
119         virtual void generate(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax);
120 };
121 */
122
123 class DecorationManager : public GenElementManager {
124 public:
125         static const char *ELEMENT_TITLE;
126         static const size_t ELEMENT_LIMIT = 0x10000;
127
128         DecorationManager(IGameDef *gamedef);
129         ~DecorationManager() {}
130
131         Decoration *create(int type)
132         {
133                 switch (type) {
134                 case DECO_SIMPLE:
135                         return new DecoSimple;
136                 case DECO_SCHEMATIC:
137                         return new DecoSchematic;
138                 //case DECO_LSYSTEM:
139                 //      return new DecoLSystem;
140                 default:
141                         return NULL;
142                 }
143         }
144
145         void clear();
146
147         size_t placeAllDecos(Mapgen *mg, u32 seed, v3s16 nmin, v3s16 nmax);
148 };
149
150 #endif