namespace = fp3_yearly

########EVENT INDEX############
#fp3_yearly.8000 - Ghazi Gone Bad, by Ola Jentzsch 
#fp3_yearly.8001 - Frontier Fortress Benefactor, by Ola Jentzsch
#fp3_yearly.8002 - Faith at the Frontier, by Ola Jentzsch
#fp3_yearly.8003 - Exotic Espand, by Ola Jentzsch
#fp3_yearly.8004 - The Frontier Beckons, by Ola Jentzsch
	#fp3_yearly.8005 - Hidden Event, sets up duel 
	#fp3_yearly.8006 - Hidden Event, in case duel is invalidated
	#fp3_yearly.8007 - Persian Parenting (follow-up-event)
	#fp3_yearly.8008 - An Ignominous Defeat (follow-up-event)
#fp3_yearly.8009 - Caliphal Concerns, by Ola Jentzsch
#fp3_yearly.8010 - The Abode of War, by Ola Jentzsch
	#fp3_yearly.8011 - Hidden Event, sets up stuff 
	#fp3_yearly.8012 - Promise Fulfilled (follow-up-event)
	#fp3_yearly.8013 - Caliphal Dissapointment (follow-up-event)
#fp3_yearly.8014 - Secrets of the Teapot, by Ola Jentzsch 
#fp3_yearly.8016 - Forgotten Runestones, by Ola Jentzsch
	#fp3_yearly.8017 - Hyrcanian Havoc, by Ola Jentzsch
#fp3_yearly.8018 - Heavenly Horses, by Ola Jentzsch 


##################################
# Ghazi Gone Bad
# By Ola Jentzsch
###################################
scripted_trigger fp3_yearly.8000_province_trigger = { #this is needed to get the loc right - we want a city!
	has_holding_type = city_holding
	barony = {
		is_capital_barony = no
	}
}

fp3_yearly.8000 = { #Ghazi Gone Bad
	type = character_event
	title = {
		first_valid = {
			triggered_desc = {
				trigger = { has_religion = religion:islam_religion }
				desc = fp3_yearly.8000.t	
			}
			desc = fp3_yearly_non_islamic.t
		}
	}
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = { has_religion = religion:islam_religion }
				desc = fp3_yearly.8000.desc_opening	
			}
			desc = fp3_yearly.8000.desc_unislamic_opening
		}
		random_valid = {
			desc = fp3_yearly.8000_dancing_girl.desc 
			desc = fp3_yearly.8000_bath_inspector.desc
			desc = fp3_yearly.8000_townsfolk.desc
		}
		desc = fp3_yearly.8000.desc
	}

	theme = skull
	left_portrait = {
		character = root
		animation = personality_rational
	}
	right_portrait = {
		character = scope:raging_ghazi
		animation = prisondungeon
	}
	lower_left_portrait = {
		character = scope:righteous_marshal
	}

	override_background = { reference = dungeon }


	trigger = {
		has_fp3_dlc_trigger = yes
		is_ruler = yes
		any_held_county = {
			any_county_province = {
				geographical_region = dlc_fp3_greater_persian_frontier_regions 
				fp3_yearly.8000_province_trigger = yes
			}
		}

		faith = {
			NOR = {
				has_doctrine_parameter = unreformed # Unreformed Pagans cannot Holy War
				has_doctrine_parameter = holy_wars_forbidden # Pacifists cannot Holy War
			}
		}
		exists = cp:councillor_marshal 

		cp:councillor_marshal = {
			is_available_ai_adult = yes 
			NOR = { #so that his personality makes sense for the story
				has_trait = zealous
				has_trait = arbitrary
				has_trait = callous 
				has_trait = faith_warrior 
			}
		}

		any_culture_global = { fp3_warrior_culture_trigger = yes } #failsafe to prevent funky errors
	}

	cooldown = {
		years = 10 
	}	

	immediate = {
		
		random_culture_global = {
			limit = { fp3_warrior_culture_trigger = yes }
			save_scope_as = warmonger_culture
		}

		random_held_county = {
			limit = {
				any_county_province = {	fp3_yearly.8000_province_trigger = yes }		
			}
			save_scope_as = murder_county #for the modifier 
		}

		scope:murder_county = {
			random_county_province = { 
				limit = { fp3_yearly.8000_province_trigger = yes }
				barony = { save_scope_as = murder_barony } #for use in loc
			}
		}	

		scope:murder_county = {
			add_county_modifier = {
				modifier = fp3_brutal_predations_county_modifier
				years = 10
			}
		}

		cp:councillor_marshal = { save_scope_as = righteous_marshal }

		create_character = { 
			template = fp3_raging_ghazi_character
			location = root.capital_province
			culture = root.culture
			save_scope_as = raging_ghazi	
		}	 	
	}

	option = { #I too have walked the holy path, go in peace
		name = fp3_yearly.8000.a
		flavor = fp3_yearly.8000.flavor.a.tt 

		trigger = {
			OR = {	
				has_trait = faith_warrior
				has_trait = holy_warrior
				has_trait = crusader_king
				has_trait = pilgrim 
				is_ai = yes #we want to encourage the AI to do this, rather than keep the ghazi around, thus we allow this option more easily for the AI 
			}
		}

		add_piety = medium_piety_gain 

		scope:raging_ghazi = { silent_disappearance_effect = yes }

		stress_impact = { 
   			zealous = medium_stress_impact_loss
   			trusting = minor_stress_impact_loss
   			forgiving = minor_stress_impact_loss
   			just = minor_stress_impact_gain	
   		}

		ai_chance = { #zealous AI prefer this option
        	base = 100
        	ai_value_modifier = {
           		ai_energy = 1 
           		ai_zeal = 1
           		ai_honor = -1
           		ai_rationality = -0.5
        	}
   		} 		
	}	

	option = { #I have a nice new prison cell just for you! 
		name = fp3_yearly.8000.b
		flavor = fp3_yearly.8000.flavor.b.tt

		add_dread = minor_dread_gain

		scope:raging_ghazi = { #the ghazi gets to languish in a dungeon
			hard_imprison_character_effect = {
				TARGET = this
				IMPRISONER = root
			}
		}

		scope:murder_county = {
			remove_county_modifier = fp3_brutal_predations_county_modifier
		}

		stress_impact = { 
   			just = medium_stress_impact_loss
   			vengeful = minor_stress_impact_loss 
   			zealous = medium_stress_impact_gain
   			callous = minor_stress_impact_gain 
   			forgiving = minor_stress_impact_gain 			 
   		}

		ai_chance = { #just and compassionate AI go for this option 
        	base = 100
        	ai_value_modifier = {
           		ai_honor = 1
            	ai_compassion = 1 
            	ai_zeal = -1
        	}
   		}
	}	

	option = { #I could use a man of your talents 
		name = fp3_yearly.8000.c

		add_courtier = scope:raging_ghazi

		scope:raging_ghazi = {
			add_opinion = {
				target = root
				modifier = respect_opinion
				opinion = 20
			}
		}

		add_hook = {
			target = scope:raging_ghazi
			type = favor_hook
		}

		scope:righteous_marshal = { 
			add_opinion = {
				target = root
				modifier = disappointed_opinion
				opinion = -20
			} 
		}

		stress_impact = { 
   			zealous = minor_stress_impact_loss
   			greedy = minor_stress_impact_loss 
   			just = major_stress_impact_gain
   			paranoid = minor_stress_impact_gain 		 
   		}

		ai_chance = { #greedy / opportunistic AI go for this option, but more rarely than the others, since we don't want to spam Persia with this character
        	base = 50
        	ai_value_modifier = {
        		ai_zeal = 0.5
           		ai_greed = 1
            	ai_rationality = 0.5
            	ai_compassion = -1
            	ai_honor = -1
        	}
   		}
	}
	after = {
		scope:raging_ghazi = {
			silent_disappearance_ai_effect = yes
		}
	}
}

scripted_trigger fp3_yearly.8001_outlying_province_trigger = {
	squared_distance = {
		target = root.capital_province
		value > squared_distance_medium 
	}
}

fp3_yearly.8001 = { #Frontier Fortress Benefactor 
	type = character_event
	title = fp3_yearly.8001.t
	desc = fp3_yearly.8001.desc
	theme = martial

	left_portrait = {
		character = root
		animation = thinking 
	}
	right_portrait = {
		character = scope:concerned_councillor
		animation = personality_bold
	}

	trigger = {
		has_fp3_dlc_trigger = yes
		is_ruler = yes
		any_held_county = {
			any_county_province = {
				fp3_yearly.8001_outlying_province_trigger = yes 
			}
		}

		is_healthy = yes #the councillor's request wouldn't make much sense otherwise 

		root.capital_province = { geographical_region = world_persian_empire } #so that this inside-to-outside worldview makes sense 

		faith = {
			NOT = {
				has_doctrine_parameter = unreformed # Unreformed Pagans don't need frontier fortresses, generally speaking
			}
		}
		
		OR = { #Either could make sense, may as well make it as flexible as possible
			exists = cp:councillor_steward
			exists = cp:councillor_marshal
		}
	}

	cooldown = {
		years = 50 
	}

	immediate = {
		random_held_county = {
			limit = {
				any_county_province = { 
					fp3_yearly.8001_outlying_province_trigger = yes  		
				}			
			}
			weight = {
				modifier = {
					factor = 100
					any_county_province = { 
						geographical_region = dlc_fp3_greater_persian_frontier_regions
					}
				}
			}
			save_scope_as = frontier_fort_county	
		}

		if = {
			limit = { exists = cp:councillor_marshal }
			cp:councillor_marshal = { save_scope_as = concerned_councillor }
		}
		else = { cp:councillor_steward = { save_scope_as = concerned_councillor } }

		if = {
			limit = { 
				any_spouse = { 
					AND = {
						is_available_healthy_ai_adult = yes
						is_landed = no 
					}
					NOR = {
						has_trait = arrogant
						has_trait = craven
						has_trait = lazy
						has_trait = shy
						has_trait = content
						has_trait = pregnant
					}
				} 
			}
			random_spouse = { save_scope_as = dutiful_spouse }
		}
	}

	option = { #Of course I shall go!
		name = fp3_yearly.8001.a 

		scope:frontier_fort_county = {
			add_county_modifier = {
				modifier = fp3_boosted_frontier_morale_county_modifier
				years = 15
			} 
		}

		add_character_modifier = {	
			modifier = fp3_visited_the_frontier_modifier
			years = 5
		}

		remove_treasury_or_gold = minor_treasury_or_gold_value #gotta pay for travel expenses! 
		
		stress_impact = { 
   			diligent = medium_stress_impact_loss
   			brave = minor_stress_impact_loss
   			humble = minor_stress_impact_loss
   			gregarious = minor_stress_impact_loss
   			shy = minor_stress_impact_gain
   			content = miniscule_stress_impact_gain
   			lazy = medium_stress_impact_gain	
   		}

		ai_chance = { #dutiful/diligent AI prefer this option
        	base = 100
        	ai_value_modifier = {
           		ai_energy = 1 
           		ai_honor = 1
           		ai_zeal = 0.5
           		ai_boldness = 0.5
        	}
   		} 		
	}

	option = { #Send your wife/husband instead
		name = fp3_yearly.8001.b
		flavor = fp3_yearly.8001.flavor.b.tt

		trigger = {
			exists = scope:dutiful_spouse
			NOT = {
				dummy_female = {
					can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = scope:concerned_councillor }
				}
			}
			scope:concerned_councillor = { #checking that they can be a misogynist/misandrist in this matter 
				NOR = {
  					faith = { has_doctrine = doctrine_gender_equal }
  					culture = { has_cultural_parameter = has_access_to_shieldmaidens }
   				}
			}
		}

		scope:concerned_councillor = {
			add_opinion = {	
				target = root 
				modifier = disappointed_opinion
				opinion = -20
			}	
		}

		scope:dutiful_spouse = {
			if = {
				limit = {
					OR = { #checking that (s)he would appreciate this opportunity
						has_trait = diligent
						has_trait = ambitious
						has_trait = brave
						has_trait = adventurer
						has_trait = shieldmaiden
						has_martial_lifestyle_trait_trigger = yes
  						has_lifestyle = martial_lifestyle
   						martial >= high_skill_rating 
   						has_stewardship_lifestyle_trait_trigger = yes
  						has_lifestyle = stewardship_lifestyle
   						stewardship >= high_skill_rating 	
					}
				}
				add_opinion = {	
					target = root 
					modifier = spouse_trusted_me_opinion
				}
			}
			else = { #otherwise, (s)he doesn't wanna go to the frontier
				add_opinion = {	
					target = root 
					modifier = fp3_sent_me_to_the_frontier_opinion
				}
			}	
		}

		scope:dutiful_spouse = {
			duel = {
			skill = martial
			value = average_skill_rating

				20 = {
					compare_modifier = {
						value = scope:duel_value
						multiplier = 2
					}
					root = {
						send_interface_toast = {
							title = delegated_fortress_inspection_toast.success
							left_icon = scope:dutiful_spouse
				
							scope:frontier_fort_county = {
								add_county_modifier = {
									modifier = fp3_boosted_frontier_morale_county_modifier
									years = 15
								}
							} 
						}
					}	
				}
				20 = {
					compare_modifier = {
						value = scope:duel_value
						multiplier = -1
					}
					root = {
						send_interface_toast = {
							title = delegated_fortress_inspection_toast.failure
							left_icon = scope:tension_councillor

							scope:frontier_fort_county = {
								add_county_modifier = {
									modifier = fp3_low_frontier_morale_county_modifier
									years = 10
								}
							}
						}
					}
				}
			}
		}

		scope:dutiful_spouse = {
			add_character_modifier = {	
				modifier = fp3_visited_the_frontier_modifier
				years = 5
			}
		}

		stress_impact = { 
   			lazy = minor_stress_impact_loss
   			craven = minor_stress_impact_loss 
   			cynical = minor_stress_impact_loss
   			ambitious = minor_stress_impact_gain
   			brave = minor_stress_impact_gain
   			diligent = minor_stress_impact_gain	
   		}

		ai_chance = { #craven but sociable AI prefer this option
        	base = 100
        	ai_value_modifier = {
           		ai_boldness = -1
           		ai_rationality = 0.5
           		ai_sociability = 1 
        	}
   		} 
	}

	option = { #Make vague promises
		name = fp3_yearly.8001.c
		flavor = fp3_yearly.8001.flavor.c.tt

		duel = { #this duel is root trying to appease the councillor 
			skill = diplomacy
			value = medium_skill_rating

			20 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 2
				}
				modifier = {
					add = 15
					has_trait = deceitful 
				}
				modifier = {
					add = 40
					scope:concerned_councillor = {
						has_trait = trusting
					}		
				}
				modifier = {
					add = 20
					scope:concerned_councillor = {
						OR = {
							has_trait = craven 
							has_trait = patient
						}
					}		
				}
				send_interface_toast = {
					title = convincing_councillor_toast.success
					left_icon = root
					right_icon = scope:concerned_councillor

					scope:concerned_councillor = {
						add_opinion = {
							target = root 
							modifier = trusting_liege_opinion
						}
					}			
				}
			}
			20 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -1
				}
				modifier = {
					add = 20
					has_trait = honest
				}
				modifier = {
					add = 10
					has_trait = brave
				}
				send_interface_toast = {
					title = convincing_councillor_toast.failure
					left_icon = root
					right_icon = scope:concerned_councillor
					
					scope:concerned_councillor = {
						add_opinion = {	
							target = root 
							modifier = weak_excuses
						}	
					}
				}
			}
		} 

		random = {
			chance = 33
			scope:frontier_fort_county = {
				add_county_modifier = {
					modifier = fp3_low_frontier_morale_county_modifier
					years = 10
				}
			} 
		}

		stress_impact = { 
   			lazy = minor_stress_impact_loss
   			craven = major_stress_impact_loss 
   			content = minor_stress_impact_loss
   			arrogant = minor_stress_impact_loss 
   			paranoid = minor_stress_impact_loss 
   			diligent = medium_stress_impact_gain
   			honest = medium_stress_impact_gain 
   			
   		}

		ai_chance = { #craven but energetic AI prefer this option
        	base = 100
        	ai_value_modifier = {
           		ai_boldness = -1
           		ai_rationality = 0.5
           		ai_energy = 1 
        	}
   		} 	
	}

	option = { #Refuse
		name = fp3_yearly.8001.d

		random = {
			chance = 50 
			scope:frontier_fort_county = {
				add_county_modifier = {
					modifier = fp3_low_frontier_morale_county_modifier
					years = 10
				}
			} 
		}

		stress_impact = { 
   			lazy = major_stress_impact_loss
   			craven = medium_stress_impact_loss 
   			content = minor_stress_impact_loss
   			diligent = medium_stress_impact_gain
   			brave = minor_stress_impact_gain 
   			zealous = minor_stress_impact_gain 
   		}

		ai_chance = { #lazy, craven AI prefer this option
        	base = 100
        	ai_value_modifier = {
           		ai_boldness = -1
           		ai_energy = -1 
        	}
   		} 	
	}				
}

############
scripted_trigger fp3_yearly.8002_zealous_vassal_or_spouse_trigger = {
	AND = {
		faith = root.faith
		is_available_healthy_ai_adult = yes
		OR = {
			has_trait = zealous 
			has_trait = faith_warrior
			has_trait = crusader_king 
   			has_trait = order_member
		}
	}
}

fp3_yearly.8002 = { #Faith at the Frontier
	type = character_event
	title = fp3_yearly.8002.t
	desc = fp3_yearly.8002.desc
	theme = faith 

	left_portrait = {
		character = root
		animation = stress
	}
	right_portrait = {
		character = scope:concerned_person
		animation = worry
	}

	trigger = {
		has_fp3_dlc_trigger = yes
		age >= 12
		is_ruler = yes
		any_held_county = {
			any_county_province = {
				fp3_yearly.8001_outlying_province_trigger = yes 
			}
		}

		root.capital_province = { geographical_region = world_persian_empire } #so that this inside-to-outside worldview makes sense 

		faith = { #so that the plot makes sense 
			NOR = {
				has_doctrine_parameter = unreformed # Unreformed Pagans don't need frontier fortresses, generally speaking
				has_doctrine = doctrine_pluralism_pluralistic
			}
		}

		OR = { #Either could make sense, may as well make it as flexible as possible
			any_spouse = { 
				fp3_yearly.8002_zealous_vassal_or_spouse_trigger = yes
			}
			any_powerful_vassal = { 
				fp3_yearly.8002_zealous_vassal_or_spouse_trigger = yes
			}
			exists = cp:councillor_court_chaplain 
		}	
	}

	cooldown = {
		years = 50 
	}

	immediate = { #finding a nice location for the event
		random_held_county = {
			limit = {
				any_county_province = { 
					fp3_yearly.8001_outlying_province_trigger = yes  		
				}			
			}
			weight = {
				modifier = {
					factor = 100
					any_county_province = { 
						geographical_region = dlc_fp3_greater_persian_frontier_regions
					}
				}
			}
			save_scope_as = frontier_fort_county	
		}

		scope:frontier_fort_county = {
			add_county_modifier = {
				modifier = fp3_frontier_heresy_county_modifier
				years = 40
			} 
		}

		if = {
			limit = { current_year >= 1050 	}
			faith.religion = {
				random_faith = { #here we're setting up a nice heresy for the event
					limit = { #some faiths didn't exist in the early period, and were extinct by the latter
						this != root.faith
						fervor > medium_fervor_value
						OR = {
							this = faith:nizari
							this = faith:zayidi 
							this = faith:qarmatian
							this = faith:zurvanism
							this = faith:khurramism
							this = faith:nestorian
							this = faith:manichean
							this = faith:mahayana
						}
					}
					alternative_limit = { #just a failsafe to avoid errors
						this != root.faith
					}
					save_scope_as = regional_heresy
				}		
			}
		}
		else = {
			faith.religion = {
				random_faith = { #here we're setting up a nice heresy for the event
					limit = { #some faiths didn't exist in the early period
						this != root.faith
						fervor > medium_fervor_value
						OR = {
							this = faith:azariqa 
							this = faith:mutazila 
							this = faith:ghulat
							this = faith:zayidi 
							this = faith:zurvanism
							this = faith:khurramism
							this = faith:mazdakism 
							this = faith:nestorian
							this = faith:manichean #the "Arch-Heresy" according to Cambridge History of Iran ^_^
							this = faith:zun_pagan
							this = faith:mahayana
						}
					}
					alternative_limit = { #just a failsafe to avoid errors
						this != root.faith
					}
					save_scope_as = regional_heresy
				}		
			}
		}
		
		if = {
			limit = { 
				any_spouse = { 
					fp3_yearly.8002_zealous_vassal_or_spouse_trigger = yes
				}
			}
			random_spouse = {
				limit = { 
					fp3_yearly.8002_zealous_vassal_or_spouse_trigger = yes
				}
				save_scope_as = concerned_person	
			}
		}
		else_if = {
			limit = { 
				any_powerful_vassal = { 											fp3_yearly.8002_zealous_vassal_or_spouse_trigger = yes 	
				}
			}
			random_powerful_vassal = {
				limit = { 
					fp3_yearly.8002_zealous_vassal_or_spouse_trigger = yes
				}
				save_scope_as = concerned_person	
			}
		}
		else = {
			cp:councillor_court_chaplain = { save_scope_as = concerned_person }
		}
	}

	option = { #Burn them all and let God sort them out
		name = fp3_yearly.8002.a

		trigger = {
			OR = {
				has_trait = zealous
				has_trait = wrathful
				has_trait = paranoid 
				has_trait = faith_warrior
				has_trait = crusader_king 
				dread >= high_dread
			}
		}

		add_dread = major_dread_gain

		scope:concerned_person = {
			if = {
				limit = {
					OR = { #if the concerned person has a... certain personality, they appreciate this
						has_trait = sadistic
						has_trait = callous 
						has_trait = paranoid
						has_trait = vengeful 
					}
				}
				add_opinion = {
					target = root
					opinion = 20
					modifier = fp3_admires_resolve_opinion
				}
			}
			else = { 
				add_opinion = { #but otherwise, they're kinda shocked
					target = root
					opinion = -20
					modifier = fp3_mildly_terrified_opinion
				}
			}
		}

		scope:frontier_fort_county = {
			add_county_modifier = {
				modifier = fp3_garrison_decimated_county_modifier 
				years = 10
			} 
		}


		random_list = {
			75 = {
				custom_tooltip = fp3_county_pacified.tt
				scope:frontier_fort_county = {
					remove_county_modifier = fp3_frontier_heresy_county_modifier
				}
			}
			25 = {
				custom_tooltip = fp3_county_galvanized.tt
				scope:frontier_fort_county = {
					set_county_faith = scope:regional_heresy 
				}
			}
		}

		stress_impact = { 
   			sadistic = major_stress_impact_loss
   			callous = medium_stress_impact_loss
   			wrathful = minor_stress_impact_loss 
   			zealous = minor_stress_impact_loss
   			greedy = minor_stress_impact_loss  
   			compassionate = massive_stress_impact_gain 
   			just = major_stress_impact_gain 

   			
   		}

		ai_chance = { #cruel, zealous AI prefer this option
        	base = 100
        	ai_value_modifier = {
           		ai_zeal = 1
           		ai_vengefulness = 1
           		ai_compassion = -1
           		ai_honor = -0.5
           		ai_rationality = -0.5 
        	}
   		} 
	}

	option = { #Join their faith
		name = fp3_yearly.8002.b

		trigger = {
			OR = {
				has_trait = cynical
				has_trait = fickle
				has_trait = humble
				has_trait = depressed
				has_trait = lunatic
				has_trait = possessed
				has_trait = lifestyle_mystic
				stress_level >= 3
			}
			NOT = {
				has_trait = zealous
			}
		}

		add_piety = medium_piety_loss
		set_character_faith_with_conversion = scope:regional_heresy

		scope:frontier_fort_county = {
			add_county_modifier = {
				modifier = tensions_eased_province_modifier
				years = 20
			}
		}

		scope:concerned_person = {
			add_opinion = {	
				target = root 
				modifier = perplexed_opinion
				opinion = -20
			}
		}

		stress_impact = { 
   			cynical = major_stress_impact_loss
   			humble = medium_stress_impact_loss
   			brave = minor_stress_impact_loss 
   			fickle = minor_stress_impact_loss 
   			content = medium_stress_impact_gain 
   			craven = medium_stress_impact_gain 
   			
   		}

		ai_chance = { #bold, cynical AI prefer this option
        	base = 40 #so that the AI is less likely to take this option
        	ai_value_modifier = {
           		ai_boldness = 0.7
           		ai_energy = 0.5
           		ai_rationality = 0.7
           		ai_zeal = -1 
        	}
   		} 	
	}

	option = { #Send them to preach
		name = fp3_yearly.8002.c

		scope:concerned_person = {
			if = {
				limit = {
					OR = { #if the concerned person has a... certain personality, or is very able to perform the task, they're okay with this
						has_trait = dull
						has_trait = intellect_bad
						has_trait = diligent
						learning >= good_skill_level
					}
				}
				add_opinion = {
					target = root
					opinion = 10
					modifier = trusted_me_opinion
				}
			}
			else = { 
				add_opinion = { #but otherwise, they see it for what it is; a mild insult
					target = root
					opinion = -10
					modifier = unfair_expectations_opinion
				}
			}
		}

		scope:concerned_person = {
			add_character_modifier = {	
				modifier = fp3_visited_the_frontier_modifier
				years = 5
			}
		}

		scope:concerned_person = {
			duel = {
			skill = learning
			value = average_skill_rating

				20 = {
					compare_modifier = {
						value = scope:duel_value
						multiplier = 2
					}
					root = {
						send_interface_toast = {
							title = dealing_with_soldier_heresy_toast.success
							left_icon = scope:concerned_person
				
							custom_tooltip = fp3_county_converted.tt
							scope:frontier_fort_county = {
								remove_county_modifier = fp3_frontier_heresy_county_modifier
							} 
						}
					}	
				}
				20 = {
					compare_modifier = {
						value = scope:duel_value
						multiplier = -1
					}
					root = {
						send_interface_toast = {
							title = dealing_with_soldier_heresy_toast.failure
							left_icon = scope:concerned_person

							custom_tooltip = fp3_county_galvanized.tt
							scope:frontier_fort_county = {
								set_county_faith = scope:regional_heresy 
							}
							if = {
								limit = { 
									NOT = {
										scope:concerned_person = { has_trait = depressed }
									}
								}
								random = {
									chance = 10
									scope:concerned_person = { add_trait = depressed_1 }
								}	
							}
						}
					}
				}
			}
		}

		stress_impact = { 
   			lazy = major_stress_impact_loss
   			shy = minor_stress_impact_loss
   			trusting = minor_stress_impact_loss 
   			arrogant = minor_stress_impact_loss 
   			brave = minor_stress_impact_loss 
   			zealous = minor_stress_impact_loss 
   			ambitious = minor_stress_impact_gain 
   			diligent = medium_stress_impact_gain 	
   		}

		ai_chance = { #hands-off/rational AI prefer this option
        	base = 100
        	ai_value_modifier = {
           		ai_vengefulness = 0.5
           		ai_rationality = 0.5
           		ai_zeal = 0.2 
           		ai_energy = -0.5   		   		
        	}
   		} 
	}

	option = { #We should wait and see how the situation develops 
		name = fp3_yearly.8002.d

		random_list = {	
			50 = {
				send_interface_toast = {
					title = frontier_heresy_eased
					left_icon = scope:root
					
					scope:frontier_fort_county = {
						add_county_modifier = {
							modifier = tensions_eased_province_modifier
							years = 20
						}
					}
				}
			}
			50 = {
				send_interface_toast = {
					title = frontier_heresy_mega_outbreak
					left_icon = scope:root
						
					scope:frontier_fort_county = {	set_county_faith = scope:regional_heresy }
				}
			}
		}

		scope:concerned_person = {
			add_opinion = {	
				target = root 
				modifier = disappointed_opinion
				opinion = -20
			}
		}

		stress_impact = { 
   			patient = medium_stress_impact_loss 
   			calm = minor_stress_impact_loss
   			cynical = minor_stress_impact_loss
   			content = minor_stress_impact_loss 
   			wrathful = minor_stress_impact_gain
   			zealous = massive_stress_impact_gain
   			paranoid = medium_stress_impact_gain
   			impatient = medium_stress_impact_gain 	
   		}

		ai_chance = { #passive or compassionate AI prefer this optio
        	base = 100
        	ai_value_modifier = {
           		ai_compassion = 1
           		ai_honor = 0.5
           		ai_zeal = -1
           		ai_vengefulness = -0.5
        	}
   		} 			
	}						
}

#######Exotic Espand, by Ola Jentzsch#####

scripted_trigger fp3_yearly_8003_far_away_mountain_trigger = {
	county_has_province_with_terrain = {
		terrain = mountains
		terrain = desert_mountains
	}
	squared_distance = {
		target = root.capital_province
		value > squared_distance_large
	}
}


fp3_yearly.8003 = { #Exotic Espand 
	type = character_event
	title = fp3_yearly.8003.t
	desc = fp3_yearly.8003.desc
	theme = mental_health

	left_portrait = {
		character = scope:superstitious_consort
		animation = paranoia
	}
	right_portrait = {
		character = root
		animation = personality_rational
	}

	lower_left_portrait = { character = scope:cruel_consort  }
	lower_right_portrait = { character = scope:quest_chaplain }

	trigger = { #the wonders of harem intrigues! 

		has_fp3_dlc_trigger = yes
		is_ruler = yes

		root.capital_province = { 
			OR = {
				geographical_region = world_persian_empire
				geographical_region = world_steppe_tarim 
			}
		} 

		any_county_in_region = {
			region = world_persian_empire
			region = world_steppe_tarim
			region = world_himalaya
			region = world_middle_east_arabia
			fp3_yearly_8003_far_away_mountain_trigger = yes
		}

		any_consort = { 
			NOT = { 
				has_trait = cynical 
				has_trait = lifestyle_herbalist
				learning >= good_skill_level
			}
			is_courtier = yes 
			is_available_adult = yes
			save_temporary_scope_as = consort_1
		}

		any_consort = {
			this != scope:consort_1
			is_available_adult = yes
			is_courtier = yes 
			opinion = { 
				target = scope:consort_1 
				value < 0
			}
		}
	}

	cooldown = { 
		years = 10
	}

	immediate = {

		random_consort = {
			limit = {
				NOT = { 
					has_trait = cynical 
					has_trait = lifestyle_herbalist
					learning >= good_skill_level
				}
				is_available_adult = yes
				is_courtier = yes 
				save_temporary_scope_as = consort_1_temp
				root = {
					any_consort = {
						this != scope:consort_1_temp
						is_available_adult = yes
						is_courtier = yes 
						opinion = {
							target = scope:consort_1_temp
							value < 0
						}
					}
				}
			}
			save_scope_as = superstitious_consort
		}
		random_consort = {
			limit = {
				this != scope:superstitious_consort
				is_available_adult = yes
				is_courtier = yes 
				opinion = {
					target = scope:superstitious_consort
					value < 0
				}
			}
			save_scope_as = cruel_consort
		}

		random_county_in_region = {
			region = world_persian_empire
			region = world_steppe_tarim
			region = world_himalaya
			region = world_middle_east_arabia
			limit = { fp3_yearly_8003_far_away_mountain_trigger = yes }
			save_scope_as = espad_mountain_province #this is only used for loc
		}

		scope:superstitious_consort = {
			add_character_modifier = {
				modifier = fp3_jinx_modifier
				years = 10
			}
		}

		if = {	
			limit = { 
				exists = cp:councillor_court_chaplain 
				cp:councillor_court_chaplain = { is_available_healthy_ai_adult = yes }
			}
			cp:councillor_court_chaplain = { save_scope_as = quest_chaplain }
		}
	}

	option = { #Trust in God, not your superstition
		name = fp3_yearly.8003.a

		trigger = {
			faith = {
				OR = {
					has_doctrine_parameter = witchcraft_illegal
					has_doctrine_parameter = witchcraft_shunned 
				}
			}
		}

		add_piety = minor_piety_gain 

		scope:superstitious_consort = { #if (s)he loves you or is forgiving, (s)he takes this less hard
			if = {
				limit = { 
					OR = { 
						has_relation_lover = root
						has_relation_soulmate = root 
						has_trait = forgiving 
					}
				}
				add_opinion = {
					target = root
					modifier = disappointed_opinion
					opinion = -20
				}
			}	
			else = {
				add_opinion = {
					target = root
					modifier = cruelty_opinion
					opinion = -40
				}
			}	
		}

		scope:cruel_consort = {
			add_opinion = {
				target = root
				modifier = pleased_opinion
				opinion = 20	
			}
		}

		stress_impact = { 
   			arrogant = minor_stress_impact_loss 
   			callous = minor_stress_impact_loss 
   			zealous = minor_stress_impact_loss 
   			compassionate = medium_stress_impact_gain
   			generous = medium_stress_impact_gain	 
   			humble = minor_stress_impact_gain	
   		}

		ai_chance = { #cruel or zealous AI prefers this option
        	base = 100
        	ai_value_modifier = {
           		ai_zeal = 0.5
           		ai_vengefulness = 0.5
           		ai_compassion = -1  		   		
        	}
   		} 
	}

	option = { #Cost what it may, I will send for it
		name = fp3_yearly.8003.b

		scope:superstitious_consort = { 
			if = {
				limit = { 
					OR = { 
						has_relation_lover = root
						has_relation_soulmate = root 
					}
				}
				add_opinion = {
					target = root
					modifier = grateful_opinion
					opinion = 20 
				}
			}	
			else = {
				custom_tooltip = fp3_closer_to_love.tt
				hidden_effect = {
					root = {
						progress_towards_lover_effect = {
							CHARACTER = scope:superstitious_consort
							REASON = lover_gave_fine_seeds # Naming conv. DLC_progress_towards_reason_TYPE_NAME. This will avoid dupes and conflicts. -h
							OPINION = 20 
						}
					}
				}
			}	
		}

		scope:cruel_consort = {
			add_opinion = {
				target = scope:superstitious_consort 
				modifier = envy_opinion
				opinion = -20	
			}
		}

		scope:cruel_consort = {
			add_opinion = {
				target = root
				modifier = fp3_resentful_opinion
				opinion = -20	
			}
		}

		remove_short_term_gold = medium_gold_value #this will be expensive!

		random = {
			chance = 75
			scope:superstitious_consort = {
				remove_character_modifier = fp3_jinx_modifier
			}
		}

		stress_impact = { 
   			generous = major_stress_impact_loss 
   			compassionate = minor_stress_impact_loss 
   			diligent = minor_stress_impact_loss 
   			zealous = minor_stress_impact_loss 
   			greedy = medium_stress_impact_gain
   			callous = medium_stress_impact_gain	 
   			cynical = miniscule_stress_impact_gain
   			temperate = miniscule_stress_impact_gain	
   		}

		ai_chance = { #compassionate, energetic, non-frugal AI prefers this option
        	base = 100
        	ai_value_modifier = {
           		ai_compassion = 0.7
           		ai_energy = 0.7
           		ai_greed = -1  		   		
        	}
   		} 
	}

	option = { #I can send my court chaplain, (s)he is very capable 
		name = fp3_yearly.8003.c


		trigger = { exists = scope:quest_chaplain }

		scope:quest_chaplain = {
			if = {
				limit = {
					OR = { #if the chaplain is adventurous or a nature specialist, or thinks very highly of the consort, (s)he appreciates the task
						has_trait = brave
						has_trait = adventurer 
						has_trait = lifestyle_herbalist 
						has_trait = lifestyle_mystic 
						has_trait = diligent
						opinion = { 
							target = scope:superstitious_consort
							value > 50
						}
					}
				}
				add_opinion = {
					target = root
					opinion = 10
					modifier = trusted_me_opinion
				}
			}
			else = { 
				add_opinion = { #but otherwise, don't really wanna go
					target = root
					modifier = fp3_sent_me_to_the_frontier_opinion
				}
			}
		}

		scope:quest_chaplain = {
			add_character_modifier = {	
				modifier = fp3_visited_the_frontier_modifier
				years = 5
			}
		}

		scope:quest_chaplain = {
			duel = {
			skill = learning
			value = average_skill_rating

				20 = {
					compare_modifier = {
						value = scope:duel_value
						multiplier = 2
					}
					root = {
						send_interface_toast = {
							title = questing_for_espand_toast.success
							left_icon = scope:quest_chaplain
							right_icon = scope:superstitious_consort
				
							custom_tooltip = fp3_espand_found.tt
							scope:superstitious_consort = {
								remove_character_modifier = fp3_jinx_modifier
							} 
						}
					}	
				}
				20 = {
					compare_modifier = {
						value = scope:duel_value
						multiplier = -1
					}
					root = {
						send_interface_toast = {
							title = questing_for_espand_toast.failure
							left_icon = scope:quest_chaplain
							right_icon = scope:superstitious_consort

							custom_tooltip = fp3_espand_unfound.tt
							scope:quest_chaplain = {
								add_character_modifier = {
									modifier = exhausted_modifier
									years = 10
								}
							}
							if = {
								limit = { 
									NOT = {
										scope:superstitious_consort = { has_trait = depressed }
									}
								}
								random = {
									chance = 20
									scope:superstitious_consort = { add_trait = depressed_1 }
								}	
							}
						}
					}
				}
			}
		}

		stress_impact = { 
   			lazy = medium_stress_impact_loss 
   			greedy = minor_stress_impact_loss 
   			trusting = minor_stress_impact_loss 
   			compassionate = minor_stress_impact_loss 
   			diligent = medium_stress_impact_gain 	
   		}

		ai_chance = { #compassionate but frugal AI prefer this option
        	base = 100
        	ai_value_modifier = {
           		ai_compassion = 1
           		ai_rationality = 0.5
           		ai_greed = -1
           		ai_energy = -0.5   		   		
        	}
   		} 
	}

	option = { #Can't you pick normal espand like everyone else? 
		name = fp3_yearly.8003.d

		scope:superstitious_consort = { #if (s)he has particular traits, (s)he takes this very hard 
			if = {
				limit = { 
					OR = { 
						has_trait = craven
						has_trait = paranoid
						has_trait = vengeful 
						has_trait = lifestyle_mystic
						has_trait = arrogant
						has_trait = greedy 
						has_trait = stubborn 
						has_trait = wrathful   
					}
				}
				add_opinion = {
					target = root
					modifier = mocked_me_in_time_of_need
				}
			}	
			else = {
				add_opinion = {
					target = root
					modifier = fp3_ignored_me_in_time_of_need_opinion
				}
			}	
		}

		scope:cruel_consort = {
			add_opinion = {
				target = root
				modifier = amused_opinion
				opinion = 10	
			}
		}

		stress_impact = { 
   			cynical = minor_stress_impact_loss 
   			callous = minor_stress_impact_loss 
   			temperate = minor_stress_impact_loss 
   			compassionate = medium_stress_impact_gain
   			generous = medium_stress_impact_gain
   		}

		ai_chance = { #cynical and frugal AI prefers this option
        	base = 100
        	ai_value_modifier = {
           		ai_rationality = 1
           		ai_greed = -1
           		ai_compassion = -0.5   		   		
        	}
   		} 
	}
}


####The Frontier's Call, by Ola Jentzsch####

scripted_trigger fp3_suitable_child_to_leave = {
	is_physically_able_adult = yes
	is_courtier_of = root
	age < 40
	is_concubine = no
	OR = { #checking that they're the venturesome type
		has_trait = brave
		has_trait = impatient 
		has_trait = lifestyle_hunter
		has_trait = education_martial
  		has_lifestyle = martial_lifestyle
  		has_martial_lifestyle_trait_trigger = yes
   		martial >= high_skill_rating
   		prowess >= high_skill_rating  
	}
	NOR = { #and that their cravings aren't already satisfied
		has_trait = faith_warrior
		has_trait = pilgrim 
		has_trait = adventurer
		has_trait = viking 
		has_trait = content
	}
	can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = root } #and that them wanting to go on adventure wouldn't be preposterous in your culture 
}

scripted_trigger fp3_suitable_relation_for_child = {
	NOT = { this = $CHAR$ }
	age >= 10
	OR = {
		is_close_family_of = $CHAR$
		is_spouse_of = $CHAR$
		is_concubine_of = $CHAR$
		is_great_grandparent_of = $CHAR$
		has_relation_friend = $CHAR$
		has_relation_lover = $CHAR$
		AND = {
			betrothed = $CHAR$
			age >= 14
		}
	}	
	NOR = {
		has_trait = brave
		has_trait = callous
		has_trait = arrogant 
	}
	opinion = { 
		target = $CHAR$
		value > 15
	}
}

scripted_effect fp3_child_leaves_effect = {
	move_to_pool_at = scope:far_frontier
	scope:parent = {
		if = {
			limit = {
				has_hook = scope:fp3_child_to_leave
			}
			remove_hook = {
				target = scope:fp3_child_to_leave
			}
		}
	}
	add_character_modifier = {
		modifier = fp3_call_of_the_wild_modifier 
		years = 25
	}
}

fp3_yearly.8004 = { #The Frontier Beckons
	type = character_event
	title = fp3_yearly.8004.t
	desc = fp3_yearly.8004.desc
	theme = family
	left_portrait = {
		character = scope:fp3_child_to_leave
		animation = personality_bold
	}
	right_portrait = {
		character = scope:worried_relation
		animation = grief
	}
	override_background = { reference = market_east }

	trigger = {

		#DLC check.
		has_fp3_dlc_trigger = yes

		is_available = yes 
		
		root.capital_province = { geographical_region = world_persian_empire }

		NAND = { #because this event is a Persian variant of an FP1 event, it's better that both cannot trigger for vikings
			has_fp1_dlc_trigger = yes
			culture = { has_cultural_pillar = heritage_north_germanic }
		}
		
		any_child = {
			fp3_suitable_child_to_leave = yes
			save_temporary_scope_as = fp3_child_to_leave_temp
		}
		
		any_courtier_or_guest = { 
			fp3_suitable_relation_for_child = { CHAR = scope:fp3_child_to_leave_temp }
		}

		any_independent_ruler = {
			NOT = {
				target_is_liege_or_above = root 
			}
			in_diplomatic_range = root 
			any_realm_province = { 
				geographical_region = dlc_fp3_greater_persian_frontier_regions
				save_temporary_scope_as = place		
			}
		}
		scope:place = {
			squared_distance = {
				target = root.capital_county
				value >= squared_distance_large
			}
		}			
	}

	cooldown = { years = 10 }

	immediate = { 

		save_scope_as = parent

		random_child = {
			limit = {
				fp3_suitable_child_to_leave = yes
				has_personality_dominant_trigger = yes
				is_primary_heir_of = root
			}
			alternative_limit = {
				fp3_suitable_child_to_leave = yes
				has_personality_dominant_trigger = yes
			}
			alternative_limit = {
				fp3_suitable_child_to_leave = yes
			}
			save_scope_as = fp3_child_to_leave
		}

		random_courtier_or_guest = { #weighting for the most suitable person!
			limit = {	
				fp3_suitable_relation_for_child = { CHAR = scope:fp3_child_to_leave }
			}
			save_scope_as = worried_relation
		}

		random_independent_ruler = {
			limit = {
				NOT = {
					target_is_liege_or_above = root 
				}
				in_diplomatic_range = root
				any_realm_province = {	
					geographical_region = dlc_fp3_greater_persian_frontier_regions
					save_temporary_scope_as = place 
				}
				scope:place = {
					squared_distance = {
						target = root.capital_county
						value >= squared_distance_large
					}
				}
			}
			random_realm_province = {
				limit = {
					geographical_region = dlc_fp3_greater_persian_frontier_regions
					save_temporary_scope_as = place
					scope:place = {
						squared_distance = {
							target = root.capital_county
							value >= squared_distance_large
						}
					}
				}
				save_scope_as = far_frontier
			}			
		}
	}

	option = { # Fight them to make them stay
		name = fp3_yearly.8004.a
		
		trigger = {
			culture = { 
				OR = {
					has_cultural_tradition = tradition_futuwaa 
					has_cultural_tradition = tradition_fp1_performative_honour
					has_cultural_tradition = tradition_warrior_culture 
				}
			}
			can_start_single_combat_trigger = yes
			scope:fp3_child_to_leave = {
				can_start_single_combat_trigger = yes
			}
		}
		custom_tooltip = fp3_yearly.8004.a.tt
		
		configure_start_single_combat_effect = {
			SC_INITIATOR = scope:parent
			SC_ATTACKER = scope:parent
			SC_DEFENDER = scope:fp3_child_to_leave
			FATALITY = no
			FIXED = no
			LOCALE = terrain_scope
			OUTPUT_EVENT = fp3_yearly.8005
			INVALIDATION_EVENT = fp3_yearly.8006
		}

		stress_impact = {
			craven = major_stress_impact_gain
			forgiving = medium_stress_impact_gain
			compassionate = medium_stress_impact_gain
			calm = medium_stress_impact_gain
			temperate = minor_stress_impact_gain
			generous = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			
			modifier = {
				factor = 2
				prowess > scope:fp3_child_to_leave.prowess
			}
			
			modifier = {
				factor = 0.1
				ai_compassion >= medium_positive_ai_value
			}
			
			modifier = {
				factor = 0
				OR = {
					has_trait = craven
					has_trait = forgiving
					has_trait = calm
				}
			}
		}
	}

	option = { # Appeal to their better nature
		name = fp3_yearly.8004.b

		stress_impact = {
			impatient = major_stress_impact_gain
			wrathful = major_stress_impact_gain
			arrogant = medium_stress_impact_gain
			fickle = medium_stress_impact_gain
			vengeful = minor_stress_impact_gain
		}

		scope:worried_relation = {
			add_opinion = {
				target = root
				modifier = grateful_opinion
				opinion = 20	
			}
		}
		
		duel = {
			skill = diplomacy
			value = scope:fp3_child_to_leave.diplomacy

			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}

				desc = fp3_yearly.8004.b.success
				send_interface_toast = {
					title = fp3_yearly.8004.b.success
					left_icon = scope:fp3_child_to_leave


					add_prestige = medium_prestige_gain
					
					scope:fp3_child_to_leave = {
						custom_tooltip = fp1_yearly.2000.b.tt #reuse from FP1 to save translation 
						add_character_modifier = {
							modifier = fp3_dutiful_scion_modifier 
							years = 25
						}
					}
				}
			}
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}

				desc = fp3_yearly.8004.b.failure
				send_interface_toast = {
					title = fp3_yearly.8004.b.failure
					left_icon = scope:fp3_child_to_leave

					add_prestige = major_prestige_loss
					
					scope:fp3_child_to_leave = {
						fp3_child_leaves_effect = yes 
					}
					scope:worried_relation = {
						add_character_modifier = {
							modifier = fp3_worried_sick_modifier
							years = 5
						}
					}
				}
			}
		}
		
		ai_chance = {
			base = 100
			
			modifier = {
				factor = 2
				diplomacy > scope:fp3_child_to_leave.diplomacy
			}
			
			modifier = {
				factor = 0
				OR = {
					has_trait = craven
					has_trait = forgiving
					has_trait = calm
				}
			}
		}
	}

	option = { # Treathen to disinherit
		name = fp3_yearly.8004.c
		flavor = fp3_yearly.8004.c.flavor 

		stress_impact = {
			impatient = major_stress_impact_gain
			wrathful = major_stress_impact_gain
			arrogant = medium_stress_impact_gain
			fickle = medium_stress_impact_gain
			vengeful = minor_stress_impact_gain
		}
		
		duel = {
			skill = intrigue
			value = scope:fp3_child_to_leave.intrigue

			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}

				desc = fp3_yearly.8004.b.success
				send_interface_toast = {
					title = fp3_yearly.8004.b.success
					left_icon = scope:fp3_child_to_leave


					add_prestige = medium_prestige_gain
					
					scope:fp3_child_to_leave = {
						custom_tooltip = fp1_yearly.2000.b.tt #reuse from FP1 to save translation 
						add_character_modifier = {
							modifier = fp3_dutiful_scion_modifier 
							years = 25
						}	
					}
				}
			}
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}

				desc = fp3_yearly.8004.b.failure
				send_interface_toast = {
					title = fp3_yearly.8004.b.failure
					left_icon = scope:fp3_child_to_leave

					add_prestige = major_prestige_loss

					
					scope:fp3_child_to_leave = {
						fp3_child_leaves_effect = yes 
						add_trait = disinherited 
					}
					progress_towards_rival_effect = {
	 					CHARACTER = scope:fp3_child_to_leave
						REASON = rival_left_for_frontier
	 					OPINION = -25
					}
					scope:worried_relation = {
						add_character_modifier = {
							modifier = fp3_worried_sick_modifier
							years = 5
						}
					}
				}
			}
		}	
		
		ai_chance = {
			base = 100
			
			modifier = {
				factor = 2
				intrigue > scope:fp3_child_to_leave.intrigue
			}
			
			modifier = {
				factor = 0
				OR = {
					has_trait = compassionate
					has_trait = craven
					has_trait = forgiving
				}
			}
		}
	}

	option = { # Go in peace, my son/daughter
		name = fp3_yearly.8004.d

		scope:fp3_child_to_leave = {
			fp3_child_leaves_effect = yes  
		}

		if = {
			limit = {
				has_hook = scope:fp3_child_to_leave
			}
			remove_hook = {
				target = scope:fp3_child_to_leave
			}
		}

		scope:fp3_child_to_leave = {
			add_opinion = {
				target = root
				modifier = grateful_opinion
				opinion = 30 
			}
		}

		scope:worried_relation = {
			add_opinion = {
				target = root
				modifier = fp3_dismayed_opinion
			}
			add_character_modifier = {
				modifier = fp3_worried_sick_modifier
				years = 5
			}
		}

		stress_impact = { 
   			compassionate = medium_stress_impact_loss 
   			patient = medium_stress_impact_loss 
   			calm = minor_stress_impact_loss
   			content = minor_stress_impact_loss 
   			arrogant = minor_stress_impact_gain
   			wrathful = medium_stress_impact_gain
   			paranoid = medium_stress_impact_gain  
   		}

		ai_chance = { #passive or compassionate AI prefer this optio
        	base = 100
        	ai_value_modifier = {
           		ai_compassion = 1
           		ai_honor = 0.5
           		ai_zeal = -1
           		ai_vengefulness = -0.5
        	}
   		} 		
	}
}

############Minor events triggered by the duel in fp3_yearly.8004.a#############

#Hidden event, to set up the result of the duel
fp3_yearly.8005 = {
	hidden = yes

	immediate = {
		if = {
			limit = {
				scope:parent = scope:sc_victor
			}
			trigger_event = { id = fp3_yearly.8007 days = 1 }
		}
		else = {
			trigger_event = { id = fp3_yearly.8008 days = 1 }
		}
	}
}

#Hidden event; the bout became invalidated, inform affected parties.
fp3_yearly.8006 = {
	hidden = yes

	immediate = {
		# Inform both parties that the duel has invalidated.
		scope:parent = {
			send_interface_toast = {	
				title = fp1_yearly.2000.trigger_failure #reused from an fp1 event, so we can save some translation resources
				left_icon = scope:fp3_child_to_leave
			}
		}
	}
}

# Beat child in combat
fp3_yearly.8007 = {
	type = character_event
	title = fp3_yearly.8007.t
	desc = fp3_yearly.8007.desc
	theme = family
	left_portrait = {
		character = scope:fp3_child_to_leave
		animation = pain
	}
	right_portrait = {
		character = root
		animation = aggressive_sword
	}
	override_background = { reference = courtyard }

	trigger = {

	}

	immediate = {
		
	}

	option = { # I will not be found wanting
		name = fp3_yearly.8007.a
		
		add_piety = medium_piety_gain
		
		scope:fp3_child_to_leave = {
			add_character_modifier = {
				modifier = fp3_dutiful_scion_modifier 
				years = 25
			}
		}
		
		ai_chance = {
			base = 100
		}
	}

	option = { # # Good. I have real responsibilities for you.
		name = fp3_yearly.8007.b
		
		add_prestige = medium_prestige_gain
		
		scope:fp3_child_to_leave = {
			add_character_modifier = {
				modifier = fp3_dutiful_scion_modifier 
				years = 25
			}
		}
		
		ai_chance = {
			base = 100
		}
	}

	option = { #And now you must marry!
		name = fp3_yearly.8007.c

		trigger = {
			scope:fp3_child_to_leave = {
				AND = {
					is_married = no
					is_betrothed = no
				}
			}
		}
		
		root.dynasty = { add_dynasty_prestige = minor_dynasty_prestige_value }
		
		scope:fp3_child_to_leave = {
			add_character_modifier = {
				modifier = fp3_marriage_material_modifier
				years = 10
			}
		}
		
		ai_chance = {
			base = 100
		}
	}
}

# Beaten by child in combat
fp3_yearly.8008 = {
	type = character_event
	title = fp3_yearly.8008.t
	desc = fp3_yearly.8008.desc
	theme = family
	left_portrait = {
		character = root
		animation = fear
	}
	right_portrait = {
		character = scope:fp3_child_to_leave
		animation = aggressive_sword
	}
	override_background = { reference = courtyard }

	trigger = {

	}

	immediate = {
		
	}

	option = { # My child I can lose, but my gold... 
		name = fp3_yearly.8008.a

		trigger = {
			has_trait = greedy 
		}
		
		pay_short_term_gold = {
			target = scope:fp3_child_to_leave
			gold = minor_gold_value
		}
		
		add_stress = medium_stress_impact_gain 
		
		scope:fp3_child_to_leave = {
			fp3_child_leaves_effect = yes 
			if = {
				limit = { 
					NOT = { has_trait = lifestyle_blademaster }
				}
				add_trait = lifestyle_blademaster
			}
		}
		
		ai_chance = {
			base = 100
		}
	}

	option = { # It would have been better to be a eunuch...
		name = fp3_yearly.8008.b

		trigger = {
			is_female = no
			is_eunuch_trigger = no
		}
		
		pay_short_term_gold = {
			target = scope:fp3_child_to_leave
			gold = minor_gold_value
		}
		
		add_prestige = medium_prestige_loss
		
		scope:fp3_child_to_leave = {
			fp3_child_leaves_effect = yes 
			if = {
				limit = { 
					NOT = { has_trait = lifestyle_blademaster }
				}
				add_trait = lifestyle_blademaster
			}
		}
		
		ai_chance = {
			base = 100
		}
	}

	option = { # Fate will bring us together again, you will see. 
		name = fp3_yearly.8008.c
		
		pay_short_term_gold = {
			target = scope:fp3_child_to_leave
			gold = minor_gold_value
		}
		
		add_prestige = medium_prestige_loss
		
		scope:fp3_child_to_leave = {
			fp3_child_leaves_effect = yes 
			if = {
				limit = { 
					NOT = { has_trait = lifestyle_blademaster }
				}
				add_trait = lifestyle_blademaster
			}
		}
		
		ai_chance = {
			base = 100
		}
	}
}

#############################Duel events end############################
#########################################################################

#########Caliphal Concerns, by Ola Jentzsch################
scripted_trigger fp3_yearly.8009_frontier_heresy_trigger = {
	any_county_province = { geographical_region = dlc_fp3_eastern_persian_frontier_regions }
	faith = { save_temporary_scope_as = compare_faith }
	root.faith.religious_head = {
		faith = {
			faith_hostility_level = { target = scope:compare_faith value > faith_astray_level }
		}
	}
}

scripted_trigger fp3_yearly.8009_root_and_hof_faith_comparison_trigger = {
	faith = { save_temporary_scope_as = compare_faith }
	root = {
		faith = {
			faith_hostility_level = { target = scope:compare_faith value <= faith_astray_level }
		}
	}
}


fp3_yearly.8009 = {
	type = character_event
	title = fp3_yearly.8009.t
	desc = {
		desc = fp3_yearly.8009.desc_beginning
		first_valid = {
			triggered_desc = {
				trigger = {
					root.faith.religious_head = { 
						OR = { 
							has_religion = religion:islam_religion
							has_religion = religion:judaism_religion
						}
					}
				}
				desc = fp3_yearly.8009.desc_muslim_or_jewish_insult_ending
			}
			desc = fp3_yearly.8009.desc_other_insult_ending		
		}
	}
	theme = faith
	override_background = { reference = throne_room }
	
	left_portrait = {
		character = root
		animation = personality_rational
		triggered_animation = {
			trigger = {
				OR = {
					has_trait = vengeful
					has_trait = wrathful
					dread >= 50
					tyranny >= 50
				}
			}
			animation = personality_vengeful
		}
	}
	right_portrait = {
		character = scope:hof_emissary
		animation = chancellor
	}
	
	lower_left_portrait = { character = scope:righteous_caliph }
	lower_right_portrait = { character = scope:loyal_chaplain }

	trigger = {
		has_fp3_dlc_trigger = yes

		faith.religious_head != root

		exists = root.faith.religious_head

		root.faith.religious_head = { 
			is_ai = yes 
			fp3_yearly.8009_root_and_hof_faith_comparison_trigger = yes
			faith = { 
				NOR = {
					has_doctrine_parameter = unreformed
					has_doctrine_parameter = witchcraft_accepted
					has_doctrine = doctrine_pluralism_pluralistic
					has_doctrine = tenet_carnal_exaltation 
				}	
			}	
		}	

		any_held_county = {
			fp3_yearly.8009_frontier_heresy_trigger = yes 
			save_temporary_scope_as = heretic_county
		}
	}

	cooldown = { years = 25 }

	immediate = {

		random_held_county = {
			limit = { fp3_yearly.8009_frontier_heresy_trigger = yes }
			save_scope_as = very_heretic_county
		}

		if = { #this is a false safe due to the funkyness of the location system
    		limit = {
        		exists = root.faith.religious_head.location
    		}
    		root.faith.religious_head.location = {
        		save_scope_as = caliphal_location
    		}
		}
		else_if = {
    		limit = {
       			exists = root.faith.religious_head.primary_title.title_capital_county.title_province
   			}
    		root.faith.religious_head.primary_title.title_capital_county.title_province = {
        		save_scope_as = caliphal_location
    		}
		}
		else = {
   			random_province = {
        		save_scope_as = caliphal_location
    		}
		}

		root.faith.religious_head = { save_scope_as = righteous_caliph }
		
		create_character = { #this is the head of faith's emissary 
			age = { 25 75 } 
			location = root.capital_province
			faith = root.faith.religious_head.faith
			gender_female_chance = root_faith_dominant_gender_female_chance #could be female, if given the right context.  
			trait = diplomat  
			template = priest_character_template
			save_scope_as = hof_emissary 	#this saves him as a scope so we can get nice effects to bounce off him! 
		}

		if = {	
			limit = { 
				exists = cp:councillor_court_chaplain 
				cp:councillor_court_chaplain = { is_available_healthy_ai_adult = yes }
			}
			cp:councillor_court_chaplain = { save_scope_as = loyal_chaplain }
		}	
	}

	option = { #I shall stamp this heresy out 
		name = fp3_yearly.8009.a

		add_dread = medium_dread_gain

		add_character_modifier = {
			modifier = fp3_fearsome_example_modifier
			years = 20
		}

		scope:righteous_caliph = {
			if = {
				limit = {
					OR = { #if the HoF has a... certain personality, they appreciate this
						has_trait = sadistic
						has_trait = callous 
						has_trait = paranoid
						has_trait = vengeful 
					}
				}
				add_opinion = {
					target = root
					opinion = 30
					modifier = fp3_admires_resolve_opinion
				}
				root = { add_piety = minor_piety_gain }
			}
			else = { 
				add_opinion = { #but otherwise, they're kinda shocked
					target = root
					opinion = -10
					modifier = fp3_went_too_far_opinion
				}
			}
		}

		random_list = {
			70 = {
				send_interface_toast = {
				title = fp3_gross_persecutions_toast
					scope:very_heretic_county = {
						add_county_modifier = {
							modifier = fp3_gross_persecutions_county_modifier 
							years = 10
						}
					}
				}
			}
			30 = {
				send_interface_toast = {
				title = fp3_galvanized_heretics_toast
					scope:very_heretic_county = {
						add_county_modifier = {
							modifier = fp3_galvanized_heretics_county_modifier 
							years = 30
						}
					}
				}
			}
		}

		stress_impact = { 
   			sadistic = major_stress_impact_loss
   			callous = medium_stress_impact_loss
   			wrathful = minor_stress_impact_loss 
   			vengeful = minor_stress_impact_loss
   			zealous = minor_stress_impact_loss
   			compassionate = massive_stress_impact_gain 
   			just = major_stress_impact_gain 	
   		}

		ai_chance = { #cruel, zealous AI prefer this option
        	base = 100
        	ai_value_modifier = {
           		ai_zeal = 1
           		ai_vengefulness = 1
           		ai_boldness = 0.5
           		ai_compassion = -1
           		ai_honor = -0.5
           		ai_rationality = -0.5 
        	}
   		} 
	}

	option = { #I shall convert them in the proper language
		name = fp3_yearly.8009.b
		flavor = fp3_yearly.8009.qurans.flavor

		trigger = { #checking if the province and root is non-arabic and the caliph arabic

			scope:very_heretic_county.culture = { 
				NOT = { has_cultural_pillar = language_arabic }
			}

			culture = {
				NOT = { has_cultural_pillar = language_arabic }
			}

			root.faith.religious_head = { 
				culture = { has_cultural_pillar = language_arabic }
			}
		}

		add_piety = medium_piety_gain

		remove_treasury_or_gold = medium_treasury_or_gold_value 

		scope:righteous_caliph = {
			add_opinion = { 
				target = root
				opinion = 20
				modifier = pleased_opinion
			}
		}

		
		add_character_modifier = {
			modifier = fp3_promoting_arabic_modifier
			years = 20
		}


		if = {
			limit = { is_ai = no } #just so this doesn't get out of hand
			culture = {
				change_cultural_acceptance = {
					target = scope:righteous_caliph.culture
					value = low_positive_culture_acceptance
					desc = cultural_acceptance_gain_arabic_books	
				}
			}
		}

		stress_impact = {  
   			humble = minor_stress_impact_loss 
   			zealous = minor_stress_impact_loss
   			arrogant = minor_stress_impact_gain 
   		}

		ai_chance = { #loyal AI prefer this option
        	base = 100
        	ai_value_modifier = {
           		ai_zeal = 0.5
           		ai_honor = 0.5
        	}

        	modifier = {
				factor = 2
				OR = {
					has_trait = humble
					has_trait = trusting
					knows_language_of_culture = scope:righteous_caliph.culture
				}
			}
   		} 
	}


	option = { #My court chaplain can handle this
		name = fp3_yearly.8009.c

		trigger = { 

			exists = scope:loyal_chaplain 
		}

		add_piety = medium_piety_gain

		scope:righteous_caliph = {
			add_opinion = { 
				target = root
				opinion = 20
				modifier = pleased_opinion
			}
		}

		scope:loyal_chaplain = {
			add_character_modifier = {
				modifier = fp3_visited_the_frontier_modifier
				years = 5
			}
		}

		scope:loyal_chaplain = {
			duel = {
			skill = learning
			value = high_skill_rating

				20 = {
					compare_modifier = {
						value = scope:duel_value
						multiplier = 2
					}
					root = {
						send_interface_toast = {
							title = dealing_with_frontier_heresy_toast.success
							left_icon = scope:loyal_chaplain
				
							custom_tooltip = fp3_county_listened.tt
							scope:very_heretic_county = {
								add_county_modifier = {
									modifier = fp3_conversion_curious_county_modifier
									years = 20 
								}
							} 
						}
					}	
				}
				20 = {
					compare_modifier = {
						value = scope:duel_value
						multiplier = -1
					}
					root = {
						send_interface_toast = {
							title = dealing_with_frontier_heresy_toast.failure
							left_icon = scope:loyal_chaplain

							custom_tooltip = fp3_county_unfazed.tt
							scope:very_heretic_county = {
								add_county_modifier = {
									modifier = fp3_frontier_heresy_county_modifier
									years = 20
								}
							}
						}
					}
				}
			}
		}

		stress_impact = { 
   			zealous = minor_stress_impact_loss 
   			diligent = medium_stress_impact_gain 	
   		}

		ai_chance = { #zealous but frugal AI prefer this option
        	base = 100
        	ai_value_modifier = {
           		ai_zeal = 1
           		ai_rationality = 0.5
           		ai_greed = -1
           		ai_energy = -0.5   		   		
        	}
   		} 
	}

	option = { #I'm busy with other things 
		name = fp3_yearly.8009.d

		add_piety = medium_piety_loss 

		add_stress = medium_stress_loss

		scope:righteous_caliph = {
			add_opinion = { 
				target = root
				opinion = -20
				modifier = disappointed_opinion
			}
		}

		stress_impact = { 
   			content = medium_stress_impact_loss
   			cynical = minor_stress_impact_loss
   			lazy = minor_stress_impact_loss
   			zealous = medium_stress_impact_gain  
   			diligent = medium_stress_impact_gain 	
   		}

		ai_chance = { #lazy or cynical AI prefer this option
        	base = 100
        	ai_value_modifier = {
           		ai_zeal = 1
           		ai_rationality = 0.5
           		ai_boldness = -0.5
           		ai_energy = -0.5   		   		
        	}
   		} 
	}
}

#########Abode of War, by Ola Jentzsch################
scripted_trigger fp3_yearly.8010_super_evil_pagan_heretic_neighboring_ruler_trigger = {
	is_ai = yes
	OR = {
		top_liege = this
		top_liege = { is_ai = yes }
	}
	NOT = {
		is_allied_to = root
		is_vassal_of = root
		has_truce = root
		has_religion = root.faith.religious_head.religion	
	}	
}

fp3_yearly.8010 = {
	type = character_event
	title = fp3_yearly.8010.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					root.faith.religious_head = { has_religion = religion:islam_religion }
				}
				desc = fp3_yearly.8010.desc_muslim
			}
			desc = fp3_yearly.8010.desc_not_muslim		
		}
	}
	theme = war
	override_background = { reference = throne_room }
	
	left_portrait = {
		character = root
		animation = personality_cynical
	}
	right_portrait = {
		character = scope:righteous_caliph
		animation = personality_dishonorable
	}
	
	lower_left_portrait = { character = scope:pagan_ruler }

	trigger = {
		has_fp3_dlc_trigger = yes

		faith.religious_head != root

		exists = root.faith.religious_head

		root.faith.religious_head = { 
			is_available_healthy_ai_adult = yes 
			fp3_yearly.8009_root_and_hof_faith_comparison_trigger = yes # sanity check
			NOR = {
				has_trait = content
				has_trait = forgiving 
				has_trait = compassionate
				has_trait = just 
			}
			faith = { 
				NOR = {
					has_doctrine_parameter = unreformed
					has_doctrine = doctrine_pluralism_pluralistic
					has_doctrine_parameter = holy_wars_forbidden # Pacifists cannot Holy War	
				}	
			}	
		}

		root.capital_province = { geographical_region = world_persian_empire } # so that this inside-to-outside worldview makes sense 	

		is_ruler = yes

		any_held_county = {
			any_county_province = {
				geographical_region = dlc_fp3_eastern_persian_frontier_regions # so that you have a suitable frontier region
			}
		}

		any_character_to_title_neighboring_county = {
			holder = {
				fp3_yearly.8010_super_evil_pagan_heretic_neighboring_ruler_trigger = yes 
			}
		}
	}

	cooldown = { years = 50 }

	immediate = {
		root.faith.religious_head = { save_scope_as = righteous_caliph }

		random_character_to_title_neighboring_county = {
			limit = { holder = { fp3_yearly.8010_super_evil_pagan_heretic_neighboring_ruler_trigger = yes } }
			save_scope_as = pagan_county
		}

		scope:pagan_county.holder = { save_scope_as = pagan_ruler }	
	}

	option = { # So be it! 
		name = fp3_yearly.8010.a

		add_piety = medium_piety_gain 

		scope:righteous_caliph = {
			add_opinion = { 
				target = root
				opinion = 30
				modifier = pleased_opinion
			}
		}

		scope:pagan_ruler = {
			add_opinion = { 
				target = root
				modifier = warmonger_opinion
			}
		}

		add_unpressed_claim = scope:pagan_county
		custom_tooltip = fp3_yearly.8010_warmonger.tt
		
		spawn_army = {
			men_at_arms = {
				type = mubarizun 
				stacks = 1
			}
			men_at_arms = {
				type = horse_archers
				stacks = 1
			}
			levies = 300
			location = root.capital_province
			war_keep_on_attacker_victory = yes
			save_scope_as = new_army
			name = ghazi_event_troops
		}

		hidden_effect = { #this sets up the "Five year deadline"
			trigger_event = {
				id = fp3_yearly.8011
				years = 5
			}
		}

		stress_impact = { 
   			brave = medium_stress_impact_loss
   			wrathful = minor_stress_impact_loss
   			zealous = minor_stress_impact_loss
   			arbitrary = miniscule_stress_impact_loss 
   			content = minor_stress_impact_gain
   			compassionate = minor_stress_impact_gain  
   			craven = major_stress_impact_gain 
   			forgiving = minor_stress_impact_gain	
   		}

		ai_chance = { #zealous and bold AI prefer this option
        	base = 100
        	ai_value_modifier = {
           		ai_zeal = 1
           		ai_boldness = 1
           		ai_compassion = -0.5
           		ai_rationality = -0.5   		   		
        	}
   		} 
	}

	option = { # Give me funds instead of troops, and I'll see what I can do
		name = fp3_yearly.8010.b

		trigger = {
			OR = {
				stewardship >= high_skill_rating
				has_stewardship_lifestyle_trait_trigger = yes
			}
		}

		add_piety = minor_piety_gain 

		add_treasury_or_gold = medium_treasury_or_gold_value

		add_unpressed_claim = scope:pagan_county
		custom_tooltip = fp3_yearly.8010_warmonger.tt
		
		scope:righteous_caliph = {
			add_opinion = { 
				target = root
				opinion = -10
				modifier = annoyed_opinion
			}
		}

		scope:pagan_ruler = {
			add_opinion = { 
				target = root
				modifier = warmonger_opinion
			}
		}

		hidden_effect = { #this sets up the "Five year deadline"
			trigger_event = {
				id = fp3_yearly.8011
				years = 5
			}
		}

		stress_impact = { 
   			brave = minor_stress_impact_loss
   			greedy = minor_stress_impact_loss
   			content = minor_stress_impact_gain
   			compassionate = minor_stress_impact_gain  
   			craven = major_stress_impact_gain 
   			forgiving = minor_stress_impact_gain		
   		}

		ai_chance = { #greedy AI prefer this option
        	base = 100
        	ai_value_modifier = {
           		ai_zeal = 0.5
           		ai_greed = 1
           		ai_compassion = -0.5
           		ai_rationality = -0.5   		   		
        	}
   		} 
	}

	option = { # Surely, my lord, this is not the right time for war?
		name = fp3_yearly.8010.c

		duel = {
			skill = diplomacy
			value = high_skill_rating

			20 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 1
				}
				root = {
					send_interface_toast = {
						title = convincing_the_caliph_toast.success
						left_icon = scope:righteous_caliph 
				
						custom_tooltip = fp3_caliph_convinced.tt
						scope:righteous_caliph  = {
							add_opinion = { 
								target = root
								opinion = 30
								modifier = fp3_convincing_argument_opinion
							}
						}
					}
				}	
			}
			20 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -1
				}
				root = {
					send_interface_toast = {
						title = convincing_the_caliph_toast.failure
						left_icon = scope:righteous_caliph 

						custom_tooltip = fp3_caliph_unconvinced.tt
						scope:righteous_caliph  = {
							add_opinion = { 
								target = root
								opinion = -30
								modifier = angry_opinion
							}
						}
						add_character_modifier = {
							modifier = fp3_refused_the_caliph_modifier
							years = 10
						}
					}
				}
			}
		}

		scope:pagan_ruler = {
			add_opinion = { 
				target = root
				opinion = 10
				modifier = relieved_opinion
			}
		} 

		stress_impact = { 
   			compassionate = major_stress_impact_loss 
   			craven = minor_stress_impact_loss 
   			patient = minor_stress_impact_loss	
   			ambitious = minor_stress_impact_gain
   			brave = minor_stress_impact_gain
   			zealous = minor_stress_impact_gain
   		}

		ai_chance = { #compassionate, energetic AI prefer this option
        	base = 100
        	ai_value_modifier = {
           		ai_compassion = 1
           		ai_energy = 0.5
           		ai_zeal = -0.8
           		ai_boldness = -0.3		   		
        	}
   		} 
	}

	option = { # No thanks
		name = fp3_yearly.8010.d

		add_character_modifier = {
			modifier = fp3_refused_the_caliph_modifier
			years = 10
		}

		scope:righteous_caliph = {
			add_opinion = { 
				target = root
				opinion = -30
				modifier = angry_opinion
			}
		}

		scope:pagan_ruler = {
			add_opinion = { 
				target = root
				modifier = respect_opinion
				opinion = 20
			}
		}

		stress_impact = { 
   			content = minor_stress_impact_loss
   			compassionate = minor_stress_impact_loss
   			cynical = minor_stress_impact_loss
   			brave = minor_stress_impact_gain  
   			wrathful = minor_stress_impact_gain 
   			zealous = minor_stress_impact_gain	
   		}

		ai_chance = { #benevolent and tolerant AI prefer this option
        	base = 100
        	ai_value_modifier = {
           		ai_compassion = 1
           		ai_rationality = 0.7
           		ai_vengefulness = -0.5
           		ai_zeal = -1   		   		
        	}
   		} 
	}
}

fp3_yearly.8011 = { #this sets up the HoF's response to your actions
	hidden = yes

	immediate = {
		if = { # Caliph dies
			limit = { 
				OR = {
					NOT = { exists = scope:righteous_caliph }
					scope:righteous_caliph = { is_alive = no }
				}
			}
			send_interface_message = {
				type = event_martial_bad_with_text
				title = fp3_caliph_dead.title
				desc = fp3_caliph_dead.desc
			}
		}
		else_if = { # You capture the region
			limit = { scope:pagan_county.holder.top_liege = root.top_liege }
			trigger_event = fp3_yearly.8012
		}
		else = { trigger_event = fp3_yearly.8013 } # You fail
	}
}

fp3_yearly.8012 = { # Promise Fulfilled (follow-up-event)
	type = character_event
	title = fp3_yearly.8012.t
	desc = fp3_yearly.8012.desc
	theme = war
	override_background = { reference = throne_room }
	
	left_portrait = {
		character = root
		animation = personality_content
	}
	right_portrait = {
		character = scope:righteous_caliph
		animation = happiness
	}

	option = {
		name = fp3_yearly.8012.a

		add_piety = minor_piety_gain

		hidden_effect = {
			random = {
				chance = 10
				send_interface_toast = {
					left_icon = scope:righteous_caliph
					right_icon = root
					title = become_faith_warrior.toast
					
					if = {
						limit = {
							NOT = { has_trait = faith_warrior }
						}
						add_trait = faith_warrior 
					}
				}
			}
		}
	}
}

fp3_yearly.8013 = { # Caliphal Dissapointment (follow-up-event)
	type = character_event
	title = fp3_yearly.8013.t
	desc = fp3_yearly.8013.desc
	theme = war
	override_background = { reference = throne_room }
	
	left_portrait = {
		character = root
		animation = worry
	}
	right_portrait = {
		character = scope:righteous_caliph
		animation = anger
	}

	option = {
		name = fp3_yearly.8013.a

		add_piety = minor_piety_loss

		scope:righteous_caliph = {
			add_opinion = { 
				target = root
				modifier = broke_promise
			}
		}
	}

	option = {
		name = fp3_yearly.8013.b

		add_piety = medium_piety_loss
		add_prestige = minor_prestige_gain

		scope:righteous_caliph = {
			add_opinion = { 
				target = root
				modifier = hate_opinion
				opinion = -40
			}
		}
	}
}

###################################
# Secrets of the Teapot, by Ola Jentzsch, idea by Elena Zenko
###################################

scripted_trigger fp3_opportunistic_drunkard_trigger = {
	faith = { trait_is_sin = drunkard }
	has_trait = deceitful 
	OR = {
		has_trait = drunkard
		has_trait = gregarious 
		has_trait = gluttonous
		has_trait = lifestyle_reveler
	}
}

fp3_yearly.8014 = {
	type = character_event  
	title = fp3_yearly.8014.t
	desc = fp3_yearly.8014.desc	
	theme = faith 

	left_portrait = {
		character = scope:smart_courtier
		animation = happiness
	}

	right_portrait = {
		character = root
		animation = scheme
	}

	trigger = { 
		has_fp3_dlc_trigger = yes

		root.capital_province = { geographical_region = world_persian_empire }

		faith = { trait_is_sin = drunkard }

		OR = {
			has_trait = drunkard
			has_trait = lifestyle_reveler
		}

		OR = {
			any_spouse = { fp3_opportunistic_drunkard_trigger = yes }
			any_courtier_or_guest = { fp3_opportunistic_drunkard_trigger = yes }
			any_powerful_vassal = { fp3_opportunistic_drunkard_trigger = yes }
		}	
	}

	cooldown = { years = 10 }

	immediate = {

		if = {
			limit = { 
				any_spouse = { 
					fp3_opportunistic_drunkard_trigger = yes
				}
			}
			random_spouse = {
				limit = { 
					fp3_opportunistic_drunkard_trigger = yes
				}
				save_scope_as = smart_courtier
			}
		}
		else_if = {
			limit = { 
				any_powerful_vassal = { 											fp3_opportunistic_drunkard_trigger = yes	
				}
			}
			random_powerful_vassal = {
				limit = { 
					fp3_opportunistic_drunkard_trigger = yes
				}
				save_scope_as = smart_courtier
			}
		}
		else_if = {
			limit = { 
				any_courtier_or_guest = { 											fp3_opportunistic_drunkard_trigger = yes	
				}
			}
			random_courtier_or_guest = {
				limit = { 
					fp3_opportunistic_drunkard_trigger = yes
				}
				save_scope_as = smart_courtier
			}
		}

		hidden_effect = {
			scope:smart_courtier = {
				add_character_modifier = {
					modifier = fp3_teapot_alcoholism_modifier
					years = 20
				}
			}
		}			
	}	
			
	option = { #Very good idea!
		name = fp3_yearly.8014.a

   		add_piety = medium_piety_loss

   		scope:smart_courtier = {
			add_opinion = {
				target = root
				opinion = 20
				modifier = took_my_advice_opinion
			}
		}

		add_character_modifier = {
			modifier = fp3_teapot_alcoholism_modifier
		}

		
		ai_chance = { #deceitful or gluttonous goes for this option
        	base = 10
        	ai_value_modifier = {
            	ai_rationality = 0.8
            	ai_greed = 0.5
            	ai_honor = -0.5
        	}
   		}

   		stress_impact = { 
   			deceitful = minor_stress_impact_loss
   			drunkard = medium_stress_impact_loss 
   			gregarious = minor_stress_impact_loss 
   			gluttonous = minor_stress_impact_loss 
   			paranoid = minor_stress_impact_loss
   			honest = medium_stress_impact_gain
   			temperate = minor_stress_impact_gain
   			zealous = medium_stress_impact_gain			
   		}
	}

	option = { #Men I can deceive, but not God
		name = fp3_yearly.8014.b

   		add_piety = medium_piety_gain

   		scope:smart_courtier = {
			add_opinion = {
				target = root
				opinion = -20
				modifier = disappointed_opinion
			}
		}

   		ai_chance = { #cautious, honorable, moderately zealous AI goes for this option
         base = 10
        	ai_value_modifier = {
           		ai_honor = 1
           		ai_boldness = -0.5
            	ai_zeal = 0.5 
        	}
   		}

   		stress_impact = { 
   			just = minor_stress_impact_loss
   			honest = minor_stress_impact_loss
   			temperate = minor_stress_impact_loss
   			zealous = minor_stress_impact_loss
   			cynical = minor_stress_impact_gain
   			gluttonous = minor_stress_impact_gain
   			drunkard = medium_stress_impact_gain
   		}
   	}

   	option = { #I should not do this, and nor will you. 
		name = fp3_yearly.8014.c
		flavor = f3_yearly.8014_forbidding_teapot_alcohol_flavor 

		trigger = { is_ruler = yes }

   		add_piety = major_piety_gain

   		scope:smart_courtier = {
			add_opinion = {
				target = root
				opinion = -20
				modifier = fp3_killjoy_opinion
			}
			remove_character_modifier = fp3_teapot_alcoholism_modifier
		}

   		ai_chance = { #zealous AI goes for this option
        	base = 100
        	ai_value_modifier = {
           		ai_zeal = 1
            	ai_energy = 0.5
            	ai_vengefulness = 0.5 
            	ai_greed = -1
        	}
   		}

   		stress_impact = { 
   			zealous = medium_stress_impact_loss
   			just = minor_stress_impact_loss
   			honest = minor_stress_impact_loss
   			temperate = minor_stress_impact_loss
   			craven = minor_stress_impact_gain 
   			cynical = minor_stress_impact_gain
   			shy = minor_stress_impact_gain 
   			gluttonous = minor_stress_impact_gain
   			drunkard = medium_stress_impact_gain
   		}
   	}		
}

#########Forgotten Runestones, by Ola Jentzsch######
scripted_trigger fp3_not_norse_trigger = {
	NOR = {
		culture = { has_cultural_pillar = heritage_north_germanic }
		culture = { has_cultural_tradition = tradition_fp1_northern_stories }
		has_religion = religion:germanic_religion
	}
}

scripted_trigger fp3_intolerant_vassal_trigger = {
	is_ai = yes
	OR = { 
   		has_trait = zealous
   		has_trait = arrogant
   		has_trait = wrathful 
   		has_trait = irritable 
   	}
   	NOR = { 
   		has_trait = cynical 
   		has_trait = forgiving
   	}
}

fp3_yearly.8016 = {
	type = character_event  
	title = fp3_yearly.8016.t
	desc = fp3_yearly.8016.desc
	theme = realm

	override_background = { reference = fp1_runestone }

	left_portrait = {
		character = root
		animation = personality_cynical
	}

	right_portrait = {
		character = scope:hyrcanian_vassal
		animation = personality_vengeful 
	}

	trigger = { 

		#Standard scope sanity checks
		has_fp3_dlc_trigger = yes

		root.capital_province = { 
			OR = {
				geographical_region = world_persian_empire
				geographical_region = world_steppe_tarim 
			}
		} 

		#This event is a bit unique, so we don't want it to fire more than once in a playthrough 
		is_ai = no
		NOT = { exists = global_var:has_had_runestone_event }

		#The important parts

		#is_available_at_peace_adult = yes #so it makes sense to be in Daylam 

		fp3_not_norse_trigger = yes

		any_powerful_vassal = {
			any_held_county = {
   				title_province = {
   					geographical_region = world_daylam
   				}
   			}
   			fp3_not_norse_trigger = yes
   			fp3_intolerant_vassal_trigger = yes	
   		}
	}

	immediate = {

		set_global_variable = has_had_runestone_event 	

		random_powerful_vassal = {
			limit = {
				any_held_county = {
   					title_province = {
   						geographical_region = world_daylam 
   					}
   				}
   				fp3_not_norse_trigger = yes
   				fp3_intolerant_vassal_trigger = yes
			}
			save_scope_as = hyrcanian_vassal
		}	

		scope:hyrcanian_vassal = {
			random_held_county = {
				limit = { 
					title_province = {
						geographical_region = world_daylam
					}
				}
				save_scope_as = runestone_county 
			}
		}

		scope:runestone_county = {
			add_county_modifier = {
				modifier = fp3_forgotten_runestones_county_modifier 
				years = 200
			}
		}

		root.capital_county = {
			save_scope_as = new_runestone_county 
		}
	}

	option = { #Very well, let us destroy them. 
		name = fp3_yearly.8016.a


		scope:hyrcanian_vassal = {
			add_opinion = {
				target = root
				opinion = 20
				modifier = pleased_opinion
			}
		}

		scope:runestone_county = {
			remove_county_modifier = fp3_forgotten_runestones_county_modifier 
		}

		scope:runestone_county = {
			add_county_modifier = {
				modifier = fp3_dismayed_daylamites_county_modifier 
				years = 30
			}
		}

		hidden_effect = {
			if = {
				limit = { current_year < 1050 } 
				random = {
					chance = 20
					trigger_event = {
						id = fp3_yearly.8017 #easter egg, fans wanted events to build on eachother 
						years = { 5 15 }
					}
				} 
			}
		}

		stress_impact = { 
			irritable = minor_stress_impact_loss
   			wrathful = minor_stress_impact_loss
   			zealous = minor_stress_impact_loss
   			calm = minor_stress_impact_gain
   			cynical = minor_stress_impact_gain
   		}		
	}

	option = { #No, you shall leave them be forever. 
		name = fp3_yearly.8016.b

		scope:hyrcanian_vassal = {
			add_opinion = {
				target = root
				opinion = -20
				modifier = angry_opinion
			}
		}

		stress_impact = { 
   			cynical = minor_stress_impact_loss
   			scholar = minor_stress_impact_loss
   			craven = minor_stress_impact_loss
   			paranoid = minor_stress_impact_loss 
   			trusting = minor_stress_impact_gain
   			wrathful = minor_stress_impact_gain
   			zealous = minor_stress_impact_gain
   		}			
	}

	option = { #Drag them to my capital
		name = fp3_yearly.8016.c

		duel = {
			skill = diplomacy
			value = average_skill_rating

			20 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 2
				}
				root = {
					send_interface_toast = {
						title = convincing_the_hyrcanian_vassal_toast.success
						left_icon = scope:hyrcanian_vassal
				
						custom_tooltip = fp3_hyrcanian_vassal_convinced.tt
						scope:hyrcanian_vassal = {
							add_opinion = {
								target = root
								opinion = 20
								modifier = pleased_opinion
							}
						}
					}
				}	
			}
			20 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -1
				}
				root = {
					send_interface_toast = {
						title = convincing_the_hyrcanian_vassal_toast.failure
						left_icon = scope:hyrcanian_vassal

						custom_tooltip = fp3_hyrcanian_vassal_unconvinced.tt
						scope:hyrcanian_vassal  = {
							add_opinion = { 
								target = root
								opinion = -20
								modifier = fp3_suspicious_motives_opinion
							}
						}
					}
				}
			}
		}

		scope:runestone_county = {
			remove_county_modifier = fp3_forgotten_runestones_county_modifier 
		}

		scope:runestone_county = {
			add_county_modifier = {
				modifier = fp3_dismayed_daylamites_county_modifier 
				years = 30
			}
		}

		scope:new_runestone_county = {
			add_county_modifier = {
				modifier = fp3_forgotten_runestones_county_modifier
				years = 200 
			}
		}

		hidden_effect = {
			if = {
				limit = { current_year < 1050 } 
				random = {
					chance = 20
					trigger_event = {
						id = fp3_yearly.8017 #easter egg, fans wanted events to build on eachother 
						years = { 5 15 }
					}
				} 
			}
		}

		stress_impact = { 
   			ambitious = minor_stress_impact_loss
   			diligent = minor_stress_impact_loss
   			trusting = minor_stress_impact_gain
   			zealous = minor_stress_impact_gain
   			wrathful = minor_stress_impact_gain 
   		}	
	}
}

###Hyrcanian Havoc by Ola Jentzsch (easter egg event, will only trigger rarely)
fp3_yearly.8017 = {
	type = character_event  
	title = fp3_yearly.8017.t
	desc = fp3_yearly.8017.desc
	theme = battle
	override_background = {
		reference = burning_building
	}
	left_portrait = {
		character = scope:raider
		animation = aggressive_axe
	}
	right_portrait = {
		character = scope:hyrcanian_vassal
		animation = fear
		triggered_animation = {
			trigger = {
				ai_vengefulness >= medium_positive_ai_value
				ai_boldness > high_negative_ai_value
			}
			animation = rage
		}
	}	

	trigger = {

		exists = global_var:has_had_runestone_event

		exists = scope:hyrcanian_vassal 

		scope:hyrcanian_vassal = {
			any_held_county = { this = scope:runestone_county }
		}
	}

	immediate = {

		create_character = { 
			template = fp1_jomsviking_bigwig
			location = scope:hyrcanian_vassal.capital_province
			save_scope_as = raider	
		}


		scope:raider = {
			add_character_flag = single_combat_duel_armor
		}

		scope:hyrcanian_vassal = {
			maimed_in_battle_effect = yes
		}

		scope:runestone_county = {
			random_county_province = {
				limit = { is_county_capital = yes }
				save_scope_as = runestone_province
			}
		}

		scope:runestone_province = {
			add_province_modifier = { 
				modifier = recently_looted_modifier
				years = 10
			}
		}
	} 

	#Oh no!
	option = {	
		name = fp3_yearly.8017.a
		add_prestige = miniscule_prestige_loss
	}

	#Send some restitution
	option = {	
		name = fp3_yearly.8017.b
		
		pay_short_term_gold = {
			target = scope:runestone_county.holder
			gold = medium_gold_value 
		}
		scope:runestone_county.holder = {
			add_opinion = {
				target = liege
				modifier = grateful_opinion
				opinion = 20
			}
		}
		stress_impact = { greedy = medium_stress_impact_gain }
	}

	#This is a bad open...maybe I'd better return those stones... 
	option = {
		name = fp3_yearly.8017.c
		
		trigger = {
			scope:new_runestone_county = {
				has_county_modifier = fp3_forgotten_runestones_county_modifier		
			}
		}

		scope:new_runestone_county = {
			remove_county_modifier = fp3_forgotten_runestones_county_modifier 
		}

		scope:runestone_county = {
			add_county_modifier = {
				modifier = fp3_forgotten_runestones_county_modifier
				years = 200 
			}
		}

		stress_impact = { 
   			craven = medium_stress_impact_loss
   			paranoid = medium_stress_impact_loss
   			zealous = minor_stress_impact_loss 
   			arrogant = medium_stress_impact_gain
   			cynical = medium_stress_impact_gain
   			brave = medium_stress_impact_gain 
   			stubborn = medium_stress_impact_gain
   		}				
	}

	after = {
		scope:raider = {
			remove_character_flag = single_combat_duel_armor
		}
	}
}

###Heavenly Horses by Ola Jentzsch############
fp3_yearly.8018 = {
	type = character_event  
	title = fp3_yearly.8018.t

	desc = {
		first_valid = {
			triggered_desc = { 
				trigger = {
					scope:horse_enthusiast = { is_eunuch_trigger = yes }
				}
				desc = fp3_yearly.8018.desc_eunuch
			}
			desc = fp3_yearly.8018.desc_grand_old_lady
		}	
	}
	theme = martial_chivalry_focus 
	left_portrait = {
		character = scope:horse_enthusiast
		animation = admiration
		triggered_animation = {
			trigger = {
				ai_sociability >= medium_positive_ai_value
				ai_boldness >= medium_positive_ai_value
			}
			animation = flirtation
		}
	}	
	right_portrait = {
		character = root
		animation = disapproval
	}

	override_background = {
		reference = wilderness_mountains
	}

	trigger = {

		has_fp3_dlc_trigger = yes

		any_owned_story = { type = story_cycle_martial_lifestyle_warhorse }

		any_held_county = {
			any_county_province = {
				geographical_region = world_transoxiana
			}
		}

		NOT = {
			culture = culture:han
		}

		gold < 0
	}
			

	immediate = {

		random_list = {
			50 = {
				create_character = { 
					template = fp3_chinese_grand_old_lady
					location = root.capital_province
					save_scope_as = horse_enthusiast	
				}
			}
			50 = {
				create_character = { 
					template = fp3_chinese_eunuch_envoy
					location = root.capital_province
					save_scope_as = horse_enthusiast	
				}
			}	
		}

		random_owned_story = {
			type = story_cycle_martial_lifestyle_warhorse
			save_scope_as = warhorse_story
		}
	}


	#Sell the horse 
	option = {	
		name = fp3_yearly.8018.a
		
		show_as_tooltip = {
			remove_horse_story_modifiers_effect = yes
		}
		scope:warhorse_story = {
			hidden_effect = { end_story = yes }
		}

		add_gold = massive_gold_value

		stress_impact = { 
   			ambitious = medium_stress_impact_gain
   			arrogant = minor_stress_impact_gain
   			compassionate = minor_stress_impact_gain
   			temperate = minor_stress_impact_loss 
   		}

   		ai_chance = { #pragmatic, desperate AI goes for this option
        	base = 100
        	ai_value_modifier = {
           		ai_rationality = 0.5
            	ai_boldness = -0.5
            	ai_compassion = -0.5
        	}
   		}	
	}

	#Refuse
	option = {	
		name = fp3_yearly.8018.b
		
		stress_impact = { 
   			stubborn = minor_stress_impact_loss
   			content = minor_stress_impact_loss 
   		}

   		ai_chance = { #horse-loving AI refuse this
        	base = 100
        	ai_value_modifier = {
           		ai_compassion = 0.5
            	ai_boldness = 0.5
            	ai_energy = 0.5
            	ai_sociability = 0.5
        	}
   		}		
	}

	#If it's the arrogant lady, insult her 
	option = {	
		name = fp3_yearly.8018.c

		trigger = {
			scope:horse_enthusiast = {
				is_female = yes
			}
		}

		add_character_modifier = {
			modifier = fp3_insulted_chinese_noble_modifier
			years = 20 
		}
		
		stress_impact = { 
   			calm = medium_stress_impact_gain
   			shy = minor_stress_impact_gain
   			compassionate = minor_stress_impact_gain
   			arrogant = medium_stress_impact_loss
   			wrathful = medium_stress_impact_loss
   			irritable = medium_stress_impact_loss
   		}

   		ai_chance = { #angry AI pick this option
        	base = 100
        	ai_value_modifier = {
           		ai_vengefulness = 1
            	ai_boldness = 0.7
        	}
   		}		
	}

	after = {

		hidden_effect = {
			scope:horse_enthusiast = {
	   			move_to_pool = yes
	  			silent_disappearance_effect = yes
	  		}
		}
	}
}
