Ver código fonte

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

DjWarmonger 13 anos atrás
pai
commit
386ac80cf9
5 arquivos alterados com 5 adições e 5 exclusões
  1. 1 1
      lib/CObjectHandler.h
  2. 1 1
      lib/HeroBonus.cpp
  3. 1 1
      lib/HeroBonus.h
  4. 1 1
      lib/ResourceSet.h
  5. 1 1
      server/CGameHandler.cpp

+ 1 - 1
lib/CObjectHandler.h

@@ -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;

+ 1 - 1
lib/HeroBonus.cpp

@@ -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);
 }

+ 1 - 1
lib/HeroBonus.h

@@ -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;
 };

+ 1 - 1
lib/ResourceSet.h

@@ -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
 {

+ 1 - 1
server/CGameHandler.cpp

@@ -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);