Browse Source

Silenced several "warning: suggest parentheses around ‘&&’ within ‘||’": added some parenthesis, optimized a couple statments and fix a bug in another.

Frank Zago 14 years ago
parent
commit
ff49b852df
7 changed files with 28 additions and 27 deletions
  1. 3 3
      client/Client.cpp
  2. 3 3
      client/mapHandler.cpp
  3. 5 4
      lib/BattleState.cpp
  4. 5 6
      lib/CGameState.cpp
  5. 2 2
      lib/HeroBonus.cpp
  6. 1 1
      lib/IGameCallback.cpp
  7. 9 8
      server/CGameHandler.cpp

+ 3 - 3
client/Client.cpp

@@ -323,9 +323,9 @@ void CClient::newGame( CConnection *con, StartInfo *si )
 	for(std::map<int, PlayerSettings>::iterator it =si->playerInfos.begin(); 
 		it != si->playerInfos.end(); ++it)
 	{
-		if(networkMode == SINGLE												//single - one client has all player
-			|| networkMode != SINGLE && serv->connectionID == it->second.human	//multi - client has only "its players"
-			|| networkMode == HOST && it->second.human == false)				//multi - host has all AI players
+		if((networkMode == SINGLE)												//single - one client has all player
+		   || (networkMode != SINGLE && serv->connectionID == it->second.human)	//multi - client has only "its players"
+		   || (networkMode == HOST && it->second.human == false))				//multi - host has all AI players
 		{
 			myPlayers.insert(ui8(it->first)); //add player
 		}

+ 3 - 3
client/mapHandler.cpp

@@ -246,8 +246,8 @@ void CMapHandler::initObjectRects()
 	{
 		const CGObjectInstance *obj = map->objects[f];
 		if(	!obj
-			|| obj->ID==HEROI_TYPE && static_cast<const CGHeroInstance*>(obj)->inTownGarrison //garrisoned hero
-			|| obj->ID==8 && static_cast<const CGBoat*>(obj)->hero //boat wih hero (hero graphics is used)
+			|| (obj->ID==HEROI_TYPE && static_cast<const CGHeroInstance*>(obj)->inTownGarrison) //garrisoned hero
+			|| (obj->ID==8 && static_cast<const CGBoat*>(obj)->hero) //boat wih hero (hero graphics is used)
 			|| !obj->defInfo
 			|| !obj->defInfo->handler) //no graphic...
 		{
@@ -549,7 +549,7 @@ void CMapHandler::terrainRect( int3 top_tile, unsigned char anim, const std::vec
 					: static_cast<const CGHeroInstance*>(obj));
 
 				//print hero / boat and flag
-				if(themp && themp->moveDir && themp->type  ||  obj->ID == 8) //it's hero or boat
+				if((themp && themp->moveDir && themp->type) || (obj->ID == 8)) //it's hero or boat
 				{
 					const int IMGVAL = 8; //frames per group of movement animation
 					ui8 dir;

+ 5 - 4
lib/BattleState.cpp

@@ -769,7 +769,8 @@ int BattleInfo::calculateSpellDuration( const CSpell * spell, const CGHeroInstan
 CStack * BattleInfo::generateNewStack(const CStackInstance &base, int stackID, bool attackerOwned, int slot, THex position) const
 {
 	int owner = attackerOwned ? sides[0] : sides[1];
-	assert(owner >= PLAYER_LIMIT  ||  base.armyObj && base.armyObj->tempOwner == owner);
+	assert((owner >= PLAYER_LIMIT)  ||
+		   (base.armyObj && base.armyObj->tempOwner == owner));
 
 	CStack * ret = new CStack(&base, owner, stackID, attackerOwned, slot);
 	ret->position = position;
@@ -1009,9 +1010,9 @@ void BattleInfo::getStackQueue( std::vector<const CStack *> &out, int howMany, i
 	for(unsigned int i=0; i<stacks.size(); ++i)
 	{
 		const CStack * const s = stacks[i];
-		if(turn <= 0 && !s->willMove() //we are considering current round and stack won't move
-			|| turn > 0 && !s->canMove(turn) //stack won't be able to move in later rounds
-			|| turn <= 0 && s == active && out.size() && s == out.front()) //it's active stack already added at the beginning of queue
+		if((turn <= 0 && !s->willMove()) //we are considering current round and stack won't move
+		   || (turn > 0 && !s->canMove(turn)) //stack won't be able to move in later rounds
+		   || (turn <= 0 && s == active && out.size() && s == out.front())) //it's active stack already added at the beginning of queue
 		{
 			continue;
 		}

+ 5 - 6
lib/CGameState.cpp

@@ -347,7 +347,7 @@ DLL_EXPORT std::string MetaString::buildList () const
 	std::string lista;		
 	for (int i = 0; i < message.size(); ++i)
 	{
-		if (i > 0 && message[i] == TEXACT_STRING || message[i] == TLOCAL_STRING)
+		if (i > 0 && (message[i] == TEXACT_STRING || message[i] == TLOCAL_STRING))
 		{
 			if (exSt == exactStrings.size() - 1)
 				lista += VLC->generaltexth->allTexts[141]; //" and "
@@ -484,8 +484,8 @@ CGHeroInstance * CGameState::HeroesPool::pickHeroFor(bool native, int player, co
 
 		for(bmap<ui32, ConstTransitivePtr<CGHeroInstance> >::iterator i=available.begin(); i!=available.end(); i++)
 		{
-			if(pavailable.find(i->first)->second & 1<<player
-				&& !bannedClass || i->second->type->heroClass != bannedClass)
+			if ((!bannedClass && (pavailable.find(i->first)->second & (1<<player))) ||
+				i->second->type->heroClass != bannedClass)
 			{
 				pool.push_back(i->second);
 				sum += i->second->type->heroClass->selectionProbability[town->typeID]; //total weight
@@ -975,8 +975,7 @@ void CGameState::init( StartInfo * si, ui32 checksum, int Seed )
 				for(int j = 0; j < ARRAY_COUNT(dp.sides[i].stacks); j++)
 				{
 					int cre = dp.sides[i].stacks[j].type, count = dp.sides[i].stacks[j].count;
-					if(!count && obj->hasStackAtSlot(j)
-						|| count)
+					if(count || obj->hasStackAtSlot(j))
 						obj->setCreature(j, cre, count);
 				}
 			}
@@ -3034,4 +3033,4 @@ DuelParameters::DuelParameters()
 TeamState::TeamState()
 {
 	nodeType = TEAM;
-}
+}

+ 2 - 2
lib/HeroBonus.cpp

@@ -125,7 +125,7 @@ void DLL_EXPORT BonusList::getBonuses(BonusList &out, const CSelector &selector)
 void DLL_EXPORT BonusList::getBonuses(BonusList &out, const CSelector &selector, const CSelector &limit) const
 {
 	BOOST_FOREACH(Bonus *i, *this)
-		if(selector(i) && (!limit && i->effectRange == Bonus::NO_LIMIT || limit && limit(i))) //add matching bonuses that matches limit predicate or have NO_LIMIT if no given predicate
+		if(selector(i) && ((!limit && i->effectRange == Bonus::NO_LIMIT) || (limit && limit(i)))) //add matching bonuses that matches limit predicate or have NO_LIMIT if no given predicate
 			out.push_back(i);
 }
 
@@ -1064,4 +1064,4 @@ StackOwnerLimiter::StackOwnerLimiter()
 StackOwnerLimiter::StackOwnerLimiter(ui8 Owner)
 	: owner(Owner)
 {
-}
+}

+ 1 - 1
lib/IGameCallback.cpp

@@ -196,7 +196,7 @@ TStacks CBattleInfoCallback::battleGetStacks(EStackOwnership whose /*= MINE_AND_
 
 	BOOST_FOREACH(const CStack *s, gs->curB->stacks)
 	{
-		bool ownerMatches = whose == MINE_AND_ENEMY || whose == ONLY_MINE && s->owner == player || whose == ONLY_ENEMY && s->owner != player;
+		bool ownerMatches = (whose == MINE_AND_ENEMY) || (whose == ONLY_MINE && s->owner == player) || (whose == ONLY_ENEMY && s->owner != player);
 		bool alivenessMatches = s->alive()  ||  !onlyAlive;
 		if(ownerMatches && alivenessMatches)
 			ret.push_back(s);

+ 9 - 8
server/CGameHandler.cpp

@@ -1188,7 +1188,7 @@ void CGameHandler::run(bool resume)
 		resume = false;
 		for(; i != gs->players.end(); i++)
 		{
-			if(i->second.towns.size()==0 && i->second.heroes.size()==0
+			if((i->second.towns.size()==0 && i->second.heroes.size()==0)
 				|| i->second.color<0 
 				|| i->first>=PLAYER_LIMIT  
 				|| i->second.status) 
@@ -1325,7 +1325,7 @@ bool CGameHandler::moveHero( si32 hid, int3 dst, ui8 instant, ui8 asker /*= 255*
 	bool blockvis = false;
 	const CGHeroInstance *h = getHero(hid);
 
-	if(!h  ||  asker != 255 && (instant  ||   h->getOwner() != gs->currentPlayer) //not turn of that hero or player can't simply teleport hero (at least not with this function)
+	if(!h  || (asker != 255 && (instant  ||   h->getOwner() != gs->currentPlayer)) //not turn of that hero or player can't simply teleport hero (at least not with this function)
 	  )
 	{
 		tlog1 << "Illegal call to move hero!\n";
@@ -3872,7 +3872,8 @@ bool CGameHandler::isAllowedExchange( int id1, int id2 )
 	{
 		boost::unique_lock<boost::recursive_mutex> lock(gsm);
 		for(std::map<ui32, std::pair<si32,si32> >::const_iterator i = allowedExchanges.begin(); i!=allowedExchanges.end(); i++)
-			if(id1 == i->second.first && id2 == i->second.second   ||   id2 == i->second.first && id1 == i->second.second)
+			if((id1 == i->second.first && id2 == i->second.second) ||
+			   (id2 == i->second.first && id1 == i->second.second))
 				return true;
 	}
 
@@ -4646,14 +4647,14 @@ bool CGameHandler::eraseStack(const StackLocation &sl, bool forceRemoval/* = fal
 bool CGameHandler::changeStackCount(const StackLocation &sl, TQuantity count, bool absoluteValue /*= false*/)
 {
 	TQuantity currentCount = sl.army->getStackCount(sl.slot);
-	if(absoluteValue && count < 0
-		|| !absoluteValue && -count > currentCount)
+	if((absoluteValue && count < 0)
+		|| (!absoluteValue && -count > currentCount))
 	{
 		COMPLAIN_RET("Cannot take more stacks than present!");
 	}
 
-	if(currentCount == -count  &&  !absoluteValue
-		|| !count && absoluteValue)
+	if((currentCount == -count  &&  !absoluteValue)
+	   || (!count && absoluteValue))
 	{
 		eraseStack(sl);
 	}
@@ -5088,4 +5089,4 @@ void CasualtiesAfterBattle::takeFromArmy(CGameHandler *gh)
 		else
 			gh->eraseStack(ncount.first, true);
 	}
-}
+}