4bf415734af3f0c40c315dc28c38f46333833d10
[oweals/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 class NoiseParams;
27 class Noise;
28 class Mapgen;
29 class ManualMapVoxelManipulator;
30
31 /////////////////// Ore generation flags
32
33 // Use absolute value of height to determine ore placement
34 #define OREFLAG_ABSHEIGHT 0x01
35
36 // Use 3d noise to get density of ore placement, instead of just the position
37 #define OREFLAG_DENSITY   0x02 // not yet implemented
38
39 // For claylike ore types, place ore if the number of surrounding
40 // nodes isn't the specified node
41 #define OREFLAG_NODEISNT  0x04 // not yet implemented
42
43 #define ORE_RANGE_ACTUAL 1
44 #define ORE_RANGE_MIRROR 2
45
46
47 enum OreType {
48         ORE_SCATTER,
49         ORE_SHEET,
50         ORE_CLAYLIKE
51 };
52
53 extern FlagDesc flagdesc_ore[];
54
55 class Ore : public GenElement {
56 public:
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 height_min;
63         s16 height_max;
64         u8 ore_param2;          // to set node-specific attributes
65         u32 flags;          // attributes for this ore
66         float nthresh;      // threshhold for noise at which an ore is placed
67         NoiseParams *np;    // noise for distribution of clusters (NULL for uniform scattering)
68         Noise *noise;
69
70         Ore();
71         virtual ~Ore();
72
73         size_t placeOre(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax);
74         virtual void generate(ManualMapVoxelManipulator *vm, int seed,
75                                                 u32 blockseed, v3s16 nmin, v3s16 nmax) = 0;
76 };
77
78 class OreScatter : public Ore {
79         virtual ~OreScatter() {}
80         virtual void generate(ManualMapVoxelManipulator *vm, int seed,
81                                                 u32 blockseed, v3s16 nmin, v3s16 nmax);
82 };
83
84 class OreSheet : public Ore {
85         virtual ~OreSheet() {}
86         virtual void generate(ManualMapVoxelManipulator *vm, int seed,
87                                                 u32 blockseed, v3s16 nmin, v3s16 nmax);
88 };
89
90 class OreManager : public GenElementManager {
91 public:
92         static const char *ELEMENT_TITLE;
93         static const size_t ELEMENT_LIMIT = 0x10000;
94
95         OreManager(IGameDef *gamedef) {}
96         ~OreManager() {}
97
98         Ore *create(int type)
99         {
100                 switch (type) {
101                 case ORE_SCATTER:
102                         return new OreScatter;
103                 case ORE_SHEET:
104                         return new OreSheet;
105                 //case ORE_CLAYLIKE: //TODO: implement this!
106                 //      return new OreClaylike;
107                 default:
108                         return NULL;
109                 }
110         }
111
112         size_t placeAllOres(Mapgen *mg, u32 seed, v3s16 nmin, v3s16 nmax);
113 };
114
115 #endif