1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-28 08:48:48 +02:00

Fixed #855 & 861. Unsigned values were bad idea to prevent overflow.

This commit is contained in:
DjWarmonger 2012-02-20 16:26:14 +00:00
parent 329f39bb2a
commit 386ac80cf9
5 changed files with 5 additions and 5 deletions

View File

@ -275,7 +275,7 @@ public:
std::string name; //may be custom
std::string biography; //if custom
si32 portrait; //may be custom
ui32 mana; // remaining spell points
si32 mana; // remaining spell points
std::vector<std::pair<ui8,ui8> > secSkills; //first - ID of skill, second - level of skill (1 - basic, 2 - adv., 3 - expert); if hero has ability (-1, -1) it meansthat it should have default secondary abilities
ui32 movement; //remaining movement points
ui8 sex;

View File

@ -387,7 +387,7 @@ ui32 IBonusBearer::getMaxDamage() const
return valOfBonuses(Selector::typeSubtype(Bonus::CREATURE_DAMAGE, 0) || Selector::typeSubtype(Bonus::CREATURE_DAMAGE, 2), cachingStr.str());
}
ui32 IBonusBearer::manaLimit() const
si32 IBonusBearer::manaLimit() const
{
return si32(getPrimSkillLevel(3) * (100.0 + valOfBonuses(Bonus::SECONDARY_SKILL_PREMY, 24)) / 10.0);
}

View File

@ -500,7 +500,7 @@ public:
bool isLiving() const; //non-undead, non-non living or alive
virtual si32 magicResistance() const;
ui32 manaLimit() const; //maximum mana value for this hero (basically 10*knowledge)
si32 manaLimit() const; //maximum mana value for this hero (basically 10*knowledge)
int getPrimSkillLevel(int id) const; //0-attack, 1-defence, 2-spell power, 3-knowledge
const TBonusListPtr getSpellBonuses() const;
};

View File

@ -4,7 +4,7 @@
#include <climits>
typedef si32 TResource;
typedef ui64 TResourceCap; //to avoid overflow when adding integers
typedef si64 TResourceCap; //to avoid overflow when adding integers. Signed values are easier to control.
namespace Res
{

View File

@ -981,7 +981,7 @@ void CGameHandler::newTurn()
if(h->visitedTown && vstd::contains(h->visitedTown->builtBuildings,0)) //if hero starts turn in town with mage guild
hth.mana = std::max(h->mana, h->manaLimit()); //restore all mana
else
hth.mana = std::max((ui32)(0), std::max(h->mana, std::min((ui32)(h->mana + h->manaRegain()), h->manaLimit())));
hth.mana = std::max((si32)(0), std::max(h->mana, std::min((si32)(h->mana + h->manaRegain()), h->manaLimit())));
n.heroes.insert(hth);