diff --git a/client/widgets/CWindowWithArtifacts.cpp b/client/widgets/CWindowWithArtifacts.cpp index 6485ac6da..af3894604 100644 --- a/client/widgets/CWindowWithArtifacts.cpp +++ b/client/widgets/CWindowWithArtifacts.cpp @@ -142,7 +142,7 @@ void CWindowWithArtifacts::clickPressedArtPlaceHero(CArtifactsOfHeroBase & artsI } else if(auto art = artPlace.getArt()) { - if(artSetPtr->getHero()->tempOwner == LOCPLINT->playerID) + if(artSetPtr->getHero()->getOwner() == LOCPLINT->playerID) { if(checkSpecialArts(*art, hero, std::is_same_v> ? true : false)) LOCPLINT->cb->swapArtifacts(ArtifactLocation(artSetPtr->getHero()->id, artPlace.slot), ArtifactLocation(artSetPtr->getHero()->id, ArtifactPosition::TRANSITION_POS)); diff --git a/lib/CGameInfoCallback.cpp b/lib/CGameInfoCallback.cpp index da6977d6e..8efb6feed 100644 --- a/lib/CGameInfoCallback.cpp +++ b/lib/CGameInfoCallback.cpp @@ -18,7 +18,6 @@ #include "mapObjects/CGHeroInstance.h" #include "mapObjects/CGTownInstance.h" #include "mapObjects/MiscObjects.h" -#include "mapObjects/CGMarket.h" #include "networkPacks/ArtifactLocation.h" #include "CGeneralTextHandler.h" #include "StartInfo.h" // for StartInfo @@ -969,30 +968,9 @@ const CGObjectInstance * CGameInfoCallback::getObjInstance( ObjectInstanceID oid return gs->map->objects[oid.num]; } -CArtifactSet * CGameInfoCallback::getArtSet(const ArtifactLocation & loc) const +const CArtifactSet * CGameInfoCallback::getArtSet(const ArtifactLocation & loc) const { - if(auto hero = const_cast(getHero(loc.artHolder))) - { - if(loc.creature.has_value()) - { - if(loc.creature.value() == SlotID::COMMANDER_SLOT_PLACEHOLDER) - return hero->commander; - else - return hero->getStackPtr(loc.creature.value()); - } - else - { - return hero; - } - } - else if(auto market = dynamic_cast(getObj(loc.artHolder, false))) - { - return const_cast(market); - } - else - { - return nullptr; - } + return gs->getArtSet(loc); } std::vector CGameInfoCallback::getVisibleTeleportObjects(std::vector ids, PlayerColor player) const diff --git a/lib/CGameInfoCallback.h b/lib/CGameInfoCallback.h index 2fe7f04d4..2be59d3ec 100644 --- a/lib/CGameInfoCallback.h +++ b/lib/CGameInfoCallback.h @@ -180,7 +180,7 @@ public: virtual int64_t estimateSpellDamage(const CSpell * sp, const CGHeroInstance * hero) const; //estimates damage of given spell; returns 0 if spell causes no dmg virtual const CArtifactInstance * getArtInstance(ArtifactInstanceID aid) const; virtual const CGObjectInstance * getObjInstance(ObjectInstanceID oid) const; - virtual CArtifactSet * getArtSet(const ArtifactLocation & loc) const; + virtual const CArtifactSet * getArtSet(const ArtifactLocation & loc) const; //virtual const CGObjectInstance * getArmyInstance(ObjectInstanceID oid) const; //objects diff --git a/lib/IGameCallback.cpp b/lib/IGameCallback.cpp index 61d940cf3..25e7d4261 100644 --- a/lib/IGameCallback.cpp +++ b/lib/IGameCallback.cpp @@ -20,11 +20,13 @@ #include "bonuses/Propagators.h" #include "bonuses/Updaters.h" +#include "networkPacks/ArtifactLocation.h" #include "serializer/CLoadFile.h" #include "serializer/CSaveFile.h" #include "rmg/CMapGenOptions.h" #include "mapObjectConstructors/AObjectTypeHandler.h" #include "mapObjectConstructors/CObjectClassesHandler.h" +#include "mapObjects/CGMarket.h" #include "mapObjects/CGTownInstance.h" #include "mapObjects/CObjectHandler.h" #include "mapObjects/CQuest.h" @@ -268,6 +270,32 @@ CArmedInstance * CNonConstInfoCallback::getArmyInstance(const ObjectInstanceID & return dynamic_cast(getObjInstance(oid)); } +CArtifactSet * CNonConstInfoCallback::getArtSet(const ArtifactLocation & loc) +{ + if(auto hero = getHero(loc.artHolder)) + { + if(loc.creature.has_value()) + { + if(loc.creature.value() == SlotID::COMMANDER_SLOT_PLACEHOLDER) + return hero->commander; + else + return hero->getStackPtr(loc.creature.value()); + } + else + { + return hero; + } + } + else if(auto market = dynamic_cast(getObjInstance(loc.artHolder))) + { + return market; + } + else + { + return nullptr; + } +} + bool IGameCallback::isVisitCoveredByAnotherQuery(const CGObjectInstance *obj, const CGHeroInstance *hero) { //only server knows diff --git a/lib/IGameCallback.h b/lib/IGameCallback.h index 01502021b..29e87dbff 100644 --- a/lib/IGameCallback.h +++ b/lib/IGameCallback.h @@ -146,6 +146,7 @@ public: using CGameInfoCallback::getTile; using CGameInfoCallback::getArtInstance; using CGameInfoCallback::getObjInstance; + using CGameInfoCallback::getArtSet; PlayerState * getPlayerState(const PlayerColor & color, bool verbose = true); TeamState * getTeam(const TeamID & teamID); //get team by team ID @@ -156,6 +157,7 @@ public: CArtifactInstance * getArtInstance(const ArtifactInstanceID & aid); CGObjectInstance * getObjInstance(const ObjectInstanceID & oid); CArmedInstance * getArmyInstance(const ObjectInstanceID & oid); + CArtifactSet * getArtSet(const ArtifactLocation & loc); virtual void updateEntity(Metatype metatype, int32_t index, const JsonNode & data) = 0; }; diff --git a/lib/constants/EntityIdentifiers.h b/lib/constants/EntityIdentifiers.h index e745a4729..c83d63bdd 100644 --- a/lib/constants/EntityIdentifiers.h +++ b/lib/constants/EntityIdentifiers.h @@ -341,7 +341,7 @@ public: enum Type { NO_OBJ = -1, - ALTAR_OF_SACRIFICE = 2, + ALTAR_OF_SACRIFICE [[deprecated]] = 2, ANCHOR_POINT = 3, ARENA = 4, ARTIFACT = 5, diff --git a/server/CGameHandler.cpp b/server/CGameHandler.cpp index 004e48fe4..6418580c2 100644 --- a/server/CGameHandler.cpp +++ b/server/CGameHandler.cpp @@ -3434,17 +3434,12 @@ bool CGameHandler::isAllowedExchange(ObjectInstanceID id1, ObjectInstanceID id2) return true; } - if(o1->ID == Obj::ALTAR_OF_SACRIFICE) - { - return true; - } - if(o2->ID == Obj::ALTAR_OF_SACRIFICE) - { - const auto visitingHero = getVisitingHero(o2); - const auto thisHero = static_cast(o1); - if(visitingHero == thisHero) - return true; - } + auto market = dynamic_cast(o1); + if(market == nullptr) + market = dynamic_cast(o2); + if(market) + return market->allowsTrade(EMarketMode::ARTIFACT_EXP); + if (o1->ID == Obj::HERO && o2->ID == Obj::HERO) { const CGHeroInstance *h1 = static_cast(o1); diff --git a/server/NetPacksServer.cpp b/server/NetPacksServer.cpp index 1120d7494..ffa256225 100644 --- a/server/NetPacksServer.cpp +++ b/server/NetPacksServer.cpp @@ -141,7 +141,7 @@ void ApplyGhNetPackVisitor::visitExchangeArtifacts(ExchangeArtifacts & pack) void ApplyGhNetPackVisitor::visitBulkExchangeArtifacts(BulkExchangeArtifacts & pack) { - if(gh.getObj(pack.srcHero)->ID != MapObjectID::ALTAR_OF_SACRIFICE) + if(dynamic_cast(gh.getObj(pack.srcHero)) == nullptr) gh.throwIfWrongOwner(&pack, pack.srcHero); if(pack.swap) gh.throwIfWrongOwner(&pack, pack.dstHero);