###########################################
#                                         #
# Charlemagne Religious Events            #
#                                         #
# ID CM.4000-CM.4999                      #
#                                         #
###########################################

# Written by Tobias Bodlund

namespace = CM

###########################################
# Knights of the Sun                      #
###########################################


# The birth of the Knights of the Sun
narrative_event = {
	id = CM.4000
	title = EVTTITLE_CM_4000
	desc = EVTDESC_CM_4000
	picture = GFX_evt_sun_temple
	border = GFX_event_narrative_frame_religion

	major = yes
	hide_from = yes
	
	only_rulers = yes
	religion = miaphysite
	only_men = yes
	has_dlc = "Charlemagne"
	has_global_flag = zun_reformation
	
	trigger = {
		controls_religion = yes # Let it happen for the Coptic Pope - he's always around
		NOT = { is_title_active = d_zun_warriors }
	}
	
	mean_time_to_happen = {
		months = 36
	}
	
	immediate = {
		activate_title = { title = d_zun_warriors status = yes }
		create_character = {
			random_traits = no
			dynasty = random
			religion = zun_pagan_reformed
			culture = afghan
			female = no
			age = 28
			trait = brilliant_strategist
			trait = zealous
			trait = humble
			trait = ambitious
			trait = strategist
			trait = holy_warrior
		}
		new_character = {
			wealth = 500
			d_zun_warriors = {
				grant_title = PREV
			}
			set_government_type = feudal_government
			create_character = {
				random_traits = yes
				dynasty = random
				religion = zun_pagan_reformed
				culture = afghan
				female = no
				age = 16
			}
			create_character = {
				random_traits = yes
				dynasty = random
				religion = zun_pagan_reformed
				culture = afghan
				female = no
				age = 18
			}
			create_character = {
				random_traits = yes
				dynasty = random
				religion = zun_pagan_reformed
				culture = afghan
				female = no
				age = 18
			}
			create_character = {
				random_traits = yes
				dynasty = random
				religion = zun_pagan_reformed
				culture = afghan
				female = no
				age = 20
			}
			create_character = {
				random_traits = yes
				dynasty = random
				religion = zun_pagan_reformed
				culture = afghan
				female = no
				age = 25
			}
			create_character = {
				random_traits = yes
				dynasty = random
				religion = zun_pagan_reformed
				culture = afghan
				female = no
				age = 26
			}
			create_character = {
				random_traits = yes
				dynasty = random
				religion = zun_pagan_reformed
				culture = afghan
				female = no
				age = 28
			}
			create_character = {
				random_traits = yes
				dynasty = random
				religion = zun_pagan_reformed
				culture = afghan
				female = yes
				age = 16
			}
			create_character = {
				random_traits = yes
				dynasty = random
				religion = zun_pagan_reformed
				culture = afghan
				female = yes
				age = 17
			}
		}
	}
	
	option = {
		name = EVTOPTA_CM_4000
		trigger = {
			OR = {
				religion = zun_pagan_reformed
				religion = zun_pagan
			}
		}
	}
	option = {
		name = EVTOPTB_SOA_2009
		trigger = {
			NOT = { religion = zun_pagan_reformed }
			NOT = { religion = zun_pagan }
		}
	}
}

# Ping event when donating money to the Knights of the Sun
character_event = {
	id = CM.4005
	
	hide_window = yes
	
	is_triggered_only = yes
	
	immediate = {
		wealth = 300
		FROM = {
			letter_event = {
				id = CM.4006
			}
		}
		opinion = {
			who = FROM
			modifier = opinion_generous_donation
		}
	}
}

# Notification event when donating money to the Knights of the Sun
letter_event = {
	id = CM.4006
	desc = EVTDESC_CM_4006
	border = GFX_event_letter_frame_religion
	
	is_triggered_only = yes
	
	option = {
		name = EXCELLENT
	}
}

# The Grand Master humbly requests the right to build a castle in your demesne
character_event = {
	id = CM.4007
	
	hide_window = yes
	
	only_playable = yes
	religion = zun_pagan_reformed
	
	trigger = {
		d_zun_warriors = {
			holder_scope = {
				wealth = 300
				NOT = {
					realm_size = 10
				}
			}
		}
		
		any_demesne_province = {
			has_empty_holding = yes
			any_province_holding = {
				NOT = { holding_type = nomad }
			}
		}
		
		has_dlc = "Charlemagne"
		
		NOT = { has_character_modifier = expelled_d_zun_warriors }
		NOT = {
			any_liege = {
				has_character_modifier = expelled_d_zun_warriors
			}
		}
	}
	
	mean_time_to_happen = {
		months = 240
		modifier = {
			factor = 0.5
			d_zun_warriors = {
				holder_scope = {
					NOT = { demesne_size = 1 }
				}
			}
		}
		modifier = {
			factor = 0.5
			d_zun_warriors = {
				holder_scope = {
					NOT = { demesne_size = 2 }
				}
			}
		}
		modifier = {
			factor = 2.0
			d_zun_warriors = {
				holder_scope = {
					num_of_count_titles = 1
				}
			}
		}
		modifier = {
			factor = 2.0
			d_zun_warriors = {
				holder_scope = {
					realm_size = 5
				}
			}
		}
	}
	
	immediate = {
		random_demesne_province = {
			limit = {
				has_empty_holding = yes
				any_province_holding = {
					NOT = { holding_type = nomad }
				}
			}
			province_event = {
				id = CM.4008
			}
		}
	}
}

province_event = {
	id = CM.4008
	
	hide_window = yes
	
	is_triggered_only = yes
	
	immediate = {
		d_zun_warriors = {
			holder_scope = {
				character_event = {
					id = CM.4009
				}
			}
		}
	}
}

character_event = {
	id = CM.4009
	
	hide_window = yes
	
	is_triggered_only = yes
	
	immediate = {
		FROMFROM = {
			letter_event = {
				id = CM.4010
			}
		}
	}
}

letter_event = {
	id = CM.4010
	desc = EVTDESC_CM_4010
	border = GFX_event_letter_frame_religion
	
	is_triggered_only = yes
	
	option = {
		name = EVTOPTA_SOA_1023 # Agree
		ai_chance = {
			factor = 80
			modifier = {
				factor = 0
				has_character_modifier = expelled_d_zun_warriors
			}
		}
		
		hidden_tooltip = {
			FROMFROM = {
				province_event = { id = CM.4011 }
			}
			remove_character_modifier = expelled_d_zun_warriors
		}
		
		piety = 200
		wealth = 100
	}
	
	option = {
		name = EVTOPTB_SOA_1153 # Refuse
		ai_chance = {
			factor = 20
		}
		
		piety = -100
	}
}

# Castle has been erected
province_event = {
	id = CM.4011
	desc = EVTDESC_CM_4011
	picture = GFX_evt_castle_construction
	border = GFX_event_normal_frame_religion
	
	is_triggered_only = yes
	
	immediate = {
		FROMFROM = {
			wealth = -300
		}
	}
	
	option = {
		name = EVTOPTA_SOA_1024
		build_holding = {
		   type = castle
		   holder = FROMFROM
		}
	}
}

# Ping event when expelling the Knights of the Sun
character_event = {
	id = CM.4012
	
	hide_window = yes
	
	is_triggered_only = yes
	
	immediate = {
		any_title_under = {
			limit = {
				tier = BARON
				location = {
					owner = {
						OR = {
							character = FROM
							is_liege_or_above = FROM
						}
					}
				}
			}
			usurp_title = FROM
		}
	
		FROM = {
			letter_event = {
				id = CM.4013
			}
		}
		
		opinion = {
			who = FROM
			modifier = opinion_expelled_from_realm
		}
	}
}

# Notification event when expelling the Knights of the Sun
letter_event = {
	id = CM.4013
	desc = EVTDESC_CM_4013
	border = GFX_event_letter_frame_religion
	
	is_triggered_only = yes
	
	option = {
		name = EVTOPTA_CM_4013
	}
}

###########################################
# Festival of the Sun  CM.4100-CM.4199    #
###########################################

# Invite vassals to festival
character_event = {
	id = CM.4100
	desc = EVTDESC_CM_4100
	picture = GFX_evt_sun_temple
	border = GFX_event_normal_frame_religion
	
	only_rulers = yes
	min_age = 16
	capable_only = yes
	prisoner = no
	has_character_flag = planning_zun_feast

	trigger = {
		war = no
		month = 3
		NOT = { month = 9 }
		is_not_busy_trigger = yes
		NOT = { is_inaccessible_trigger = yes }
	}
	
	mean_time_to_happen = {
		days = 1
	}

	option = {
		name = EVTOPTA_CM_4100
		clr_character_flag = planning_zun_feast
		any_vassal = {
			limit = {
				has_regent = no
				war = no
				is_not_busy_trigger = yes
			}
			letter_event = {
				id = CM.4101
				tooltip = EVTTOOLTIP1_RoI_1000
			}
		}
		hidden_tooltip = {
			character_event = { id = CM.4120 days = 12 }
			add_character_modifier = {
				name = do_not_disturb
				days = 45
				hidden = yes
			}
		}
	}
}

# Vassal receives invitation
letter_event = {
	id = CM.4101
	desc = EVTDESC_CM_4101
	border = GFX_event_letter_frame_religion
	
	is_triggered_only = yes
	
	option = {
		name = EVTOPTA_CM_4101 #Travel to the feast
		ai_chance = {
			factor = 2
			modifier  = {
				factor = 10
				has_focus = focus_theology
				OR = {
					religion = zun_pagan
					religion = zun_pagan_reformed
				}
			}
			modifier  = {
				factor = 0.1
				is_inaccessible_trigger = yes
			}
			modifier  = {
				factor = 2
				opinion = { who = from value = -30 }
			}
			modifier  = {
				factor = 5
				opinion = { who = from value = -15 }
			}
			modifier  = {
				factor = 5
				opinion = { who = from value = 0 }
			}
		}
		hidden_tooltip = {
			set_character_flag = attending_zun_feast
			character_event = { id = CM.4105 days = 12 }  # Hidden - arrives at feast
			character_event = { id = CM.4199 days = 42 } # Safety event for clearing all flags
			add_character_modifier = {
				name = do_not_disturb
				days = 45
				hidden = yes
			}
		}		
		end_inaccessibility_effect = yes
	}
	option = {
		name = EVTOPTB_RoI_1001 #Refuse invitation
		ai_chance = {
			factor = 1
			modifier  = {
				factor = 0
				opinion = { who = FROM value = 25 }
				NOT = { is_inaccessible_trigger = yes }
			}
			modifier  = {
				factor = 5
				NOT = {
					OR = {
						religion = zun_pagan
						religion = zun_pagan_reformed
					}
				}
			}
		}
		FROM = {
			letter_event = {
				id = CM.4102
				days = 3
				tooltip = EVTTOOLTIP1_RoI_2001
			}
		}
	}
}

# If vassal refuses to come to the feast
letter_event = {
	id = CM.4102
	desc = EVTDESC_CM_4102
	
	is_triggered_only = yes
	
	option = {
		name = EVTOPTA_SoA_502
		opinion = {
			modifier = opinion_dislike
			who = FROM
			years = 2
		}
	}
}

# Festival begins
character_event = {
	id = CM.4120
	desc = EVTDESC_CM_4120
	picture = GFX_evt_sun_temple
	border = GFX_event_normal_frame_religion

	is_triggered_only = yes
	
	option = {
		name = EVTOPTA_CM_4120
		hidden_tooltip = { character_event = { id = CM.4195 days = 30 } } # End festival
		hidden_tooltip = { character_event = { id = CM.4199 days = 31 } } # Clearing all flags and modifiers after feast
		hidden_tooltip = {
			narrative_event = { id = CM.4130 days = 10 } # Walking in the sun
			character_event = { id = CM.4190 days = 20 } # Temple ceremony
		}
		any_courtier = {
			limit = {
				is_adult = yes
				is_ruler = no
				NOT = { trait = incapable }
				NOT = { has_character_flag = attending_zun_feast }
				OR = {
					religion = zun_pagan
					religion = zun_pagan_reformed
				}
			}
			set_character_flag = attending_zun_feast
			narrative_event = { id = CM.4130 days = 10 } # Walking in the sun
			hidden_tooltip = { character_event = { id = CM.4199 days = 31 } } # Clearing all flags and modifiers after feast
		}
	}
}

# Vassal arrives at festival
character_event = {
	id = CM.4105
	desc = EVTDESC_CM_4120
	picture = GFX_evt_sun_temple
	border = GFX_event_normal_frame_religion

	is_triggered_only = yes
	
	option = {
		name = EVTOPTA_CM_4120
		hidden_tooltip = {
			if = {
				limit = {
					OR = {
						religion = zun_pagan
						religion = zun_pagan_reformed
					}
				}
				narrative_event = { id = CM.4130 days = 10 } # Walking in the sun
			}
			character_event = { id = CM.4190 days = 20 } # Temple ceremony
		}
	}
}

# Festival ends
character_event = {
	id = CM.4195

	hide_window = yes
	
	is_triggered_only = yes
	
	immediate = {
		character_event = { id = CM.4196 }
		any_vassal = {
			limit = { has_character_flag = attending_zun_feast }
			character_event = { id = CM.4198 }
		}
		any_courtier = {
			limit = {
				has_character_flag = attending_zun_feast
				NOT = { vassal_of = ROOT }
			}
			character_event = { id = CM.4198 }
		}
	}
}

# Festival is over - host
character_event = {
	id = CM.4196
	desc = EVTDESC_CM_4196
	picture = GFX_evt_sun_temple
	border = GFX_event_normal_frame_religion

	is_triggered_only = yes
	
	option = {
		name = EVTOPTA_CM_4196
		add_character_modifier = {
			name = large_feast_timer
			duration = 1095
			hidden = yes
		}
		hidden_tooltip = {
			remove_do_not_disturb_effect = yes
		}
	}
}

# Festival is over - guest
character_event = {
	id = CM.4198
	desc = EVTDESC_CM_4196
	picture = GFX_evt_sun_temple
	border = GFX_event_normal_frame_religion

	is_triggered_only = yes
	
	option = {
		name = EVTOPTA_CM_4196
		add_character_modifier = {
			name = large_feast_timer
			duration = 365
			hidden = yes
		}
		opinion = {
			modifier = opinion_enjoyed_feast
			who = FROM
			years = 2
		}
		hidden_tooltip = {
			remove_do_not_disturb_effect = yes
			clr_character_flag = attending_zun_feast
		}
	}
}

# Clear all character flags and modifiers - safety catch
character_event = {
	id = CM.4199

	hide_window = yes
	
	is_triggered_only = yes
	
	immediate = {
		clr_character_flag = attending_zun_feast
	}
}

# Walking in the sun
narrative_event = {
	id = CM.4130
	title = EVTTITLE_CM_4130
	desc = EVTDESC_CM_4130
	picture = GFX_evt_sun_temple
	border = GFX_event_narrative_frame_religion

	is_triggered_only = yes
	
	capable_only = yes
	
	option = {
		name = EVTOPTA_CM_4130
		piety = 30
		hidden_tooltip = {
			random_list = {
				5 = { character_event = { id = CM.4131 } } # Weak or old character becomes ill
				5 = { character_event = { id = CM.4133 } } # Character goes insane
				5 = { character_event = { id = CM.4135 } } # Character becomes possessed
				10 = { character_event = { id = CM.4137 } } # Character becomes zealous
				10 = { character_event = { id = CM.4139 } } # Character becomes stronger
				10 = { character_event = { id = CM.4141 } } # Character becomes wiser
				5 = { character_event = { id = CM.4143 } } # Zealous character stares into sun and goes blind
				300 = {} # No event
			}
		}
	}
}

# Weak or old character becomes ill or incapable
character_event = {
	id = CM.4131
	desc = EVTDESC_CM_4131
	picture = GFX_evt_sun_temple
	border = GFX_event_normal_frame_religion
	
	is_triggered_only = yes
	
	trigger = {
		immortal = no
		OR = {
			age = 70
			health_traits = 1
		}
	}
	
	option = {
		name = EVTOPTA_CM_4131
		if = {
			limit = {
				is_ill = yes
			}
			add_trait = incapable
		}
		if = {
			limit = {
				is_ill = no
			}
			if = {
				limit = {
					NOT = {
						has_dlc = "Reapers"
					}
				}
				add_trait = ill
			}
			if = {
				limit = {
					has_dlc = "Reapers"
				}
				add_symptom_effect = yes
			}
		}
	}
}

# Character goes insane
character_event = {
	id = CM.4133
	desc = EVTDESC_CM_4133
	picture = GFX_evt_sun_temple
	border = GFX_event_normal_frame_religion
	
	is_triggered_only = yes
	
	trigger = {
		NOT = { trait = lunatic }
		OR = {
			trait = stressed
			trait = depressed
			AND = {
				health_traits = 1
				trait = zealous
			}
		}
	}
	
	option = {
		name = EVTOPTA_CM_4133
		add_trait = lunatic
	}
}

# Character becomes possessed
character_event = {
	id = CM.4135
	desc = EVTDESC_CM_4135
	picture = GFX_evt_sun_temple
	border = GFX_event_normal_frame_religion
	
	is_triggered_only = yes
	
	trigger = {
		NOT = { trait = possessed }
		trait = zealous
	}
	
	option = {
		name = EVTOPTA_CM_4135
		add_trait = possessed
	}
}

# Character becomes zealous
character_event = {
	id = CM.4137
	desc = EVTDESC_CM_4137
	picture = GFX_evt_sun_temple
	border = GFX_event_normal_frame_religion
	
	is_triggered_only = yes
	
	trigger = {
		NOT = { trait = zealous }
		NOT = { trait = cynical }
	}
	
	option = {
		name = EVTOPTA_CM_4137
		add_trait = zealous
	}
}

# Character becomes stronger
character_event = {
	id = CM.4139
	desc = EVTDESC_CM_4139
	picture = GFX_evt_sun_temple
	border = GFX_event_normal_frame_religion
	
	is_triggered_only = yes
	
	trigger = {
		is_strong_trigger = no
		is_weak_trigger = no
		NOT = { trait = slothful }
		NOT = { health_traits = 1 }
	}
	
	option = {
		name = EVTOPTA_CM_4137
		add_trait = robust
	}
}

# Character becomes wiser
character_event = {
	id = CM.4141
	desc = EVTDESC_CM_4141
	picture = GFX_evt_sun_temple
	border = GFX_event_normal_frame_religion
	
	is_triggered_only = yes
	
	trigger = {
		is_smart_trigger = no
	}
	
	option = {
		name = EVTOPTA_CM_4141
		add_trait = shrewd
	}
}

# Character stares into sun and becomes blind
character_event = {
	id = CM.4143
	desc = EVTDESC_CM_4143
	picture = GFX_evt_sun_temple
	border = GFX_event_normal_frame_religion
	
	is_triggered_only = yes
	
	trigger = {
		trait = zealous
		NOT = { trait = blinded }
	}
	
	option = {
		name = EVTOPTA_CM_4143
		if = {
			limit = {
				trait = one_eyed
			}
			remove_trait = one_eyed
		}
		add_trait = blinded
	}
}


# Temple ceremony - host and guests
character_event = {
	id = CM.4190
	desc = EVTDESC_CM_4190
	picture = GFX_evt_sun_temple
	border = GFX_event_normal_frame_religion

	is_triggered_only = yes
	
	option = {
		name = EVTOPTA_CM_4190
		piety = 20
	}
}

###########################################
# Byzantine religious events              #
###########################################

# Byzantine Emperor renounces iconoclasm
character_event = {
	id = CM.4200
	desc = EVTDESC_CM_4200
	picture = GFX_evt_icon
	border = GFX_event_normal_frame_religion

	is_triggered_only = yes
	
	option = {
		name = EVTOPTA_CM_4200
		religion = FROM
		ai_chance = {
			factor = 1
			modifier = {
				factor = 0.3
				trait = zealous
				intrigue = 3
			}
			modifier = {
				factor = 0
				trait = zealous
				NOT = { intrigue = 3 }
			}
		}
		if = {
			limit = { trait = zealous }
			remove_trait = zealous
			piety = -50
		}
	}
	option = {
		name = EVTOPTB_CM_4200
		piety = 100
		ai_chance = {
			factor = 1
			modifier = {
				factor = 0
				NOT = { trait = zealous }
			}
		}
	}
}

##################################
# The Haruriyyah CM.4300-CM.4399 #
##################################

# The Grand Master demands one of your sons due to debt
character_event = {
	id = CM.4300
	
	hide_window = yes
	
	min_age = 16
	only_playable = yes
	religion_group = muslim
	
	trigger = {
		has_character_modifier = borrowed_from_haruriyyah
		OR = {
			religion = ibadi
			religion = kharijite
		}
		is_heretic = no
		NOT = { has_character_flag = sent_son_to_haruriyyah }
		any_child = {
			is_female = no
			is_adult = yes
			is_ruler = no
			prisoner = no
			NOT = { trait = incapable }
			ROOT = {
				NOT = { 
					current_heir = { 
						character = PREVPREV 
					}
				}
			}
		}
		has_dlc = "Charlemagne"
	}
	
	mean_time_to_happen = {
		months = 120
	}
	
	immediate = {
		random_child = {
			limit = {
				is_female = no
				is_adult = yes
				is_ruler = no
				prisoner = no
				NOT = { trait = incapable }
				ROOT = {
					NOT = { 
						current_heir = { 
							character = PREVPREV 
						}
					}
				}
			}
			character_event = {
				id = CM.4301
			}
		}
	}
}

character_event = {
	id = CM.4301

	hide_window = yes
	
	is_triggered_only = yes
	
	immediate = {
		d_haruriyyah = {
			holder_scope = {
				character_event = {
					id = CM.4302
				}
			}
		}
	}
}

character_event = {
	id = CM.4302
	
	hide_window = yes
	
	is_triggered_only = yes
	
	immediate = {
		FROMFROM = {
			letter_event = {
				id = CM.4303
			}
		}
	}
}

letter_event = {
	id = CM.4303
	desc = EVTDESC_CM_4303
	border = GFX_event_letter_frame_religion
	
	is_triggered_only = yes
	
	option = {
		name = EVTOPTA_SOA_1003 # Agree
		ai_chance = {
			factor = 100
		}
		
		set_character_flag = sent_son_to_haruriyyah
		
		piety = 100
		
		d_haruriyyah = {
			holder_scope = {
				FROMFROM = {
					move_character = PREV
					hidden_tooltip = {
						transfer_scaled_wealth = { to = PREV value = all }
					}
				}
			}
		}
	}
	
	option = {
		name = EVTOPTB_SOA_1003 # Pay them back
		wealth = -300
		hidden_tooltip = {
			remove_character_modifier = borrowed_from_haruriyyah
		}
		FROM = {
			wealth = 300
		}
	}
	
	option = {
		name = EVTOPTC_SOA_1003 # Refuse
		piety = -1000
	}
}


# Birth of the Haruriyyah Order
narrative_event = {
	id = CM.4309
	title = EVTTITLE_CM_4309
	desc = EVTDESC_CM_4309
	picture = GFX_evt_moors
	border = GFX_event_narrative_frame_religion
	
	major = yes
	hide_from = yes
	
	only_playable = yes
	only_men = yes
	religion_group = muslim
	has_dlc = "Charlemagne"
	has_global_flag = muslim_jihads_unlocked
	
	trigger = {
		OR = {
			religion = ibadi
			religion = kharijite
		}
		is_heretic = no
		NOT = {
			is_title_active = d_haruriyyah
		}
		
		
		OR = {
			869 = { # Hajar
				NOT = { owner = { religion_group = muslim } }
			}
			728 = { # Damascus
				NOT = { owner = { religion_group = muslim } }
			}
			796 = { # Cairo
				NOT = { owner = { religion_group = muslim } }
			}
			774 = { # Jerusalem
				NOT = { owner = { religion_group = muslim } }
			}
			719 = { # Mecca
				NOT = { owner = { religion_group = muslim } }
			}
		}
	}
	
	mean_time_to_happen = {
		months = 6
	}
	
	immediate = {
		activate_title = { title = d_haruriyyah status = yes }
		create_character = {
			random_traits = no
			dynasty = random
			religion = ROOT
			culture = persian
			female = no
			age = 25
			attributes = {
				martial = 10
				diplomacy = 9
				stewardship = 9
				intrigue = 7
				learning = 9
			}
			health = 6
			fertility = 0.5
			trait = brilliant_strategist
			trait = sayyid
			trait = hajjaj
			trait = hafiz
			trait = patient
			trait = zealous
			trait = scholar
			trait = temperate
		}
		new_character = {
			wealth = 500
			d_haruriyyah = {
				grant_title = PREV
				religion = PREV
			}
			set_government_type = feudal_government
			create_character = {
				random_traits = yes
				dynasty = random
				religion = ROOT
				culture = persian
				female = no
				age = 16
			}
			create_character = {
				random_traits = yes
				dynasty = random
				religion = ROOT
				culture = persian
				female = no
				age = 18
			}
			create_character = {
				random_traits = yes
				dynasty = random
				religion = ROOT
				culture = persian
				female = no
				age = 18
			}
			create_character = {
				random_traits = yes
				dynasty = random
				religion = ROOT
				culture = persian
				female = no
				age = 20
			}
			create_character = {
				random_traits = yes
				dynasty = random
				religion = ROOT
				culture = persian
				female = no
				age = 25
			}
			create_character = {
				random_traits = yes
				dynasty = random
				religion = ROOT
				culture = persian
				female = no
				age = 26
			}
			create_character = {
				random_traits = yes
				dynasty = random
				religion = ROOT
				culture = persian
				female = no
				age = 28
			}
			create_character = {
				random_traits = yes
				dynasty = random
				religion = ROOT
				culture = persian
				female = yes
				age = 16
			}
			create_character = {
				random_traits = yes
				dynasty = random
				religion = ROOT
				culture = persian
				female = yes
				age = 17
			}
		}
	}
	
	option = {
		name = EVTOPTA_CM_4309
		trigger = {
			religion = ROOT
		}
	}
	option = {
		name = EVTOPTB_CM_4309
		trigger = {
			NOT = { religion = ROOT }
		}
	}
}

# The Grand Master requests the right to build a castle in your demesne
character_event = {
	id = CM.4350
	
	hide_window = yes
	
	only_playable = yes
	religion_group = muslim
	
	trigger = {
		OR = {
			religion = ibadi
			religion = kharijite
		}
		
		d_haruriyyah = {
			holder_scope = {
				wealth = 300
				NOT = {
					realm_size = 10
				}
				NOT = {
					num_of_count_titles = 1
				}
			}
		}
		
		any_demesne_province = {
			has_empty_holding = yes
			port = yes
			any_province_holding = {
				NOT = { holding_type = nomad }
			}
		}
		
		has_dlc = "Charlemagne"
		
		NOT = { has_character_modifier = expelled_d_haruriyyah }
		NOT = {
			any_liege = {
				has_character_modifier = expelled_d_haruriyyah
			}
		}
	}
	
	mean_time_to_happen = {
		months = 240
		modifier = {
			factor = 0.5
			d_haruriyyah = {
				holder_scope = {
					NOT = { demesne_size = 1 }
				}
			}
		}
		modifier = {
			factor = 0.5
			d_haruriyyah = {
				holder_scope = {
					NOT = { demesne_size = 2 }
				}
			}
		}
		modifier = {
			factor = 2.0
			d_haruriyyah = {
				holder_scope = {
					realm_size = 5
				}
			}
		}
	}
	
	immediate = {
		random_demesne_province = {
			limit = {
				has_empty_holding = yes
				port = yes
				any_province_holding = {
					NOT = { holding_type = nomad }
				}
			}
			province_event = {
				id = CM.4351
			}
		}
	}
}

province_event = {
	id = CM.4351
	
	hide_window = yes
	
	is_triggered_only = yes
	
	immediate = {
		d_haruriyyah = {
			holder_scope = {
				character_event = {
					id = CM.4352
				}
			}
		}
	}
}

character_event = {
	id = CM.4352
	
	hide_window = yes
	
	is_triggered_only = yes
	
	immediate = {
		FROMFROM = {
			letter_event = {
				id = CM.4353
			}
		}
	}
}

letter_event = {
	id = CM.4353
	desc = EVTDESC_CM_4353
	border = GFX_event_letter_frame_religion
	
	is_triggered_only = yes
	
	option = {
		name = EVTOPTA_SOA_1023 # Agree
		ai_chance = {
			factor = 100
			modifier = {
				factor = 0
				has_character_modifier = expelled_d_haruriyyah
			}
		}
		
		hidden_tooltip = {
			FROMFROM = {
				province_event = { id = CM.4354 }
			}
			remove_character_modifier = expelled_d_haruriyyah
		}
		
		piety = 200
		wealth = 100
	}
	
	option = {
		name = EVTOPTB_SOA_1031 # Refuse
		ai_chance = {
			factor = 20
		}
		
		piety = -100
	}
}

# Castle has been erected
province_event = {
	id = CM.4354
	desc = EVTDESC_CM_4324
	picture = GFX_evt_moors
	border = GFX_event_normal_frame_religion
	
	is_triggered_only = yes
	
	immediate = {
		FROMFROM = {
			wealth = -300
		}
	}
	
	option = {
		name = EVTOPTA_SOA_1024
		build_holding = {
		   type = castle
		   holder = FROMFROM
		}
	}
}

# Notification event when donating money to the Muslim orders
letter_event = {
	id = CM.4399
	desc = EVTDESC_CM_4399
	border = GFX_event_letter_frame_religion
	
	is_triggered_only = yes
	
	option = {
		name = EVTOPTA_CM_4399
	}
}

