Minetest 5.10.0-dev
 
Loading...
Searching...
No Matches
mg_decoration.h
Go to the documentation of this file.
1/*
2Minetest
3Copyright (C) 2014-2018 kwolekr, Ryan Kwolek <kwolekr@minetest.net>
4Copyright (C) 2015-2018 paramat
5
6This program is free software; you can redistribute it and/or modify
7it under the terms of the GNU Lesser General Public License as published by
8the Free Software Foundation; either version 2.1 of the License, or
9(at your option) any later version.
10
11This program is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU Lesser General Public License for more details.
15
16You should have received a copy of the GNU Lesser General Public License along
17with this program; if not, write to the Free Software Foundation, Inc.,
1851 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19*/
20
21#pragma once
22
23#include <unordered_set>
24#include "objdef.h"
25#include "noise.h"
26#include "nodedef.h"
27
28typedef u16 biome_t; // copy from mg_biome.h to avoid an unnecessary include
29
30class Mapgen;
31class MMVManip;
32class PcgRandom;
33class Schematic;
34namespace treegen { struct TreeDef; }
35
41
42#define DECO_PLACE_CENTER_X 0x01
43#define DECO_PLACE_CENTER_Y 0x02
44#define DECO_PLACE_CENTER_Z 0x04
45#define DECO_USE_NOISE 0x08
46#define DECO_FORCE_PLACEMENT 0x10
47#define DECO_LIQUID_SURFACE 0x20
48#define DECO_ALL_FLOORS 0x40
49#define DECO_ALL_CEILINGS 0x80
50
51extern FlagDesc flagdesc_deco[];
52
53
54class Decoration : public ObjDef, public NodeResolver {
55public:
56 Decoration() = default;
57 virtual ~Decoration() = default;
58
59 virtual void resolveNodeNames();
60
62 size_t placeDeco(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax);
63
64 virtual size_t generate(MMVManip *vm, PcgRandom *pr, v3s16 p, bool ceiling) = 0;
65
66 u32 flags = 0;
67 int mapseed = 0;
68 std::vector<content_t> c_place_on;
69 s16 sidelen = 1;
70 s16 y_min;
71 s16 y_max;
72 float fill_ratio = 0.0f;
74 std::vector<content_t> c_spawnby;
77 s16 check_offset = -1;
78
79 std::unordered_set<biome_t> biomes;
80
81protected:
82 void cloneTo(Decoration *def) const;
83};
84
85
86class DecoSimple : public Decoration {
87public:
88 ObjDef *clone() const;
89
90 virtual void resolveNodeNames();
91 virtual size_t generate(MMVManip *vm, PcgRandom *pr, v3s16 p, bool ceiling);
92
93 std::vector<content_t> c_decos;
98};
99
100
101class DecoSchematic : public Decoration {
102public:
103 ObjDef *clone() const;
104
105 DecoSchematic() = default;
106 virtual ~DecoSchematic();
107
108 virtual size_t generate(MMVManip *vm, PcgRandom *pr, v3s16 p, bool ceiling);
109
112 bool was_cloned = false; // see FIXME inside DecoSchemtic::clone()
113};
114
115
116class DecoLSystem : public Decoration {
117public:
118 ObjDef *clone() const;
119
120 virtual size_t generate(MMVManip *vm, PcgRandom *pr, v3s16 p, bool ceiling);
121
122 // In case it gets cloned it uses the same tree def.
123 std::shared_ptr<treegen::TreeDef> tree_def;
124};
125
126
128public:
129 DecorationManager(IGameDef *gamedef);
130 virtual ~DecorationManager() = default;
131
132 DecorationManager *clone() const;
133
134 const char *getObjectTitle() const
135 {
136 return "decoration";
137 }
138
140 {
141 switch (type) {
142 case DECO_SIMPLE:
143 return new DecoSimple;
144 case DECO_SCHEMATIC:
145 return new DecoSchematic;
146 case DECO_LSYSTEM:
147 return new DecoLSystem;
148 default:
149 return NULL;
150 }
151 }
152
153 size_t placeAllDecos(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax);
154
155private:
157};
Definition mg_decoration.h:116
virtual size_t generate(MMVManip *vm, PcgRandom *pr, v3s16 p, bool ceiling)
Definition mg_decoration.cpp:488
ObjDef * clone() const
Definition mg_decoration.cpp:478
std::shared_ptr< treegen::TreeDef > tree_def
Definition mg_decoration.h:123
Definition mg_decoration.h:101
bool was_cloned
Definition mg_decoration.h:112
Rotation rotation
Definition mg_decoration.h:110
virtual ~DecoSchematic()
Definition mg_decoration.cpp:400
virtual size_t generate(MMVManip *vm, PcgRandom *pr, v3s16 p, bool ceiling)
Definition mg_decoration.cpp:425
DecoSchematic()=default
ObjDef * clone() const
Definition mg_decoration.cpp:407
Schematic * schematic
Definition mg_decoration.h:111
Definition mg_decoration.h:86
u8 deco_param2_max
Definition mg_decoration.h:97
s16 deco_height
Definition mg_decoration.h:94
virtual void resolveNodeNames()
Definition mg_decoration.cpp:321
ObjDef * clone() const
Definition mg_decoration.cpp:306
s16 deco_height_max
Definition mg_decoration.h:95
virtual size_t generate(MMVManip *vm, PcgRandom *pr, v3s16 p, bool ceiling)
Definition mg_decoration.cpp:328
u8 deco_param2
Definition mg_decoration.h:96
std::vector< content_t > c_decos
Definition mg_decoration.h:93
Definition mg_decoration.h:127
virtual ~DecorationManager()=default
DecorationManager()
Definition mg_decoration.h:156
static Decoration * create(DecorationType type)
Definition mg_decoration.h:139
DecorationManager * clone() const
Definition mg_decoration.cpp:71
size_t placeAllDecos(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax)
Definition mg_decoration.cpp:54
const char * getObjectTitle() const
Definition mg_decoration.h:134
Definition mg_decoration.h:54
NoiseParams np
Definition mg_decoration.h:73
float fill_ratio
Definition mg_decoration.h:72
void cloneTo(Decoration *def) const
Definition mg_decoration.cpp:284
s16 y_max
Definition mg_decoration.h:71
virtual size_t generate(MMVManip *vm, PcgRandom *pr, v3s16 p, bool ceiling)=0
s16 check_offset
Definition mg_decoration.h:77
virtual void resolveNodeNames()
Definition mg_decoration.cpp:82
virtual ~Decoration()=default
size_t placeDeco(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax)
Definition mg_decoration.cpp:146
s16 nspawnby
Definition mg_decoration.h:75
s16 sidelen
Definition mg_decoration.h:69
bool canPlaceDecoration(MMVManip *vm, v3s16 p)
Definition mg_decoration.cpp:89
u32 flags
Definition mg_decoration.h:66
std::vector< content_t > c_spawnby
Definition mg_decoration.h:74
int mapseed
Definition mg_decoration.h:67
std::unordered_set< biome_t > biomes
Definition mg_decoration.h:79
s16 place_offset_y
Definition mg_decoration.h:76
s16 y_min
Definition mg_decoration.h:70
Decoration()=default
std::vector< content_t > c_place_on
Definition mg_decoration.h:68
Definition gamedef.h:51
Definition map.h:320
Definition mapgen.h:168
Definition nodedef.h:853
Definition objdef.h:70
Definition objdef.h:44
Definition noise.h:89
Definition mg_schematic.h:94
core::vector3d< s16 > v3s16
Definition irr_v3d.h:28
Rotation
Definition mapnode.h:103
DecorationType
Definition mg_decoration.h:36
@ DECO_SCHEMATIC
Definition mg_decoration.h:38
@ DECO_LSYSTEM
Definition mg_decoration.h:39
@ DECO_SIMPLE
Definition mg_decoration.h:37
FlagDesc flagdesc_deco[]
Definition mg_decoration.cpp:33
u16 biome_t
Definition mg_decoration.h:28
Definition mg_decoration.h:34
Definition string.h:80
Definition noise.h:119
Definition treegen.h:40
static std::string p(std::string path)
Definition test_filesys.cpp:66