浏览代码

Fixes for handling starting spells / spellbook.

Michał W. Urbańczyk 16 年之前
父节点
当前提交
670a408fab
共有 2 个文件被更改,包括 15 次插入6 次删除
  1. 8 4
      hch/CObjectHandler.cpp
  2. 7 2
      lib/map.cpp

+ 8 - 4
hch/CObjectHandler.cpp

@@ -660,12 +660,16 @@ void CGHeroInstance::initHero()
 		initHeroDefInfo();
 	if(!type)
 		type = VLC->heroh->heroes[subID];
-	artifWorn[16] = 3;
-	if(type->startingSpell >= 0) //hero starts with a spell
-	{
-		artifWorn[17] = 0; //give him spellbook
+	if(!vstd::contains(spells, 0xffffffff) && type->startingSpell >= 0) //hero starts with a spell
 		spells.insert(type->startingSpell);
+	else //remove placeholder
+		spells -= 0xffffffff;
+
+	if(!vstd::contains(artifWorn, 16) && type->startingSpell >= 0) //no catapult means we haven't read pre-existant set
+	{
+		artifWorn[17] = 0; //give spellbook
 	}
+	artifWorn[16] = 3; //everyone has a catapult
 
 	if(portrait < 0 || portrait == 255)
 		portrait = subID;

+ 7 - 2
lib/map.cpp

@@ -981,6 +981,8 @@ void Mapa::loadHero( CGObjectInstance * &nobj, unsigned char * bufor, int &i )
 			int id = readNormalNr(bufor,i, artidlen); i+=artidlen;
 			if(id!=artmask)
 				nhi->artifWorn[16] = id;
+			else
+				nhi->artifWorn[16] = 3; //catapult by default
 		}
 		//spellbook
 		int id = readNormalNr(bufor,i, artidlen); i+=artidlen;
@@ -1027,6 +1029,7 @@ void Mapa::loadHero( CGObjectInstance * &nobj, unsigned char * bufor, int &i )
 
 		if(areSpells) //TODO: sprawdziæ //seems to be ok - tow
 		{
+			nhi->spells.insert(0xffffffff); //placeholder "preset spells"
 			int ist = i;
 			for(i; i<ist+9; ++i)
 			{
@@ -1045,9 +1048,11 @@ void Mapa::loadHero( CGObjectInstance * &nobj, unsigned char * bufor, int &i )
 	else if(version==AB) //we can read one spell
 	{
 		unsigned char buff = bufor[i]; ++i;
-		if(buff!=254)
+		if(buff != 254)
 		{
-			nhi->spells.insert(buff);
+			nhi->spells.insert(0xffffffff); //placeholder "preset spells"
+			if(buff < 254) //255 means no spells
+				nhi->spells.insert(buff);
 		}
 	}
 	//spells loaded