ReturnValue Game::internalMoveCreature(Creature* actor, Creature* creature, Cylinder* fromCylinder, Cylinder* toCylinder, uint32_t flags/* = 0*/)
{
//check if we can move the creature to the destination
ReturnValue ret = toCylinder->__queryAdd(0, creature, 1, flags);
if(ret != RET_NOERROR)
return ret;
//height check
Tile* toTile = toCylinder->getTile();
Tile* fromTile = fromCylinder->getTile();
if(toTile->getHeight() - fromTile->getHeight() >= 2) {
return RET_NOTPOSSIBLE;
}
fromCylinder->getTile()->moveCreature(actor, creature, toCylinder);
if(creature->getParent() != toCylinder)
return RET_NOERROR;
Item* toItem = NULL;
Cylinder* subCylinder = NULL;
int32_t n = 0, tmp = 0;
while((subCylinder = toCylinder->__queryDestination(tmp, creature, &toItem, flags)) != toCylinder)
{
toCylinder->getTile()->moveCreature(actor, creature, subCylinder);
if(creature->getParent() != subCylinder) //could happen if a script move the creature
break;
toCylinder = subCylinder;
flags = 0;
if(++n >= MAP_MAX_LAYERS) //to prevent infinite loop
break;
}
return RET_NOERROR;
}