MultiblockTree.cpp 1.8 KB

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