MultiblockTree.cpp 2.8 KB

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