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