1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-12 02:28:11 +02:00

suggested changes

This commit is contained in:
SoundSSGood 2022-11-30 17:57:39 +02:00
parent 3bf0cfe4fa
commit 45a3064e5d
4 changed files with 45 additions and 37 deletions

View File

@ -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<ArtifactPosition::EArtifactPosition> & ArtifactUtils::unmovableSlots()
{
return
{
ArtifactPosition::SPELLBOOK,
ArtifactPosition::MACH4
};
}
DLL_LINKAGE const std::vector<ArtifactPosition::EArtifactPosition> & 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<ArtifactPosition, ArtSlotInfo> & 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)

View File

@ -386,28 +386,9 @@ namespace ArtifactUtils
DLL_LINKAGE ArtifactPosition getArtifactDstPosition( const CArtifactInstance * artifact,
const CArtifactSet * target,
ArtBearer::ArtBearer bearer);
const std::array<ArtifactPosition::EArtifactPosition, 2> unmovableSlots =
{
ArtifactPosition::SPELLBOOK,
ArtifactPosition::MACH4
};
const std::array<ArtifactPosition::EArtifactPosition, 14> 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<ArtifactPosition::EArtifactPosition> & unmovableSlots();
DLL_LINKAGE const std::vector<ArtifactPosition::EArtifactPosition> & constituentWornSlots();
DLL_LINKAGE bool isArtRemovable(const std::pair<ArtifactPosition, ArtSlotInfo> & slot);
DLL_LINKAGE bool checkSpellbookIsNeeded(const CGHeroInstance * heroPtr, ArtifactID artID, ArtifactPosition slot);
DLL_LINKAGE bool isSlotBackpack(ArtifactPosition slot);

View File

@ -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<int>()(aid.num);
}
};
};
ID_LIKE_OPERATORS(ArtifactID, ArtifactID::EArtifactID)

View File

@ -15,25 +15,13 @@
#include "../CCreatureSet.h"
#include "../NetPacksBase.h"
namespace std
{
// Used in std::unordered_map
template<> struct hash<VCMI_LIB_WRAP_NAMESPACE(ArtifactID)>
{
size_t operator()(const VCMI_LIB_WRAP_NAMESPACE(ArtifactID) & aid) const
{
return hash<int>{}(aid.num);
}
};
}
VCMI_LIB_NAMESPACE_BEGIN
class CGCreature;
class DLL_LINKAGE CQuest final
{
mutable std::unordered_map<ArtifactID, unsigned> artifactsRequirements; // artifact ID -> required count
mutable std::unordered_map<ArtifactID, unsigned, ArtifactID::hash> 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,