Freeciv
(→‎City output (food/production/trade): So this is how to round your taxes!)
No edit summary
Tag: Visual edit
 
(106 intermediate revisions by 25 users not shown)
Line 1: Line 1:
Here are formulas that are used by FreeCiv to calculate some things, presented in a form better for mathematicians.
+
This page is a project to collect formulas that are used by Freeciv and present them in a form suitable for mathematicians.
   
  +
== Score of a player ==
== City output (food/production/trade) ==
 
  +
Shown in F3 tab, is equal to the sum of
  +
* Number of citizens (the sum of city sizes)
  +
* Number of known techs * 2
  +
* Number of known future techs * 5
  +
* Number of wonders * 5 (the big ones)
  +
* Spaceship score (100 points for every 10.000 citizens on the spaceship multiplied by success rate)
  +
* Number of units built / 10
  +
* Number of units killed / 3
  +
*Number of culture points / 50
  +
  +
==Demographics==
  +
{| border="0" cellpadding="1" cellspacing="1" class="article-table article-table-selected" style="width: 500px;"
  +
|'''Population'''
  +
| The sum of the [[population]] in each of your cities. Note that it's not proportional to the total number of your citizens, bigger cities contribute quadratically more.
  +
|-
  +
|'''Land Area'''
  +
|The sum of every tile of your [[territory]] (including Ocean) on the map multiplied by 1,000 in "square miles". If the [[borders]] are disabled, it's the "settled area" increased on land tiles with units of this player at stack top<ref name=d1 group=demo /> out of any of the player's city's working radius
  +
|-
  +
|'''Settled Area'''
  +
|The sum of every land tile on the map that is being currently worked by a city including the "city tile", plus any other land tiles with the player's units at stack top<ref name=d1 group=demo /> within the city radii, multiplied by 1,000 in "square miles"
  +
|-
  +
|'''Research Speed'''
  +
|The total amount of "bulbs" being produced by you per turn
  +
|-
  +
|'''Literacy'''
  +
|The percentage of your civilization's population that live inside a city that is close, beyond or at a 100% output bonus in science. I.e., a city with 100% bonus or any more contributes total its population (without the "thousands" multiplier) to a counter, for bonuses from 1% to 99% the value will be proportionally smaller, and finally the counter is divided on total population. Under the default ruleset for example, a library provides a +100% bonus to science; if every city had one - your civilization would have 100% literacy.
  +
|-
  +
|'''Production'''
  +
|The sum of the surplus production after being spent on unit upkeep and waste in each of your cities in "M tons"
  +
|-
  +
|'''Economics'''
  +
|The sum of the surplus trade after losses to corruption in each of your cities in "M goods"
  +
|-
  +
|'''Military Service'''
  +
|<math>\frac{\text{Number of Military Units} \times 5000}{10 + [\text{Total Population}/1000]} </math>--- in months
  +
|-
  +
|
  +
'''Pollution'''
  +
|The sum of the total pollution being produced by each of your cities in "tons"
  +
|}
  +
<references group=demo>
  +
<ref name=d1>Stack top of a tile is usually a unit on it that came there last, but it's not guaranteed.</ref>
  +
</references>
  +
  +
== Tile output ==
  +
Tiles produce six types of output: food, shields (for production), trade, and also gold, science and luxury. To calculate the output of a tile (note: extra kinds are identified by their causes, being "Road", "Mine" or "Irrigate"; all percentages are rounded down):
  +
  +
{| class="wikitable"
  +
|-
  +
! Operation !! Ruleset variable
  +
|-
  +
|Start with the base output for the terrain type.||terrain.ruleset: terrain_*.* (second * for food, shield, trade)
  +
|-
  +
|Add output from the special resource, if the tile has any.||terrain.ruleset: resource_*.*
  +
|-
  +
| colspan="2" |Add the point bonuses from terrain improvements:
  +
|-
  +
|{{*}}Add bonus to food, if the tile has some irrigation (or is the center of a city having auto-bonus for irrigation).
  +
|effects.ruleset: "Irrigation_Pct"
  +
|-
  +
|{{*}} Add bonus to shields, if the tile has a mine. (desert, glacier, hills or mountains)
  +
|effects.ruleset: "Mining_Pct"
  +
|-
  +
|{{*}} Add variable bonuses from roads scaled to terrain percentage (e.g. road bonus to trade, if the tile has a road and is grassland, plains or desert)
  +
|terrain.ruleset: road_*.*_incr, terrain_*.road_*_incr_pct
  +
|-
  +
|{{*}} Add constant bonuses from roads (e.g. trade, if the tile has a river).
  +
|terrain.ruleset: road_*.*_incr_const
  +
|-
  +
|{{*}} Increase the result on percentage equal to the sum of road bonuses [50% to shields from railroad]
  +
|terrain.ruuleset: road_*.*_bonus
  +
|-
  +
|Add unconditional bonus from effect [as from Harbor or Offshore Platform].||effects.ruleset: "Output_Add_Tile"
  +
|-
  +
|If the production is above zero, add the conditional bonus [like the +1 trade bonus for Republic or Democracy]; if the city also celebrates, add also another one [like the +1 trade bonus for Monarchy or Communism]||effects.ruleset: "Output_Inc_Tile", "Output_Inc_Tile_Celebrate"
  +
|-
  +
|Add percentage bonus from effect [as from Superhighways or Supermarket].||effects.ruleset: "Output_Per_Tile"
  +
|-
  +
|If the city does not celebrate, subtract 1 point if the output exceeds the penalty limit [like the penalty for exceeding 2 points during Anarchy or Despotism].||effects.ruleset: "Output_Penalty_Tile"
  +
|-
  +
|Subtract penalty percentage [in default ruleset, 50% if the tile has pollution, 50% for nuclear fallout and 75% for both]||effects.ruleset: "Output_Tile_Punish_Pct"
  +
|-
  +
|Apply minimum values [1/1/0 in default ruleset], if the tile is the center of a city.
  +
|game.ruleset: min_city_center_*
  +
|}
  +
  +
See get_worked_tile_output() and city_tile_output() in common/city.c.
  +
  +
Note that "celebrating" city for tiles' output means "a city that was in celebrating mood the previous turn and has enough citizens for celebration".
  +
  +
Note also that tile outputs of science, luxury and gold are not displayed on the map in standard clients, and other outputs with tile values over 9 will be displayed as 9.
  +
  +
==City output (food/production/trade)==
 
Cities produce six types of output: food, shields (for production), trade, gold, luxury and science. To calculate the output of any single city:
 
Cities produce six types of output: food, shields (for production), trade, gold, luxury and science. To calculate the output of any single city:
   
  +
{| class="wikitable"
# Start with the base citizen output from all citizens who are working tiles, or who are specialists.
 
  +
|-
# If the city has any trade routes, then add the bonus from these routes to trade.
 
  +
!Operation!!Ruleset factors and game settings
# If the city pays tithes (like from Fundamentalism in civ2 ruleset), then add the tithes to gold.
 
  +
|-
# Calculate waste and corruption.
 
  +
|Start with the base citizen output from all citizens who are working tiles, or who are specialists.||See above and effects.ruleset: "Specialist_Output"
# Apply tax rates to trade. Add result to gold, luxury and science.
 
  +
|-
# Apply city bonus effects (like 50% shield bonus from Factory, and the 100% science bonus from Library.)
 
  +
|If the city has any trade routes, then add the bonus from these routes to trade.
  +
|[ [[Longturn]] servers only: setting "trade_revenue_style"]<br />game.ruleset: trade.settings.{type, pct, cancelling}<br />effects.ruleset: "Traderoute_Pct"
  +
|-
  +
|If the city pays tithes (like from Fundamentalism in civ2 ruleset), then add the tithes to gold.
  +
|effects.ruleset: "Happiness_To_Gold"
  +
|-
  +
|Calculate production with bonuses for each output type:<br /><!--
  +
-->prod = floor(prod_0 * floor((100 + bonus) * (100 + bonus2) / 100) / 100)
  +
|effects.ruleset: "Output_Bonus", "Output_Bonus_2"
  +
|- style="background-color: lightblue"
  +
|'''Since v.3.2:''' add absolute city bonus and make the result at least 0 for each output type.
  +
|effects.ruleset: "Output_Bonus_Absolute"
  +
|-
  +
| colspan="2" |At this moment of calculations, shields value affects city pollution (see below).
  +
|-
  +
|Calculate waste/corruption for each output. For trade, it is full prod if the city has not overgrown no-trade size, or proportional (rounded down) part of prod if the citysize is between no-trade size and full trade size, for the remnant normal waste is applied additionally. If your nation happens to have no governmental center (happens to [[barbarians]] in standard rulesets), then all production is wasted; otherwise,<br /><!--
  +
-->basic_waste = floor(prod * (basic_waste + min_govcenter_dist * dist_waste) / 100),<br /><!--
  +
-->waste = basic_waste - floor(basic_waste * waste_pct / 100)
  +
  +
(clipped into the range from 0 to prod)
  +
|game settings: "notradesize", "fulltradesize"<br />effects.ruleset: "Gov_Center", "Output_Waste", "Output_Waste_By_Distance", "Output_Waste_Pct"
  +
|-
  +
|Calculate the amount of all city-based upkeeps for units and buildings, usage of food by citizens
  +
|game.ruleset: civstyle.food_cost, civstyle.gold_upkeep_style<br />units.ruleset: unit_*.uk_*, flag = "Fanatic"<br />buildings.ruleset: building_*.upkeep<br /><!--
  +
-->effects.ruleset: "Upkeep_Free", "Upkeep_Factor", "Unit_Upkeep_Free_Per_City", "Fanatics"
  +
|-
  +
|Apply tax rates to trade (without corruption and upkeep, if any). Add results to gold, luxury and science values (before bonus multiplication).
  +
|cities.ruleset: parameters.(changable_tax, forced_science, forced_gold, forced_luxury)
  +
|-
  +
|Apply city bonus effects to outputs after taxes added. Surpluses are calculated here by subtracting usage from the production (they may be negative before the city/nation is ballanced during turn change)
  +
|(see above)
  +
|-
  +
|Calculate citizens' moods. Note that (v.2.6.3 regarded) luxury usage by units, if any, has no effect here.
  +
|See [[Happiness]]
  +
|-
  +
|If the city is in disorder, calculate unhappy penalty: for gold and science, it is full city production; for food and shield, it is all what remains after usage on upkeeps (minimum 0); not applied to trade and luxury.
  +
|not configurable yet
  +
|}
   
  +
Thus, note that "Output_Waste" effect on science is applied only to the science collected by scientists or workers (they produce a unit of science with Copernicus Observatory in some rulesets), and to reduce the effectivity of taxing science from trade as well you should introduce negative "Output_Bonus".
 
References:
 
References:
* enum output_type_id in common/fc_types.h
+
*enum output_type_id in common/fc_types.h
* output_type_iterate() in common/city.h
+
*output_type_iterate() in common/city.h
* set_city_production() in common/city.c
+
*city_refresh_from_main_map(), set_city_production() in common/city.c
   
=== Food box ===
+
===Food box===
 
The amount of food needed to fill the food box is a function of the game.ruleset values ''granary_food_ini'' and ''granary_food_inc''. The server option ''foodbox'' adjusts the amount.
 
The amount of food needed to fill the food box is a function of the game.ruleset values ''granary_food_ini'' and ''granary_food_inc''. The server option ''foodbox'' adjusts the amount.
   
* Recursive formula:
+
*Recursive formula:
** <math>city\_granary\_size = f(city\_size) \times \frac{foodbox}{100}</math>
+
**<math>city\_granary\_size = f(city\_size) \times \frac{foodbox}{100}</math>
** <math>f(city\_size) = \begin{cases}
+
**<math>f(city\_size) = \begin{cases}
 
granary\_food\_ini[city\_size] & \mbox{if } city\_size \le num\_inis \\
 
granary\_food\_ini[city\_size] & \mbox{if } city\_size \le num\_inis \\
 
f(city\_size - 1) + granary\_food\_inc & \mbox{if } city\_size > num\_inis \\
 
f(city\_size - 1) + granary\_food\_inc & \mbox{if } city\_size > num\_inis \\
 
\end{cases}
 
\end{cases}
 
</math>
 
</math>
* Where:
+
*Where:
** ''city_size'' is the current size of the city.
+
**''city_size'' is the current size of the city.
** ''num_inis'' is the number of values in ''granary_food_ini'' (which is a list).
+
**''num_inis'' is the number of values in ''granary_food_ini'' (which is a list).
   
  +
When a city changes its size with a [[Granary]] in effect, the preserved amount of food is calculated from the final city size but with the percentage related to the initial city size (i.e., if we have auto-granary 50% before size 3, city size 3 completes its 30 food stock and becomes a size 4 city with 40 food stock, it has 20 food inside, but if it starves back to 3, it will have 0). When a migration happens, the source city invariantly loses half of its foodbox that is eaten by the migrant on the way.
When you add a settler the food in the foodbox is kept. With a granary the foodbox will be half full when the city is decreased because of starvation, but when you grow a settler the foodbox will be empty(?). When you add a settler you will not gain half a foodbox
 
   
 
References:
 
References:
* load_ruleset_game in server/ruleset.c
+
*load_ruleset_game in server/ruleset.c
* city_granary_size in common/city.c
+
*city_granary_size in common/city.c
   
=== Production ===
+
===Production hurry cost===
Gold needed to finish production (<math>T</math> - shields left to produce):
+
Gold needed to finish production (<math>T</math>
  +
- shields left to produce):
* For units: <math>2T+\frac{T^2}{20}</math>
 
* For buildings: <math>2T</math>
+
*For units:<math>2T+\frac{T^2}{20}</math>
* For wonders: <math>4T</math>
+
*For buildings:<math>2T</math>
  +
*For wonders:<math>4T</math>
 
Multiply these values by 2 if there is no shield in the city stock (<math>C</math> - cost in shields):
+
Multiply these values by 2 if there is no shield in the city stock (<math>C</math>
  +
- cost in shields):
* For units: <math>4C+\frac{C^2}{10}</math>
 
* For buildings: <math>4C</math>
+
*For units:<math>4C+\frac{C^2}{10}</math>
* For wonders: <math>8C</math>
+
*For buildings:<math>4C</math>
  +
*For wonders:<math>8C</math>
  +
The basic cost of upgrading units is the unit's buy cost had the unit been disbanded (contributing half of its shields) into an empty production stock and then new one bought; this cost may be modified on a percentage of "Upgrade_Price_Pct" effect (player-ranged, should be negative to get a discount).
   
 
References:
 
References:
* impr_buy_gold_cost in common/improvement.c
+
*impr_buy_gold_cost in common/improvement.c
* utype_buy_gold_cost in common/unittype.c
+
*utype_buy_gold_cost in common/unittype.c
   
=== Trade routes ===
+
===Corruption / Waste===
  +
Corruption and Waste refer to the same thing: a penalty on city output based on two effects in ''effects.ruleset'': '''Output_Waste''' and '''Output_Waste_By_Distance'''. ''(Some people use the word "corruption" to refer to trade waste, and may use the term "waste" to refer to either production waste or any kind of waste in general.)''
Trade route revenue generated every turn in cities: (<math>T_1</math> = trade production in the city 1, <math>T_2</math> = trade production in the city 2. These values doesn't include the extra trade revenues from other trade routes
 
* With yourself, on the same continent: <math>\frac{(T_1 + T_2 + 4)}{16}</math>
 
* With another player, on the same continent: <math>\frac{(T_1 + T_2 + 4)}{8}</math>
 
* With yourself, on another continent: <math>\frac{(T_1 + T_2 + 4)}{8}</math>
 
* With another player, on another continent: <math>\frac{(T_1 + T_2 + 4)}{4}</math>
 
* With experimental trade route revenues (on [[Warclient|Warserver]]): <math>\frac{(T_1 + T_2 + 4)}{4}</math>
 
   
  +
In most rulesets, the starting base for '''Output_Waste''' and '''Output_Waste_By_Distance '''are determined by the form of government. However, a ruleset could hypothetically set other triggers for these effects.
  +
*'''Output_Waste''' is a base level of waste for a particular output type. For example:
  +
[effect_corruption_monarchy]
  +
type = "Output_Waste"
  +
value = 20
  +
reqs =
  +
{ "type", "name", "range"
  +
"Gov", "Monarchy", "Player"
  +
"OutputType", "Trade", "Local"
  +
}
  +
This sets the base level of waste on trade to 20% for nations who are Monarchy. This base level would apply to all cities across the empire.
  +
*'''Output_Waste_By_Distance '''adds to the above an additional percentage of waste, based on "real distance" to the nearest Government Center (typically, the city with Palace.) "Real Distance" is '''''not''''' Pythagorean distance, but rather, the "distance as a crow flies if it used cursor keys", or the shortest number of moves to get from A to B if one is able to move unrestricted. On a Cartesian (square tile) map, "Real distance" is always the greater of δx,δy. For example, a city with distance δx=5 and δy=7 will have a "Real Distance" of 7. Example of '''Output_Waste_By_Distance''':
  +
[effect_corruption_monarchy_distance_from_capital]
  +
type = "Output_Waste_By_Distance"
  +
value = 200
  +
reqs =
  +
{ "type", "name", "range"
  +
"Gov", "Monarchy", "Player"
  +
"OutputType", "Trade", "Local"
  +
}
  +
This adds 200% of the "real distance" to the '''Output_Waste. '''Let's revisit our example of a city in Monarchy whose distance from the capital is δx=5 and δy=7. It has '''Output_Waste '''of 20%. Its real distance is 7. Its '''Output_Waste_By_Distance '''is 200. Therefore this city would suffer 20%+(2 * 7) = 34% trade waste. If it has raw trade of 11, its corruption would be trunc(0.34 * 11) = trunc(3.74) = 3. Note in this example, the truncation rounding results in a real corruption of 3 or only 27% corruption.
  +
*'''Other''' '''Factors''': all mainstream rulesets have things which can alter the above. Specifically, there are other triggers in ''effects.ruleset'' to reduce or increase the waste determined by '''Output_Waste '''and '''Output_Waste_By_Distance'''. Typically, these are buildings like Palace, Courthouse, or possibly certain Wonders. For example:
  +
[effect_courthouse]
  +
type = "Output_Waste_Pct"
  +
value = 50
  +
reqs =
  +
{ "type", "name", "range"
  +
"Building", "Courthouse", "City"
  +
"OutputType", "Trade", "Local"
  +
}
  +
In this example from a typical ruleset, a Courthouse reduces the final ''trade waste'' by 50%. Note that in our above example, this is not 50% * 34% = 17%. But rather, 50% of trunc(0.34*11) will be removed ''post facto. ''Thus, if a city had 11 trade, trunc(34%*11) would yield corruption of 3. 50% of 3 is 1.5 which truncates down to 1, yielding total corruption of (34%*11) - trunc(50%*3) = 3-1 = 2. Thus, while the 34% corruption the city was actually supposed to suffer was only 27%, the 50% corruption reduction the Courthouse was supposed to offer was only 33%. In a way this balances out, though one should be aware that any ruleset with a Courthouse like the example above, would get nowhere near 50% corruption reduction for cities with typical corruption:
  +
{| class="article-table"
  +
!Corruption
  +
!-50%
  +
!rounded
  +
!real value
  +
|-
  +
|1
  +
|0.5
  +
|'''0'''
  +
|'''-0%'''
  +
|-
  +
|2
  +
|1
  +
|1
  +
|<nowiki>-50%</nowiki>
  +
|-
  +
|3
  +
|1.5
  +
|'''1'''
  +
|'''-33%'''
  +
|-
  +
|4
  +
|2
  +
|2
  +
|<nowiki>-50%</nowiki>
  +
|-
  +
|5
  +
|2.5
  +
|'''2'''
  +
|'''-40%'''
  +
|-
  +
|6
  +
|3
  +
|3
  +
|<nowiki>-50%</nowiki>
  +
|-
  +
|7
  +
|3.5
  +
|'''3'''
  +
|'''-43%'''
  +
|-
  +
|8
  +
|4
  +
|4
  +
|<nowiki>-50%</nowiki>
  +
|-
  +
|9
  +
|4.5
  +
|'''4'''
  +
|'''-44%'''
  +
|}
  +
*<sub>In a frequency distribution for a typical Monarchy in the middle of its Monarchy period, 12 non-capital cities had corruption of: 1, 1, 1, 2, 2, 3, 3, 3, 4, 5, 6, 7. Yielding total corruption of 38. One would suppose Courthouses would result in corruption of 38-19=19. But in fact, it results in 38-15=23, for an actual 39% reduction: a number closer to 1/3 than it is to 1/2. While it can be argued that the discounted corruption from step one is balanced by this penalized reduction, the real effect is a strong discouragement on the use of corruption reducing mechanics in empires experiencing single digit corruption values. (Higher values converge closer toward 50%). While it has been proposed that some effects should use alternative rounding such as [https://en.wikipedia.org/wiki/Rounding#Round_half_to_even Bankers' Rounding] to solve this, other rulesets such as [[Multiplayer II Game Manual|MP2]] have improved this mechanic in simple heuristic ways. In any case, players and ruleset designers should all be aware of it, as it has a major impact on game equilibrium.</sub>
  +
  +
'''Hint:''' If "Output_Waste_By_Distance" is 300 or more for a given government, the autogenerated help for it says that the losses will increase ''quickly'' with distance from capital; if its value is from 1 to 199, it says that they will increase ''slowly''. The effect "Output_Waste_By_Rel_Distance" is commented the same way (just from (effect+39)/40 value) since the help text does not know actual world scaling (the effect is actually similar to "Output_Waste_By_Distance" when the world bigger dimension is 50).
  +
  +
*TO DO: this subsection is incomplete and could benefit by a more accurate redaction of the server code in ''city.c'' into a mathematical formula. The above is an ''incomplete oversimplified ''draft as a courtesy for players who have experienced FAQs and also "frequently experienced frustrations" regarding the unintuitive and hitherto undocumented ways that waste works in Freeciv.
  +
  +
===Trade routes===
  +
'''Freeciv 2.1 uses the following formulas:'''
  +
  +
Trade route revenue generated every turn in cities: (
  +
  +
<math>T_1</math>
  +
= trade production in the city 1,
  +
  +
<math>T_2</math>
  +
= trade production in the city 2. These values do not include the extra trade revenues from other trade routes )
  +
*With yourself, on the same continent:<math>\frac{(T_1 + T_2 + 4)}{16}</math>
  +
*With another player, on the same continent:<math>\frac{(T_1 + T_2 + 4)}{8}</math>
  +
*With yourself, on another continent:<math>\frac{(T_1 + T_2 + 4)}{8}</math>
  +
*With another player, on another continent:<math>\frac{(T_1 + T_2 + 4)}{4}</math>
  +
*With experimental trade route revenues (on [[Warclient|Warserver]]): <math>\frac{(T_1 + T_2 + 4)}{4}</math>
  +
  +
'''Freeciv 2.2 uses the following formulas:'''
  +
  +
Trade route revenue generated every turn in cities: ( D = real distance between city 1 and city 2, all directions counting as 1, S1 = size of city 1, S2 = size of city 2 )
   
  +
*With yourself, on the same continent: ( D + S1 + S2 ) / 12
  +
*With another player, on the same continent: ( D + S1 + S2 ) / 6
  +
*With yourself, on another continent: ( D + S1 + S2 ) / 6
  +
*With another player, on another continent: ( D + S1 + S2 ) / 3
 
[[Caravan]] bonus, the gold and science you get when establishing a new trade route: (<math>T_1</math> = trade production (including trade routes revenues) in the city 1, <math>T_2</math> = trade production in the city 2, <math>D</math> = real distance between the cities):
 
[[Caravan]] bonus, the gold and science you get when establishing a new trade route: (<math>T_1</math> = trade production (including trade routes revenues) in the city 1, <math>T_2</math> = trade production in the city 2, <math>D</math> = real distance between the cities):
* <math>\frac{(D + 10) (T_1 + T_2)}{8}</math>
+
*<math>\frac{(D + 10) (T_1 + T_2)}{8}</math>
 
The possession of the technologies Railroad and Flight each reduces the bonus by <math>\frac{1}{3}</math>. Then:
 
The possession of the technologies Railroad and Flight each reduces the bonus by <math>\frac{1}{3}</math>. Then:
* You have one of this technologies: <math>\frac{(D + 10) (T_1 + T_2)}{12}</math>
+
*You have one of this technologies:<math>\frac{(D + 10) (T_1 + T_2)}{12}</math>
* You have two of this technologies: <math>\frac{(D + 10) (T_1 + T_2)}{18}</math>
+
*You have two of this technologies:<math>\frac{(D + 10) (T_1 + T_2)}{18}</math>
* With experimental caravan bonus style (on [[Warclient|Warserver]]): <math>(2 \log(D + 20 + T_1 + T_2)) ^ 2</math>
+
*With experimental caravan bonus style (on [[Warclient|Warserver]]):<math>(2 \log(D + 20 + T_1 + T_2)) ^ 2</math>, where <math>D</math> is real map distance, <math>T_1</math> and <math>T_2</math> are maximal possible trade values that the cities can get reassigning their citizens on their tiles (plus trade from existing routes without goods factors, without theoretically possible city trade specialists output).
 
 
Bonus from a caravan, when it enter in a existent trade place, you get only <math>\frac{1}{3}</math> of the bonus: (<math>T_1</math> - trade production in the city 1, <math>T_2</math> - trade production in the city 2, <math>D</math> - real distance between the cities):
 
Bonus from a caravan, when it enter in a existent trade place, you get only <math>\frac{1}{3}</math> of the bonus: (<math>T_1</math> - trade production in the city 1, <math>T_2</math> - trade production in the city 2, <math>D</math> - real distance between the cities):
* <math>\frac{(D + 10) (T_1 + T_2)}{24}</math>
+
*<math>\frac{(D + 10) (T_1 + T_2)}{24}</math>
 
The possession of the technologies Railroad and Flight each reduces the bonus by <math>\frac{1}{3}</math>. Then:
 
The possession of the technologies Railroad and Flight each reduces the bonus by <math>\frac{1}{3}</math>. Then:
* You have one of this technologies: <math>\frac{(D + 10) (T_1 + T_2)}{36}</math>
+
*You have one of this technologies:<math>\frac{(D + 10) (T_1 + T_2)}{36}</math>
* You have two of this technologies: <math>\frac{(D + 10) (T_1 + T_2)}{54}</math>
+
*You have two of this technologies:<math>\frac{(D + 10) (T_1 + T_2)}{54}</math>
* With experimental caravan bonus style (on [[Warclient|Warserver]]): <math>\frac{(2 \log(D + 20 + T_1 + T_2)) ^ 2}{3}</math>
+
*With experimental caravan bonus style (on [[Warclient|Warserver]]): <math>\frac{(2 \log(D + 20 + T_1 + T_2)) ^ 2}{3}</math>, with the same notation as for trade revenue (the final coefficiency is <math>(E/1000)^2</math> where <math>E</math> is "Trade_Revenue_Bonus" effect, it's <math>1\over3</math> if <math>E=577</math>).
  +
  +
These formulas are the base of the calculation. Different [[Government|governments]] output different amounts of trade in each city. Republic and Democracy get a +1 trade bonus in tiles that are generating trade, so usually, you will make a lot more profit under these governments. Monarchy and Communism get the +1 trade bonus only if they are celebrating.
  +
  +
  +
'''The following formulas are used under the server setting''' <code>trade_revenue_style = "SIMPLE"</code>
  +
  +
This formula is used in [[Multiplayer II Game Manual|MP2]] rulesets, but is also user configurable in any game via the above server setting.
  +
  +
Trade route revenue generated every turn in cities:
  +
  +
<math>T_1</math>= trade production in City<sub>1</sub>,
  +
  +
<math>T_2</math>= trade production in City<sub>2</sub>. (These values do not include the extra trade revenues from other trade routes.)
  +
  +
*Base trade formula:<math>\frac{3\times(T_1 + T_2 + 4)}{12}</math>
  +
  +
NOTE: some rulesets may have other adjustments for the following external conditions:
  +
  +
*Bonus/penalty for possessing certain technologies, wonders, diplomatic states.
  +
**In MP2:
  +
***Railroad and Flight reduce the bonus.
  +
***Diplomatic state of war cancels the bonus.
  +
*Trading with yourself or with another player
  +
*Cities are on same or different continents
  +
  +
See:
  +
  +
*<code>Trade_Revenue_Bonus</code> effects in <code>effects.ruleset</code>
  +
  +
  +
TODO: the above only specifies the base trade between cities. This is a component of a larger formula which remains to be specified here.
   
  +
<br />
These formulas are the base of the calculation. Different [[Government|governments]] output different amounts of trade in each city. Republic and Democracy get a +1 trade bonus in tiles that are generating trade, so usually, you will make a lot more profit under these governments. Monarchy and Communism get the +1 trade bonus only if they are celebrating.
 
   
=== Taxation of trade ===
+
===Taxation of trade===
 
For each city, multiply the trade output (after subtracting corruption) by the tax rates to yield the gold/luxury/science output ''taxed from trade''. (See add_tax_income() in common/city.c.) The problem is how round the result to exact integers, without increasing or decreasing the trade output (which must exactly equal the sum of the three tax outputs).
 
For each city, multiply the trade output (after subtracting corruption) by the tax rates to yield the gold/luxury/science output ''taxed from trade''. (See add_tax_income() in common/city.c.) The problem is how round the result to exact integers, without increasing or decreasing the trade output (which must exactly equal the sum of the three tax outputs).
   
Line 101: Line 371:
 
In Wikipedia, this method is the [[Wikipedia:Largest remainder method|Largest remainder method]] using the [[Wikipedia:Hare quota|Hare quota]]. (Wikipedia discusses elections, so pretend that the trade points are senate seats, and that the tax rates are 100 votes for the Gold, Luxury, or Science party lists.)
 
In Wikipedia, this method is the [[Wikipedia:Largest remainder method|Largest remainder method]] using the [[Wikipedia:Hare quota|Hare quota]]. (Wikipedia discusses elections, so pretend that the trade points are senate seats, and that the tax rates are 100 votes for the Gold, Luxury, or Science party lists.)
   
  +
In the government used during revolutions, everything is taxed to luxury despite of any settings.
==== Example 1 ====
 
  +
* Trade surplus: +2
 
  +
====Example 1====
* Tax rates: 60% science, 40% gold
 
  +
*Trade surplus: +2
  +
*Tax rates: 60% science, 40% gold
   
 
Initial multiplication:
 
Initial multiplication:
* <math>science = +2 \times 60\% = 1 + \frac{20}{100}</math>
+
*<math>science = +2 \times 60\% = 1 + \frac{20}{100}</math>
* <math>gold = +2 \times 40\% = 0 + \frac{80}{100}</math>
+
*<math>gold = +2 \times 40\% = 0 + \frac{80}{100}</math>
   
 
This gives 1 science and 0 gold, but uses only 1 of 2 trade points. Gold has the highest remainder (80 > 20), so Freeciv gives the other point to gold.
 
This gives 1 science and 0 gold, but uses only 1 of 2 trade points. Gold has the highest remainder (80 > 20), so Freeciv gives the other point to gold.
   
 
Final result:
 
Final result:
* 1 science, 50% of +2
+
*1 science, 50% of +2
* 1 gold, 50% of +2
+
*1 gold, 50% of +2
   
==== Example 2 ====
+
====Example 2====
* Trade surplus: +17
+
*Trade surplus: +17
* Tax rates: 30% science, 30% gold, 40% luxury
+
*Tax rates: 30% science, 30% gold, 40% luxury
   
 
Initial multiplication:
 
Initial multiplication:
* <math>science = +17 \times 30\% = 5 + \frac{10}{100}</math>
+
*<math>science = +17 \times 30\% = 5 + \frac{10}{100}</math>
* <math>gold = +17 \times 30\% = 5 + \frac{10}{100}</math>
+
*<math>gold = +17 \times 30\% = 5 + \frac{10}{100}</math>
* <math>luxury = +17 \times 40\% = 6 + \frac{80}{100}</math>
+
*<math>luxury = +17 \times 40\% = 6 + \frac{80}{100}</math>
   
 
This uses 5 + 5 + 6 = 16 trade points. Luxury has the highest remainder (80 > 10) and receives the 17th point.
 
This uses 5 + 5 + 6 = 16 trade points. Luxury has the highest remainder (80 > 10) and receives the 17th point.
   
 
Final result:
 
Final result:
* 5 science, ≈29.4% of +17
+
*5 science, ≈29.4% of +17
* 5 gold, ≈29.4% of +17
+
*5 gold, ≈29.4% of +17
* 7 luxury, ≈41.2% of +17
+
*7 luxury, ≈41.2% of +17
   
==== Example 3 ====
+
====Example 3====
* Trade surplus: +18
+
*Trade surplus: +18
* Tax rates: 30% science, 30% gold, 40% luxury
+
*Tax rates: 30% science, 30% gold, 40% luxury
   
 
Initial multiplication:
 
Initial multiplication:
* <math>science = +18 \times 30\% = 5 + \frac{40}{100}</math>
+
*<math>science = +18 \times 30\% = 5 + \frac{40}{100}</math>
* <math>gold = +18 \times 30\% = 5 + \frac{40}{100}</math>
+
*<math>gold = +18 \times 30\% = 5 + \frac{40}{100}</math>
* <math>luxury = +18 \times 40\% = 7 + \frac{20}{100}</math>
+
*<math>luxury = +18 \times 40\% = 7 + \frac{20}{100}</math>
   
 
This uses 5 + 5 + 7 = 17 trade points. Science and gold tie for the highest remainder. To break the tie, Freeciv would give the 18th point to the group with fewer points, but both groups have 5 points. In this case, Freeciv always prefers science to gold, and gives the 18th point to science.
 
This uses 5 + 5 + 7 = 17 trade points. Science and gold tie for the highest remainder. To break the tie, Freeciv would give the 18th point to the group with fewer points, but both groups have 5 points. In this case, Freeciv always prefers science to gold, and gives the 18th point to science.
   
 
Final result:
 
Final result:
* 6 science, ≈33.3% of +18
+
*6 science, ≈33.3% of +18
* 5 gold, ≈27.8% of +18
+
*5 gold, ≈27.8% of +18
* 7 luxury, ≈38.9% of +18
+
*7 luxury, ≈38.9% of +18
   
==== Example 4 ====
+
====Example 4====
* Trade surplus: +24
+
*Trade surplus: +24
* Tax rates: 60% science, 10% gold, 30% luxury
+
*Tax rates: 60% science, 10% gold, 30% luxury
   
 
Initial multiplication:
 
Initial multiplication:
* <math>science = +24 \times 60\% = 14 + \frac{40}{100}</math>
+
*<math>science = +24 \times 60\% = 14 + \frac{40}{100}</math>
* <math>gold = +24 \times 10\% = 2 + \frac{40}{100}</math>
+
*<math>gold = +24 \times 10\% = 2 + \frac{40}{100}</math>
* <math>luxury = +24 \times 30\% = 7 + \frac{20}{100}</math>
+
*<math>luxury = +24 \times 30\% = 7 + \frac{20}{100}</math>
   
 
This uses 14 + 2 + 7 = 23 points. Science and gold again tie for the highest remainder, but now gold has fewer points. To break the tie, Freeciv gives the 24th point to gold.
 
This uses 14 + 2 + 7 = 23 points. Science and gold again tie for the highest remainder, but now gold has fewer points. To break the tie, Freeciv gives the 24th point to gold.
   
 
Final result:
 
Final result:
* 14 science, ≈58.3% of +24
+
*14 science, ≈58.3% of +24
* 3 gold, 12.5% of +24
+
*3 gold, 12.5% of +24
* 7 luxury, ≈29.2% of +24
+
*7 luxury, ≈29.2% of +24
   
== City health ==
+
===Upkeep===
  +
Units homed to any city may require upkeep in shields, food or gold (in theory, in other outputs too, but this is a buggy matter), and, as a special case, "happiness upkeep" for agressive units (see [[Happiness]]). Buildings may require gold upkeep only. City population itself requires proportional food upkeep. Gold is paid city-based, nation-based or nation-based for units (as long as your nation vaults are big enough after ''previous'' cities' processing!) and city-based for buildings depending on upkeep style. You also may have bulbs upkeep for technologies but it is always nation based and will be discussed elsewhere.
  +
*Wonders never need upkeep. A city improvement doesn't pay upkeep if its upkeep value is not greater than its "Upkeep_Free" effect. Otherwise, it pays its ruleset-defined upkeep in gold.
  +
*Fanatic units don't pay any upkeep if the player has positive effect "Fanatics".
  +
*Ruleset unit upkeeps are multiplied on "Upkeep_Factor" effect value (this effect varies by types of upkeep but it is uniform for all units of a given player). Then, the upkeeps are subtracted from the units' home city free upkeep capacity as long as it is greater or equal the next upkeep value; if some value is going to exceed it, the remnant is subtracted from the unit's upkeep, and the rest of the units pay full upkeep. (This procedure has few difference from simple "city upkeep = max(sum(unit upkeeps) * upkeep_factor - free_upkeep, 0)" formula but it explains the upkeeps displayed in the city dialog.)
  +
*If there is not enough production/vaults for upkeep, some random buildings are sold, then some random units are disbanded with their upkeep (and in certain cases their cost) returned to the ballance, until the ballance goes above zero. (This procedure runs for national and/or city upkeep, depending on the ruleset.) In certain cases city size may be decreased at 1 (if the citizens can't get food from the granary or when an undisbandable unit can't get shields upkeep).
   
=== Settings ===
+
==City health==
  +
  +
===Settings===
   
 
The health of a city is defined by the possibility of an illness (plague). The following ruleset options are available in game.ruleset, section [civstyle]:
 
The health of a city is defined by the possibility of an illness (plague). The following ruleset options are available in game.ruleset, section [civstyle]:
Line 182: Line 461:
 
illness_pollution_factor = 50
 
illness_pollution_factor = 50
   
  +
===Equations===
Furthermore for the aqueduct and the sewer system an health effect is defined:
 
   
  +
The possibility of an illness is given by a base value, defined in the game.ruleset file (illness_base_factor: maximum propability for illness in percent). Illness due to trade infection and illness due to pollution are added to this value. The illness values calculated below are given in tenths of percent.
[effect_aqueduct_health]
 
name = "Health"
 
value = 50
 
reqs =
 
{ "type", "name", "range"
 
"Building", "Aqueduct", "City"
 
}
 
   
  +
The base illness value depends on the city size reduced by the minimum size for illness (illness_min_size) and is given by
[effect_sewer_system_health]
 
name = "Health"
 
value = 30
 
reqs =
 
{ "type", "name", "range"
 
"Building", "Aqueduct", "City"
 
"Building", "Sewer System", "City"
 
}
 
   
  +
<math>illness\_size = (1- \exp(- \frac{size - illness\_min\_size}{10})) \times 10 \times illness\_base\_factor</math>
The possibility of an illness is reduced by &lt;value&gt; percent defined by the effect '''Health'''
 
  +
This function starts at 0 for
   
  +
<math>size - illness\_min\_size = 0</math>
=== Equations ===
 
  +
and goes asymptotic to its maximum
  +
value (illness_base_factor).
   
The possibility of an illness is given by a base value, illness due to trade infection and illness due to pollution.
+
If a trade city had an illness within the last 5 turns the illness value is
  +
increased by
   
  +
<math>illness\_trade = \frac{illness\_trade\_infection}{100} \times \sqrt{size \times trade\_city\_size}</math>
The base illness value depends on the city size and is given by
 
 
<math>ill\_size = (1- \exp(- \frac{size}{10})) \times 10 \times illness\_base\_factor</math>
 
 
This function starts at 0 for size = 0 and goes asymptotic to its maximum
 
value (illness\_base\_factor).
 
 
If a trade city had an illness within the last 5 turns the illness is
 
increased by
 
   
  +
Pollution also increases the illness value:
<math>ill\_trade = \frac{illness\_trade\_infection}{100} \times \sqrt{size \times trade\_city\_size}</math>
 
   
  +
<math>illness\_pollution = \frac{illness\_pollution\_factor}{100} \times pollution</math>
Pollution also increases the illness:
 
   
  +
'''Remember:''' The illness value is the illness in tenth of percent, i.e. a value of 56 means 5.6% propability for an illness within the city.
<math>ill\_pollution = \frac{illness\_pollution\_factor}{100} \times pollution</math>
 
   
  +
===Example===
   
=== Example ===
 
   
 
 
[[Image:city_health_example.png | thumb | City health example (using this [[Math_of_Freeciv/health.m|m-file]])]]
 
[[Image:city_health_example.png | thumb | City health example (using this [[Math_of_Freeciv/health.m|m-file]])]]
   
 
Taking into account a city size of 1 to 50, a pollution level which equals six times the city size (pollution = 6 * size) and four trade cities of size 10 the illness possibility of the city is given in the following table (in percent).
 
Taking into account a city size of 1 to 50, a pollution level which equals six times the city size (pollution = 6 * size) and four trade cities of size 10 the illness possibility of the city is given in the following table (in percent).
   
{|border="1" style="margin: auto;"
+
{| style="margin: auto;" border="1"
!#
+
!#
!colspan="3"|(illness)
+
! colspan="3" |(illness)
!colspan="3"|aqueduct
+
! colspan="3" |aqueduct
!colspan="3"|aqueduct + sewer system
+
! colspan="3" |aqueduct + sewer system
 
|-
 
|-
!
+
!
!base
+
!base
!+trade
+
!+trade
!+pollution
+
!+pollution
!base
+
!base
!+trade
+
!+trade
!+pollution
+
!+pollution
!base
+
!base
!+trade
+
!+trade
 
!+pollution
 
!+pollution
 
|-
 
|-
|align="right"|5
+
| align="right" |5
|align="right"|9.800
+
| align="right" |9.800
|align="right"|11.200
+
| align="right" |11.200
|align="right"|12.700
+
| align="right" |12.700
|align="right"|4.900
+
| align="right" |4.900
|align="right"|5.600
+
| align="right" |5.600
|align="right"|6.350
+
| align="right" |6.350
|align="right"|1.960
+
| align="right" |1.960
|align="right"|2.240
+
| align="right" |2.240
|align="right"|2.540
+
| align="right" |2.540
 
|-
 
|-
|align="right"|10
+
| align="right" |10
|align="right"|15.800
+
| align="right" |15.800
|align="right"|17.800
+
| align="right" |17.800
|align="right"|20.800
+
| align="right" |20.800
|align="right"|7.900
+
| align="right" |7.900
|align="right"|8.900
+
| align="right" |8.900
|align="right"|10.400
+
| align="right" |10.400
|align="right"|3.160
+
| align="right" |3.160
|align="right"|3.560
+
| align="right" |3.560
|align="right"|4.160
+
| align="right" |4.160
 
|-
 
|-
|align="right"|15
+
| align="right" |15
|align="right"|19.400
+
| align="right" |19.400
|align="right"|21.800
+
| align="right" |21.800
|align="right"|26.300
+
| align="right" |26.300
|align="right"|9.700
+
| align="right" |9.700
|align="right"|10.900
+
| align="right" |10.900
|align="right"|13.150
+
| align="right" |13.150
|align="right"|3.880
+
| align="right" |3.880
|align="right"|4.360
+
| align="right" |4.360
|align="right"|5.260
+
| align="right" |5.260
 
|-
 
|-
|align="right"|20
+
| align="right" |20
|align="right"|21.600
+
| align="right" |21.600
|align="right"|24.400
+
| align="right" |24.400
|align="right"|30.400
+
| align="right" |30.400
|align="right"|10.800
+
| align="right" |10.800
|align="right"|12.200
+
| align="right" |12.200
|align="right"|15.200
+
| align="right" |15.200
|align="right"|4.320
+
| align="right" |4.320
|align="right"|4.880
+
| align="right" |4.880
|align="right"|6.080
+
| align="right" |6.080
 
|-
 
|-
|align="right"|25
+
| align="right" |25
|align="right"|22.900
+
| align="right" |22.900
|align="right"|26.100
+
| align="right" |26.100
|align="right"|33.600
+
| align="right" |33.600
|align="right"|11.450
+
| align="right" |11.450
|align="right"|13.050
+
| align="right" |13.050
|align="right"|16.800
+
| align="right" |16.800
|align="right"|4.580
+
| align="right" |4.580
|align="right"|5.220
+
| align="right" |5.220
|align="right"|6.720
+
| align="right" |6.720
 
|-
 
|-
|align="right"|30
+
| align="right" |30
|align="right"|23.800
+
| align="right" |23.800
|align="right"|27.300
+
| align="right" |27.300
|align="right"|36.300
+
| align="right" |36.300
|align="right"|11.900
+
| align="right" |11.900
|align="right"|13.650
+
| align="right" |13.650
|align="right"|18.150
+
| align="right" |18.150
|align="right"|4.760
+
| align="right" |4.760
|align="right"|5.460
+
| align="right" |5.460
|align="right"|7.260
+
| align="right" |7.260
 
|-
 
|-
|align="right"|35
+
| align="right" |35
|align="right"|24.200
+
| align="right" |24.200
|align="right"|27.900
+
| align="right" |27.900
|align="right"|38.400
+
| align="right" |38.400
|align="right"|12.100
+
| align="right" |12.100
|align="right"|13.950
+
| align="right" |13.950
|align="right"|19.200
+
| align="right" |19.200
|align="right"|4.840
+
| align="right" |4.840
|align="right"|5.580
+
| align="right" |5.580
|align="right"|7.680
+
| align="right" |7.680
 
|-
 
|-
|align="right"|40
+
| align="right" |40
|align="right"|24.500
+
| align="right" |24.500
|align="right"|28.500
+
| align="right" |28.500
|align="right"|40.500
+
| align="right" |40.500
|align="right"|12.250
+
| align="right" |12.250
|align="right"|14.250
+
| align="right" |14.250
|align="right"|20.250
+
| align="right" |20.250
|align="right"|4.900
+
| align="right" |4.900
|align="right"|5.700
+
| align="right" |5.700
|align="right"|8.100
+
| align="right" |8.100
 
|-
 
|-
|align="right"|45
+
| align="right" |45
|align="right"|24.700
+
| align="right" |24.700
|align="right"|28.900
+
| align="right" |28.900
|align="right"|42.400
+
| align="right" |42.400
|align="right"|12.350
+
| align="right" |12.350
|align="right"|14.450
+
| align="right" |14.450
|align="right"|21.200
+
| align="right" |21.200
|align="right"|4.940
+
| align="right" |4.940
|align="right"|5.780
+
| align="right" |5.780
|align="right"|8.480
+
| align="right" |8.480
 
|-
 
|-
|align="right"|50
+
| align="right" |50
|align="right"|24.800
+
| align="right" |24.800
|align="right"|29.300
+
| align="right" |29.300
|align="right"|44.300
+
| align="right" |44.300
|align="right"|12.400
+
| align="right" |12.400
|align="right"|14.650
+
| align="right" |14.650
|align="right"|22.150
+
| align="right" |22.150
|align="right"|4.960
+
| align="right" |4.960
|align="right"|5.860
+
| align="right" |5.860
|align="right"|8.860
+
| align="right" |8.860
 
|}
 
|}
   
  +
===Health effect===
  +
  +
Furthermore for the aqueduct and the sewer system a health effect is defined.
  +
  +
[effect_aqueduct_health]
  +
name = "Health_Pct"
  +
value = 50
  +
reqs =
  +
{ "type", "name", "range"
  +
"Building", "Aqueduct", "City"
  +
}
  +
  +
[effect_sewer_system_health]
  +
name = "Health_Pct"
  +
value = 30
  +
reqs =
  +
{ "type", "name", "range"
  +
"Building", "Aqueduct", "City"
  +
"Building", "Sewer System", "City"
  +
}
  +
  +
The possibility of an illness is reduced by &lt;value&gt; percent defined by the effect '''Health_Pct''' (i.e aqueduct + sewer system = Health effect of 80; an base illness possibility of 10% is reduced by 80% to 2%).
   
== Migration ==
+
==Migration==
   
=== Settings ===
+
===Settings===
   
 
Migration between cities is controlled by the following game settings. They can be changed by using the ''set'' server command. ''help &lt;setting&gt;'' will give you more information.
 
Migration between cities is controlled by the following game settings. They can be changed by using the ''set'' server command. ''help &lt;setting&gt;'' will give you more information.
   
* migration - Whether to enable citizen migration (default: 0 = off)
+
*migration - Whether to enable citizen migration (default: 0 = off)
* mgr_turninterval - Number of turns between migrations from a city (default: 5; min:1; max: 100)
+
*mgr_turninterval - Number of turns between migrations from a city (default: 5; min:1; max: 100)
* mgr_foodneeded - Whether migration is limited by food (default: 1 = on)
+
*mgr_foodneeded - Whether migration is limited by food (default: 1 = on)
* mgr_distance - Maximum distance citizens may migrate (default: 3; min: 1; max: 7)
+
*mgr_distance - Maximum distance citizens may migrate (default: 3; min: 1; max: 7)
* mgr_nationchance - Percent probability for migration within the same nation (default: 50; min: 0; max: 100)
+
*mgr_nationchance - Percent probability for migration within the same nation (default: 50; min: 0; max: 100)
* mgr_worldchance- Percent probability for migration between foreign cities (default: 10; min:0; max: 100)
+
*mgr_worldchance- Percent probability for migration between foreign cities (default: 10; min:0; max: 100)
   
=== Equations ===
+
===Equations===
   
 
Helper function to calculate a "score" of a city. The score is used to get an estimate of the "migration desirability" of the city. The higher the score the more likely citizens will migrate to it.
 
Helper function to calculate a "score" of a city. The score is used to get an estimate of the "migration desirability" of the city. The higher the score the more likely citizens will migrate to it.
Line 379: Line 662:
 
The score depends on the city size, the feeling of its citizens, the cost of all buildings in the city, and the surplus of trade, luxury and science.
 
The score depends on the city size, the feeling of its citizens, the cost of all buildings in the city, and the surplus of trade, luxury and science.
   
* base formula: <math>score = (city\_size + feeling) \times \prod factors</math>
+
*base formula:<math>score = (city\_size + feeling) \times \prod factors</math>
* feeling of the citizens: <math>feeling = 1.00 \times [happy~citizens] + 0.00 \times [content~citizens] - 0.25 \times [unhappy~citizens] - 0.50 \times [unhappy~citizens]</math>
+
*feeling of the citizens:<math>feeling = 1.00 \times [happy~citizens] + 0.00 \times [content~citizens] - 0.25 \times [unhappy~citizens] - 0.50 \times [angry~citizens]</math>
* factors
+
*factors
** if the city has at least one wonder a factor of 1.25 is added
+
**if the city has at least one wonder a factor of 1.25 is added
** for the capital an additional factor of 1.25 is used
+
**for the capital an additional factor of 1.25 is used
** an additional factor is given by the effect 'Migration_Pct': <math>f = 1 + \frac{\sum_{effect} Migration\_Pct}{100}</math>
+
**an additional factor is given by the effect 'Migration_Pct':<math>f = 1 + \frac{\sum_{effect} Migration\_Pct}{100}</math>
** the build costs of all buildings: <math>f = (1 + \frac{1 - \exp(- \frac{[build~shield~cost] }{1000})}{5})</math>
+
**the build costs of all buildings:<math>f = \left(1 + \frac{1 - \exp\left(- \frac{[build~shield~cost] }{1000}\right)}{5}\right)</math>
** the trade of the city: <math>f = (1 + \frac{1 - \exp(- \frac{[city~surplus~trade] }{100 })}{5})</math>
+
**the trade of the city:<math>f = \left(1 + \frac{1 - \exp\left(- \frac{[city~surplus~trade] }{100 }\right)}{5}\right)</math>
** the luxury within the city: <math>f = (1 + \frac{1 - \exp(- \frac{[city~surplus~luxury] }{100 })}{5})</math>
+
**the luxury within the city:<math>f = \left(1 + \frac{1 - \exp\left(- \frac{[city~surplus~luxury] }{100 }\right)}{5}\right)</math>
** the science within the city: <math>f = (1 + \frac{1 - \exp(- \frac{[city~surplus~science]}{100 })}{5})</math>
+
**the science within the city:<math>f = \left(1 + \frac{1 - \exp\left(- \frac{[city~surplus~science]}{100 }\right)}{5}\right)</math>
  +
**the food available in the city:<math>f = \left(1 + [city~surpuls~food] / 10\right)</math>
   
The last four factors f have values between 1 and 1.2; the overall factor will be between 1.0 (smaller cities) and 2.0 (bigger cities)
+
The first four factors f have values between 1 and 1.2 while the factor for food is limited between 0.9 (10 food) and 1.2 (+20 food). The overall factor will be between 1.0 (smaller cities) and 2.0 (bigger cities)
   
[build shield cost], [city surplus trade], [city surplus luxury] and [city surplus science] '''must''' be &gt;= 0!
+
[build shield cost], [city surplus trade], [city surplus luxury] and [city surplus science] '''must''' be &gt;= 0! [city surplus food] can be below zero.
   
 
The score of the source city is multiplied by 3 to take into account the persistence of the citizens.
 
The score of the source city is multiplied by 3 to take into account the persistence of the citizens.
Line 401: Line 685:
   
 
<math>weight = \frac{[maximal~distance] + 1 - dist}{[maximal~distance] + 1}</math>
 
<math>weight = \frac{[maximal~distance] + 1 - dist}{[maximal~distance] + 1}</math>
 
 
<math>score\_target = city\_score * weight</math>
 
<math>score\_target = city\_score * weight</math>
   
=== Example ===
+
===Example===
   
 
For the following three city the migration score is calculated:
 
For the following three city the migration score is calculated:
   
{|border="1" cellpadding="2" style="margin: auto;"
+
{| style="margin: auto;" cellpadding="2" border="1"
!colspan="4"|city characteristics
+
! colspan="4" |city characteristics
 
|-
 
|-
!
+
!
!city 1
+
!city 1
!city 2
+
!city 2
 
!city 3
 
!city 3
 
|-
 
|-
 
|city size
 
|city size
|align="right"|17
+
| align="right" |17
|align="right"|5
+
| align="right" |5
|align="right"|3
+
| align="right" |3
 
|-
 
|-
 
|citizens (happy/content/unhappy/angry)
 
|citizens (happy/content/unhappy/angry)
|align="right"|7/9/1/0
+
| align="right" |7/9/1/0
|align="right"|1/4/0/0
+
| align="right" |1/4/0/0
|align="right"|0/3/0/0
+
| align="right" |0/3/0/0
 
|-
 
|-
 
|city has a wonder
 
|city has a wonder
|align="right"|yes
+
| align="right" |yes
|align="right"|yes
+
| align="right" |yes
|align="right"|no
+
| align="right" |no
 
|-
 
|-
 
|city is capital
 
|city is capital
|align="right"|yes
+
| align="right" |yes
|align="right"|no
+
| align="right" |no
|align="right"|no
+
| align="right" |no
 
|-
 
|-
 
|effect ''Migration_Pct''
 
|effect ''Migration_Pct''
|align="right"|30
+
| align="right" |30
|align="right"|0
+
| align="right" |0
|align="right"|0
+
| align="right" |0
 
|-
 
|-
 
|build shild cost
 
|build shild cost
|align="right"|2500
+
| align="right" |2500
|align="right"|1000
+
| align="right" |1000
|align="right"|250
+
| align="right" |250
 
|-
 
|-
 
|city surplus (trade/luxury/science)
 
|city surplus (trade/luxury/science)
|align="right"|62/16/15
+
| align="right" |62/16/15
|align="right"|10/2/5
+
| align="right" |10/2/5
|align="right"|6/0/6
+
| align="right" |6/0/6
 
|-
 
|-
!colspan="4"|distance
+
! colspan="4" |distance
 
|-
 
|-
 
|city 1
 
|city 1
|align="right"| -
+
| align="right" | -
|align="right"|3
+
| align="right" |3
|align="right"|5
+
| align="right" |5
 
|-
 
|-
 
|city 2
 
|city 2
|align="right"|3
+
| align="right" |3
|align="right"| -
+
| align="right" | -
|align="right"|3
+
| align="right" |3
 
|-
 
|-
 
|city 3
 
|city 3
|align="right"|5
+
| align="right" |5
|align="right"|3
+
| align="right" |3
|align="right"| -
+
| align="right" | -
 
|-
 
|-
!colspan="4"|calculated values
+
! colspan="4" |calculated values
 
|-
 
|-
!
+
!
!city 1
+
!city 1
!city 2
+
!city 2
 
!city 3
 
!city 3
 
|-
 
|-
 
|city size
 
|city size
|align="right"|17.000
+
| align="right" |17.000
|align="right"|5.000
+
| align="right" |5.000
|align="right"|3.000
+
| align="right" |3.000
 
|-
 
|-
 
|feeling
 
|feeling
|align="right"|6.750
+
| align="right" |6.750
|align="right"|1.000
+
| align="right" |1.000
|align="right"|0.000
+
| align="right" |0.000
 
|-
 
|-
 
|factor: wonder
 
|factor: wonder
|align="right"|1.250
+
| align="right" |1.250
|align="right"|1.250
+
| align="right" |1.250
|align="right"|1.000
+
| align="right" |1.000
 
|-
 
|-
 
|factor: capital
 
|factor: capital
|align="right"|1.250
+
| align="right" |1.250
|align="right"|1.000
+
| align="right" |1.000
|align="right"|1.000
+
| align="right" |1.000
 
|-
 
|-
 
|factor: effect ''Migration_Pct''
 
|factor: effect ''Migration_Pct''
|align="right"|1.300
+
| align="right" |1.300
|align="right"|1.000
+
| align="right" |1.000
|align="right"|1.000
+
| align="right" |1.000
 
|-
 
|-
 
|factor: build shield cost
 
|factor: build shield cost
|align="right"|1.184
+
| align="right" |1.184
|align="right"|1.126
+
| align="right" |1.126
|align="right"|1.044
+
| align="right" |1.044
 
|-
 
|-
 
|factor: surplus trade
 
|factor: surplus trade
|align="right"|1.092
+
| align="right" |1.092
|align="right"|1.019
+
| align="right" |1.019
|align="right"|1.012
+
| align="right" |1.012
 
|-
 
|-
 
|factor: surplus luxery
 
|factor: surplus luxery
|align="right"|1.030
+
| align="right" |1.030
|align="right"|1.004
+
| align="right" |1.004
|align="right"|1.000
+
| align="right" |1.000
 
|-
 
|-
 
|factor: surplus science
 
|factor: surplus science
|align="right"|1.028
+
| align="right" |1.028
|align="right"|1.010
+
| align="right" |1.010
|align="right"|1.012
+
| align="right" |1.012
 
|-
 
|-
 
|basic city score
 
|basic city score
|align="right"|66.044
+
| align="right" |66.044
|align="right"|8.726
+
| align="right" |8.726
|align="right"|3.208
+
| align="right" |3.208
 
|-
 
|-
 
|weight: distance city 1
 
|weight: distance city 1
|align="right"| -
+
| align="right" | -
|align="right"|0.625
+
| align="right" |0.625
|align="right"|0.375
+
| align="right" |0.375
 
|-
 
|-
 
|weight: distance city 2
 
|weight: distance city 2
|align="right"|0.625
+
| align="right" |0.625
|align="right"| -
+
| align="right" | -
|align="right"|0.625
+
| align="right" |0.625
 
|-
 
|-
 
|weight: distance city 3
 
|weight: distance city 3
|align="right"|0.375
+
| align="right" |0.375
|align="right"|0.625
+
| align="right" |0.625
|align="right"| -
+
| align="right" | -
 
|-
 
|-
!colspan="4"|migration checks
+
! colspan="4" |migration checks
 
|-
 
|-
!source city / target city
+
!source city / target city
!city 1 (source)
+
!city 1 (source)
!city 2 (source)
+
!city 2 (source)
 
!city 3 (source)
 
!city 3 (source)
 
|-
 
|-
 
|city 1 (target)
 
|city 1 (target)
|align="center"| -
+
| align="center" | -
|align="right"|'''26.179 / 41.2773'''
+
| align="right" |'''26.179 / 41.2773'''
|align="right"|'''9.623 / 24.7664'''
+
| align="right" |'''9.623 / 24.7664'''
 
|-
 
|-
 
|city 2 (target)
 
|city 2 (target)
|align="right"|198.131 / 5.4539
+
| align="right" |198.131 / 5.4539
|align="center"| -
+
| align="center" | -
|align="right"|9.623 / 5.4539
+
| align="right" |9.623 / 5.4539
 
|-
 
|-
 
|city 3 (target)
 
|city 3 (target)
|align="right"|198.131 / 2.0048
+
| align="right" |198.131 / 2.0048
|align="right"|26.179 / 3.2076
+
| align="right" |26.179 / 3.2076
|align="center"| -
+
| align="center" | -
 
|}
 
|}
   
 
Migration will take place from city 2 to city 1 and from city 3 to city 1 with the possibility given in the corresponding game settings (''mgr_nationchance'' and ''mgr_worldchance'').
 
Migration will take place from city 2 to city 1 and from city 3 to city 1 with the possibility given in the corresponding game settings (''mgr_nationchance'' and ''mgr_worldchance'').
   
== Science ==
+
===Migration Effect===
  +
  +
TODO: exact description of the effect; increase / decrease the possibility of migration (i.e for different governments)
  +
  +
==Science==
   
 
Technology cost formula depends on several game settings: techcoststyle, researchcost, techcostdoubleyear, techleackage, techleackagerate. There might be differences between calculated values and real-game ones due to rounding to integers in several places.
 
Technology cost formula depends on several game settings: techcoststyle, researchcost, techcostdoubleyear, techleackage, techleackagerate. There might be differences between calculated values and real-game ones due to rounding to integers in several places.
   
* Future techs: calculated like common techs with techcoststyle=0.
+
*Future techs: calculated like common techs with techcoststyle=0.
* Common techs:
+
*Common techs:
** If techcoststyle=2, ruleset might set its own values, not calculated by FreeCiv. For the techs not overrided by the ruleset, cost is calculated like if techcoststyle=1.
+
**If techcoststyle=2, ruleset might set its own values, not calculated by Freeciv. For the techs not overrided by the ruleset, cost is calculated like if techcoststyle=1.
** If techcoststyle=1 (the default case), <math>
+
**If techcoststyle=1 (the default case),<math>
 
\textrm{basecost}=\frac12 \times (n+2)^{1.5} \times \textrm{researchcost}
 
\textrm{basecost}=\frac12 \times (n+2)^{1.5} \times \textrm{researchcost}
</math>, but not less than researchcost. <math>n</math> is number of all (including already researched) technologies required by given tech.
+
</math>, but not less than researchcost.<math>n</math> is number of all (including already researched) technologies required by given tech.
** If techcoststyle=0, to discover nth technology you need <math>\textrm{basecost}=(n-1)\times\textrm{researchcost}</math> (like in Civilization I/II games).
+
**If techcoststyle=0, to discover nth technology you need<math>\textrm{basecost}=(n-1)\times\textrm{researchcost}</math> (like in Civilization I/II games).
   
 
Additional rules.
 
Additional rules.
* If techcostdoubleyear parameter is not zero, cost doubles starting from this year.
+
*If techcostdoubleyear parameter is not zero, cost doubles starting from this year.
* If techleakage parameter is not zero, you get bonus when other players already have developed the tech. The formula is:<math>
+
*If techleakage parameter is not zero, you get bonus when other players already have developed the tech. The formula is:<math>
 
\textrm{bonus}=
 
\textrm{bonus}=
 
\textrm{basecost}\times
 
\textrm{basecost}\times
Line 585: Line 872:
 
1-\frac{\textrm{techleakagerate}}{100}\times\frac{p_2}{p_1}
 
1-\frac{\textrm{techleakagerate}}{100}\times\frac{p_2}{p_1}
 
\right)
 
\right)
</math>, where <math>p_1</math> is total number of players and <math>p_2</math> is:
+
</math>, where<math>p_1</math> is total number of players and<math>p_2</math> is:
** number of players that know the technology and you have embassy, when techleakage=1,
+
**number of players that know the technology and you have embassy, when techleakage=1,
** number of players that know the technology, when techleakage=2,
+
**number of players that know the technology, when techleakage=2,
** number of players that know the technology, excluding barbarian players, when techleakage=3 (in this case total number of players is calculated without barbarians too).
+
**number of players that know the technology, excluding barbarian players, when techleakage=3 (in this case total number of players is calculated without barbarians too).
:Note: <math>\textrm{techleakagerate}</math> is a [[Warclient|Warserver]] setting. On standard server, <math>\textrm{techleakagerate} = 100</math>.
+
:Note:<math>\textrm{techleakagerate}</math> is a [[Warclient|Warserver]] setting. On standard server,<math>\textrm{techleakagerate} = 100</math>.
* For AI players there might be a penalty/bonus depending on AI skill.
+
*For AI players there might be a penalty/bonus depending on AI skill.
* If the calculated cost is zero, the real cost is 1 bulb.
+
*If the calculated cost is zero, the real cost is 1 bulb.
   
=== Getting tech without research ===
+
===Getting tech without research===
You can get techs, when you conquer a city, use a diplomat, or from [[Great Library]]. The chances and costs of this is decided by server settings conquercost, diplochance, freecost etc.
+
You can get techs, when you conquer a city, use a diplomat, from [[Great Library]], by completing traderoutes, or by Darwin's Voyage wonder or discovery of Philosophy. The chances and costs of this is decided by server settings conquercost, diplochance, freecost, by disallowing traderoutes before the start of each game, etc.
   
=== Research ===
+
===Research===
 
You can research either by science out put from your trade income, or by using Specialists when your cities are at size 5 or above.
 
You can research either by science out put from your trade income, or by using Specialists when your cities are at size 5 or above.
 
{|
 
{|
!Specialists
+
!Specialists
!Default output
+
!Default output
!With library
+
!With library
 
!With university
 
!With university
 
|-
 
|-
|1 scientists
+
| 1 scientists
|3 bulbs
+
| 3 bulbs
|6 bulbs
+
| 6 bulbs
 
|10 bulbs
 
|10 bulbs
 
|-
 
|-
|2 scientists
+
| 2 scientists
|6 bulbs
+
| 6 bulbs
 
|12 bulbs
 
|12 bulbs
 
|21 bulbs
 
|21 bulbs
 
|}
 
|}
  +
  +
==Probability of winning a fight==
  +
:'''Main page: [[/Battle outcome]]'''
  +
The chances of winning a fight are sometimes counter-intuitive. E.g., what would you say are your chances of winning in the following situation (after taking into account the land advantages and other modifiers): you have an attack of 2 against a defense of 3, and the same number of hit points? Considering that the probability of winning each round is 2/5, you might think that this will give you with a reasonable chance of victory, something like 40%. Lost. You only have 19% chances of winning. The fact that the battle lasts several rounds tends to give a larger advantage to the biggest power than one could think beforehand.
  +
  +
Supposing the reader is aware of the rules of the fight (for each round, take a random number, decide who wins that round, etc.), let's try to find a formula representing the chances of victory.
  +
  +
===Notations and basic computations===
  +
Consider a unit having a strength (all modifications, field, city, unit experience of combat, etc. being applied)
  +
  +
<math>s</math>
  +
and an enemy unit having a defense
  +
  +
<math>r</math>
  +
. The number of hit points of the defending unit is written
  +
  +
<math>d_\text{hp}</math>
  +
, the damages per victorious rounds from the attacking unit is
  +
  +
<math>a_\text{fp}</math>
  +
. Let us note
  +
  +
<math>k</math>
  +
the number of victorious rounds required to win the fight. And
  +
  +
<math>l</math>
  +
is the number of rounds that, if lost, implies a defeat (
  +
  +
<math>l</math>
  +
is for "losing allowance"). When the attacking unit cause one damage per victorious rounds (
  +
  +
<math>a_\text{fp}=1</math>
  +
),
  +
  +
<math>k</math>
  +
is the number of hit points of the defending unit (
  +
  +
<math>d_\text{hp}</math>
  +
). More generally,
  +
  +
<math>k = \lfloor\frac{d_\text{hp} + a_\text{fp} - 1}{a_\text{fp}}\rfloor</math>
  +
.
  +
  +
<math>l</math>
  +
may be computed similarily. The chance of winning each round, let us note it
  +
  +
<math>p</math>
  +
, is
  +
  +
<math>p = \frac{s}{s+r}</math>
  +
. (Thus the chance of losing a round is
  +
  +
<math>1-p</math>
  +
.)
  +
  +
===Reasoning===
  +
Now let us suppose that the fight takes
  +
  +
<math>n</math>
  +
rounds to achieve, and let us compute the probability of victory. Note that we do not know
  +
  +
<math>n</math>
  +
in advance but we suppose for now that it is given. For a given
  +
  +
<math>n</math>
  +
, the probability of victory is the probability that
  +
  +
<math>k</math>
  +
rounds have been won over these
  +
  +
<math>n</math>
  +
tries and less than
  +
  +
<math>l</math>
  +
rounds have been lost. If
  +
  +
<math>n < k + l</math>
  +
, then the probability of victory is simply the probability that
  +
  +
<math>k</math>
  +
rounds have been won over these
  +
  +
<math>n</math>
  +
tries (as this implies that less than
  +
  +
<math>l</math>
  +
rounds have been lost). In case of victory, the last round must be the final hit (otherwise the fight would have been stopped earlier). Apart from that, there must be
  +
  +
<math>k - 1</math>
  +
hits among the
  +
  +
<math>n - 1</math>
  +
other rounds. That probability is given by a [http://en.wikipedia.org/wiki/Binomial_distribution binomial]
  +
  +
<math>B(n-1,k-1)</math>
  +
and is
  +
  +
<math>{n-1 \choose k-1} p^{k-1} (1-p)^{n-k}</math>
  +
. As the last round must be won, we multiply by
  +
  +
<math>p</math>
  +
and get a probability of victory with
  +
  +
<math>n</math>
  +
rounds of
  +
  +
<math>{n-1 \choose k-1} p^k (1-p)^{n-k}</math>
  +
. For the attacking unit to win the fight, we must have
  +
  +
<math>k \leq n < k + l</math>
  +
. Thus finally the probability of winning equals:
  +
  +
<math>\sum_{n = k}^{k+l-1} {n-1 \choose k-1} p^k (1-p)^{n-k}</math>
  +
.
  +
  +
===Alternative reasoning===
  +
The freeciv source code uses a slightly different reasoning (look at ./common/combat.c:unit_win_chance() and ./common/combat.c:win_chance()). Let us note
  +
  +
<math>d</math>
  +
the number of rounds lost, which must be smaller than
  +
  +
<math>l</math>
  +
for a victorious attack. Then we have the following probability of victory.
  +
  +
<math>\sum_{d = 0}^{l - 1} {k - 1 + d \choose d} p^{k-1} (1-p)^d p</math>
  +
. We get the initial formula by using
  +
  +
<math>n = k + d</math>
  +
and
  +
  +
<math>{n-1 \choose n-k} = {n-1 \choose k-1}</math>
  +
. In the code,
  +
  +
<math>k</math>
  +
is def_N_lose,
  +
  +
<math>l</math>
  +
is att_N_lose,
  +
  +
<math>p</math>
  +
is def_P_lose1,
  +
  +
<math>(1-p)</math>
  +
is att_P_lose1,
  +
  +
<math>d</math>
  +
is lr.
  +
  +
==Unit bribe cost==
  +
'''''bribe_cost''''' = (1 + '''''UHP''''') * ('''''base'''''/2)
  +
  +
where
  +
  +
'''''UHP''''' = unit health percent = (current hit points / full hit points)
  +
  +
'''''base''''' = '''''TG''''' + '''''GI<sub>bbc</sub>''''' * ('''''UCS'''''/10) * (1 + '''''EFT<sub>ubc_pct</sub>'''''/100) * ('''''VPF'''''/100) * ('''''VMR'''''/'''''SMR''''') / ('''''δGC'''''+2)
  +
  +
'''''TG''''' = treasury gold for player of bribed unit
  +
  +
'''''GI<sub>bbc</sub>''''' = <code>game.info.base_bribe_cost</code> (set in game.ruleset, often set as '''750''')
  +
  +
'''''δGC''''' = [[Manhattan distance|Manhattan Distance]] to nearest government center or capital
  +
  +
'''''UCS''''' = unit shield cost
  +
  +
'''''EFT<sub>ubc_pct</sub>''''' = '''EFT_UNIT_BRIBE_COST_PCT''', ''any percentage bonus vs. bribing that are active in the ruleset''
  +
  +
'''''VPF''''' = Veteran Power Factor. ''(e.g., veteran level 1 is often VPF=150 in many rulesets.)''
  +
  +
'''''VMR''''' = Veteran move rate
  +
  +
'''''SMR''''' = Standard move rate<br />
  +
==City incite cost==
  +
Gold needed to incite a city is calculated by this formula (most operations are in real numbers):
  +
  +
:<math>IC = (G_O + BIC + IUF \times \sum S_u + IIF \times \sum S_i) \times</math>
  +
::<math> \times H \times (OF) \times\max(1, N_\text{spec}+N_\text{cont}+2N_\text{happy}-2N_\text{angry})\times </math>
  +
::<math>\times ITF / (\min(OCD, 32)+3)\times (NF)\times \frac{1+EIC/100\%}{100}</math>
  +
  +
where
  +
:<math>G_O</math>is owner's current treasury
  +
:<i>BIC</i> is incite_cost.base_incite_cost from game.ruleset
  +
:<i>IUF, IIF</i> are factors of shield costs of units and buildings inside: incite_cost.unit_factor and improvement_factor
  +
:<math>H</math>is city happiness factor: 1 for disorder, 2 for content, 4 for celebrating
  +
:If citizens don't have nationalities in the game, ''OF'' is 1/2 for buying back a city that you have founded and 2/3 for buying third-party conquered city. If they have, ''NF'' is calculated from citizens' nationalities as<math>\frac{N_O+0.7N_3+0.5N_I}{N_\text{all}}</math>.
  +
:<math>N_{sth}</math>is the number of corresponding citizens: ''<big>N<sub>O</sub> = current owner N<sub>3</sub> = third nationality N<sub>I =</sub> indigenous (original native owner)</big>''
  +
:''ITF'' is incite_cost.total_factor
  +
:''OCD'' is the [[Manhattan distance|Manhattan Distance]] to the owner's capital.
  +
:''EIC'' is "<code>Incite_Cost_Pct</code>" effect values: add the sum of all actively triggered "<code>Incite_Cost_Pct</code>" effects for this city as described in the <code>effects.ruleset</code> file for the ruleset of the game being played.
  +
  +
==Global Warming and Nuclear Winter==
  +
  +
The two global catastrophes are driven by the same engine, <tt>update_environmental_upset()</tt> in <tt>srv_main.c</tt>, but are independent of each other.
  +
  +
There isn't very much configurable about this mechanism. The various magic numbers mentioned below are hardcoded. About all you can do in rulesets currently is to change how likely tiles are to get polluted in the first place (base_pollution). Since 3.0, two new server settings <tt>globalwarming_percent</tt> and <tt>nuclearwinter_percent</tt> are introduced to balance some games better.
  +
  +
Each turn, the chance of catastrophe is affected by the current count of polluted tiles (for GW) or tiles with fallout (for NW) on the world map. (Pollution in cities doesn't directly affect global warming, beyond being the means by which tiles become polluted.)
  +
  +
However, the chance is not purely a function of that number; it also depends on the past.
  +
  +
The chance of catastrophe "accum" is calculated each turn as follows:
  +
  +
<math>accum_t = \max(0,accum_{t-1} + current - level)</math>
  +
  +
<math>current = \lfloor count\times percent/100\rfloor</math>
  +
  +
where the variables are:
  +
{| style="margin: auto;" cellpadding="2" border="1"
  +
! rowspan="2" |Variable
  +
! colspan="2" |Specific name
  +
! rowspan="2" |Description
  +
|-
  +
!Global Warming
  +
!Nuclear Winter
  +
|-
  +
|count
  +
| -
  +
| -
  +
|Number of polluted tiles this turn
  +
|-
  +
|current
  +
|game.info.heating
  +
|game.info.cooling
  +
|Number of polluted tiles this turn, in newer versions multiplied on the percentage.<br />Applied as a delta (hence name "heating"/"cooling").<br />(Only stored for display purposes, not carried from one turn to the next.)
  +
|-
  +
|percent
  +
|game.server.global_warming_percent
  +
|game.server.nuclear_winter_percent
  +
|The server setting, goes from 1 to 10000, defaults to 100
  +
|-
  +
|level
  +
|game.info.warminglevel
  +
|game.info.coolinglevel
  +
|A constant (but see below): critical level of pollution<br />(same units as "current")
  +
|-
  +
|accum
  +
|game.info.globalwarming
  +
|game.info.nuclearwinter
  +
|The chance of catastrophe each turn is proportional to "accum".<br />Carried from one turn to the next.
  +
|}
  +
  +
Thus:
  +
*<math>count = level\times\frac{100}{percent}</math>represents a critical number of polluted tiles at which the chance of catastrophe remains constant over time. Depending on the past, that chance could be zero or it could be a high level.
  +
*If ''current'' is below ''level'', then the chance of catastrophe will decline and eventually become zero.
  +
*If ''current'' is above ''level'', then the chance of catastrophe will increase.
  +
  +
Thus, the effect of polluted tiles is cumulative. If there's currently an elevated risk of catastrophe, even if you then clean up all existing polluted tiles in the world in a single turn with Engineers, the risk won't necessarily drop to zero next turn; it will gradually reduce over several turns until it hits zero.
  +
  +
For both kinds of catastrophe, ''level'' is initially based on the map size intiles:
  +
  +
<math>level = \left \lceil \frac{1}{500} \times map\_num\_tiles() \right \rceil</math>
  +
. Since ''accum'' starts at zero, this effectively means that bigger worlds can take more punishment before there is any risk of catastrophe: 0.2% of a world's tiles must become polluted before the risk starts to increase at all, if ''percent'' is default. Nevertheless, [[Longturn]]ers have complained on too quick pollution. Changing the multiplier, one can make this number up to 100 times bigger or smaller. The actual chance of catastrophe is also affected by the map size in tiles: ignoring rounding,
  +
  +
<math>P(catastrophe) = \frac{20 \times accum}{map\_num\_tiles()}</math>
  +
  +
===Client display===
  +
  +
The client lets you see quantities like the following:
  +
  +
Global warming chance: 6% (-1%/turn)
  +
Nuclear winter chance: 0% (-2%/turn)
  +
  +
Shows the rate of global warming:
  +
Pollution rate: -1%
  +
Chance of catastrophic warming each turn: 6%
  +
(Up to 2.1.11/2.2.0, due to a bug -- {{gna|15563}} -- the quantities displayed are only really percentages for the default map size of 4000 tiles. For bigger maps, the percentage displayed will be too big, and a displayed chance of 100% will correspond to a
  +
  +
<math>P(catastrophe)</math>
  +
of less than 1.0. This is fixed as of 2.2.1.)
  +
  +
The displayed "chance" is proportional to "accum". The "rate" is proportional to "current - level". They have the same units; in the first example, you can expect the displayed "Global warming chance" to drop to (approximately) 5% next turn (assuming the number of polluted tiles doesn't change wildly). Examples:
  +
*When "chance" is 0% and "rate" is negative, you're comfortably below the critical level of pollution and "chance" will remain zero.
  +
*When "rate" is 0%, you are around the critical level of pollution.
  +
  +
===When catastrophe strikes===
  +
  +
Each turn, dice are rolled for each kind of catastrophe to determine whether it occurs, based on "accum" as described above.
  +
  +
If it does occur, then the magnitude of the catastrophe ''also'' depends on "accum", as well as the map's dimensions -- approximately, the number of tiles changed to another type of terrain increases with "accum". So there's a double effect: a higher risk of catastrophe, in addition to being more likely to occur each turn (by definition), will also lead to more severe effects when it does occur.
  +
  +
After a given catastrophe has actually occurred:
  +
*The appropriate "level" is ''increased'', so that it takes ''more'' pollution for that kind of catastrophe to occur again, and recovery will happen quicker once pollution is cleaned. "level" is increased by<math>\left \lceil \frac{1}{1000} \times map\_num\_tiles() \right \rceil</math>; for the first catastrophe, this increases the critical level by 1.5×.
  +
*The appropriate "accum" is zeroed, so that the risk of further catastrophe is reduced to zero. (Of course, if the pollution remains above even the new "level", then the risk will start to increase again.)
  +
  +
A rough estimation of how many turns it at average takes to climate change from zero accum with a constant pollution rate <math>r</math> is <math>\sqrt\frac{100\%}{r}</math>.
  +
  +
==Unit upgrades==
  +
upgrade cost = (2*C + [C*C/20]) * (100+E)/100,
  +
  +
where C = shield_cost_of_new - [shield_cost_of_old/2], E is the "Upgrade_Price_Pct" effect value.
  +
  +
That means, a unit upgrade basically costs as much as buying the new unit in a city where the old unit was previously recycled into an empty production stock.
  +
  +
==Pollution==
  +
A city's '''''pollution score''''' represents the percentage chance, each turn, that it will generate [[Cities#Pollution|Pollution]] on one of the tiles within the city's radius.
  +
  +
The '''''pollution score''''' is calculated from the sum of two different types of pollution: '''''production pollution''''' and '''''population pollution'''''.
  +
  +
The sum is then reduced by subtracting a third component called '''''base_pollution'''.''
  +
  +
===Pollution Score Formula===
  +
<math>Pollution Score = ProdPollu + PopPollu - BasePollu</math>
  +
  +
The result is ''rounded down'' to the nearest whole number. The component elements of this formula are given below.
  +
  +
===Pollution Score Elements:===
  +
  +
#'''''ProdPollu''''' is the influence that shield production has on the pollution of the city:
  +
#*<math>ProdPollu = Shields \times (100+PrEFT)%</math>
  +
#**where '''''PrEFT''''' is the <code>Pollu_Prod_Pct</code> effect which gives an active bonus or penalty in the ruleset.
  +
#***for example, in <code>Classic</code> rules, having a <code>Recycling Center</code> sets '''''PrEFT''''' to -66%, ''thus:'' <math>ProdPollu = Shields \times 34%</math>.
  +
#'''''PopPollu''''' is the influence that a city's population ''(size)'' has on the pollution of the city:
  +
#*<math>PopPollu = CitySize \times (100+PopEFT)%</math>
  +
#**where '''''PopEFT''''' is product of <code>Pollu_Pop_Pct</code> bonuses and <code>Pollu_Pop_Pct_2</code> penalties:
  +
#***<code><math>PopEFT = (100+Pollu\_Pop\_Pct)% \times (100+Pollu\_Pop\_Pct\_2)%</math></code>
  +
#***Typically, '''''PopEFT''''' starts at -100 to create 100-100=0% population pollution. Then the game introduces certain penalties as the nation industrializes.
  +
#'''''BasePollu''''' can be thought of as how much of your pollution is "free" — that is, you only generate pollution after you exceed this level.
  +
#*''BasePollu is'' defined by the variable <code>base_pollution</code> in the file <code>game.ruleset</code>.
  +
  +
{| class="fandom-table"
  +
!Ruleset:
  +
!'''Classic'''
  +
!'''Civ2Civ3'''
  +
!'''Multiplayer'''
  +
!'''MP2'''
  +
!'''Civ2'''
  +
!'''Civ1'''
  +
|-
  +
|BasePollu'':''
  +
| -20
  +
| -20
  +
| -20
  +
| -20
  +
| -20
  +
| -20
  +
|}
  +
  +
===Pollution Score Example===
  +
Below is an example of how to compute pollution. In this example, a nation with Industrialization tech has a size 19 city that produces 22 shields per turn.
  +
*city has 22 shields of production
  +
**the city has no Recycling Center, Hydro Plant, or other building that gives a '''''PrEFT''''' bonus to reduce '''''production pollution'''''
  +
*city size is 19
  +
**nation possesses the technology [[Technology#Industrialization|Industrialization]].
  +
**The ruleset specifies that having Industrialization increases population pollution by 25%
  +
*The ruleset uses the conventional standard of: '''''BasePollu''''' = -20
  +
  +
<math>Pollution Score</math>
  +
  +
<math>= ProdPollu + PopPollu - BasePollu</math>
  +
  +
<math>= Shields \times (100+PrEFT)% + CitySize \times (100+PopEFT)% - BasePollu</math>
  +
  +
<math>= 22 \times (100+0)% + 19 \times [100+(-100+25)]% - 20
  +
</math>
  +
  +
<math>= 22 \times 100% + 19 \times (100-75)% - 20
  +
</math>
  +
  +
<math>= 22 + (19 \times 25%) - 20
  +
</math>
  +
  +
<math>= 22 + 4.75 - 20
  +
</math>
  +
  +
<math>= 26.75 - 20
  +
</math>
  +
  +
<math>= 6.75
  +
</math>
  +
  +
<math>= 6
  +
</math>(rounded down)
  +
  +
In this example city, there is a '''6%''' chance each turn, that it will generate pollution on a random tile inside its radius.<br />
  +
[[Category:Technical docs]]

Latest revision as of 17:56, 11 April 2024

This page is a project to collect formulas that are used by Freeciv and present them in a form suitable for mathematicians.

Score of a player[]

Shown in F3 tab, is equal to the sum of

  • Number of citizens (the sum of city sizes)
  • Number of known techs * 2
  • Number of known future techs * 5
  • Number of wonders * 5 (the big ones)
  • Spaceship score (100 points for every 10.000 citizens on the spaceship multiplied by success rate)
  • Number of units built / 10
  • Number of units killed / 3
  • Number of culture points / 50

Demographics[]

Population  The sum of the population in each of your cities. Note that it's not proportional to the total number of your citizens, bigger cities contribute quadratically more.
Land Area The sum of every tile of your territory (including Ocean) on the map multiplied by 1,000 in "square miles". If the borders are disabled, it's the "settled area" increased on land tiles with units of this player at stack top[demo 1] out of any of the player's city's working radius
Settled Area The sum of every land tile on the map that is being currently worked by a city including the "city tile", plus any other land tiles with the player's units at stack top[demo 1] within the city radii, multiplied by 1,000 in "square miles"
Research Speed The total amount of "bulbs" being produced by you per turn
Literacy The percentage of your civilization's population that live inside a city that is close, beyond or at a 100% output bonus in science. I.e., a city with 100% bonus or any more contributes total its population (without the "thousands" multiplier) to a counter, for bonuses from 1% to 99% the value will be proportionally smaller, and finally the counter is divided on total population. Under the default ruleset for example, a library provides a +100% bonus to science; if every city had one - your civilization would have 100% literacy.
Production The sum of the surplus production after being spent on unit upkeep and waste in each of your cities in "M tons"
Economics The sum of the surplus trade after losses to corruption in each of your cities in "M goods"
Military Service --- in months

Pollution

The sum of the total pollution being produced by each of your cities in "tons"
  1. 1.0 1.1 Stack top of a tile is usually a unit on it that came there last, but it's not guaranteed.

Tile output[]

Tiles produce six types of output: food, shields (for production), trade, and also gold, science and luxury. To calculate the output of a tile (note: extra kinds are identified by their causes, being "Road", "Mine" or "Irrigate"; all percentages are rounded down):

Operation Ruleset variable
Start with the base output for the terrain type. terrain.ruleset: terrain_*.* (second * for food, shield, trade)
Add output from the special resource, if the tile has any. terrain.ruleset: resource_*.*
Add the point bonuses from terrain improvements:
•Add bonus to food, if the tile has some irrigation (or is the center of a city having auto-bonus for irrigation). effects.ruleset: "Irrigation_Pct"
• Add bonus to shields, if the tile has a mine. (desert, glacier, hills or mountains) effects.ruleset: "Mining_Pct"
• Add variable bonuses from roads scaled to terrain percentage (e.g. road bonus to trade, if the tile has a road and is grassland, plains or desert) terrain.ruleset: road_*.*_incr, terrain_*.road_*_incr_pct
• Add constant bonuses from roads (e.g. trade, if the tile has a river). terrain.ruleset: road_*.*_incr_const
• Increase the result on percentage equal to the sum of road bonuses [50% to shields from railroad] terrain.ruuleset: road_*.*_bonus
Add unconditional bonus from effect [as from Harbor or Offshore Platform]. effects.ruleset: "Output_Add_Tile"
If the production is above zero, add the conditional bonus [like the +1 trade bonus for Republic or Democracy]; if the city also celebrates, add also another one [like the +1 trade bonus for Monarchy or Communism] effects.ruleset: "Output_Inc_Tile", "Output_Inc_Tile_Celebrate"
Add percentage bonus from effect [as from Superhighways or Supermarket]. effects.ruleset: "Output_Per_Tile"
If the city does not celebrate, subtract 1 point if the output exceeds the penalty limit [like the penalty for exceeding 2 points during Anarchy or Despotism]. effects.ruleset: "Output_Penalty_Tile"
Subtract penalty percentage [in default ruleset, 50% if the tile has pollution, 50% for nuclear fallout and 75% for both] effects.ruleset: "Output_Tile_Punish_Pct"
Apply minimum values [1/1/0 in default ruleset], if the tile is the center of a city. game.ruleset: min_city_center_*

See get_worked_tile_output() and city_tile_output() in common/city.c.

Note that "celebrating" city for tiles' output means "a city that was in celebrating mood the previous turn and has enough citizens for celebration".

Note also that tile outputs of science, luxury and gold are not displayed on the map in standard clients, and other outputs with tile values over 9 will be displayed as 9.

City output (food/production/trade)[]

Cities produce six types of output: food, shields (for production), trade, gold, luxury and science. To calculate the output of any single city:

Operation Ruleset factors and game settings
Start with the base citizen output from all citizens who are working tiles, or who are specialists. See above and effects.ruleset: "Specialist_Output"
If the city has any trade routes, then add the bonus from these routes to trade. [ Longturn servers only: setting "trade_revenue_style"]
game.ruleset: trade.settings.{type, pct, cancelling}
effects.ruleset: "Traderoute_Pct"
If the city pays tithes (like from Fundamentalism in civ2 ruleset), then add the tithes to gold. effects.ruleset: "Happiness_To_Gold"
Calculate production with bonuses for each output type:
prod = floor(prod_0 * floor((100 + bonus) * (100 + bonus2) / 100) / 100)
effects.ruleset: "Output_Bonus", "Output_Bonus_2"
Since v.3.2: add absolute city bonus and make the result at least 0 for each output type. effects.ruleset: "Output_Bonus_Absolute"
At this moment of calculations, shields value affects city pollution (see below).
Calculate waste/corruption for each output. For trade, it is full prod if the city has not overgrown no-trade size, or proportional (rounded down) part of prod if the citysize is between no-trade size and full trade size, for the remnant normal waste is applied additionally. If your nation happens to have no governmental center (happens to barbarians in standard rulesets), then all production is wasted; otherwise,
basic_waste = floor(prod * (basic_waste + min_govcenter_dist * dist_waste) / 100),
waste = basic_waste - floor(basic_waste * waste_pct / 100)

(clipped into the range from 0 to prod)

game settings: "notradesize", "fulltradesize"
effects.ruleset: "Gov_Center", "Output_Waste", "Output_Waste_By_Distance", "Output_Waste_Pct"
Calculate the amount of all city-based upkeeps for units and buildings, usage of food by citizens game.ruleset: civstyle.food_cost, civstyle.gold_upkeep_style
units.ruleset: unit_*.uk_*, flag = "Fanatic"
buildings.ruleset: building_*.upkeep
effects.ruleset: "Upkeep_Free", "Upkeep_Factor", "Unit_Upkeep_Free_Per_City", "Fanatics"
Apply tax rates to trade (without corruption and upkeep, if any). Add results to gold, luxury and science values (before bonus multiplication). cities.ruleset: parameters.(changable_tax, forced_science, forced_gold, forced_luxury)
Apply city bonus effects to outputs after taxes added. Surpluses are calculated here by subtracting usage from the production (they may be negative before the city/nation is ballanced during turn change) (see above)
Calculate citizens' moods. Note that (v.2.6.3 regarded) luxury usage by units, if any, has no effect here. See Happiness
If the city is in disorder, calculate unhappy penalty: for gold and science, it is full city production; for food and shield, it is all what remains after usage on upkeeps (minimum 0); not applied to trade and luxury. not configurable yet

Thus, note that "Output_Waste" effect on science is applied only to the science collected by scientists or workers (they produce a unit of science with Copernicus Observatory in some rulesets), and to reduce the effectivity of taxing science from trade as well you should introduce negative "Output_Bonus". References:

  • enum output_type_id in common/fc_types.h
  • output_type_iterate() in common/city.h
  • city_refresh_from_main_map(), set_city_production() in common/city.c

Food box[]

The amount of food needed to fill the food box is a function of the game.ruleset values granary_food_ini and granary_food_inc. The server option foodbox adjusts the amount.

  • Recursive formula:
  • Where:
    • city_size is the current size of the city.
    • num_inis is the number of values in granary_food_ini (which is a list).

When a city changes its size with a Granary in effect, the preserved amount of food is calculated from the final city size but with the percentage related to the initial city size (i.e., if we have auto-granary 50% before size 3, city size 3 completes its 30 food stock and becomes a size 4 city with 40 food stock, it has 20 food inside, but if it starves back to 3, it will have 0). When a migration happens, the source city invariantly loses half of its foodbox that is eaten by the migrant on the way.

References:

  • load_ruleset_game in server/ruleset.c
  • city_granary_size in common/city.c

Production hurry cost[]

Gold needed to finish production ( - shields left to produce):

  • For units:
  • For buildings:
  • For wonders:

Multiply these values by 2 if there is no shield in the city stock ( - cost in shields):

  • For units:
  • For buildings:
  • For wonders:

The basic cost of upgrading units is the unit's buy cost had the unit been disbanded (contributing half of its shields) into an empty production stock and then new one bought; this cost may be modified on a percentage of "Upgrade_Price_Pct" effect (player-ranged, should be negative to get a discount).

References:

  • impr_buy_gold_cost in common/improvement.c
  • utype_buy_gold_cost in common/unittype.c

Corruption / Waste[]

Corruption and Waste refer to the same thing: a penalty on city output based on two effects in effects.ruleset: Output_Waste and Output_Waste_By_Distance. (Some people use the word "corruption" to refer to trade waste, and may use the term "waste" to refer to either production waste or any kind of waste in general.)

In most rulesets, the starting base for Output_Waste and Output_Waste_By_Distance are determined by the form of government. However, a ruleset could hypothetically set other triggers for these effects.

  • Output_Waste is a base level of waste for a particular output type. For example:
[effect_corruption_monarchy]
type    = "Output_Waste"
value	= 20
reqs	=
    { "type", "name", "range"
      "Gov", "Monarchy", "Player"
      "OutputType", "Trade", "Local"
    }

This sets the base level of waste on trade to 20% for nations who are Monarchy. This base level would apply to all cities across the empire.

  • Output_Waste_By_Distance adds to the above an additional percentage of waste, based on "real distance" to the nearest Government Center (typically, the city with Palace.) "Real Distance" is not Pythagorean distance, but rather, the "distance as a crow flies if it used cursor keys", or the shortest number of moves to get from A to B if one is able to move unrestricted. On a Cartesian (square tile) map, "Real distance" is always the greater of δx,δy. For example, a city with distance δx=5 and δy=7 will have a "Real Distance" of 7. Example of Output_Waste_By_Distance:
[effect_corruption_monarchy_distance_from_capital]
type    = "Output_Waste_By_Distance"
value	= 200
reqs	=
    { "type", "name", "range"
      "Gov", "Monarchy", "Player"
      "OutputType", "Trade", "Local"
    }

This adds 200% of the "real distance" to the Output_Waste. Let's revisit our example of a city in Monarchy whose distance from the capital is δx=5 and δy=7. It has Output_Waste of 20%. Its real distance is 7. Its Output_Waste_By_Distance is 200. Therefore this city would suffer 20%+(2 * 7) = 34% trade waste. If it has raw trade of 11, its corruption would be trunc(0.34 * 11) = trunc(3.74) = 3. Note in this example, the truncation rounding results in a real corruption of 3 or only 27% corruption.

  • Other Factors: all mainstream rulesets have things which can alter the above. Specifically, there are other triggers in effects.ruleset to reduce or increase the waste determined by Output_Waste and Output_Waste_By_Distance. Typically, these are buildings like Palace, Courthouse, or possibly certain Wonders. For example:
[effect_courthouse]
type    = "Output_Waste_Pct"
value	= 50
reqs	=
    { "type", "name", "range"
      "Building", "Courthouse", "City"
      "OutputType", "Trade", "Local"
    }

In this example from a typical ruleset, a Courthouse reduces the final trade waste by 50%. Note that in our above example, this is not 50% * 34% = 17%. But rather, 50% of trunc(0.34*11) will be removed post facto. Thus, if a city had 11 trade, trunc(34%*11) would yield corruption of 3. 50% of 3 is 1.5 which truncates down to 1, yielding total corruption of (34%*11) - trunc(50%*3) = 3-1 = 2. Thus, while the 34% corruption the city was actually supposed to suffer was only 27%, the 50% corruption reduction the Courthouse was supposed to offer was only 33%. In a way this balances out, though one should be aware that any ruleset with a Courthouse like the example above, would get nowhere near 50% corruption reduction for cities with typical corruption:

Corruption -50% rounded real value
1 0.5 0 -0%
2 1 1 -50%
3 1.5 1 -33%
4 2 2 -50%
5 2.5 2 -40%
6 3 3 -50%
7 3.5 3 -43%
8 4 4 -50%
9 4.5 4 -44%
  • In a frequency distribution for a typical Monarchy in the middle of its Monarchy period, 12 non-capital cities had corruption of: 1, 1, 1, 2, 2, 3, 3, 3, 4, 5, 6, 7. Yielding total corruption of 38. One would suppose Courthouses would result in corruption of 38-19=19. But in fact, it results in 38-15=23, for an actual 39% reduction: a number closer to 1/3 than it is to 1/2. While it can be argued that the discounted corruption from step one is balanced by this penalized reduction, the real effect is a strong discouragement on the use of corruption reducing mechanics in empires experiencing single digit corruption values. (Higher values converge closer toward 50%). While it has been proposed that some effects should use alternative rounding such as Bankers' Rounding to solve this, other rulesets such as MP2 have improved this mechanic in simple heuristic ways. In any case, players and ruleset designers should all be aware of it, as it has a major impact on game equilibrium.

Hint: If "Output_Waste_By_Distance" is 300 or more for a given government, the autogenerated help for it says that the losses will increase quickly with distance from capital; if its value is from 1 to 199, it says that they will increase slowly. The effect "Output_Waste_By_Rel_Distance" is commented the same way (just from (effect+39)/40 value) since the help text does not know actual world scaling (the effect is actually similar to "Output_Waste_By_Distance" when the world bigger dimension is 50).

  • TO DO: this subsection is incomplete and could benefit by a more accurate redaction of the server code in city.c into a mathematical formula. The above is an incomplete oversimplified draft as a courtesy for players who have experienced FAQs and also "frequently experienced frustrations" regarding the unintuitive and hitherto undocumented ways that waste works in Freeciv.

Trade routes[]

Freeciv 2.1 uses the following formulas:

Trade route revenue generated every turn in cities: (

= trade production in the city 1,

= trade production in the city 2. These values do not include the extra trade revenues from other trade routes )

  • With yourself, on the same continent:
  • With another player, on the same continent:
  • With yourself, on another continent:
  • With another player, on another continent:
  • With experimental trade route revenues (on Warserver):

Freeciv 2.2 uses the following formulas:

Trade route revenue generated every turn in cities: ( D = real distance between city 1 and city 2, all directions counting as 1, S1 = size of city 1, S2 = size of city 2 )

  • With yourself, on the same continent: ( D + S1 + S2 ) / 12
  • With another player, on the same continent: ( D + S1 + S2 ) / 6
  • With yourself, on another continent: ( D + S1 + S2 ) / 6
  • With another player, on another continent: ( D + S1 + S2 ) / 3

Caravan bonus, the gold and science you get when establishing a new trade route: ( = trade production (including trade routes revenues) in the city 1, = trade production in the city 2, = real distance between the cities):

The possession of the technologies Railroad and Flight each reduces the bonus by . Then:

  • You have one of this technologies:
  • You have two of this technologies:
  • With experimental caravan bonus style (on Warserver):, where is real map distance, and are maximal possible trade values that the cities can get reassigning their citizens on their tiles (plus trade from existing routes without goods factors, without theoretically possible city trade specialists output).

Bonus from a caravan, when it enter in a existent trade place, you get only of the bonus: ( - trade production in the city 1, - trade production in the city 2, - real distance between the cities):

The possession of the technologies Railroad and Flight each reduces the bonus by . Then:

  • You have one of this technologies:
  • You have two of this technologies:
  • With experimental caravan bonus style (on Warserver): , with the same notation as for trade revenue (the final coefficiency is where is "Trade_Revenue_Bonus" effect, it's if ).

These formulas are the base of the calculation. Different governments output different amounts of trade in each city. Republic and Democracy get a +1 trade bonus in tiles that are generating trade, so usually, you will make a lot more profit under these governments. Monarchy and Communism get the +1 trade bonus only if they are celebrating.


The following formulas are used under the server setting trade_revenue_style = "SIMPLE"

This formula is used in MP2 rulesets, but is also user configurable in any game via the above server setting.

Trade route revenue generated every turn in cities:

= trade production in City1,

= trade production in City2. (These values do not include the extra trade revenues from other trade routes.)

  • Base trade formula:

NOTE: some rulesets may have other adjustments for the following external conditions:

  • Bonus/penalty for possessing certain technologies, wonders, diplomatic states.
    • In MP2:
      • Railroad and Flight reduce the bonus.
      • Diplomatic state of war cancels the bonus.
  • Trading with yourself or with another player
  • Cities are on same or different continents

See:

  • Trade_Revenue_Bonus effects in effects.ruleset


TODO: the above only specifies the base trade between cities. This is a component of a larger formula which remains to be specified here.


Taxation of trade[]

For each city, multiply the trade output (after subtracting corruption) by the tax rates to yield the gold/luxury/science output taxed from trade. (See add_tax_income() in common/city.c.) The problem is how round the result to exact integers, without increasing or decreasing the trade output (which must exactly equal the sum of the three tax outputs).

From distribute() in utility/distribute.c:

  /* 
   * Distribution of a number of items into a number of groups with a given
   * ratio.  This follows a modified Hare/Niemeyer algorithm (also known
   * as "Hamilton's Method"):
   *
   * 1) distribute the whole-numbered part of the targets
   * 2) sort the remaining fractions (called rest[])
   * 3) divide the remaining source among the targets starting with the
   *    biggest fraction. (If two targets have the same fraction the
   *    target with the smaller whole-numbered value is chosen.  If two
   *    values are still equal it is the _first_ group which will be given
   *    the item.)
   */

The order of the three groups in Freeciv is science, gold, luxury.

In Wikipedia, this method is the Largest remainder method using the Hare quota. (Wikipedia discusses elections, so pretend that the trade points are senate seats, and that the tax rates are 100 votes for the Gold, Luxury, or Science party lists.)

In the government used during revolutions, everything is taxed to luxury despite of any settings.

Example 1[]

  • Trade surplus: +2
  • Tax rates: 60% science, 40% gold

Initial multiplication:

This gives 1 science and 0 gold, but uses only 1 of 2 trade points. Gold has the highest remainder (80 > 20), so Freeciv gives the other point to gold.

Final result:

  • 1 science, 50% of +2
  • 1 gold, 50% of +2

Example 2[]

  • Trade surplus: +17
  • Tax rates: 30% science, 30% gold, 40% luxury

Initial multiplication:

This uses 5 + 5 + 6 = 16 trade points. Luxury has the highest remainder (80 > 10) and receives the 17th point.

Final result:

  • 5 science, ≈29.4% of +17
  • 5 gold, ≈29.4% of +17
  • 7 luxury, ≈41.2% of +17

Example 3[]

  • Trade surplus: +18
  • Tax rates: 30% science, 30% gold, 40% luxury

Initial multiplication:

This uses 5 + 5 + 7 = 17 trade points. Science and gold tie for the highest remainder. To break the tie, Freeciv would give the 18th point to the group with fewer points, but both groups have 5 points. In this case, Freeciv always prefers science to gold, and gives the 18th point to science.

Final result:

  • 6 science, ≈33.3% of +18
  • 5 gold, ≈27.8% of +18
  • 7 luxury, ≈38.9% of +18

Example 4[]

  • Trade surplus: +24
  • Tax rates: 60% science, 10% gold, 30% luxury

Initial multiplication:

This uses 14 + 2 + 7 = 23 points. Science and gold again tie for the highest remainder, but now gold has fewer points. To break the tie, Freeciv gives the 24th point to gold.

Final result:

  • 14 science, ≈58.3% of +24
  • 3 gold, 12.5% of +24
  • 7 luxury, ≈29.2% of +24

Upkeep[]

Units homed to any city may require upkeep in shields, food or gold (in theory, in other outputs too, but this is a buggy matter), and, as a special case, "happiness upkeep" for agressive units (see Happiness). Buildings may require gold upkeep only. City population itself requires proportional food upkeep. Gold is paid city-based, nation-based or nation-based for units (as long as your nation vaults are big enough after previous cities' processing!) and city-based for buildings depending on upkeep style. You also may have bulbs upkeep for technologies but it is always nation based and will be discussed elsewhere.

  • Wonders never need upkeep. A city improvement doesn't pay upkeep if its upkeep value is not greater than its "Upkeep_Free" effect. Otherwise, it pays its ruleset-defined upkeep in gold.
  • Fanatic units don't pay any upkeep if the player has positive effect "Fanatics".
  • Ruleset unit upkeeps are multiplied on "Upkeep_Factor" effect value (this effect varies by types of upkeep but it is uniform for all units of a given player). Then, the upkeeps are subtracted from the units' home city free upkeep capacity as long as it is greater or equal the next upkeep value; if some value is going to exceed it, the remnant is subtracted from the unit's upkeep, and the rest of the units pay full upkeep. (This procedure has few difference from simple "city upkeep = max(sum(unit upkeeps) * upkeep_factor - free_upkeep, 0)" formula but it explains the upkeeps displayed in the city dialog.)
  • If there is not enough production/vaults for upkeep, some random buildings are sold, then some random units are disbanded with their upkeep (and in certain cases their cost) returned to the ballance, until the ballance goes above zero. (This procedure runs for national and/or city upkeep, depending on the ruleset.) In certain cases city size may be decreased at 1 (if the citizens can't get food from the granary or when an undisbandable unit can't get shields upkeep).

City health[]

Settings[]

The health of a city is defined by the possibility of an illness (plague). The following ruleset options are available in game.ruleset, section [civstyle]:

; Whether plagues (illness) are possible 
illness_on = 0 
; the base factor for illness (of percent) 
illness_base_factor = 25 
; minimum city size for illness 
illness_min_size = 3 
; factor for how much trading with a plagued city increases our city's 
; chance for plague (in percent) 
illness_trade_infection = 50 
; factor for how much pollution within a city increases its chance for 
; plague (in percent) 
illness_pollution_factor = 50

Equations[]

The possibility of an illness is given by a base value, defined in the game.ruleset file (illness_base_factor: maximum propability for illness in percent). Illness due to trade infection and illness due to pollution are added to this value. The illness values calculated below are given in tenths of percent.

The base illness value depends on the city size reduced by the minimum size for illness (illness_min_size) and is given by

This function starts at 0 for

and goes asymptotic to its maximum value (illness_base_factor).

If a trade city had an illness within the last 5 turns the illness value is increased by

Pollution also increases the illness value:

Remember: The illness value is the illness in tenth of percent, i.e. a value of 56 means 5.6% propability for an illness within the city.

Example[]

City health example

City health example (using this m-file)

Taking into account a city size of 1 to 50, a pollution level which equals six times the city size (pollution = 6 * size) and four trade cities of size 10 the illness possibility of the city is given in the following table (in percent).

# (illness) aqueduct aqueduct + sewer system
base +trade +pollution base +trade +pollution base +trade +pollution
5 9.800 11.200 12.700 4.900 5.600 6.350 1.960 2.240 2.540
10 15.800 17.800 20.800 7.900 8.900 10.400 3.160 3.560 4.160
15 19.400 21.800 26.300 9.700 10.900 13.150 3.880 4.360 5.260
20 21.600 24.400 30.400 10.800 12.200 15.200 4.320 4.880 6.080
25 22.900 26.100 33.600 11.450 13.050 16.800 4.580 5.220 6.720
30 23.800 27.300 36.300 11.900 13.650 18.150 4.760 5.460 7.260
35 24.200 27.900 38.400 12.100 13.950 19.200 4.840 5.580 7.680
40 24.500 28.500 40.500 12.250 14.250 20.250 4.900 5.700 8.100
45 24.700 28.900 42.400 12.350 14.450 21.200 4.940 5.780 8.480
50 24.800 29.300 44.300 12.400 14.650 22.150 4.960 5.860 8.860

Health effect[]

Furthermore for the aqueduct and the sewer system a health effect is defined.

[effect_aqueduct_health] 
name	= "Health_Pct"
value	= 50 
reqs	= 
    { "type", "name", "range" 
      "Building", "Aqueduct", "City" 
    }
[effect_sewer_system_health] 
name	= "Health_Pct"
value	= 30 
reqs	= 
    { "type", "name", "range" 
      "Building", "Aqueduct", "City" 
      "Building", "Sewer System", "City" 
    }

The possibility of an illness is reduced by <value> percent defined by the effect Health_Pct (i.e aqueduct + sewer system = Health effect of 80; an base illness possibility of 10% is reduced by 80% to 2%).

Migration[]

Settings[]

Migration between cities is controlled by the following game settings. They can be changed by using the set server command. help <setting> will give you more information.

  • migration - Whether to enable citizen migration (default: 0 = off)
  • mgr_turninterval - Number of turns between migrations from a city (default: 5; min:1; max: 100)
  • mgr_foodneeded - Whether migration is limited by food (default: 1 = on)
  • mgr_distance - Maximum distance citizens may migrate (default: 3; min: 1; max: 7)
  • mgr_nationchance - Percent probability for migration within the same nation (default: 50; min: 0; max: 100)
  • mgr_worldchance- Percent probability for migration between foreign cities (default: 10; min:0; max: 100)

Equations[]

Helper function to calculate a "score" of a city. The score is used to get an estimate of the "migration desirability" of the city. The higher the score the more likely citizens will migrate to it.

The score depends on the city size, the feeling of its citizens, the cost of all buildings in the city, and the surplus of trade, luxury and science.

  • base formula:
  • feeling of the citizens:
  • factors
    • if the city has at least one wonder a factor of 1.25 is added
    • for the capital an additional factor of 1.25 is used
    • an additional factor is given by the effect 'Migration_Pct':
    • the build costs of all buildings:
    • the trade of the city:
    • the luxury within the city:
    • the science within the city:
    • the food available in the city:

The first four factors f have values between 1 and 1.2 while the factor for food is limited between 0.9 (10 food) and 1.2 (+20 food). The overall factor will be between 1.0 (smaller cities) and 2.0 (bigger cities)

[build shield cost], [city surplus trade], [city surplus luxury] and [city surplus science] must be >= 0! [city surplus food] can be below zero.

The score of the source city is multiplied by 3 to take into account the persistence of the citizens.

The score of the target city is weighted by the distance between both cities. The weight factor is calculated as

Example[]

For the following three city the migration score is calculated:

city characteristics
city 1 city 2 city 3
city size 17 5 3
citizens (happy/content/unhappy/angry) 7/9/1/0 1/4/0/0 0/3/0/0
city has a wonder yes yes no
city is capital yes no no
effect Migration_Pct 30 0 0
build shild cost 2500 1000 250
city surplus (trade/luxury/science) 62/16/15 10/2/5 6/0/6
distance
city 1 - 3 5
city 2 3 - 3
city 3 5 3 -
calculated values
city 1 city 2 city 3
city size 17.000 5.000 3.000
feeling 6.750 1.000 0.000
factor: wonder 1.250 1.250 1.000
factor: capital 1.250 1.000 1.000
factor: effect Migration_Pct 1.300 1.000 1.000
factor: build shield cost 1.184 1.126 1.044
factor: surplus trade 1.092 1.019 1.012
factor: surplus luxery 1.030 1.004 1.000
factor: surplus science 1.028 1.010 1.012
basic city score 66.044 8.726 3.208
weight: distance city 1 - 0.625 0.375
weight: distance city 2 0.625 - 0.625
weight: distance city 3 0.375 0.625 -
migration checks
source city / target city city 1 (source) city 2 (source) city 3 (source)
city 1 (target) - 26.179 / 41.2773 9.623 / 24.7664
city 2 (target) 198.131 / 5.4539 - 9.623 / 5.4539
city 3 (target) 198.131 / 2.0048 26.179 / 3.2076 -

Migration will take place from city 2 to city 1 and from city 3 to city 1 with the possibility given in the corresponding game settings (mgr_nationchance and mgr_worldchance).

Migration Effect[]

TODO: exact description of the effect; increase / decrease the possibility of migration (i.e for different governments)

Science[]

Technology cost formula depends on several game settings: techcoststyle, researchcost, techcostdoubleyear, techleackage, techleackagerate. There might be differences between calculated values and real-game ones due to rounding to integers in several places.

  • Future techs: calculated like common techs with techcoststyle=0.
  • Common techs:
    • If techcoststyle=2, ruleset might set its own values, not calculated by Freeciv. For the techs not overrided by the ruleset, cost is calculated like if techcoststyle=1.
    • If techcoststyle=1 (the default case),, but not less than researchcost. is number of all (including already researched) technologies required by given tech.
    • If techcoststyle=0, to discover nth technology you need (like in Civilization I/II games).

Additional rules.

  • If techcostdoubleyear parameter is not zero, cost doubles starting from this year.
  • If techleakage parameter is not zero, you get bonus when other players already have developed the tech. The formula is:, where is total number of players and is:
    • number of players that know the technology and you have embassy, when techleakage=1,
    • number of players that know the technology, when techleakage=2,
    • number of players that know the technology, excluding barbarian players, when techleakage=3 (in this case total number of players is calculated without barbarians too).
Note: is a Warserver setting. On standard server,.
  • For AI players there might be a penalty/bonus depending on AI skill.
  • If the calculated cost is zero, the real cost is 1 bulb.

Getting tech without research[]

You can get techs, when you conquer a city, use a diplomat, from Great Library, by completing traderoutes, or by Darwin's Voyage wonder or discovery of Philosophy. The chances and costs of this is decided by server settings conquercost, diplochance, freecost, by disallowing traderoutes before the start of each game, etc.

Research[]

You can research either by science out put from your trade income, or by using Specialists when your cities are at size 5 or above.

Specialists Default output With library With university
1 scientists 3 bulbs 6 bulbs 10 bulbs
2 scientists 6 bulbs 12 bulbs 21 bulbs

Probability of winning a fight[]

Main page: /Battle outcome

The chances of winning a fight are sometimes counter-intuitive. E.g., what would you say are your chances of winning in the following situation (after taking into account the land advantages and other modifiers): you have an attack of 2 against a defense of 3, and the same number of hit points? Considering that the probability of winning each round is 2/5, you might think that this will give you with a reasonable chance of victory, something like 40%. Lost. You only have 19% chances of winning. The fact that the battle lasts several rounds tends to give a larger advantage to the biggest power than one could think beforehand.

Supposing the reader is aware of the rules of the fight (for each round, take a random number, decide who wins that round, etc.), let's try to find a formula representing the chances of victory.

Notations and basic computations[]

Consider a unit having a strength (all modifications, field, city, unit experience of combat, etc. being applied)

and an enemy unit having a defense

. The number of hit points of the defending unit is written

, the damages per victorious rounds from the attacking unit is

. Let us note

the number of victorious rounds required to win the fight. And

is the number of rounds that, if lost, implies a defeat (

is for "losing allowance"). When the attacking unit cause one damage per victorious rounds (

),

is the number of hit points of the defending unit (

). More generally,

.

may be computed similarily. The chance of winning each round, let us note it

, is

. (Thus the chance of losing a round is

.)

Reasoning[]

Now let us suppose that the fight takes

rounds to achieve, and let us compute the probability of victory. Note that we do not know

in advance but we suppose for now that it is given. For a given

, the probability of victory is the probability that

rounds have been won over these

tries and less than

rounds have been lost. If

, then the probability of victory is simply the probability that

rounds have been won over these

tries (as this implies that less than

rounds have been lost). In case of victory, the last round must be the final hit (otherwise the fight would have been stopped earlier). Apart from that, there must be

hits among the

other rounds. That probability is given by a binomial

and is

. As the last round must be won, we multiply by

and get a probability of victory with

rounds of

. For the attacking unit to win the fight, we must have

. Thus finally the probability of winning equals:

.

Alternative reasoning[]

The freeciv source code uses a slightly different reasoning (look at ./common/combat.c:unit_win_chance() and ./common/combat.c:win_chance()). Let us note

the number of rounds lost, which must be smaller than

for a victorious attack. Then we have the following probability of victory.

. We get the initial formula by using

and

. In the code,

is def_N_lose,

is att_N_lose,

is def_P_lose1,

is att_P_lose1,

is lr.

Unit bribe cost[]

bribe_cost = (1 + UHP) * (base/2)

where

UHP = unit health percent = (current hit points / full hit points)

base = TG + GIbbc * (UCS/10) * (1 + EFTubc_pct/100) * (VPF/100) * (VMR/SMR) / (δGC+2)

TG = treasury gold for player of bribed unit

GIbbc = game.info.base_bribe_cost (set in game.ruleset, often set as 750)

δGC = Manhattan Distance to nearest government center or capital

UCS = unit shield cost

EFTubc_pct = EFT_UNIT_BRIBE_COST_PCT, any percentage bonus vs. bribing that are active in the ruleset

VPF = Veteran Power Factor. (e.g., veteran level 1 is often VPF=150 in many rulesets.)

VMR = Veteran move rate

SMR = Standard move rate

City incite cost[]

Gold needed to incite a city is calculated by this formula (most operations are in real numbers):

where

is owner's current treasury
BIC is incite_cost.base_incite_cost from game.ruleset
IUF, IIF are factors of shield costs of units and buildings inside: incite_cost.unit_factor and improvement_factor
is city happiness factor: 1 for disorder, 2 for content, 4 for celebrating
If citizens don't have nationalities in the game, OF is 1/2 for buying back a city that you have founded and 2/3 for buying third-party conquered city. If they have, NF is calculated from citizens' nationalities as.
is the number of corresponding citizens: NO = current owner N3 = third nationality NI = indigenous (original native owner)
ITF is incite_cost.total_factor
OCD is the Manhattan Distance to the owner's capital.
EIC is "Incite_Cost_Pct" effect values: add the sum of all actively triggered "Incite_Cost_Pct" effects for this city as described in the effects.ruleset file for the ruleset of the game being played.

Global Warming and Nuclear Winter[]

The two global catastrophes are driven by the same engine, update_environmental_upset() in srv_main.c, but are independent of each other.

There isn't very much configurable about this mechanism. The various magic numbers mentioned below are hardcoded. About all you can do in rulesets currently is to change how likely tiles are to get polluted in the first place (base_pollution). Since 3.0, two new server settings globalwarming_percent and nuclearwinter_percent are introduced to balance some games better.

Each turn, the chance of catastrophe is affected by the current count of polluted tiles (for GW) or tiles with fallout (for NW) on the world map. (Pollution in cities doesn't directly affect global warming, beyond being the means by which tiles become polluted.)

However, the chance is not purely a function of that number; it also depends on the past.

The chance of catastrophe "accum" is calculated each turn as follows:

where the variables are:

Variable Specific name Description
Global Warming Nuclear Winter
count - - Number of polluted tiles this turn
current game.info.heating game.info.cooling Number of polluted tiles this turn, in newer versions multiplied on the percentage.
Applied as a delta (hence name "heating"/"cooling").
(Only stored for display purposes, not carried from one turn to the next.)
percent game.server.global_warming_percent game.server.nuclear_winter_percent The server setting, goes from 1 to 10000, defaults to 100
level game.info.warminglevel game.info.coolinglevel A constant (but see below): critical level of pollution
(same units as "current")
accum game.info.globalwarming game.info.nuclearwinter The chance of catastrophe each turn is proportional to "accum".
Carried from one turn to the next.

Thus:

  • represents a critical number of polluted tiles at which the chance of catastrophe remains constant over time. Depending on the past, that chance could be zero or it could be a high level.
  • If current is below level, then the chance of catastrophe will decline and eventually become zero.
  • If current is above level, then the chance of catastrophe will increase.

Thus, the effect of polluted tiles is cumulative. If there's currently an elevated risk of catastrophe, even if you then clean up all existing polluted tiles in the world in a single turn with Engineers, the risk won't necessarily drop to zero next turn; it will gradually reduce over several turns until it hits zero.

For both kinds of catastrophe, level is initially based on the map size intiles:

. Since accum starts at zero, this effectively means that bigger worlds can take more punishment before there is any risk of catastrophe: 0.2% of a world's tiles must become polluted before the risk starts to increase at all, if percent is default. Nevertheless, Longturners have complained on too quick pollution. Changing the multiplier, one can make this number up to 100 times bigger or smaller. The actual chance of catastrophe is also affected by the map size in tiles: ignoring rounding,

Client display[]

The client lets you see quantities like the following:

Global warming chance: 6% (-1%/turn)
Nuclear winter chance: 0% (-2%/turn)
Shows the rate of global warming:
Pollution rate: -1%
Chance of catastrophic warming each turn: 6%

(Up to 2.1.11/2.2.0, due to a bug -- GNA#15563 -- the quantities displayed are only really percentages for the default map size of 4000 tiles. For bigger maps, the percentage displayed will be too big, and a displayed chance of 100% will correspond to a

of less than 1.0. This is fixed as of 2.2.1.)

The displayed "chance" is proportional to "accum". The "rate" is proportional to "current - level". They have the same units; in the first example, you can expect the displayed "Global warming chance" to drop to (approximately) 5% next turn (assuming the number of polluted tiles doesn't change wildly). Examples:

  • When "chance" is 0% and "rate" is negative, you're comfortably below the critical level of pollution and "chance" will remain zero.
  • When "rate" is 0%, you are around the critical level of pollution.

When catastrophe strikes[]

Each turn, dice are rolled for each kind of catastrophe to determine whether it occurs, based on "accum" as described above.

If it does occur, then the magnitude of the catastrophe also depends on "accum", as well as the map's dimensions -- approximately, the number of tiles changed to another type of terrain increases with "accum". So there's a double effect: a higher risk of catastrophe, in addition to being more likely to occur each turn (by definition), will also lead to more severe effects when it does occur.

After a given catastrophe has actually occurred:

  • The appropriate "level" is increased, so that it takes more pollution for that kind of catastrophe to occur again, and recovery will happen quicker once pollution is cleaned. "level" is increased by; for the first catastrophe, this increases the critical level by 1.5×.
  • The appropriate "accum" is zeroed, so that the risk of further catastrophe is reduced to zero. (Of course, if the pollution remains above even the new "level", then the risk will start to increase again.)

A rough estimation of how many turns it at average takes to climate change from zero accum with a constant pollution rate is .

Unit upgrades[]

upgrade cost = (2*C + [C*C/20]) * (100+E)/100,

where C = shield_cost_of_new - [shield_cost_of_old/2], E is the "Upgrade_Price_Pct" effect value.

That means, a unit upgrade basically costs as much as buying the new unit in a city where the old unit was previously recycled into an empty production stock.

Pollution[]

A city's pollution score represents the percentage chance, each turn, that it will generate Pollution on one of the tiles within the city's radius.

The pollution score is calculated from the sum of two different types of pollution: production pollution and population pollution.

The sum is then reduced by subtracting a third component called base_pollution.

Pollution Score Formula[]

The result is rounded down to the nearest whole number. The component elements of this formula are given below.

Pollution Score Elements:[]

  1. ProdPollu is the influence that shield production has on the pollution of the city:
      • where PrEFT is the Pollu_Prod_Pct effect which gives an active bonus or penalty in the ruleset.
        • for example, in Classic rules, having a Recycling Center sets PrEFT to -66%, thus: .
  2. PopPollu is the influence that a city's population (size) has on the pollution of the city:
      • where PopEFT is product of Pollu_Pop_Pct bonuses and Pollu_Pop_Pct_2 penalties:
        • Typically, PopEFT starts at -100 to create 100-100=0% population pollution. Then the game introduces certain penalties as the nation industrializes.
  3. BasePollu can be thought of as how much of your pollution is "free" — that is, you only generate pollution after you exceed this level.
    • BasePollu is defined by the variable base_pollution in the file game.ruleset.
Ruleset: Classic Civ2Civ3 Multiplayer MP2 Civ2 Civ1
BasePollu: -20 -20 -20 -20 -20 -20

Pollution Score Example[]

Below is an example of how to compute pollution. In this example, a nation with Industrialization tech has a size 19 city that produces 22 shields per turn.

  • city has 22 shields of production
    • the city has no Recycling Center, Hydro Plant, or other building that gives a PrEFT bonus to reduce production pollution
  • city size is 19
    • nation possesses the technology Industrialization.
    • The ruleset specifies that having Industrialization increases population pollution by 25%
  • The ruleset uses the conventional standard of: BasePollu = -20

(rounded down)

In this example city, there is a 6% chance each turn, that it will generate pollution on a random tile inside its radius.