mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-22 22:13:35 +02:00
Remove flaggable bonus on object deletion
This commit is contained in:
parent
7be31c94f2
commit
16d25e903c
@ -51,6 +51,12 @@ void FlaggableMapObject::onHeroVisit( const CGHeroInstance * h ) const
|
||||
giveBonusTo(h->getOwner());
|
||||
}
|
||||
|
||||
void FlaggableMapObject::markAsDeleted() const
|
||||
{
|
||||
if(getOwner().isValidPlayer())
|
||||
takeBonusFrom(getOwner());
|
||||
}
|
||||
|
||||
void FlaggableMapObject::initObj(vstd::RNG & rand)
|
||||
{
|
||||
if(getOwner().isValidPlayer())
|
||||
|
@ -28,6 +28,7 @@ public:
|
||||
using CGObjectInstance::CGObjectInstance;
|
||||
|
||||
void onHeroVisit(const CGHeroInstance * h) const override;
|
||||
void markAsDeleted() const;
|
||||
void initObj(vstd::RNG & rand) override;
|
||||
|
||||
const IOwnableObject * asOwnable() const final;
|
||||
|
@ -45,6 +45,7 @@
|
||||
#include "mapObjectConstructors/CObjectClassesHandler.h"
|
||||
#include "campaign/CampaignState.h"
|
||||
#include "IGameSettings.h"
|
||||
#include "mapObjects/FlaggableMapObject.h"
|
||||
|
||||
VCMI_LIB_NAMESPACE_BEGIN
|
||||
|
||||
@ -1184,7 +1185,6 @@ void RemoveBonus::applyGs(CGameState *gs)
|
||||
|
||||
void RemoveObject::applyGs(CGameState *gs)
|
||||
{
|
||||
|
||||
CGObjectInstance *obj = gs->getObjInstance(objectID);
|
||||
logGlobal->debug("removing object id=%d; address=%x; name=%s", objectID, (intptr_t)obj, obj->getObjectName());
|
||||
//unblock tiles
|
||||
@ -1197,7 +1197,6 @@ void RemoveObject::applyGs(CGameState *gs)
|
||||
{
|
||||
auto * beatenHero = dynamic_cast<CGHeroInstance *>(obj);
|
||||
assert(beatenHero);
|
||||
PlayerState * p = gs->getPlayerState(beatenHero->tempOwner);
|
||||
gs->map->heroesOnMap -= beatenHero;
|
||||
|
||||
auto * siegeNode = beatenHero->whereShouldBeAttachedOnSiege(gs);
|
||||
@ -1253,7 +1252,16 @@ void RemoveObject::applyGs(CGameState *gs)
|
||||
}
|
||||
|
||||
if(obj->getOwner().isValidPlayer())
|
||||
gs->getPlayerState(obj->getOwner())->removeOwnedObject(obj); //object removed via map event
|
||||
{
|
||||
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();
|
||||
|
Loading…
Reference in New Issue
Block a user