MultiblockTree.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. #include "MultiblockTree.h"
  2. #include "Block.h"
  3. using namespace Framework;
  4. MultiblockTree::MultiblockTree(
  5. int dimensionId, __int64 structureId, Framework::Vec3<int> uniquePosition)
  6. : MultiblockStructure(dimensionId,
  7. structureId,
  8. uniquePosition,
  9. MultiblockStructureEnum::TREE)
  10. {}
  11. void MultiblockTree::onBlockRemoved(
  12. Entity* zActor, Item* zUsedItem, ItemSkill* zUsedSkill, Block* zBlock)
  13. {
  14. if (isBlockMember(zBlock))
  15. {
  16. MultiblockStructure::onBlockRemoved(
  17. zActor, zUsedItem, zUsedSkill, zBlock);
  18. for (int d = 4; d >= 0; d--)
  19. {
  20. bool foundStablizer = 0;
  21. Array<Block*> checked;
  22. Array<Block*> queue;
  23. Either<Block*, int> tmp = Game::INSTANCE->zBlockAt(
  24. zBlock->getPos() + getDirection(getDirectionFromIndex(d)),
  25. getDimensionId(),
  26. 0);
  27. Block* current = tmp.isA() ? tmp.getA() : 0;
  28. if (current && isBlockMember(current)) queue.add(current);
  29. while (queue.getEintragAnzahl() > 0)
  30. {
  31. current = queue.get(0);
  32. queue.remove(0);
  33. tmp = Game::INSTANCE->zBlockAt(
  34. zBlock->getPos()
  35. + getDirection(getDirectionFromIndex(d) | BOTTOM),
  36. getDimensionId(),
  37. 0);
  38. Block* bottom = tmp.isA() ? tmp.getA() : 0;
  39. if (bottom && isBlockMember(bottom))
  40. {
  41. foundStablizer = 1;
  42. break;
  43. }
  44. checked.add(current);
  45. for (int i = 0; i < 4; i++)
  46. {
  47. tmp = Game::INSTANCE->zBlockAt(
  48. zBlock->getPos()
  49. + getDirection(getDirectionFromIndex(d)
  50. | getDirectionFromIndex(i)),
  51. getDimensionId(),
  52. 0);
  53. Block* neighbor = tmp.isA() ? tmp.getA() : 0;
  54. if (neighbor && isBlockMember(neighbor))
  55. {
  56. bool found = 0;
  57. for (Block* b : checked)
  58. {
  59. if (b == neighbor)
  60. {
  61. found = 1;
  62. break;
  63. }
  64. }
  65. if (!found)
  66. {
  67. for (Block* b : queue)
  68. {
  69. if (b == neighbor)
  70. {
  71. found = 1;
  72. break;
  73. }
  74. }
  75. }
  76. if (!found) queue.add(neighbor);
  77. }
  78. }
  79. }
  80. if (!foundStablizer)
  81. {
  82. for (Block* b : checked)
  83. b->setHP(zActor, zUsedItem, zUsedSkill, 0);
  84. }
  85. }
  86. }
  87. }
  88. MultiblockTreeStructureType::MultiblockTreeStructureType()
  89. : MultiblockStructureType(MultiblockStructureEnum::TREE)
  90. {}
  91. MultiblockStructure* MultiblockTreeStructureType::createStructure(
  92. int dimensionId,
  93. __int64 structureId,
  94. Framework::Vec3<int> uniquePosition) const
  95. {
  96. return new MultiblockTree(dimensionId, structureId, uniquePosition);
  97. }