Add Ore infrastructure and l_register_ore()
[oweals/minetest.git] / src / mapgen.h
1 /*
2 Minetest
3 Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
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 MAPGEN_HEADER
21 #define MAPGEN_HEADER
22
23 #include "irrlichttypes_extrabloated.h"
24 #include "util/container.h" // UniqueQueue
25 #include "gamedef.h"
26 #include "mapnode.h"
27 #include "noise.h"
28 #include "settings.h"
29 #include <map>
30
31 /////////////////// Mapgen flags
32 #define MG_TREES         0x01
33 #define MG_CAVES         0x02
34 #define MG_DUNGEONS      0x04
35 #define MGV6_JUNGLES     0x08
36 #define MGV6_BIOME_BLEND 0x10
37 #define MG_FLAT          0x20
38
39 extern FlagDesc flagdesc_mapgen[];
40
41 class BiomeDefManager;
42 class Biome;
43 class EmergeManager;
44 class MapBlock;
45 class ManualMapVoxelManipulator;
46 class VoxelManipulator;
47 class INodeDefManager;
48 struct BlockMakeData;
49 class VoxelArea;
50
51 struct MapgenParams {
52         std::string mg_name;
53         int chunksize;
54         u64 seed;
55         int water_level;
56         u32 flags;
57
58         MapgenParams() {
59                 mg_name     = "v6";
60                 seed        = 0;
61                 water_level = 1;
62                 chunksize   = 5;
63                 flags       = MG_TREES | MG_CAVES | MGV6_BIOME_BLEND;
64         }
65         
66         virtual bool readParams(Settings *settings) = 0;
67         virtual void writeParams(Settings *settings) {};
68 };
69
70 class Mapgen {
71 public:
72         int seed;
73         int water_level;
74         bool generating;
75         int id;
76         ManualMapVoxelManipulator *vm;
77         INodeDefManager *ndef;
78
79         void updateLiquid(UniqueQueue<v3s16> *trans_liquid, v3s16 nmin, v3s16 nmax);
80         void setLighting(v3s16 nmin, v3s16 nmax, u8 light);
81         void lightSpread(VoxelArea &a, v3s16 p, u8 light);
82         void calcLighting(v3s16 nmin, v3s16 nmax);
83         void calcLightingOld(v3s16 nmin, v3s16 nmax);
84
85         virtual void makeChunk(BlockMakeData *data) {};
86         virtual int getGroundLevelAtPoint(v2s16 p) = 0;
87
88         //Legacy functions for Farmesh (pending removal)
89         static bool get_have_beach(u64 seed, v2s16 p2d);
90         static double tree_amount_2d(u64 seed, v2s16 p);
91         static s16 find_ground_level_from_noise(u64 seed, v2s16 p2d, s16 precision);
92 };
93
94 struct MapgenFactory {
95         virtual Mapgen *createMapgen(int mgid, MapgenParams *params,
96                                                                  EmergeManager *emerge) = 0;
97         virtual MapgenParams *createMapgenParams() = 0;
98 };
99
100 enum OreType {
101         ORE_SCATTER,
102         ORE_SHEET,
103         ORE_CLAYLIKE
104 };
105
106 class Ore {
107 public:
108         std::string ore_name;
109         std::string wherein_name;
110
111         content_t ore;
112         content_t wherein;  // the node to be replaced
113         s16 clust_scarcity; //
114         s16 clust_num_ores; // how many ore nodes are in a chunk
115         s16 clust_size;     // how large (in nodes) a chunk of ore is
116         s16 height_min;
117         s16 height_max;
118         float nthresh;      // threshhold for noise at which an ore is placed 
119         NoiseParams *np;    // noise for distribution of clusters (NULL for uniform scattering)
120         Noise *noise;
121         
122         Ore() {
123                 ore     = CONTENT_IGNORE;
124                 wherein = CONTENT_IGNORE;
125                 np      = NULL;
126                 noise   = NULL;
127         }
128         
129         void resolveNodeNames(INodeDefManager *ndef);
130         virtual void generate(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax) = 0;
131 };
132
133 class OreScatter : public Ore {
134          void generate(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax);
135 };
136
137 class OreSheet : public Ore {
138         void generate(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax);
139 };
140
141 Ore *createOre(OreType type);
142
143 #endif
144