]> git.lizzy.rs Git - dragonfireclient.git/blob - src/mapgen/mg_decoration.h
Revert "Make Lint Happy"
[dragonfireclient.git] / src / mapgen / mg_decoration.h
1 /*
2 Minetest
3 Copyright (C) 2014-2018 kwolekr, Ryan Kwolek <kwolekr@minetest.net>
4 Copyright (C) 2015-2018 paramat
5
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.
10
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.
15
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.
19 */
20
21 #pragma once
22
23 #include <unordered_set>
24 #include "objdef.h"
25 #include "noise.h"
26 #include "nodedef.h"
27
28 typedef u16 biome_t;  // copy from mg_biome.h to avoid an unnecessary include
29
30 class Mapgen;
31 class MMVManip;
32 class PcgRandom;
33 class Schematic;
34
35 enum DecorationType {
36         DECO_SIMPLE,
37         DECO_SCHEMATIC,
38         DECO_LSYSTEM
39 };
40
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
49
50 extern FlagDesc flagdesc_deco[];
51
52
53 class Decoration : public ObjDef, public NodeResolver {
54 public:
55         Decoration() = default;
56         virtual ~Decoration() = default;
57
58         virtual void resolveNodeNames();
59
60         bool canPlaceDecoration(MMVManip *vm, v3s16 p);
61         size_t placeDeco(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax);
62
63         virtual size_t generate(MMVManip *vm, PcgRandom *pr, v3s16 p, bool ceiling) = 0;
64
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;
76
77         std::unordered_set<biome_t> biomes;
78
79 protected:
80         void cloneTo(Decoration *def) const;
81 };
82
83
84 class DecoSimple : public Decoration {
85 public:
86         ObjDef *clone() const;
87
88         virtual void resolveNodeNames();
89         virtual size_t generate(MMVManip *vm, PcgRandom *pr, v3s16 p, bool ceiling);
90
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;
96 };
97
98
99 class DecoSchematic : public Decoration {
100 public:
101         ObjDef *clone() const;
102
103         DecoSchematic() = default;
104         virtual ~DecoSchematic();
105
106         virtual size_t generate(MMVManip *vm, PcgRandom *pr, v3s16 p, bool ceiling);
107
108         Rotation rotation;
109         Schematic *schematic = nullptr;
110         bool was_cloned = false; // see FIXME inside DecoSchemtic::clone()
111 };
112
113
114 /*
115 class DecoLSystem : public Decoration {
116 public:
117         virtual void generate(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax);
118 };
119 */
120
121
122 class DecorationManager : public ObjDefManager {
123 public:
124         DecorationManager(IGameDef *gamedef);
125         virtual ~DecorationManager() = default;
126
127         DecorationManager *clone() const;
128
129         const char *getObjectTitle() const
130         {
131                 return "decoration";
132         }
133
134         static Decoration *create(DecorationType type)
135         {
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;
145                 }
146         }
147
148         size_t placeAllDecos(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax);
149
150 private:
151         DecorationManager() {};
152 };