Simulates one or more airstrikes and returns the average losses for both sides, the average infrastructure destroyed, and the probability of each victory type.
Each airstrike resolves as 3 rolls. Every roll each side generates a value
between 40% and 100% of its airforce value (Aircraft * 3); the side with the
higher value wins the roll. The number of rolls won determines the victory type:
3 wins → Immense Triumph, 2 → Moderate Victory, 1 → Pyrrhic Victory, 0 → Utter Failure.
Aircraft casualties accrue each roll from the opponent's roll value:
Targeted units killed (soldiers/tanks/ships) use the base formula: Killed = ROUND(MAX(MIN(Enemy Units, Enemy Units * capRate + capFlat, (Att Aircraft - Def Aircraft * 0.5) * coeff * RAND(0.85, 1.05)), 0)) scaled by the victory type: Immense Triumph 100%, Moderate 70%, Pyrrhic 40%, Utter Failure 0% (no targeted units are killed on a failure).
Infrastructure destroyed uses:
Infra = MAX(MIN((Att Aircraft - Def Aircraft * 0.5) * 0.35353535 * RAND(0.85, 1.05)
* (wins / 3), City Infrastructure * 0.5 + 100), 0)
(note the wins / 3 scaling differs from the unit-kill scaling), reduced to 1/3
for any airstrike that is not explicitly targeting infrastructure, then multiplied
by the war-type factor (see warTypeInfraMultiplier) and the combined
war-policy factor (see airstrikeInfraPolicyMultiplier).
The attacker's aircraft count
The defender's aircraft count
Number of airstrikes to simulate (results are averaged over these)
The airstrike target (see AirstrikeType)
The defender's soldiers (only used when targeting soldiers)
The defender's tanks (only used when targeting tanks)
The defender's ships (only used when targeting ships)
The targeted city's infrastructure (drives the infra-damage cap)
OptionalattackerWarPolicy: WarPolicy
The attacker's war policy (offensive infra modifier)
OptionaldefenderWarPolicy: WarPolicy
The defender's war policy (defensive infra modifier)
The war type (offensive infra modifier; defaults to Ordinary)
The averaged AirstrikeSimResult across all simulated airstrikes
Calculates the base population for a city based on its infrastructure value.
The infrastructure value of the city (must be non-negative)
The base population (100 per infrastructure point)
Calculates the building bonus multiplier for food production or other city stats.
The number of relevant buildings currently present in the city.
The maximum number of buildings possible for the city.
The building bonus multiplier (between 1 and 1.5).
Formula: bonus = 1 + (0.5 / (maxbuildings - 1)) * (currentbuildings - 1) This scales the bonus linearly from 1 (at 1 building) up to 1.5 (at max buildings).
Calculate the cost of a new city based on the new formula (effective late February 2025).
The city cost projects (MP, UP, AUP) were removed and replaced with a dynamic formula that considers the top 20% average city count.
The city number being purchased (e.g., if you have 10 cities, this is 11)
The average city count of the top 20% of active nations (updated monthly)
The cost in dollars for the next city
Calculates the commerce value for a city based on the number of various buildings and special infrastructure.
Building limits:
Special infrastructure:
Commerce calculation: (superMarkets * 15) + (banks * 20) + (shoppingMalls * 25) + (stadiums * 10) + (subway * 15)
Number of supermarkets (max 4)
Number of banks (max 6)
Number of shopping malls (max 5)
Number of stadiums (max 3)
Number of subways (max 1)
Whether the city has an International Trade Center (default: false)
Whether the city has a Telecommunications Satellite (default: false)
The calculated commerce value for the city
Check if a nation has a specific project built.
The Politics & War API stores project data as a bit field where each bit represents whether a project is built. Bits are indexed right-to-left using standard bit shift operations, where position 0 is the rightmost/least significant bit.
The project_bits string from the API (e.g., "1679868772347")
The bit position (0-40) using standard right-to-left indexing
true if the nation has the project, false otherwise
Calculates the number of crime-related deaths in a city.
The calculated crime rate
The infrastructure value of the city
The number of crime-related deaths
Calculates the crime percentage for a city using the following formula:
Crime (%) = ((103 - commerce)^2 + (infrastructure * 100)) / 111111 - policeModifier
The commerce value of the city
The infrastructure value of the city
The police modifier value
The calculated crime rate
Calculates the number of disease deaths in a city.
The calculated disease rate
The base population of the city
The number of disease deaths
Calculates the disease rate for a city using the following formula:
Disease Rate = ((((populationDensity^2) * 0.01) - 25) / 100) + (basePopulation / 100000) + pollutionModifier - hospitalModifier
The population density of the city
The base population of the city
The pollution modifier value
The hospital modifier value
The calculated disease rate
Estimates the success odds (%) of an espionage operation.
Initial Odds = (safetyLevel * 25) + ((yourSpies * 100) / ((enemySpies * 3) + 1)), then divided by the operation's SabotageType difficulty factor.
The attacker's espionage safety level (0-3)
The attacker's number of spies
The defender's number of spies
The espionage operation type (see SabotageType)
The estimated success odds
Calculates the espionage range for a nation — the span of nation scores it can run espionage operations against (40% to 250% of its own score).
The nation's score
The minimum and maximum targetable enemy score
Calculates the food production for a city based on farms, land, radiation index, irrigation, and season.
Number of farms in the city
Amount of land in the city
Radiation index modifier
Whether mass irrigation is enabled (default: false)
The current season ('spring', 'summer', 'fall', 'winter')
The calculated food production value
Simulates one or more ground battles and returns the average soldier and tank losses for both sides, the average infrastructure destroyed, and the probability of each victory type.
Each side's forces are converted to army values:
soldier value = soldiers * (using munitions ? 1.75 : 1)
tank value = tanks * 40
The defender additionally gains population / 400 resisting army strength on its
soldier value.
Each battle resolves as 3 rolls. Every roll, each side rolls its soldier value and its tank value independently between 40% and 100%; the attacker's total roll (AR = soldier + tank) is compared to the defender's (DR). The number of rolls the attacker wins (AR > DR) determines the victory type:
3 wins → Immense Triumph, 2 → Moderate Victory, 1 → Pyrrhic Victory, 0 → Utter Failure.
Casualties accrue each roll from the opponent's rolls: soldier losses = opponent soldier roll * 0.0084 + opponent tank roll * 0.0092 tank losses = opponent soldier roll * s + opponent tank roll * t, where the winning side uses (0.0004060606, 0.00066666666) and the losing side uses (0.00043225806, 0.00070967741).
Infrastructure destroyed uses: Infra = MAX(MIN(((Att Soldiers - Def Soldiers * 0.5) * 0.000606061 + (Att Tanks - Def Tanks * 0.5) * 0.01) * RAND(0.85, 1.05) * (wins / 3), City Infrastructure * 0.2 + 25), 0) multiplied by the war-type factor (see warTypeInfraMultiplier) and the combined war-policy factor (see infraPolicyMultiplier).
The attacker's soldier count (must be at least 50)
The attacker's tank count
The defender's soldier count
The defender's tank count
Number of ground battles to simulate (results are averaged over these)
Whether the attacker's soldiers fight with munitions (1.75x vs 1x value)
Whether the defender's soldiers fight with munitions (1.75x vs 1x value)
The defender's population (adds population / 400 resisting strength)
The targeted city's infrastructure (drives the infra-damage cap)
OptionalattackerWarPolicy: WarPolicy
The attacker's war policy (infra and loot modifier)
OptionaldefenderWarPolicy: WarPolicy
The defender's war policy (infra and loot modifier)
The war type (infra and loot modifier; defaults to Ordinary)
The defender's on-hand money (drives the loot amount and its caps)
The averaged GroundSimResult across all simulated battles
Calculates the hospital modifier for disease rate reduction. Each hospital reduces disease rate by 2.5, or 3.5 if a Clinical Research Center is present.
Number of hospitals in the city
Whether a Clinical Research Center is present (default: false)
The hospital modifier value
Calculates the total infrastructure cost between two amounts, applying discounts for various projects.
Starting infrastructure amount
Ending infrastructure amount
If true, applies 5% or 10% discount with advancedEngineeringCorps
If true, applies additional discount with centerOfCivilEngineering
If true, applies discount based on governmentSupportAgency or bureauOfDomesticAffairs
If true, increases urbanization discount
If true, increases urbanization discount further
Total infrastructure cost after discounts
Returns the combined infrastructure-damage multiplier applied to an airstrike from the attacker's and the defender's war policies.
Attacker (offensive) modifiers:
Defender (damage-taken) modifiers:
All other policies have no effect on airstrike infrastructure damage.
Optionalattacker: WarPolicy
The attacker's war policy
Optionaldefender: WarPolicy
The defender's war policy
The multiplier to apply to the base infrastructure damage
Calculates the inverse espionage range — given a nation's score, the span of attacker scores that can run espionage against it (the inverse of espionageRange).
The nation's score
The minimum and maximum attacker score that has this nation in range
Calculates the inverse war range — given a nation's score, the span of attacker scores that can declare war on it (the inverse of warRange).
The nation's score
The minimum and maximum attacker score that has this nation in range
Calculates the total land cost between two amounts, applying discounts for various projects.
Starting land amount
Ending land amount
If true, applies 5% or 10% discount with advancedEngineeringCorps
If true, applies additional discount with arableLandAgency
If true, applies discount based on governmentSupportAgency or bureauOfDomesticAffairs
If true, increases rapidExpansion discount
If true, increases rapidExpansion discount further
Total land cost after discounts
Returns the combined war-policy loot multiplier from the attacker's and defender's war policies:
All other policies have no effect on loot.
Optionalattacker: WarPolicy
The attacker's war policy
Optionaldefender: WarPolicy
The defender's war policy
The multiplier to apply to the base loot
Simulates the money looted from a successful ground attack.
Loot = (Attacking Soldiers * 1.1 + Attacking Tanks * 25.15) * VictoryFactor * RAND(0.8, 1.1) * WarTypeFactor * WarPolicyFactor
where VictoryFactor is the victory tier (0 for Utter Failure up to 3 for Immense Triumph), the war-type factor comes from warTypeLootMultiplier, and the war-policy factor from lootPolicyMultiplier. The result is capped at 75% of the defender's cash on hand, cannot take their last $1,000,000, and is floored at zero.
Number of the attacker's surviving soldiers
Number of the attacker's surviving tanks
The victory tier (see VictoryType)
The defender's on-hand money
The war type (loot modifier; defaults to Ordinary)
OptionalattackerWarPolicy: WarPolicy
The attacker's war policy (loot modifier)
OptionaldefenderWarPolicy: WarPolicy
The defender's war policy (loot modifier)
The amount of money looted
Simulates the infrastructure destroyed by a missile strike on a city.
Infra Destroyed = min( randBetween(300, max(350, populationDensity * 3)), (cityInfrastructure * 0.3) + 100, // city infra limit cityInfrastructure // can't destroy more than the city has )
The city's current infrastructure
The city's population density
The amount of infrastructure destroyed
Simulates one or more naval battles and returns the average ship losses for both sides, the average infrastructure destroyed, and the probability of each victory type.
Each battle resolves as 3 rolls. Every roll each side generates a value between
40% and 100% of its naval value (Ships * 4); the side with the higher value
wins the roll. The number of rolls won determines the victory type:
3 wins → Immense Triumph, 2 → Moderate Victory, 1 → Pyrrhic Victory, 0 → Utter Failure.
Ship casualties accrue each roll from the opponent's roll value: each side loses
(opponent's roll) * 0.01375 ships per roll.
Infrastructure destroyed uses: Infra = MAX(MIN((Att Ships - Def Ships * 0.5) * 2.625 * RAND(0.85, 1.05) * (wins / 3), City Infrastructure * 0.5 + 25), 0) multiplied by the war-type factor (see warTypeInfraMultiplier) and the combined war-policy factor (see airstrikeInfraPolicyMultiplier — the Attrition/Turtle/Moneybags/Covert/Arcane modifiers apply to naval battles too).
The attacker's ship count
The defender's ship count
Number of naval battles to simulate (results are averaged over these)
The targeted city's infrastructure (drives the infra-damage cap)
OptionalattackerWarPolicy: WarPolicy
The attacker's war policy (offensive infra modifier)
OptionaldefenderWarPolicy: WarPolicy
The defender's war policy (defensive infra modifier)
The war type (offensive infra modifier; defaults to Ordinary)
The averaged NavalSimResult across all simulated battles
Simulates the infrastructure destroyed by a nuclear strike on a city.
Infra Destroyed = min( randBetween(1700, max(2000, populationDensity * 13.5)), (cityInfrastructure * 0.8) + 150, // city infra limit cityInfrastructure // can't destroy more than the city has )
The city's current infrastructure
The city's population density
The amount of infrastructure destroyed
Calculates the police modifier for crime rate reduction. Each police station reduces crime rate by 2.5, or 3.5 if a Specialized Police Training Program is present.
Number of police stations in the city
Whether a Specialized Police Training Program is present (default: false)
The police modifier value
Calculates a city's total pollution index from its improvement counts, summing ImprovementPollution across every improvement and applying national project modifiers. The result is floored at zero.
National project modifiers:
Improvement counts keyed by lowercase name (e.g. steel_mill)
Whether the nation has the Green Technologies project (default: false)
Whether the nation has the Recycling Initiative project (default: false)
The total pollution index (never negative)
Calculates the pollution modifier for disease rate.
The pollution index value
The pollution modifier value
Calculates the actual (displayed) population for a city.
Population = (Base Population - Disease Deaths - Crime Deaths) * Age Bonus
The base population (infrastructure * 100)
Population lost to disease (see diseaseDeaths)
Population lost to crime (see crimeDeaths)
The city age bonus modifier (see ageBonus)
The actual population, floored at zero
const basePop = basePopulation(50); // 5000
const ageBonusValue = ageBonus(20); // Age bonus for a 20-turn-old city
const diseaseDeaths = 120;
const crimeDeaths = 80;
const pop = population(basePop, diseaseDeaths, crimeDeaths, ageBonusValue);
console.log(pop); // Actual population after deaths and age bonus
Calculates the population density for a city.
The total population of the city (must be non-negative)
The land area of the city (must be greater than zero)
The population density (population divided by land)
Calculates the radiation index modifier for a city based on continent and global radiation values.
Radiation value for the continent
Global radiation value
The calculated radiation index modifier
Calculates the war declaration range for a nation — the span of nation scores it can declare war on (75% to 250% of its own score).
The nation's score
The minimum and maximum declarable enemy score
Returns the fraction of potential infrastructure damage an attacker deals based on the war type:
The war type
The infrastructure-damage multiplier for the attacker
Returns the war-type loot multiplier — the fraction of potential loot an attacker takes based on the war type:
(Note this differs from the infrastructure war-type factor, where Attrition is the strongest and Raid the weakest.)
The war type
The loot multiplier for the attacker
Collection of utility functions for Politics & War calculations and data transformations.
Provides helper functions for:
Example