]> git.lizzy.rs Git - dragonfireclient.git/blob - src/mapgen/mg_ore.h
76420fab4732807c96896744d389ffefa8aae5f5
[dragonfireclient.git] / src / mapgen / mg_ore.h
1 /*
2 Minetest
3 Copyright (C) 2015-2020 paramat
4 Copyright (C) 2014-2016 kwolekr, Ryan Kwolek <kwolekr@minetest.net>
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 typedef u16 biome_t;  // copy from mg_biome.h to avoid an unnecessary include
29
30 class Noise;
31 class Mapgen;
32 class MMVManip;
33
34 /////////////////// Ore generation flags
35
36 #define OREFLAG_ABSHEIGHT     0x01 // Non-functional but kept to not break flags
37 #define OREFLAG_PUFF_CLIFFS   0x02
38 #define OREFLAG_PUFF_ADDITIVE 0x04
39 #define OREFLAG_USE_NOISE     0x08
40 #define OREFLAG_USE_NOISE2    0x10
41
42 enum OreType {
43         ORE_SCATTER,
44         ORE_SHEET,
45         ORE_PUFF,
46         ORE_BLOB,
47         ORE_VEIN,
48         ORE_STRATUM,
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<biome_t> biomes;
70
71         Ore() = default;;
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, biome_t *biomemap) = 0;
79
80 protected:
81         void cloneTo(Ore *def) const;
82 };
83
84 class OreScatter : public Ore {
85 public:
86         static const bool NEEDS_NOISE = false;
87
88         ObjDef *clone() const;
89
90         virtual void generate(MMVManip *vm, int mapseed, u32 blockseed,
91                 v3s16 nmin, v3s16 nmax, biome_t *biomemap);
92 };
93
94 class OreSheet : public Ore {
95 public:
96         static const bool NEEDS_NOISE = true;
97
98         ObjDef *clone() const;
99
100         u16 column_height_min;
101         u16 column_height_max;
102         float column_midpoint_factor;
103
104         virtual void generate(MMVManip *vm, int mapseed, u32 blockseed,
105                 v3s16 nmin, v3s16 nmax, biome_t *biomemap);
106 };
107
108 class OrePuff : public Ore {
109 public:
110         static const bool NEEDS_NOISE = true;
111
112         ObjDef *clone() const;
113
114         NoiseParams np_puff_top;
115         NoiseParams np_puff_bottom;
116         Noise *noise_puff_top = nullptr;
117         Noise *noise_puff_bottom = nullptr;
118
119         OrePuff() = default;
120         virtual ~OrePuff();
121
122         virtual void generate(MMVManip *vm, int mapseed, u32 blockseed,
123                 v3s16 nmin, v3s16 nmax, biome_t *biomemap);
124 };
125
126 class OreBlob : public Ore {
127 public:
128         static const bool NEEDS_NOISE = true;
129
130         ObjDef *clone() const;
131
132         virtual void generate(MMVManip *vm, int mapseed, u32 blockseed,
133                 v3s16 nmin, v3s16 nmax, biome_t *biomemap);
134 };
135
136 class OreVein : public Ore {
137 public:
138         static const bool NEEDS_NOISE = true;
139
140         ObjDef *clone() const;
141
142         float random_factor;
143         Noise *noise2 = nullptr;
144         int sizey_prev = 0;
145
146         OreVein() = default;
147         virtual ~OreVein();
148
149         virtual void generate(MMVManip *vm, int mapseed, u32 blockseed,
150                 v3s16 nmin, v3s16 nmax, biome_t *biomemap);
151 };
152
153 class OreStratum : public Ore {
154 public:
155         static const bool NEEDS_NOISE = false;
156
157         ObjDef *clone() const;
158
159         NoiseParams np_stratum_thickness;
160         Noise *noise_stratum_thickness = nullptr;
161         u16 stratum_thickness;
162
163         OreStratum() = default;
164         virtual ~OreStratum();
165
166         virtual void generate(MMVManip *vm, int mapseed, u32 blockseed,
167                 v3s16 nmin, v3s16 nmax, biome_t *biomemap);
168 };
169
170 class OreManager : public ObjDefManager {
171 public:
172         OreManager(IGameDef *gamedef);
173         virtual ~OreManager() = default;
174
175         OreManager *clone() const;
176
177         const char *getObjectTitle() const
178         {
179                 return "ore";
180         }
181
182         static Ore *create(OreType type)
183         {
184                 switch (type) {
185                 case ORE_SCATTER:
186                         return new OreScatter;
187                 case ORE_SHEET:
188                         return new OreSheet;
189                 case ORE_PUFF:
190                         return new OrePuff;
191                 case ORE_BLOB:
192                         return new OreBlob;
193                 case ORE_VEIN:
194                         return new OreVein;
195                 case ORE_STRATUM:
196                         return new OreStratum;
197                 default:
198                         return nullptr;
199                 }
200         }
201
202         void clear();
203
204         size_t placeAllOres(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax);
205
206 private:
207         OreManager() {};
208 };