MultiblockTree.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #include "MultiblockTree.h"
  2. using namespace Framework;
  3. MultiblockTree::MultiblockTree(int dimensionId, __int64 structureId, Framework::Vec3<int> uniquePosition)
  4. : MultiblockStructure(
  5. dimensionId, structureId, uniquePosition, MultiblockStructureEnum::TREE)
  6. {}
  7. void MultiblockTree::onBlockRemoved(Block* zBlock)
  8. {
  9. if (isBlockMember(zBlock))
  10. {
  11. MultiblockStructure::onBlockRemoved(zBlock);
  12. for (int d = 4; d >= 0; d--)
  13. {
  14. bool foundStablizer = 0;
  15. Array<Block*> checked;
  16. Array<Block*> queue;
  17. Block* current = zBlock->zNeighbor(getDirectionFromIndex(d));
  18. if (current && isBlockMember(current))
  19. queue.add(current);
  20. while (queue.getEintragAnzahl() > 0)
  21. {
  22. current = queue.get(0);
  23. queue.remove(0);
  24. Block* bottom = current->zNeighbor(BOTTOM);
  25. if (bottom && isBlockMember(bottom))
  26. {
  27. foundStablizer = 1;
  28. break;
  29. }
  30. checked.add(current);
  31. for (int i = 0; i < 4; i++)
  32. {
  33. Block* neighbor = current->zNeighbor(getDirectionFromIndex(i));
  34. if (neighbor && isBlockMember(neighbor))
  35. {
  36. bool found = 0;
  37. for (Block* b : checked)
  38. {
  39. if (b == neighbor)
  40. {
  41. found = 1;
  42. break;
  43. }
  44. }
  45. if (!found)
  46. {
  47. for (Block* b : queue)
  48. {
  49. if (b == neighbor)
  50. {
  51. found = 1;
  52. break;
  53. }
  54. }
  55. }
  56. if (!found)
  57. queue.add(neighbor);
  58. }
  59. }
  60. }
  61. if (!foundStablizer)
  62. {
  63. for (Block* b : checked)
  64. b->setHP(0);
  65. }
  66. }
  67. }
  68. }
  69. MultiblockTreeStructureType::MultiblockTreeStructureType()
  70. : MultiblockStructureType(MultiblockStructureEnum::TREE)
  71. {}
  72. MultiblockStructure* MultiblockTreeStructureType::createStructure(int dimensionId, __int64 structureId, Framework::Vec3<int> uniquePosition) const
  73. {
  74. return new MultiblockTree(dimensionId, structureId, uniquePosition);
  75. }