3 Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
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.
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.
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.
23 #include "irrlichttypes_extrabloated.h"
24 #include "util/container.h" // UniqueQueue
31 /////////////////// Mapgen flags
34 #define MG_DUNGEONS 0x04
35 #define MGV6_JUNGLES 0x08
36 #define MGV6_BIOME_BLEND 0x10
38 #define MG_NOLIGHT 0x40
39 #define MGV7_MOUNTAINS 0x80
40 #define MGV7_RIDGES 0x100
42 /////////////////// Ore generation flags
43 // Use absolute value of height to determine ore placement
44 #define OREFLAG_ABSHEIGHT 0x01
45 // Use 3d noise to get density of ore placement, instead of just the position
46 #define OREFLAG_DENSITY 0x02 // not yet implemented
47 // For claylike ore types, place ore if the number of surrounding
48 // nodes isn't the specified node
49 #define OREFLAG_NODEISNT 0x04 // not yet implemented
51 /////////////////// Decoration flags
52 #define DECO_PLACE_CENTER_X 1
53 #define DECO_PLACE_CENTER_Y 2
54 #define DECO_PLACE_CENTER_Z 4
56 extern FlagDesc flagdesc_mapgen[];
57 extern FlagDesc flagdesc_ore[];
58 extern FlagDesc flagdesc_deco_schematic[];
60 class BiomeDefManager;
64 class ManualMapVoxelManipulator;
65 class VoxelManipulator;
82 flags = MG_TREES | MG_CAVES | MGV6_BIOME_BLEND;
85 virtual bool readParams(Settings *settings) { return true; }
86 virtual void writeParams(Settings *settings) {}
87 virtual ~MapgenParams() {}
96 ManualMapVoxelManipulator *vm;
97 INodeDefManager *ndef;
106 s16 findGroundLevelFull(v2s16 p2d);
107 s16 findGroundLevel(v2s16 p2d, s16 ymin, s16 ymax);
108 void updateHeightmap(v3s16 nmin, v3s16 nmax);
109 void updateLiquid(UniqueQueue<v3s16> *trans_liquid, v3s16 nmin, v3s16 nmax);
110 void setLighting(v3s16 nmin, v3s16 nmax, u8 light);
111 void lightSpread(VoxelArea &a, v3s16 p, u8 light);
112 void calcLighting(v3s16 nmin, v3s16 nmax);
113 void calcLightingOld(v3s16 nmin, v3s16 nmax);
115 virtual void makeChunk(BlockMakeData *data) {}
116 virtual int getGroundLevelAtPoint(v2s16 p) { return 0; }
119 struct MapgenFactory {
120 virtual Mapgen *createMapgen(int mgid, MapgenParams *params,
121 EmergeManager *emerge) = 0;
122 virtual MapgenParams *createMapgenParams() = 0;
123 virtual ~MapgenFactory() {}
140 #define ORE_RANGE_ACTUAL 1
141 #define ORE_RANGE_MIRROR 2
145 std::string ore_name;
146 std::vector<std::string> wherein_names;
148 std::vector<content_t> wherein; // the node to be replaced
149 u32 clust_scarcity; // ore cluster has a 1-in-clust_scarcity chance of appearing at a node
150 s16 clust_num_ores; // how many ore nodes are in a chunk
151 s16 clust_size; // how large (in nodes) a chunk of ore is
154 u8 ore_param2; // to set node-specific attributes
155 u32 flags; // attributes for this ore
156 float nthresh; // threshhold for noise at which an ore is placed
157 NoiseParams *np; // noise for distribution of clusters (NULL for uniform scattering)
161 ore = CONTENT_IGNORE;
168 void resolveNodeNames(INodeDefManager *ndef);
169 void placeOre(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax);
170 virtual void generate(ManualMapVoxelManipulator *vm, int seed,
171 u32 blockseed, v3s16 nmin, v3s16 nmax) = 0;
174 class OreScatter : public Ore {
176 virtual void generate(ManualMapVoxelManipulator *vm, int seed,
177 u32 blockseed, v3s16 nmin, v3s16 nmax);
180 class OreSheet : public Ore {
182 virtual void generate(ManualMapVoxelManipulator *vm, int seed,
183 u32 blockseed, v3s16 nmin, v3s16 nmax);
186 Ore *createOre(OreType type);
189 enum DecorationType {
203 CutoffData(s16 x, s16 y, s16 z, s16 h) {
212 INodeDefManager *ndef;
215 std::string place_on_name;
216 content_t c_place_on;
222 //std::list<CutoffData> cutoffs;
223 //JMutex cutoff_mutex;
226 virtual ~Decoration();
228 virtual void resolveNodeNames(INodeDefManager *ndef);
229 void placeDeco(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax);
230 void placeCutoffs(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax);
232 virtual void generate(Mapgen *mg, PseudoRandom *pr, s16 max_y, v3s16 p) = 0;
233 virtual int getHeight() = 0;
234 virtual std::string getName() = 0;
237 class DecoSimple : public Decoration {
239 std::string deco_name;
240 std::string spawnby_name;
247 std::vector<std::string> decolist_names;
248 std::vector<content_t> c_decolist;
252 void resolveNodeNames(INodeDefManager *ndef);
253 virtual void generate(Mapgen *mg, PseudoRandom *pr, s16 max_y, v3s16 p);
254 virtual int getHeight();
255 virtual std::string getName();
258 #define MTSCHEM_FILE_SIGNATURE 0x4d54534d // 'MTSM'
259 #define MTSCHEM_PROB_NEVER 0x00
260 #define MTSCHEM_PROB_ALWAYS 0xFF
262 class DecoSchematic : public Decoration {
264 std::string filename;
266 std::vector<std::string> *node_names;
267 std::vector<content_t> c_nodes;
268 std::map<std::string, std::string> replacements;
278 void resolveNodeNames(INodeDefManager *ndef);
279 virtual void generate(Mapgen *mg, PseudoRandom *pr, s16 max_y, v3s16 p);
280 virtual int getHeight();
281 virtual std::string getName();
283 void blitToVManip(v3s16 p, ManualMapVoxelManipulator *vm,
284 Rotation rot, bool force_placement);
286 bool loadSchematicFile();
287 void saveSchematicFile(INodeDefManager *ndef);
289 bool getSchematicFromMap(Map *map, v3s16 p1, v3s16 p2);
290 void placeStructure(Map *map, v3s16 p);
291 void applyProbabilities(std::vector<std::pair<v3s16, u8> > *plist, v3s16 p0);
294 void build_nnlist_and_update_ids(MapNode *nodes, u32 nodecount,
295 std::vector<content_t> *usednodes);
298 class DecoLSystem : public Decoration {
300 virtual void generate(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax);
304 Decoration *createDecoration(DecorationType type);