mg_decoration.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /*
  2. Minetest
  3. Copyright (C) 2014-2018 kwolekr, Ryan Kwolek <kwolekr@minetest.net>
  4. Copyright (C) 2015-2018 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 Mapgen;
  23. class MMVManip;
  24. class PcgRandom;
  25. class Schematic;
  26. enum DecorationType {
  27. DECO_SIMPLE,
  28. DECO_SCHEMATIC,
  29. DECO_LSYSTEM
  30. };
  31. #define DECO_PLACE_CENTER_X 0x01
  32. #define DECO_PLACE_CENTER_Y 0x02
  33. #define DECO_PLACE_CENTER_Z 0x04
  34. #define DECO_USE_NOISE 0x08
  35. #define DECO_FORCE_PLACEMENT 0x10
  36. #define DECO_LIQUID_SURFACE 0x20
  37. #define DECO_ALL_FLOORS 0x40
  38. #define DECO_ALL_CEILINGS 0x80
  39. extern FlagDesc flagdesc_deco[];
  40. class Decoration : public ObjDef, public NodeResolver {
  41. public:
  42. Decoration() = default;
  43. virtual ~Decoration() = default;
  44. virtual void resolveNodeNames();
  45. bool canPlaceDecoration(MMVManip *vm, v3s16 p);
  46. size_t placeDeco(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax);
  47. virtual size_t generate(MMVManip *vm, PcgRandom *pr, v3s16 p, bool ceiling) = 0;
  48. u32 flags = 0;
  49. int mapseed = 0;
  50. std::vector<content_t> c_place_on;
  51. s16 sidelen = 1;
  52. s16 y_min;
  53. s16 y_max;
  54. float fill_ratio = 0.0f;
  55. NoiseParams np;
  56. std::vector<content_t> c_spawnby;
  57. s16 nspawnby;
  58. s16 place_offset_y = 0;
  59. std::unordered_set<u8> biomes;
  60. };
  61. class DecoSimple : public Decoration {
  62. public:
  63. virtual void resolveNodeNames();
  64. virtual size_t generate(MMVManip *vm, PcgRandom *pr, v3s16 p, bool ceiling);
  65. std::vector<content_t> c_decos;
  66. s16 deco_height;
  67. s16 deco_height_max;
  68. u8 deco_param2;
  69. u8 deco_param2_max;
  70. };
  71. class DecoSchematic : public Decoration {
  72. public:
  73. DecoSchematic() = default;
  74. virtual size_t generate(MMVManip *vm, PcgRandom *pr, v3s16 p, bool ceiling);
  75. Rotation rotation;
  76. Schematic *schematic = nullptr;
  77. };
  78. /*
  79. class DecoLSystem : public Decoration {
  80. public:
  81. virtual void generate(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax);
  82. };
  83. */
  84. class DecorationManager : public ObjDefManager {
  85. public:
  86. DecorationManager(IGameDef *gamedef);
  87. virtual ~DecorationManager() = default;
  88. const char *getObjectTitle() const
  89. {
  90. return "decoration";
  91. }
  92. static Decoration *create(DecorationType type)
  93. {
  94. switch (type) {
  95. case DECO_SIMPLE:
  96. return new DecoSimple;
  97. case DECO_SCHEMATIC:
  98. return new DecoSchematic;
  99. //case DECO_LSYSTEM:
  100. // return new DecoLSystem;
  101. default:
  102. return NULL;
  103. }
  104. }
  105. size_t placeAllDecos(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax);
  106. };