﻿add_namespace = Afghanistan
add_namespace = AfghanistanNews
add_namespace = AfghanistanBorderWars

### Afghanistan civil war cleanup events ###

#Give the winner AFG cosmetic tag
country_event = {
	id = Afghanistan.0
	
	hidden = yes
	
	trigger = {
		OR = {
			AND = {
				tag = AFG
				NOT = {
					country_exists = TAL
				}
			}
			AND = {
				tag = TAL
				NOT = {
					country_exists = AFG
				}
			}
		}
		NOT = { has_global_flag = Afghanistan_Civil_War_Over }
	}
	
	mean_time_to_happen = {
		days = 2
	}
	
	immediate = {
		#Civil war is over
		set_global_flag = Afghanistan_Civil_War_Over
		#Clear core status
		409 = {
			remove_core_of = AFG
			remove_core_of = TAL
		}
		410 = {
			remove_core_of = AFG
			remove_core_of = TAL
		}
		411 = {
			remove_core_of = AFG
			remove_core_of = TAL
		}
		412 = {
			remove_core_of = AFG
			remove_core_of = TAL
		}
		414 = {
			remove_core_of = AFG
			remove_core_of = TAL
		}
		415 = {
			remove_core_of = AFG
			remove_core_of = TAL
		}
		#Make the winner Afghanistan
		drop_cosmetic_tag = yes
		if = {
			limit = {
				tag = TAL
			}
			set_cosmetic_tag = AFG
		}
		add_state_core = 409
		add_state_core = 410
		add_state_core = 411
		add_state_core = 412
		add_state_core = 414
		add_state_core = 415
		set_capital = 414
	}
	
	option = {
		name = Afghanistan.0.a
		hidden_effect = { news_event = { id = AfghanistanNews.1 hours = 6 } }
		log = "[GetDateText]: [This.GetName]: Afghanistan.0.a executed"
	}
}

#Recreate Afghanistan in case it has been annexed
country_event = {
	id = Afghanistan.1
	
	hidden = yes
	
	trigger = {
		NOT = {
			country_exists = AFG
			country_exists = TAL
		}
		NOT = { 414 = { is_core_of = AFG } }
	}
	
	mean_time_to_happen = {
		days = 2
	}
	
	immediate = {
		#Clear core status
		409 = {
			remove_core_of = AFG
			remove_core_of = TAL
		}
		410 = {
			remove_core_of = AFG
			remove_core_of = TAL
		}
		411 = {
			remove_core_of = AFG
			remove_core_of = TAL
		}
		412 = {
			remove_core_of = AFG
			remove_core_of = TAL
		}
		414 = {
			remove_core_of = AFG
			remove_core_of = TAL
		}
		415 = {
			remove_core_of = AFG
			remove_core_of = TAL
		}
		AFG = {
			add_state_core = 409
			add_state_core = 410
			add_state_core = 411
			add_state_core = 412
			add_state_core = 414
			add_state_core = 415
			set_capital = 414
		}
	}
	
	option = {
		name = Afghanistan.1.a
		log = "[GetDateText]: [This.GetName]: Afghanistan.1.a executed"
	}
}

#Death of Ahmad Shah Massoud  Neutral_conservatism
country_event = {

	id = Afghanistan.3
	title = Afghanistan.3.t
	desc = Afghanistan.3.d
	picture = GFX_ahmad_shah_massoud
	
	fire_only_once = yes
	
	trigger = {
		tag = AFG
		has_war_with = TAL
		USA = { NOT = { has_country_flag = Operation_enduring_freedom } }
		has_country_leader = { name = "Ahmed Shah Massoud" ruling_only = yes }
	}
	
	mean_time_to_happen = {
		days = 270
	}
	
	option = {
		name = Afghanistan.3.a
		log = "[GetDateText]: [This.GetName]: Afghanistan.3.a executed"
		ai_chance = { factor = 100 }
		random_list = {
			90 = {
				custom_effect_tooltip = TT_CURRENT_LEADER_DIES
				hidden_effect = {
					meta_effect = {
						text = {
							set_country_flag = [META_SET_RULING_PARTY]
						}
						META_SET_RULING_PARTY = "[meta_set_ruling_leader]"
					}
					set_leader = yes
				}
				hidden_effect = { news_event = { id = AfghanistanNews.6 hours = 6 } }
				set_country_flag = Massoud_dead
			}
			10 = {
			}
		}
	}
	
}

#US sets up a government
country_event = {

	id = Afghanistan.4
	title = Afghanistan.4.t
	desc = Afghanistan.4.d
	picture = GFX_bonn_agreement
	
	is_triggered_only = yes	
	
	option = {
		name = Afghanistan.4.a
		log = "[GetDateText]: [This.GetName]: Afghanistan.4.a executed"
		ai_chance = { factor = 100 }
		if = { 
			limit = { has_country_flag = AFG_new_administration_Karzai }	
			custom_effect_tooltip = TT_KARZAI_ADMINISTRATION
			set_politics = {
				ruling_party = democratic
				elections_allowed = yes
			}
			add_popularity = {
				ideology = democratic
				popularity = 0.25
			}
			effect_tooltip = {
				create_country_leader = {
					name = "Hamid Karzai"
					picture = "Hamid_Karzai.dds"
					ideology = conservatism
					traits = {
						western_Western_Autocracy
					}
				}
			}
			clear_array = ruling_party
			clear_array = gov_coalition_array
			add_to_array = { ruling_party = 0 } #Western autocracy
			for_each_loop = {
				array = ruling_party
				value = v
				multiply_variable = { party_pop_array^v = 1.5 }
			}
			add_popularity = {
				ideology = fascism
				popularity = 0.15
			}
			add_to_variable = { var = party_pop_array^11 value = 0.15 }
			add_popularity = {
				ideology = nationalist
				popularity = 0.05
			}
			add_to_variable = { var = party_pop_array^23 value = 0.05 }
		}
		if = { 
			limit = { has_country_flag = AFG_new_administration_Rabbani }
			custom_effect_tooltip = TT_RABBANI_ADMINISTRATION
			add_popularity = {
				ideology = neutrality
				popularity = 0.20
			}
			if = { 
				limit = {
					NOT = { has_country_leader = { name = "Burhanuddin Rabbani" ruling_only = yes } }
				}
				effect_tooltip = {
					create_country_leader = {
						name = "Burhanuddin Rabbani"
						picture = "Burhanuddin_Rabbani.dds"
						ideology = Nat_Populism
						traits = {
							neutrality_Neutral_Muslim_Brotherhood
						}
					}
				}
				hidden_effect = {
					meta_effect = {
						text = {
							set_country_flag = [META_SET_RULING_PARTY]
						}
						META_SET_RULING_PARTY = "[meta_set_ruling_leader]"
					}
					set_leader = yes
				}
			}	
			clear_array = ruling_party
			clear_array = gov_coalition_array
			add_to_array = { ruling_party = 12 } #Muslim Brotherhood
			for_each_loop = {
				array = ruling_party
				value = v
				multiply_variable = { party_pop_array^v = 1.5 }
			}
			add_popularity = {
				ideology = fascism
				popularity = 0.05
			}
			add_to_variable = { var = party_pop_array^11 value = 0.05 }
		}
		if = { 
			limit = { has_country_flag = AFG_new_administration_Massoud }
			custom_effect_tooltip = TT_RABBANI_ADMINISTRATION
			add_popularity = {
				ideology = neutrality
				popularity = 0.20
			}
			effect_tooltip = {
				create_country_leader = {
					name = "Ahmed Shah Massoud"
					picture = "Ahmad_Shah_Massoud.dds"
					expire = "2001.9.9"
					ideology = Neutral_Muslim_Brotherhood
					traits = {
						neutrality_Neutral_Muslim_Brotherhood
					}
				}
			}
			clear_array = ruling_party
			clear_array = gov_coalition_array
			add_to_array = { ruling_party = 12 } #Muslim Brotherhood
			for_each_loop = {
				array = ruling_party
				value = v
				multiply_variable = { party_pop_array^v = 1.5 }
			}
		}
		if = { 
			limit = { has_country_flag = AFG_new_administration_Zahir_Shah }
			custom_effect_tooltip = TT_SHAH_ADMINISTRATION
			clear_array = ruling_party
			clear_array = gov_coalition_array
			add_to_array = { ruling_party = 23 } #monarchist
			set_politics = {
				ruling_party = nationalist
				elections_allowed = no
			}
			add_popularity = {
				ideology = nationalist
				popularity = 0.15
			}
			effect_tooltip = {
				create_country_leader = {
					name = "Mohammed Zahir Shah"
					picture = "generic.dds"
					ideology = Monarchist
					traits = {
						nationalist_Monarchist
					}
				}
			}
			for_each_loop = {
				array = ruling_party
				value = v
				add_to_variable = { var = party_pop_array^v value = 0.15 }
			}
			add_popularity = {
				ideology = fascism
				popularity = 0.25
			}
			add_to_variable = { var = party_pop_array^11 value = 0.25 }
		}
	}
	
}

#Afghanistan wins border war
country_event = {

	id = AfghanistanBorderWars.1
	title = AfghanistanBorderWars.1.t
	desc = AfghanistanBorderWars.1.d
	
	is_triggered_only = yes
	
	immediate = {
		event_target:AFG_ATTACKER = {
			if = {
				limit = { has_country_flag = AFG_attacking_417 }
				transfer_state = 417
				clr_country_flag = AFG_attacking_417
			}
			if = {
				limit = { has_country_flag = AFG_attacking_418 }
				transfer_state = 418
				clr_country_flag = AFG_attacking_418
			}
			if = {
				limit = { has_country_flag = AFG_attacking_419 }
				transfer_state = 419
				clr_country_flag = AFG_attacking_419
			}
			if = {
				limit = { has_country_flag = AFG_attacking_594 }
				transfer_state = 594
				clr_country_flag = AFG_attacking_594
			}
			if = {
				limit = { has_country_flag = AFG_attacking_416 }
				transfer_state = 416
				clr_country_flag = AFG_attacking_416
			}
		}
	}
	
	option = {
		name = AfghanistanBorderWars.1.a
		trigger = { tag = event_target:AFG_ATTACKER }
		log = "[GetDateText]: [This.GetName]: AfghanistanBorderWars.1.a executed"
	}
	option = {
		name = AfghanistanBorderWars.1.b
		trigger = { tag = event_target:AFG_ATTACKER }
		log = "[GetDateText]: [This.GetName]: AfghanistanBorderWars.1.b executed"
		ai_chance = {
			factor = 20
		}
		relative_change_neg_8 = yes
		decrease_popularity_5 = yes
	}
	option = {
		name = AfghanistanBorderWars.1.c
		trigger = { tag = event_target:AFG_ATTACKER }
		log = "[GetDateText]: [This.GetName]: AfghanistanBorderWars.1.c executed"
		ai_chance = {
			factor = 80
		}
		declare_war_on = {
			target = event_target:AFG_ATTACKER
			type = annex_everything
		}
		random_country = {
			limit = {
				original_tag = PAK
				NOT = { tag = event_target:AFG_ATTACKER }
			}
			declare_war_on = {
				target = event_target:AFG_ATTACKER
				type = annex_everything
			}
		}
	}
}

#Afghanistan loses border war
country_event = {

	id = AfghanistanBorderWars.2
	title = AfghanistanBorderWars.2.t
	desc = AfghanistanBorderWars.2.d
	
	is_triggered_only = yes
	
	
	option = {
		name = AfghanistanBorderWars.2.a
		trigger = { tag = event_target:AFG_ATTACKER }
		log = "[GetDateText]: [This.GetName]: AfghanistanBorderWars.2.a executed"
	}
	option = {
		name = AfghanistanBorderWars.2.b
		trigger = { tag = event_target:AFG_ATTACKER }
		log = "[GetDateText]: [This.GetName]: AfghanistanBorderWars.2.b executed"
		if = {
			limit = { has_variable = AFG_fail_meter }
			add_to_variable = {
				var = AFG_fail_meter
				value = 1
			}
		}
		else = {
			set_variable = {
				var = AFG_fail_meter
				value = 1
			}
		}
		relative_change_neg_6 = yes
		decrease_popularity_5 = yes
	}
}

news_event = {

	id = AfghanistanNews.1
	title = AfghanistanNews.1.t
	desc = {
		text = AfghanistanNews.1.TAL.d
		trigger = { FROM = { original_tag = TAL } }
	}
	desc = {
		text = AfghanistanNews.1.AFG.d
		trigger = { FROM = { original_tag = AFG } }
	}
	picture = GFX_news_rise_of_taliban
	
	major = yes
	
	is_triggered_only = yes
	
	option = {
		name = AfghanistanNews.1.a
		log = "[GetDateText]: [This.GetName]: AfghanistanNews.1.a executed"
	}
	
}	

news_event = {

	id = AfghanistanNews.2
	title = AfghanistanNews.2.t
	desc = AfghanistanNews.2.d
	picture = GFX_news_afghanistan_pakistan
	
	major = yes
	
	is_triggered_only = yes
	
	option = {
		name = AfghanistanNews.2.a
		log = "[GetDateText]: [This.GetName]: AfghanistanNews.2.a executed"
	}
	
}		

news_event = {

	id = AfghanistanNews.3
	title = AfghanistanNews.3.t
	desc = AfghanistanNews.3.d
	picture = GFX_news_afghanistan_pakistan
	
	major = yes
	
	is_triggered_only = yes
	
	option = {
		name = AfghanistanNews.3.a
		log = "[GetDateText]: [This.GetName]: AfghanistanNews.3.a executed"
	}
	
}		

news_event = {

	id = AfghanistanNews.4
	title = AfghanistanNews.4.t
	desc = AfghanistanNews.4.d
	picture = GFX_news_afghanistan_pakistan
	
	major = yes
	
	is_triggered_only = yes
	
	option = {
		name = AfghanistanNews.4.a
		log = "[GetDateText]: [This.GetName]: AfghanistanNews.4.a executed"
	}
	
}		

news_event = {

	id = AfghanistanNews.5
	title = AfghanistanNews.5.t
	desc = AfghanistanNews.5.d
	picture = GFX_news_rise_of_taliban
	
	major = yes
	
	is_triggered_only = yes
	
	option = {
		name = AfghanistanNews.5.a
		log = "[GetDateText]: [This.GetName]: AfghanistanNews.5.a executed"
	}
	
}	

news_event = {

	id = AfghanistanNews.6
	title = AfghanistanNews.6.t
	desc = AfghanistanNews.6.d
	picture = GFX_news_ahmad_shah_massoud
	
	major = yes
	
	is_triggered_only = yes
	
	option = {
		name = AfghanistanNews.6.a
		log = "[GetDateText]: [This.GetName]: AfghanistanNews.6.a executed"
	}
	
}