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
53 #define DECO_SCHEM_CIDS_UPDATED 8
55 #define ORE_RANGE_ACTUAL 1
56 #define ORE_RANGE_MIRROR 2
58 #define NUM_GEN_NOTIFY 6
61 extern FlagDesc flagdesc_mapgen[];
62 extern FlagDesc flagdesc_ore[];
63 extern FlagDesc flagdesc_deco_schematic[];
64 extern FlagDesc flagdesc_gennotify[];
66 class BiomeDefManager;
70 class ManualMapVoxelManipulator;
71 class VoxelManipulator;
91 GENNOTIFY_LARGECAVE_BEGIN,
92 GENNOTIFY_LARGECAVE_END
102 struct MapgenSpecificParams {
103 virtual void readParams(Settings *settings) = 0;
104 virtual void writeParams(Settings *settings) = 0;
105 virtual ~MapgenSpecificParams() {}
108 struct MapgenParams {
115 MapgenSpecificParams *sparams;
118 mg_name = DEFAULT_MAPGEN;
122 flags = MG_TREES | MG_CAVES | MG_LIGHT;
133 ManualMapVoxelManipulator *vm;
134 INodeDefManager *ndef;
141 std::vector<v3s16> *gen_notifications[NUM_GEN_NOTIFY];
146 s16 findGroundLevelFull(v2s16 p2d);
147 s16 findGroundLevel(v2s16 p2d, s16 ymin, s16 ymax);
148 void updateHeightmap(v3s16 nmin, v3s16 nmax);
149 void updateLiquid(UniqueQueue<v3s16> *trans_liquid, v3s16 nmin, v3s16 nmax);
150 void setLighting(v3s16 nmin, v3s16 nmax, u8 light);
151 void lightSpread(VoxelArea &a, v3s16 p, u8 light);
152 void calcLighting(v3s16 nmin, v3s16 nmax);
153 void calcLightingOld(v3s16 nmin, v3s16 nmax);
155 virtual void makeChunk(BlockMakeData *data) {}
156 virtual int getGroundLevelAtPoint(v2s16 p) { return 0; }
159 struct MapgenFactory {
160 virtual Mapgen *createMapgen(int mgid, MapgenParams *params,
161 EmergeManager *emerge) = 0;
162 virtual MapgenSpecificParams *createMapgenParams() = 0;
163 virtual ~MapgenFactory() {}
168 content_t c_ore; // the node to place
169 std::vector<content_t> c_wherein; // the nodes to be placed in
170 u32 clust_scarcity; // ore cluster has a 1-in-clust_scarcity chance of appearing at a node
171 s16 clust_num_ores; // how many ore nodes are in a chunk
172 s16 clust_size; // how large (in nodes) a chunk of ore is
175 u8 ore_param2; // to set node-specific attributes
176 u32 flags; // attributes for this ore
177 float nthresh; // threshhold for noise at which an ore is placed
178 NoiseParams *np; // noise for distribution of clusters (NULL for uniform scattering)
182 c_ore = CONTENT_IGNORE;
189 void placeOre(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax);
190 virtual void generate(ManualMapVoxelManipulator *vm, int seed,
191 u32 blockseed, v3s16 nmin, v3s16 nmax) = 0;
194 class OreScatter : public Ore {
196 virtual void generate(ManualMapVoxelManipulator *vm, int seed,
197 u32 blockseed, v3s16 nmin, v3s16 nmax);
200 class OreSheet : public Ore {
202 virtual void generate(ManualMapVoxelManipulator *vm, int seed,
203 u32 blockseed, v3s16 nmin, v3s16 nmax);
206 Ore *createOre(OreType type);
209 enum DecorationType {
223 CutoffData(s16 x, s16 y, s16 z, s16 h) {
232 INodeDefManager *ndef;
235 std::vector<content_t> c_place_on;
241 //std::list<CutoffData> cutoffs;
242 //JMutex cutoff_mutex;
245 virtual ~Decoration();
247 void placeDeco(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax);
248 void placeCutoffs(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax);
250 virtual void generate(Mapgen *mg, PseudoRandom *pr, s16 max_y, v3s16 p) = 0;
251 virtual int getHeight() = 0;
252 virtual std::string getName() = 0;
255 class DecoSimple : public Decoration {
257 std::vector<content_t> c_decos;
258 std::vector<content_t> c_spawnby;
265 bool canPlaceDecoration(ManualMapVoxelManipulator *vm, v3s16 p);
266 virtual void generate(Mapgen *mg, PseudoRandom *pr, s16 max_y, v3s16 p);
267 virtual int getHeight();
268 virtual std::string getName();
271 #define MTSCHEM_FILE_SIGNATURE 0x4d54534d // 'MTSM'
272 #define MTSCHEM_FILE_VER_HIGHEST_READ 3
273 #define MTSCHEM_FILE_VER_HIGHEST_WRITE 3
275 #define MTSCHEM_PROB_NEVER 0x00
276 #define MTSCHEM_PROB_ALWAYS 0xFF
278 class DecoSchematic : public Decoration {
280 std::string filename;
282 std::vector<content_t> c_nodes;
293 void updateContentIds();
294 virtual void generate(Mapgen *mg, PseudoRandom *pr, s16 max_y, v3s16 p);
295 virtual int getHeight();
296 virtual std::string getName();
298 void blitToVManip(v3s16 p, ManualMapVoxelManipulator *vm,
299 Rotation rot, bool force_placement);
301 bool loadSchematicFile(NodeResolver *resolver,
302 std::map<std::string, std::string> &replace_names);
303 void saveSchematicFile(INodeDefManager *ndef);
305 bool getSchematicFromMap(Map *map, v3s16 p1, v3s16 p2);
306 void placeStructure(Map *map, v3s16 p, bool force_placement);
307 void applyProbabilities(v3s16 p0,
308 std::vector<std::pair<v3s16, u8> > *plist,
309 std::vector<std::pair<s16, u8> > *splist);
312 void build_nnlist_and_update_ids(MapNode *nodes, u32 nodecount,
313 std::vector<content_t> *usednodes);
316 class DecoLSystem : public Decoration {
318 virtual void generate(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax);
322 Decoration *createDecoration(DecorationType type);