Ores: Make 'absheight' flag non-functional
[oweals/minetest.git] / src / mg_ore.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_ORE_HEADER
22 #define MG_ORE_HEADER
23
24 #include <unordered_set>
25 #include "objdef.h"
26 #include "noise.h"
27 #include "nodedef.h"
28
29 class Noise;
30 class Mapgen;
31 class MMVManip;
32
33 /////////////////// Ore generation flags
34
35 #define OREFLAG_ABSHEIGHT     0x01 // Non-functional but kept to not break flags
36 #define OREFLAG_PUFF_CLIFFS   0x02
37 #define OREFLAG_PUFF_ADDITIVE 0x04
38 #define OREFLAG_USE_NOISE     0x08
39
40 enum OreType {
41         ORE_SCATTER,
42         ORE_SHEET,
43         ORE_PUFF,
44         ORE_BLOB,
45         ORE_VEIN,
46 };
47
48 extern FlagDesc flagdesc_ore[];
49
50 class Ore : public ObjDef, public NodeResolver {
51 public:
52         static const bool NEEDS_NOISE = false;
53
54         content_t c_ore;                  // the node to place
55         std::vector<content_t> c_wherein; // the nodes to be placed in
56         u32 clust_scarcity; // ore cluster has a 1-in-clust_scarcity chance of appearing at a node
57         s16 clust_num_ores; // how many ore nodes are in a chunk
58         s16 clust_size;     // how large (in nodes) a chunk of ore is
59         s16 y_min;
60         s16 y_max;
61         u8 ore_param2;          // to set node-specific attributes
62         u32 flags = 0;          // attributes for this ore
63         float nthresh;      // threshold for noise at which an ore is placed
64         NoiseParams np;     // noise for distribution of clusters (NULL for uniform scattering)
65         Noise *noise = nullptr;
66         std::unordered_set<u8> biomes;
67
68         Ore() {};
69         virtual ~Ore();
70
71         virtual void resolveNodeNames();
72
73         size_t placeOre(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax);
74         virtual void generate(MMVManip *vm, int mapseed, u32 blockseed,
75                 v3s16 nmin, v3s16 nmax, u8 *biomemap) = 0;
76 };
77
78 class OreScatter : public Ore {
79 public:
80         static const bool NEEDS_NOISE = false;
81
82         virtual void generate(MMVManip *vm, int mapseed, u32 blockseed,
83                 v3s16 nmin, v3s16 nmax, u8 *biomemap);
84 };
85
86 class OreSheet : public Ore {
87 public:
88         static const bool NEEDS_NOISE = true;
89
90         u16 column_height_min;
91         u16 column_height_max;
92         float column_midpoint_factor;
93
94         virtual void generate(MMVManip *vm, int mapseed, u32 blockseed,
95                 v3s16 nmin, v3s16 nmax, u8 *biomemap);
96 };
97
98 class OrePuff : public Ore {
99 public:
100         static const bool NEEDS_NOISE = true;
101
102         NoiseParams np_puff_top;
103         NoiseParams np_puff_bottom;
104         Noise *noise_puff_top = nullptr;
105         Noise *noise_puff_bottom = nullptr;
106
107         OrePuff();
108         virtual ~OrePuff();
109
110         virtual void generate(MMVManip *vm, int mapseed, u32 blockseed,
111                 v3s16 nmin, v3s16 nmax, u8 *biomemap);
112 };
113
114 class OreBlob : public Ore {
115 public:
116         static const bool NEEDS_NOISE = true;
117
118         virtual void generate(MMVManip *vm, int mapseed, u32 blockseed,
119                 v3s16 nmin, v3s16 nmax, u8 *biomemap);
120 };
121
122 class OreVein : public Ore {
123 public:
124         static const bool NEEDS_NOISE = true;
125
126         float random_factor;
127         Noise *noise2 = nullptr;
128
129         OreVein();
130         virtual ~OreVein();
131
132         virtual void generate(MMVManip *vm, int mapseed, u32 blockseed,
133                 v3s16 nmin, v3s16 nmax, u8 *biomemap);
134 };
135
136 class OreManager : public ObjDefManager {
137 public:
138         OreManager(IGameDef *gamedef);
139         virtual ~OreManager() {}
140
141         const char *getObjectTitle() const
142         {
143                 return "ore";
144         }
145
146         static Ore *create(OreType type)
147         {
148                 switch (type) {
149                 case ORE_SCATTER:
150                         return new OreScatter;
151                 case ORE_SHEET:
152                         return new OreSheet;
153                 case ORE_PUFF:
154                         return new OrePuff;
155                 case ORE_BLOB:
156                         return new OreBlob;
157                 case ORE_VEIN:
158                         return new OreVein;
159                 default:
160                         return nullptr;
161                 }
162         }
163
164         void clear();
165
166         size_t placeAllOres(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax);
167 };
168
169 #endif