1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-22 22:13:35 +02:00

Merge pull request #5051 from IvanSavenko/hero_removal_fix

Remove object from owned objects before resetting owner
This commit is contained in:
Ivan Savenko 2024-12-08 14:07:23 +02:00 committed by GitHub
commit 04987eef5c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1193,6 +1193,17 @@ void RemoveObject::applyGs(CGameState *gs)
if (initiator.isValidPlayer())
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
{
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->objects[objectID.getNum()].dellNull();
gs->map->calculateGuardingGreaturePositions();//FIXME: excessive, update only affected tiles