###########################
# Portugal in Exile Events
# Don't merge this file into the base Portugal file, it's separate to avoid merge issues
###########################

add_namespace = portugal_exile

country_event = { #Portugal's Last Stand
	id = portugal_exile.1
	immediate = { log = "[GetDateText]: [Root.GetName]: event portugal_exile.1" }
	title = portugal_exile.1.t
	desc = portugal_exile.1.d

	is_triggered_only = yes

trigger = {
		tag = POR
		NOT = { has_idea = POR_last_stand }
	}

	option = {
		name = portugal_exile.1.a
		add_war_support = 0.2
		add_ideas = POR_last_stand
		PAF = {
			add_ideas = POR_last_stand
		}
	}
}

country_event = { #The Fall of Portugal
	id = portugal_exile.2
	immediate = { log = "[GetDateText]: [Root.GetName]: event portugal_exile.2" }
	title = portugal_exile.2.t
	desc = portugal_exile.2.d

	fire_only_once = yes
	is_triggered_only = yes

trigger = {
		tag = POR
		NOT = {
			has_global_flag = MAF_POR_border_war
			has_country_flag = SCW_POR_intervention
			controls_state = 112 #Lisbon
			controls_state = 179 #Beja
			controls_state = 180 #Porto
			controls_state = 181 #Guarda
		}
	}

	option = {
		name = portugal_exile.2.a

		### Transfer all mainland states to whoever controls Lisbon (or its overlord if a subject)
		every_owned_state = {
			limit = {
				OR = {
					region = 236 #Southern Iberia
					region = 237 #Western Iberia
				}
			}
			var:112.controller = {
				if = {
					limit = { is_subject = yes }
					overlord = { transfer_state = PREV.PREV }
				}
				else = {
					transfer_state = PREV
				}
			}
		}

		### Peace out whoever controls Lisbon and POR, if POR is not in the Entente
		if = {
			limit = { is_valid_peace_target = yes }
			var:112.controller = { white_peace_with_ROOT = yes }
			hidden_effect = {
				### Prompt POR to join the Entente
				if = {
					limit = {
						ENT = { is_faction_leader = yes }
					}
					country_event = {
						id = portugal_exile.3
						days = 2
					}
				}
				### POR collapses afterwards if the Entente is dead
				else = {
					country_event = {
						id = portugal_exile.14
						days = 7
					}
				}
			}
		}

		hidden_effect = {
			### Notify the owner of Lisbon
			var:112.owner = { country_event = portugal_exile.7 }
			PAF = {
				every_unit_leader = { set_nationality = POR }
				transfer_navy = {
					target = POR
				}
			}
			POR = {
				annex_country = {
					target = PAF
					transfer_troops = yes
				}
			}
		}
	}
}

country_event = { #Rejoin the Entente? (POR)
	id = portugal_exile.3
	immediate = { log = "[GetDateText]: [Root.GetName]: event portugal_exile.3" }
	title = portugal_exile.3.t
	desc = portugal_exile.3.d
	picture = GFX_report_event_POR_entente

	is_triggered_only = yes

trigger = {
		ENT = { is_faction_leader = yes }
	}

	option = {
		name = portugal_exile.3.a
		ENT = {
			country_event = {
				id = portugal_exile.4
				days = 1
			}
		}
	}
}

country_event = { #An Old Ally's Plight (ENT)
	id = portugal_exile.4
	immediate = { log = "[GetDateText]: [Root.GetName]: event portugal_exile.4" }
	title = portugal_exile.4.t
	desc = portugal_exile.4.d
	picture = GFX_report_event_POR_entente

	is_triggered_only = yes

trigger = {
		is_faction_leader = yes
		country_exists = FROM
	}

	option = {
		name = portugal_exile.4.a
		add_to_faction = FROM
		hidden_effect = {
			FROM = {
				country_event = portugal_exile.5
			}
		}
	}

	option = {
		name = portugal_exile.4.b
	trigger = {
			is_ai = no
		}
		hidden_effect = {
			FROM = {
				country_event = portugal_exile.5
			}
		}
	}
}

country_event = { #ENT responds (POR)
	id = portugal_exile.5
	immediate = { log = "[GetDateText]: [Root.GetName]: event portugal_exile.5" }

	title = {
		text = portugal_exile.5.t.accept
	trigger = { is_in_faction_with = FROM }
	}
	title = {
		text = portugal_exile.5.t.refuse
	trigger = { NOT = { is_in_faction_with = FROM } }
	}

	desc = {
		text = portugal_exile.5.d.accept
	trigger = { is_in_faction_with = FROM }
	}
	desc = {
		text = portugal_exile.5.d.refuse
	trigger = { NOT = { is_in_faction_with = FROM } }
	}

	picture = GFX_report_event_generic_diplomacy1

	is_triggered_only = yes

	option = {
		name = portugal_exile.5.a
	trigger = {
			is_in_faction_with = FROM
		}
		add_political_power = 25
		add_opinion_modifier = {
			target = FROM
			modifier = KR_close_allies
		}
	}

	option = {
		name = portugal_exile.5.b
	trigger = {
			NOT = { is_in_faction_with = FROM }
		}
		add_political_power = -50
		add_stability = -0.1
		add_opinion_modifier = {
			target = FROM
			modifier = KR_outraged
		}
		hidden_effect = {
			country_event = { id = portugal_exile.14 days = 7 }
			PAF = { country_event = { id = portugal_exile.14 days = 7 } }
		}
	}
}

country_event = { #The Portuguese Collapse (MAF)
	id = portugal_exile.6
	immediate = { log = "[GetDateText]: [Root.GetName]: event portugal_exile.6" }
	title = portugal_exile.6.t

	desc = {
		text = portugal_exile.6.d.peace
	trigger = {
			NOT = { has_war_with = POR }
		}
	}
	desc = {
		text = portugal_exile.6.d.war
	trigger = { has_war_with = POR }
	}

	picture = GFX_report_event_POR_entente

	is_triggered_only = yes

	option = {
		name = portugal_exile.6.a
	trigger = {
			NOT = { has_war_with = POR }
		}
		add_political_power = 50
		add_stability = 0.1
		remove_ideas = MAF_border_shit_show
	}

	option = {
		name = portugal_exile.6.b
	trigger = { has_war_with = POR }
		add_political_power = 50
		add_stability = 0.1
		remove_ideas = MAF_border_shit_show
		PAF = {
			every_owned_state = {
				limit = {
					OR = {
						region = 3 #Congo
						region = 139 #South Africa
						region = 188 #East Africa
						region = 190 #Middle Africa
					}
				}
				ROOT = { transfer_state = PREV }
			}
			white_peace_with_ROOT = yes
		}
	}
}

country_event = { #The Portuguese Collapse (CNT)
	id = portugal_exile.7
	immediate = { log = "[GetDateText]: [Root.GetName]: event portugal_exile.7" }
	title = portugal_exile.7.t
	desc = portugal_exile.7.d
	picture = GFX_report_event_POR_entente

	is_triggered_only = yes

	option = {
		name = portugal_exile.7.a
		add_political_power = 50
	}
}

country_event = { #Seizure of Macau?
	id = portugal_exile.9
	immediate = { log = "[GetDateText]: [Root.GetName]: event portugal_exile.9" }
	title = portugal_exile.9.t
	desc = portugal_exile.9.d
	picture = GFX_report_event_POR_entente

	is_triggered_only = yes

trigger = {
		PAF = { owns_state = 729 }
	}

	option = {
		name = portugal_exile.seize
		transfer_state = 729
		hidden_effect = {
			POR = {
				country_event = {
					id = portugal_exile.12
					days = 3
				}
			}
		}
	}

	option = {
		name = portugal_exile.dont_seize
		trigger = { is_ai = no }
	}
}

country_event = { #Seizure of Goa?
	id = portugal_exile.10
	immediate = { log = "[GetDateText]: [Root.GetName]: event portugal_exile.10" }
	title = portugal_exile.10.t
	desc = portugal_exile.10.d
	picture = GFX_report_event_POR_entente

	is_triggered_only = yes

trigger = {
		PAF = { owns_state = 321 }
	}

	option = {
		name = portugal_exile.seize
		transfer_state = 321
		hidden_effect = {
			POR = {
				country_event = {
					id = portugal_exile.12
					days = 3
				}
			}
		}
	}

	option = {
		name = portugal_exile.dont_seize
		trigger = { is_ai = no }
	}
}

country_event = { #Seizure of Timor?
	id = portugal_exile.11
	immediate = { log = "[GetDateText]: [Root.GetName]: event portugal_exile.11" }
	title = portugal_exile.11.t
	desc = portugal_exile.11.d
	picture = GFX_report_event_POR_entente

	is_triggered_only = yes

trigger = {
		PAF = {
			owns_state = 721
			owns_state = 972
		}
	}

	option = {
		name = portugal_exile.seize
		transfer_state = 721
		transfer_state = 972
		if = {
			limit = { tag = INS }
			add_state_core = 721
			add_state_core = 972
		}
		hidden_effect = {
			POR = {
				country_event = {
					id = portugal_exile.12
					days = 3
				}
			}
		}
	}

	option = {
		name = portugal_exile.dont_seize
	trigger = { is_ai = no }
	}
}

country_event = { #Eastern Possessions Seized!
	id = portugal_exile.12
	immediate = { log = "[GetDateText]: [Root.GetName]: event portugal_exile.12" }
	title = portugal_exile.12.t
	desc = portugal_exile.12.d
	picture = GFX_report_event_POR_entente

	is_triggered_only = yes

	option = {
		name = portugal_exile.12.a
	}
}

news_event = { #Collapse of the Portuguese Empire
	id = portugal_exile.13
	immediate = { log = "[GetDateText]: [Root.GetName]: event portugal_exile.13" }
	title = portugal_exile.13.t
	desc = portugal_exile.13.d
	picture = GFX_news_event_kingston

	is_triggered_only = yes

	major = yes

	option = {
		name = portugal_exile.13.a
		if = {
			limit = {
				tag = POR
				}
			add_political_power = -100
		}
	}
}

country_event = { #The Final Collapse
	id = portugal_exile.14
	immediate = { log = "[GetDateText]: [Root.GetName]: event portugal_exile.14" }
	title = portugal_exile.14.t
	desc = portugal_exile.14.d
	picture = GFX_report_event_POR_entente

trigger = { is_in_faction = no }

	is_triggered_only = yes

	option = {
		name = portugal_exile.14.a
		if = {
			limit = {
				var:112.owner = { is_subject = yes }
			}
			var:112.owner:overlord = {
				country_event = { id = portugal_exile.17 days = 4 }
			}
		}
		else = {
			var:112.owner = {
				country_event = { id = portugal_exile.17 days = 4 }
			}
		}
	}
}

country_event = { #The Portuguese Government Collapses (MAF)
	id = portugal_exile.15
	immediate = { log = "[GetDateText]: [Root.GetName]: event portugal_exile.15" }
	title = portugal_exile.15.t
	desc = portugal_exile.15.d
	picture = GFX_report_event_POR_entente
	
	fire_only_once = yes

trigger = {
		PAF = {
			any_owned_state = {
				OR = {
					region = 3 #Congo
					region = 139 #South Africa
					region = 188 #East Africa
					region = 190 #Middle Africa
				}
			}
		}
	}

	
	is_triggered_only = yes

	option = {
		name = portugal_exile.15.a #Move troops into Angola and Mozambique
		PAF = {
			every_owned_state = {
				limit = {
					OR = {
						region = 3 #Congo
						region = 139 #South Africa
						region = 188 #East Africa
						region = 190 #Middle Africa
					}
				}
				ROOT = { transfer_state = PREV }
			}
			white_peace_with_ROOT = yes
		}
	}

	option = {
		name = portugal_exile.dont_seize
	trigger = { is_ai = no }
		hidden_effect = {
			PAF = {
				if = {
					limit = {
						any_owned_state = { is_core_of = ANG }
						NOT = { country_exists = ANG }
					}
					every_owned_state = {
						limit = { is_core_of = ANG }
						ANG = { transfer_state = PREV }
					}
				}
				if = {
					limit = {
						any_owned_state = { is_core_of = MZB }
						NOT = { country_exists = MZB }
					}
					every_owned_state = {
						limit = { is_core_of = MZB }
						MZB = { transfer_state = PREV }
					}
				}
			}
		}
	}
}

country_event = { #The Portuguese Government Collapses (NFA)
	id = portugal_exile.16
	immediate = { log = "[GetDateText]: [Root.GetName]: event portugal_exile.16" }
	title = portugal_exile.16.t
	desc = portugal_exile.16.d
	picture = GFX_report_event_POR_entente
	
	fire_only_once = yes

trigger = {
		PAF = {
			any_owned_state = {
				OR = {
					state = 296 #Portuguese Guinea
					state = 702 #Cape Verde
					state = 705 #Sao Tome
				}
			}
		}
	}

	
	is_triggered_only = yes

	option = {
		name = portugal_exile.16.a #Move troops into Guinea and Cape Verde
		set_country_flag = CVG_CONQ
		PAF = {
			every_owned_state = {
				limit = {
					OR = {
						state = 296 #Portuguese Guinea
						state = 702 #Cape Verde
						state = 705 #Sao Tome
					}
				}
				ROOT = { transfer_state = PREV }
			}
			white_peace_with_ROOT = yes
		}
	}

	option = {
		name = portugal_exile.dont_seize
	trigger = { is_ai = no }
		hidden_effect = {
			PAF = {
				if = {
					limit = {
						any_owned_state = { is_core_of = CVG }
						NOT = { country_exists = CVG }
					}
					every_owned_state = {
						limit = { is_core_of = CVG }
						CVG = { transfer_state = PREV }
					}
				}
			}
		}
	}
}

country_event = { #The Portuguese Government Collapses (CNT)
	id = portugal_exile.17
	immediate = { log = "[GetDateText]: [Root.GetName]: event portugal_exile.17" }
	title = portugal_exile.17.t
	desc = portugal_exile.17.d
	picture = GFX_report_event_POR_entente

	fire_only_once = yes
	
	is_triggered_only = yes

	option = {
		name = portugal_exile.17.a
		if = {
			limit = { tag = CNT }
			annex_country = {
				target = FROM
				transfer_troops = no
			}
			if = {
				limit = {
					NOT = { has_country_flag = POR_CONQ }
				}
				occupy_medium_country = yes
				set_country_flag = POR_CONQ
				add_state_claim = 112 #Lisbon
				add_state_claim = 179 #Beja
				add_state_claim = 180 #Porto
				add_state_claim = 181 #Guarda
				add_state_claim = 697 #Madeira
				add_state_claim = 698 #Azores
			}
		}
		else = {
			hidden_effect = {
				if = {
					limit = {
						any_country_with_original_tag = {
							original_tag_to_check = FROM
							is_subject_of = ROOT
						}
					}
					random_country = {
						limit = {
							original_tag = FROM
							is_subject_of = ROOT
						}
						FROM = {
							annex_country = {
								target = PREV
								transfer_troops = yes
							}
						}
					}
				}
			}
			if = {
				limit = { original_tag = FROM }
				FROM = {
					copy_government_of_ROOT = yes
					annex_country = {
						target = ROOT
						transfer_troops = yes
					}
					change_tag_from = ROOT
				}
			}
			else = {
				every_owned_state = {
					limit = { is_core_of = FROM }
					FROM = { transfer_state = PREV }
				}
				puppet = FROM
			}
		}
	}
}

country_event = { # Collapse of Portuguese Ultramar
	id = portugal_exile.18
	immediate = { log = "[GetDateText]: [Root.GetName]: event portugal_exile.18" }
	title = portugal_exile.18.t
	desc = portugal_exile.18.d
	picture = GFX_report_event_creek
	
	fire_only_once = yes
	
	mean_time_to_happen = {
		days = 60
	}

	trigger = {
		tag = PAF
		POR = { is_ai = yes }
		date > 1936.07.01
		NOT = {
			has_game_rule = {
				rule = PAF_survival
				option = PAF_SURVIVAL_LIVES
			}
		}
		OR = {
			has_stability < 0
			has_game_rule = {
				rule = PAF_survival
				option = PAF_SURVIVAL_DIES
			}
		}
		NOT = {
			has_war_with = MAF
			AND = {
				is_ai = yes
				has_war = yes
			}
		}
	}

	option = {
		name = portugal_exile.18.a
		news_event = {
			id = portugal_exile.13
			days = 1
		}
		hidden_effect = {
			every_unit_leader = { set_nationality = POR }
			transfer_navy = {
				target = POR
			}
			PAF_collapse = yes
			}
		}
	option = {
		name = portugal_exile.18.a
	trigger = {
			is_ai = yes
		}
		news_event = {
			id = portugal_exile.13
			days = 1
		}
		hidden_effect = {
			every_unit_leader = { set_nationality = POR }
			transfer_navy = {
				target = POR
			}
			PAF_collapse = yes
			}
		}
	option = {
		name = portugal_exile.18.a
	trigger = {
			is_ai = no
		}
		news_event = {
			id = portugal_exile.13
			days = 1
		}
		hidden_effect = {
			every_unit_leader = { set_nationality = POR }
			transfer_navy = {
				target = POR
			}
			PAF_collapse = yes
				POR = {
					change_tag_from = PAF
				}
			}
		}
	}

