1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-23 22:37:55 +02:00

Create heroes in pool via handler to properly initialize appearance

This commit is contained in:
Ivan Savenko
2025-06-17 14:36:17 +03:00
parent a7732db0fe
commit 6d359e4112
2 changed files with 5 additions and 2 deletions

View File

@@ -554,6 +554,7 @@ void CGameState::placeStartingHero(const PlayerColor & playerColor, const HeroTy
hero = std::dynamic_pointer_cast<CGHeroInstance>(object);
hero->ID = Obj::HERO;
hero->setHeroType(heroTypeId);
assert(hero->appearance != nullptr);
}
hero->tempOwner = playerColor;

View File

@@ -42,6 +42,7 @@
#include "../networkPacks/ArtifactLocation.h"
#include "../spells/CSpellHandler.h"
#include "../texts/TextOperations.h"
#include "entities/hero/CHeroClass.h"
VCMI_LIB_NAMESPACE_BEGIN
@@ -843,8 +844,9 @@ void CMapLoaderH3M::readPredefinedHeroes()
if(!custom)
continue;
auto hero = std::make_shared<CGHeroInstance>(map->cb);
hero->ID = Obj::HERO;
auto handler = LIBRARY->objtypeh->getHandlerFor(Obj::HERO, HeroTypeID(heroID).toHeroType()->heroClass->getIndex());
auto object = handler->create(map->cb, handler->getTemplates().front());
auto hero = std::dynamic_pointer_cast<CGHeroInstance>(object);
hero->subID = heroID;
bool hasExp = reader->readBool();