MultiblockTree.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #include "MultiblockTree.h"
  2. using namespace Framework;
  3. MultiblockTree::MultiblockTree(int dimensionId, __int64 structureId, Framework::Vec3<int> uniquePosition)
  4. : MultiblockStructure(dimensionId, structureId, uniquePosition)
  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. }