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_bloated.h"
24 #include "util/container.h" // UniqueQueue
31 #define DEFAULT_MAPGEN "v6"
33 /////////////////// Mapgen flags
36 #define MG_DUNGEONS 0x04
40 /////////////////// Ore generation flags
41 // Use absolute value of height to determine ore placement
42 #define OREFLAG_ABSHEIGHT 0x01
43 // Use 3d noise to get density of ore placement, instead of just the position
44 #define OREFLAG_DENSITY 0x02 // not yet implemented
45 // For claylike ore types, place ore if the number of surrounding
46 // nodes isn't the specified node
47 #define OREFLAG_NODEISNT 0x04 // not yet implemented
49 /////////////////// Decoration flags
50 #define DECO_PLACE_CENTER_X 1
51 #define DECO_PLACE_CENTER_Y 2
52 #define DECO_PLACE_CENTER_Z 4
54 #define ORE_RANGE_ACTUAL 1
55 #define ORE_RANGE_MIRROR 2
57 #define NUM_GEN_NOTIFY 6
60 extern FlagDesc flagdesc_mapgen[];
61 extern FlagDesc flagdesc_ore[];
62 extern FlagDesc flagdesc_deco_schematic[];
63 extern FlagDesc flagdesc_gennotify[];
65 class BiomeDefManager;
69 class ManualMapVoxelManipulator;
70 class VoxelManipulator;
90 GENNOTIFY_LARGECAVE_BEGIN,
91 GENNOTIFY_LARGECAVE_END
101 struct MapgenSpecificParams {
102 virtual void readParams(Settings *settings) = 0;
103 virtual void writeParams(Settings *settings) = 0;
104 virtual ~MapgenSpecificParams() {}
107 struct MapgenParams {
114 MapgenSpecificParams *sparams;
117 mg_name = DEFAULT_MAPGEN;
121 flags = MG_TREES | MG_CAVES | MG_LIGHT;
132 ManualMapVoxelManipulator *vm;
133 INodeDefManager *ndef;
140 std::vector<v3s16> *gen_notifications[NUM_GEN_NOTIFY];
145 s16 findGroundLevelFull(v2s16 p2d);
146 s16 findGroundLevel(v2s16 p2d, s16 ymin, s16 ymax);
147 void updateHeightmap(v3s16 nmin, v3s16 nmax);
148 void updateLiquid(UniqueQueue<v3s16> *trans_liquid, v3s16 nmin, v3s16 nmax);
149 void setLighting(v3s16 nmin, v3s16 nmax, u8 light);
150 void lightSpread(VoxelArea &a, v3s16 p, u8 light);
151 void calcLighting(v3s16 nmin, v3s16 nmax);
152 void calcLightingOld(v3s16 nmin, v3s16 nmax);
154 virtual void makeChunk(BlockMakeData *data) {}
155 virtual int getGroundLevelAtPoint(v2s16 p) { return 0; }
158 struct MapgenFactory {
159 virtual Mapgen *createMapgen(int mgid, MapgenParams *params,
160 EmergeManager *emerge) = 0;
161 virtual MapgenSpecificParams *createMapgenParams() = 0;
162 virtual ~MapgenFactory() {}
167 std::string ore_name;
168 std::vector<std::string> wherein_names;
170 std::vector<content_t> wherein; // the node to be replaced
171 u32 clust_scarcity; // ore cluster has a 1-in-clust_scarcity chance of appearing at a node
172 s16 clust_num_ores; // how many ore nodes are in a chunk
173 s16 clust_size; // how large (in nodes) a chunk of ore is
176 u8 ore_param2; // to set node-specific attributes
177 u32 flags; // attributes for this ore
178 float nthresh; // threshhold for noise at which an ore is placed
179 NoiseParams *np; // noise for distribution of clusters (NULL for uniform scattering)
183 ore = CONTENT_IGNORE;
190 void resolveNodeNames(INodeDefManager *ndef);
191 void placeOre(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax);
192 virtual void generate(ManualMapVoxelManipulator *vm, int seed,
193 u32 blockseed, v3s16 nmin, v3s16 nmax) = 0;
196 class OreScatter : public Ore {
198 virtual void generate(ManualMapVoxelManipulator *vm, int seed,
199 u32 blockseed, v3s16 nmin, v3s16 nmax);
202 class OreSheet : public Ore {
204 virtual void generate(ManualMapVoxelManipulator *vm, int seed,
205 u32 blockseed, v3s16 nmin, v3s16 nmax);
208 Ore *createOre(OreType type);
211 enum DecorationType {
225 CutoffData(s16 x, s16 y, s16 z, s16 h) {
234 INodeDefManager *ndef;
237 std::string place_on_name;
238 content_t c_place_on;
244 //std::list<CutoffData> cutoffs;
245 //JMutex cutoff_mutex;
248 virtual ~Decoration();
250 virtual void resolveNodeNames(INodeDefManager *ndef);
251 void placeDeco(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax);
252 void placeCutoffs(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax);
254 virtual void generate(Mapgen *mg, PseudoRandom *pr, s16 max_y, v3s16 p) = 0;
255 virtual int getHeight() = 0;
256 virtual std::string getName() = 0;
259 class DecoSimple : public Decoration {
261 std::string deco_name;
262 std::string spawnby_name;
269 std::vector<std::string> decolist_names;
270 std::vector<content_t> c_decolist;
274 void resolveNodeNames(INodeDefManager *ndef);
275 virtual void generate(Mapgen *mg, PseudoRandom *pr, s16 max_y, v3s16 p);
276 virtual int getHeight();
277 virtual std::string getName();
280 #define MTSCHEM_FILE_SIGNATURE 0x4d54534d // 'MTSM'
281 #define MTSCHEM_FILE_VER_HIGHEST_READ 3
282 #define MTSCHEM_FILE_VER_HIGHEST_WRITE 3
284 #define MTSCHEM_PROB_NEVER 0x00
285 #define MTSCHEM_PROB_ALWAYS 0xFF
287 class DecoSchematic : public Decoration {
289 std::string filename;
291 std::vector<std::string> *node_names;
292 std::vector<content_t> c_nodes;
293 std::map<std::string, std::string> replacements;
304 void resolveNodeNames(INodeDefManager *ndef);
305 virtual void generate(Mapgen *mg, PseudoRandom *pr, s16 max_y, v3s16 p);
306 virtual int getHeight();
307 virtual std::string getName();
309 void blitToVManip(v3s16 p, ManualMapVoxelManipulator *vm,
310 Rotation rot, bool force_placement);
312 bool loadSchematicFile();
313 void saveSchematicFile(INodeDefManager *ndef);
315 bool getSchematicFromMap(Map *map, v3s16 p1, v3s16 p2);
316 void placeStructure(Map *map, v3s16 p);
317 void applyProbabilities(v3s16 p0,
318 std::vector<std::pair<v3s16, u8> > *plist,
319 std::vector<std::pair<s16, u8> > *splist);
322 void build_nnlist_and_update_ids(MapNode *nodes, u32 nodecount,
323 std::vector<content_t> *usednodes);
326 class DecoLSystem : public Decoration {
328 virtual void generate(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax);
332 Decoration *createDecoration(DecorationType type);