소스 검색

- Fixed hero / army strength handling

beegee1 11 년 전
부모
커밋
5971ceaa7f
3개의 변경된 파일17개의 추가작업 그리고 6개의 파일을 삭제
  1. 1 1
      AI/VCAI/VCAI.cpp
  2. 12 3
      lib/CObjectHandler.cpp
  3. 4 2
      lib/CObjectHandler.h

+ 1 - 1
AI/VCAI/VCAI.cpp

@@ -309,7 +309,7 @@ void VCAI::heroExchangeStarted(ObjectInstanceID hero1, ObjectInstanceID hero2, Q
 
 	requestActionASAP([=]()
 	{
-		if (firstHero->getHeroStrength() > secondHero->getHeroStrength() && canGetArmy (firstHero, secondHero))
+		if (firstHero->getFightingStrength() > secondHero->getFightingStrength() && canGetArmy (firstHero, secondHero))
 			pickBestCreatures (firstHero, secondHero);
 		else if (canGetArmy (secondHero, firstHero))
 			pickBestCreatures (secondHero, firstHero);

+ 12 - 3
lib/CObjectHandler.cpp

@@ -1362,15 +1362,24 @@ void CGHeroInstance::setPropertyDer( ui8 what, ui32 val )
 		setStackCount(SlotID(0), val);
 }
 
+double CGHeroInstance::getFightingStrength() const
+{
+	return sqrt((1.0 + 0.05*getPrimSkillLevel(PrimarySkill::ATTACK)) * (1.0 + 0.05*getPrimSkillLevel(PrimarySkill::DEFENSE)));
+}
+
+double CGHeroInstance::getMagicStrength() const
+{
+	return sqrt((1.0 + 0.05*getPrimSkillLevel(PrimarySkill::KNOWLEDGE)) * (1.0 + 0.05*getPrimSkillLevel(PrimarySkill::SPELL_POWER)));
+}
+
 double CGHeroInstance::getHeroStrength() const
 {
-	return sqrt((1.0 + 0.05*getPrimSkillLevel(PrimarySkill::ATTACK)) * (1.0 + 0.05*getPrimSkillLevel(PrimarySkill::DEFENSE)) *
-				(1.0 + 0.05*getPrimSkillLevel(PrimarySkill::KNOWLEDGE)) * (1.0 + 0.05*getPrimSkillLevel(PrimarySkill::SPELL_POWER)));
+	return sqrt(pow(getFightingStrength(), 2.0) * pow(getMagicStrength(), 2.0));
 }
 
 ui64 CGHeroInstance::getTotalStrength() const
 {
-	double ret = getHeroStrength() * getArmyStrength();
+	double ret = getFightingStrength() * getArmyStrength();
 	return (ui64) ret;
 }
 

+ 4 - 2
lib/CObjectHandler.h

@@ -423,8 +423,10 @@ public:
 
 	//int getSpellSecLevel(int spell) const; //returns level of secondary ability (fire, water, earth, air magic) known to this hero and applicable to given spell; -1 if error
 	static int3 convertPosition(int3 src, bool toh3m); //toh3m=true: manifest->h3m; toh3m=false: h3m->manifest
-	double getHeroStrength() const;
-	ui64 getTotalStrength() const;
+	double getFightingStrength() const; // takes attack / defense skill into account
+	double getMagicStrength() const; // takes knowledge / spell power skill into account
+	double getHeroStrength() const; // includes fighting and magic strength
+	ui64 getTotalStrength() const; // includes fighting strength and army strength
 	TExpType calculateXp(TExpType exp) const; //apply learning skill
 	ui8 getSpellSchoolLevel(const CSpell * spell, int *outSelectedSchool = nullptr) const; //returns level on which given spell would be cast by this hero (0 - none, 1 - basic etc); optionally returns number of selected school by arg - 0 - air magic, 1 - fire magic, 2 - water magic, 3 - earth magic,
 	bool canCastThisSpell(const CSpell * spell) const; //determines if this hero can cast given spell; takes into account existing spell in spellbook, existing spellbook and artifact bonuses