01e063ca27bc976a18129718e5761948b6ea3bb6
[oweals/minetest.git] / src / 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
46 extern FlagDesc flagdesc_deco[];
47
48
49 class Decoration : public ObjDef, public NodeResolver {
50 public:
51         Decoration() = default;
52         virtual ~Decoration() = default;
53
54         virtual void resolveNodeNames();
55
56         bool canPlaceDecoration(MMVManip *vm, v3s16 p);
57         size_t placeDeco(Mapgen *mg, u32 blockseed,
58                 v3s16 nmin, v3s16 nmax, s16 deco_zero_level);
59
60         virtual size_t generate(MMVManip *vm, PcgRandom *pr, v3s16 p) = 0;
61         virtual int getHeight() = 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
74         std::unordered_set<u8> biomes;
75 };
76
77
78 class DecoSimple : public Decoration {
79 public:
80         virtual void resolveNodeNames();
81         virtual size_t generate(MMVManip *vm, PcgRandom *pr, v3s16 p);
82         virtual int getHeight();
83
84         std::vector<content_t> c_decos;
85         s16 deco_height;
86         s16 deco_height_max;
87         u8 deco_param2;
88 };
89
90
91 class DecoSchematic : public Decoration {
92 public:
93         DecoSchematic() = default;
94
95         virtual size_t generate(MMVManip *vm, PcgRandom *pr, v3s16 p);
96         virtual int getHeight();
97
98         Rotation rotation;
99         s16 place_offset_y = 0;
100         Schematic *schematic = nullptr;
101 };
102
103
104 /*
105 class DecoLSystem : public Decoration {
106 public:
107         virtual void generate(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax);
108 };
109 */
110
111
112 class DecorationManager : public ObjDefManager {
113 public:
114         DecorationManager(IGameDef *gamedef);
115         virtual ~DecorationManager() = default;
116
117         const char *getObjectTitle() const
118         {
119                 return "decoration";
120         }
121
122         static Decoration *create(DecorationType type)
123         {
124                 switch (type) {
125                 case DECO_SIMPLE:
126                         return new DecoSimple;
127                 case DECO_SCHEMATIC:
128                         return new DecoSchematic;
129                 //case DECO_LSYSTEM:
130                 //      return new DecoLSystem;
131                 default:
132                         return NULL;
133                 }
134         }
135
136         size_t placeAllDecos(Mapgen *mg, u32 blockseed,
137                 v3s16 nmin, v3s16 nmax, s16 deco_zero_level = 0);
138 };