]> git.lizzy.rs Git - minetest.git/blob - src/mg_ore.h
67ca9a849630f03d1ad5801ab157ecf4e10874e1
[minetest.git] / src / mg_ore.h
1 /*
2 Minetest
3 Copyright (C) 2010-2013 kwolekr, Ryan Kwolek <kwolekr@minetest.net>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #ifndef MG_ORE_HEADER
21 #define MG_ORE_HEADER
22
23 #include "util/string.h"
24 #include "mapgen.h"
25
26 struct NoiseParams;
27 class Noise;
28 class Mapgen;
29 class MMVManip;
30
31 /////////////////// Ore generation flags
32
33 // Use absolute value of height to determine ore placement
34 #define OREFLAG_ABSHEIGHT 0x01
35 #define OREFLAG_USE_NOISE 0x08
36
37 #define ORE_RANGE_ACTUAL 1
38 #define ORE_RANGE_MIRROR 2
39
40
41 enum OreType {
42         ORE_TYPE_SCATTER,
43         ORE_TYPE_SHEET,
44         ORE_TYPE_BLOB,
45         ORE_TYPE_VEIN,
46 };
47
48 extern FlagDesc flagdesc_ore[];
49
50 class Ore : public GenElement, 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;          // attributes for this ore
63         float nthresh;      // threshhold for noise at which an ore is placed
64         NoiseParams np;     // noise for distribution of clusters (NULL for uniform scattering)
65         Noise *noise;
66
67         Ore();
68         virtual ~Ore();
69
70         virtual void resolveNodeNames(NodeResolveInfo *nri);
71
72         size_t placeOre(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax);
73         virtual void generate(MMVManip *vm, int mapseed, u32 blockseed,
74                 v3s16 nmin, v3s16 nmax) = 0;
75 };
76
77 class OreScatter : public Ore {
78 public:
79         static const bool NEEDS_NOISE = false;
80
81         virtual void generate(MMVManip *vm, int mapseed, u32 blockseed,
82                 v3s16 nmin, v3s16 nmax);
83 };
84
85 class OreSheet : public Ore {
86 public:
87         static const bool NEEDS_NOISE = true;
88
89         virtual void generate(MMVManip *vm, int mapseed, u32 blockseed,
90                 v3s16 nmin, v3s16 nmax);
91 };
92
93 class OreBlob : public Ore {
94 public:
95         static const bool NEEDS_NOISE = true;
96
97         virtual void generate(MMVManip *vm, int mapseed, u32 blockseed,
98                 v3s16 nmin, v3s16 nmax);
99 };
100
101 class OreVein : public Ore {
102 public:
103         static const bool NEEDS_NOISE = true;
104
105         float random_factor;
106         Noise *noise2;
107
108         OreVein();
109         virtual ~OreVein();
110
111         virtual void generate(MMVManip *vm, int mapseed, u32 blockseed,
112                 v3s16 nmin, v3s16 nmax);
113 };
114
115 class OreManager : public GenElementManager {
116 public:
117         static const char *ELEMENT_TITLE;
118         static const size_t ELEMENT_LIMIT = 0x10000;
119
120         OreManager(IGameDef *gamedef);
121         ~OreManager() {}
122
123         Ore *create(int type)
124         {
125                 switch (type) {
126                 case ORE_TYPE_SCATTER:
127                         return new OreScatter;
128                 case ORE_TYPE_SHEET:
129                         return new OreSheet;
130                 case ORE_TYPE_BLOB:
131                         return new OreBlob;
132                 case ORE_TYPE_VEIN:
133                         return new OreVein;
134                 default:
135                         return NULL;
136                 }
137         }
138
139         void clear();
140
141         size_t placeAllOres(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax);
142 };
143
144 #endif