﻿add_namespace = Somalia
add_namespace = SomaliaNews

### Somalia civil war cleanup events ###

#Give the winner SOM cosmetic tag
country_event = {
	id = Somalia.0

	hidden = yes

	trigger = {
		has_start_date > 2016.1.1
		OR = {
			AND = {
				tag = SOM
				NOT = {
					country_exists = SHB
				}
			}
			AND = {
				tag = SHB
				NOT = {
					country_exists = SOM
				}
			}
		}
		NOT = { has_global_flag = Somalia_Civil_War_Over }
	}

	mean_time_to_happen = {
		days = 2
	}

	immediate = {
		#Civil war is over
		set_global_flag = Somalia_Civil_War_Over
		#Clear core status
		240 = {
			remove_core_of = SOM
			remove_core_of = SHB
		}
		239 = {
			remove_core_of = SOM
			remove_core_of = SHB
		}
		928 = {
			remove_core_of = SOM
			remove_core_of = SHB
		}
		238 = {
			remove_core_of = SOM
			remove_core_of = SHB
		}
		237 = {
			remove_core_of = SOM
			remove_core_of = SHB
		}
		581 = {
			remove_core_of = SOM
			remove_core_of = SHB
		}
		584 = {
			remove_core_of = SOM
			remove_core_of = SHB
		}
		593 = {
			remove_core_of = SOM
			remove_core_of = SHB
		}
		208 = {
			remove_core_of = SOM
			remove_core_of = SHB
		}
		#Make the winner Somalia
		if = {
			limit = { tag = SHB	}
			set_cosmetic_tag = SOM
		}
		add_state_core = 240
		add_state_core = 239
		add_state_core = 238
		add_state_core = 237
		add_state_core = 581
		add_state_core = 584
		add_state_core = 593
		add_state_core = 208
		set_capital = 593
		#Mark who won
		if = {
			limit = { tag = SHB }
			set_country_flag = Somalia_Civil_War_Islamist_Victory
			news_event = { id = SomaliaNews.0 hours = 6 }
		}
		if = {
			limit = { tag = SOM }
			set_country_flag = Somalia_Civil_War_Government_Victory
			news_event = { id = SomaliaNews.1 hours = 6 }
		}
	}

	option = {
		name = Somalia.0.a
		log = "[GetDateText]: [This.GetName]: Somalia.0.a executed"
	}
}

#Recreate Somalia in case it has been annexed
country_event = {
	id = Somalia.1

	hidden = yes

	trigger = {
		NOT = {
			country_exists = SOM
			country_exists = SHB
		}
		NOT = { 593 = { is_core_of = SOM } }
	}

	mean_time_to_happen = {
		days = 2
	}

	immediate = {
		#Clear core status
		240 = {
			remove_core_of = SOM
			remove_core_of = SHB
		}
		239 = {
			remove_core_of = SOM
			remove_core_of = SHB
		}
		928 = {
			remove_core_of = SOM
			remove_core_of = SHB
		}
		238 = {
			remove_core_of = SOM
			remove_core_of = SHB
		}
		237 = {
			remove_core_of = SOM
			remove_core_of = SHB
		}
		581 = {
			remove_core_of = SOM
			remove_core_of = SHB
		}
		584 = {
			remove_core_of = SOM
			remove_core_of = SHB
		}
		593 = {
			remove_core_of = SOM
			remove_core_of = SHB
		}
		SOM = {
			add_state_core = 240
			add_state_core = 239
			add_state_core = 238
			add_state_core = 237
			add_state_core = 581
			add_state_core = 584
			add_state_core = 593
			set_capital = 593
		}
	}

	option = {
		name = Somalia.1.a
		log = "[GetDateText]: [This.GetName]: Somalia.1.a executed"
	}
}

#Give the winner SOM cosmetic tag - 2000 civil war version
country_event = {
	id = Somalia.2

	hidden = yes

	trigger = {
		has_start_date < 2016.1.1
		OR = {
			AND = {				#government victory
				tag = SOM
				NOT = { country_exists = SNA }
				OR = {
					NOT = { country_exists = SWS }
					NOT = { has_war_with = SWS }
				}
				OR = {
					NOT = { country_exists = JUB }
					NOT = { has_war_with = JUB }
				}
			}
			AND = {				#rebel victory
				tag = SNA
				NOT = { country_exists = SOM }
				OR = {
					NOT = { country_exists = SWS }
					NOT = { has_war_with = SWS }
				}
				OR = {
					NOT = { country_exists = JUB }
					NOT = { has_war_with = JUB }
				}
			}
			AND = {				#somalia is fucked
				OR = {
					tag = JUB
					tag = SWS
				}
				OR = {
					NOT = { country_exists = SOM }
					SOM = { is_subject_of = ROOT }
				}
				OR = {
					NOT = { country_exists = SNA }
					SNA = { is_subject_of = ROOT }
				}
			}
		}
		NOT = { has_global_flag = Somalia_Civil_War_Over }
	}

	mean_time_to_happen = {
		days = 2
	}

	immediate = {
		#Civil war is over
		set_global_flag = Somalia_Civil_War_Over
		#Clear core status
		240 = {
			remove_core_of = SOM
			remove_core_of = SNA
		}
		239 = {
			remove_core_of = SOM
			remove_core_of = SNA
		}
		928 = {
			remove_core_of = SOM
			remove_core_of = SNA
		}
		238 = {
			remove_core_of = SOM
			remove_core_of = SNA
		}
		237 = {
			remove_core_of = SOM
			remove_core_of = SNA
		}
		581 = {
			remove_core_of = SOM
			remove_core_of = SNA
		}
		584 = {
			remove_core_of = SOM
			remove_core_of = SNA
		}
		593 = {
			remove_core_of = SOM
			remove_core_of = SNA
		}
		#Make the winner Somalia
		if = {
			limit = { tag = SNA	}
			set_cosmetic_tag = SOM
		}
		if = {
			limit = {
				OR = {
					tag = SNA
					tag = SOM
				}
			}
			add_state_core = 240
			add_state_core = 239
			add_state_core = 238
			add_state_core = 237
			add_state_core = 581
			add_state_core = 584
			add_state_core = 593
			set_capital = 593
		}
		else = {
			SOM = {
				add_state_core = 240
				add_state_core = 239
				add_state_core = 238
				add_state_core = 237
				add_state_core = 581
				add_state_core = 584
				add_state_core = 593
				set_capital = 593
			}
		}
		news_event = { id = SomaliaNews.2 hours = 6 }
	}

	option = {
		name = Somalia.2.a
		log = "[GetDateText]: [This.GetName]: Somalia.2.a executed"
	}
}

#Al-Shabaab victory
news_event = {

	id = SomaliaNews.0
	title = SomaliaNews.0.t
	desc = SomaliaNews.0.d

	picture = GFX_news_somalia_civil_war_jihadists

	major = yes

	is_triggered_only = yes

	option = {
		name = SomaliaNews.0.a
		log = "[GetDateText]: [This.GetName]: SomaliaNews.0.a executed"
		trigger = {	NOT = { has_government = fascism } }
		ai_chance = { factor = 100 }
	}
	option = {
		name = SomaliaNews.0.b
		log = "[GetDateText]: [This.GetName]: SomaliaNews.0.b executed"
		trigger = {	has_government = fascism }
		ai_chance = { factor = 100 }
	}

}

#Government victory
news_event = {

	id = SomaliaNews.1
	title = SomaliaNews.1.t
	desc = SomaliaNews.1.d

	picture = GFX_news_somalia_civil_war

	major = yes

	is_triggered_only = yes

	option = {
		name = SomaliaNews.1.a
		log = "[GetDateText]: [This.GetName]: SomaliaNews.1.a executed"
		trigger = {	NOT = { has_government = fascism } }
		ai_chance = { factor = 100 }
	}
	option = {
		name = SomaliaNews.1.b
		log = "[GetDateText]: [This.GetName]: SomaliaNews.1.b executed"
		trigger = {	has_government = fascism }
		ai_chance = { factor = 100 }
	}

}

#Government victory
news_event = {

	id = SomaliaNews.2
	title = SomaliaNews.2.t
	desc = {
		text = SomaliaNews.2.SOM.d
		trigger = { FROM = { original_tag = SOM } }
	}
	desc = {
		text = SomaliaNews.2.SNA.d
		trigger = { FROM = { original_tag = SNA } }
	}
	desc = {
		text = SomaliaNews.2.Separatist.d
		trigger = {
			FROM = {
				OR = {
					original_tag = SWS
					original_tag = JUB
				}
			}
		}
	}

	picture = GFX_news_somalia_civil_war

	major = yes

	is_triggered_only = yes

	option = {
		name = SomaliaNews.2.a
		log = "[GetDateText]: [This.GetName]: SomaliaNews.2.a executed"
		ai_chance = { factor = 100 }
	}

}
