mapgen.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. /*
  2. Minetest
  3. Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU Lesser General Public License as published by
  6. the Free Software Foundation; either version 2.1 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public License along
  13. with this program; if not, write to the Free Software Foundation, Inc.,
  14. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  15. */
  16. #ifndef MAPGEN_HEADER
  17. #define MAPGEN_HEADER
  18. #include "irrlichttypes_bloated.h"
  19. #include "util/container.h" // UniqueQueue
  20. #include "gamedef.h"
  21. #include "nodedef.h"
  22. #include "mapnode.h"
  23. #include "noise.h"
  24. #include "settings.h"
  25. #define DEFAULT_MAPGEN "v6"
  26. /////////////////// Mapgen flags
  27. #define MG_TREES 0x01
  28. #define MG_CAVES 0x02
  29. #define MG_DUNGEONS 0x04
  30. #define MG_FLAT 0x08
  31. #define MG_LIGHT 0x10
  32. /////////////////// Ore generation flags
  33. // Use absolute value of height to determine ore placement
  34. #define OREFLAG_ABSHEIGHT 0x01
  35. // Use 3d noise to get density of ore placement, instead of just the position
  36. #define OREFLAG_DENSITY 0x02 // not yet implemented
  37. // For claylike ore types, place ore if the number of surrounding
  38. // nodes isn't the specified node
  39. #define OREFLAG_NODEISNT 0x04 // not yet implemented
  40. /////////////////// Decoration flags
  41. #define DECO_PLACE_CENTER_X 1
  42. #define DECO_PLACE_CENTER_Y 2
  43. #define DECO_PLACE_CENTER_Z 4
  44. #define ORE_RANGE_ACTUAL 1
  45. #define ORE_RANGE_MIRROR 2
  46. #define NUM_GEN_NOTIFY 6
  47. extern FlagDesc flagdesc_mapgen[];
  48. extern FlagDesc flagdesc_ore[];
  49. extern FlagDesc flagdesc_deco_schematic[];
  50. extern FlagDesc flagdesc_gennotify[];
  51. class BiomeDefManager;
  52. class Biome;
  53. class EmergeManager;
  54. class MapBlock;
  55. class ManualMapVoxelManipulator;
  56. class VoxelManipulator;
  57. struct BlockMakeData;
  58. class VoxelArea;
  59. class Map;
  60. enum MapgenObject {
  61. MGOBJ_VMANIP,
  62. MGOBJ_HEIGHTMAP,
  63. MGOBJ_BIOMEMAP,
  64. MGOBJ_HEATMAP,
  65. MGOBJ_HUMIDMAP,
  66. MGOBJ_GENNOTIFY
  67. };
  68. enum GenNotify {
  69. GENNOTIFY_DUNGEON,
  70. GENNOTIFY_TEMPLE,
  71. GENNOTIFY_CAVE_BEGIN,
  72. GENNOTIFY_CAVE_END,
  73. GENNOTIFY_LARGECAVE_BEGIN,
  74. GENNOTIFY_LARGECAVE_END
  75. };
  76. enum OreType {
  77. ORE_SCATTER,
  78. ORE_SHEET,
  79. ORE_CLAYLIKE
  80. };
  81. struct MapgenSpecificParams {
  82. virtual void readParams(Settings *settings) = 0;
  83. virtual void writeParams(Settings *settings) = 0;
  84. virtual ~MapgenSpecificParams() {}
  85. };
  86. struct MapgenParams {
  87. std::string mg_name;
  88. int chunksize;
  89. u64 seed;
  90. int water_level;
  91. u32 flags;
  92. MapgenSpecificParams *sparams;
  93. MapgenParams() {
  94. mg_name = DEFAULT_MAPGEN;
  95. seed = 0;
  96. water_level = 1;
  97. chunksize = 5;
  98. flags = MG_TREES | MG_CAVES | MG_LIGHT;
  99. sparams = NULL;
  100. }
  101. };
  102. class Mapgen {
  103. public:
  104. int seed;
  105. int water_level;
  106. bool generating;
  107. int id;
  108. ManualMapVoxelManipulator *vm;
  109. INodeDefManager *ndef;
  110. s16 *heightmap;
  111. u8 *biomemap;
  112. v3s16 csize;
  113. u32 gennotify;
  114. std::vector<v3s16> *gen_notifications[NUM_GEN_NOTIFY];
  115. Mapgen();
  116. virtual ~Mapgen();
  117. s16 findGroundLevelFull(v2s16 p2d);
  118. s16 findGroundLevel(v2s16 p2d, s16 ymin, s16 ymax);
  119. void updateHeightmap(v3s16 nmin, v3s16 nmax);
  120. void updateLiquid(UniqueQueue<v3s16> *trans_liquid, v3s16 nmin, v3s16 nmax);
  121. void setLighting(v3s16 nmin, v3s16 nmax, u8 light);
  122. void lightSpread(VoxelArea &a, v3s16 p, u8 light);
  123. void calcLighting(v3s16 nmin, v3s16 nmax);
  124. void calcLightingOld(v3s16 nmin, v3s16 nmax);
  125. virtual void makeChunk(BlockMakeData *data) {}
  126. virtual int getGroundLevelAtPoint(v2s16 p) { return 0; }
  127. };
  128. struct MapgenFactory {
  129. virtual Mapgen *createMapgen(int mgid, MapgenParams *params,
  130. EmergeManager *emerge) = 0;
  131. virtual MapgenSpecificParams *createMapgenParams() = 0;
  132. virtual ~MapgenFactory() {}
  133. };
  134. class Ore {
  135. public:
  136. std::string ore_name;
  137. std::vector<std::string> wherein_names;
  138. content_t ore;
  139. std::vector<content_t> wherein; // the node to be replaced
  140. u32 clust_scarcity; // ore cluster has a 1-in-clust_scarcity chance of appearing at a node
  141. s16 clust_num_ores; // how many ore nodes are in a chunk
  142. s16 clust_size; // how large (in nodes) a chunk of ore is
  143. s16 height_min;
  144. s16 height_max;
  145. u8 ore_param2; // to set node-specific attributes
  146. u32 flags; // attributes for this ore
  147. float nthresh; // threshhold for noise at which an ore is placed
  148. NoiseParams *np; // noise for distribution of clusters (NULL for uniform scattering)
  149. Noise *noise;
  150. Ore() {
  151. ore = CONTENT_IGNORE;
  152. np = NULL;
  153. noise = NULL;
  154. }
  155. virtual ~Ore();
  156. void resolveNodeNames(INodeDefManager *ndef);
  157. void placeOre(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax);
  158. virtual void generate(ManualMapVoxelManipulator *vm, int seed,
  159. u32 blockseed, v3s16 nmin, v3s16 nmax) = 0;
  160. };
  161. class OreScatter : public Ore {
  162. ~OreScatter() {}
  163. virtual void generate(ManualMapVoxelManipulator *vm, int seed,
  164. u32 blockseed, v3s16 nmin, v3s16 nmax);
  165. };
  166. class OreSheet : public Ore {
  167. ~OreSheet() {}
  168. virtual void generate(ManualMapVoxelManipulator *vm, int seed,
  169. u32 blockseed, v3s16 nmin, v3s16 nmax);
  170. };
  171. Ore *createOre(OreType type);
  172. enum DecorationType {
  173. DECO_SIMPLE = 1,
  174. DECO_SCHEMATIC,
  175. DECO_LSYSTEM
  176. };
  177. #if 0
  178. struct CutoffData {
  179. VoxelArea a;
  180. Decoration *deco;
  181. //v3s16 p;
  182. //v3s16 size;
  183. //s16 height;
  184. CutoffData(s16 x, s16 y, s16 z, s16 h) {
  185. p = v3s16(x, y, z);
  186. height = h;
  187. }
  188. };
  189. #endif
  190. class Decoration {
  191. public:
  192. INodeDefManager *ndef;
  193. int mapseed;
  194. std::string place_on_name;
  195. content_t c_place_on;
  196. s16 sidelen;
  197. float fill_ratio;
  198. NoiseParams *np;
  199. std::set<u8> biomes;
  200. //std::list<CutoffData> cutoffs;
  201. //JMutex cutoff_mutex;
  202. Decoration();
  203. virtual ~Decoration();
  204. virtual void resolveNodeNames(INodeDefManager *ndef);
  205. void placeDeco(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax);
  206. void placeCutoffs(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax);
  207. virtual void generate(Mapgen *mg, PseudoRandom *pr, s16 max_y, v3s16 p) = 0;
  208. virtual int getHeight() = 0;
  209. virtual std::string getName() = 0;
  210. };
  211. class DecoSimple : public Decoration {
  212. public:
  213. std::string deco_name;
  214. std::string spawnby_name;
  215. content_t c_deco;
  216. content_t c_spawnby;
  217. s16 deco_height;
  218. s16 deco_height_max;
  219. s16 nspawnby;
  220. std::vector<std::string> decolist_names;
  221. std::vector<content_t> c_decolist;
  222. ~DecoSimple() {}
  223. void resolveNodeNames(INodeDefManager *ndef);
  224. virtual void generate(Mapgen *mg, PseudoRandom *pr, s16 max_y, v3s16 p);
  225. virtual int getHeight();
  226. virtual std::string getName();
  227. };
  228. #define MTSCHEM_FILE_SIGNATURE 0x4d54534d // 'MTSM'
  229. #define MTSCHEM_FILE_VER_HIGHEST_READ 3
  230. #define MTSCHEM_FILE_VER_HIGHEST_WRITE 3
  231. #define MTSCHEM_PROB_NEVER 0x00
  232. #define MTSCHEM_PROB_ALWAYS 0xFF
  233. class DecoSchematic : public Decoration {
  234. public:
  235. std::string filename;
  236. std::vector<std::string> *node_names;
  237. std::vector<content_t> c_nodes;
  238. std::map<std::string, std::string> replacements;
  239. u32 flags;
  240. Rotation rotation;
  241. v3s16 size;
  242. MapNode *schematic;
  243. u8 *slice_probs;
  244. DecoSchematic();
  245. ~DecoSchematic();
  246. void resolveNodeNames(INodeDefManager *ndef);
  247. virtual void generate(Mapgen *mg, PseudoRandom *pr, s16 max_y, v3s16 p);
  248. virtual int getHeight();
  249. virtual std::string getName();
  250. void blitToVManip(v3s16 p, ManualMapVoxelManipulator *vm,
  251. Rotation rot, bool force_placement);
  252. bool loadSchematicFile();
  253. void saveSchematicFile(INodeDefManager *ndef);
  254. bool getSchematicFromMap(Map *map, v3s16 p1, v3s16 p2);
  255. void placeStructure(Map *map, v3s16 p, bool force_placement);
  256. void applyProbabilities(v3s16 p0,
  257. std::vector<std::pair<v3s16, u8> > *plist,
  258. std::vector<std::pair<s16, u8> > *splist);
  259. };
  260. void build_nnlist_and_update_ids(MapNode *nodes, u32 nodecount,
  261. std::vector<content_t> *usednodes);
  262. /*
  263. class DecoLSystem : public Decoration {
  264. public:
  265. virtual void generate(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax);
  266. };
  267. */
  268. Decoration *createDecoration(DecorationType type);
  269. #endif