ba3e9d3b258d8abf2cc880c5f5119cf5be8a0c16
[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 "objdef.h"
25 #include "noise.h"
26 #include "nodedef.h"
27
28 class Mapgen;
29 class MMVManip;
30 class PcgRandom;
31 class Schematic;
32
33 enum DecorationType {
34         DECO_SIMPLE,
35         DECO_SCHEMATIC,
36         DECO_LSYSTEM
37 };
38
39 #define DECO_PLACE_CENTER_X  0x01
40 #define DECO_PLACE_CENTER_Y  0x02
41 #define DECO_PLACE_CENTER_Z  0x04
42 #define DECO_USE_NOISE       0x08
43 #define DECO_FORCE_PLACEMENT 0x10
44 #define DECO_LIQUID_SURFACE  0x20
45
46 extern FlagDesc flagdesc_deco[];
47
48
49 #if 0
50 struct CutoffData {
51         VoxelArea a;
52         Decoration *deco;
53         //v3s16 p;
54         //v3s16 size;
55         //s16 height;
56
57         CutoffData(s16 x, s16 y, s16 z, s16 h) {
58                 p = v3s16(x, y, z);
59                 height = h;
60         }
61 };
62 #endif
63
64 class Decoration : public ObjDef, public NodeResolver {
65 public:
66         Decoration();
67         virtual ~Decoration();
68
69         virtual void resolveNodeNames();
70
71         size_t placeDeco(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax);
72         //size_t placeCutoffs(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax);
73
74         virtual size_t generate(MMVManip *vm, PcgRandom *pr, v3s16 p) = 0;
75         virtual int getHeight() = 0;
76
77         u32 flags;
78         int mapseed;
79         std::vector<content_t> c_place_on;
80         s16 sidelen;
81         s16 y_min;
82         s16 y_max;
83         float fill_ratio;
84         NoiseParams np;
85
86         std::set<u8> biomes;
87         //std::list<CutoffData> cutoffs;
88         //Mutex cutoff_mutex;
89 };
90
91 class DecoSimple : public Decoration {
92 public:
93         virtual size_t generate(MMVManip *vm, PcgRandom *pr, v3s16 p);
94         bool canPlaceDecoration(MMVManip *vm, v3s16 p);
95         virtual int getHeight();
96
97         virtual void resolveNodeNames();
98
99         std::vector<content_t> c_decos;
100         std::vector<content_t> c_spawnby;
101         s16 deco_height;
102         s16 deco_height_max;
103         s16 nspawnby;
104 };
105
106 class DecoSchematic : public Decoration {
107 public:
108         DecoSchematic();
109
110         virtual size_t generate(MMVManip *vm, PcgRandom *pr, v3s16 p);
111         virtual int getHeight();
112
113         Rotation rotation;
114         Schematic *schematic;
115 };
116
117
118 /*
119 class DecoLSystem : public Decoration {
120 public:
121         virtual void generate(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax);
122 };
123 */
124
125 class DecorationManager : public ObjDefManager {
126 public:
127         DecorationManager(IGameDef *gamedef);
128         virtual ~DecorationManager() {}
129
130         const char *getObjectTitle() const
131         {
132                 return "decoration";
133         }
134
135         static Decoration *create(DecorationType type)
136         {
137                 switch (type) {
138                 case DECO_SIMPLE:
139                         return new DecoSimple;
140                 case DECO_SCHEMATIC:
141                         return new DecoSchematic;
142                 //case DECO_LSYSTEM:
143                 //      return new DecoLSystem;
144                 default:
145                         return NULL;
146                 }
147         }
148
149         size_t placeAllDecos(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax);
150 };
151
152 #endif