Selaa lähdekoodia

Added workaround for loading spellbook existance status

Ivan Savenko 2 vuotta sitten
vanhempi
sitoutus
cc91be3518
3 muutettua tiedostoa jossa 14 lisäystä ja 3 poistoa
  1. 1 0
      lib/GameConstants.h
  2. 10 3
      lib/mapObjects/CGHeroInstance.cpp
  3. 3 0
      lib/mapping/MapFormatH3M.cpp

+ 1 - 0
lib/GameConstants.h

@@ -1223,6 +1223,7 @@ class SpellID
 public:
 	enum ESpellID
 	{
+		SPELLBOOK_PRESET = -3,
 		PRESET = -2,
 		NONE = -1,
 		SUMMON_BOAT=0, SCUTTLE_BOAT=1, VISIONS=2, VIEW_EARTH=3, DISGUISE=4, VIEW_AIR=5,

+ 10 - 3
lib/mapObjects/CGHeroInstance.cpp

@@ -287,16 +287,23 @@ void CGHeroInstance::initHero(CRandomGenerator & rand)
 	if (ID == Obj::HERO)
 		appearance = VLC->objtypeh->getHandlerFor(Obj::HERO, type->heroClass->getIndex())->getTemplates().front();
 
-	if(!vstd::contains(spells, SpellID::PRESET)) //hero starts with a spell
+	if(!vstd::contains(spells, SpellID::PRESET))
 	{
+		// hero starts with default spells
 		for(const auto & spellID : type->spells)
 			spells.insert(spellID);
 	}
 	else //remove placeholder
 		spells -= SpellID::PRESET;
 
-	if(!getArt(ArtifactPosition::MACH4) && !getArt(ArtifactPosition::SPELLBOOK) && type->haveSpellBook) //no catapult means we haven't read pre-existent set -> use default rules for spellbook
-		putArtifact(ArtifactPosition::SPELLBOOK, ArtifactUtils::createNewArtifactInstance(ArtifactID::SPELLBOOK));
+	if(!vstd::contains(spells, SpellID::SPELLBOOK_PRESET))
+	{
+		// hero starts with default spellbook presence status
+		if(!getArt(ArtifactPosition::SPELLBOOK) && type->haveSpellBook)
+			putArtifact(ArtifactPosition::SPELLBOOK, ArtifactUtils::createNewArtifactInstance(ArtifactID::SPELLBOOK));
+	}
+	else
+		spells -= SpellID::SPELLBOOK_PRESET;
 
 	if(!getArt(ArtifactPosition::MACH4))
 		putArtifact(ArtifactPosition::MACH4, ArtifactUtils::createNewArtifactInstance(ArtifactID::CATAPULT)); //everyone has a catapult

+ 3 - 0
lib/mapping/MapFormatH3M.cpp

@@ -878,6 +878,9 @@ void CMapLoaderH3M::loadArtifactsOfHero(CGHeroInstance * hero)
 	if(!hasArtSet)
 		return;
 
+	// Workaround - if hero has customized artifacts game should not attempt to add spellbook based on hero type
+	hero->spells.insert(SpellID::SPELLBOOK_PRESET);
+
 	if(!hero->artifactsWorn.empty() || !hero->artifactsInBackpack.empty())
 	{
 		logGlobal->warn("Hero %s at %s has set artifacts twice (in map properties and on adventure map instance). Using the latter set...", hero->getNameTranslated(), hero->pos.toString());