########################################
# Events for Kilwa
#
# written by Henrik Lohmander
########################################

namespace = flavor_zan
normal_or_historical_nations = yes

# Shirazi Islam and the Patricians of Kilwa
country_event = {
	id = flavor_zan.1
	title = flavor_zan.1.t
	desc = flavor_zan.1.d
	picture = RELIGION_eventPicture

	fire_only_once = yes

	trigger = {
		tag = ZAN
		religion = sunni
		NOT = { piety = -0.05 }
		NOT = { is_year = 1480 }
	}
	
	mean_time_to_happen = {
		months = 108
	}
	
	option = {
		name = flavor_zan.1.a	#We must follow the ways of our ancestors.
		ai_chance = { factor = 1 }
		set_country_flag = zan_shirazi_islam_confirmed
		add_legitimacy = 30
		add_piety = -0.25
		every_known_country = {
			limit = {
				num_of_ports = 1
				religion_group = muslim
				NOT = {
					tag = PTE
					tag = MLI
					tag = MBA
					tag = SFA
				}
				NOT = { capital_scope = { region = malaya_region } }
				NOT = { capital_scope = { region = moluccas_region } }
				NOT = { capital_scope = { region = indonesia_region } }
			}
			add_opinion = { who = ZAN modifier = zan_shirazi_islam }
		}
	}
	option = {
		name = flavor_zan.1.b #Let us purge our kingdom of pagan beliefs and magical ceremonies.
		ai_chance = { factor = 0 }
		add_legitimacy = -30
		add_piety = 0.15
		add_country_modifier = {
			name = zan_religious_unrest
			duration = 3650
		}
		every_known_country = {
			limit = {
				num_of_ports = 1
				religion_group = muslim
				NOT = {
					tag = PTE
					tag = MLI
					tag = MBA
					tag = SFA
				}
				NOT = { capital_scope = { region = malaya_region } }
				NOT = { capital_scope = { region = moluccas_region } }
				NOT = { capital_scope = { region = indonesia_region } }
			}
			add_opinion = { who = ZAN modifier = zan_religious_orthodoxy }
		}
		set_country_flag = zan_moving_away_from_shirazi_islam
	}
}

# The Kilwa Chronicle
country_event = {
	id = flavor_zan.2
	title = flavor_zan.2.t
	desc = flavor_zan.2.d
	picture = BIG_BOOK_eventPicture

	fire_only_once = yes

	trigger = {
		tag = ZAN
		is_year = 1500
		NOT = { is_year = 1520 }
		religion = sunni
		has_country_flag = zan_shirazi_islam_confirmed
	}
	
	mean_time_to_happen = {
		months = 60
	}
	
	option = {
		name = flavor_zan.2.a	#Let us create such a Chronicle.
		ai_chance = { factor = 1 }
		if = {
			limit = {
				NOT = { has_completed_all_reforms_trigger = yes }
			}
			add_reform_progress_small_effect = yes
		}
		add_years_of_income = -0.1
		add_legitimacy = 5
		add_prestige = 5
		add_country_modifier = {
			name = zan_kilwa_chronicle
			duration = -1
		}
	}
	option = {
		name = flavor_zan.2.b #We have more important matters to attend.
		ai_chance = { factor = 0 }
		
	}
}

# Abandoning Shirazi traditions.
# Never really done in Kilwa but did happen to some extent in other Swahili states and would be a possible result of changing policies.
country_event = {
	id = flavor_zan.3
	title = flavor_zan.3.t
	desc = flavor_zan.3.d
	picture = RELIGIOUS_TURMOIL_eventPicture

	fire_only_once = yes

	trigger = {
		tag = ZAN
		is_year = 1570
		NOT = { is_year = 1590 }
		religion = sunni
		has_country_flag = zan_moving_away_from_shirazi_islam
	}
	
	mean_time_to_happen = {
		months = 60
	}
	
	option = {
		name = flavor_zan.3.a #Let's not go overboard.
		ai_chance = { factor = 1 }
		add_stability_or_adm_power = yes
	}
	option = {
		name = flavor_zan.3.b	#Let us embrace twelver Shiism.
		ai_chance = { factor = 0 }
		add_stability = -3
		add_legitimacy = -25
		change_religion = shiite
		add_country_modifier = {
			name = zan_religious_unrest
			duration = 3650
		}
		every_known_country = {
			limit = {
				num_of_ports = 1
				religion = shiite
			}
			add_opinion = { who = ZAN modifier = zan_religious_orthodoxy }
		}
	}
	option = {
		name = flavor_zan.3.c #Let us align with the Ibadis of Oman.
		ai_chance = { factor = 0 }
		add_stability = -3
		add_legitimacy = -25
		change_religion = ibadi
		add_country_modifier = {
			name = zan_religious_unrest
			duration = 3650
		}
		every_known_country = {
			limit = {
				num_of_ports = 1
				religion = ibadi
			}
			add_opinion = { who = ZAN modifier = zan_religious_orthodoxy }
		}
	}
	option = {
		name = flavor_zan.3.od #We should invite Sunni scholars to help reform our kingdom.
		ai_chance = { factor = 0 }
		add_piety = 0.25
		add_country_modifier = {
			name = zan_religious_unrest
			duration = 3650
		}
		every_known_country = {
			limit = {
				num_of_ports = 1
				religion = sunni
				NOT = {
					tag = PTE
					tag = MLI
					tag = MBA
					tag = SFA
				}
				NOT = { capital_scope = { region = malaya_region } }
				NOT = { capital_scope = { region = moluccas_region } }
				NOT = { capital_scope = { region = indonesia_region } }
			}
			add_opinion = { who = ZAN modifier = zan_religious_orthodoxy }
		}
		add_legitimacy = -25
		add_stability = -1
	}
}

#Arrival of the Zimba
country_event = {
	id = flavor_zan.4
	title = flavor_zan.4.t
	desc = flavor_zan.4.d
	picture = WOUNDED_SOLDIERS_eventPicture

	fire_only_once = yes

	trigger = {
		tag = ZAN
		is_year = 1585
		NOT = { is_year = 1610 }
		owns = 1196 #Kilwa
	}
	
	mean_time_to_happen = {
		months = 75
	}
	
	option = {
		name = flavor_zan.4.a #A day of sorrow.
		1196 = {
			add_province_modifier = {
				name = zan_sacked_by_the_zimba
				duration = 3650
			}
		}
	}
	option = {
		name = flavor_zan.4.b #Use all resources to rebuild and restore Kilwa
		trigger = {
			years_of_income = 0.3
		}
		add_years_of_income = -0.3
		1196 = {
			add_province_modifier = {
				name = zan_sacked_by_the_zimba
				duration = 1825
			}
		}
	}
}

#Events relating to the political instability of Kilwa in the 15th century.
#Coup of Suleiman and Muhammad al-Mazlum.
country_event = {
	id = flavor_zan.5
	title = flavor_zan.5.t
	desc = flavor_zan.5.d
	picture = DEATH_OF_HEIR_eventPicture

	fire_only_once = yes
	is_triggered_only = yes

	trigger = {
		tag = ZAN #Will trigger upon first ruler change.
		OR = {
			government = monarchy
			government = tribal
		}
		has_government_attribute = heir
	}
	
	option = {
		name = flavor_zan.5.a #Suleiman takes the throne.
		ai_chance = { factor = 1 }
		set_country_flag = zan_plotting_viziers
		add_stability = -2
		define_ruler = {
			name = "000000I&"
			dynasty = "000000"
			claim = 80
		}
		if = {
			limit = {
				has_states_general_mechanic = yes
			}
			change_statists_vs_orangists = 1
		}
		#add_legitimacy = -20
		set_ruler_flag = zan_muhammad_and_suleiman
		hidden_effect = {
			define_heir = {
				claim = 75
				dynasty = al-Mazlum
				name = "00000"
				age = 45
			}
		}
	}
	option = {
		name = flavor_zan.5.b #Muhammad al-Muzlum takes the throne.
		ai_chance = { factor = 0 }
		set_country_flag = zan_plotting_viziers
		add_stability = -2
		define_ruler = {
			name = "00000"
			dynasty = "al-Mazlum"
			claim = 80
		}
		if = {
			limit = {
				has_states_general_mechanic = yes
			}
			change_statists_vs_orangists = 1
		}
		#add_legitimacy = -20
		set_ruler_flag = zan_muhammad_and_suleiman
		hidden_effect = {
			define_heir = {
				claim = 75
				dynasty = "000000"
				name = "000000I&"
				age = 50
			}
		}
	}
	option = {
		name = flavor_zan.5.c #XXXX is our rightful ruler!
		ai_chance = { factor = 0 }
		set_country_flag = zan_plotting_viziers
		add_stability = -1
		capital_scope = {
			spawn_rebels = {
				type = pretender_rebels
				leader = "Muhammad"
				leader_dynasty = "al-Mazlum"
				size = 2
			}
		}
	}
}


#Unpopular coupmaker
country_event = {
	id = flavor_zan.6
	title = flavor_zan.6.t
	desc = flavor_zan.6.d
	picture = ANGRY_MOB_eventPicture

	fire_only_once = yes

	trigger = {
		tag = ZAN
		has_country_flag = zan_plotting_viziers
		has_ruler_flag = zan_muhammad_and_suleiman
		government = monarchy
	}
	
	mean_time_to_happen = {
		months = 30
	}
	
	option = {
		trigger = { has_heir = yes }
		name = flavor_zan.6.a #Abdicate in favor of heir
		kill_ruler = yes
	}
	option = {
		name = flavor_zan.6.b #Our ruler has won the right to this throne.
		add_stability = -1
	}
}

#Plotting Viziers
#A general event relating to the great number of coups in the politically unstable period between 1442 and the end of the 15th century.
country_event = {
	id = flavor_zan.7
	title = flavor_zan.7.t
	desc = flavor_zan.7.d
	picture = SPY_eventPicture

	trigger = {
		tag = ZAN
		has_country_flag = zan_plotting_viziers
		government = monarchy
		is_tribal = yes	#Goes away when you manage to reform.
		NOT = { is_year = 1510 } #Or if you manage to ride out the period of instability.
		NOT = { legitimacy = 70 }
		NOT = { stability = 2 }
		NOT = { has_ruler_flag = zan_muhammad_and_suleiman }
		NOT = { has_ruler_flag = vizier_plotted }
	}
	
	mean_time_to_happen = {
		months = 75
	}
	
	option = {
		name = flavor_zan.7.a #Ok.
		set_ruler_flag = vizier_plotted
		random_owned_province = {
			spawn_rebels = {
				type = pretender_rebels
				size = 2
			}
		}
	}
}

########################################
# More events for Kilwa
#
# scripted by Ogulcan Yildirim
# Localization written by lvaro Sanz
########################################

#Embassy Events
#Meet Persian origin
country_event = {
	id = flavor_zan.8
	title = flavor_zan.8.t
	desc = flavor_zan.8.desc
	picture = DIPLOMACY_eventPicture
	
	is_triggered_only = yes
	
	option = {	#Send an ambassador to Persia
		name = flavor_zan.8.a
		custom_tooltip = flavor_zan.8.a.tt
		hidden_effect = {
			2218 = {
				owner = {
					country_event = {
						id = flavor_zan.9
					}
				}
			}
		}
		ai_chance = {
			factor = 1
			modifier = {
				factor = 0
				2218 = {
					owner = {
						NOT = { tag = PER }
						NOT = { was_tag = PER }
						NOT = { culture_group = iranian }
					}
				}
			}
		}
	}
	
	option = {	#It's not really worth it
		name = flavor_zan.8.b
		add_prestige = 20
		add_legitimacy = 20
		ai_chance = {
			factor = 1
			modifier = {
				factor = 0
				2218 = {
					owner = {
						OR = {
							tag = PER
							was_tag = PER
							culture_group = iranian
						}
					}
				}
			}
		}
	}
}

#A [From.GetAdjective] ambassador meets us
country_event = {
	id = flavor_zan.9
	title = flavor_zan.9.t
	desc = flavor_zan.9.desc
	picture = DIPLOMACY_eventPicture
	
	is_triggered_only = yes
	
	option = {	#Welcome him!
		name = flavor_zan.9.a
		FROM = {
			country_event = {
				id = flavor_zan.10
			}
		}
		2218 = {
			add_province_modifier = {
				name = zan_kilwan_embassy
				duration = -1
				desc = zan_embassy_desc
			}
		}
		reverse_add_opinion = {
			who = FROM
			modifier = zan_has_embassy
		}
		hidden_effect = {
			save_global_event_target_as = kilwan_embassy_holder
		}
		ai_chance = {
			factor = 1
			modifier = {
				factor = 0
				NOT = { tag = PER }
				NOT = { was_tag = PER }
				NOT = { culture_group = iranian }
			}
		}
	}
	
	option = {	#We have no need for diplomacy with Kilwa
		name = flavor_zan.9.b
		FROM = {
			country_event = {
				id = flavor_zan.11
			}
		}
		ai_chance = {
			factor = 1
			modifier = {
				factor = 0
				OR = {
					tag = PER
					was_tag = PER
					culture_group = iranian
				}
			}
		}
	}
}

#Persia welcomes our ambassador + embassy
country_event = {
	id = flavor_zan.10
	title = flavor_zan.10.t
	desc = flavor_zan.10.desc
	picture = DIPLOMACY_eventPicture
	
	is_triggered_only = yes
	
	option = {
		name = flavor_zan.10.a
		capital_scope = {
			add_province_modifier = {
				name = zan_persian_embassy
				duration = -1
				desc = zan_embassy_desc
			}
		}
		reverse_add_opinion = {
			who = FROM
			modifier = zan_has_embassy
		}
		hidden_effect = {
			set_global_flag = zan_persia_embassy
			save_global_event_target_as = persian_embassy_holder
		}
		ai_chance = {
			factor = 1
		}
	}
}

#Persia expelled the ambassador
country_event = {
	id = flavor_zan.11
	title = flavor_zan.11.t
	desc = flavor_zan.11.desc
	picture = ACCUSATION_eventPicture
	
	is_triggered_only = yes
	
	option = {
		name = flavor_zan.11.a
		add_opinion = {
			who = FROM
			modifier = zan_declined_embassy
		}
		ai_chance = {
			factor = 1
		}
	}
}

#Embassy gets destroyed
country_event = {
	id = flavor_zan.12
	title = flavor_zan.12.t
	desc = flavor_zan.12.desc
	picture = COUNTRY_COLLAPSE_eventPicture

	trigger = {
		has_global_flag = zan_persia_embassy
		is_or_was_tag = {
			tag = ZAN
		}
		OR = {
			all_owned_province = { NOT = { has_province_modifier = zan_persian_embassy } }
			2218 = { NOT = { has_province_modifier = zan_kilwan_embassy } }
		}
	}

	immediate = {
		hidden_effect = {
			clr_global_flag = zan_persia_embassy
			clear_global_event_target = persian_embassy_holder
			clear_global_event_target = kilwan_embassy_holder
		}
	}

	mean_time_to_happen = {
		days = 1
	}

	option = {
		name = flavor_zan.12.a
		trigger = {
			all_owned_province = { NOT = { has_province_modifier = zan_persian_embassy } }
		}
		if = {
			limit = {
				2218 = { has_province_modifier = zan_kilwan_embassy }
			}
			2218 = {
				owner = {
					country_event = {
						id = flavor_zan.13
					}
				}
			}
		}
		random_country = {
			limit = {
				has_opinion_modifier = {
					who = ROOT
					modifier = zan_has_embassy
				}
			}
			remove_opinion = {
				who = ROOT
				modifier = zan_has_embassy
			}
		}

		ai_chance = {
			factor = 1
		}
	}

	option = {
		name = flavor_zan.12.b
		trigger = {
			2218 = { NOT = { has_province_modifier = zan_kilwan_embassy } }
		}
		random_owned_province = {
			limit = {
				has_province_modifier = zan_persian_embassy
			}
			remove_province_modifier = zan_persian_embassy
		}
		random_country = {
			limit = {
				has_opinion_modifier = {
					who = ROOT
					modifier = zan_has_embassy
				}
			}
			country_event = {
				id = flavor_zan.14
			}
		}

		ai_chance = {
			factor = 1
		}
	}
}

#Kilwa lost the Persian embassy!
country_event = {
	id = flavor_zan.13
	title = flavor_zan.13.t
	desc = flavor_zan.13.desc
	picture = COUNTRY_COLLAPSE_eventPicture
	
	is_triggered_only = yes
	
	option = {
		name = flavor_zan.13.a
		2218 = {
			remove_province_modifier = zan_kilwan_embassy
		}
		FROM = {
			remove_opinion = {
				who = ROOT
				modifier = zan_has_embassy
			}
		}
		ai_chance = {
			factor = 1
		}
	}
}

#Kilwa disbanded the Persian embassy!
country_event = {
	id = flavor_zan.14
	title = flavor_zan.14.t
	desc = flavor_zan.14.desc
	picture = COUNTRY_COLLAPSE_eventPicture
	
	is_triggered_only = yes
	
	option = {
		name = flavor_zan.14.a
		remove_opinion = {
			who = FROM
			modifier = zan_has_embassy
		}
		reverse_remove_opinion = {
			who = ROOT
			modifier = zan_has_embassy
		}
		ai_chance = {
			factor = 1
		}
	}
}

#Merchants visit the other country
country_event = {
	id = flavor_zan.15
	title = flavor_zan.15.t
	desc = flavor_zan.15.desc
	picture = MERCHANTS_TALKING_eventPicture

	trigger = {
		has_global_flag = zan_persia_embassy
		any_owned_province = {
			OR = {
				has_province_modifier = zan_persian_embassy
				has_province_modifier = zan_kilwan_embassy
			}
		}
		OR = {
			NOT = { has_country_flag = had_embassy_event }
			had_country_flag = {
				flag = had_embassy_event
				days = 3650
			}
		}
	}

	mean_time_to_happen = {
		months = 60
	}

	immediate = {
		hidden_effect = {
			clr_country_flag = had_embassy_event
			set_country_flag = had_embassy_event
		}
	}

	option = {
		name = flavor_zan.15.a
		add_years_of_income = 0.25
		ai_chance = {
			factor = 1
		}
	}
}

#Knowledge sharing
country_event = {
	id = flavor_zan.16
	title = flavor_zan.16.t
	desc = flavor_zan.16.desc
	picture = CULTURE_eventPicture

	trigger = {
		has_global_flag = zan_persia_embassy
		any_owned_province = {
			OR = {
				has_province_modifier = zan_persian_embassy
				has_province_modifier = zan_kilwan_embassy
			}
		}
		OR = {
			NOT = { has_country_flag = had_embassy_event }
			had_country_flag = {
				flag = had_embassy_event
				days = 3650
			}
		}
	}

	mean_time_to_happen = {
		months = 60
	}

	immediate = {
		hidden_effect = {
			clr_country_flag = had_embassy_event
			set_country_flag = had_embassy_event
		}
	}

	option = {
		name = flavor_zan.16.a
		random_list = {
			33 = { add_adm_power = 50 }
			33 = { add_dip_power = 50 }
			33 = { add_mil_power = 50 }
			1 = { add_adm_power = 50 add_dip_power = 50 add_mil_power = 50 }
		}
		ai_chance = {
			factor = 1
		}
	}
}

#Religious Interactions
country_event = {
	id = flavor_zan.17
	title = flavor_zan.17.t
	desc = flavor_zan.17.desc
	picture = MOSQUE_eventPicture

	trigger = {
		has_global_flag = zan_persia_embassy
		any_owned_province = {
			OR = {
				has_province_modifier = zan_persian_embassy
				has_province_modifier = zan_kilwan_embassy
			}
		}
		OR = {
			NOT = { has_country_flag = had_embassy_event }
			had_country_flag = {
				flag = had_embassy_event
				days = 3650
			}
		}
	}

	mean_time_to_happen = {
		months = 60
	}

	immediate = {
		hidden_effect = {
			clr_country_flag = had_embassy_event
			set_country_flag = had_embassy_event
		}
	}

	option = {
		name = flavor_zan.17.a
		add_stability_or_adm_power = yes
		ai_chance = {
			factor = 1
		}
	}
}

#Kilwa can convert to Persia's religion
country_event = {
	id = flavor_zan.18
	title = flavor_zan.18.t
	desc = flavor_zan.18.desc
	picture = MOSQUE_eventPicture
	fire_only_once = yes

	trigger = {
		has_global_flag = zan_persia_embassy
		any_owned_province = {
			has_province_modifier = zan_persian_embassy
		}
		2218 = {
			owner = {
				NOT = { religion = ROOT }
			}
		}
		OR = {
			NOT = { has_country_flag = had_embassy_event }
			had_country_flag = {
				flag = had_embassy_event
				days = 3650
			}
		}
	}

	mean_time_to_happen = {
		months = 60
	}

	immediate = {
		hidden_effect = {
			clr_country_flag = had_embassy_event
			set_country_flag = had_embassy_event
			2218 = {
				owner = {
					save_event_target_as = zan_persia
				}
			}
		}
	}

	option = {	#Change religion to Persia
		name = flavor_zan.18.a
		change_religion = event_target:zan_persia

		ai_chance = {
			factor = 0
		}
	}

	option = {	#Not really worth it
		name = flavor_zan.18.b
		add_piety = 0.05

		ai_chance = {
			factor = 1
		}
	}
}

#Kilwa gets claims on Persia due to Shirazi's connection
country_event = {
	id = flavor_zan.19
	title = flavor_zan.19.t
	desc = flavor_zan.19.desc
	picture = SONGHAI_eventPicture
	fire_only_once = yes

	trigger = {
		has_global_flag = zan_persia_embassy
		any_owned_province = {
			has_province_modifier = zan_persian_embassy
		}
		2218 = {
			owner = {
				NOT = { religion = ROOT }
			}
		}
		OR = {
			NOT = { has_country_flag = had_embassy_event }
			had_country_flag = {
				flag = had_embassy_event
				days = 3650
			}
		}
	}

	mean_time_to_happen = {
		months = 1200
	}

	immediate = {
		hidden_effect = {
			clr_country_flag = had_embassy_event
			set_country_flag = had_embassy_event
		}
	}

	option = {	#We must pressure the claims of our origins!
		name = flavor_zan.19.a
		random_owned_province = {
			limit = {
				has_province_modifier = zan_persian_embassy
			}
			remove_province_modifier = zan_persian_embassy
		}
		persia_region = {
			add_claim = ROOT
		}

		ai_chance = {
			factor = 0
		}
	}

	option = {	#Not really worth it
		name = flavor_zan.19.b
		add_prestige = 25

		ai_chance = {
			factor = 1
		}
	}
}

###

#Mogadishu admits defeat
country_event = {
	id = flavor_zan.20
	title = flavor_zan.20.t
	desc = flavor_zan.20.desc
	picture = CONQUEST_eventPicture
	
	is_triggered_only = yes
	
	option = {
		name = flavor_zan.20.a
		1196 = {
			if = {
				limit = { NOT = { province_has_center_of_trade_of_level = 2 } }
				add_center_of_trade_level = 1
			}
			else = {
				add_base_production = 3
			}
			add_prosperity = 100
		}
		1205 = {
			if = {
				limit = { province_has_center_of_trade_of_level = 2 }
				add_center_of_trade_level = -1
			}
			else = {
				add_base_production = -2
			}
		}
		add_treasury = 400

		ai_chance = {
			factor = 1
		}
	}
}

#New maps
country_event = {
	id = flavor_zan.21
	title = flavor_zan.21.t
	desc = flavor_zan.21.desc
	picture = MERCHANTS_TALKING_eventPicture
	
	is_triggered_only = yes
	
	option = {
		name = flavor_zan.21.a
		custom_tooltip = flavor_zim.8.a.tt
		hidden_effect = {
			discover_province = 524
			discover_province = 684
			discover_province = 584
			bay_of_bengal_area = { discover_country = ROOT }
			andaman_sea_area = { discover_country = ROOT }
			south_china_sea_area = { discover_country = ROOT }
			east_china_sea_area = { discover_country = ROOT }
		}

		ai_chance = {
			factor = 1
		}
	}
}