From 45a3064e5d7aaa062b0a78e44a385895673826c1 Mon Sep 17 00:00:00 2001 From: SoundSSGood <87084363+SoundSSGood@users.noreply.github.com> Date: Wed, 30 Nov 2022 17:57:39 +0200 Subject: [PATCH] suggested changes --- lib/CArtHandler.cpp | 35 +++++++++++++++++++++++++++++++++-- lib/CArtHandler.h | 25 +++---------------------- lib/GameConstants.h | 8 ++++++++ lib/mapObjects/CQuest.h | 14 +------------- 4 files changed, 45 insertions(+), 37 deletions(-) diff --git a/lib/CArtHandler.cpp b/lib/CArtHandler.cpp index d33f87721..96aeaf896 100644 --- a/lib/CArtHandler.cpp +++ b/lib/CArtHandler.cpp @@ -1019,7 +1019,7 @@ bool CCombinedArtifactInstance::canBePutAt(const CArtifactSet *artSet, ArtifactP } //we iterate over all active slots and check if constituents fits them - for(const auto pos : ArtifactUtils::constituentWornSlots) + for(const auto pos : ArtifactUtils::constituentWornSlots()) { for(auto art = constituentsToBePlaced.begin(); art != constituentsToBePlaced.end(); art++) { @@ -1372,6 +1372,7 @@ void CArtifactSet::eraseArtSlot(ArtifactPosition slot) { if(ArtifactUtils::isSlotBackpack(slot)) { + assert(artifactsInBackpack.begin() + slot < artifactsInBackpack.end()); slot = ArtifactPosition(slot - GameConstants::BACKPACK_START); artifactsInBackpack.erase(artifactsInBackpack.begin() + slot); } @@ -1544,11 +1545,41 @@ DLL_LINKAGE ArtifactPosition ArtifactUtils::getArtifactDstPosition( const CArtif return ArtifactPosition(GameConstants::BACKPACK_START); } +DLL_LINKAGE const std::vector & ArtifactUtils::unmovableSlots() +{ + return + { + ArtifactPosition::SPELLBOOK, + ArtifactPosition::MACH4 + }; +} + +DLL_LINKAGE const std::vector & ArtifactUtils::constituentWornSlots() +{ + return + { + ArtifactPosition::HEAD, + ArtifactPosition::SHOULDERS, + ArtifactPosition::NECK, + ArtifactPosition::RIGHT_HAND, + ArtifactPosition::LEFT_HAND, + ArtifactPosition::TORSO, + ArtifactPosition::RIGHT_RING, + ArtifactPosition::LEFT_RING, + ArtifactPosition::FEET, + ArtifactPosition::MISC1, + ArtifactPosition::MISC2, + ArtifactPosition::MISC3, + ArtifactPosition::MISC4, + ArtifactPosition::MISC5, + }; +} + DLL_LINKAGE bool ArtifactUtils::isArtRemovable(const std::pair & slot) { return slot.second.artifact && !slot.second.locked - && !vstd::contains(unmovableSlots, slot.first); + && !vstd::contains(unmovableSlots(), slot.first); } DLL_LINKAGE bool ArtifactUtils::checkSpellbookIsNeeded(const CGHeroInstance * heroPtr, ArtifactID artID, ArtifactPosition slot) diff --git a/lib/CArtHandler.h b/lib/CArtHandler.h index a631a6036..70a8bc5c7 100644 --- a/lib/CArtHandler.h +++ b/lib/CArtHandler.h @@ -386,28 +386,9 @@ namespace ArtifactUtils DLL_LINKAGE ArtifactPosition getArtifactDstPosition( const CArtifactInstance * artifact, const CArtifactSet * target, ArtBearer::ArtBearer bearer); - const std::array unmovableSlots = - { - ArtifactPosition::SPELLBOOK, - ArtifactPosition::MACH4 - }; - const std::array constituentWornSlots = - { - ArtifactPosition::HEAD, - ArtifactPosition::SHOULDERS, - ArtifactPosition::NECK, - ArtifactPosition::RIGHT_HAND, - ArtifactPosition::LEFT_HAND, - ArtifactPosition::TORSO, - ArtifactPosition::RIGHT_RING, - ArtifactPosition::LEFT_RING, - ArtifactPosition::FEET, - ArtifactPosition::MISC1, - ArtifactPosition::MISC2, - ArtifactPosition::MISC3, - ArtifactPosition::MISC4, - ArtifactPosition::MISC5, - }; + // TODO: Make this constexpr when the toolset is upgraded + DLL_LINKAGE const std::vector & unmovableSlots(); + DLL_LINKAGE const std::vector & constituentWornSlots(); DLL_LINKAGE bool isArtRemovable(const std::pair & slot); DLL_LINKAGE bool checkSpellbookIsNeeded(const CGHeroInstance * heroPtr, ArtifactID artID, ArtifactPosition slot); DLL_LINKAGE bool isSlotBackpack(ArtifactPosition slot); diff --git a/lib/GameConstants.h b/lib/GameConstants.h index 09eedddf8..068fbfd90 100644 --- a/lib/GameConstants.h +++ b/lib/GameConstants.h @@ -1054,6 +1054,14 @@ public: ID_LIKE_CLASS_COMMON(ArtifactID, EArtifactID) EArtifactID num; + + struct hash + { + size_t operator()(const ArtifactID & aid) const + { + return std::hash()(aid.num); + } + }; }; ID_LIKE_OPERATORS(ArtifactID, ArtifactID::EArtifactID) diff --git a/lib/mapObjects/CQuest.h b/lib/mapObjects/CQuest.h index 31e2c6af0..12312bac3 100644 --- a/lib/mapObjects/CQuest.h +++ b/lib/mapObjects/CQuest.h @@ -15,25 +15,13 @@ #include "../CCreatureSet.h" #include "../NetPacksBase.h" -namespace std -{ - // Used in std::unordered_map - template<> struct hash - { - size_t operator()(const VCMI_LIB_WRAP_NAMESPACE(ArtifactID) & aid) const - { - return hash{}(aid.num); - } - }; -} - VCMI_LIB_NAMESPACE_BEGIN class CGCreature; class DLL_LINKAGE CQuest final { - mutable std::unordered_map artifactsRequirements; // artifact ID -> required count + mutable std::unordered_map artifactsRequirements; // artifact ID -> required count public: enum Emission {MISSION_NONE = 0, MISSION_LEVEL = 1, MISSION_PRIMARY_STAT = 2, MISSION_KILL_HERO = 3, MISSION_KILL_CREATURE = 4,