mg_ore.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. /*
  2. Minetest
  3. Copyright (C) 2014-2016 kwolekr, Ryan Kwolek <kwolekr@minetest.net>
  4. Copyright (C) 2015-2017 paramat
  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.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU Lesser General Public License for more details.
  13. You should have received a copy of the GNU Lesser General Public License along
  14. with this program; if not, write to the Free Software Foundation, Inc.,
  15. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  16. */
  17. #pragma once
  18. #include <unordered_set>
  19. #include "objdef.h"
  20. #include "noise.h"
  21. #include "nodedef.h"
  22. class Noise;
  23. class Mapgen;
  24. class MMVManip;
  25. /////////////////// Ore generation flags
  26. #define OREFLAG_ABSHEIGHT 0x01 // Non-functional but kept to not break flags
  27. #define OREFLAG_PUFF_CLIFFS 0x02
  28. #define OREFLAG_PUFF_ADDITIVE 0x04
  29. #define OREFLAG_USE_NOISE 0x08
  30. enum OreType {
  31. ORE_SCATTER,
  32. ORE_SHEET,
  33. ORE_PUFF,
  34. ORE_BLOB,
  35. ORE_VEIN,
  36. };
  37. extern FlagDesc flagdesc_ore[];
  38. class Ore : public ObjDef, public NodeResolver {
  39. public:
  40. static const bool NEEDS_NOISE = false;
  41. content_t c_ore; // the node to place
  42. std::vector<content_t> c_wherein; // the nodes to be placed in
  43. u32 clust_scarcity; // ore cluster has a 1-in-clust_scarcity chance of appearing at a node
  44. s16 clust_num_ores; // how many ore nodes are in a chunk
  45. s16 clust_size; // how large (in nodes) a chunk of ore is
  46. s16 y_min;
  47. s16 y_max;
  48. u8 ore_param2; // to set node-specific attributes
  49. u32 flags = 0; // attributes for this ore
  50. float nthresh; // threshold for noise at which an ore is placed
  51. NoiseParams np; // noise for distribution of clusters (NULL for uniform scattering)
  52. Noise *noise = nullptr;
  53. std::unordered_set<u8> biomes;
  54. Ore() = default;;
  55. virtual ~Ore();
  56. virtual void resolveNodeNames();
  57. size_t placeOre(Mapgen *mg, u32 blockseed,
  58. v3s16 nmin, v3s16 nmax, s16 ore_zero_level);
  59. virtual void generate(MMVManip *vm, int mapseed, u32 blockseed,
  60. v3s16 nmin, v3s16 nmax, u8 *biomemap) = 0;
  61. };
  62. class OreScatter : public Ore {
  63. public:
  64. static const bool NEEDS_NOISE = false;
  65. virtual void generate(MMVManip *vm, int mapseed, u32 blockseed,
  66. v3s16 nmin, v3s16 nmax, u8 *biomemap);
  67. };
  68. class OreSheet : public Ore {
  69. public:
  70. static const bool NEEDS_NOISE = true;
  71. u16 column_height_min;
  72. u16 column_height_max;
  73. float column_midpoint_factor;
  74. virtual void generate(MMVManip *vm, int mapseed, u32 blockseed,
  75. v3s16 nmin, v3s16 nmax, u8 *biomemap);
  76. };
  77. class OrePuff : public Ore {
  78. public:
  79. static const bool NEEDS_NOISE = true;
  80. NoiseParams np_puff_top;
  81. NoiseParams np_puff_bottom;
  82. Noise *noise_puff_top = nullptr;
  83. Noise *noise_puff_bottom = nullptr;
  84. OrePuff() = default;
  85. virtual ~OrePuff();
  86. virtual void generate(MMVManip *vm, int mapseed, u32 blockseed,
  87. v3s16 nmin, v3s16 nmax, u8 *biomemap);
  88. };
  89. class OreBlob : public Ore {
  90. public:
  91. static const bool NEEDS_NOISE = true;
  92. virtual void generate(MMVManip *vm, int mapseed, u32 blockseed,
  93. v3s16 nmin, v3s16 nmax, u8 *biomemap);
  94. };
  95. class OreVein : public Ore {
  96. public:
  97. static const bool NEEDS_NOISE = true;
  98. float random_factor;
  99. Noise *noise2 = nullptr;
  100. OreVein() = default;
  101. virtual ~OreVein();
  102. virtual void generate(MMVManip *vm, int mapseed, u32 blockseed,
  103. v3s16 nmin, v3s16 nmax, u8 *biomemap);
  104. };
  105. class OreManager : public ObjDefManager {
  106. public:
  107. OreManager(IGameDef *gamedef);
  108. virtual ~OreManager() = default;
  109. const char *getObjectTitle() const
  110. {
  111. return "ore";
  112. }
  113. static Ore *create(OreType type)
  114. {
  115. switch (type) {
  116. case ORE_SCATTER:
  117. return new OreScatter;
  118. case ORE_SHEET:
  119. return new OreSheet;
  120. case ORE_PUFF:
  121. return new OrePuff;
  122. case ORE_BLOB:
  123. return new OreBlob;
  124. case ORE_VEIN:
  125. return new OreVein;
  126. default:
  127. return nullptr;
  128. }
  129. }
  130. void clear();
  131. size_t placeAllOres(Mapgen *mg, u32 blockseed,
  132. v3s16 nmin, v3s16 nmax, s16 ore_zero_level = 0);
  133. };