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