123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- #include "MultiblockStructure.h"
- #include "Game.h"
- using namespace Framework;
- MultiblockStructure::MultiblockStructure(int dimensionId, __int64 structureId, Framework::Vec3<int> uniquePosition)
- : ReferenceCounter(),
- uniquePosition(uniquePosition),
- dimensionId(dimensionId),
- structureId(structureId)
- {}
- MultiblockStructure::~MultiblockStructure()
- {}
- void MultiblockStructure::onBlockLoaded(Block* block)
- {
- if (isBlockMember(block))
- loadedMembers.add(block);
- else
- block->release();
- }
- void MultiblockStructure::onBlockUnloaded(Block* zBlock)
- {
- for (auto i = loadedMembers.begin(); i; ++i)
- {
- if ((Block*)i == zBlock)
- {
- i.remove();
- return;
- }
- }
- }
- void MultiblockStructure::addMemberPosition(Framework::Vec3<int > blockPos)
- {
- memberBlockPositions.add(blockPos);
- Punkt center = Game::INSTANCE->getChunkCenter(blockPos.x, blockPos.y);
- for (const Punkt& p : affectedChunks)
- {
- if (p == center)
- return;
- }
- affectedChunks.add(center);
- }
- void MultiblockStructure::onBlockRemoved(Block* zBlock)
- {
- for (auto i = memberBlockPositions.begin(); i; ++i)
- {
- if (i.val() == zBlock->getPos())
- {
- Punkt center = Game::INSTANCE->getChunkCenter(i.val().x, i.val().y);
- i.remove();
- // check if other blocks in the same chunk exists
- for (Vec3<int> pos : memberBlockPositions)
- {
- if (center == Game::INSTANCE->getChunkCenter(pos.x, pos.y))
- return;
- }
- // remove chunk from affected chunks if no other block is in this chunk
- for (auto p = affectedChunks.begin(); p; ++p)
- {
- if (p.val() == center)
- p.remove();
- }
- return;
- }
- }
- }
- bool MultiblockStructure::isEmpty() const
- {
- return memberBlockPositions.getEintragAnzahl() > 0;
- }
- bool MultiblockStructure::isFullyLoaded() const
- {
- for (Punkt p : affectedChunks)
- {
- if (!Game::INSTANCE->isChunkLoaded(p.x, p.y, dimensionId))
- return 0;
- }
- return 1;
- }
- bool MultiblockStructure::isFullyUnloaded() const
- {
- for (Punkt p : affectedChunks)
- {
- if (Game::INSTANCE->isChunkLoaded(p.x, p.y, dimensionId))
- return 0;
- }
- return 1;
- }
- bool MultiblockStructure::isBlockMember(Block* zBlock) const
- {
- for (const Vec3<int>& pos : memberBlockPositions)
- {
- if (pos == zBlock->getPos())
- return 1;
- }
- return 0;
- }
- __int64 MultiblockStructure::getStructureId() const
- {
- return structureId;
- }
- Framework::Vec3<int> MultiblockStructure::getUniquePosition() const
- {
- return uniquePosition;
- }
|