[SDK]Trouble with an "IF city has this building" statement

Joined
Jun 27, 2007
Messages
2,248
Location
Hamilton, Ontario
I was trying to edit this part of the global warming code:
Code:
	for (int iPlayer = 0; iPlayer < MAX_PLAYERS; ++iPlayer)
	{
		CvPlayer& kPlayer = GET_PLAYER((PlayerTypes) iPlayer);
		if (kPlayer.isAlive())
		{
			int iLoop;
			for (CvCity* pCity = kPlayer.firstCity(&iLoop); pCity != NULL; pCity = kPlayer.nextCity(&iLoop))
			{
				iGlobalWarmingValue -= pCity->getBuildingBadHealth() * iUnhealthWeight;
			}
		}
	}
to have it check for a recycling center and only count it's BuildingBadHealth if it didn't have it. I tried to reverse engineer the code from other places and although it did successfully compile so I know it wasn't gibberish I was writing but nothing worked. Eventually I tried something that had to return as false:
Code:
			for (CvCity* pCity = kPlayer.firstCity(&iLoop); pCity != NULL; pCity = kPlayer.nextCity(&iLoop))
			{
				if (1 == 0);
				{
					iGlobalWarmingValue -= pCity->getBuildingBadHealth() * iUnhealthWeight;
				}
			}
but it still a mathematical impossibility doesn't stop it. So obviously there's something I'm doing wrong. Is there something about this context where an if statement doesn't work?
Also, assuming there's is a right way to even have a condition where I want it, what's the right way to check for a building in this context?
 
If you want to factor in a Recycling Center, it's easier to just use CvCity::totalBadBuildingHealth() instead; see some discussion on this in the topic you started a while back :p

Regarding the problems with the posted code: Try removing that semicolon after your if statement; it's closing the if block prematurely.
 
If you want to factor in a Recycling Center, it's easier to just use CvCity::totalBadBuildingHealth() instead; see some discussion on this in the topic you started a while back :p
Well I must have forgotten about that since back then it was someone else's problem to solve so the information wasn't any use to me. Anyway, it works. I've also added :yuck: from bonuses (oil and coal) and :yuck: from power to the count. I changed the GLOBAL_WARMING_UNHEALTH_WEIGHT to 10 and gave the 10 I took from it to the bonus and power global warming weight. Now I just have environmentalism to deal with, and figure out how to get my plan for it to work.
Regarding the problems with the posted code: Try removing that semicolon after your if statement; it's closing the if block prematurely.
I tried it that way but it wouldn't compile and said a semicolon was missing, but it seemed to work your way now, so I don't know what the problem was. It's irrelevant now
 
Top Bottom