Fog effect when camera is inside cloud
[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 #ifndef MG_DECORATION_HEADER
22 #define MG_DECORATION_HEADER
23
24 #include <unordered_set>
25 #include "objdef.h"
26 #include "noise.h"
27 #include "nodedef.h"
28
29 class Mapgen;
30 class MMVManip;
31 class PcgRandom;
32 class Schematic;
33
34 enum DecorationType {
35         DECO_SIMPLE,
36         DECO_SCHEMATIC,
37         DECO_LSYSTEM
38 };
39
40 #define DECO_PLACE_CENTER_X  0x01
41 #define DECO_PLACE_CENTER_Y  0x02
42 #define DECO_PLACE_CENTER_Z  0x04
43 #define DECO_USE_NOISE       0x08
44 #define DECO_FORCE_PLACEMENT 0x10
45 #define DECO_LIQUID_SURFACE  0x20
46
47 extern FlagDesc flagdesc_deco[];
48
49
50 #if 0
51 struct CutoffData {
52         VoxelArea a;
53         Decoration *deco;
54         //v3s16 p;
55         //v3s16 size;
56         //s16 height;
57
58         CutoffData(s16 x, s16 y, s16 z, s16 h) {
59                 p = v3s16(x, y, z);
60                 height = h;
61         }
62 };
63 #endif
64
65 class Decoration : public ObjDef, public NodeResolver {
66 public:
67         Decoration() {};
68         virtual ~Decoration() {};
69
70         virtual void resolveNodeNames();
71
72         bool canPlaceDecoration(MMVManip *vm, v3s16 p);
73         size_t placeDeco(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax);
74         //size_t placeCutoffs(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax);
75
76         virtual size_t generate(MMVManip *vm, PcgRandom *pr, v3s16 p) = 0;
77         virtual int getHeight() = 0;
78
79         u32 flags = 0;
80         int mapseed = 0;
81         std::vector<content_t> c_place_on;
82         s16 sidelen = 1;
83         s16 y_min;
84         s16 y_max;
85         float fill_ratio = 0.0f;
86         NoiseParams np;
87         std::vector<content_t> c_spawnby;
88         s16 nspawnby;
89
90         std::unordered_set<u8> biomes;
91 };
92
93 class DecoSimple : public Decoration {
94 public:
95         virtual void resolveNodeNames();
96         virtual size_t generate(MMVManip *vm, PcgRandom *pr, v3s16 p);
97         virtual int getHeight();
98
99         std::vector<content_t> c_decos;
100         s16 deco_height;
101         s16 deco_height_max;
102         u8 deco_param2;
103 };
104
105 class DecoSchematic : public Decoration {
106 public:
107         DecoSchematic() {};
108
109         virtual size_t generate(MMVManip *vm, PcgRandom *pr, v3s16 p);
110         virtual int getHeight();
111
112         Rotation rotation;
113         Schematic *schematic = nullptr;
114 };
115
116
117 /*
118 class DecoLSystem : public Decoration {
119 public:
120         virtual void generate(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax);
121 };
122 */
123
124 class DecorationManager : public ObjDefManager {
125 public:
126         DecorationManager(IGameDef *gamedef);
127         virtual ~DecorationManager() {}
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
151 #endif