]> git.lizzy.rs Git - dragonfireclient.git/blob - src/mapgen.h
Remove use of operator[] on a std::map, so no spurious elements get inserted. (fixes...
[dragonfireclient.git] / src / mapgen.h
1 /*
2 Minetest-c55
3 Copyright (C) 2010-2011 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_FORESTS     0x08
36 #define MGV6_BIOME_BLEND 0x10
37
38 class BiomeDefManager;
39 class Biome;
40 class EmergeManager;
41 class MapBlock;
42 class ManualMapVoxelManipulator;
43 class VoxelManipulator;
44 class INodeDefManager;
45
46 struct BlockMakeData {
47         bool no_op;
48         ManualMapVoxelManipulator *vmanip;
49         u64 seed;
50         v3s16 blockpos_min;
51         v3s16 blockpos_max;
52         v3s16 blockpos_requested;
53         UniqueQueue<v3s16> transforming_liquid;
54         INodeDefManager *nodedef;
55
56         BlockMakeData();
57         ~BlockMakeData();
58 };
59
60 struct MapgenParams {
61         std::string mg_name;
62         int chunksize;
63         u64 seed;
64         int water_level;
65         u32 flags;
66
67         MapgenParams() {
68                 mg_name     = "v6";
69                 seed        = 0;
70                 water_level = 1;
71                 chunksize   = 5;
72                 flags       = MG_TREES | MG_CAVES | MGV6_BIOME_BLEND;
73         }
74         
75         virtual bool readParams(Settings *settings) = 0;
76         virtual void writeParams(Settings *settings) {};
77 };
78
79 class Mapgen {
80 public:
81         int seed;
82         int water_level;
83         bool generating;
84         int id;
85
86         virtual void makeChunk(BlockMakeData *data) {};
87         virtual int getGroundLevelAtPoint(v2s16 p) = 0;
88
89         //Legacy functions for Farmesh (pending removal)
90         static bool get_have_beach(u64 seed, v2s16 p2d);
91         static double tree_amount_2d(u64 seed, v2s16 p);
92         static s16 find_ground_level_from_noise(u64 seed, v2s16 p2d, s16 precision);
93 };
94
95 struct MapgenFactory {
96         virtual Mapgen *createMapgen(int mgid, MapgenParams *params,
97                                                                  EmergeManager *emerge) = 0;
98         virtual MapgenParams *createMapgenParams() = 0;
99 };
100
101 class EmergeManager {
102 public:
103         std::map<std::string, MapgenFactory *> mglist;
104
105         //settings
106         MapgenParams *params;
107
108         //mapgen objects here
109         Mapgen *mapgen;
110
111         //biome manager
112         BiomeDefManager *biomedef;
113
114         EmergeManager(IGameDef *gamedef, BiomeDefManager *bdef);
115         ~EmergeManager();
116
117         void initMapgens(MapgenParams *mgparams);
118         Mapgen *createMapgen(std::string mgname, int mgid,
119                                                 MapgenParams *mgparams, EmergeManager *emerge);
120         MapgenParams *createMapgenParams(std::string mgname);
121         Mapgen *getMapgen();
122         void addBlockToQueue();
123         
124         bool registerMapgen(std::string name, MapgenFactory *mgfactory);
125         MapgenParams *getParamsFromSettings(Settings *settings);
126         
127         //mapgen helper methods
128         Biome *getBiomeAtPoint(v3s16 p);
129         int getGroundLevelAtPoint(v2s16 p);
130         bool isBlockUnderground(v3s16 blockpos);
131         u32 getBlockSeed(v3s16 p);
132 };
133
134 #endif
135