]> git.lizzy.rs Git - minetest.git/blob - src/mg_decoration.h
910f1a581fc8ee620fc1a050284c4243a5994bc8
[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         float fill_ratio;
70         NoiseParams np;
71
72         std::set<u8> biomes;
73         //std::list<CutoffData> cutoffs;
74         //JMutex cutoff_mutex;
75
76         Decoration();
77         virtual ~Decoration();
78
79         virtual void resolveNodeNames(NodeResolveInfo *nri);
80
81         size_t placeDeco(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax);
82         size_t placeCutoffs(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax);
83
84         virtual size_t generate(Mapgen *mg, PseudoRandom *pr, s16 max_y, v3s16 p) = 0;
85         virtual int getHeight() = 0;
86 };
87
88 class DecoSimple : public Decoration {
89 public:
90         std::vector<content_t> c_decos;
91         std::vector<content_t> c_spawnby;
92         s16 deco_height;
93         s16 deco_height_max;
94         s16 nspawnby;
95
96         virtual void resolveNodeNames(NodeResolveInfo *nri);
97
98         bool canPlaceDecoration(ManualMapVoxelManipulator *vm, v3s16 p);
99         virtual size_t generate(Mapgen *mg, PseudoRandom *pr, s16 max_y, v3s16 p);
100         virtual int getHeight();
101 };
102
103 class DecoSchematic : public Decoration {
104 public:
105         Rotation rotation;
106         Schematic *schematic;
107         std::string filename;
108
109         virtual size_t generate(Mapgen *mg, PseudoRandom *pr, s16 max_y, v3s16 p);
110         virtual int getHeight();
111 };
112
113
114 /*
115 class DecoLSystem : public Decoration {
116 public:
117         virtual void generate(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax);
118 };
119 */
120
121 class DecorationManager : public GenElementManager {
122 public:
123         static const char *ELEMENT_TITLE;
124         static const size_t ELEMENT_LIMIT = 0x10000;
125
126         DecorationManager(IGameDef *gamedef);
127         ~DecorationManager() {}
128
129         Decoration *create(int type)
130         {
131                 switch (type) {
132                 case DECO_SIMPLE:
133                         return new DecoSimple;
134                 case DECO_SCHEMATIC:
135                         return new DecoSchematic;
136                 //case DECO_LSYSTEM:
137                 //      return new DecoLSystem;
138                 default:
139                         return NULL;
140                 }
141         }
142
143         void clear();
144
145         size_t placeAllDecos(Mapgen *mg, u32 seed, v3s16 nmin, v3s16 nmax);
146 };
147
148 #endif