1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-02 00:10:22 +02:00

Remove object from owned objects before resetting owner

This commit is contained in:
Ivan Savenko 2024-12-08 11:25:48 +00:00
parent 543ce94132
commit 970d7d795f

View File

@ -1193,6 +1193,17 @@ void RemoveObject::applyGs(CGameState *gs)
if (initiator.isValidPlayer()) if (initiator.isValidPlayer())
gs->getPlayerState(initiator)->destroyedObjects.insert(objectID); gs->getPlayerState(initiator)->destroyedObjects.insert(objectID);
if(obj->getOwner().isValidPlayer())
{
gs->getPlayerState(obj->getOwner())->removeOwnedObject(obj); //object removed via map event or hero got beaten
FlaggableMapObject* flaggableObject = dynamic_cast<FlaggableMapObject*>(obj);
if(flaggableObject)
{
flaggableObject->markAsDeleted();
}
}
if(obj->ID == Obj::HERO) //remove beaten hero if(obj->ID == Obj::HERO) //remove beaten hero
{ {
auto * beatenHero = dynamic_cast<CGHeroInstance *>(obj); auto * beatenHero = dynamic_cast<CGHeroInstance *>(obj);
@ -1251,18 +1262,6 @@ void RemoveObject::applyGs(CGameState *gs)
} }
} }
if(obj->getOwner().isValidPlayer())
{
gs->getPlayerState(obj->getOwner())->removeOwnedObject(obj); //object removed via map event or hero got beaten
FlaggableMapObject* flaggableObject = dynamic_cast<FlaggableMapObject*>(obj);
if(flaggableObject)
{
flaggableObject->markAsDeleted();
}
}
gs->map->instanceNames.erase(obj->instanceName); gs->map->instanceNames.erase(obj->instanceName);
gs->map->objects[objectID.getNum()].dellNull(); gs->map->objects[objectID.getNum()].dellNull();
gs->map->calculateGuardingGreaturePositions();//FIXME: excessive, update only affected tiles gs->map->calculateGuardingGreaturePositions();//FIXME: excessive, update only affected tiles