Code: Select all
bool Entity::canFastReplace(const Entity* entity, const Entity* other, bool allowGhosts)
{
// Can't fast replace buildings owned by someone else.
if (entity->getForce() != other->getForce())
return false;
// If the entities aren't on the same position they can't fast-replace each other
// Except for splitters <==> (underground) belts.
if (entity->isSplitter() != other->isSplitter())
{
if (!entity->collide(other->getBoundingBox()))
return false;
if (entity->hasDirection() && other->hasDirection() &&
entity->getDirection() != other->getDirection())
return false;
}
else if (entity->position != other->position)
return false;
// Check for allowing real replacing ghosts
const bool otherIsGhost = other->isEntityGhost();
if (otherIsGhost)
{
if (!allowGhosts)
return false;
// Get the inner entity for all furthur checks
other = static_cast<const EntityGhost*>(other)->innerEntity;
}
// If 'this' is a ghost it can never fast-replace anything else
if (entity->isEntityGhost())
return false;
//if (entity->getPrototype()->tileGridSize(entity->getDirection()) !=
// other->getPrototype()->tileGridSize(other->getDirection()))
// return false;
// For real entities: when the direction is same and id is same, the fast replace wouldn't change anything
if (!otherIsGhost && entity->getPrototype()->getID() == other->getPrototype()->getID())
{
// Direction is the same or doesn't matter
if (entity->getDirection() == other->getDirection() || !other->hasDirection() || entity->preservesDirectionInFastReplaceSetup())
return false;
}
return true;
}