﻿# Rota Fortunae — the Hegemonic Crisis.
# One instance per coalition target. Opened when a coalition gathers two members; the theatre is
# exactly the realm of the hegemon and the realms of its coalition, so the crisis map shows the
# hegemon in gold, the coalition in red and the rest of the world in grey. Phases follow the coalition's life:
# tension -> escalation (menace 75+) -> general war (coalition war) -> aftermath (5 years, then ends).
rf_hegemonic_crisis = {
	is_unique = no
	window = situation
	gui_window_name = "window_situation"
	gui_participation_window_name = "window_situation_participation"
	illustration = "gfx/interface/illustrations/event_scenes/councilchamber.dds"
	situation_group_type = major
	sort_order = 50
	map_mode = participant_groups

	sub_regions = {
		rf_theatre = {
			icon = "gfx/interface/icons/situation_types/rf_hegemonic_crisis.dds"
			illustration = "gfx/interface/illustrations/event_scenes/councilchamber.dds"
			map_color = { 0.85 0.65 0.25 }
		}
	}

	participant_groups = {
		rf_hegemon = {
			icon = "gfx/interface/icons/flat_icons/county_crown.dds"
			map_color = { 0.86 0.68 0.2 }
			auto_add_rulers = yes
			auto_add_landless_rulers = no
			require_realm_in_sub_region = yes
			is_character_valid = {
				exists = scope:situation.var:rf_hegemon_title.holder
				this = scope:situation.var:rf_hegemon_title.holder
			}
		}
		# The hegemon's vassals: same colour on the map, no phase modifiers.
		rf_hegemon_realm = {
			icon = "gfx/interface/icons/flat_icons/county_crown.dds"
			map_color = { 0.86 0.68 0.2 }
			auto_add_rulers = yes
			auto_add_landless_rulers = no
			require_realm_in_sub_region = yes
			is_character_valid = {
				highest_held_title_tier >= tier_county
				this != top_liege
				exists = scope:situation.var:rf_hegemon_title.holder
				top_liege = scope:situation.var:rf_hegemon_title.holder
			}
		}
		rf_coalition = {
			icon = "gfx/interface/icons/casus_bellis/bloc.dds"
			map_color = { 0.8 0.12 0.1 }
			auto_add_rulers = yes
			auto_add_landless_rulers = no
			require_realm_in_sub_region = yes
			is_character_valid = {
				rf_is_realm_trigger = yes
				exists = scope:situation.var:rf_hegemon_title
				exists = primary_title.var:rf_coalition_against
				primary_title.var:rf_coalition_against = scope:situation.var:rf_hegemon_title
			}
		}
		# The members' vassals: same colour on the map, no phase modifiers.
		rf_coalition_realm = {
			icon = "gfx/interface/icons/casus_bellis/bloc.dds"
			map_color = { 0.8 0.12 0.1 }
			auto_add_rulers = yes
			auto_add_landless_rulers = no
			require_realm_in_sub_region = yes
			is_character_valid = {
				highest_held_title_tier >= tier_county
				this != top_liege
				exists = scope:situation.var:rf_hegemon_title
				exists = top_liege.primary_title.var:rf_coalition_against
				top_liege.primary_title.var:rf_coalition_against = scope:situation.var:rf_hegemon_title
			}
		}
		rf_neutral = {
			icon = "gfx/interface/icons/flat_icons/war_outcome_white_peace.dds"
			map_color = { 0.42 0.42 0.42 }
			auto_add_rulers = yes
			auto_add_landless_rulers = no
			require_realm_in_sub_region = yes
			is_character_valid = {
				rf_is_realm_trigger = yes
			}
		}
	}

	on_yearly = {
		if = {
			limit = {
				exists = var:rf_crisis_end_year
				current_year >= var:rf_crisis_end_year
			}
			end_situation = yes
		}
		# The hegemon's title no longer exists or has lost the crisis: wind down.
		else_if = {
			limit = {
				NOT = { exists = var:rf_crisis_end_year }
				OR = {
					NOT = { exists = var:rf_hegemon_title }
					NOT = { exists = var:rf_hegemon_title.holder }
					var:rf_hegemon_title.holder ?= { rf_is_realm_trigger = no }
					NOT = { exists = var:rf_hegemon_title.var:rf_crisis }
				}
			}
			situation_sub_region:rf_theatre = { change_phase = { phase = rf_crisis_aftermath } }
			set_variable = { name = rf_crisis_end_year value = { value = current_year add = 5 } }
		}
	}

	on_end = {
		if = {
			limit = {
				exists = var:rf_hegemon_title
				exists = var:rf_hegemon_title.var:rf_crisis
			}
			var:rf_hegemon_title = { remove_variable = rf_crisis }
		}
	}

	start_phase = rf_crisis_tension

	phases = {
		rf_crisis_tension = {
			icon = "gfx/interface/icons/flat_icons/prestige.dds"
			illustration = "gfx/interface/illustrations/event_scenes/councilchamber.dds"
			future_phases = {
				rf_crisis_escalation = {}
				rf_crisis_war = {}
				rf_crisis_aftermath = {}
			}
			modifier_sets = {
				rf_crisis_tension_effects = {
					icon = "gfx/interface/icons/flat_icons/prestige.dds"
					rf_hegemon = {
						character_modifier = {
							monthly_prestige_gain_mult = 0.1
						}
					}
					rf_coalition = {
						character_modifier = {
							levy_reinforcement_rate = 0.1
						}
					}
					rf_neutral = {
						character_modifier = {
							monthly_prestige = 0.5
						}
					}
				}
			}
		}

		rf_crisis_escalation = {
			on_start = {
				scope:situation_sub_region = {
					every_situation_sub_region_participant = {
						limit = { is_ai = no }
						send_interface_message = {
							type = event_generic_neutral
							title = rf_msg_crisis_escalation_title
							desc = rf_msg_crisis_escalation_desc
						}
					}
				}
			}
			icon = "gfx/interface/icons/flat_icons/declare_war.dds"
			illustration = "gfx/interface/illustrations/event_scenes/courtyard.dds"
			map_province_effect = drought
			map_province_effect_intensity = 0.15
			future_phases = {
				rf_crisis_tension = {}
				rf_crisis_war = {}
				rf_crisis_aftermath = {}
			}
			modifier_sets = {
				rf_crisis_escalation_effects = {
					icon = "gfx/interface/icons/flat_icons/declare_war.dds"
					rf_hegemon = {
						character_modifier = {
							defender_advantage = 2
							stress_gain_mult = 0.1
						}
					}
					rf_coalition = {
						character_modifier = {
							levy_size = 0.05
							levy_reinforcement_rate = 0.15
						}
					}
					rf_neutral = {
						character_modifier = {
							monthly_prestige = 1
						}
					}
				}
			}
		}

		rf_crisis_war = {
			on_start = {
				scope:situation_sub_region = {
					every_situation_sub_region_participant = {
						limit = { is_ai = no }
						send_interface_message = {
							type = event_generic_neutral
							title = rf_msg_crisis_war_title
							desc = rf_msg_crisis_war_desc
						}
					}
				}
			}
			icon = "gfx/interface/icons/flat_icons/war_outcome_victory.dds"
			illustration = "gfx/interface/illustrations/event_scenes/battlefield.dds"
			map_province_effect = drought
			map_province_effect_intensity = 0.3
			future_phases = {
				rf_crisis_tension = {}
				rf_crisis_escalation = {}
				rf_crisis_aftermath = {}
			}
			modifier_sets = {
				rf_crisis_war_effects = {
					icon = "gfx/interface/icons/flat_icons/war_outcome_victory.dds"
					rf_hegemon = {
						character_modifier = {
							defender_advantage = 4
							levy_reinforcement_rate = 0.2
						}
					}
					rf_coalition = {
						character_modifier = {
							attacker_advantage = 2
							levy_reinforcement_rate = 0.2
						}
					}
					rf_neutral = {
						character_modifier = {
							domain_tax_mult = 0.05
						}
					}
				}
			}
		}

		rf_crisis_aftermath = {
			on_start = {
				scope:situation_sub_region = {
					every_situation_sub_region_participant = {
						limit = { is_ai = no }
						send_interface_message = {
							type = event_generic_neutral
							title = rf_msg_crisis_aftermath_title
							desc = rf_msg_crisis_aftermath_desc
						}
					}
				}
			}
			icon = "gfx/interface/icons/flat_icons/war_outcome_white_peace.dds"
			illustration = "gfx/interface/illustrations/event_scenes/courtyard.dds"
			future_phases = {
				rf_crisis_tension = {}
			}
			modifier_sets = {
				rf_crisis_aftermath_effects = {
					icon = "gfx/interface/icons/flat_icons/war_outcome_white_peace.dds"
					all = {
						character_modifier = {
							build_gold_cost = -0.05
						}
					}
				}
			}
		}
	}
}
