generator.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. #ifndef GENERATOR_H_
  2. #define GENERATOR_H_
  3. #include "layers.h"
  4. /* Minecraft versions */
  5. enum MCversion
  6. {
  7. MC_1_7, MC_1_8, MC_1_9, MC_1_10, MC_1_11, MC_1_12, MC_1_13, MC_1_14,
  8. MC_1_15, MC_1_16,
  9. MC_BE = 128
  10. };
  11. /* Enumeration of the layer indices in the generator. */
  12. enum
  13. {
  14. L_ISLAND_4096 = 0,
  15. L_ZOOM_2048,
  16. L_ADD_ISLAND_2048,
  17. L_ZOOM_1024,
  18. L_ADD_ISLAND_1024A,
  19. L_ADD_ISLAND_1024B,
  20. L_ADD_ISLAND_1024C,
  21. L_REMOVE_OCEAN_1024,
  22. L_ADD_SNOW_1024,
  23. L_ADD_ISLAND_1024D,
  24. L_COOL_WARM_1024,
  25. L_HEAT_ICE_1024,
  26. L_SPECIAL_1024, /* Good entry for: temperature categories */
  27. L_ZOOM_512,
  28. L_ZOOM_256,
  29. L_ADD_ISLAND_256,
  30. L_ADD_MUSHROOM_256, /* Good entry for: mushroom biomes */
  31. L_DEEP_OCEAN_256,
  32. L_BIOME_256, /* Good entry for: major biome types */
  33. L_ZOOM_128,
  34. L_ZOOM_64,
  35. L_BIOME_EDGE_64,
  36. L_RIVER_INIT_256,
  37. L_ZOOM_128_HILLS,
  38. L_ZOOM_64_HILLS,
  39. L_HILLS_64, /* Good entry for: minor biome types */
  40. L_RARE_BIOME_64,
  41. L_ZOOM_32,
  42. L_ADD_ISLAND_32,
  43. L_ZOOM_16,
  44. L_SHORE_16,
  45. L_ZOOM_8,
  46. L_ZOOM_4,
  47. L_SMOOTH_4,
  48. L_ZOOM_128_RIVER,
  49. L_ZOOM_64_RIVER,
  50. L_ZOOM_32_RIVER,
  51. L_ZOOM_16_RIVER,
  52. L_ZOOM_8_RIVER,
  53. L_ZOOM_4_RIVER,
  54. L_RIVER_4,
  55. L_SMOOTH_4_RIVER,
  56. L_RIVER_MIX_4,
  57. L_VORONOI_ZOOM_1,
  58. // 1.13 layers
  59. L13_OCEAN_TEMP_256,
  60. L13_ZOOM_128,
  61. L13_ZOOM_64,
  62. L13_ZOOM_32,
  63. L13_ZOOM_16,
  64. L13_ZOOM_8,
  65. L13_ZOOM_4,
  66. L13_OCEAN_MIX_4,
  67. // 1.14 layers
  68. L14_BAMBOO_256,
  69. // largeBiomes layers
  70. L_ZOOM_LARGE_BIOME_A,
  71. L_ZOOM_LARGE_BIOME_B,
  72. L_NUM
  73. };
  74. STRUCT(LayerStack)
  75. {
  76. Layer layers[L_NUM];
  77. Layer *entry_1; // entry layer, scale (1:1) [L_VORONOI_ZOOM_1]
  78. Layer *entry_4; // entry layer, scale (1:4) [L_RIVER_MIX_4|L13_OCEAN_MIX_4]
  79. OceanRnd oceanRnd;
  80. };
  81. typedef int (*mapfunc_t)(const Layer *, int *, int, int, int, int);
  82. #ifdef __cplusplus
  83. extern "C"
  84. {
  85. #endif
  86. /* Initialise an instance of a generator. */
  87. void setupGenerator(LayerStack *g, int mcversion);
  88. /* Initialise an instance of a generator with largeBiomes configuration. */
  89. void setupLargeBiomesGenerator(LayerStack *g, int mcversion);
  90. /* Calculates the minimum size of the buffers required to generate an area of
  91. * dimensions 'sizeX' by 'sizeZ' at the specified layer.
  92. */
  93. int calcRequiredBuf(const Layer *layer, int areaX, int areaZ);
  94. /* Allocates an amount of memory required to generate an area of dimensions
  95. * 'sizeX' by 'sizeZ' for the magnification of the given layer.
  96. */
  97. int *allocCache(const Layer *layer, int sizeX, int sizeZ);
  98. /* Set up custom layers. */
  99. void setupLayer(Layer *l, Layer *p, int s, mapfunc_t getMap);
  100. void setupMultiLayer(Layer *l, Layer *p1, Layer *p2, int s, mapfunc_t getMap);
  101. /* Sets the world seed for the generator */
  102. void applySeed(LayerStack *g, int64_t seed);
  103. /* Generates the specified area using the current generator settings and stores
  104. * the biomeIDs in 'out'.
  105. * The biomeIDs will be indexed in the form: out[x + z*areaWidth]
  106. * It is recommended that 'out' is allocated using allocCache() for the correct
  107. * buffer size.
  108. */
  109. int genArea(const Layer *layer, int *out, int areaX, int areaZ, int areaWidth, int areaHeight);
  110. /******************************** BIOME TABLES *********************************
  111. * The biome tables below are lists of the biomes that can be present at some
  112. * notable layers. Of cause, layers that are applied later in the hierarchy will
  113. * also contain these biomes.
  114. */
  115. //==============================================================================
  116. // MC 1.13 Biome Tables
  117. //==============================================================================
  118. static const int BIOMES_L13_OCEAN_TEMP_256[] =
  119. {
  120. ocean, frozen_ocean, warm_ocean, lukewarm_ocean, cold_ocean
  121. };
  122. static const int BIOMES_L13_OCEAN_MIX_4[] =
  123. {
  124. ocean, plains, desert, mountains, forest, taiga, swamp, river, /*hell, sky,*/ // 0-9
  125. frozen_ocean, frozen_river, snowy_tundra, snowy_mountains, mushroom_fields, mushroom_field_shore, beach, desert_hills, wooded_hills, taiga_hills, // 10-19
  126. /*mountain_edge,*/ jungle, jungle_hills, jungleEdge, deep_ocean, stone_shore, snowy_beach, birch_forest, birch_forest_hills, dark_forest, // 20-29
  127. snowy_taiga, snowy_taiga_hills, giant_tree_taiga, giant_tree_taiga_hills, wooded_mountains, savanna, savanna_plateau, badlands, wooded_badlands_plateau, badlands_plateau, // 30-39
  128. /*skyIslandLow, skyIslandMedium, skyIslandHigh, skyIslandBarren,*/ warm_ocean, lukewarm_ocean, cold_ocean, /*deep_warm_ocean,*/ deep_lukewarm_ocean, deep_cold_ocean, // 40-49
  129. deep_frozen_ocean,
  130. // Modified variants...
  131. plains+128, desert+128, mountains+128, forest+128, taiga+128, swamp+128,
  132. snowy_tundra+128, jungle+128, jungleEdge+128, birch_forest+128, birch_forest_hills+128, dark_forest+128,
  133. snowy_taiga+128, giant_tree_taiga+128, giant_tree_taiga_hills+128, wooded_mountains+128, savanna+128, savanna_plateau+128, badlands+128, wooded_badlands_plateau+128, badlands_plateau+128
  134. };
  135. //==============================================================================
  136. // MC 1.7 Biome Tables
  137. //==============================================================================
  138. /* L_ADD_MUSHROOM_ISLAND_256 and L_DEEP_OCEAN_256
  139. * add the mushroom_fields and deep_ocean biomes respectively, however the rest of
  140. * the biomes are incomplete and are better described by temperature categories
  141. * with special modifications bits.
  142. */
  143. // BIOMES_L_BIOME_256: Changes temperature to weighted biomes:
  144. // Warm -> [desert, desert, desert, savanna, savanna, plains]
  145. // Warm,special -> [badlands_plateau, wooded_badlands_plateau, wooded_badlands_plateau]
  146. // Lush -> [forest, dark_forest, mountains, plains, birch_forest, swamp]
  147. // Lush,special -> [jungle]
  148. // Cold -> [forest, mountains, taiga, plains]
  149. // Cold,special -> [giant_tree_taiga]
  150. // Freezing -> [snowy_tundra, snowy_tundra, snowy_tundra, snowy_taiga]
  151. static const int BIOMES_L_BIOME_256[] =
  152. {
  153. ocean, plains, desert, mountains, forest, taiga, swamp, /*river, hell, sky,*/ // 0-9
  154. /*frozen_ocean, frozen_river,*/ snowy_tundra, /*snowy_mountains,*/ mushroom_fields, /*mushroom_field_shore, beach, desert_hills, wooded_hills, taiga_hills,*/ // 10-19
  155. /*mountain_edge,*/ jungle, /*jungle_hills, jungleEdge,*/ deep_ocean, /*stone_shore, snowy_beach,*/ birch_forest, /*birch_forest_hills,*/ dark_forest, // 20-29
  156. snowy_taiga, /*snowy_taiga_hills,*/ giant_tree_taiga, /*giant_tree_taiga_hills, wooded_mountains,*/ savanna, /*savanna_plateau, badlands,*/ wooded_badlands_plateau, badlands_plateau, // 30-39
  157. };
  158. // Introduces biomes: jungleEdge, wooded_mountains, badlands
  159. static const int BIOMES_L_BIOME_EDGE_64[] =
  160. {
  161. ocean, plains, desert, mountains, forest, taiga, swamp, /*river, hell, sky,*/ // 0-9
  162. /*frozen_ocean, frozen_river,*/ snowy_tundra, /*snowy_mountains,*/ mushroom_fields, /*mushroom_field_shore, beach, desert_hills, wooded_hills, taiga_hills,*/ // 10-19
  163. /*mountain_edge,*/ jungle, /*jungle_hills,*/ jungleEdge, deep_ocean, /*stone_shore, snowy_beach,*/ birch_forest, /*birch_forest_hills,*/ dark_forest, // 20-29
  164. snowy_taiga, /*snowy_taiga_hills,*/ giant_tree_taiga, /*giant_tree_taiga_hills,*/ wooded_mountains, savanna, /*savanna_plateau,*/ badlands, wooded_badlands_plateau, badlands_plateau, // 30-39
  165. };
  166. // Introduces biomes: snowy_mountains, desert_hills, wooded_hills, taiga_hills,
  167. // jungle_hills, birch_forest_hills, snowy_taiga_hills, giant_tree_taiga_hills, savanna_plateau
  168. // and all 21 mutated biomes
  169. static const int BIOMES_L_HILLS_64[] =
  170. {
  171. ocean, plains, desert, mountains, forest, taiga, swamp, /*river, hell, sky,*/ // 0-9
  172. /*frozen_ocean, frozen_river,*/ snowy_tundra, snowy_mountains, mushroom_fields, /*mushroom_field_shore, beach,*/ desert_hills, wooded_hills, taiga_hills, // 10-19
  173. /*mountain_edge,*/ jungle, jungle_hills, jungleEdge, deep_ocean, /*stone_shore, snowy_beach,*/ birch_forest, birch_forest_hills, dark_forest, // 20-29
  174. snowy_taiga, snowy_taiga_hills, giant_tree_taiga, giant_tree_taiga_hills, wooded_mountains, savanna, savanna_plateau, badlands, wooded_badlands_plateau, badlands_plateau, // 30-39
  175. // Modified variants...
  176. plains+128, desert+128, mountains+128, forest+128, taiga+128, swamp+128,
  177. snowy_tundra+128, jungle+128, jungleEdge+128, birch_forest+128, birch_forest_hills+128, dark_forest+128,
  178. snowy_taiga+128, giant_tree_taiga+128, giant_tree_taiga_hills+128, wooded_mountains+128, savanna+128, savanna_plateau+128, badlands+128, wooded_badlands_plateau+128, badlands_plateau+128
  179. };
  180. // Introduces biomes: mushroom_field_shore, beach, stone_shore, snowy_beach
  181. static const int BIOMES_L_SHORE_16[] =
  182. {
  183. ocean, plains, desert, mountains, forest, taiga, swamp, /*river, hell, sky,*/ // 0-9
  184. /*frozen_ocean, frozen_river,*/ snowy_tundra, snowy_mountains, mushroom_fields, mushroom_field_shore, beach, desert_hills, wooded_hills, taiga_hills, // 10-19
  185. /*mountain_edge,*/ jungle, jungle_hills, jungleEdge, deep_ocean, stone_shore, snowy_beach, birch_forest, birch_forest_hills, dark_forest, // 20-29
  186. snowy_taiga, snowy_taiga_hills, giant_tree_taiga, giant_tree_taiga_hills, wooded_mountains, savanna, savanna_plateau, badlands, wooded_badlands_plateau, badlands_plateau, // 30-39
  187. // Modified variants...
  188. plains+128, desert+128, mountains+128, forest+128, taiga+128, swamp+128,
  189. snowy_tundra+128, jungle+128, jungleEdge+128, birch_forest+128, birch_forest_hills+128, dark_forest+128,
  190. snowy_taiga+128, giant_tree_taiga+128, giant_tree_taiga_hills+128, wooded_mountains+128, savanna+128, savanna_plateau+128, badlands+128, wooded_badlands_plateau+128, badlands_plateau+128
  191. };
  192. // Merges the river branch and adds frozen_river biome
  193. static const int BIOMES_L_RIVER_MIX_4[] =
  194. {
  195. ocean, plains, desert, mountains, forest, taiga, swamp, river, /*hell, sky,*/ // 0-9
  196. /*frozen_ocean,*/ frozen_river, snowy_tundra, snowy_mountains, mushroom_fields, mushroom_field_shore, beach, desert_hills, wooded_hills, taiga_hills, // 10-19
  197. /*mountain_edge,*/ jungle, jungle_hills, jungleEdge, deep_ocean, stone_shore, snowy_beach, birch_forest, birch_forest_hills, dark_forest, // 20-29
  198. snowy_taiga, snowy_taiga_hills, giant_tree_taiga, giant_tree_taiga_hills, wooded_mountains, savanna, savanna_plateau, badlands, wooded_badlands_plateau, badlands_plateau, // 30-39
  199. // Modified variants...
  200. plains+128, desert+128, mountains+128, forest+128, taiga+128, swamp+128,
  201. snowy_tundra+128, jungle+128, jungleEdge+128, birch_forest+128, birch_forest_hills+128, dark_forest+128,
  202. snowy_taiga+128, giant_tree_taiga+128, giant_tree_taiga_hills+128, wooded_mountains+128, savanna+128, savanna_plateau+128, badlands+128, wooded_badlands_plateau+128, badlands_plateau+128
  203. };
  204. #ifdef __cplusplus
  205. }
  206. #endif
  207. #endif /* GENERATOR_H_ */