The only thing I don't know how to program is to make it stop once a certain tech is researched. Here is the script:
Code: Select all
Random chance to civil war due to total cities, culture and happiness.
In each turn started, we check:
1st: we check total cities against civil war threshold.
Check passed if player has city equal or more than minimum number of cities for civil war.
2nd: we check total cities.
Check passed if player passes probability of total cities / (1000 + total cities).
3rd: we check culture.
Check passed if player passes probability of 2000 / (2000 + culture).
4th: we check happiness (instead of normal civil war check).
Check passed if player passes probability of (total cities - celebrating cities + unhappy cities) / (total cities * 2).
If all of the above checks passed, civil war will occur at 100%.
--]]
function random_chance_to_civil_war(turn, year)
local total_cities = 0
local civil_war_threshold = tonumber(server.setting.get("civilwarsize"))
local celebrating_cities = 0
local unhappy_cities = 0
-- Check each player.
for target_player in players_iterate() do
total_cities = target_player:num_cities()
-- Check total cities against minimum number of cities for civil war.
if total_cities >= civil_war_threshold then
-- Check total cities.
if random(0, 1000 + total_cities - 1) < total_cities then
notify.player(target_player, "You passed total cities check to civil war. Pay attention to your city.")
-- Initialize city count.
celebrating_cities = 0
unhappy_cities = 0
-- Count city for check happiness.
for target_player_city in target_player:cities_iterate() do
if target_player_city:is_celebrating() then
celebrating_cities = celebrating_cities + 1
elseif target_player_city:is_unhappy() then
unhappy_cities = unhappy_cities + 1
end
end
-- Check happiness.
if random(0, total_cities * 2 - 1) < total_cities - celebrating_cities + unhappy_cities then
notify.player(target_player, "You passed happiness check to civil war. Prepare for against the rebel.")
-- Raiding party!
target_player:civil_war(100)
end
end
end
end
-- Continue processing.
return false
end