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