]> git.lizzy.rs Git - dragonfireclient.git/blob - src/mg_decoration.h
fd7739b926e7d439e571606bb0181b1c1147f287
[dragonfireclient.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 MMVManip;
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 #define DECO_FORCE_PLACEMENT 0x10
43
44 extern FlagDesc flagdesc_deco[];
45
46
47 #if 0
48 struct CutoffData {
49         VoxelArea a;
50         Decoration *deco;
51         //v3s16 p;
52         //v3s16 size;
53         //s16 height;
54
55         CutoffData(s16 x, s16 y, s16 z, s16 h) {
56                 p = v3s16(x, y, z);
57                 height = h;
58         }
59 };
60 #endif
61
62 class Decoration : public GenElement, public NodeResolver {
63 public:
64         INodeDefManager *ndef;
65
66         u32 flags;
67         int mapseed;
68         std::vector<content_t> c_place_on;
69         s16 sidelen;
70         s16 y_min;
71         s16 y_max;
72         float fill_ratio;
73         NoiseParams np;
74
75         std::set<u8> biomes;
76         //std::list<CutoffData> cutoffs;
77         //JMutex cutoff_mutex;
78
79         Decoration();
80         virtual ~Decoration();
81
82         virtual void resolveNodeNames(NodeResolveInfo *nri);
83
84         size_t placeDeco(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax);
85         //size_t placeCutoffs(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax);
86
87         virtual size_t generate(MMVManip *vm, PseudoRandom *pr, s16 max_y, v3s16 p) = 0;
88         virtual int getHeight() = 0;
89 };
90
91 class DecoSimple : public Decoration {
92 public:
93         std::vector<content_t> c_decos;
94         std::vector<content_t> c_spawnby;
95         s16 deco_height;
96         s16 deco_height_max;
97         s16 nspawnby;
98
99         virtual void resolveNodeNames(NodeResolveInfo *nri);
100
101         bool canPlaceDecoration(MMVManip *vm, v3s16 p);
102         virtual size_t generate(MMVManip *vm, PseudoRandom *pr, s16 max_y, v3s16 p);
103         virtual int getHeight();
104 };
105
106 class DecoSchematic : public Decoration {
107 public:
108         Rotation rotation;
109         Schematic *schematic;
110         std::string filename;
111
112         virtual size_t generate(MMVManip *vm, PseudoRandom *pr, s16 max_y, v3s16 p);
113         virtual int getHeight();
114 };
115
116
117 /*
118 class DecoLSystem : public Decoration {
119 public:
120         virtual void generate(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax);
121 };
122 */
123
124 class DecorationManager : public GenElementManager {
125 public:
126         static const char *ELEMENT_TITLE;
127         static const size_t ELEMENT_LIMIT = 0x10000;
128
129         DecorationManager(IGameDef *gamedef);
130         ~DecorationManager() {}
131
132         Decoration *create(int type)
133         {
134                 switch (type) {
135                 case DECO_SIMPLE:
136                         return new DecoSimple;
137                 case DECO_SCHEMATIC:
138                         return new DecoSchematic;
139                 //case DECO_LSYSTEM:
140                 //      return new DecoLSystem;
141                 default:
142                         return NULL;
143                 }
144         }
145
146         void clear();
147
148         size_t placeAllDecos(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax);
149 };
150
151 #endif