Luanti 5.11.0-dev
 
Loading...
Searching...
No Matches
mg_decoration.h
Go to the documentation of this file.
1// Luanti
2// SPDX-License-Identifier: LGPL-2.1-or-later
3// Copyright (C) 2014-2018 kwolekr, Ryan Kwolek <kwolekr@minetest.net>
4// Copyright (C) 2015-2018 paramat
5
6#pragma once
7
8#include <unordered_set>
9#include "objdef.h"
10#include "noise.h"
11#include "nodedef.h"
12
13typedef u16 biome_t; // copy from mg_biome.h to avoid an unnecessary include
14
15class Mapgen;
16class MMVManip;
17class PcgRandom;
18class Schematic;
19namespace treegen { struct TreeDef; }
20
26
27#define DECO_PLACE_CENTER_X 0x01
28#define DECO_PLACE_CENTER_Y 0x02
29#define DECO_PLACE_CENTER_Z 0x04
30#define DECO_USE_NOISE 0x08
31#define DECO_FORCE_PLACEMENT 0x10
32#define DECO_LIQUID_SURFACE 0x20
33#define DECO_ALL_FLOORS 0x40
34#define DECO_ALL_CEILINGS 0x80
35
36extern FlagDesc flagdesc_deco[];
37
38
39class Decoration : public ObjDef, public NodeResolver {
40public:
41 Decoration() = default;
42 virtual ~Decoration() = default;
43
44 virtual void resolveNodeNames();
45
47 size_t placeDeco(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax);
48
49 virtual size_t generate(MMVManip *vm, PcgRandom *pr, v3s16 p, bool ceiling) = 0;
50
51 u32 flags = 0;
52 int mapseed = 0;
53 std::vector<content_t> c_place_on;
54 s16 sidelen = 1;
55 s16 y_min;
56 s16 y_max;
57 float fill_ratio = 0.0f;
59 std::vector<content_t> c_spawnby;
62 s16 check_offset = -1;
63
64 std::unordered_set<biome_t> biomes;
65
66protected:
67 void cloneTo(Decoration *def) const;
68};
69
70
71class DecoSimple : public Decoration {
72public:
73 ObjDef *clone() const;
74
75 virtual void resolveNodeNames();
76 virtual size_t generate(MMVManip *vm, PcgRandom *pr, v3s16 p, bool ceiling);
77
78 std::vector<content_t> c_decos;
83};
84
85
86class DecoSchematic : public Decoration {
87public:
88 ObjDef *clone() const;
89
90 DecoSchematic() = default;
91 virtual ~DecoSchematic();
92
93 virtual size_t generate(MMVManip *vm, PcgRandom *pr, v3s16 p, bool ceiling);
94
96 Schematic *schematic = nullptr;
97 bool was_cloned = false; // see FIXME inside DecoSchemtic::clone()
98};
99
100
101class DecoLSystem : public Decoration {
102public:
103 ObjDef *clone() const;
104
105 virtual size_t generate(MMVManip *vm, PcgRandom *pr, v3s16 p, bool ceiling);
106
107 // In case it gets cloned it uses the same tree def.
108 std::shared_ptr<treegen::TreeDef> tree_def;
109};
110
111
113public:
114 DecorationManager(IGameDef *gamedef);
115 virtual ~DecorationManager() = default;
116
117 DecorationManager *clone() const;
118
119 const char *getObjectTitle() const
120 {
121 return "decoration";
122 }
123
125 {
126 switch (type) {
127 case DECO_SIMPLE:
128 return new DecoSimple;
129 case DECO_SCHEMATIC:
130 return new DecoSchematic;
131 case DECO_LSYSTEM:
132 return new DecoLSystem;
133 default:
134 return NULL;
135 }
136 }
137
138 size_t placeAllDecos(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax);
139
140private:
142};
Definition mg_decoration.h:101
virtual size_t generate(MMVManip *vm, PcgRandom *pr, v3s16 p, bool ceiling)
Definition mg_decoration.cpp:473
ObjDef * clone() const
Definition mg_decoration.cpp:463
std::shared_ptr< treegen::TreeDef > tree_def
Definition mg_decoration.h:108
Definition mg_decoration.h:86
bool was_cloned
Definition mg_decoration.h:97
Rotation rotation
Definition mg_decoration.h:95
virtual ~DecoSchematic()
Definition mg_decoration.cpp:385
virtual size_t generate(MMVManip *vm, PcgRandom *pr, v3s16 p, bool ceiling)
Definition mg_decoration.cpp:410
DecoSchematic()=default
ObjDef * clone() const
Definition mg_decoration.cpp:392
Schematic * schematic
Definition mg_decoration.h:96
Definition mg_decoration.h:71
u8 deco_param2_max
Definition mg_decoration.h:82
s16 deco_height
Definition mg_decoration.h:79
virtual void resolveNodeNames()
Definition mg_decoration.cpp:306
ObjDef * clone() const
Definition mg_decoration.cpp:291
s16 deco_height_max
Definition mg_decoration.h:80
virtual size_t generate(MMVManip *vm, PcgRandom *pr, v3s16 p, bool ceiling)
Definition mg_decoration.cpp:313
u8 deco_param2
Definition mg_decoration.h:81
std::vector< content_t > c_decos
Definition mg_decoration.h:78
Definition mg_decoration.h:112
virtual ~DecorationManager()=default
DecorationManager()
Definition mg_decoration.h:141
static Decoration * create(DecorationType type)
Definition mg_decoration.h:124
DecorationManager * clone() const
Definition mg_decoration.cpp:56
size_t placeAllDecos(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax)
Definition mg_decoration.cpp:39
const char * getObjectTitle() const
Definition mg_decoration.h:119
Definition mg_decoration.h:39
NoiseParams np
Definition mg_decoration.h:58
float fill_ratio
Definition mg_decoration.h:57
void cloneTo(Decoration *def) const
Definition mg_decoration.cpp:269
s16 y_max
Definition mg_decoration.h:56
virtual size_t generate(MMVManip *vm, PcgRandom *pr, v3s16 p, bool ceiling)=0
s16 check_offset
Definition mg_decoration.h:62
virtual void resolveNodeNames()
Definition mg_decoration.cpp:67
virtual ~Decoration()=default
size_t placeDeco(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax)
Definition mg_decoration.cpp:131
s16 nspawnby
Definition mg_decoration.h:60
s16 sidelen
Definition mg_decoration.h:54
bool canPlaceDecoration(MMVManip *vm, v3s16 p)
Definition mg_decoration.cpp:74
u32 flags
Definition mg_decoration.h:51
std::vector< content_t > c_spawnby
Definition mg_decoration.h:59
int mapseed
Definition mg_decoration.h:52
std::unordered_set< biome_t > biomes
Definition mg_decoration.h:64
s16 place_offset_y
Definition mg_decoration.h:61
s16 y_min
Definition mg_decoration.h:55
Decoration()=default
std::vector< content_t > c_place_on
Definition mg_decoration.h:53
Definition gamedef.h:36
Definition map.h:305
Definition mapgen.h:153
Definition nodedef.h:837
Definition objdef.h:56
Definition objdef.h:30
Definition noise.h:89
Definition mg_schematic.h:79
core::vector3d< s16 > v3s16
Definition irr_v3d.h:13
Rotation
Definition mapnode.h:88
DecorationType
Definition mg_decoration.h:21
@ DECO_SCHEMATIC
Definition mg_decoration.h:23
@ DECO_LSYSTEM
Definition mg_decoration.h:24
@ DECO_SIMPLE
Definition mg_decoration.h:22
FlagDesc flagdesc_deco[]
Definition mg_decoration.cpp:18
u16 biome_t
Definition mg_decoration.h:13
Definition mg_decoration.h:19
Definition string.h:67
Definition noise.h:119
Definition treegen.h:25
static std::string p(std::string path)
Definition test_filesys.cpp:53