From 665bd4346e87af539174396ec21c0bc407aad33a Mon Sep 17 00:00:00 2001 From: Andrii Danylchenko Date: Sat, 9 Jul 2022 19:00:03 +0300 Subject: [PATCH] Fix getting battlefield crash --- lib/mapObjects/CGHeroInstance.cpp | 6 ++++++ lib/mapObjects/CGHeroInstance.h | 2 ++ lib/mapObjects/CObjectHandler.h | 2 +- lib/mapObjects/MiscObjects.cpp | 5 +++++ lib/mapObjects/MiscObjects.h | 1 + 5 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/mapObjects/CGHeroInstance.cpp b/lib/mapObjects/CGHeroInstance.cpp index 5fe402118..2e40ea49d 100644 --- a/lib/mapObjects/CGHeroInstance.cpp +++ b/lib/mapObjects/CGHeroInstance.cpp @@ -151,6 +151,12 @@ int3 CGHeroInstance::convertPosition(int3 src, bool toh3m) //toh3m=true: manifes return src; } } + +BattleField CGHeroInstance::getBattlefield() const +{ + return BattleField::NONE; +} + int3 CGHeroInstance::getPosition(bool h3m) const //h3m=true - returns position of hero object; h3m=false - returns position of hero 'manifestation' { if (h3m) diff --git a/lib/mapObjects/CGHeroInstance.h b/lib/mapObjects/CGHeroInstance.h index 02b738c68..4263fb818 100644 --- a/lib/mapObjects/CGHeroInstance.h +++ b/lib/mapObjects/CGHeroInstance.h @@ -270,6 +270,8 @@ public: void afterAddToMap(CMap * map) override; void updateFrom(const JsonNode & data) override; + + BattleField getBattlefield() const override; protected: void setPropertyDer(ui8 what, ui32 val) override;//synchr ///common part of hero instance and hero definition diff --git a/lib/mapObjects/CObjectHandler.h b/lib/mapObjects/CObjectHandler.h index 3db649b4e..851796db8 100644 --- a/lib/mapObjects/CObjectHandler.h +++ b/lib/mapObjects/CObjectHandler.h @@ -159,7 +159,7 @@ public: std::set getBlockedOffsets() const; //returns set of relative positions blocked by this object bool isVisitable() const; //returns true if object is visitable - BattleField getBattlefield() const; + virtual BattleField getBattlefield() const; virtual bool isTile2Terrain() const { return false; } diff --git a/lib/mapObjects/MiscObjects.cpp b/lib/mapObjects/MiscObjects.cpp index 3a8f405ba..acf6d28ae 100644 --- a/lib/mapObjects/MiscObjects.cpp +++ b/lib/mapObjects/MiscObjects.cpp @@ -1406,6 +1406,11 @@ void CGArtifact::pick(const CGHeroInstance * h) const cb->removeObject(this); } +BattleField CGArtifact::getBattlefield() const +{ + return BattleField::NONE; +} + void CGArtifact::battleFinished(const CGHeroInstance *hero, const BattleResult &result) const { if(result.winner == 0) //attacker won diff --git a/lib/mapObjects/MiscObjects.h b/lib/mapObjects/MiscObjects.h index e13165fe0..e970d9c44 100644 --- a/lib/mapObjects/MiscObjects.h +++ b/lib/mapObjects/MiscObjects.h @@ -201,6 +201,7 @@ public: void initObj(CRandomGenerator & rand) override; void afterAddToMap(CMap * map) override; + BattleField getBattlefield() const override; template void serialize(Handler &h, const int version) {