MultiblockTree.cpp 2.7 KB

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