1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-22 03:39:45 +02:00

Added overloaded version of getObjectHandler to CGHeroInstance

This commit is contained in:
Ivan Savenko 2024-10-13 13:06:31 +00:00
parent 184d8de82e
commit ad7f0416a7
5 changed files with 18 additions and 5 deletions

View File

@ -370,7 +370,7 @@ void CGameStateCampaign::replaceHeroesPlaceholders()
heroToPlace->tempOwner = heroPlaceholder->tempOwner;
heroToPlace->setAnchorPos(heroPlaceholder->anchorPos());
heroToPlace->setHeroType(heroToPlace->getHeroTypeID());
heroToPlace->appearance = VLC->objtypeh->getHandlerFor(Obj::HERO, heroToPlace->getHeroTypeID())->getTemplates().front();
heroToPlace->appearance = heroToPlace->getObjectHandler()->getTemplates().front();
gameState->map->removeBlockVisTiles(heroPlaceholder, true);
gameState->map->objects[heroPlaceholder->id.getNum()] = nullptr;

View File

@ -339,12 +339,20 @@ void CGHeroInstance::initHero(vstd::RNG & rand, const HeroTypeID & SUBID)
initHero(rand);
}
TObjectTypeHandler CGHeroInstance::getObjectHandler() const
{
if (ID == Obj::HERO)
return VLC->objtypeh->getHandlerFor(ID, getHeroClass()->getIndex());
else // prison or random hero
return VLC->objtypeh->getHandlerFor(ID, 0);
}
void CGHeroInstance::initHero(vstd::RNG & rand)
{
assert(validTypes(true));
if (ID == Obj::HERO)
appearance = VLC->objtypeh->getHandlerFor(Obj::HERO, getHeroClass()->getIndex())->getTemplates().front();
appearance = getObjectHandler()->getTemplates().front();
if(!vstd::contains(spells, SpellID::PRESET))
{

View File

@ -307,6 +307,8 @@ public:
std::string getHoverText(PlayerColor player) const override;
std::string getMovementPointsTextIfOwner(PlayerColor player) const;
TObjectTypeHandler getObjectHandler() const override;
void afterAddToMap(CMap * map) override;
void afterRemoveFromMap(CMap * map) override;

View File

@ -360,8 +360,11 @@ void CGObjectInstance::serializeJson(JsonSerializeFormat & handler)
//only save here, loading is handled by map loader
if(handler.saving)
{
handler.serializeString("type", typeName);
handler.serializeString("subtype", subTypeName);
std::string ourTypeName = getTypeName();
std::string ourSubtypeName = getSubtypeName();
handler.serializeString("type", ourTypeName);
handler.serializeString("subtype", ourSubtypeName);
handler.serializeInt("x", pos.x);
handler.serializeInt("y", pos.y);

View File

@ -101,7 +101,7 @@ public:
std::optional<AudioPath> getVisitSound(vstd::RNG & rng) const;
std::optional<AudioPath> getRemovalSound(vstd::RNG & rng) const;
TObjectTypeHandler getObjectHandler() const;
virtual TObjectTypeHandler getObjectHandler() const;
/** VIRTUAL METHODS **/