瀏覽代碼

Hero speciality in creatures (growing with level) is now ready.

Fixed Tree of Knowledge giving only 2^31 XP.
DjWarmonger 15 年之前
父節點
當前提交
ab8e24c490
共有 6 個文件被更改,包括 55 次插入68 次删除
  1. 1 0
      global.h
  2. 0 1
      hch/CHeroHandler.h
  3. 51 29
      hch/CObjectHandler.cpp
  4. 2 1
      hch/CObjectHandler.h
  5. 0 1
      lib/HeroBonus.h
  6. 1 36
      lib/NetPacksLib.cpp

+ 1 - 0
global.h

@@ -14,6 +14,7 @@ typedef boost::int64_t si64; //signed int 64 bits (8 bytes)
 typedef boost::int32_t si32; //signed int 32 bits (4 bytes)
 typedef boost::int16_t si16; //signed int 16 bits (2 bytes)
 typedef boost::int8_t si8; //signed int 8 bits (1 byte)
+typedef si64 expType;
 #include "int3.h"
 #include <map>
 #include <vector>

+ 0 - 1
hch/CHeroHandler.h

@@ -14,7 +14,6 @@
  * Full text of license available in license.txt file, in main folder
  *
  */
-
 class CHeroClass;
 class CDefHandler;
 class CGameInfo;

+ 51 - 29
hch/CObjectHandler.cpp

@@ -975,10 +975,6 @@ void CGHeroInstance::initObj()
 				{
 					speciality.growthsWithLevel = true;
 
-					bonus.type = Bonus::SPECIAL_CREATURE_LEV; // general info to indicate type of growing bonus
-					bonus.additionalInfo = it->additionalinfo; //base creature ID
-					speciality.bonuses.push_back (bonus);
-
 					const CCreature &specCreature = *VLC->creh->creatures[it->additionalinfo]; //creature in which we have specialty
 
 					int creLevel = specCreature.level;
@@ -993,40 +989,21 @@ void CGHeroInstance::initObj()
 						}
 					}
 
-					int levelFactor = level / creLevel; //round down
-					double primSkillModifier = levelFactor / 20.0;
-
-					bonus.limiter = new CCreatureTypeLimiter(specCreature);
+					bonus.limiter = new CCreatureTypeLimiter (specCreature, true); //with upgrades
 					bonus.type = Bonus::PRIMARY_SKILL; 
+					bonus.additionalInfo = it->additionalinfo;
 					bonus.valType = Bonus::ADDITIVE_VALUE;
 
 					bonus.subtype = PrimarySkill::ATTACK;
-					bonus.val = std::ceil(primSkillModifier * specCreature.attack);
 					speciality.bonuses.push_back (bonus);
 
 					bonus.subtype = PrimarySkill::DEFENSE;
-					bonus.val = std::ceil(primSkillModifier * specCreature.defence);
 					speciality.bonuses.push_back (bonus);
+					//values will be calculated later
 
 					bonus.type = Bonus::STACKS_SPEED;
 					bonus.val = 1; //+1 speed
 					speciality.bonuses.push_back (bonus);
-
-// 					for (std::set<ui32>::iterator i = (*creatures)[it->additionalinfo]->upgrades.begin();
-// 						i != VLC->creh->creatures[it->additionalinfo]->upgrades.end(); i++)
-// 					{
-// 						bonus.val = (*i); // for all direct upgrades of that creature
-// 						bonus.type = Bonus::PRIMARY_SKILL;
-// 						bonus.subtype = 1; //attack
-// 						bonus.val = level * (*creatures)[*i]->attack / (*creatures)[*i]->level /20;
-// 						speciality.bonuses.push_back (bonus);
-// 						bonus.subtype = 2; //defense
-// 						bonus.val = level * (*creatures)[*i]->defence / (*creatures)[*i]->level /20;
-// 						speciality.bonuses.push_back (bonus);
-// 						bonus.type = Bonus::STACKS_SPEED;
-// 						bonus.val = 1; //+1 speed
-// 						speciality.bonuses.push_back (bonus);
-// 					}
 				}
 				break;
 			case 2://secondary skill
@@ -1137,6 +1114,49 @@ void CGHeroInstance::initObj()
 				tlog2 << "Unexpected hero speciality " << type <<'\n';
 		}
 	}
+	UpdateSpeciality();
+}
+void CGHeroInstance::UpdateSpeciality()
+{
+	if (speciality.growthsWithLevel)
+	{
+		std::vector<CCreature*>* creatures = &VLC->creh->creatures;
+		for (std::list<Bonus>::iterator it = speciality.bonuses.begin(); it != speciality.bonuses.end(); it++)
+		{
+			switch (it->type)
+			{
+				case Bonus::SECONDARY_SKILL_PREMY:
+					it->val = (speciality.valOfBonuses(Bonus::SPECIAL_SECONDARY_SKILL, it->subtype) *
+						valOfBonuses(Bonus::SECONDARY_SKILL_PREMY, it->subtype) * level)/100;
+					break;
+				case Bonus::PRIMARY_SKILL: //for crearures, that is
+					int creLevel = (*creatures)[it->additionalInfo]->level;
+					if(!creLevel)
+					{
+						if(it->additionalInfo == 146)
+							creLevel = 5; //treat ballista as 5-level
+						else
+						{
+							tlog2 << "Warning: unknown level of " << (*creatures)[it->additionalInfo]->namePl << std::endl;
+							continue;
+						}
+					}
+
+					double primSkillModifier = (int)(level / creLevel) / 20.0;
+
+					switch (it->subtype)
+					{
+						case PrimarySkill::ATTACK:
+							it->val = (*creatures)[it->additionalInfo]->attack * primSkillModifier;
+						break;
+						case PrimarySkill::DEFENSE:
+							it->val = (*creatures)[it->additionalInfo]->defence * primSkillModifier;
+							break;
+					}
+					break;
+			}
+		}
+	}
 }
 void CGHeroInstance::setPropertyDer( ui8 what, ui32 val )
 {
@@ -2232,7 +2252,7 @@ void CGVisitableOPH::initObj()
 		ttype = -1;
 }
 
-void CGVisitableOPH::treeSelected( int heroID, int resType, int resVal, ui64 expVal, ui32 result ) const
+void CGVisitableOPH::treeSelected( int heroID, int resType, int resVal, expType expVal, ui32 result ) const
 {
 	if(result) //player agreed to give res for exp
 	{
@@ -2243,7 +2263,8 @@ void CGVisitableOPH::treeSelected( int heroID, int resType, int resVal, ui64 exp
 }
 void CGVisitableOPH::onNAHeroVisit(int heroID, bool alreadyVisited) const
 {
-	int id=0, subid=0, ot=0, val=1, sound = 0;
+	int id=0, subid=0, ot=0, sound = 0;
+	expType val=1;
 	switch(ID)
 	{
 	case 4: //arena
@@ -2355,7 +2376,8 @@ void CGVisitableOPH::onNAHeroVisit(int heroID, bool alreadyVisited) const
 				}
 				else
 				{
-					int res, resval;
+					ui32 res;
+					expType resval;
 					if(ttype==1)
 					{
 						res = 6;

+ 2 - 1
hch/CObjectHandler.h

@@ -381,6 +381,7 @@ public:
 	void giveArtifact (ui32 aid);
 	void initHeroDefInfo();
 	void pushPrimSkill(int which, int val);
+	void UpdateSpeciality();
 
 	CGHeroInstance();
 	virtual ~CGHeroInstance();
@@ -424,7 +425,7 @@ public:
 	void onHeroVisit(const CGHeroInstance * h) const;
 	void onNAHeroVisit(int heroID, bool alreadyVisited) const;
 	void initObj();
-	void treeSelected(int heroID, int resType, int resVal, ui64 expVal, ui32 result) const; //handle player's anwer to the Tree of Knowledge dialog
+	void treeSelected(int heroID, int resType, int resVal, expType expVal, ui32 result) const; //handle player's anwer to the Tree of Knowledge dialog
 	void schoolSelected(int heroID, ui32 which) const;
 	void arenaSelected(int heroID, int primSkill) const;
 

+ 0 - 1
lib/HeroBonus.h

@@ -148,7 +148,6 @@ namespace PrimarySkill
 	BONUS_NAME(NO_LUCK) /*eg. when fighting on cursed ground*/	\
 	BONUS_NAME(NO_MORALE) /*eg. when fighting on cursed ground*/ \
 	BONUS_NAME(DARKNESS) /*val = radius */ \
-	BONUS_NAME(SPECIAL_CREATURE_LEV) /*val = base id*/ \
 	BONUS_NAME(SPECIAL_SECONDARY_SKILL) /*val = id, additionalInfo = value per level in percent*/ \
 	BONUS_NAME(SPECIAL_SPELL_LEV) /*val = id, additionalInfo = value per level in percent*/\
 	BONUS_NAME(SPECIFIC_SPELL_DAMAGE) /*val = id of spell, additionalInfo = value*/\

+ 1 - 36
lib/NetPacksLib.cpp

@@ -707,42 +707,7 @@ DLL_EXPORT void HeroLevelUp::applyGs( CGameState *gs )
 	CGHeroInstance* h = gs->getHero(heroid);
 	h->level = level;
 	//speciality
-	if (h->speciality.growthsWithLevel)
-	{
-		std::vector<CCreature*>* creatures = &VLC->creh->creatures;
-		for (std::list<Bonus>::iterator it = h->speciality.bonuses.begin(); it != h->speciality.bonuses.end(); it++)
-		{
-			switch (it->type)
-			{
-				case Bonus::SECONDARY_SKILL_PREMY:
-					it->val = (h->speciality.valOfBonuses(Bonus::SPECIAL_SECONDARY_SKILL, it->subtype) *
-						h->valOfBonuses(Bonus::SECONDARY_SKILL_PREMY,it->subtype) * h->level)/100;
-				break;
-				case Bonus::PRIMARY_SKILL:
-					int creLevel = (*creatures)[it->additionalInfo]->level;
-					if(!creLevel)
-					{
-						if(it->additionalInfo == 146)
-							creLevel = 5; //treat ballista as 5-level
-						else
-						{
-							tlog2 << "Warning: unknown level of " << (*creatures)[it->val]->namePl << std::endl;
-							continue;
-						}
-					}
-					switch (it->subtype)
-					{
-					case 1:
-						it->val = (level * (*creatures)[it->additionalInfo]->attack)/creLevel /20;
-						break;
-					case 2:
-							it->val = (level * (*creatures)[it->additionalInfo]->defence)/creLevel /20;
-							break;
-					}
-					break;
-			}
-		}
-	}
+	h->UpdateSpeciality();
 }
 
 DLL_EXPORT void BattleStart::applyGs( CGameState *gs )