Move files to subdirectories (#6599)
[oweals/minetest.git] / src / mapgen / mg_decoration.h
1 /*
2 Minetest
3 Copyright (C) 2014-2016 kwolekr, Ryan Kwolek <kwolekr@minetest.net>
4 Copyright (C) 2015-2017 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 class Mapgen;
29 class MMVManip;
30 class PcgRandom;
31 class Schematic;
32
33 enum DecorationType {
34         DECO_SIMPLE,
35         DECO_SCHEMATIC,
36         DECO_LSYSTEM
37 };
38
39 #define DECO_PLACE_CENTER_X  0x01
40 #define DECO_PLACE_CENTER_Y  0x02
41 #define DECO_PLACE_CENTER_Z  0x04
42 #define DECO_USE_NOISE       0x08
43 #define DECO_FORCE_PLACEMENT 0x10
44 #define DECO_LIQUID_SURFACE  0x20
45 #define DECO_ALL_FLOORS      0x40
46 #define DECO_ALL_CEILINGS    0x80
47
48 extern FlagDesc flagdesc_deco[];
49
50
51 class Decoration : public ObjDef, public NodeResolver {
52 public:
53         Decoration() = default;
54         virtual ~Decoration() = default;
55
56         virtual void resolveNodeNames();
57
58         bool canPlaceDecoration(MMVManip *vm, v3s16 p);
59         size_t placeDeco(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax);
60
61         virtual size_t generate(MMVManip *vm, PcgRandom *pr, v3s16 p, bool ceiling) = 0;
62
63         u32 flags = 0;
64         int mapseed = 0;
65         std::vector<content_t> c_place_on;
66         s16 sidelen = 1;
67         s16 y_min;
68         s16 y_max;
69         float fill_ratio = 0.0f;
70         NoiseParams np;
71         std::vector<content_t> c_spawnby;
72         s16 nspawnby;
73         s16 place_offset_y = 0;
74
75         std::unordered_set<u8> biomes;
76 };
77
78
79 class DecoSimple : public Decoration {
80 public:
81         virtual void resolveNodeNames();
82         virtual size_t generate(MMVManip *vm, PcgRandom *pr, v3s16 p, bool ceiling);
83
84         std::vector<content_t> c_decos;
85         s16 deco_height;
86         s16 deco_height_max;
87         u8 deco_param2;
88         u8 deco_param2_max;
89 };
90
91
92 class DecoSchematic : public Decoration {
93 public:
94         DecoSchematic() = default;
95
96         virtual size_t generate(MMVManip *vm, PcgRandom *pr, v3s16 p, bool ceiling);
97
98         Rotation rotation;
99         Schematic *schematic = nullptr;
100 };
101
102
103 /*
104 class DecoLSystem : public Decoration {
105 public:
106         virtual void generate(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax);
107 };
108 */
109
110
111 class DecorationManager : public ObjDefManager {
112 public:
113         DecorationManager(IGameDef *gamedef);
114         virtual ~DecorationManager() = default;
115
116         const char *getObjectTitle() const
117         {
118                 return "decoration";
119         }
120
121         static Decoration *create(DecorationType type)
122         {
123                 switch (type) {
124                 case DECO_SIMPLE:
125                         return new DecoSimple;
126                 case DECO_SCHEMATIC:
127                         return new DecoSchematic;
128                 //case DECO_LSYSTEM:
129                 //      return new DecoLSystem;
130                 default:
131                         return NULL;
132                 }
133         }
134
135         size_t placeAllDecos(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax);
136 };