From 5971ceaa7fb4b54f0ddbe737c74f5258ae4147fe Mon Sep 17 00:00:00 2001 From: beegee1 Date: Tue, 31 Dec 2013 16:11:18 +0000 Subject: [PATCH] - Fixed hero / army strength handling --- AI/VCAI/VCAI.cpp | 2 +- lib/CObjectHandler.cpp | 15 ++++++++++++--- lib/CObjectHandler.h | 6 ++++-- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/AI/VCAI/VCAI.cpp b/AI/VCAI/VCAI.cpp index ed821cb1d..fe761dc9b 100644 --- a/AI/VCAI/VCAI.cpp +++ b/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); diff --git a/lib/CObjectHandler.cpp b/lib/CObjectHandler.cpp index 33fb40943..265af6a26 100644 --- a/lib/CObjectHandler.cpp +++ b/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; } diff --git a/lib/CObjectHandler.h b/lib/CObjectHandler.h index 7d896c900..eb2c24244 100644 --- a/lib/CObjectHandler.h +++ b/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