Global warming (Civ4)

Global warming is a game element in Civilization IV: Beyond the Sword.
== Overview ==
The following information comes from the 3.17 changelog:BTS patch 3.17 changelog
 Global warming in forests and jungles just removes those features, without turning plot to desert
 Global warming takes into account the number of forests and jungles in the world
 Global Warming is affected by unhealthy buildings in addition to nuclear explosions.
Global warming is caused by pollution (namely, "unhealthy" buildings) and nuclear explosions (which may sound counter-intuitive but is seemingly normal in the Civilization series). It is adverted by a large number of forests and jungles present on the world map. Its effects are to reduce the production of tiles, usually turning random tiles into desert. The tiles affected when global warming strikes are picked randomly, regardless of how much each nation contributed to its occurrence.
== Mechanics ==
The mechanics of global warming are explained in detail below. The original post was written by Refar, a user of the CivFanatics forums.https://forums.civfanatics.com/threads/3-17-global-warming-mechanics.280111/
=== The XML tags ===
All found in GlobalDefines.XML. New ones (or those believed to be new) are highlighted.
==== Code ====
 <Define>
 	<DefineName>GLOBAL_WARMING_TERRAIN</DefineName>
 	<DefineTextVal>TERRAIN_DESERT</DefineTextVal>
 </Define>
 <Define>
 	<DefineName>GLOBAL_WARMING_PROB</DefineName>
 	<iDefineIntVal>20</iDefineIntVal>
 </Define>
 <Define>
 	<DefineName>[B][COLOR="SeaGreen"]GLOBAL_WARMING_FOREST[/COLOR][/B]</DefineName>
 	<iDefineIntVal>50</iDefineIntVal>
 </Define>
 <Define>
 	<DefineName>[B][COLOR="SeaGreen"]GLOBAL_WARMING_UNHEALTH_WEIGHT[/COLOR][/B]</DefineName>
 	<iDefineIntVal>20</iDefineIntVal>
 </Define>
 <Define>
 	<DefineName>[B][COLOR="SeaGreen"]GLOBAL_WARMING_NUKE_WEIGHT[/COLOR][/B]</DefineName>
 	<iDefineIntVal>50</iDefineIntVal>
 </Define>
==== Other variables involved ====
* #LAND - The number of land Plots on the map.
* #PLOTS - The number of plots in the map (Width x Height).
* #FOREST - The number of forest/jungle tiles on the map. Actually features with (getGrowthProbability() > 0) are counted. For default game those are Jungle and Forest. Might be different in mods.
* #BADLAND - Land plots not giving any yield (Desert, Frozen land).
* #BAD_HEALTH - The global caused by buildings. The from overpopulation, features or other possible sources does not count.
* ??? It is assumed that the 2 from power counts here, though it has not been confirmed. ???
* #NUKES_EXPLODED - The number of Nukes ever exploded. This counts for any kind of nuclear explosion - ICBM, Tactical Nuke and Plant Meltdown.
==== Derived Variables ====
The code on Global Warming is within CvCity.cpp; doGlobalWarming();
GW_DEFENSE = #FOREST / #LAND * GLOBAL_WARMING_FOREST
GW_VALUE = #BAD_HEALTH * GLOBAL_WARMING_UNHEALTH_WEIGHT / #_PLOTS + #NUKES_EXPLODED * GLOBAL_WARMING_NUKE_WEIGHT / 100
=== Global Warming Probability ===
On every turn there will be GW_VALUE independent random tests, each with a probability to cause Global Warming:
 PROB1 = ( GLOBAL_WARMING_PROB - GW_DEFENSE ) / 100
This results in a chance of no GW at a given turn:
 PROBtotal_no_GW = (1 - PROB1)GW_VALUE
And hence the chance of at least one GW event on any given turn:
 PROBGW_strikes = 1 - (1 - PROB1)GW_VALUE
=== With the standard XML values ===
 GW_DEFENSE = #_FOREST / #_LAND * 50
 GW_VALUE = - #_BUILDING_BAD_HEALTH / #_PLOTS * 20 + #_NUCLEAR_EXPLOSIONS * 1/2
 PROBGW_strikes = 1 - (0.8 + #FOREST/#LAND * 0.5)GW_VALUE
=== Effect of Global Warming ===
If Global Warming strikes, a random land PLOT which is not a city will be chosen.
There is no regional, player, team or other bias in choosing the target plot for Global Warming. It does not matter who, where or why caused the nuclear explosions, built the polluting buildings, chopped or preserved the forests.
If PLOT has a feature (Forest, Jungle, Floodplain, Oasis), this feature will be removed, but the terrain type does not change (unless the feature is Fallout, in which case nothing happens at all).
If PLOT has no Feature and can give any yield (i.e. is not desert or frozen), then it will be turned into GLOBAL_WARMING_TERRAIN, which is - per standard XML - desert.
=== Note on probability ===
This de facto reduces the Probability of Global Warming with increasing amount of useless land plots on the map. Since if a plot is chosen to be victim of Global Warming, that can not be worked anyway, nothing happens. So actually:
 PROBGW_strikes = 1 - (1 - PROB1 + PROB1*#BADLAND/#LAND)GW_VALUE
Depending on how high PROB1 actually is and how much "bad land" we have it might result in 5-10 % (or even more in really extreme cases) less visible GW.
Same thing with fallout. Should be negligible in most games, but could become interesting in a huge Nuclear War, where the Fallout will actually help preserve the terrain under it. Of course, as soon as you clear the Fallout after the war, the plots will become affected by Global Warming again.
=== Notes ===
Nukes now count only half. This means that a single explosion (say a meltdown) will not cause GW by itself. However this is only true if there are no other sources of GW.
The from buildings is weighted by map size (number of plots). To give an idea of its impact let's assume a Standard size map:
 1 * 20 / 4368 = ~0.005
So ~110 from buildings would have the same effect as one Nuke, giving us a half of a GW_VALUE point. Also since there is integer division involved and assuming no nukes, the first ~220 are free (as long as #BAD_HEALTH * GLOBAL_WARMING_UNHEALTH_WEIGHT / #_PLOTS < 1).
One city with all possible pollution sources and no Recycling Center can "provide" 17 (give or take 1-2 points).
== Green World ==
To completely avoid Global Warming we would need to:
# Never get GW_VALUE >= 1. As mentioned above this could still allow one nuke explosion and/or some very minor building .
# Have enough forests to make PROB1 drop to 0. At standard XML values this would require 40% of the landmass to be covered with Forest or Jungle.
== Modding ==
Setting GLOBAL_WARMING_PROB = 0 will still remove all GW. However, the method examining all plots and cities will still run, so it would be a bit faster to put a check there and skip the rest if == 0.
GLOBAL_WARMING_FOREST is a positive modifier - increasing the value will make fewer Forests/Jungles needed to avoid GW. A GLOBAL_WARMING_FOREST = 100, for example, would make only 20% of forested Landmass needed to count as a green planet.
Also note again - while talking FOREST we actually mean all Features that can grow.
GLOBAL_WARMING_UNHEALTH_WEIGHT and GLOBAL_WARMING_NUKE_WEIGHT are negative modifiers - reducing those will result in fewer Global Warming events.
== References ==
== See also ==
* Global warming in other games
Category:Game concepts (Civ4)