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

added toEntity overload that accepts generic Services class

This commit is contained in:
Ivan Savenko 2023-11-04 17:04:53 +02:00
parent 04aeea9b68
commit 5487f07d3b
11 changed files with 43 additions and 23 deletions

View File

@ -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<CLabel>(165, 28, FONT_BIG, ETextAlignment::CENTER, Colors::YELLOW, titleString.toString());
costText = std::make_shared<CLabel>(165, 218, FONT_MEDIUM, ETextAlignment::CENTER, Colors::WHITE, CGI->generaltexth->jktexts[43]);

View File

@ -114,35 +114,35 @@ std::string MetaString::getLocalString(const std::pair<EMetaText, ui32> & 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<EMetaText, ui32> & 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 "#!#";

View File

@ -100,13 +100,13 @@ std::string Bonus::Description(std::optional<si32> customValue) const
switch(source)
{
case BonusSource::ARTIFACT:
str << sid.as<ArtifactID>().toEntity(VLC->artifacts())->getNameTranslated();
str << sid.as<ArtifactID>().toEntity(VLC)->getNameTranslated();
break;
case BonusSource::SPELL_EFFECT:
str << sid.as<SpellID>().toEntity(VLC->spells())->getNameTranslated();
str << sid.as<SpellID>().toEntity(VLC)->getNameTranslated();
break;
case BonusSource::CREATURE_ABILITY:
str << sid.as<CreatureID>().toEntity(VLC->creatures())->getNamePluralTranslated();
str << sid.as<CreatureID>().toEntity(VLC)->getNamePluralTranslated();
break;
case BonusSource::SECONDARY_SKILL:
str << VLC->skills()->getById(sid.as<SecondarySkill>())->getNameTranslated();

View File

@ -21,6 +21,7 @@
#include <vcmi/HeroTypeService.h>
#include <vcmi/HeroClass.h>
#include <vcmi/HeroClassService.h>
#include <vcmi/Services.h>
#include <vcmi/spells/Spell.h>
#include <vcmi/spells/Service.h>
@ -192,12 +193,12 @@ std::string HeroTypeID::entityType()
const CArtifact * ArtifactIDBase::toArtifact() const
{
return dynamic_cast<const CArtifact*>(toEntity(VLC->artifacts()));
return dynamic_cast<const CArtifact*>(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<const CHero*>(toEntity(VLC->heroTypes()));
return dynamic_cast<const CHero*>(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)

View File

@ -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<ArtifactID, ArtifactIDBase>
@ -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;
};

View File

@ -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()))

View File

@ -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)

View File

@ -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())
{

View File

@ -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)
{

View File

@ -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;
}

View File

@ -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;