﻿###########################
# Spanish Events
###########################

add_namespace = spain

# Spanish Civil War
country_event = {
	id = spain.1
	title = spain.1.t
	desc = spain.1.d
	picture = GFX_report_event_spain_civil_war_soldiers

	fire_only_once = yes

	trigger = { #EAI: less random
		NOT = { has_global_flag = scw_over }
		tag = SPR
		has_defensive_war = no
		NOT = { has_government = fascism }
		date > 1936.5.16 # Trigger at some point after 1936 elections
		NOT = { has_dlc = "La Resistance" }
	}

	mean_time_to_happen = {
		days = 140	# Historical outbreak time after elections
		modifier = { factor = 0.1 date > 1936.12.1 }
	}

	immediate = {
		hidden_effect = {
			if = {
				limit = {
					has_country_leader = {
					    character = SPR_niceto_alcala_zamora
					    ruling_only = yes
					}
				}
				retire_country_leader = yes
				add_country_leader_role = {
					character = SPR_manuel_azana
					country_leader = {
					 	ideology = conservatism
					 	traits = { }
					 	expire = "1965.1.1"
					}
					promote_leader = yes
				}
			}
		}
	}

	option = { # Support Nationalists
		name = spain.1.a
		trigger = { is_ai = no }
		hidden_effect = {
			set_capital = { state = 176 }
			start_civil_war = {
				ruling_party = fascism
				ideology = communism
				size = 0.5
				capital = 41
				states = { 41 165 167 168 173 175 790 792 793 794 }
			}
			random_other_country = {
				limit = {
					original_tag = SPR
					has_government = communism
				}
				load_oob = "SPR_Civil_War"
				set_equipment_fraction = 0.5
				set_stability = 0.9
				set_war_support = 0.8
				#country_event = { id = spain.3 days = 1 }
				add_popularity = {
					ideology = democratic
					popularity = 0.35
				}
			}
			news_event = { hours = 6 id = news.63 }
			set_global_flag = spanish_civil_war
			set_country_flag = scw_no_lar_nationalists

			load_oob = "SPA_Civil_War"
			set_equipment_fraction = 0.5
			set_stability = 0.9
			set_war_support = 0.8

			add_popularity = {
				ideology = fascism
				popularity = 1
			}
			random_other_country = {
				limit = {
					original_tag = SPR
					has_government = communism
				}
				set_cosmetic_tag = SPR_civil_war
				set_country_flag = scw_no_lar_republicans
			}

			#country_event = { id = spain.2 days = 7 }
		}
		custom_effect_tooltip = nationalists_chosen
	}
	option = { # Support Republicans
		name = spain.1.b
		hidden_effect = {
			start_civil_war = {
				ideology = fascism
				size = 0.5
				capital = 176
				states = { 166 169 170 171 172 174 176 177 178 290 297 699 788 789 791 }
			}
			random_other_country = {
				limit = {
					original_tag = SPR
					has_government = fascism
				}
				set_equipment_fraction = 0.5
				set_stability = 0.9
				set_war_support = 0.8
				#country_event = { id = spain.2 days = 1 }
				load_oob = "SPA_Civil_War"
			}
			news_event = { hours = 6 id = news.63 }
			set_global_flag = spanish_civil_war
			set_country_flag = scw_no_lar_republicans

			set_politics = {
				ruling_party = communism
				elections_allowed = no
			}
			add_popularity = {
				ideology = communism
				popularity = 0.5
			}
			add_popularity = {
				ideology = fascism
				popularity = -1
			}
			random_other_country = {
				limit = {
					original_tag = SPR
					has_government = fascism
				}
				set_cosmetic_tag = SPR_civil_war
				set_country_flag = scw_no_lar_nationalists
			}
			load_oob = "SPR_Civil_War"
			set_equipment_fraction = 0.5
			set_stability = 0.9
			set_war_support = 0.8

			#country_event = { id = spain.3 days = 7 }
		}
		custom_effect_tooltip = republicans_chosen
	}
}

# Nationalists: Seek Support
country_event = {
	id = spain.2
	title = spain.2.t
	desc = spain.2.d
	picture = GFX_report_event_spain_civil_war_volunteers_01

	is_triggered_only = yes

	trigger = {
		has_civil_war = yes
		original_tag = SPR
	}

	option = {
		name = spain.2.a
		every_other_country = {
			limit = {
				has_government = fascism
				NOT = { original_tag = SPR }
			}
			country_event = { id = spain.4 days = 1 }
		}
		if = {
			limit = {
				POR = { NOT = { has_government = communism } }
			}
			POR = { country_event = { id = spain.4 days = 1 } }
		}
	}

	option = {
		name = spain.2.b
		add_political_power = 40
		ai_chance = { factor = 0 }
	}
}

# Republicans: Seek Support
country_event = {
	id = spain.3
	title = spain.2.t
	desc = spain.3.d
	picture = GFX_report_event_spain_civil_war_volunteers

	is_triggered_only = yes

	trigger = {
		has_civil_war = yes
	}

	option = {
		name = spain.3.a
		every_other_country = {
			limit = {
				has_government = communism
				NOT = { tag = SPR }
			}
			country_event = { id = spain.5 days = 1 }
		}
		if = {
			limit = {
				MEX = { NOT = { has_government = fascism } }
			}
			MEX = { country_event = { id = spain.5 days = 1 } }
		}
	}

	option = {
		name = spain.3.b
		add_political_power = 40
		ai_chance = { factor = 0 }
	}
}

# Nationalist Spain Wants Our Help
country_event = {
	id = spain.4
	title = spain.4.t
	desc = spain.4.d
	picture = GFX_report_event_spain_civil_war_soldiers

	is_triggered_only = yes

	trigger = {
		SPR = { has_civil_war = yes }
	}

	option = {
		name = spain.4.a
		set_country_flag = promised_help_nationalist_spain
		custom_effect_tooltip = spain.4.a.tt
	}

	option = {
		name = spain.4.b

	}
}

# Republican Spain Wants Our Help
country_event = {
	id = spain.5
	title = spain.5.t
	desc = spain.5.d
	picture = GFX_report_event_spain_civil_war_volunteers_02

	is_triggered_only = yes

	trigger = {
		SPR = { has_civil_war = yes }
	}

	option = {
		name = spain.5.a
		set_country_flag = promised_help_republican_spain
		custom_effect_tooltip = spain.4.a.tt
	}

	option = {
		name = spain.5.b

	}
}

# Nationalist Spain Appreciates our Help
country_event = {
	id = spain.6
	title = spain.6.t
	desc = spain.6.d
	picture = GFX_report_event_finnish_letter

	trigger = {
		has_country_flag = promised_help_nationalist_spain
		SPR = { has_civil_war = yes }
		any_other_country = {
			original_tag = SPR
			has_government = fascism
			ROOT = { is_lend_leasing = PREV }
		}
	}

	mean_time_to_happen = {
		days = 2
	}

	option = {
		name = spain.6.a
		clr_country_flag = promised_help_nationalist_spain
		random_other_country = {
			limit = {
				original_tag = SPR
				has_government = fascism
			}
			add_opinion_modifier = { target = ROOT modifier = lend_leased_spanish_civil_war }
		}
	}
}

# Republican Spain Appreciates our Help
country_event = {
	id = spain.7
	title = spain.7.t
	desc = spain.7.d
	picture = GFX_report_event_spain_civil_war_volunteers_01

	trigger = {
		has_country_flag = promised_help_republican_spain
		SPR = { has_civil_war = yes }
		is_lend_leasing = SPR
	}

	mean_time_to_happen = {
		days = 2
	}

	option = {
		name = spain.7.a
		clr_country_flag = promised_help_republican_spain
		SPR = { add_opinion_modifier = { target = ROOT modifier = lend_leased_spanish_civil_war } }
	}
}

# Civil war over. Move Capital
country_event = {
	id = spain.8
	title = spain.8.t
	desc = spain.8.d
	picture = GFX_report_event_spain_civil_war_volunteers_01

	trigger = {
		original_tag = SPR
		has_government = fascism
		has_global_flag = nationalist_victory
		owns_state = 41
		NOT = {
			41 = { is_capital = yes }
		}
	}

	fire_only_once = yes

	mean_time_to_happen = {
		days = 2
	}

	option = {
		ai_chance = { factor = 1 }
		name = spain.8.a
		set_capital = { state = 41 }
	}
	option = {
		ai_chance = { factor = 0 }
		name = spain.8.b
	}
}

# Election of 1936
country_event = {
	id = spain.9
	title = spain.9.t
	desc = spain.9.d
	picture = GFX_report_event_election_vote

	is_triggered_only = yes

	fire_only_once = yes

	trigger = {
		tag = SPR
		date < 1937.1.1
		NOT = {
			has_dlc = "La Resistance"
		}
	}

	# Popular Front
	option = {
		ai_chance = { factor = 1 }
		name = spain.9.a
		add_popularity = {
			ideology = communism
			popularity = 0.1
		}
	}

	# Falange
	option = {
		ai_chance = { factor = 0 }
		name = spain.9.b
		set_politics = {
			ruling_party = fascism
			elections_allowed = no
		}
		set_country_flag = SPR_communist_civil_war
	}
}

# Spanish Civil War if Franco is elected
country_event = {
	id = spain.10
	title = spain.1.t
	desc = spain.10.d
	picture = GFX_report_event_spain_civil_war_soldiers

	fire_only_once = yes

	trigger = {
		NOT = { has_global_flag = scw_over }
		has_country_flag = SPR_communist_civil_war
		has_defensive_war = no
		date > 1936.2.16 # Trigger at some point after 1936 elections
	}

	mean_time_to_happen = {
		days = 151	# Historical outbreak time after elections
	}

	option = { # Support Nationalists
		name = spain.1.a
		trigger = { is_ai = no }
		hidden_effect = {
			set_capital = { state = 176 }
			start_civil_war = {
				ruling_party = fascism
				ideology = communism
				size = 0.5
				capital = 41
				states = { 41 165 167 168 173 175 790 792 793 794 }
			}
			random_other_country = {
				limit = {
					original_tag = SPR
					has_government = communism
				}
				load_oob = "SPR_Civil_War"
				set_equipment_fraction = 0.7
				set_stability = 0.8
				set_war_support = 0.8
				add_popularity = {
					ideology = democratic
					popularity = 0.35
				}
			}
			news_event = { hours = 6 id = news.63 }
			set_global_flag = spanish_civil_war

			load_oob = "SPA_Civil_War"
			set_equipment_fraction = 0.7
			set_stability = 0.9
			set_war_support = 0.8
			add_popularity = {
				ideology = fascism
				popularity = 1
			}
			random_other_country = {
				limit = {
					original_tag = SPR
					has_government = communism
				}
				set_cosmetic_tag = SPR_civil_war
			}
		}
		custom_effect_tooltip = nationalists_chosen
	}
	option = { # Support Republicans
		name = spain.10.b
		hidden_effect = {
			start_civil_war = {
				ideology = fascism
				size = 0.5
				capital = 176
				states = { 166 169 170 171 172 174 176 177 178 290 297 699 788 789 791 }
			}
			random_other_country = {
				limit = {
					original_tag = SPR
					has_government = fascism
				}
				set_equipment_fraction = 0.7
				set_stability = 0.9
				set_war_support = 0.8
				load_oob = "SPA_Civil_War"
			}
			news_event = { hours = 6 id = news.63 }
			set_global_flag = spanish_civil_war

			set_politics = {
				ruling_party = communism
				elections_allowed = no
			}
			load_oob = "SPR_Civil_War"
			set_equipment_fraction = 0.7
			set_stability = 0.9
			set_war_support = 0.8
			add_popularity = {
				ideology = fascism
				popularity = -1
			}
			add_popularity = {
				ideology = communism
				popularity = 1
			}
			add_popularity = {
				ideology = democratic
				popularity = 0.35
			}
			random_other_country = {
				limit = {
					original_tag = SPR
					has_government = fascism
				}
				set_cosmetic_tag = SPR_civil_war
			}
		}
		custom_effect_tooltip = republicans_chosen
	}
}