diff --git a/client/windows/CCastleInterface.cpp b/client/windows/CCastleInterface.cpp index a894a752d..5bce62993 100644 --- a/client/windows/CCastleInterface.cpp +++ b/client/windows/CCastleInterface.cpp @@ -1944,7 +1944,7 @@ CBlacksmithDialog::CBlacksmithDialog(bool possible, CreatureID creMachineID, Art cancelText.appendTextID("core.genrltxt.596"); cancelText.replaceTextID(creature->getNameSingularTextID()); - std::string costString = std::to_string(aid.toEntity(CGI->artifacts())->getPrice()); + std::string costString = std::to_string(aid.toEntity(CGI)->getPrice()); title = std::make_shared(165, 28, FONT_BIG, ETextAlignment::CENTER, Colors::YELLOW, titleString.toString()); costText = std::make_shared(165, 218, FONT_MEDIUM, ETextAlignment::CENTER, Colors::WHITE, CGI->generaltexth->jktexts[43]); diff --git a/lib/MetaString.cpp b/lib/MetaString.cpp index b56705ffe..bd02386f2 100644 --- a/lib/MetaString.cpp +++ b/lib/MetaString.cpp @@ -114,35 +114,35 @@ std::string MetaString::getLocalString(const std::pair & txt) c { case EMetaText::ART_NAMES: { - const auto * art = ArtifactID(ser).toEntity(VLC->artifacts()); + const auto * art = ArtifactID(ser).toEntity(VLC); if(art) return art->getNameTranslated(); return "#!#"; } case EMetaText::ART_DESCR: { - const auto * art = ArtifactID(ser).toEntity(VLC->artifacts()); + const auto * art = ArtifactID(ser).toEntity(VLC); if(art) return art->getDescriptionTranslated(); return "#!#"; } case EMetaText::ART_EVNTS: { - const auto * art = ArtifactID(ser).toEntity(VLC->artifacts()); + const auto * art = ArtifactID(ser).toEntity(VLC); if(art) return art->getEventTranslated(); return "#!#"; } case EMetaText::CRE_PL_NAMES: { - const auto * cre = CreatureID(ser).toEntity(VLC->creatures()); + const auto * cre = CreatureID(ser).toEntity(VLC); if(cre) return cre->getNamePluralTranslated(); return "#!#"; } case EMetaText::CRE_SING_NAMES: { - const auto * cre = CreatureID(ser).toEntity(VLC->creatures()); + const auto * cre = CreatureID(ser).toEntity(VLC); if(cre) return cre->getNameSingularTranslated(); return "#!#"; @@ -157,7 +157,7 @@ std::string MetaString::getLocalString(const std::pair & txt) c } case EMetaText::SPELL_NAME: { - const auto * spell = SpellID(ser).toEntity(VLC->spells()); + const auto * spell = SpellID(ser).toEntity(VLC); if(spell) return spell->getNameTranslated(); return "#!#"; diff --git a/lib/bonuses/Bonus.cpp b/lib/bonuses/Bonus.cpp index 6fe775536..39c0c1c44 100644 --- a/lib/bonuses/Bonus.cpp +++ b/lib/bonuses/Bonus.cpp @@ -100,13 +100,13 @@ std::string Bonus::Description(std::optional customValue) const switch(source) { case BonusSource::ARTIFACT: - str << sid.as().toEntity(VLC->artifacts())->getNameTranslated(); + str << sid.as().toEntity(VLC)->getNameTranslated(); break; case BonusSource::SPELL_EFFECT: - str << sid.as().toEntity(VLC->spells())->getNameTranslated(); + str << sid.as().toEntity(VLC)->getNameTranslated(); break; case BonusSource::CREATURE_ABILITY: - str << sid.as().toEntity(VLC->creatures())->getNamePluralTranslated(); + str << sid.as().toEntity(VLC)->getNamePluralTranslated(); break; case BonusSource::SECONDARY_SKILL: str << VLC->skills()->getById(sid.as())->getNameTranslated(); diff --git a/lib/constants/EntityIdentifiers.cpp b/lib/constants/EntityIdentifiers.cpp index 6b343f2b0..6ad6f37a1 100644 --- a/lib/constants/EntityIdentifiers.cpp +++ b/lib/constants/EntityIdentifiers.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include #include @@ -192,12 +193,12 @@ std::string HeroTypeID::entityType() const CArtifact * ArtifactIDBase::toArtifact() const { - return dynamic_cast(toEntity(VLC->artifacts())); + return dynamic_cast(toEntity(VLC)); } -const Artifact * ArtifactIDBase::toEntity(const ArtifactService * service) const +const Artifact * ArtifactIDBase::toEntity(const Services * services) const { - return service->getByIndex(num); + return services->artifacts()->getByIndex(num); } si32 ArtifactID::decode(const std::string & identifier) @@ -238,6 +239,11 @@ const CCreature * CreatureIDBase::toCreature() const return VLC->creh->objects.at(num); } +const Creature * CreatureIDBase::toEntity(const Services * services) const +{ + return toEntity(services->creatures()); +} + const Creature * CreatureIDBase::toEntity(const CreatureService * creatures) const { return creatures->getByIndex(num); @@ -272,6 +278,11 @@ const CSpell * SpellIDBase::toSpell() const return VLC->spellh->objects[num]; } +const spells::Spell * SpellIDBase::toEntity(const Services * services) const +{ + return toEntity(services->spells()); +} + const spells::Spell * SpellIDBase::toEntity(const spells::Service * service) const { return service->getByIndex(num); @@ -279,12 +290,12 @@ const spells::Spell * SpellIDBase::toEntity(const spells::Service * service) con const CHero * HeroTypeID::toHeroType() const { - return dynamic_cast(toEntity(VLC->heroTypes())); + return dynamic_cast(toEntity(VLC)); } -const HeroType * HeroTypeID::toEntity(const HeroTypeService * service) const +const HeroType * HeroTypeID::toEntity(const Services * services) const { - return service->getByIndex(num); + return services->heroTypes()->getByIndex(num); } si32 SpellID::decode(const std::string & identifier) diff --git a/lib/constants/EntityIdentifiers.h b/lib/constants/EntityIdentifiers.h index ed6d46435..f7aad1cdd 100644 --- a/lib/constants/EntityIdentifiers.h +++ b/lib/constants/EntityIdentifiers.h @@ -14,6 +14,7 @@ VCMI_LIB_NAMESPACE_BEGIN +class Services; class Artifact; class ArtifactService; class Creature; @@ -190,7 +191,7 @@ public: static std::string entityType(); const CHero * toHeroType() const; - const HeroType * toEntity(const HeroTypeService * service) const; + const HeroType * toEntity(const Services * services) const; DLL_LINKAGE static const HeroTypeID NONE; DLL_LINKAGE static const HeroTypeID RANDOM; @@ -681,7 +682,7 @@ public: }; DLL_LINKAGE const CArtifact * toArtifact() const; - DLL_LINKAGE const Artifact * toEntity(const ArtifactService * service) const; + DLL_LINKAGE const Artifact * toEntity(const Services * service) const; }; class ArtifactID : public IdentifierWithEnum @@ -721,6 +722,7 @@ public: }; DLL_LINKAGE const CCreature * toCreature() const; + DLL_LINKAGE const Creature * toEntity(const Services * services) const; DLL_LINKAGE const Creature * toEntity(const CreatureService * creatures) const; }; @@ -839,6 +841,7 @@ public: }; const CSpell * toSpell() const; //deprecated + const spells::Spell * toEntity(const Services * service) const; const spells::Spell * toEntity(const spells::Service * service) const; }; diff --git a/lib/gameState/CGameState.cpp b/lib/gameState/CGameState.cpp index 2287c2089..dac105832 100644 --- a/lib/gameState/CGameState.cpp +++ b/lib/gameState/CGameState.cpp @@ -760,7 +760,7 @@ void CGameState::initStartingBonus() logGlobal->error("Cannot give starting artifact - no heroes!"); break; } - const Artifact * toGive = VLC->arth->pickRandomArtifact(getRandomGenerator(), CArtifact::ART_TREASURE).toEntity(VLC->artifacts()); + const Artifact * toGive = VLC->arth->pickRandomArtifact(getRandomGenerator(), CArtifact::ART_TREASURE).toEntity(VLC); CGHeroInstance *hero = elem.second.heroes[0]; if(!giveHeroArtifact(hero, toGive->getId())) diff --git a/lib/mapObjects/CArmedInstance.cpp b/lib/mapObjects/CArmedInstance.cpp index 4f4ce64e7..baf878870 100644 --- a/lib/mapObjects/CArmedInstance.cpp +++ b/lib/mapObjects/CArmedInstance.cpp @@ -73,7 +73,7 @@ void CArmedInstance::updateMoraleBonusFromArmy() for(const auto & slot : Slots()) { const CStackInstance * inst = slot.second; - const auto * creature = inst->getCreatureID().toEntity(VLC->creatures()); + const auto * creature = inst->getCreatureID().toEntity(VLC); factions.insert(creature->getFaction()); // Check for undead flag instead of faction (undead mummies are neutral) diff --git a/lib/mapObjects/CBank.cpp b/lib/mapObjects/CBank.cpp index 590e4760b..ae8fc22d0 100644 --- a/lib/mapObjects/CBank.cpp +++ b/lib/mapObjects/CBank.cpp @@ -314,7 +314,7 @@ void CBank::doVisit(const CGHeroInstance * hero) const } for(const SpellID & spellId : bc->spells) { - const auto * spell = spellId.toEntity(VLC->spells()); + const auto * spell = spellId.toEntity(VLC); iw.text.appendLocalString(EMetaText::SPELL_NAME, spellId); if(spell->getLevel() <= hero->maxSpellLevel()) { diff --git a/lib/mapping/MapFormatH3M.cpp b/lib/mapping/MapFormatH3M.cpp index ae2e84c60..5bd59ca3b 100644 --- a/lib/mapping/MapFormatH3M.cpp +++ b/lib/mapping/MapFormatH3M.cpp @@ -926,7 +926,7 @@ bool CMapLoaderH3M::loadArtifactToSlot(CGHeroInstance * hero, int slot) if(artifactID == ArtifactID::NONE) return false; - const Artifact * art = artifactID.toEntity(VLC->artifacts()); + const Artifact * art = artifactID.toEntity(VLC); if(!art) { diff --git a/lib/rewardable/Limiter.cpp b/lib/rewardable/Limiter.cpp index 103d4ad79..05c77909a 100644 --- a/lib/rewardable/Limiter.cpp +++ b/lib/rewardable/Limiter.cpp @@ -128,7 +128,7 @@ bool Rewardable::Limiter::heroAllowed(const CGHeroInstance * hero) const for(const auto & spell : canLearnSpells) { - if (!hero->canLearnSpell(spell.toEntity(VLC->spells()), true)) + if (!hero->canLearnSpell(spell.toEntity(VLC), true)) return false; } diff --git a/lib/spells/ISpellMechanics.h b/lib/spells/ISpellMechanics.h index e3185acd9..2a0f8603d 100644 --- a/lib/spells/ISpellMechanics.h +++ b/lib/spells/ISpellMechanics.h @@ -23,6 +23,7 @@ VCMI_LIB_NAMESPACE_BEGIN struct Query; class IBattleState; class CRandomGenerator; +class CreatureService; class CMap; class CGameInfoCallback; class CBattleInfoCallback; @@ -32,6 +33,11 @@ class CStack; class CGObjectInstance; class CGHeroInstance; +namespace spells +{ +class Service; +} + namespace vstd { class RNG;