Browse Source

Create heroes in pool via handler to properly initialize appearance

Ivan Savenko 4 months ago
parent
commit
6d359e4112
2 changed files with 5 additions and 2 deletions
  1. 1 0
      lib/gameState/CGameState.cpp
  2. 4 2
      lib/mapping/MapFormatH3M.cpp

+ 1 - 0
lib/gameState/CGameState.cpp

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

+ 4 - 2
lib/mapping/MapFormatH3M.cpp

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