Entity::canFastReplace

Bilka
Factorio Staff
Factorio Staff
Posts: 3314
Joined: Sat Aug 13, 2016 9:20 am
Contact:

Entity::canFastReplace

Post by Bilka »

Basically

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;
}
but accessible from the api please :) It would be even nicer if we didn't have to give a second entity, but instead only give a position and the entity that we want to place. Perhaps as surface::canFastReplace
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.
Post Reply

Return to “Implemented mod requests”