###########################################
# Flavor Events for Morocco
#
# Scripted by Henrik Lohmander
###########################################

namespace = flavor_mor
normal_or_historical_nations = yes

#Crisis of the Maghreb
country_event = {
	id = flavor_mor.1
	title = flavor_mor.1.t
	desc = flavor_mor.1.d
	picture = FAMINE_eventPicture
	
	fire_only_once = yes
	
	trigger = {
		tag = MOR
		NOT = { is_year = 1450 }
	}
	
	mean_time_to_happen = {
		months = 3
	}

	option = {
		name = flavor_mor.1.a #Let them try! We shall rise again!
		add_country_modifier = {
			name = "mor_crisis"
			duration = 1825
		}
		every_known_country = {
			limit = {
				capital_scope = {
					region = maghreb_region
				}
			}
			add_country_modifier = {
				name = "mor_crisis"
				duration = 1825
			}
			country_event = { id = flavor_mor.11 }
		}
	}
}

#Moorish Refugees
country_event = {
	id = flavor_mor.2
	title = flavor_mor.2.t
	desc = flavor_mor.2.d
	picture = HARBOUR_eventPicture
	
	fire_only_once = yes
	
	trigger = {
		tag = MOR
		any_known_country = { has_country_flag = end_of_granada }
	}
	
	mean_time_to_happen = {
		months = 48
	}
	
	option = {
		name = flavor_mor.2.a #We welcome you with open arms
		add_country_modifier = {
			name = "mor_andalucian_moors"
			duration = 3650
		}
	}
}

#Muhammad al-Jazuli and the Dala'il al-Khayrat
country_event = {
	id = flavor_mor.3
	title = flavor_mor.3.t
	desc = flavor_mor.3.d
	picture = BIG_BOOK_eventPicture
	
	fire_only_once = yes
	
	trigger = {
		tag = MOR
		NOT = { is_year = 1465 }
	}
	
	mean_time_to_happen = {
		months = 63
	}
	
	option = {
		name = flavor_mor.3.a #Ok
		add_piety = -0.25
		add_prestige = 10
	}
}

#Idrisid Cult of Fez
country_event = {
	id = flavor_mor.4
	title = flavor_mor.4.t
	desc = flavor_mor.4.d
	picture = RELIGIOUS_CONVERSION_eventPicture
	
	fire_only_once = yes
	
	trigger = {
		tag = MOR
		NOT = { is_year = 1500 }
	}
	
	mean_time_to_happen = {
		months = 168
	}
	
	option = {
		name = flavor_mor.4.a #Ok
		add_piety = -0.25
		add_country_modifier = {
			name = "mor_idrisid_cult_soaring"
			duration = 3650
		}
	}
	
	option = {
		name = flavor_mor.4.b #Ok
		add_piety = 0.1
	}
}

#The Wattasid Viziers - Foreboding
country_event = {
	id = flavor_mor.5
	title = flavor_mor.5.t
	desc = flavor_mor.5.d
	picture = KING_SICK_IN_BED_eventPicture
	
	fire_only_once = yes
	
	trigger = {
		tag = MOR
		NOT = { is_year = 1455 } #Died in 1448
	}
	
	mean_time_to_happen = {
		months = 33
	}
	
	option = {
		name = flavor_mor.5.a #A great man has passed away
		add_piety = -0.05
		set_country_flag = mor_death_of_yahya
	}
	
}

#A Wattasid Conspiracy?
country_event = {
	id = flavor_mor.6
	title = flavor_mor.6.t
	desc = flavor_mor.6.d
	picture = ACCUSATION_eventPicture
	
	fire_only_once = yes
	
	trigger = {
		tag = MOR
		has_country_flag = mor_death_of_yahya
		NOT = { is_year = 1490 }
	}
	
	mean_time_to_happen = {
		months = 126
	}
	
	option = {
		name = flavor_mor.6.a #Kill them all!
		ai_chance = { factor = 1 }
		add_stability = -1
		country_event = { id = flavor_mor.7 days = 30 }
	}
	
	option = {
		name = flavor_mor.6.b #They remain our trusted advisors.
		ai_chance = { factor = 0 }
		set_country_flag = mor_wattasid_power
	}
	
}

#Wattasid Revolt
country_event = {
	id = flavor_mor.7
	title = flavor_mor.7.t
	desc = flavor_mor.7.d
	picture = CIVIL_WAR_eventPicture
	
	fire_only_once = yes
	is_triggered_only = yes
	
	immediate = {
		set_country_flag = wattasid_resolution
	}
	
	option = {
		name = flavor_mor.7.a
		random_owned_province = {
			limit = {
				is_capital = no
			}
			spawn_rebels = {
				type = pretender_rebels
				size = 3
				culture = berber
				religion = sunni
				leader = "Muhammad"
				leader_dynasty = "ibn Yahya Wattasid"
			}
		}
	}
	
}

#Wattasid Ultimatum
country_event = {
	id = flavor_mor.8
	title = flavor_mor.8.t
	desc = flavor_mor.8.d
	picture = CIVIL_WAR_eventPicture
	
	fire_only_once = yes
	
	trigger = {
		tag = MOR
		has_country_flag = mor_wattasid_power
	}
	
	mean_time_to_happen = {
		months = 30
	}
	
	immediate = {
		set_country_flag = wattasid_resolution
	}
	
	option = {
		name = flavor_mor.8.a #Abdicate
		ai_chance = { factor = 50 }
		add_stability = -2
		define_ruler = {
			name = "00000 I"
			dynasty = "Wattasid"
			culture = berber
		}
		if = {
			limit = {
				has_states_general_mechanic = yes
			}
			change_statists_vs_orangists = 1
		}
		if = {
			limit = {
				has_heir = yes
			}
			kill_heir = { allow_new_heir = no }
		}
	}
	
	option = {
		name = flavor_mor.8.b #This is my Throne!
		ai_chance = { factor = 50 }
		random_owned_province = {
			limit = {
				is_capital = no
			}
			spawn_rebels = {
				type = pretender_rebels
				size = 3
				religion = sunni
				culture = berber
				leader = "Muhammad"
				leader_dynasty = "ibn Yahya Wattasid"
			}
		}
	}
	
}

#The Sudanese Expedition
country_event = {
	id = flavor_mor.9
	title = flavor_mor.9.t
	desc = flavor_mor.9.d
	picture = EXPLORERS_eventPicture
	
	fire_only_once = yes
	
	trigger = {
		OR = {
			AND = {
				NOT = { has_dlc = "Golden Century" }
				tag = MOR
				is_year = 1550
				OR = {
					owns_core_province = 2466
					owns_core_province = 2460
				}
				1127 = {
					is_empty = yes
				}
				NOT = { owns = 1128 }
			}
			has_country_flag = mor_sudanese_expedition
		}
	}
	
	immediate = {
		hidden_effect = {
			every_country = {
				limit = {
					owns = 1128
					owns = 1129
					owns = 1132
					owns = 2247
				}
				set_country_flag = mor_crosses_sahara
			}
		}
	}
	
	mean_time_to_happen = {
		months = 150
	}
	
	option = {
		name = flavor_mor.9.a #Let us cross the Sahara!
		ai_chance = { factor = 1 }
		1127 = {
			add_core = MOR
			cede_province = MOR
		}
		every_province = {
			limit = {
				OR = {
					province_id = 1128
					province_id = 1129
					province_id = 1132
					province_id = 2247
				}
			}
			add_permanent_claim = MOR
		}
		every_country = {
			limit = { has_country_flag = mor_crosses_sahara }
			country_event = { id = flavor_mor.10 }
		}
		
	}	
}

#The Sudanese Expedition - Info Popup
country_event = {
	id = flavor_mor.10
	title = flavor_mor.10.t
	desc = flavor_mor.10.d
	picture = BORDER_TENSION_eventPicture
	
	is_triggered_only = yes
	
	trigger = {
		NOT = { tag = MOR }
	}
	
	option = {
		name = flavor_mor.10.a #This cannot end well.
		tooltip = {
			every_province = {
				limit = {
					OR = {
						province_id = 1128
						province_id = 1129
						province_id = 1132
						province_id = 2247
					}
				}
				add_permanent_claim = MOR
			}
		}
	}
	
}

#Crisis of the Maghreb - Info Popup
country_event = {
	id = flavor_mor.11
	title = flavor_mor.1.t
	desc = flavor_mor.1.d
	picture = FAMINE_eventPicture
	
	is_triggered_only = yes
	
	trigger = {
		NOT = { tag = MOR }
	}
	
	option = {
		name = flavor_mor.1.a
		tooltip = {
			add_country_modifier = {
			name = "mor_crisis"
			duration = 1825
			}
		}
	}
	
}

# New for 1.28

# Imperial Cities of Morocco by Daniel Tolman
country_event = {
	id = flavor_mor.12
	title = flavor_mor.12.t
	desc = flavor_mor.12.desc
	picture = CITY_VIEW_eventPicture
	
	is_triggered_only = yes
	
	option = {
		name = "flavor_mor.12.a"
		343 = {
			if = {
				limit = {
					NOT = {
						is_capital = yes
					}
				}
				move_capital_effect = yes
			}
			add_base_tax = 1
			add_base_production = 1
			add_base_manpower = 1
		}
	}
	option = {
		name = "flavor_mor.12.b"
		344 = {
			if = {
				limit = {
					NOT = {
						is_capital = yes
					}
				}
				move_capital_effect = yes
			}
			add_base_tax = 1
			add_base_production = 1
			add_base_manpower = 1
		}
	}
	option = {
		name = "flavor_mor.12.c"
		2467 = {
			if = {
				limit = {
					NOT = {
						is_capital = yes
					}
				}
				move_capital_effect = yes
			}
			add_base_tax = 1
			add_base_production = 1
			add_base_manpower = 1
		}
	}
	option = {
		name = "flavor_mor.12.d"
		342 = {
			if = {
				limit = {
					NOT = {
						is_capital = yes
					}
				}
				move_capital_effect = yes
			}
			add_base_tax = 1
			add_base_production = 1
			add_base_manpower = 1
		}
	}
}

# Tribes and Sufis sense weakness
country_event = {
	id = flavor_mor.13
	title = flavor_mor.13.t
	desc = flavor_mor.13.desc
	picture = ANGRY_MOB_eventPicture
	
	fire_only_once = yes
	
	trigger = {
		tag = MOR
		has_country_flag = wattasid_resolution
		owns_core_province = 343
		OR = {
			MRK = {
				is_subject_of = ROOT
			}
			SOS = {
				is_subject_of = ROOT
			}
			TFL = {
				is_subject_of = ROOT
			}
		}
	}
	mean_time_to_happen = {
		months = 24
	}
	option = { # Assert Dominance beyond the capital
		name = "flavor_mor.13.a"
		add_stability = -1
		add_country_modifier = {
			name = "mor_looks_outward"
			duration = 7300
		}
		if = {
			limit = {
				MRK = {
					is_subject_of = ROOT
				}
			}
			MRK = {
				add_liberty_desire = 10
			}
		}
		else_if = {
			limit = {
				344 = { owned_by = ROOT }
			}
			344 = {
				add_local_autonomy = -25
			}
		}
		if = {
			limit = {
				SOS = {
					is_subject_of = ROOT
				}
			}
			SOS = {
				add_liberty_desire = 10
			}
		}
		else_if = {
			limit = {
				348 = { owned_by = ROOT }
			}
			348 = {
				add_local_autonomy = -25
			}
		}
		if = {
			limit = {
				TFL = {
					is_subject_of = ROOT
				}
			}
			TFL = {
				add_liberty_desire = 10
			}
		}
		else_if = {
			limit = {
				346 = { owned_by = ROOT }
			}
			346 = {
				add_local_autonomy = -25
			}
		}
	}
	option = { # Remain cloistered in Fez
		name = "flavor_mor.13.b"
		add_stability = 1
		343 = {
			add_province_modifier = {
				name = "mor_looks_inward"
				duration = 7300
			}
		}
	}
}