3 Copyright (C) 2015-2020 paramat
4 Copyright (C) 2014-2016 kwolekr, Ryan Kwolek <kwolekr@minetest.net>
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.
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.
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.
23 #include <unordered_set>
28 typedef u16 biome_t; // copy from mg_biome.h to avoid an unnecessary include
34 /////////////////// Ore generation flags
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
51 extern FlagDesc flagdesc_ore[];
53 class Ore : public ObjDef, public NodeResolver {
55 const bool needs_noise;
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
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;
71 explicit Ore(bool needs_noise): needs_noise(needs_noise) {}
74 virtual void resolveNodeNames();
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;
81 void cloneTo(Ore *def) const;
84 class OreScatter : public Ore {
86 OreScatter() : Ore(false) {}
88 ObjDef *clone() const override;
90 void generate(MMVManip *vm, int mapseed, u32 blockseed,
91 v3s16 nmin, v3s16 nmax, biome_t *biomemap) override;
94 class OreSheet : public Ore {
96 OreSheet() : Ore(true) {}
98 ObjDef *clone() const override;
100 u16 column_height_min;
101 u16 column_height_max;
102 float column_midpoint_factor;
104 void generate(MMVManip *vm, int mapseed, u32 blockseed,
105 v3s16 nmin, v3s16 nmax, biome_t *biomemap) override;
108 class OrePuff : public Ore {
110 ObjDef *clone() const override;
112 NoiseParams np_puff_top;
113 NoiseParams np_puff_bottom;
114 Noise *noise_puff_top = nullptr;
115 Noise *noise_puff_bottom = nullptr;
117 OrePuff() : Ore(true) {}
120 void generate(MMVManip *vm, int mapseed, u32 blockseed,
121 v3s16 nmin, v3s16 nmax, biome_t *biomemap) override;
124 class OreBlob : public Ore {
126 ObjDef *clone() const override;
128 OreBlob() : Ore(true) {}
129 void generate(MMVManip *vm, int mapseed, u32 blockseed,
130 v3s16 nmin, v3s16 nmax, biome_t *biomemap) override;
133 class OreVein : public Ore {
135 ObjDef *clone() const override;
138 Noise *noise2 = nullptr;
141 OreVein() : Ore(true) {}
144 void generate(MMVManip *vm, int mapseed, u32 blockseed,
145 v3s16 nmin, v3s16 nmax, biome_t *biomemap) override;
148 class OreStratum : public Ore {
150 ObjDef *clone() const override;
152 NoiseParams np_stratum_thickness;
153 Noise *noise_stratum_thickness = nullptr;
154 u16 stratum_thickness;
156 OreStratum() : Ore(false) {}
157 virtual ~OreStratum();
159 void generate(MMVManip *vm, int mapseed, u32 blockseed,
160 v3s16 nmin, v3s16 nmax, biome_t *biomemap) override;
163 class OreManager : public ObjDefManager {
165 OreManager(IGameDef *gamedef);
166 virtual ~OreManager() = default;
168 OreManager *clone() const;
170 const char *getObjectTitle() const
175 static Ore *create(OreType type)
179 return new OreScatter;
189 return new OreStratum;
197 size_t placeAllOres(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax);