]> git.lizzy.rs Git - dragonfireclient.git/blob - src/mg_ore.h
db204437ebf5cc0c3d0bec0022e2cf20f6908516
[dragonfireclient.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 "objdef.h"
24 #include "noise.h"
25 #include "nodedef.h"
26
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_SCATTER,
43         ORE_SHEET,
44         ORE_BLOB,
45         ORE_VEIN,
46 };
47
48 extern FlagDesc flagdesc_ore[];
49
50 class Ore : public ObjDef, 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         std::set<u8> biomes;
67
68         Ore();
69         virtual ~Ore();
70
71         virtual void resolveNodeNames();
72
73         size_t placeOre(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax);
74         virtual void generate(MMVManip *vm, int mapseed, u32 blockseed,
75                 v3s16 nmin, v3s16 nmax, u8 *biomemap) = 0;
76 };
77
78 class OreScatter : public Ore {
79 public:
80         static const bool NEEDS_NOISE = false;
81
82         virtual void generate(MMVManip *vm, int mapseed, u32 blockseed,
83                 v3s16 nmin, v3s16 nmax, u8 *biomemap);
84 };
85
86 class OreSheet : public Ore {
87 public:
88         static const bool NEEDS_NOISE = true;
89
90         u16 column_height_min;
91         u16 column_height_max;
92         float column_midpoint_factor;
93
94         virtual void generate(MMVManip *vm, int mapseed, u32 blockseed,
95                 v3s16 nmin, v3s16 nmax, u8 *biomemap);
96 };
97
98 class OreBlob : public Ore {
99 public:
100         static const bool NEEDS_NOISE = true;
101
102         virtual void generate(MMVManip *vm, int mapseed, u32 blockseed,
103                 v3s16 nmin, v3s16 nmax, u8 *biomemap);
104 };
105
106 class OreVein : public Ore {
107 public:
108         static const bool NEEDS_NOISE = true;
109
110         float random_factor;
111         Noise *noise2;
112
113         OreVein();
114         virtual ~OreVein();
115
116         virtual void generate(MMVManip *vm, int mapseed, u32 blockseed,
117                 v3s16 nmin, v3s16 nmax, u8 *biomemap);
118 };
119
120 class OreManager : public ObjDefManager {
121 public:
122         OreManager(IGameDef *gamedef);
123         virtual ~OreManager() {}
124
125         const char *getObjectTitle() const
126         {
127                 return "ore";
128         }
129
130         static Ore *create(OreType type)
131         {
132                 switch (type) {
133                 case ORE_SCATTER:
134                         return new OreScatter;
135                 case ORE_SHEET:
136                         return new OreSheet;
137                 case ORE_BLOB:
138                         return new OreBlob;
139                 case ORE_VEIN:
140                         return new OreVein;
141                 default:
142                         return NULL;
143                 }
144         }
145
146         void clear();
147
148         size_t placeAllOres(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax);
149 };
150
151 #endif