clientobject: add null checks
[waspsaliva.git] / src / mapgen / mg_decoration.h
blob1ea02a527d0fe701c48c451abcb3690e1728bfaa
1 /*
2 Minetest
3 Copyright (C) 2014-2018 kwolekr, Ryan Kwolek <kwolekr@minetest.net>
4 Copyright (C) 2015-2018 paramat
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation; either version 2.1 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public License along
17 with this program; if not, write to the Free Software Foundation, Inc.,
18 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 #pragma once
23 #include <unordered_set>
24 #include "objdef.h"
25 #include "noise.h"
26 #include "nodedef.h"
28 typedef u16 biome_t; // copy from mg_biome.h to avoid an unnecessary include
30 class Mapgen;
31 class MMVManip;
32 class PcgRandom;
33 class Schematic;
35 enum DecorationType {
36 DECO_SIMPLE,
37 DECO_SCHEMATIC,
38 DECO_LSYSTEM
41 #define DECO_PLACE_CENTER_X 0x01
42 #define DECO_PLACE_CENTER_Y 0x02
43 #define DECO_PLACE_CENTER_Z 0x04
44 #define DECO_USE_NOISE 0x08
45 #define DECO_FORCE_PLACEMENT 0x10
46 #define DECO_LIQUID_SURFACE 0x20
47 #define DECO_ALL_FLOORS 0x40
48 #define DECO_ALL_CEILINGS 0x80
50 extern FlagDesc flagdesc_deco[];
53 class Decoration : public ObjDef, public NodeResolver {
54 public:
55 Decoration() = default;
56 virtual ~Decoration() = default;
58 virtual void resolveNodeNames();
60 bool canPlaceDecoration(MMVManip *vm, v3s16 p);
61 size_t placeDeco(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax);
63 virtual size_t generate(MMVManip *vm, PcgRandom *pr, v3s16 p, bool ceiling) = 0;
65 u32 flags = 0;
66 int mapseed = 0;
67 std::vector<content_t> c_place_on;
68 s16 sidelen = 1;
69 s16 y_min;
70 s16 y_max;
71 float fill_ratio = 0.0f;
72 NoiseParams np;
73 std::vector<content_t> c_spawnby;
74 s16 nspawnby;
75 s16 place_offset_y = 0;
77 std::unordered_set<biome_t> biomes;
79 protected:
80 void cloneTo(Decoration *def) const;
84 class DecoSimple : public Decoration {
85 public:
86 ObjDef *clone() const;
88 virtual void resolveNodeNames();
89 virtual size_t generate(MMVManip *vm, PcgRandom *pr, v3s16 p, bool ceiling);
91 std::vector<content_t> c_decos;
92 s16 deco_height;
93 s16 deco_height_max;
94 u8 deco_param2;
95 u8 deco_param2_max;
99 class DecoSchematic : public Decoration {
100 public:
101 ObjDef *clone() const;
103 DecoSchematic() = default;
104 virtual ~DecoSchematic();
106 virtual size_t generate(MMVManip *vm, PcgRandom *pr, v3s16 p, bool ceiling);
108 Rotation rotation;
109 Schematic *schematic = nullptr;
110 bool was_cloned = false; // see FIXME inside DecoSchemtic::clone()
115 class DecoLSystem : public Decoration {
116 public:
117 virtual void generate(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax);
122 class DecorationManager : public ObjDefManager {
123 public:
124 DecorationManager(IGameDef *gamedef);
125 virtual ~DecorationManager() = default;
127 DecorationManager *clone() const;
129 const char *getObjectTitle() const
131 return "decoration";
134 static Decoration *create(DecorationType type)
136 switch (type) {
137 case DECO_SIMPLE:
138 return new DecoSimple;
139 case DECO_SCHEMATIC:
140 return new DecoSchematic;
141 //case DECO_LSYSTEM:
142 // return new DecoLSystem;
143 default:
144 return NULL;
148 size_t placeAllDecos(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax);
150 private:
151 DecorationManager() {};