MultiblockTree.cpp 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #include "MultiblockTree.h"
  2. using namespace Framework;
  3. MultiblockTree::MultiblockTree(
  4. int dimensionId, __int64 structureId, Framework::Vec3<int> uniquePosition)
  5. : MultiblockStructure(
  6. dimensionId, structureId, uniquePosition, MultiblockStructureEnum::TREE)
  7. {}
  8. void MultiblockTree::onBlockRemoved(Block* zBlock)
  9. {
  10. if (isBlockMember(zBlock))
  11. {
  12. MultiblockStructure::onBlockRemoved(zBlock);
  13. for (int d = 4; d >= 0; d--)
  14. {
  15. bool foundStablizer = 0;
  16. Array<Block*> checked;
  17. Array<Block*> queue;
  18. Block* current = zBlock->zNeighbor(getDirectionFromIndex(d));
  19. if (current && isBlockMember(current)) 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
  34. = current->zNeighbor(getDirectionFromIndex(i));
  35. if (neighbor && isBlockMember(neighbor))
  36. {
  37. bool found = 0;
  38. for (Block* b : checked)
  39. {
  40. if (b == neighbor)
  41. {
  42. found = 1;
  43. break;
  44. }
  45. }
  46. if (!found)
  47. {
  48. for (Block* b : queue)
  49. {
  50. if (b == neighbor)
  51. {
  52. found = 1;
  53. break;
  54. }
  55. }
  56. }
  57. if (!found) 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(
  73. int dimensionId,
  74. __int64 structureId,
  75. Framework::Vec3<int> uniquePosition) const
  76. {
  77. return new MultiblockTree(dimensionId, structureId, uniquePosition);
  78. }