Math and global warming

Joined
Jun 27, 2007
Messages
2,248
Location
Hamilton, Ontario
About this part of the code:
Code:
				iGlobalWarmingValue -= pCity->getBuildingBadHealth() * iUnhealthWeight;
Does getBuildingBadHealth return a negative number? Because the part of the GW code with nukes has += instead of the -= found in the building bad health part so I assume getBuildingBadHealth returns negative which is reversed to positive by the -=.

Also can someone explain how random numbers, specifically here:
Code:
if (getSorenRandNum(100, "Global Warming") + iGlobalWarmingDefense < GC.getDefineINT("GLOBAL_WARMING_PROB"))
works. Keep in mind I don't know C++ so this is probably something basic you'd be explaining.

Lastly, I'm going to add more stuff to some of these calculations. Do I use these brackets: () these: [] or these: {}? I don't know if there's a difference or not, but I don't want to confuse things.
 
{} encase full functions, they are not mathematical. [] indicate an item in an array, they are also non-mathematical. () just group things together, and are safe to use for math.


Random numbers work fairly simply. The important bit is just:

getSorenRandNum(##, "DESCRIPTION")

The description is there for your own personal benefit, but is also required. It can be absolutely anything, typically you describe why you want a random number. The ## is any number you want it to be, and the entire function will wind up being a randomly selected integer from 0 to the number you entered (so in this case there are 101 possibilities). from 0 to 1 less than the number you entered (so in this case 100 possibilities, 0 through 99)


As for the buildingbadhealth, I would seem to recall that buildingbadhealth is always a positive value, to indicate how much disease is added to the city from buildings. iUnhealthWeight might be a negative number though. it is a negative value, see the post below for better info on it.


EDIT: Modified to include corrections from next post, just incase someone reads this thread in the future and misses it
 
Does getBuildingBadHealth return a negative number?
Yes, it is always negative (or zero). Furthermore, that is the base total of :yuck: from buildings regardless of other modifiers. For example a city with a forge, airport, and drydock will return a -3 for getBuildingBadHealth() even if it has a recycling center and a drydock that's had 1 :health: added from the better coal fuel event will still contribute a -1 to the getBuildingBadHealth() count since the event simply balances the 1 :yuck: rather than actually removing it.

Regarding random numbers, the number generated will always be less than the argument, but the count starts at zero. getSorenRandNum(100, "Global Warming") has 100 possible results but the actual result will be from 0 and 99 inclusive.
 
...Furthermore, that is the base total of :yuck: from buildings regardless of other modifiers. For example a city with a forge, airport, and drydock will return a -3 for getBuildingBadHealth() even if it has a recycling center and a drydock that's had 1 :health: added from the better coal fuel event will still contribute a -1 to the getBuildingBadHealth() count since the event simply balances the 1 :yuck: rather than actually removing it...

I'm well aware of that travesty and I won't stand for it. I started with other things where it was more obvious how I'd get it to work. I've successfully gotten the icecaps to melt and terrain to go one step at a time towards desert (snow->tundra->grassland->plains->dessert). I'm astonished that I've been able to get this far considering my previous coding work was in BASIC and reading a few lessens on python on the Internet. I've really only been able to cut and paste existing code together when I know what the pieces do and can't write my own, but it's worked so far. To deal with the recycling center I have to look for somewhere in the code when it checks to see if a city has a specific building. I have a plan for environmentalism but I need someway to count the civs running the civic but I don't think that exists. I may need someone else to write it for me.
 
Top Bottom