namespace = fp2_struggle

### SYSTEM EVENTS #################################################################
## # Parameter Events
## 0001 - 0010	VIP spontaneous relationship management.
## 0011 - 0040	Struggle VIPs spontaneously develop negative relationships with each other.
## 0041 - 0070	Struggle VIPs spontaneously develop postive relationships with each other.
## # Other Events
## 0501 - 0510	Struggle Intro Events
## 0900 - 0999	Struggle ending decision events
### EVENT LIST ####################################################################
## XXXX	- XXXX	YYY by ZZZ
## 1000	- 1000	Stoking the Fire by Ola Jentzsch
## 1001	- 1001	War Widows by Ola Jentzsch
## 1002	- 1002	Andalusian Advancements by Ola Jentzsch
## 1010	- 1012	Soul of Iron by Ola Jentzsch
## 1020	- 1020	Death of a Councilman by Ola Jentzsch
## 1050	- 1050	The Vision by Ola Jentzsch
## 2000 - 2000	Disorderly Market by Hugo Cortell
## 2001 - 2002	Desperate Villagers Seek New Lord by Hugo Cortell
## 2003 - 2003	Lost Migratory Birds by Hugo Cortell
## 2004	- 2005	Ship building event by Hugo Cortell
## 2006	- 2006	The Borders of Faith by Hugo Cortell
## 2007 - 2007	Castle Worthy of Iberia by Hugo Cortell
## 2008 - 2008	Misdeeds of The Chaplain by Hugo Cortell
## 2009 - 2012	Catching Thieves of Myth by Hugo Cortell
## 2013	- 2014	The Secret to Freedom by Hugo Cortell
## 2015	- 2016	Letter on The Back by Hugo Cortell
## 2021	- 2022	RETURN OF THE THIEF KING by Hugo Cortell
## 3001	- 3010	The Price of War by Veronica Pazos
## 3011	- 3020	Order of the Hatchet by Veronica Pazos
## 3021	- 3030	The Wrath of Heaven by Veronica Pazos
###################################################################################

# Setting AI Intent
fp2_struggle.0003 = {
	hidden = yes
	scope = none
	scope = struggle

	trigger = { # Should not need this, but, redundancy check!
		exists = struggle:iberian_struggle
		struggle:iberian_struggle = { any_involved_ruler = { } } # For when the conflict is ongoing but nobody is left to fight it
	}

	immediate = {
		# prepare needed variables; they will be destroyed at the end of the immediate
		set_variable = {
			name = agents_for_escalation
			value = 0
		}
		set_variable = {
			name = agents_for_deescalation
			value = 0
		}

		# Go through the characters to distribute them between the potential transitions
		struggle:iberian_struggle = {
			every_involved_ruler = {
				limit = { is_alive = yes }
				#######################
				# Play cue track
				######################
				if = {
					limit = { is_ai = no }
					play_music_cue = "mx_Struggle_Opening"
				}

				#######################
				# Check existing flags
				######################
				if = {
					limit = { has_character_flag = agenda_towards_escalation }
					root = {
						change_variable = {
							name = agents_for_escalation
							add = 1
						}
					}
				}
				else_if = {
					limit = { has_character_flag = agenda_towards_deescalation }
					root = {
						change_variable = {
							name = agents_for_deescalation
							add = 1
						}
					}
				}
				else = { # Set a flag
					#############################
					# Current Phase: Opportunity
					#############################
					if = {
						limit = { root = { is_struggle_phase = struggle_iberia_phase_opportunity } }
						random_list = {
							# Working towards Hostility
							# It should be for characters looking for direct conflicts and domination, with the will and ability to expand their realms
							100 = {
								# Odds modifiers
								fp2_struggle_set_ai_agenda_common_modifiers = {
									PHASE = hostility
									INTENT = escalation
								}

								# Apply effects
								fp2_struggle_apply_ai_agenda_effect = {
									INTENT = escalation
								}
							}
							# Working towards Conciliation
							100 = {
								# Odds modifiers
								fp2_struggle_set_ai_agenda_common_modifiers = {
									PHASE = conciliation
									INTENT = deescalation
								}

								# Apply effects
								fp2_struggle_apply_ai_agenda_effect = {
									INTENT = deescalation
								}
							}
						}
					}

					#############################
					# Current Phase: Hostility
					#############################
					if = {
						limit = { root = { is_struggle_phase = struggle_iberia_phase_hostility } }
						random_list = {
							# Working towards Hostility: it means that the character wants to stay in
							100 = {
								# Odds modifiers
								fp2_struggle_set_ai_agenda_common_modifiers = {
									PHASE = hostility
									INTENT = escalation
								}

								# Apply effects
								fp2_struggle_apply_ai_agenda_effect = {
									INTENT = escalation
								}
							}
							# Working towards Compromise
							100 = {
								# Odds modifiers
								fp2_struggle_set_ai_agenda_common_modifiers = {
									PHASE = compromise
									INTENT = deescalation
								}

								# Apply effects
								fp2_struggle_apply_ai_agenda_effect = {
									INTENT = deescalation
								}
							}
						}
					}

					#############################
					# Current Phase: Compromise
					#############################
					if = {
						limit = { root = { is_struggle_phase = struggle_iberia_phase_compromise } }
						random_list = {

							# Working towards Opportunity
							100 = {
								# Odds modifiers
								fp2_struggle_set_ai_agenda_common_modifiers = {
									PHASE = opportunity
									INTENT = escalation
								}

								# Apply effects
								fp2_struggle_apply_ai_agenda_effect = {
									INTENT = escalation
								}
							}
							# Working towards Compromise: they want to stay in the same phase
							100 = {
								# Odds modifiers
								fp2_struggle_set_ai_agenda_common_modifiers = {
									PHASE = compromise
									INTENT = deescalation
								}

								# Apply effects
								fp2_struggle_apply_ai_agenda_effect = {
									INTENT = deescalation
								}
							}
						}
					}

					#############################
					# Current Phase: Conciliation
					#############################
					if = {
						limit = { root = { is_struggle_phase = struggle_iberia_phase_conciliation } }
						random_list = {
							# Working towards Compromise
							100 = {
								# Odds modifiers
								fp2_struggle_set_ai_agenda_common_modifiers = {
									PHASE = compromise
									INTENT = escalation
								}

								# Apply effects
								fp2_struggle_apply_ai_agenda_effect = {
									INTENT = escalation
								}
							}
							# Working towards Conciliation: they want to stay in the same phase
							100 = {
								# Odds modifiers
								fp2_struggle_set_ai_agenda_common_modifiers = {
									PHASE = conciliation
									INTENT = deescalation
								}

								# Apply effects
								fp2_struggle_apply_ai_agenda_effect = {
									INTENT = deescalation
								}
							}
						}
					}
				}
			}
		}

		# Clean variables
		remove_variable = agents_for_escalation
		remove_variable = agents_for_deescalation
	}
}

# Set AI Intent on join
fp2_struggle.004 = {
	hidden = yes
	scope = none

	immediate = {
		set_variable = {
			name = agents_for_escalation
			value = 0
		}
		set_variable = {
			name = agents_for_deescalation
			value = 0
		}

		############################
		# Update the variables
		############################
		every_character_struggle = {
			every_involved_ruler = {
				limit = { is_alive = yes }
				if = {
					limit = { has_character_flag = agenda_towards_escalation }
					root = {
						change_variable = {
							name = agents_for_escalation
							add = 1
						}
					}
				}
				else_if = {
					limit = { has_character_flag = agenda_towards_deescalation }
					root = {
						change_variable = {
							name = agents_for_deescalation
							add = 1
						}
					}
				}
			}
		}

		if = {
			limit = {
				NOR = {
					has_character_flag = agenda_towards_escalation
					has_character_flag = agenda_towards_deescalation
				}
			}

			#############################
			# Current Phase: Opportunity
			#############################
			if = {
				limit = { any_character_struggle = { is_struggle_phase = struggle_iberia_phase_opportunity } }
				random_list = {
					# Working towards Hostility
					# It should be for characters looking for direct conflicts and domination, with the will and ability to expand their realms
					100 = {
						# Odds modifiers
						fp2_struggle_set_ai_agenda_common_modifiers = {
							PHASE = hostility
							INTENT = escalation
						}

						# Apply effects
						fp2_struggle_apply_ai_agenda_effect = {
							INTENT = escalation
						}
					}
					# Working towards Conciliation
					100 = {
						# Odds modifiers
						fp2_struggle_set_ai_agenda_common_modifiers = {
							PHASE = conciliation
							INTENT = deescalation
						}

						# Apply effects
						fp2_struggle_apply_ai_agenda_effect = {
							INTENT = deescalation
						}
					}
				}
			}

			#############################
			# Current Phase: Hostility
			#############################
			if = {
				limit = { any_character_struggle = { is_struggle_phase = struggle_iberia_phase_hostility } }
				random_list = {
					# Working towards Hostility: it means that the character wants to stay in
					100 = {
						# Odds modifiers
						fp2_struggle_set_ai_agenda_common_modifiers = {
							PHASE = hostility
							INTENT = escalation
						}

						# Apply effects
						fp2_struggle_apply_ai_agenda_effect = {
							INTENT = escalation
						}
					}
					# Working towards Compromise
					100 = {
						# Odds modifiers
						fp2_struggle_set_ai_agenda_common_modifiers = {
							PHASE = compromise
							INTENT = deescalation
						}

						# Apply effects
						fp2_struggle_apply_ai_agenda_effect = {
							INTENT = deescalation
						}
					}
				}
			}

			#############################
			# Current Phase: Compromise
			#############################
			if = {
				limit = { any_character_struggle = { is_struggle_phase = struggle_iberia_phase_compromise } }
				random_list = {

					# Working towards Opportunity
					100 = {
						# Odds modifiers
						fp2_struggle_set_ai_agenda_common_modifiers = {
							PHASE = opportunity
							INTENT = escalation
						}

						# Apply effects
						fp2_struggle_apply_ai_agenda_effect = {
							INTENT = escalation
						}
					}
					# Working towards Compromise: they want to stay in the same phase
					100 = {
						# Odds modifiers
						fp2_struggle_set_ai_agenda_common_modifiers = {
							PHASE = compromise
							INTENT = deescalation
						}

						# Apply effects
						fp2_struggle_apply_ai_agenda_effect = {
							INTENT = deescalation
						}
					}
				}
			}

			#############################
			# Current Phase: Conciliation
			#############################
			if = {
				limit = { any_character_struggle = { is_struggle_phase = struggle_iberia_phase_conciliation } }
				random_list = {
					# Working towards Compromise
					100 = {
						# Odds modifiers
						fp2_struggle_set_ai_agenda_common_modifiers = {
							PHASE = compromise
							INTENT = escalation
						}

						# Apply effects
						fp2_struggle_apply_ai_agenda_effect = {
							INTENT = escalation
						}
					}
					# Working towards Conciliation: they want to stay in the same phase
					100 = {
						# Odds modifiers
						fp2_struggle_set_ai_agenda_common_modifiers = {
							PHASE = conciliation
							INTENT = deescalation
						}

						# Apply effects
						fp2_struggle_apply_ai_agenda_effect = {
							INTENT = deescalation
						}
					}
				}
			}
		}

		# Clean variables
		remove_variable = agents_for_escalation
		remove_variable = agents_for_deescalation
	}
}

###################################
# Iberian Struggle Intro Events
# 0501 - 599
###################################
fp2_struggle.0501 = { # Fullscreen Intro Event
	type = character_event
	window = fullscreen_event
	title = fp2_struggle.0501.t
	desc = {
		desc = fp2_struggle.0501.desc
		first_valid = {
			triggered_desc = {
				trigger = {
					any_character_struggle = {
						involvement = involved
						is_struggle_type = iberian_struggle
					}
				}
				desc = fp2_struggle.0501.desc.involved
			}
			triggered_desc = {
				trigger = {
					any_character_struggle = {
						involvement = interloper
						is_struggle_type = iberian_struggle
					}
				}
				desc = fp2_struggle.0501.desc.interloper
			}
		}
	}
	theme = realm
	trigger = { # we need to prevent this from firing for all players when a new player joins in MP
		is_ai = no
		NOT = { has_character_flag = fp2_struggle_intro_event_flag }
		character_any_involvement_reconquista_struggle_trigger = yes
 	}
	override_background = { reference = fp2_fullscreen_intro }
	override_sound = { reference = "event:/DLC/FP2/SFX/UI/fp2_struggle_ui_intro_animate" }

	cooldown = { years = 100 }

	widgets = {
		widget = {
 			gui = "event_window_widget_struggle_info"
 			container = "dynamic_content_widget"
 			controller = struggle_info
 			setup_scope = { struggle:iberian_struggle = { save_scope_as = struggle } }
		}
	}
	immediate = {
		play_music_cue = "mx_Struggle_Opening"
		add_character_flag = fp2_struggle_intro_event_flag
		save_scope_value_as = {
			name = start
			value = yes
		}
	}
	option = {
		name = fp2_struggle.0501.a
		clicksound = "event:/DLC/FP2/SFX/UI/fp2_struggle_start_select"
	}
}

###################################
# Struggle Endings
# by Joe Parkin
# 0900-0912
###################################
fp2_struggle.0900 = { # Hostility
	type = character_event
	window = fullscreen_event
	title = fp2_struggle.0900.t
	desc = {
		first_valid = {
		    triggered_desc = {
		        trigger = {
					culture = {
						OR = {
							this = culture:basque
							any_parent_culture = { this = culture:basque }
							has_cultural_pillar = language_basque
						}
					}
		        }
		        desc = fp2_struggle.0900.opening.basque
		    }
		    triggered_desc = {
		        trigger = {
					culture = {
						OR = {
							this = culture:andalusian
							any_parent_culture = { this = culture:andalusian }
							has_cultural_pillar = language_arabic
						}
					}
		        }
		        desc = fp2_struggle.0900.opening.andalusian
		    }
		    triggered_desc = {
		        trigger = {
					culture = { has_cultural_pillar = heritage_iberian }
		        }
		        desc = fp2_struggle.0900.opening.iberian
		    }
		    desc = fp2_struggle.0900.opening
		}
		desc = fp2_struggle.0900.desc
	}
	theme = court
	override_background = { reference = fp2_fullscreen_hostility }
	override_sound = { reference = "event:/DLC/FP2/SFX/UI/fp2_struggle_ui_intro_end_animate" }

	immediate = {
		# Add all involved rulers to a list, for ping event
		play_music_cue = "mx_Struggle_ending_hostility"
		fp2_stuggle_ending_involved_list_effect = yes
		give_nickname = nick_the_conquistador
		dynasty = { add_dynasty_prestige = 10000 }
	}

	# Faith victory
	option = {
		name = fp2_struggle.0900.a
		if = {
			limit = { exists = house }
			house = {
				add_house_modifier = {
					modifier = fp2_struggle_hostility_house_faith_modifier
				}
			}
		}
		# Piety reward for faith victory
		add_piety = 1000
		custom_description_no_bullet = { text = fp2_struggle_house_tt }
		custom_tooltip = fp2_struggle_hostility_holy_cb_tt
		custom_tooltip = fp2_struggle_hostility_conversion_holy_tt
		stress_impact = {
			cynical = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_zeal = 1
			}
		}
	}

	# Culture victory
	option = {
		name = fp2_struggle.0900.b
		# Renown reward for culture victory
		if = {
			limit = { exists = house }
			dynasty = { add_dynasty_prestige = 1000 }
			house = {
				add_house_modifier = {
					modifier = fp2_struggle_hostility_house_culture_modifier
				}
			}
		}
		custom_description_no_bullet = { text = fp2_struggle_house_tt }
		custom_tooltip = fp2_struggle_hostility_culture_cb_tt
		custom_tooltip = fp2_struggle_hostility_conversion_culture_tt
		# All Involved cultures lose acceptance of each other
		custom_tooltip = {
			text = fp2_struggle_hostility_culture_tt
			fp2_struggle_hostility_cultural_acceptance_effect = yes
		}
		stress_impact = {
			humble = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
		}
	}

	# Combined victory
	option = {
		name = fp2_struggle.0900.c
		# Reduced renown and piety rewards for combined
		if = {
			limit = { exists = house }
			house = {
				add_house_modifier = {
					modifier = fp2_struggle_hostility_house_combined_modifier
				}
			}
		}
		add_prestige = 3000
		custom_description_no_bullet = { text = fp2_struggle_house_tt }
		custom_tooltip = fp2_struggle_hostility_holy_cb_tt
		custom_tooltip = culture_parameter_cb_lower_piety_level_requirement
		custom_tooltip = fp2_struggle_hostility_culture_cb_tt
		custom_tooltip = fp2_struggle_hostility_conversion_holy_tt
		custom_tooltip = fp2_struggle_hostility_conversion_culture_tt
		# All Involved cultures lose acceptance of each other
		custom_tooltip = {
			text = fp2_struggle_hostility_culture_large_tt 
			fp2_struggle_hostility_cultural_acceptance_large_effect = yes
		}
		stress_impact = {
			humble = medium_stress_impact_gain
			cynical = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_zeal = 2
				ai_boldness = 1
			}
		}
	}

	after = {
		# Notify & End Struggle
		save_scope_as = fp2_loc_struggle_ender # Loc used to use root, this fixes it
		every_player = {
			limit = { fp2_does_this_player_care_about_the_fate_of_iberia = yes } # Needs to be checked before the struggle ends due to race condition issues
			add_to_list = player_to_notify # Making a list so stuff is tiggered after the struggle ends, to make extra sure I don't break anything.
		}

		struggle:iberian_struggle = { end_struggle = struggle_iberia_ending_hostility_decision }
		every_in_list = { # Then we *actually* notify palyers, making sure the struggle has already ended
			list = player_to_notify
			trigger_event = fp2_struggle.0910
		}
	}
}

fp2_struggle.0910 = {
	type = character_event
	window = fullscreen_event
	title = fp2_struggle.0900.t
	desc = {
		first_valid = {
		    triggered_desc = {
		        trigger = { is_in_list = struggle_involvees }
		        desc = fp2_struggle.0910.opening.involved
		    }
		    desc = fp2_struggle.0910.opening
		}
		desc = fp2_struggle.0910.desc
		first_valid = {
		    triggered_desc = {
		        trigger = {
		        	scope:struggle_ender.house = { has_house_modifier = fp2_struggle_hostility_house_faith_modifier }
		        }
		        desc = fp2_struggle.0910.closing.faith
		    }
		    triggered_desc = {
		        trigger = {
		        	scope:struggle_ender.house = { has_house_modifier = fp2_struggle_hostility_house_culture_modifier }
		        }
		        desc = fp2_struggle.0910.closing.culture
		    }
		    desc = fp2_struggle.0910.closing.combined
		}
	}
	theme = court
	override_background = { reference = fp2_fullscreen_hostility }
	override_sound = { reference = "event:/DLC/FP2/SFX/UI/fp2_struggle_ui_intro_end_animate" }

	immediate = {
		play_music_cue = "mx_Struggle_ending_hostility"
		##### Major Effects #####
		show_as_tooltip = {
			scope:struggle_ender = {
				#dynasty = { add_dynasty_prestige = 10000 }
				fp2_struggle_hostility_ender_effect = yes
			}
		}
		# Hispania is available!
		custom_tooltip = fp2_struggle_can_create_empire_of_hispania_tt 
		# Choose Holy War boost, Culture War boost, or both
		scope:struggle_ender.house = {
			switch = {
				trigger = has_house_modifier
				fp2_struggle_hostility_house_faith_modifier = {
					show_as_tooltip = { add_house_modifier = fp2_struggle_hostility_house_faith_modifier }
					custom_description_no_bullet = { text = fp2_struggle_house_tt }
					custom_tooltip = fp2_struggle_hostility_holy_cb_tt
				}
				fp2_struggle_hostility_house_culture_modifier = {
					show_as_tooltip = { add_house_modifier = fp2_struggle_hostility_house_culture_modifier }
					custom_description_no_bullet = { text = fp2_struggle_house_tt }
					custom_tooltip = fp2_struggle_hostility_culture_cb_tt
					custom_tooltip = fp2_struggle_hostility_culture_tt
				}
				fp2_struggle_hostility_house_combined_modifier = {
					show_as_tooltip = { add_house_modifier = fp2_struggle_hostility_house_combined_modifier }
					custom_description_no_bullet = { text = fp2_struggle_house_tt }
					custom_tooltip = fp2_struggle_hostility_holy_cb_tt
					custom_tooltip = fp2_struggle_hostility_culture_cb_tt
					custom_tooltip = fp2_struggle_hostility_culture_large_tt
				}
			}
		}
	}

	# Ok
	option = {
		name = {
			text = fp2_struggle.0910.a
			trigger = { is_in_list = struggle_involvees }
		}
		name = {
			text = fp2_struggle.0910.b
			trigger = {
				NOT = { is_in_list = struggle_involvees }
			}
		}
	}
}

fp2_struggle.0901 = { # Compromise
	type = character_event
	window = fullscreen_event
	title = fp2_struggle.0901.t
	desc = {
		first_valid = {
		    triggered_desc = {
		        trigger = {
					culture = {
						OR = {
							this = culture:basque
							any_parent_culture = { this = culture:basque }
							has_cultural_pillar = language_basque
						}
					}
		        }
		        desc = fp2_struggle.0900.opening.basque
		    }
		    triggered_desc = {
		        trigger = {
					culture = {
						OR = {
							this = culture:andalusian
							any_parent_culture = { this = culture:andalusian }
							has_cultural_pillar = language_arabic
						}
					}
		        }
		        desc = fp2_struggle.0900.opening.andalusian
		    }
		    triggered_desc = {
		        trigger = {
					culture = { has_cultural_pillar = heritage_iberian }
		        }
		        desc = fp2_struggle.0900.opening.iberian
		    }
		    desc = fp2_struggle.0900.opening
		}
		desc = fp2_struggle.0901.desc
	}
	theme = court
	override_background = { reference = fp2_fullscreen_compromise }
	override_sound = { reference = "event:/DLC/FP2/SFX/UI/fp2_struggle_ui_intro_end_animate" }

	immediate = {
		play_music_cue = "mx_Struggle_ending_compromise"
		# Independent/Split De Jure Duchies will become De Jure Kingdoms
		if = {
			limit = {
				title:e_spain = {
					any_in_de_jure_hierarchy = { fp2_struggle_ending_compromise_independent_duchy_trigger = yes }
				}
			}
			custom_tooltip = {
				text = fp2_struggle_compromise_create_new_kingdoms_tt
				fp2_struggle_compromise_duchies_to_kingdoms_effect = yes
			}
		}
		# Move duchies to right kingdoms
		fp2_struggle_compromise_transfer_duchies_effect = yes
		# Turn kingdoms to empires
		fp2_struggle_compromise_kingdoms_to_empires_effect = yes
		# distribute small kingdoms
		fp2_struggle_compromise_distribute_kingdoms_to_neighbouring_empires_effect = yes
		# assign the new title to existing characters
		fp2_struggle_compromise_distribute_the_actual_titles = yes

		# Set up truces
		fp2_struggle_compromise_truce_effect = yes

		##### Major Effects #####
		fp2_struggle_compromise_ender_effect = yes
		
		# Tooltips!
		fp2_struggle_compromise_tooltip_effect = yes

		##### Minor Effects #####
		# Self-sufficiency modifiers for each independent realm
		fp2_struggle_compromise_modifier_rewards_effect = yes
		set_global_variable = {
			name = fp2_struggle_compromise_ending
			value = yes
		}
		# Add all involved rulers to a list, for ping event
		fp2_stuggle_ending_involved_list_effect = yes
	}

	# Ok
	option = {
		name = fp2_struggle.0901.a
		if = {
			limit = {
				any_in_list = {
					list = kingdom_empire
					this = root.primary_title
				}
			}
			custom_tooltip = fp2_struggle.0901.tt
		}
	}

	after = {
		stress_impact = {
			arrogant = medium_stress_impact_gain
		}

		# Notify & End Struggle
		save_scope_as = fp2_loc_struggle_ender # Loc used to use root, this fixes it
		every_player = {
			limit = { fp2_does_this_player_care_about_the_fate_of_iberia = yes } # Needs to be checked before the struggle ends due to race condition issues
			add_to_list = player_to_notify # Making a list so stuff is tiggered after the struggle ends, to make extra sure I don't break anything.
		}

		struggle:iberian_struggle = { end_struggle = struggle_iberia_ending_compromise_decision }
		every_in_list = { # Then we *actually* notify palyers, making sure the struggle has already ended
			list = player_to_notify
			trigger_event = fp2_struggle.0911
		}
	}
}

fp2_struggle.0911 = {
	type = character_event
	window = fullscreen_event
	title = fp2_struggle.0901.t
	desc = {
		first_valid = {
		    triggered_desc = {
		        trigger = { is_in_list = struggle_involvees }
		        desc = fp2_struggle.0910.opening.involved
		    }
		    desc = fp2_struggle.0910.opening
		}
		desc = fp2_struggle.0911.desc
	}
	theme = court
	override_background = { reference = fp2_fullscreen_compromise }
	override_sound = { reference = "event:/DLC/FP2/SFX/UI/fp2_struggle_ui_intro_end_animate" }

	immediate = {
		play_music_cue = "mx_Struggle_ending_compromise"
		##### Major Effects #####
		show_as_tooltip = {
			scope:struggle_ender = { fp2_struggle_compromise_ender_effect = yes }
		}
		# Independent/Split De Jure Duchies will become De Jure Kingdoms
		custom_tooltip = fp2_struggle_compromise_create_new_kingdoms_tt
		# RIP Hispania
		fp2_struggle_compromise_tooltip_effect = yes

		##### Minor Effects #####
		if = {
			limit = {
				any_in_list = {
					list = kingdom_empire
					OR = {
						this = root.primary_title
						this = root.primary_title.de_jure_liege
						this = root.primary_title.de_jure_liege.de_jure_liege
					}
				}
			}
			custom_tooltip = fp2_struggle.0901.tt
		}
		if = {
			limit = { is_in_list = struggle_involvees }
			show_as_tooltip = {
				fp2_struggle_compromise_modifier_rewards_personal_house_effect = yes
				fp2_struggle_compromise_modifier_rewards_personal_county_effect = yes
			}
		}
	}

	# Ok
	option = {
		name = {
			text = fp2_struggle.0911.a
			trigger = { is_in_list = struggle_involvees }
		}
		name = {
			text = fp2_struggle.0910.b
			trigger = {
				NOT = { is_in_list = struggle_involvees }
			}
		}
	}
}

fp2_struggle.0902 = { # Conciliation
	type = character_event
	window = fullscreen_event
	title = fp2_struggle.0902.t
	desc = {
		first_valid = {
		    triggered_desc = {
		        trigger = {
					culture = {
						OR = {
							this = culture:basque
							any_parent_culture = { this = culture:basque }
							has_cultural_pillar = language_basque
						}
					}
		        }
		        desc = fp2_struggle.0900.opening.basque
		    }
		    triggered_desc = {
		        trigger = {
					culture = {
						OR = {
							this = culture:andalusian
							any_parent_culture = { this = culture:andalusian }
							has_cultural_pillar = language_arabic
						}
					}
		        }
		        desc = fp2_struggle.0900.opening.andalusian
		    }
		    triggered_desc = {
		        trigger = {
					culture = { has_cultural_pillar = heritage_iberian }
		        }
		        desc = fp2_struggle.0900.opening.iberian
		    }
		    desc = fp2_struggle.0900.opening
		}
		desc = fp2_struggle.0902.desc
	}
	theme = court
	override_background = { reference = fp2_fullscreen_conciliation }
	override_sound = { reference = "event:/DLC/FP2/SFX/UI/fp2_struggle_ui_intro_end_animate" }

	immediate = {
		play_music_cue = "mx_Struggle_ending_conciliation"
		set_global_variable = {
			name = fp2_struggle_conciliation_ending
			value = yes
		}
		# Add all involved rulers to a list, for ping event
		fp2_stuggle_ending_involved_list_effect = yes

		# Add all involved cultures with counties to a list, for marriage and holy war checks
		fp2_struggle_ending_culture_list_effect = yes

		# Change cultural acceptance
		fp2_struggle_conciliation_cultural_acceptance_effect = yes

		##### Major Effects #####
		fp2_struggle_conciliation_ender_effect = yes
		fp2_struggle_conciliation_tooltip_effect = yes
		fp2_struggle_conciliation_modifier_rewards_effect = yes
	}

	# 
	option = {
		name = fp2_struggle.0902.a
	}

	after = {
		stress_impact = {
			arrogant = medium_stress_impact_gain
			zealous = medium_stress_impact_gain
		}

		# Notify & End Struggle
		save_scope_as = fp2_loc_struggle_ender # Loc used to use root, this fixes it
		every_player = {
			limit = { fp2_does_this_player_care_about_the_fate_of_iberia = yes } # Needs to be checked before the struggle ends due to race condition issues
			add_to_list = player_to_notify # Making a list so stuff is tiggered after the struggle ends, to make extra sure I don't break anything.
		}

		struggle:iberian_struggle = { end_struggle = struggle_iberia_ending_conciliation_decision }
		every_in_list = { # Then we *actually* notify palyers, making sure the struggle has already ended
			list = player_to_notify
			trigger_event = fp2_struggle.0912
		}
	}
}

fp2_struggle.0912 = {
	type = character_event
	window = fullscreen_event
	title = fp2_struggle.0902.t
	desc = {
		first_valid = {
		    triggered_desc = {
		        trigger = { is_in_list = struggle_involvees }
		        desc = fp2_struggle.0910.opening.involved
		    }
		    desc = fp2_struggle.0910.opening
		}
		desc = fp2_struggle.0912.desc
	}
	theme = court
	override_background = { reference = fp2_fullscreen_conciliation }
	override_sound = { reference = "event:/DLC/FP2/SFX/UI/fp2_struggle_ui_intro_end_animate" }

	immediate = {
		play_music_cue = "mx_Struggle_ending_conciliation"
		##### Major Effects #####
		show_as_tooltip = {
			scope:struggle_ender = { fp2_struggle_conciliation_ender_effect = yes }
		}
		fp2_struggle_conciliation_tooltip_effect = yes

		##### Minor Effects #####
		# All involved rulers gain diff culture opinion and learn language scheme power
		if = {
			limit = { is_in_list = struggle_involvees }
			show_as_tooltip = { fp2_struggle_conciliation_modifier_rewards_personal_effect = yes }
		}
	}

	# Ok
	option = {
		name = {
			text = fp2_struggle.0912.a
			trigger = { is_in_list = struggle_involvees }
		}
		name = {
			text = fp2_struggle.0910.b
			trigger = {
				NOT = { is_in_list = struggle_involvees }
			}
		}
	}
}

###################################
# Stoking the Fire
# By Ola Jentzsch
###################################
scripted_trigger fp2_struggle_1000_tension_county_trigger = {
	is_landless_type_title = no
	any_county_province = { geographical_region = world_europe_west_iberia }
	faith = { save_temporary_scope_as = compare_faith }
	root = {
		faith = {
			faith_hostility_level = { target = scope:compare_faith value > faith_astray_level }
		}
	}
}
scripted_trigger fp2_struggle_1000_tension_councillor_trigger = {
	faith = { this = root.faith }
	is_available_healthy_ai_adult = yes
	OR = {
		has_trait = zealous
		has_trait = wrathful
		has_trait = deceitful 
		has_trait = sadistic
		has_trait = holy_warrior
		has_trait = callous
	}
	NOR = {
		has_trait = compassionate
		has_trait = just
	}				
}

fp2_struggle.1000 = {
	orphan = yes
	type = character_event
	title = fp2_struggle.1000.t
	desc = fp2_struggle.1000.desc
	theme = dread

	left_portrait = {
		character = root
		animation = stress
	}
	right_portrait = {
		character = scope:tension_councillor
		animation = scheme
	}

	
	trigger = {
		has_fp2_dlc_trigger = yes
		fp2_character_involved_in_struggle_trigger = yes
		custom_description = {
			text = empty_spooky_trigger #This is entirely pointless, but code likes it, so ghost away! 
			any_held_county = { fp2_struggle_1000_tension_county_trigger = yes }
			OR = {
				any_councillor = { fp2_struggle_1000_tension_councillor_trigger = yes }
				any_vassal = { fp2_struggle_1000_tension_councillor_trigger = yes }
				exists = cp:councillor_marshal 
			}
		}
		OR = {
			capital_province = { geographical_region = world_europe_west_iberia }
			culture = { has_cultural_pillar = heritage_iberian }
		}
	}

	cooldown = { #this shouldn't fire too often
		years = 50
	}

	immediate = { #We need a province and a suitable councillor; this fixes that. 
		random_held_county = {
			limit = { fp2_struggle_1000_tension_county_trigger = yes }
			save_scope_as = tension_county
		}
		if = {
			limit = {
				any_councillor = {
					fp2_struggle_1000_tension_councillor_trigger = yes
				}
			}
			random_councillor = {
				limit = {
					fp2_struggle_1000_tension_councillor_trigger = yes
				}
				save_scope_as = tension_councillor
			}
		}	
		else_if = {
			limit = {
				any_vassal = {
					fp2_struggle_1000_tension_councillor_trigger = yes
				}
			}
			random_vassal = {
				limit = {
					fp2_struggle_1000_tension_councillor_trigger = yes 
				}
				save_scope_as = tension_councillor
			}
		}
		else = {
			random_councillor = {
				limit = {
					has_council_position = councillor_marshal
				}
				save_scope_as = tension_councillor
			}
		}
		
		if = { #this code checks if there is an eligible person for the 4th option 
			limit = {
				any_vassal = {
					is_available_healthy_ai_adult = yes
					faith = scope:tension_county.faith
				}
			}
			random_vassal = {
				limit = { 
					is_available_healthy_ai_adult = yes
					faith = scope:tension_county.faith
				}	
				save_scope_as = minority_courtier
			}
		}
		else_if = {
			limit = {
				any_courtier = {
					is_available_healthy_ai_adult = yes
					faith = scope:tension_county.faith
	 	 		}
 	 		}
			random_courtier = {
				limit = { 
					is_available_healthy_ai_adult = yes
					faith = scope:tension_county.faith
				}	
				save_scope_as = minority_courtier
			}
		}
	}
					
	option = { #Let us spread some hatred...discreetly.  
		name = fp2_struggle.1000.a

		ai_chance = { #Cruel and fanatical characters pick this option
        	base = 10
        	ai_value_modifier = {
           		ai_zeal = 1
           		ai_vengefulness = 0.5  
            	ai_compassion = -1
            	ai_honor = -1
        	}
   		}

   		stress_impact = {
			# Righteous characters find this a very unappealing option. 
			compassionate = medium_stress_impact_gain
			gallant = medium_stress_impact_gain
			honest = medium_stress_impact_gain
			just = medium_stress_impact_gain
			paragon = medium_stress_impact_gain
			# As do lazy ones. 
			lazy = minor_stress_impact_gain
		}

		scope:tension_councillor = {
			add_opinion = {
				target = root
				opinion = 10
				modifier = took_my_advice_opinion
			}
		}

		 
		add_character_modifier = {
			modifier = fanatical_recruits_modifier 
			years = 10 
		}
		
		duel = { #You try to create a hate campaign - and get away with it. 
			skill = intrigue
			value = average_skill_rating

			20 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 2
				}
				send_interface_toast = {
					title = stoke_tension_toast.success
					left_icon = root

					add_dread = minor_dread_gain
					
					scope:tension_county = {
						add_county_modifier = {
							modifier = riots_and_murders_province_modifier
							years = 5
						}
					}
				}
			}

			20 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -1
				}
				send_interface_toast = {
					title = stoke_tension_toast.failure
					left_icon = root
					add_character_modifier = {
						modifier = hate_monger_modifier
						years = 10
					}

					scope:tension_county = {
						add_county_modifier = {
							modifier = riots_and_murders_province_modifier
							years = 5
						}
					}
				}
			}
		}
	}

	option = { #I trust you to handle it 
		name = fp2_struggle.1000.b

		trigger = {
			intrigue <= medium_skill_rating 
		}

		show_unlock_reason = no

		ai_chance = { #Cruel and fanatical characters pick this option
        	base = 10
        	ai_value_modifier = {
           		ai_zeal = 0.5
           		ai_rationality = 0.2
            	ai_compassion = -0.5
            	ai_honor = -1
        	}
   		}

   		stress_impact = {
			# Righteous characters find this a very unappealing option. 
			compassionate = medium_stress_impact_gain
			gallant = medium_stress_impact_gain
			honest = medium_stress_impact_gain
			just = medium_stress_impact_gain
			paragon = medium_stress_impact_gain	
			# As do lazy ones. 
			lazy = miniscule_stress_impact_gain	
		}

		if = {
			limit = {
				intrigue <= medium_skill_rating
			}
			custom_tooltip = bad_intrigue.tt
		}

		scope:tension_councillor = {
			if = {
				limit = {
					intrigue >= average_skill_level
				}
				add_opinion = {
					target = root
					opinion = 10
					modifier = trusted_me_opinion
				}
			}
			else = { 
				add_opinion = {
					target = root
					opinion = -10
					modifier = unfair_expectations_opinion
				}
			}
		}

		add_character_modifier = {
			modifier = fanatical_recruits_modifier 
			years = 10 
		}
	


		scope:tension_councillor = {
			duel = {
			skill = intrigue
			value = average_skill_rating

				20 = {
					compare_modifier = {
						value = scope:duel_value
						multiplier = 2
					}
					root = {
						send_interface_toast = {
							title = delegated_stoke_tension_toast.success
							left_icon = scope:tension_councillor
				
							scope:tension_county = {
								add_county_modifier = {
									modifier = riots_and_murders_province_modifier
									years = 5
								}
							}
						}
					}	
				}
				20 = {
					compare_modifier = {
						value = scope:duel_value
						multiplier = -1
					}
					root = {
						send_interface_toast = {
							title = stoke_tension_toast.failure
							left_icon = scope:tension_councillor

							root = {
								add_character_modifier = {
									modifier = hate_monger_modifier
									years = 10
								}
							}
							scope:tension_councillor = {
								add_character_modifier = {
									modifier = hate_monger_modifier
									years = 10
								}
							}
							scope:tension_county = {
								add_county_modifier = {
									modifier = riots_and_murders_province_modifier
									years = 5
								}
							}
						}
					}
				}
			}
		}
	}

	option = {  #"No, I shall try to ease the tensions."
		name = fp2_struggle.1000.c

		ai_chance = { #just and compassionate characters pick this option
        	base = 10
        	ai_value_modifier = {
           		ai_honor = 0.8
           		ai_compassion = 0.7
           		ai_rationality = 0.2  
            	ai_zeal = -0.8
            	ai_vengefulness = -0.7
        	}
   		}

   		stress_impact = {
			# Aggressive characters find this an unappealing option.
			wrathful = minor_stress_impact_gain
			zealous = minor_stress_impact_gain
			sadistic = minor_stress_impact_gain 
			vengeful = minor_stress_impact_gain
			}
			
		scope:tension_councillor = {
			add_opinion = {
				target = root
				opinion = -10
				modifier = disappointed_opinion
			}
		}

		duel = {
			skill = diplomacy
			value = high_skill_rating

			30 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 2
				}
				send_interface_toast = {
					title = ease_tension_toast.success
					left_icon = root

					add_character_modifier = {
						modifier = tolerance_gospel_modifier 
						years = 10 
					} 
					
					scope:tension_county = {
						add_county_modifier = {
							modifier = tensions_eased_province_modifier
							years = 5
						}
					}
				}
			}
			20 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -1
				}
				send_interface_toast = {
					title = ease_tension_toast.failure
					left_icon = root
					scope:tension_county = {
						add_county_modifier = {	
							modifier = riots_and_murders_province_modifier
							years = 5
						}
					}
				}
			}
		}
	}   
	
	option = { #"If I cannot stop this madness...  
		name = fp2_struggle.1000.d
		
		trigger = { 
			exists = scope:minority_courtier 
				
			scope:tension_county = {
				this != root.capital_county
			}
		}

		ai_chance = { #just and compassionate characters pick this option
        	base = 10
        	ai_value_modifier = {
           		ai_honor = 0.3
           		ai_compassion = 0.3
           		ai_rationality = 0.8 
            	ai_zeal = -0.8
            	ai_vengefulness = -0.7
            	ai_greed = -1
        	}
   		}

   		stress_impact = {
			# Aggressive characters find this unappealing
			wrathful = minor_stress_impact_gain
			zealous = major_stress_impact_gain
			sadistic = minor_stress_impact_gain 
			vengeful = minor_stress_impact_gain

			#As do power-mongers, you're giving away a whole province! 
			ambitious = minor_stress_impact_gain
			stubborn = minor_stress_impact_gain
			greedy = minor_stress_impact_gain
			arrogant = minor_stress_impact_gain
			paranoid = minor_stress_impact_gain

		}

		scope:minority_courtier = {
			add_opinion = {
				target = root
				opinion = 20
				modifier = received_title_county
			}
		}

		create_title_and_vassal_change = {
			type = granted
			save_scope_as = change
			add_claim_on_loss = yes
		}

		scope:tension_county = {
			change_title_holder = {
				holder = scope:minority_courtier
				change = scope:change
			}
		}

		resolve_title_and_vassal_change = scope:change

		add_stress = medium_stress_loss

		scope:tension_councillor = {
			add_opinion = {
				target = root
				opinion = -10
				modifier = disappointed_opinion
			}
		}

		scope:tension_county = {
			add_county_modifier = {
				modifier = tensions_eased_province_modifier
				years = 10
			}
		}
	} 		
}

###################################
# War Widows
# By Ola Jentzsch
###################################
# Idea by Isabella welch
###################################

scripted_trigger fp2_struggle.1001_weird_option_traits = { # These, presumably, makes you even more sympathethic to widows and orphans, or likely to take an ill-thought out decision. 
	OR = {
		has_character_modifier = associates_with_strange_peasants_modifier	
		has_trait = bastard
		has_trait = legitimized_bastard
		has_trait = intellect_bad_3
		has_trait = intellect_bad_2
		has_trait = improvident
		has_trait = lifestyle_reveler 
		has_trait = pregnant
		has_trait = lunatic
		has_trait = eccentric
	}
}

scripted_trigger fp2_struggle.1001_expectant_vassal_or_courtier_traits = { # This is about the personality the pregnant courtier should have to get this idea to begin with 
	has_trait = pregnant 
	is_available_ai = yes
	NOR = {
		has_trait = callous
		has_trait = content
		has_trait = arrogant
		has_trait = dull
	}
}

fp2_struggle.1001 = {
	orphan = yes
	type = character_event
	title = fp2_struggle.1001.t
	desc = fp2_struggle.1001.desc
	theme = faith
	cooldown = { years = 50 }

	left_portrait = {
		character = root
		animation = personality_cynical
	}
	right_portrait = {
		character = scope:expectant_courtier
		animation = happiness
	}
	
	trigger = {
		has_fp2_dlc_trigger = yes
		OR = {
			any_vassal = {
				fp2_struggle.1001_expectant_vassal_or_courtier_traits = yes
			}	
			any_courtier = {
				fp2_struggle.1001_expectant_vassal_or_courtier_traits = yes
			}
		}	
		gold >= medium_gold_value_check 

		any_truce_target = { }
	}

	immediate = {
		random_vassal = { 
			limit = {
				fp2_struggle.1001_expectant_vassal_or_courtier_traits = yes
				is_spouse_of = root	
			}
		
			alternative_limit = {
				fp2_struggle.1001_expectant_vassal_or_courtier_traits = yes
				any_player_heir = { is_spouse_of = prev }	
			}
			alternative_limit = {
				fp2_struggle.1001_expectant_vassal_or_courtier_traits = yes
				is_councillor = yes 	
			}
			alternative_limit = {
				fp2_struggle.1001_expectant_vassal_or_courtier_traits = yes
				is_powerful_vassal = yes
			}

			alternative_limit = {
                fp2_struggle.1001_expectant_vassal_or_courtier_traits = yes
            }
            
			save_scope_as = expectant_courtier
		} 
		
		if = { 
			limit = {
				NOT = {
					exists = scope:expectant_courtier
				}
			}
			random_courtier = { 
				limit = {
					fp2_struggle.1001_expectant_vassal_or_courtier_traits = yes
					is_spouse_of = root	
				}
				alternative_limit = {
					fp2_struggle.1001_expectant_vassal_or_courtier_traits = yes
					any_player_heir = { is_spouse_of = prev }	
				}
				alternative_limit = {
					fp2_struggle.1001_expectant_vassal_or_courtier_traits = yes
					is_councillor = yes 	
				}
				alternative_limit = {
					fp2_struggle.1001_expectant_vassal_or_courtier_traits = yes
				}
				save_scope_as = expectant_courtier
			} 
		}
	}

	

	option = { #A good idea! I shall create such a fund. 
		name = fp2_struggle.1001.a

		stress_impact = {
			# Arrogant or cruel characters find this an unappealing option.
			arbitrary = medium_stress_impact_gain
			arrogant = medium_stress_impact_gain
			sadistic = medium_stress_impact_gain 

			# As do, of course, greedy ones. 
			greedy = medium_stress_impact_gain

			# As do callous and content ones, to an extent. 
			callous = minor_stress_impact_gain
			content = minor_stress_impact_gain 

			# But generous and compassionate characters like it.
			compassionate = minor_stress_impact_loss
			generous = medium_stress_impact_loss
		}	

		ai_chance = { #Just and compassionate characters pick this option
        	base = 10
        	ai_value_modifier = {
           		ai_honor = 0.5
           		ai_compassion = 1
            	ai_vengefulness = -0.2
            	ai_greed = -0.5 
        	}
   		}

		remove_treasury_or_gold = major_treasury_or_gold_value 

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

		
		add_character_modifier = {
			modifier = nursing_salaries_for_single_mothers_modifier 
			years = 20 
		} 		
	}

	option = { #Widows I will support, but not whores! 
		name = fp2_struggle.1001.b
		flavor = fp2_struggle.1001.b.tt
		trigger = {
			fp2_struggle.1001_weird_option_traits = no
			trait_is_shunned_or_criminal_in_faith_trigger = {
				FAITH = faith
				TRAIT = adulterer
				GENDER_CHARACTER = dummy_female
			}
		}

		stress_impact = {
			# Truly righteous characters wouldn't say this. 
			compassionate = minor_stress_impact_gain
			gallant = minor_stress_impact_gain 
			generous = minor_stress_impact_gain 
			humble = minor_stress_impact_gain
			just = minor_stress_impact_gain 

			# And greedy ones still don't wanna pay up
			greedy = minor_stress_impact_gain
		}

		ai_chance = { #Zealous AI characters pick this option
        	base = 10
        	ai_value_modifier = {
           		ai_zeal = 1
           		ai_compassion = -0.8
        	}
   		}

		remove_treasury_or_gold = medium_treasury_or_gold_value
		add_piety = minor_piety_gain
		add_character_modifier = {
			modifier = widows_and_widowers_amazing_funds_modifier
			years = 20 
		}

		scope:expectant_courtier = {
			if = {
				limit = {
					has_trait = zealous 
				}
				add_opinion = {
					target = root
					opinion = 10
					modifier = pleased_opinion
				}
			}
			else = { 
				add_opinion = {
					target = root
					opinion = -10
					modifier = slightly_disappointed_opinion
				}
			}
		}
	}


	option = { #But they can come stay at my court! We have food in abundance! 
		name = fp2_struggle.1001.c
		flavor = fp2_struggle.1001.c.tt
		trigger = {
	 		fp2_struggle.1001_weird_option_traits = yes 
		}

		stress_impact = {
			# Cheap or shy character's don't like this
			greedy = medium_stress_impact_gain
			shy = medium_stress_impact_gain

			#Nor do those wo really care about the appearance and glory of their courts

			ambitious = minor_stress_impact_gain
			arrogant = medium_stress_impact_gain
			temperate = medium_stress_impact_gain
			august = medium_stress_impact_gain
			born_in_the_purple = minor_stress_impact_gain 

			# But hypersocial hippies love it

			humble = minor_stress_impact_loss 
			gregarious = minor_stress_impact_loss 
			eccentric = minor_stress_impact_loss 
		}

		ai_chance = { #Deranged or hypersocial but irrational AI characters pick this option
        	base = 10
        	ai_value_modifier = {
           		ai_boldness = 0.5
           		ai_energy = 0.8
           		ai_rationality = -0.8
        	}
   		}

		scope:expectant_courtier = {
			if = {
				limit = {
					OR = {
						has_character_modifier = associates_with_strange_peasants_modifier	
						has_trait = bastard
						has_trait = legitimized_bastard
						has_trait = intellect_bad_3
						has_trait = intellect_bad_2
						has_trait = improvident
						has_trait = gregarious
					}	has_trait = lunatic 
				}
				add_opinion = {
					target = root
					opinion = 10
					modifier = pleased_opinion
				}
			}
			else = { 
				add_opinion = {
					target = root
					opinion = -10
					modifier = perplexed_opinion
				}
			}
		}
		if = {
			limit = { 
				root = {
					faith = {
						OR = {
							trait_is_virtue = gregarious
							trait_is_virtue = humble
							trait_is_virtue = generous  	
						}	
					}
				}
			}
			add_piety = medium_piety_gain
		}
		else = {
			add_piety = minor_piety_gain
		}
		add_character_modifier = {
			modifier = destitute_single_mothers_modifier
			years = 15  
		}
	}

	option = { #Surely, my benevolent vassals can help funding this.   
		name = fp2_struggle.1001.d

		trigger = {
			any_vassal = {
				count = all
					is_ai = yes
			}
		}
		
		stress_impact = {
			# Careful or dilpomatically minded characters won't do this.
			content = medium_stress_impact_gain
			diplomat = medium_stress_impact_gain 
			paranoid = medium_stress_impact_gain						
		}

		ai_chance = { #Economic AI characters pick this option, while the careful don't. 
        	base = 10
        	ai_value_modifier = {
           		ai_compassion = 0.5
           		ai_greed = 0.5
           		ai_rationality = -0.5
        	}
   		}

		remove_treasury_or_gold = minor_treasury_or_gold_value

		custom_tooltip = fp2_struggle.1001.specialdescpositive
		custom_tooltip = fp2_struggle.1001.specialdescnegative 
		hidden_effect = {
			every_vassal = {
				IF = { 
					limit = {
						NOT = {
							has_trait = pregnant
						}
					}
					IF = {
						limit = {
							OR = {
								has_trait = compassionate
								has_trait = generous
								has_trait = just
							}	
						}
						add_opinion = {
							target = root
							opinion = 10
							modifier = funded_righteous_cause_opinion
						}
					}
					ELSE = { 
						add_opinion = {
							target = root
							opinion = -10
							modifier = extorted_me_opinion
						}
					}
				}	
			}
		}
		
		scope:expectant_courtier = {  
			IF = {
				limit = {
					is_vassal_of = root #if she is, she gets angry because now SHE is expected to pay for this... 
				}
				add_opinion = {
					target = root
					opinion = -20
					modifier = extorted_me_opinion
				}
			}
			ELSE = { 
				add_opinion = {
					target = root
					opinion = 10
					modifier = pleased_opinion
				}
			}
		}

		add_character_modifier = {
			modifier = nursing_salaries_for_single_mothers_modifier 
			years = 20 
		} 			
	}

	option = { #I am your king, not a wet nurse!  
		name = fp2_struggle.1001.e
	
		stress_impact = {
			# Benevolent characters wouldn't ignore this.
			compassionate = medium_stress_impact_gain
			gallant = medium_stress_impact_gain 
			generous = medium_stress_impact_gain

			# nor would those who are truly competent or just.
			administrator = minor_stress_impact_gain
			ambitious = minor_stress_impact_gain 
			diligent = minor_stress_impact_gain
			just = minor_stress_impact_gain
			eccentric = minor_stress_impact_gain
		}

		ai_chance = { #Callous or cheap AI characters pick this option
        	base = 10
        	ai_value_modifier = {
           		ai_rationality = 0.5
           		ai_greed = 0.5
           		ai_honor = -0.7
           		ai_compassion = -0.7
        	}
   		}

		scope:expectant_courtier = {
			add_opinion = {
				target = root
				opinion = -20
				modifier = hurt_opinion
			}
		}
		
		random = {
			chance = 50
			send_interface_toast = {
				left_icon = root
				title = not_my_problem_toast
				add_character_modifier = {
					modifier = starving_single_mothers_and_children_modifier 
					years = 15
				}
			}
		}
	}
}

###################################
# Andalusian Advancements
# By Ola Jentzsch
###################################
# Inspired by an idea by Isabella welch
#########################################
scripted_trigger neighboring_ruler_proper_culture_trigger = {
	OR = {
		culture = culture:andalusian
		culture = culture:bedouin
		culture = culture:baranis 
		culture = culture:butr
		culture = culture:levantine 
		culture = culture:sephardi 	
	}
}

fp2_struggle.1002 = {
 	type = character_event
 	title = fp2_struggle.1002.t
 	desc = { #Different flavor depending on time period
	 	first_valid = {
		 	triggered_desc = {
			 	trigger = { current_date <= 1030.1.1 } 
			 	desc = fp2_struggle.1002.desc_early_golden_age 
		 	}
		 	triggered_desc = {
			 	trigger = { 
				 	current_year >= 1250 
				 	has_religion = religion:christianity_religion
			 	}
			 	desc = fp2_struggle.1002.desc_post_golden_age_christian #this triggers the latinized names of the polymaths
		 	}
		 	triggered_desc = {
			 	trigger = { current_year >= 1250 }
			 	desc = fp2_struggle.1002.desc_post_golden_age_unchristian #or their arabic ones
		 	}
		 	triggered_desc = {
			 	trigger = { current_year >= 1030 }
			 	desc = fp2_struggle.1002.desc_late_golden_age			
		 	}
	 	}
	 	first_valid = {
		 	triggered_desc = { #tests if the event would fire one of the historical physicians 
			 	trigger = {
				 	AND = {
					 	current_year > 976
					 	current_year < 1010
				 	}
				 	exists = global_var:albucasis_created
				 	exists = scope:albucasis_physician
				 	scope:great_physician = scope:albucasis_physician #this is a measure taken so that the loc gets tied to the appropriate character
			 	}
			 	desc = fp2_struggle.1002.desc_albucasis #this is the dialogue text if Albucasis spawns
		 	}
		 	triggered_desc = { #tests if the event would fire one of the historical physicians 
			 	trigger = {
				 	AND = {
					 	current_year > 1125
					 	current_year < 1165
				 	}
				 	exists = global_var:avenzoar_created 
				 	exists = scope:avenzoar_physician
				 	scope:great_physician = scope:avenzoar_physician
			 	}
			 	desc = fp2_struggle.1002.desc_avenzoar #this is the dialogue if Avenzoar spawns
		 	}
		 	triggered_desc = { #tests if the event would fire one of the historical physicians 
			 	trigger = {
				 	AND = {
					 	current_year > 1140
					 	current_year < 1180
				 	}
				 	exists = global_var:tufail_created 
				 	exists = scope:tufail_physician
				 	scope:great_physician = scope:tufail_physician
			 	}
			 	desc = fp2_struggle.1002.desc_tufail #this is the dialogue if Ibn Tufail spawns
		 	}
		 	triggered_desc = { #this defaults to a random Andalusian physician 
			 	trigger = { current_year >= 1050 } ##
			 	desc = fp2_struggle.1002.desc_no_historical_physician_late
		 	}
		 	desc = fp2_struggle.1002.desc_no_historical_physician_early 
	 	}
		first_valid = { #if root has a court physician, it changes the narrative a bit.
		 	triggered_desc = {
			 	trigger = { 
				 	court_physician_available_trigger = yes 
				 	has_religion = religion:christianity_religion
			 	}
			 	desc = fp2_struggle.1002.desc_has_physician_and_is_christian #in this case, the slur "heathen" is used
		 	}
		 	triggered_desc = {
			 	trigger = { court_physician_available_trigger = yes }
			 	desc = fp2_struggle.1002.desc_has_physician_but_not_christian #in this case, the slur "eccentric" is used
		 	}
		 	triggered_desc = {
			 	trigger = { has_religion = religion:christianity_religion }
			 	desc = fp2_struggle.1002.desc_has_no_physician_but_is_christian #in this case, the slur "heathen" is used
		 	}
		 	desc = fp2_struggle.1002.desc_has_no_physician #default option should all else fail
	 	}			
 	}

 	theme = medicine 
 	override_background = { reference = throne_room }

 	left_portrait = {
	 	character = root
	 	animation = personality_content
 	}
	right_portrait = {
		character = scope:great_physician
		animation = personality_rational #polymaths should always have this pose :D 
	}

	lower_left_portrait = scope:neighboring_ruler #this is the ruler that's angry with the polymath

	lower_right_portrait = scope:scoped_physician #this is your court physician if you have one

 	cooldown = { years = 100 }
 
 	trigger = { 
	 	has_fp2_dlc_trigger = yes
		#any_character_to_title_neighboring_county = { #this searches for a neighboring province that has the xenophilic tradition, which is this event's dynamic way of checking for Andalusian culture or cultures derived from it. 
	 	any_neighboring_and_across_water_top_liege_realm_owner = {
		 	culture = {
			 	OR = {
			 		has_cultural_tradition = tradition_xenophilic 
			 		has_cultural_tradition = tradition_medicinal_plants
			 		has_cultural_tradition = tradition_fp2_malleable_subjects 
			 	}
		 	}
	 	}

	 	root.capital_province = { #so that it only triggers for people close to Andalusia 
			OR = {
				geographical_region = world_europe_west_iberia 
				geographical_region = world_europe_west_francia
				geographical_region = world_europe_south_italy
			}
		}

	 	NOT = { #So that it doesn't fire for the Andalusians themselves, because that'd make the narrative weird 
		 	culture = culture:andalusian  
	 	}

	 	NOT = { #So that it doesn't fire for the Umayyads when they control Iberia
		 	AND = {
			 	culture = culture:levantine  
			 	root.capital_province = { geographical_region = world_europe_west_iberia }
		 	}
	 	}

		any_neighboring_and_across_water_top_liege_realm_owner = { 
			is_ai = yes 	
		}
 	}

 	weight_multiplier = {
		base = 0.4
	 	modifier = {
		 	OR = {
			 	AND = {
				 	current_year > 976
				 	current_year < 1010
			 	}
			 	AND = {
				 	current_year > 1125
				 	current_year < 1180
			 	}
		 	}
		 	add = 1.6
	 	}
	 	modifier = {
		 	neighboring_ruler_proper_culture_trigger = yes
		 	add = 0.5
	 	}
 	}


 	immediate = {
	 
	 	random_neighboring_and_across_water_top_liege_realm_owner = { #this searches for a neighboring ruler with the proper cultural tradition, which is this event's dynamic way of checking for Andalusian culture or cultures derived from it. 
		 	limit = {
			 	culture = { 
			 		OR = {
			 			has_cultural_tradition = tradition_xenophilic 
			 			has_cultural_tradition = tradition_medicinal_plants
			 			has_cultural_tradition = tradition_fp2_malleable_subjects 
			 		}
			 	}
		 	}
			culture = { save_scope_as = xenophilic_culture } #this is mostly used for error-checking because the debug log is unclear. 
	 	}

	 	if = { #This looks to see if one of three historical physicians will be used in the event 
		 	limit = { #their rough period of activity
			 	AND = {
				 	current_year > 976
				 	current_year < 1010
			 	}
			 	NOT = { exists = global_var:albucasis_created } #makes sure that he wasn't already spawned by the event elsewhere
			 	is_ai = no
			 	scope:xenophilic_culture = culture:andalusian 
		 	}
		 	create_character = { 
			 	age = { 40 70 } #their rough age during the period of their flourishing 
			 	location = root.capital_province
			 	name = "Abu al-Qasim Al-Zahrawi" #Albucasis
			 	gender = male
			 	template = scholar_character
			 	trait = intellect_good_3 #He was one of the Middle Ages' greatest geniuses
			 	trait = lifestyle_herbalist 
			 	trait = lifestyle_physician
			 	trait = education_learning_4
			 	random_traits_list = { #his personality, extrapolated from my research
				 	count = 3
				 	ambitious = {}
				 	compassionate = {}
				 	calm = {}
				 	diligent = {}
				 	humble = {}
				 	patient = {}
			 	}
			 	random_traits_list = { #this is to hint to the player why he was exiled from the previous court 
				 	count = 1
				 	fornicator = {}
				 	deviant = {}
				 	sodomite = {}		
			 	}
			 	culture = culture:andalusian
			 	dynasty = none 
			 	faith = faith:muwalladi
			 	save_scope_as = albucasis_physician #this is needed to get the loc right 	
		 	}
		 	set_global_variable = albucasis_created 
		 	scope:albucasis_physician = {
				save_scope_as = great_physician #this is to create one easy, generic scope for use in the rest of the event
		 	}
	 	}

	 	else_if = {
		 	limit = { #their rough period of activity
			 	AND = {
				 	current_year > 1125
				 	current_year < 1165
			 	}
			 	NOT = { exists = global_var:avenzoar_created } #makes sure that he wasn't already spawned by the event elsewhere
			 	is_ai = no
			 	scope:xenophilic_culture = culture:andalusian 
		 	}
			create_character = {
			 	age = { 31 71 } #their rough age during the period of their flourishing 
			 	location = root.capital_province
			 	name = "Abū Marwān ibn Zuhr" #Avenzoar
			 	gender = male
			 	template = scholar_character
			 	trait = intellect_good_2
			 	trait = scholar 
			 	trait = lifestyle_physician 
			 	trait = education_learning_4
			 	random_traits_list = { #his personality, extrapolated from my research 
				 	count = 3
				 	diligent = {}
				 	cynical = {}
				 	humble = {}
				 	vengeful = {} #He was bitter over having been exiled from Morocco 
			 	}
			 	random_traits_list = { #this is to hint to the player why he was exiled from the previous court
				 	count = 1
				 	fornicator = {}
				 	deviant = {}
				 	sodomite = {}
				 	murderer = {}		
				}
			 	culture = culture:andalusian
			 	dynasty = none
			 	faith = faith:muwalladi
			 	save_scope_as = avenzoar_physician 	
		 	}
		 	
		 	set_global_variable = avenzoar_created
		 	scope:avenzoar_physician = {
			 	save_scope_as = great_physician
		 	} 
	 	}

	 	else_if = {
		 	limit = { #their rough period of activity
			 	AND = {
				 	current_year > 1140
				 	current_year < 1180
			 	}	
			 	NOT = { exists = global_var:tufail_created } #makes sure that he wasn't already spawned by the event elsewhere
			 	is_ai = no
			 	scope:xenophilic_culture = culture:andalusian 
		 	}
		 	create_character = {
			 	age = { 35 75 } #their rough age during the period of their flourishing 
			 	location = root.capital_province
			 	name = "Abū Bakr ibn Tufail" #Ibn Tufail
			 	gender = male
			 	template = scholar_character
			 	trait = intellect_good_2
			 	trait = theologian 
			 	trait = lifestyle_physician 
			 	trait = education_learning_3
			 	trait = journaller #He was an avid writer 
			 	random_traits_list = { #his personality, extrapolated from my research 
				 	count = 3
				 	diligent = {}
				 	calm = {}
				 	humble = {}
				 	trusting = {}
			 	}
			 	random_traits_list = { #this is to hint to the player why he was exiled from the previous court
				 	count = 1
				 	fornicator = {}
				 	deviant = {}
				 	sodomite = {}
				 	witch = {}	
			 	}
			 	culture = culture:andalusian
			 	dynasty = none 
			 	faith = faith:muwalladi
			 	save_scope_as = tufail_physician 	
		 	}
		 	set_global_variable = tufail_created
		 	scope:tufail_physician = {
			 	save_scope_as = great_physician
		 	}	
	 	}
	 

	 else = { #or it defaults to a random one 
		 create_character = {
			 age = { 32 50 }
			 location = root.capital_province
			 template = scholar_character
			 trait = education_learning_3
			 trait = lifestyle_physician 
			 trait = mortal
			 random_traits_list = {
				 count = 3
				 ambitious = {}
				 calm = {}
				 diligent = {}
				 cynical = {}
				 humble = {}
				 patient = {}
			 }
			 random_traits_list = { ##his is to hint to the player why he was exiled from the previous court
				 count = 1
				 fornicator = {}
				 deviant = {}
				 sodomite = {}
				 incestuous = {}
				 witch = {}
			 }
			 culture = scope:xenophilic_culture 
			 faith = faith:innocence
			 save_scope_as = great_physician 
		 }
	 }

	 	hidden_effect = {
		 	scope:great_physician = {
		 		add_trait_xp = {
	                trait = lifestyle_physician
	                value = 100
	            }				
		 	}
		}

	 	random_neighboring_and_across_water_top_liege_realm_owner = {
		 	limit = { 
			 	AND = {
				 	neighboring_ruler_proper_culture_trigger = yes #the event prefers the neighboring ruler to be of these cultures, since it makes the most sense histrically for the scholar to have been at that court. 
				 	is_ai = yes
			 	}
		 	}
		 	alternative_limit = { is_ai = yes}		
			save_scope_as = neighboring_ruler 	
		}	

	 	if = { #if you have a court physician already, he has a stake in this! 
		 	limit = {
			 	court_physician_available_trigger = yes
		 	}
		 	save_court_physician_as_effect = { SCOPE_NAME = scoped_physician }
	 	}	
 	}

 	option = { #I could use a new physician...  
	 	name = fp2_struggle.1002.a

	 	ai_chance = { #rational AIs pick this option
		 	base = 10
		 	ai_value_modifier = {
				ai_rationality = 0.7
			 	ai_zeal = -0.7 
		 	}
		}

	 	stress_impact = {
			# Conservative characters don't want to do this. 
			content = minor_stress_impact_gain
			 
			# Nor do self-absorbed ones 
			arrogant = minor_stress_impact_gain
			callous = minor_stress_impact_gain 
			greedy = minor_stress_impact_gain
	 	}	

	 	remove_treasury_or_gold = major_treasury_or_gold_value #this guy is expensive!

	 	add_courtier = scope:great_physician #he's added to root's court 

	 	court_position_grant_effect = {
	 		EMPLOYER = root
	 		CANDIDATE = scope:great_physician
	 		POS = court_physician
	 	}

	 	scope:great_physician = { #naturally, the polymath likes to get a new job
		 	add_opinion = {
			 	target = root
			 	opinion = 10
			 	modifier = hired_me_opinion
		 	}
	 	}

	 	scope:neighboring_ruler = { #but the neighboring ruler gets angry that you harbor him
		 	progress_towards_rival_effect = {
				REASON = rival_harbored_polymath
			 	CHARACTER = root
			 	OPINION = 0
		 	}
	 	}

	 	add_character_modifier = { #while you get inspired! 
		 	modifier = inspired_medicine_modifier
		 	years = 20  
	 	} 
 	}

 	option = { #I do not need you, I can read myself. 
	 	name = fp2_struggle.1002.b
	 	flavor = fp2_struggle.1002.b.tt
	 
	 	trigger = { #This only fires after Avicenna's life, as his books are referenced. 
		 	current_year >= 1030 
		 	learning >= medium_skill_rating #and you have to be at least somewhat learned to have this option appear, otherwise it'd be superflous 
		 	NOT = {
			 	exists = scope:scoped_physician
		 	}
	 	}

	 	ai_chance = { #energetic, overconfident AI chooses this 
		 	base = 10
		 	ai_value_modifier = {
				ai_energy = 0.7
				ai_boldness = 0.6
				ai_rationality = 0.4
			 	ai_zeal = -0.6
			 	ai_greed = -0.6 
		 	}
		}

		stress_impact = {
			# Conservative, dull or cheap characters won't do this
			content = minor_stress_impact_gain
			greedy = minor_stress_impact_gain
			lazy = minor_stress_impact_gain
			zealous = minor_stress_impact_gain
			dull = medium_stress_impact_gain 
	 	}

	 	custom_tooltip = fp2_struggle.1002.physicianleaves

	 	remove_short_term_gold = minor_gold_value #books are expensive! 

	 	if = {
		 	limit = { has_lifestyle = learning_lifestyle }
		 	add_learning_lifestyle_xp = medium_lifestyle_experience
	 	}

	 	if = { #your physician gets disappointed for your lack of trust in them 
		 	limit = { exists = scope:scoped_physician }
		 	scope:scoped_physician = {
			 	add_opinion = {
				 	target = root
				 	opinion = -10
				 	modifier = disappointed_opinion	
			 	}
		 	}
	 	}

	 	duel = { #you try to read Arabic books 
		 	skill = learning
		 	value = medium_skill_rating

		 	20 = {
			 	compare_modifier = {
				 	value = scope:duel_value
				 	multiplier = 2
			 	}
			 	send_interface_toast = { #you succeed! 
				 	title = reading_avicenna_toast.success
				 	left_icon = root
				 	root = {
					 	add_character_modifier = {
						 	modifier = inspired_medicine_modifier 
						 	years = 20 
					 	} 
				 	} 
			 	}
		 	}
		 	20 = {
			 	compare_modifier = {
				 	value = scope:duel_value
				 	multiplier = -1
			 	}
			 	send_interface_toast = { #you misunderstod something!
				 	title = reading_avicenna_toast.failure
				 	left_icon = root
				 	root = {
					 	add_character_modifier = {
							modifier = misread_medicine_incompetence_modifier 
							years = 20 
					 	}
				 	}
			 	}
		 	}
	 	}		
	}


 	option = { #What do I need you for? I can read Greek myself    
	 	name = fp2_struggle.1002.c
	 	flavor = fp2_struggle.1002.c.tt

	 	trigger = { #This triggers for the early period, before the Canon of Medicine was published. 
		 	current_date <= 1030.1.1 
		 	learning >= medium_skill_rating 
		 	NOT = {
			 	exists = scope:scoped_physician
		 	}
	 	}

	 	ai_chance = { #energetic AI are the most likely to attempt this in this early time period 
		 	base = 10
		 	ai_value_modifier = {
				ai_energy = 0.8
			 	ai_rationality = 0.2 
			 	ai_zeal = -0.2
		 	}
		}

	 	stress_impact = {
		 	# Conservative, dull or cheap characters won't do this
		 	content = minor_stress_impact_gain
		 	greedy = minor_stress_impact_gain
		 	lazy = minor_stress_impact_gain
		 	zealous = minor_stress_impact_gain
		 	dull = medium_stress_impact_gain 
	 	}

	 	custom_tooltip = fp2_struggle.1002.physicianleaves

	 	remove_short_term_gold = minor_gold_value #books are really expensive in this early period

	 	if = {
		 	limit = { has_lifestyle = learning_lifestyle }
		 	add_learning_lifestyle_xp = medium_lifestyle_experience
	 	}

	 	if = {
		 	limit = { exists = scope:scoped_physician } #your physician still gets disappointed in you
		 	scope:scoped_physician = {
			 	add_opinion = {
				 	target = root
				 	opinion = -10
				 	modifier = disappointed_opinion	
				 }
		 	}
	 	}

	 	duel = { #this duel is difficult - it's mostly an option for extremely learned or overconfident rulers. 
		 	skill = learning
		 	value = high_skill_rating

		 	20 = {
			 	compare_modifier = {
					value = scope:duel_value
					multiplier = 2
				}
			 	send_interface_toast = {
				 	title = reading_hippocrates_toast.success #You can read greek! 
				 	left_icon = root
				 	root = {
					 	add_character_modifier = {
						 	modifier = medical_insights_modifier 
						 	years = 20 
						 } 
					 } 
			 	}
		 	}
		 	20 = {
			 	compare_modifier = {
				 	value = scope:duel_value
				 	multiplier = -1
			 	}
			 	send_interface_toast = {
				 	title = reading_hippocrates_toast.failure #apparently, your Greek skills aren't all you cranked them up to be. 
				 	left_icon = root
				 	root = {
					 	add_character_modifier = {
							modifier = cannot_read_greek_modifier 
							years = 20 
					 	}
				 	}
			 	}
		 	}	
	 	}				
 	}

 	option = { #I will send you back from whence you came...in chains.    
	 	name = fp2_struggle.1002.d

	 	ai_chance = { #but vengeful ones sure love it! 
		 	base = 10
		 	ai_value_modifier = {
				ai_vengefulness = 0.8
			 	ai_honor = -0.2
		 	}
		}

	 	stress_impact = {
			#Caring, carefree or just characters won't do this
		 	generous = minor_stress_impact_gain
		 	gregarious = minor_stress_impact_gain
		 	just = minor_stress_impact_gain
		 	trusting = minor_stress_impact_gain
		 	compassionate = major_stress_impact_gain
		 	forgiving = major_stress_impact_gain 

		 	#But arbitrary bastards love it
		 	arbitrary = minor_stress_impact_loss 
	 	}

	 	scope:great_physician = { #the polymath, naturally, gets sad that you send him back to his disgruntled former employer. 
		 	add_opinion = {
			 	target = root
			 	opinion = -40
			 	modifier = left_me_to_wolves_opinion
		 	}
	 	}
		 
	 	if = { #but your current physician is very happy! 
		 	limit = { exists = scope:scoped_physician }
		 	scope:scoped_physician = {
			 	add_opinion = {
				 	target = root
				 	opinion = 20
				 	modifier = let_me_keep_my_job_opinion 
			 	}
		 	}
	 	}

	 	scope:neighboring_ruler = { #as is the neighboring ruler, especially if he is your friend
		 	if = {
			 	limit = { 
			 	has_relation_friend = root
			 	}
				add_opinion = {
					target = root
					modifier = strengthened_friendship_opinion
			 	}
			}	
		 	else = {
			 	progress_towards_friend_effect = {
					REASON = friend_returned_refugee
					CHARACTER = root
					OPINION = 0
			 	}
		 	}	
	 	}

	 	add_dread = minor_dread_gain	#you gain some dread for doing this, naturally

	 	custom_tooltip = fp2_struggle.1001.physician_imprisoned 
	 	hidden_effect = {
		 	if = {
			 	limit = {
				 	scope:neighboring_ruler = {
					 	is_ruler = yes 
				 	}
			 	}
			 	scope:great_physician = { #while the polymath gets to languish in a dungeon 
				   	hard_imprison_character_effect = {
					   TARGET = this
					   IMPRISONER = scope:neighboring_ruler
					}
				}
			}
			else = {
				scope:great_physician = {
					silent_disappearance_effect = yes
				}
			}
		}
 	}

 	option = { #Wash my hands? Are you insane?"   
	 	name = fp2_struggle.1002.e
	 
	 	trigger = {	#This only triggers for Christianity and similar faiths 
		 	faith = {
			   	has_doctrine_parameter = theocracy_temple_lease	
			   	NOR = {
				 	has_doctrine_parameter = legalism_modified_law_costs
				   	has_doctrine_parameter = literalist_debate_enabled 
			 	}
		 	} 
		 	NOT = { has_lifestyle = learning_lifestyle } #So that this doesn't fire if you have the "Wash your hands" perk
	 	}

		 ai_chance = { #and fanatics don't care about hygiene...apparently 
		 	base = 10
		 	ai_value_modifier = {
				ai_zeal = 0.8
			 	ai_rationality = -0.8
		 	}
		}

	 	stress_impact = {
		 	# Innovative or nervous chracters wouldn't pick this option. 
		 	ambitious = minor_stress_impact_gain
		 	craven = minor_stress_impact_gain
			  
		 	#But stubborn or content ones would
		 	content = minor_stress_impact_loss
		 	lazy = minor_stress_impact_loss
		 	stubborn = minor_stress_impact_loss
		 	eccentric = minor_stress_impact_loss
	 	}
 
	 	custom_tooltip = fp2_struggle.1002.physicianleaves

	 	if = { #your physician, again, loves that they get to keep their job
		 	limit = { exists = scope:scoped_physician }
		 	scope:scoped_physician = {
			 	add_opinion = {
				 	target = root
				 	opinion = 20
				 	modifier = let_me_keep_my_job_opinion
			 	}
		 	}
	 	}
 
	 	add_piety = medium_piety_gain #and your faith rewards you for turning away the heathen 

	 	add_character_modifier = { #but you're rolling in filth
		 	modifier = rolling_in_filth_modifier
		 	years = 5  
	 	} 
 	}



 	option = { #Begone, innovation should only come from God.  
	 	name = fp2_struggle.1002.f
	 
	 	trigger = {	
		 	current_year >= 1065 #because this option refers to developments in islam that happened within the Seljuk empire 
		 	faith = { #it checks for doctrines, rather than islam itself, to make the event more dynamic 
			 	OR = {
				   	has_doctrine_parameter = legalism_modified_law_costs
				   	has_doctrine_parameter = literalist_debate_enabled 
				   	has_doctrine_parameter = religious_legal_pronouncements_law_cost_reduction 
			 	}
		 	} 
	 	}

	 	ai_chance = { #zealous AIs pick this, but it's not entirely unrational - just hostile to new ideas. 
		 	base = 10
		 	ai_value_modifier = {
				ai_zeal = 0.8
			 	ai_rationality = -0.2
		 	}
		}

		 stress_impact = {
		 	#True rationalists abhor this option
		  	ambitious = medium_stress_impact_gain
		 	diligent = medium_stress_impact_gain
			  
		 	#But stubborn and fanatical ones like it
		 	content = minor_stress_impact_loss
		 	stubborn = minor_stress_impact_loss
		 	zealous = minor_stress_impact_loss 
		 	eccentric = minor_stress_impact_loss 
	 	}

	 	custom_tooltip = fp2_struggle.1002.physicianleaves

	 	if = { #your physician, again, loves that they get to keep their job
		 	limit = { exists = scope:scoped_physician }
		 	scope:scoped_physician = {
			 	add_opinion = {
				 	target = root
				 	opinion = 20
				 	modifier = let_me_keep_my_job_opinion	
			 	}
		 	}
	 	}

	 	scope:neighboring_ruler = { #the neighboring ruler likes that you rebuked the polymath, at least
		 	add_opinion = {
			 	target = root
			 	opinion = 10
			 	modifier = rejected_my_enemy_opinion
		 	}
	 	}
	 
	 	add_character_modifier = { #but you draw closer to the Nizamiyah movement, rejecting innovation. 
		 	modifier = anti_innovation_muslim_modifier  
		 	years = 15  
	 	} 		
 	} 
}

###################################
# Soul of Iron
# By Ola Jentzsch
###################################
fp2_struggle.1010 = { # Soul of Iron, by Ola Jentzsch
	type = character_event
	title = fp2_struggle.1010.t
	desc = fp2_struggle.1010.desc
	theme = realm

	left_portrait = {
		character = root
		animation = happiness #root smells an opportunity! 
	}
	right_portrait = {
		character = scope:great_swordsmith
		animation = scheme #he's a scheming bastard, kinda 
	}

	
	trigger = { #The province must also be involved in the Iberian struggle 
		is_ai = no
		has_fp2_dlc_trigger = yes
		any_held_county = {
			any_county_province = {
				has_building_or_higher = blacksmiths_01 #This event needs ROOT to have a blacksmith building
			}
		}
		fp2_character_involved_in_struggle_trigger = yes 
	}

	cooldown = { years = 100 }

	immediate = {

		random_held_county = { #this is to find the county that has the blacksmith
			limit = { 
				any_county_province = {
					has_building_or_higher = blacksmiths_01
				}
			}
			save_scope_as = blacksmith_county #this scopes it - note that it might be the same county as toledo_county; that is intentional. 
		}

		title:b_toledo = { save_scope_as = toledo_holding } #this is used in the localization

		title:c_toledo = { save_scope_as = toledo_county } #this is used in option c, as well as the localization

		create_character = { #this is the mighty blacksmith that the event needs
			age = { 45 55 } #he's experienced and aging, but not old
			location = root.capital_province
			gender_female_chance = root_faith_dominant_gender_female_chance #could be female, if given the right context. 
			trait = intellect_good_1 #he's a genius craftsman
			trait = strong #and a blacksmith...
			trait = arrogant #he's supremely gifted, but also extremely arrogant, Fëanor basically 
			trait = mortal
			random_traits_list = { #the rest of his questionable personality 
				count = 2
				ambitious = {}
				diligent = {}
				callous = {}
				greedy = {}
				patient = {}
				stubborn = {}
				vengeful = {}
			}
			random_traits_list = { #something fun to give him character!
				count = 1
				one_eyed = {}
				scarred = {}
			}
			culture = scope:toledo_county.culture
			faith = faith:innocence
			dynasty = none 
			save_scope_as = great_swordsmith 	#this saves him as a scope so we can get nice effects to bounce off him! 
		}

		hidden_effect = {
			scope:great_swordsmith = {
				add_character_modifier = {
					modifier = master_smith_npc_modifier #this is a neat modifier he gets as a master smith. it's pretty powerful, giving a boost to Stewardship and gold income, but since he's an NPC, it doesn't matter much. It's mostly to create flavor if the player actually examines his stats. 
				}
			}
		}
	}


	option = { #Let us make a compromise
	name = fp2_struggle.1010.a
	flavor = toledo_compromise_flavor

		trigger = { #root needs to control Toledo, and it needs to have a blacksmith building. 
			any_held_county = {
				any_county_province = { 
					barony = title:b_toledo
				}
			}
			scope:toledo_county = { #so that this option doesn't fire twice 
				NOT = { has_county_modifier = toledo_steel_county_modifier }	
			}
		}

		ai_chance = { #Smart, patient AIs pick this option, others are more likely to go for a bolder approach. 
        	base = 10
        	ai_value_modifier = {
           		ai_rationality = 1
           		ai_honor = 0.5
           		ai_boldness = -0.5
           		ai_zeal = -0.5
        	}
   		}

   		stress_impact = { #arrogant or visionless rulers dislike this option 
   			arrogant = minor_stress_impact_gain
   			callous = minor_stress_impact_gain
   			content = minor_stress_impact_gain
   			wrathful = minor_stress_impact_gain
   		}

   		remove_short_term_gold = major_gold_value #someone still has to be bribed here 

   		scope:toledo_county = {
			add_county_modifier = {
				modifier = toledo_steel_county_modifier		
			}
		}

		scope:toledo_county = {
			add_county_modifier = {	
				modifier = governance_1041_quarreling_guilds_modifier
				years = 20
			}	
		}		
   	}

   	option = { #Whatever knowledge you possess, I shall draw it out. 
	name = fp2_struggle.1010.b
	flavor = fp2_struggle.1010.swordsmith_imprisoned 

		trigger = {
			OR = {
				has_trait = schemer
				has_trait = torturer
				has_trait = paranoid 
				dread >= high_dread 
			}
			NAND = {
				any_held_county = {
					any_county_province = { 
						barony = title:b_toledo
					}
				}
				scope:toledo_county = { #so that this option doesn't fire twice 
					NOT = { has_county_modifier = toledo_steel_county_modifier }
				}
			}
		}
		
		
		scope:great_swordsmith = { #while the great swordsmiths gets to languish in a dungeon 
  			hard_imprison_character_effect = {
  				TARGET = this
  				IMPRISONER = root
   			}
   		}
   	

		ai_chance = { #Compassionate or just AI wouldn't do this, but hateful paranoid psychopats, sure!  Perhaps the smith even deserved it... 
        	base = 10
        	ai_value_modifier = {
           		ai_vengefulness = 1
           		ai_honor = -1 		
        	}
   		}

   		stress_impact = { #this is not what a Buddha would do 
   			compassionate = major_stress_impact_gain
   			generous = medium_stress_impact_gain
   			gregarious = medium_stress_impact_gain
   			just = medium_stress_impact_gain
   		}

   		add_dread = minor_dread_gain	#you gain some dread for doing this, naturally

   		scope:great_swordsmith = {
   			add_character_modifier = {
 				modifier = recently_tortured
  				years = 5
  			}
  		}


  		add_character_modifier = {
  			modifier =  tortured_smith_spilling_secrets_modifier
  			years = 25 
  		}

   		custom_tooltip = fp2_struggle.1010.compassionate_courtiers
		hidden_effect = { #Compassionate or righteous courtiers will secretly dislike this 
   			every_courtier = {
   				IF = {
   					limit = {
   						OR = {
   							has_trait = compassionate
   							has_trait = just
   						}
   					}
   					add_opinion = {
   						target = root
   						opinion = -10
   						modifier = cruelty_opinion
   					}
   				}
   			}
   		}
   	}

	option = { #You shall have it, if you make swords for my armies 
		name = fp2_struggle.1010.c
		flavor = fp2_struggle.1010.smithgoesaway

		ai_chance = { #ambitious AIs pick this option
        	base = 10
        	ai_value_modifier = {
           		ai_energy = 0.7
            	ai_vengefulness = 0.7 
        	}
   		}

   		stress_impact = { 
   			content = minor_stress_impact_gain
   			craven = minor_stress_impact_gain
   			greedy = minor_stress_impact_gain
   			just = minor_stress_impact_gain
   		}

   		remove_treasury_or_gold = major_treasury_or_gold_value #this guy is expensive!

   		add_character_modifier = { #as promised, your armies gets equipped with Toledo steel! 
   			modifier = toledo_steel_armaments_modifier 
   			years = 50
   		}

   		scope:blacksmith_county = { #the great smith usurps the blacksmiths' guild, with your blessing
			add_county_modifier = {
				modifier = county_corruption_uncooperative_guilds_modifier
				years = 10
			}
		}
		
		custom_tooltip = fp2_struggle.1010.paranoid_rivals  #your neighbors gets really paranoid when they learn about this
		hidden_effect = {
			struggle:reconquista_struggle = {
				every_involved_ruler = {
					limit = {
						NOT = { is_allied_to = root }	
						character_is_realm_neighbor = root 	
					}
					add_opinion = {
						target = root
						opinion = -20
						modifier = threatened_by_buildup_opinion
					}
				}
			}
		}
   	}

   	option = { #Make me Iberia's finest blade, and all the smithies shall be yours
		name = fp2_struggle.1010.d

		flavor = fp2_struggle.1010.smithmakesweapon #the master swordsmiths stays in your court for the time being, to make the great sword he promised you. 

   		add_courtier = scope:great_swordsmith 
   	
   		hidden_effect = {
   			scope:great_swordsmith = {
   				set_knight_status = forbid #this is to prevent him being auto-turned into a knight during his stay, as he tends to get quite high prowess. The player can still make him a knight manually if they insist on it. 
   			}
   		}

		ai_chance = { #Self-absorbed AIs pick this option
        	base = 10
        	ai_value_modifier = {
           		ai_greed = 0.7
           		ai_boldness = 0.7 
        	}
   		}

   		stress_impact = { #this is an extravagant option, not for the humble or temperate - but just people don't like it either, since it still lets the blacksmith usurp the guilds. 
   			humble = minor_stress_impact_gain
   			just = minor_stress_impact_gain
   			temperate = minor_stress_impact_gain
   		}

   		remove_short_term_gold = major_gold_value #this guy knows what he's worth!

   		scope:blacksmith_county = { #the guild gets usurped by the arrogant master smith! 
			add_county_modifier = {
				modifier = county_corruption_uncooperative_guilds_modifier
				years = 10
			}
		}

		hidden_effect = { #this looks weird in the tooltip otherwise!
			random_list = { #I recommend increasing the odds for the special cool sword when testing this event! 
				25 = { #You have a 25% chance of getting a really cool sword here! 
					trigger = { is_ai = no } #this option is just for players, to create less inflation on awesume swords. 
					trigger_event = {
						id = fp2_struggle.1011 
						days = { 30 60 }
					}
				}
				75 = { #but you can still get a nice toledo blade! 
					trigger_event = {
						id = fp2_struggle.1012
  						days = { 30 60 }
					}
				}
			}
		}
   	}

   	option = { #I will not anger the guilds for your vanity.  
	name = fp2_struggle.1010.e

	flavor = fp2_struggle.1010.swordsmith_leaves
		
		ai_chance = { #Lazy or worried AI pick this option
        	base = 10
        	ai_value_modifier = {
           		ai_energy = -0.7
           		ai_greed = 0.3	
           		ai_boldness = -0.5
        	}
   		}

   		stress_impact = { #this is not the option for opportunists, but a good option for some humble stress loss
   			ambitious = major_stress_impact_gain
   			diligent = medium_stress_impact_gain
   			content = minor_stress_impact_loss
   			humble = minor_stress_impact_loss
   			temperate = minor_stress_impact_loss 
   			paranoid = minor_stress_impact_loss 		 
   		}

   		scope:blacksmith_county = { #You curry favor with the blacksmith's guild 
			add_county_modifier = {
				modifier = guild_rights_protected_modifier
				years = 20
			}
		}

   		scope:great_swordsmith = {
   			add_opinion = {
   				target = root
   				modifier = insulted_opinion
  			}
  		}	
   	}
}

fp2_struggle.1011 = { # The Masterwork, by Ola Jentzsch
	type = character_event 
	title = fp2_struggle.1011.t
	desc = fp2_struggle.1011.desc
	theme = realm

	left_portrait = {
		character = root
		animation = admiration 
	}
	right_portrait = {
		character = scope:great_swordsmith
		animation = marshal 
	}

	artifact = { # To display the artifact in the event-window
	    target = scope:amazing_toledo_sword 
	    position = lower_right_portrait
	}
	
	trigger = { 
		has_fp2_dlc_trigger = yes
		scope:great_swordsmith = {
			is_available_healthy_ai_adult = yes
		}
	}

	immediate = {

		save_scope_as = owner 
		set_artifact_rarity_illustrious = yes 

		create_artifact = {	
			name = awesome_toledo_sword_name 
			creator = scope:great_swordsmith
			description = awesome_toledo_sword_desc 
			visuals = sword
			type = sword 
			modifier = artifact_amazing_toledo_sword_modifier
			wealth = scope:wealth  # This comes from the scripted effect above
			quality = scope:quality # This comes from the scripted effect above
			save_scope_as = amazing_toledo_sword # Allows the sword to be accessed via scope after its creation
		}		
	}

	option = { #Martiello, the hammer
	name = fp2_struggle.1011.a

		trigger = { 
			root = {
				culture = { has_cultural_pillar = language_iberian }
			}
		}
		
		scope:amazing_toledo_sword = { set_artifact_name = martiello_name }

		custom_tooltip = fp2_struggle.1011.swordsmith_leaves
		hidden_effect = {
			remove_courtier_or_guest = scope:great_swordsmith 
		}
	}

	option = { #Tiniebra, the darkness 
	name = fp2_struggle.1011.b

		trigger = { 
			root = {
				culture = { has_cultural_pillar = language_iberian }
			}
		}

		scope:amazing_toledo_sword = { set_artifact_name = tiniebra_name }

		custom_tooltip = fp2_struggle.1011.swordsmith_leaves
		hidden_effect = {
			remove_courtier_or_guest = scope:great_swordsmith 
		}
	}

	option = { #Vermejo, the red
	name = fp2_struggle.1011.c

		trigger = { 
			root = {
				culture = { has_cultural_pillar = language_iberian }
			}
		}

		scope:amazing_toledo_sword = { set_artifact_name = vermejo_name }

		custom_tooltip = fp2_struggle.1011.swordsmith_leaves
		hidden_effect = {
			remove_courtier_or_guest = scope:great_swordsmith 
		}
	}

	option = { #Jargonça, like the blue gemstone.  
	name = fp2_struggle.1011.d

		trigger = { 
			root = {
				culture = { has_cultural_pillar = language_iberian }
			}
		}

		scope:amazing_toledo_sword = { set_artifact_name = jargonca_name }

		custom_tooltip = fp2_struggle.1011.swordsmith_leaves
		hidden_effect = {
			remove_courtier_or_guest = scope:great_swordsmith 
		}
	}	

	option = { #Suhayl, the glorious.  
	name = fp2_struggle.1011.e

		trigger = { 
			root = {
				culture = { has_cultural_pillar = language_arabic }
			}
		}

		scope:amazing_toledo_sword = { set_artifact_name = suhayl_name }

		custom_tooltip = fp2_struggle.1011.swordsmith_leaves
		hidden_effect = {
			remove_courtier_or_guest = scope:great_swordsmith 
		} 
	}	

	option = { #al-Battar, the cutter  
	name = fp2_struggle.1011.f

		trigger = { 
			root = {
				culture = { has_cultural_pillar = language_arabic }
			}
		}

		scope:amazing_toledo_sword = { set_artifact_name = albattar_name }

		custom_tooltip = fp2_struggle.1011.swordsmith_leaves
		hidden_effect = {
			remove_courtier_or_guest = scope:great_swordsmith 
		}
	}	

	option = { #Qazeeb, of the strong handle 
	name = fp2_struggle.1011.g

		trigger = { 
			root = {
				culture = { has_cultural_pillar = language_arabic }
			}
		}

		scope:amazing_toledo_sword = { set_artifact_name = qazeeb_name }

		custom_tooltip = fp2_struggle.1011.swordsmith_leaves
		hidden_effect = {
			remove_courtier_or_guest = scope:great_swordsmith 
		}
	}	

	option = { #Zumurrud, like the blinding emerald 
	name = fp2_struggle.1011.h

		trigger = { 
			root = {
				culture = { has_cultural_pillar = language_arabic }
			}
		}

		scope:amazing_toledo_sword = { set_artifact_name = zumurrud_name }

		custom_tooltip = fp2_struggle.1011.swordsmith_leaves
		hidden_effect = {
			remove_courtier_or_guest = scope:great_swordsmith 
		}
	}	

	option = { #Ortzi, like the thunder 
	name = fp2_struggle.1011.i

		trigger = { 
			root = {
				culture = { has_cultural_pillar = language_basque }
			}
		}

		scope:amazing_toledo_sword = { set_artifact_name = ortzi_name }

		custom_tooltip = fp2_struggle.1011.swordsmith_leaves
		hidden_effect = {
			remove_courtier_or_guest = scope:great_swordsmith 
		}
	}	

	option = { #Gaueko, the night spirit 
	name = fp2_struggle.1011.j

		trigger = { 
			root = {
				culture = { has_cultural_pillar = language_basque }
			}
		}

		scope:amazing_toledo_sword = { set_artifact_name = gaueko_name }

		custom_tooltip = fp2_struggle.1011.swordsmith_leaves
		hidden_effect = {
			remove_courtier_or_guest = scope:great_swordsmith 
		}
	}	

	option = { #Gorri, the red one
	name = fp2_struggle.1011.k

		trigger = { 
			root = {
				culture = { has_cultural_pillar = language_basque }
			}
		}

		scope:amazing_toledo_sword = { set_artifact_name = gorri_name }

		custom_tooltip = fp2_struggle.1011.swordsmith_leaves
		hidden_effect = {
			remove_courtier_or_guest = scope:great_swordsmith 
		}
	}	

	option = { #Aiztoto, the little knife
	name = fp2_struggle.1011.l

		trigger = { 
			root = {
				culture = { has_cultural_pillar = language_basque }
			}
		}

		scope:amazing_toledo_sword = { set_artifact_name = aiztoto_name }

		custom_tooltip = fp2_struggle.1011.swordsmith_leaves
		hidden_effect = {
			remove_courtier_or_guest = scope:great_swordsmith 
		}
	}	

	option = { #Escremire, the fencer
	name = fp2_struggle.1011.m

		trigger = { 
			root = {
				culture = { has_cultural_pillar = language_occitano_romance }
			}
		}

		scope:amazing_toledo_sword = { set_artifact_name = escremire_name }

		custom_tooltip = fp2_struggle.1011.swordsmith_leaves
		hidden_effect = {
			remove_courtier_or_guest = scope:great_swordsmith 
		}
	}

	option = { #Folha, the leaf
	name = fp2_struggle.1011.n

		trigger = { 
			root = {
				culture = { has_cultural_pillar = language_occitano_romance }
			}
		}

		scope:amazing_toledo_sword = { set_artifact_name = folha_name }

		custom_tooltip = fp2_struggle.1011.swordsmith_leaves
		hidden_effect = {
			remove_courtier_or_guest = scope:great_swordsmith 
		}
	}	

	option = { #Proeza, valour 
	name = fp2_struggle.1011.o

		trigger = { 
			root = {
				culture = { has_cultural_pillar = language_occitano_romance }
			}
		}

		scope:amazing_toledo_sword = { set_artifact_name = proeza_name }

		custom_tooltip = fp2_struggle.1011.swordsmith_leaves
		hidden_effect = {
			remove_courtier_or_guest = scope:great_swordsmith 
		}
	}	

	option = { #Trebalhar, the tormenter 
	name = fp2_struggle.1011.p

		trigger = { 
			root = {
				culture = { has_cultural_pillar = language_occitano_romance }
			}
		}

		scope:amazing_toledo_sword = { set_artifact_name = trebalhar_name }

		custom_tooltip = fp2_struggle.1011.swordsmith_leaves
		hidden_effect = {
			remove_courtier_or_guest = scope:great_swordsmith 
		}
	}	

	option = { #Sufax, like the great hero in days of old
	name = fp2_struggle.1011.q

		trigger = { 
			root = {
				culture = { has_cultural_pillar = language_berber }
			}
		}

		scope:amazing_toledo_sword = { set_artifact_name = sufax_name }

		custom_tooltip = fp2_struggle.1011.swordsmith_leaves
		hidden_effect = {
			remove_courtier_or_guest = scope:great_swordsmith 
		}
	}

	option = { #Toumellalt, the white one.
	name = fp2_struggle.1011.r

		trigger = { 
			root = {
				culture = { has_cultural_pillar = language_berber }
			}
		}

		scope:amazing_toledo_sword = { set_artifact_name = toumellalt_name }

		custom_tooltip = fp2_struggle.1011.swordsmith_leaves
		hidden_effect = {
			remove_courtier_or_guest = scope:great_swordsmith 
		}
	}	

	option = { #Ayugu, the yoke.  
	name = fp2_struggle.1011.s

		trigger = { 
			root = {
				culture = { has_cultural_pillar = language_berber }
			}
		}

		scope:amazing_toledo_sword = { set_artifact_name = ayugu_name }

		custom_tooltip = fp2_struggle.1011.swordsmith_leaves
		hidden_effect = {
			remove_courtier_or_guest = scope:great_swordsmith 
		}
	}	

	option = { #Well, "Ironsoul" of course
	name = fp2_struggle.1011.u

		trigger = { 
			root = {
				culture = {
					NOT = {
						has_cultural_pillar = language_iberian
						has_cultural_pillar = language_arabic
						has_cultural_pillar = language_basque
						has_cultural_pillar = language_occitano_romance
						has_cultural_pillar = language_berber  
					}
				}
			}
		}

		scope:amazing_toledo_sword = { set_artifact_name = ironsoul_name }

		custom_tooltip = fp2_struggle.1011.swordsmith_leaves
		hidden_effect = {
			remove_courtier_or_guest = scope:great_swordsmith 
		}
	}	

	option = { #I quite like "Mistletoe"...
	name = fp2_struggle.1011.v

		trigger = { 
			root = {
				culture = {
					NOT = {
						has_cultural_pillar = language_iberian
						has_cultural_pillar = language_arabic
						has_cultural_pillar = language_basque
						has_cultural_pillar = language_occitano_romance
						has_cultural_pillar = language_berber  
					}
				}
			}
		}

		scope:amazing_toledo_sword = { set_artifact_name = mistletoe_name }

		custom_tooltip = fp2_struggle.1011.swordsmith_leaves
		hidden_effect = {
			remove_courtier_or_guest = scope:great_swordsmith 
		}
	}	

	option = { #Moor-cleaver, what else? 
	name = fp2_struggle.1011.w

		trigger = { 
			has_religion = religion:roadofkings_religion 
			root = {
				culture = {
					NOT = {
						has_cultural_pillar = language_iberian
						has_cultural_pillar = language_arabic
						has_cultural_pillar = language_basque
						has_cultural_pillar = language_occitano_romance
						has_cultural_pillar = language_berber  
					}
				}
			}
		}

		stress_impact = {
   			compassionate = minor_stress_impact_gain
   		}

		scope:amazing_toledo_sword = { set_artifact_name = moormurder_name }

		custom_tooltip = fp2_struggle.1011.swordsmith_leaves
		hidden_effect = {
			remove_courtier_or_guest = scope:great_swordsmith 
		}
	}	

	option = { #Usurper's blade seem fitting, giving what we did to the guilds... 
	name = fp2_struggle.1011.x

		trigger = { 
			root = {
				culture = {
					NOT = {
						has_cultural_pillar = language_iberian
						has_cultural_pillar = language_arabic
						has_cultural_pillar = language_basque
						has_cultural_pillar = language_occitano_romance
						has_cultural_pillar = language_berber  
					}
				}
			}
		}

		scope:amazing_toledo_sword = { set_artifact_name = usurperblade_name }

		custom_tooltip = fp2_struggle.1011.swordsmith_leaves
		hidden_effect = {
			remove_courtier_or_guest = scope:great_swordsmith 
		}
	}	
}

fp2_struggle.1012 = { # Soul of Iron (3), by Ola Jentzsch
	type = character_event
	title = fp2_struggle.1012.t
	desc = fp2_struggle.1012.desc
	theme = realm

	left_portrait = {
		character = root
		animation = admiration 
	}
	right_portrait = {
		character = scope:great_swordsmith
		animation = marshal 
	}

	artifact = { # To display the artifact in the event-window
	    target = scope:toledo_sword 
	    position = lower_right_portrait
	}
	
	trigger = { 
		has_fp2_dlc_trigger = yes
		scope:great_swordsmith = {
			is_available_healthy_ai_adult = yes
		}
	}

	immediate = {

		save_scope_as = owner
		set_artifact_rarity_masterwork = yes 

		create_artifact = {	
			name = toledo_sword_name 
			creator = scope:great_swordsmith
			description = toledo_sword_desc 
			visuals = sword
			type = sword 
			modifier = artifact_masterwork_toledo_sword_modifier
			wealth = scope:wealth  # This comes from the scripted effect above
			quality = scope:quality # This comes from the scripted effect above
			save_scope_as = toledo_sword # Allows the sword to be accessed via scope after its creation
		}
	}

	option = { #It is...exquisite. You may go in peace. 
	name = fp2_struggle.1012.a
	flavor = fp2_struggle.1012.swordsmith_leaves

		ai_chance = { #Only greedy AI wouldn't pick this option.  
        	base = 10
        	ai_value_modifier = {
           		ai_greed = -1	
        	}
   		}	
		
		remove_courtier_or_guest = scope:great_swordsmith 	
	}

	option = { #It is as promised. May I not convince you to stay and serve me? 
	name = fp2_struggle.1012.b

		ai_chance = { #Only greedy would pick this option.  
        	base = 10
        	ai_value_modifier = {
           		ai_greed = 1	
        	}
   		}
   		
		custom_tooltip = fp2_struggle.1012_swordsmith_stays 
		
		remove_treasury_or_gold = major_treasury_or_gold_value #this guy is expensive!	
	}
}

###################################
# Death of a Councilman
# By Ola Jentzsch
###################################
scripted_trigger fp2_struggle.1020_minority_councillor_faith_trigger = {
	save_temporary_scope_as = fp2_struggle_1020_temp_councillor
	is_ai = yes
	NOT = { is_spouse_of = root }
	root.capital_county.faith = {
		faith_hostility_level = { 
			target = scope:fp2_struggle_1020_temp_councillor.faith 
			value >= faith_hostile_level 
		}
	}
}

fp2_struggle.1020 = {
	orphan = yes
	type = character_event
	title = fp2_struggle.1020.t
	desc = {
		desc = fp2_struggle.1020_desc_opening 
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:minority_councillor = {
						death_reason = death_beaten_by_mob 
					}
				}
				desc = fp2_struggle.1020_desc_beaten_by_mob
			}
			triggered_desc = {
				trigger = {
					scope:minority_councillor = {
						death_reason = death_burned_by_mob 
					}
				}
				desc = fp2_struggle.1020_desc_burned_by_mob
			}
			triggered_desc = {
				trigger = {
					scope:minority_councillor = {
						death_reason = death_hanged_and_disemboweled_by_mob 
					}
				}
				desc = fp2_struggle.1020_desc_hanged_and_disemboweled_by_mob
			}
			triggered_desc = {
				trigger = {
					scope:minority_councillor = {
						death_reason = death_crucified_by_mob 
					}
				}
				desc = fp2_struggle.1020_desc_crucified_by_mob
			}
			triggered_desc = {
				trigger = {
					scope:minority_councillor = {
						death_reason = death_defenestrated_by_mob 
					}
				}
				desc = fp2_struggle.1020_desc_defenestrated_by_mob
			}
			triggered_desc = {
				trigger = {
					scope:minority_councillor = {
						death_reason = death_molten_silver_by_mob 
					}
				}
				desc = fp2_struggle.1020_desc_molten_silver_by_mob
			}
			triggered_desc = {
				trigger = {
					scope:minority_councillor = {
						death_reason = death_torn_to_pieces_by_mob 
					}
				}
				desc = fp2_struggle.1020_desc_torn_to_pieces_by_mob
			}
		}
		first_valid = {
			triggered_desc = {
				trigger = { 
					scope:councillor_executor = {
						exists = var:relative_created 
					}
				}
				desc = fp2_struggle.1020_desc_councillor_had_family
			}
			triggered_desc = {
				trigger = {
					scope:minority_councillor =	{
						fp2_struggle.1020_minority_councillor_faith_trigger = yes 
					}
				}
				desc = fp2_struggle.1020_desc_councillor_had_no_family_faith 
			}		
		}
	}
				
	theme = dread
	cooldown = { years = 15 }
	override_background = { reference = council_chamber }

	left_portrait = {
		character = root
		animation = disbelief 
	}
	right_portrait = {
		character = scope:councillor_executor  
		animation = anger 
	}

	lower_left_portrait = scope:minority_councillor 

	
	trigger = {
		has_fp2_dlc_trigger = yes

		any_councillor = {	fp2_struggle.1020_minority_councillor_faith_trigger = yes }

		capital_county = { county_control < low_county_control_limit } #root's capital having low control isn't strictly necessary, but adds to the emergent feeling here
	}	

	immediate = {
 
 		random_councillor = { #this is the dead councillor
 			limit = { fp2_struggle.1020_minority_councillor_faith_trigger = yes }
			save_scope_as = minority_councillor 
		}

		capital_county = { save_scope_as = unrest_capital } #so we can use the capital for loc 

		scope:minority_councillor = { #and this is how they met their untimely end 
			random_list = {
				10 = {
					death = {
						death_reason = death_beaten_by_mob
					}
				}
				10 = {
					death = {
						death_reason = death_burned_by_mob
					}
				}
				20 = {
					death = {
						death_reason = death_hanged_and_disemboweled_by_mob
					}
				}
				20 = {
					death = {
						death_reason = death_crucified_by_mob
					}
				}
				10 = {
					death = {
						death_reason = death_defenestrated_by_mob
					}
				}
				20 = {
					death = {
						death_reason = death_molten_silver_by_mob
					}
				}
				10 = {
					death = {
						death_reason = death_torn_to_pieces_by_mob 
					}
				}	
			}
		}

		if = { #now let's see if there's any relative of the late councillor that could be considered relevant! 
			limit = {
				any_powerful_vassal = {
					is_ai = yes 
					is_close_or_extended_family_of = scope:minority_councillor 
					is_powerful_vassal = yes
				} 
			}
			random_powerful_vassal = {
				limit = {
					is_ai = yes 
					is_close_or_extended_family_of = scope:minority_councillor 
					is_powerful_vassal = yes 
				}
				save_scope_as = councillor_executor
				set_variable = relative_created #this variable is for use in triggers later
			}	 
		}

		else_if = {
			limit = {
				any_powerful_vassal = {
					is_ai = yes 
					is_close_family_of = scope:minority_councillor 
				} 
			}
			random_powerful_vassal = {
				limit = {
					is_ai = yes 
					is_close_family_of = scope:minority_councillor 
				}
				save_scope_as = councillor_executor
				set_variable = relative_created 
			}
		}

		else_if = {
			limit = {
				any_powerful_vassal = {
					is_ai = yes 
					is_close_or_extended_family_of = scope:minority_councillor 
				} 
			}
			random_powerful_vassal = {
				limit = {
					is_ai = yes 
					is_close_or_extended_family_of = scope:minority_councillor 
				}
				save_scope_as = councillor_executor
				set_variable = relative_created 
			}
		}
			
		else_if = { 
			limit = {
				any_neighboring_and_across_water_top_liege_realm_owner = {
					is_ai = yes
					is_close_or_extended_family_of = scope:minority_councillor 
					OR = {
						fp2_character_involved_in_struggle_trigger = yes
   						fp2_character_interloper_in_struggle_trigger = yes
					}
				}
			}
			random_neighboring_and_across_water_top_liege_realm_owner = {
				limit = {
					is_ai = yes 
					is_close_or_extended_family_of = scope:minority_councillor 
					OR = {
						fp2_character_involved_in_struggle_trigger = yes
   						fp2_character_interloper_in_struggle_trigger = yes
					}
				}
				save_scope_as = councillor_executor 
				set_variable = relative_created
			}
		}

		else_if = { 
			limit = {
				any_ruler = {
					is_ai = yes
					is_close_or_extended_family_of = scope:minority_councillor 
				}
			}
			random_ruler = {
				limit = {
					is_ai = yes 
					is_close_or_extended_family_of = scope:minority_councillor 
				}
				save_scope_as = councillor_executor 
				set_variable = relative_created
			}
		}

		else_if = { 
			limit = {
				any_courtier = {
					is_ai = yes
					is_close_or_extended_family_of = scope:minority_councillor 
				}
			}
			random_courtier = {
				limit = {
					is_ai = yes 
					is_close_or_extended_family_of = scope:minority_councillor 
				}
				save_scope_as = councillor_executor 
				set_variable = relative_created
			}
		}

		else = { #if no relevant relative was found, we instead create a community leader to fire option b with! 
			create_character = {
				age = { 20 80 }
				location = root.capital_province
				template = merchant_template
				culture = scope:minority_councillor.culture 
				faith = scope:minority_councillor.faith 
				save_scope_as = councillor_executor  
			}
			hidden_effect = {
				scope:councillor_executor = { #just because, I want more rotund people 
					add_character_modifier = {
						modifier = obese_modifier 
					}
				}
			}
		}	

		scope:minority_councillor = {
			every_close_or_extended_family_member = {
				custom = all_family_members
				if = {
					limit = { is_ai = yes }
					add_opinion = {
						target = root
						opinion = -20
						modifier = blames_for_death_of_relative_opinion 
					}
				}					
			}		
		}	
	}


	option = { #Make amends to councillor's dynasty
		name = fp2_struggle.1020.a

		trigger = {
			scope:councillor_executor = {
				exists = var:relative_created 
			}
		}

		ai_chance = { #rational and somewhat honorable AIs pick this option
        	base = 10
        	ai_value_modifier = {
           		ai_rationality = 0.5
            	ai_honor = 0.3 
            	#but bold and vengeful ones do not
            	ai_boldness = -0.5
            	ai_vengefulness = -0.5
        	}
   		}

   		stress_impact = {
			#arrogant characters don't care for this
			arrogant = minor_stress_impact_gain
			callous = minor_stress_impact_gain 
			stubborn = minor_stress_impact_gain

			#socially awkward ones aren't fond of it either
			paranoid = minor_stress_impact_gain
			shy = minor_stress_impact_gain
		}

		add_character_modifier = {
			modifier = compelling_apology_modifier 
			years = 10 
		}

		scope:minority_councillor = {
			every_close_or_extended_family_member = {
			custom = all_family_members
				if = {
					limit = { is_ai = yes }
					add_opinion = {
						target = root
						opinion = 10
						modifier = made_amends_opinion 
					}
				}					
			}		
		}		
	}

	option = { #Pay restitution to councillor's people 
		name = fp2_struggle.1020.b

		trigger = {
			scope:councillor_executor = {
				NOT = { exists = var:relative_created }
			}
		}

		ai_chance = { #compassionate AIs takes this option
        	base = 10
        	ai_value_modifier = {
           		ai_compassion = 0.7
            	ai_honor = 0.3 
            	#but zealous and vengeful ones do not
            	ai_zeal = -0.5
            	ai_vengefulness = -0.5
        	}
   		}

   		stress_impact = {
			#arrogant characters don't wanna do this 
			arrogant = minor_stress_impact_gain
			callous = minor_stress_impact_gain 
			stubborn = minor_stress_impact_gain

			#nor those who hate the people
			paranoid = minor_stress_impact_gain
			vengeful = minor_stress_impact_gain
		}

		remove_treasury_or_gold = medium_treasury_or_gold_value #restitution isn't free! 

		add_character_modifier = {
			modifier = restitution_to_minorities_modifier 
			years = 15
		} 			
	}

	option = { #Hunt down the perpetrators 
		name = fp2_struggle.1020.c

		ai_chance = { #energetic and vengeful AI picks this option. 
        	base = 10
        	ai_value_modifier = {
           		ai_energy = 0.5
            	ai_vengefulness = 0.7
            	#but compassionate ones might not
            	ai_compassion = -0.7
        	}
   		}

   		stress_impact = { #this is cruel and a lot of effort... 
			compassionate = minor_stress_impact_gain
			forgiving = minor_stress_impact_gain
			lazy = minor_stress_impact_gain 
		}

		
		add_character_modifier = {
			modifier = memorable_public_execution_modifier 
			years = 10 
		} 
					

		add_prestige = minor_prestige_gain	

		if = { 
			limit = { exists = var:relative_created }
			scope:councillor_executor = {
				add_opinion = {
					target = root
					opinion = 20
					modifier = avenged_relative_opinion	
					
				}
			}
		}		
	}

	option = { #Restore order in the capital 
		name = fp2_struggle.1020.d

		ai_chance = { #rational and compassionate AIs pick this option
        	base = 10
        	ai_value_modifier = {
           		ai_rationality = 0.9
            	ai_compassion = 0.3 
            	#but bold and zealous ones do not
            	ai_boldness = -0.5
            	ai_zeal = -0.5
        	}
   		}

   		stress_impact = {
			#cruel or lazy characters don't bother with this
			callous = minor_stress_impact_gain
			lazy = minor_stress_impact_gain 
			sadistic = minor_stress_impact_gain

			#and vengeful ones would rather pursue revenge. 
			vengeful = minor_stress_impact_gain
		}	

		if = { 
			limit = { exists = var:relative_created }
			scope:councillor_executor = {
				add_opinion = {
					target = root
					opinion = -10
					modifier = ignored_demands_opinion	
				}
			}
		}
		
		add_prestige = minor_prestige_gain 

		root.capital_county = { change_county_control = medium_county_control_gain }										
	}							
}

###################################
# The Vision
# By Ola Jentzsch
###################################
fp2_struggle.1050 = {
	type = character_event 
	title = fp2_struggle.1050.t
	desc = {
		first_valid = {
			desc = fp2_struggle.1050.desc_opening
		}
		first_valid = {
			triggered_desc = {
				trigger = {
					has_religion = religion:christianity_religion
					scope:visionary_spouse= {
						has_religion = religion:christianity_religion 
					}
				}
				desc = fp2_struggle.1050.desc_christian
			}
			triggered_desc = {
				trigger = {
					has_religion = religion:islam_religion
					scope:visionary_spouse= {
						has_religion = religion:islam_religion
					}
				}
				desc = fp2_struggle.1050.desc_islamic 
			}
			triggered_desc = {
				trigger = {
					has_religion = religion:germanic_religion
					scope:visionary_spouse= {
						has_religion = religion:germanic_religion
					}
				}
				desc = fp2_struggle.1050.desc_rampaging_barbarian_heathen 
			}
			desc = fp2_struggle.1050.desc_non_barbarian_heathen	
		}
		first_valid = {
			triggered_desc = {
				trigger = {
					root = {
						OR = {
							culture = culture:andalusian
							culture = culture:bedouin
						}
					}
					scope:visionary_spouse = {
						OR = {
							culture = culture:andalusian
							culture = culture:bedouin
						}
					}
				}
				desc = fp2_struggle.1050.desc_islamic_heritage
			}
			triggered_desc = {
				trigger = {
					has_faith = faith:catholic 
					scope:visionary_spouse= {
						has_faith = faith:catholic
					}
				}
				desc = fp2_struggle.1050.desc_christian_bling_reference_drop
			}
			desc = fp2_struggle.1050.desc_middle_neutral_version
		}
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:visionary_spouse = {
						OR = { 
							has_relation_lover = root
							has_relation_soulmate = root 
						}
					}
				}
				desc = fp2_struggle.1050.desc_love_and_warmth_ending 
			}
			desc = fp2_struggle.1050.desc_no_love_and_warmth_ending 
		}
	}

	theme = death
	override_background = { reference = battlefield } ##

	left_portrait = {
		character = root
		animation = disapproval 
	}
	right_portrait = {
		character = scope:visionary_spouse 
		animation = paranoia 
	}

	
	trigger = { 
		has_fp2_dlc_trigger = yes

		is_landed_or_landless_administrative = yes
		
		any_spouse = { is_courtier = yes }

		character_any_involvement_reconquista_struggle_trigger = yes 

	}
		
	cooldown = { #this event shouldn't fire too often, since the context with the spouse's dream is pretty specific. 
		years = 100
	}


	immediate = {

		random_spouse = { 
			weight = {
				base = 1
				modifier = {
					factor = 5
					this = primary_spouse 
				}
			}
			save_scope_as = visionary_spouse 
		}

		scope:visionary_spouse = {
			add_character_modifier = {
				modifier = foreboding_visions_modifier 
				years = 10 
			}
		}

	}

	#option = {
	#name = fp2_struggle.1050.a
	#
	#	trigger = {
	#		faith = {
	#			OR = {
	#				has_doctrine_parameter = witchcraft_illegal
	#				has_doctrine_parameter = witchcraft_shunned 
	#			}
	#		}
	#	}
	#
	#	ai_chance = { #bold, vengeful and zealous AI goes for this option
    #    	base = 10
    #    	ai_value_modifier = {
    #       		ai_boldness = 0.5
    #        	ai_vengefulness = 0.7 
    #        	ai_zeal = 0.7
    #        	ai_compassion = -1 #whereas compassionate, rational and honorable ones really, really doesn't
    #        	ai_rationality = -1
    #        	ai_honor = -0.5
    #    	}
   	#	}
	#
   	#	stress_impact = { 
   	#		compassionate = major_stress_impact_gain #compassionate people don't accuse their spouse of being a witch
   	#		craven = minor_stress_impact_gain #cravens don't dare throw her in jail
   	#		trusting = medium_stress_impact_gain #and trusting people don't accuse her either
   	#	}
	#
   	#	custom_tooltip = fp2_struggle.1050.spouse_imprisoned #you throw your spouse into the dungeon for being a suspected witch
	#	hidden_effect = {
	#		scope:visionary_spouse = { 
  	#			hard_imprison_character_effect = {
  	#				TARGET = this
  	#				IMPRISONER = root
   	#			}
   	#		}
   	#	}
	#}

	option = {
	name = fp2_struggle.1050.b

		ai_chance = { #lazy zealous AI pick this option 
        	base = 10
        	ai_value_modifier = {
           		ai_zeal = 0.8
           		ai_energy = -0.7
            	ai_vengefulness = -0.7 
        	}
   		}

   		stress_impact = { 
   			cynical = minor_stress_impact_gain #cynics don't really put their faith in God
   		}

   		duel = { #this duel is root trying to make their spouse feel better. 
			skill = diplomacy
			value = medium_skill_rating

			20 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 2
				}
				modifier = {
					add = 15
					has_trait = compassionate
				}
				modifier = {
					add = 20
					has_trait = zealous 
				}
				send_interface_toast = {
					title = comforting_spouse_visionary_toast.success
					left_icon = root
					right_icon = scope:visionary_spouse 

					scope:visionary_spouse = {
						add_opinion = {
							target = root 
							modifier = comforted_opinion
						}
					}
					custom_tooltip = fp2_struggle.1050.condition_might_improve
				}
			}
			20 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -1
				}
				modifier = {
					add = 20
					has_trait = callous
				}
				modifier = {
					add = 10
					has_trait = sadistic
				}
				send_interface_toast = {
					title = comforting_spouse_visionary.failure
					left_icon = root
					right_icon = scope:visionary_spouse
					
					scope:visionary_spouse = {
						add_opinion = {	
							target = root 
							modifier = failed_comfort_opinion
						}	
					}

					custom_tooltip = fp2_struggle.1050.condition_might_get_worse
					hidden_effect = {
						scope:visionary_spouse = {
							add_character_modifier = {
								modifier = mysterious_prophetess_illness_modifier 
								years = 5
							}
						}
					}
				}
			}
		} 
	}

	option = { #Come, tell me more of your visions 
	name = fp2_struggle.1050.c

		ai_chance = { #compassionate AIs pick this option
        	base = 10
        	ai_value_modifier = {
           		ai_compassion = 1
            	ai_energy = 0.5
            	ai_vengefulness = -0.5
        	}
   		}

   		stress_impact = { #unpleasant types don't pick this option... 
   			arrogant = minor_stress_impact_gain 
   			callous = medium_stress_impact_gain
   			sadistic = medium_stress_impact_gain
			eccentric = minor_stress_impact_loss
   		}

   		scope:visionary_spouse = { 
			if = {
				limit = { 
					OR = { 
						has_relation_lover = root
						has_relation_soulmate = root 
					}
				}
				add_opinion = {
					target = root
					modifier = listened_opinion
				}
			}	
			else = {
				progress_towards_lover_effect = {
					CHARACTER = root
					REASON = lover_comforted_nightmare
					OPINION = 0
				}
			}	
		}

		custom_tooltip = fp2_struggle.1050.condition_might_improve
					#hidden_effect = {
					#	scope:visionary_spouse = { 
					#		recover_from_disease_effect = { DISEASE = ill }		
					#	}
					#}

		add_character_modifier = {
			modifier = frightened_by_portent_modifier
			years = 10 
		}
	}

	option = { #Leave me be, I am planning my next conquest 
	name = fp2_struggle.1050.d

		ai_chance = { #Ambitious AIs pick this option
        	base = 10
        	ai_value_modifier = {
           		ai_boldness = 0.5
            	ai_energy = 0.7 
            	ai_greed = 0.5
            	ai_compassion = -0.7
        	}
   		}

   		stress_impact = { 
   			compassionate = minor_stress_impact_gain
			eccentric = minor_stress_impact_gain
   		}

   		scope:visionary_spouse = {
			add_opinion = {	
				target = root 
				modifier = failed_comfort_opinion
			}	
		}

   		custom_tooltip = fp2_struggle.1050.condition_might_get_very_worse 
		hidden_effect = {
			random = {
				chance = 90
				scope:visionary_spouse = {
					add_character_modifier = {
						modifier = mysterious_prophetess_illness_modifier 
						years = 5
					}
					#add_trait = depressed_1
				}
			}
		}
	}
}

###################################
# Disorderly Market
# By Hugo Cortell
################################### VSCODE: Use control + / to comment/uncomment entire blocks of code. And control + shift + [ (or ]) to fold/unfold a block!
scripted_trigger fp2_struggle_2000_check_holds_city_scripted_trigger = {
	title_province = { has_holding_type = city_holding }
	exists = holder
	holder != root
}

fp2_struggle.2000 = {
	type = character_event
	title = fp2_struggle.2000.t
	desc = fp2_struggle.2000.desc
	theme = stewardship
	cooldown = { years = 5 }
	override_background = { reference = market }
	left_portrait = root
	right_portrait = {
		character = scope:fp2_2000_market_inspector
		animation = anger
	}

	trigger = {
		has_fp2_dlc_trigger = yes
		has_religion = religion:ashirra_religion
		faith = {
			OR = {
				has_doctrine = tenet_tax_nonbelievers
				has_doctrine = special_doctrine_jizya
				has_doctrine = tenet_religious_legal_pronouncements
				has_doctrine = tenet_legalism
			}
		}

		exists = cp:councillor_steward
		cp:councillor_steward 	= { is_available_ai_adult = yes }
		exists = cp:councillor_court_chaplain
		cp:councillor_court_chaplain = { is_available_ai_adult = yes }
		
		any_sub_realm_barony = { 
			fp2_struggle_2000_check_holds_city_scripted_trigger = yes
		}

		any_pool_character = {
			province = root.capital_province
			has_no_particular_noble_roots_trigger = yes
			is_available_healthy_ai_adult = yes
		}
	}

	immediate = {
		random_sub_realm_barony = { 
			limit = { fp2_struggle_2000_check_holds_city_scripted_trigger = yes }
			county = { save_scope_as = se_2000_county }
		}

		cp:councillor_steward 	= { save_scope_as = 2000_scoped_steward }
		cp:councillor_court_chaplain = { save_scope_as = 2000_scoped_chaplain }

		create_character = {
			age = { 20 50 }
			location = root.capital_province
			gender_female_chance = root_faith_dominant_gender_female_chance
			trait = just
			trait = craven
			trait = patient
			trait = temperate
			trait = mortal
			culture = root.culture
			faith = root.faith

			dynasty = none
			after_creation = { 
				add_gold = { minor_gold_value medium_gold_value }
				add_prestige = { minor_prestige_gain medium_prestige_gain }
				add_piety = { medium_piety_gain major_piety_gain }
			}

			save_scope_as = fp2_2000_market_inspector
		}
		if = { # RoCo
			limit = {
				has_dlc_feature = royal_court
				employs_court_position = chief_qadi_court_position
				any_court_position_holder = {
					type = chief_qadi_court_position
					is_available_ai_adult = yes
				}
			}
			random_court_position_holder = {
				type = chief_qadi_court_position
				limit = {
					is_available_ai_adult = yes
				}
				save_scope_as = fp2_2000_chief_qadi
			}
		}
	}

	option = { # Mandatory lunatic option (now rakish)
		name = fp2_struggle.2000.f
		trigger = { has_trait = rakish }
		stress_impact = { 
			chaste = major_stress_impact_gain
			zealous = major_stress_impact_gain
		}

		flavor = fp2_struggle.2000.f.desc
		send_interface_toast = {
			type = event_stewardship_good_with_text
			title = fp2_struggle.2000.f.notif
			desc = fp2_struggle.2000.f.notif.desc

			stress_impact = { chaste = medium_stress_impact_gain }

			scope:2000_scoped_chaplain = {
				add_opinion = {
					target = root
					modifier = impious_opinion
					opinion = -25
				}
			}

			add_piety = major_piety_loss

			scope:se_2000_county = { 
				add_county_modifier = {
					modifier = fp2_free_market_boom_modifier
					years = 5
				}
			}
			add_character_modifier = {
				modifier = fp2_lenient_towards_foreign_merchants_modifier
				years = 5
			}
		}

		ai_chance = {
			base = 15
		}
	}

	option = { # Guards! Purge!
		name = fp2_struggle.2000.e

		trigger = {
			OR = {
				has_trait = reaver
				has_trait = order_member
				has_trait = aggressive_attacker 
			}
		}
		stress_impact = { 
			just = major_stress_impact_gain
			forgiving = major_stress_impact_gain
			calm = minor_stress_impact_gain
			trusting = medium_stress_impact_gain
		}

		if = {
			limit = { has_trait = sadistic } # Small detail
			send_interface_toast = {
				type = event_toast_effect_good
				title = fp2_ruthless_market_oversight_modifier
				left_icon = root
	
				add_dread = medium_dread_gain
				scope:se_2000_county = {
					add_county_modifier = {
						modifier = fp2_ruthless_market_oversight_modifier
						years = 5
					}
				}
			}
		}
		else = {
			send_interface_toast = {
				type = event_toast_effect_bad
				title = fp2_ruthless_market_oversight_modifier
				left_icon = root
	
				add_dread = medium_dread_gain
				scope:se_2000_county = {
					add_county_modifier = {
						modifier = fp2_ruthless_market_oversight_modifier
						years = 5
					}
				}
			}
		}

		ai_chance = {
			base = 5
			modifier = {
				add = 15
				OR = {
					has_trait = sadistic
					has_trait = zealous
					has_trait = wrathful
				}
			}
			modifier = {
				add = -40
				has_trait = compassionate
			}
		}
	}

	option = { # Intervene with threat of calling judge
		name = fp2_struggle.2000.a
		flavor = fp2_struggle.2000.a.desc

		duel = {
			skill = diplomacy
			value = medium_skill_rating

			30 = {
				desc = fp2_struggle.2000.a.a

				compare_modifier = {
					value = scope:duel_value
					multiplier = 2.5
				}
				modifier = {
					add = 5
					has_trait = fickle
				}
				modifier = {
					add = 20
					has_trait = craven
				}
				modifier = {
					add = 3
					has_trait = lazy
				}
				modifier = {
					add = 3
					has_trait = arbitrary
				}

				send_interface_toast = {
					type = event_toast_effect_bad
					title = fp2_struggle.2000.a.a.notif

					if = { # RoCo
						limit = {
							exists = scope:fp2_2000_chief_qadi
						}
						reverse_add_opinion = {
							target = scope:fp2_2000_chief_qadi
							modifier = respect_opinion
							opinion = 15
						}
					}
	
					scope:se_2000_county = { 
						add_county_modifier = {
							modifier = fp2_inefficient_market_oversight_modifier
							years = 5
						}
					}
				}
			}
			70 = {
				desc = fp2_struggle.2000.a.b

				compare_modifier = {
					value = scope:duel_value
					multiplier = 2.5
				}
				
				modifier = {
					add = 5
					has_trait = humble
				}
				modifier = {
					add = 5
					has_trait = ambitious
				}
				modifier = {
					add = 10
					has_trait = gregarious
				}
				modifier = {
					add = 15
					has_trait = just
				}

				send_interface_toast = {
					type = event_toast_effect_good
					title = fp2_struggle.2000.a.b.notif
					left_icon = scope:2000_scoped_steward

					scope:se_2000_county = { 
						add_county_modifier = {
							modifier = fp2_smooth_market_oversight_modifier
							years = 5
						}
					}
				}
			}
		}

		ai_chance = {
			base = 60
			modifier = {
				add = 25
				has_trait = just
			}
			modifier = {
				add = -25
				has_trait = arbitrary
			}
			modifier = {
				add = -15
				has_trait = lazy
			}
			modifier = {
				add = -5
				has_trait = arrogant
			}
		}
	}

	option = { # Let the free market decide, free from tradition
		name = fp2_struggle.2000.d
		flavor = fp2_struggle.2000.d.desc

		stress_impact = { 
			zealous = major_stress_impact_gain
			humble = medium_stress_impact_gain
			content = medium_stress_impact_gain
			just = minor_stress_impact_gain
			temperate = medium_stress_impact_gain
		}

		reverse_add_opinion = {
			target = scope:2000_scoped_chaplain
			modifier = impious_opinion
			opinion = -30
		}
		reverse_add_opinion = {
			target = scope:2000_scoped_steward
			modifier = respect_opinion
			opinion = 15
		}

		send_interface_toast = {
			type = event_toast_effect_good
			title = fp2_free_market_boom_modifier
			left_icon = scope:2000_scoped_steward

			add_piety = medium_piety_loss

			scope:se_2000_county = { 
				add_county_modifier = {
					modifier = fp2_free_market_boom_modifier
					years = 6
				}
			}
		}

		ai_chance = {
			base = 0
			modifier = {
			  add = 15
			  has_trait = greedy
			}
			modifier = {
			  add = -40
			  has_trait = zealous
			}
		}
	}

	option = { # Reprimand the inspector
		name = fp2_struggle.2000.b
		flavor = fp2_struggle.2000.b.desc

		stress_impact = { compassionate = medium_stress_impact_gain }
		add_dread = miniscule_dread_gain

		send_interface_toast = {
			type = event_stewardship_good_with_text
			title = fp2_struggle.2000.b.notif
			desc = fp2_struggle.2000.b.notif.desc

			scope:se_2000_county = { 
				add_county_modifier = {
					modifier = fp2_smooth_market_oversight_modifier
					years = 5
				}
			}

			scope:2000_scoped_chaplain = {
				add_opinion = {
					target = root
					modifier = cruelty_opinion
					opinion = -15
				}
			}
		}

		ai_chance = {
			base = 34
			modifier = {
				add = 15
				OR = {
					has_trait = sadistic
					has_trait = callous
				}
			}
			modifier = {
				add = 5
				has_trait = impatient
			}
			modifier = {
				add = 3
				has_trait = diligent
			}
			modifier = {
				add = -25
				has_trait = compassionate
			}
			modifier = {
				add = -15
				OR = {
					has_trait = trusting
					has_trait = calm
					has_trait = forgiving
				}
			}
			modifier = {
				add = -5
				has_trait = humble
			}
		}
	}

	after = { scope:fp2_2000_market_inspector = { silent_disappearance_effect = yes } }
}

###################################
# Desperate Villagers Seek New Lord
# By Hugo Cortell
###################################
scripted_trigger fp2_struggle_2001_desperate_county_scripted_trigger = {
	NOT = { root = { has_claim_on = prev } }
	trigger_if = {	# Checking that we are not offering up the capital of a duke or higher
		limit = { 
			holder = {
				highest_held_title_tier >= tier_duchy
			}
		}
		this != holder.capital_county
	}

	holder = { # Balance, malus must not affect players
		is_ai = yes
		top_liege = { is_ai = yes }
	}

	OR = {
		county_opinion < 0
		county_control < 81 # Note: if considered too restrictive for normal play, update to != 100
	}

	squared_distance = {
		target = root.capital_province
		value < squared_distance_medium 
	}
}

fp2_struggle.2001 = {
	type = character_event
	title = fp2_struggle.2001.t
	desc = {
		desc = fp2_struggle.2001.desc
		triggered_desc = {
			trigger = {
				is_allied_to = scope:fp2_2001_desperate_county.holder
			}
			desc = fp2_struggle.2001.desc.extra.a
		}
		triggered_desc = {
			trigger = {
				has_truce = scope:fp2_2001_desperate_county.holder
			}
			desc = fp2_struggle.2001.desc.extra.b
		}
	} 

	theme = vassal
	cooldown = { years = 20 }
	left_portrait = {
		character = root
		animation = personality_rational
	}
	right_portrait = {
		character = scope:fp2_2001_desperate_elder
		animation = beg
	}
	lower_right_portrait = scope:fp2_2001_desperate_county.holder.top_liege

	trigger = {
		has_fp2_dlc_trigger = yes
		exists = struggle:reconquista_struggle
		struggle:reconquista_struggle = {
			OR = {
				is_struggle_phase = struggle_reconquista_phase_hostility
			}
		}
		
		any_neighboring_and_across_water_top_liege_realm_owner = {
			character_any_involvement_reconquista_struggle_trigger = yes
			any_sub_realm_county = {
				fp2_struggle_2001_desperate_county_scripted_trigger = yes
			}
		}
	}

	immediate = {
		if = {
			limit = { exists = cp:councillor_court_chaplain }
			cp:councillor_court_chaplain = { save_scope_as = 2001_scoped_chaplain }
		}

		random_neighboring_and_across_water_top_liege_realm_owner = {
			limit = {
				character_any_involvement_reconquista_struggle_trigger = yes
				any_sub_realm_county = { fp2_struggle_2001_desperate_county_scripted_trigger = yes }
			}
			random_sub_realm_county = {
				limit = { fp2_struggle_2001_desperate_county_scripted_trigger = yes }
				save_scope_as = fp2_2001_desperate_county
			}
		}

		create_character = {
			age = { 38 71 }
			location = scope:fp2_2001_desperate_county.title_province
			gender_female_chance = root_faith_dominant_gender_female_chance
			trait = peasant_leader
			trait = mortal
			random_traits = yes
			culture = scope:fp2_2001_desperate_county.culture
			random_faith = { 
				root.faith = { trigger = { always = yes } }
				scope:fp2_2001_desperate_county.faith  = { trigger = { always = yes } }
			}
			dynasty = none
			after_creation = { add_gold = medium_gold_value }

			save_scope_as = fp2_2001_desperate_elder
		}

		# AI war-savviness calc variables
		scope:fp2_2001_desperate_county.holder.top_liege = { save_temporary_scope_as = target_military }
		set_variable = {
			name = ai_strength_multiplier # This is how much stronger root has to be (could even be used for custom loc! but the script is complex enough as it is)
			value = 1.25
		}
		if = { # Calculate if AI can win war, decision of war requires traits AND for it to be favourable. This calcs if it is favourable
			limit = { 
				is_ai = yes # Are you AI?
				scope:fp2_2001_desperate_county.holder.top_liege = { 
					NOT = { 
						is_at_war_with = root 
						is_ai = no # Enemy must be AI (prevents AI from attacking player characters, otherwise it would feel as if the attack was random)
					} 
				}

				# Actual strength is calc below, thanks to joe
				root_military_strength_higher_than_military_target_value > target_military_strength_root_value
			}
			save_scope_as = fp2_se_2001_ai_war_winnable # Acts as boolean for wether or not the AI has a chance at winning
		}
		remove_variable = ai_strength_multiplier

		# Option exclusivity stuffs, easier to keep track of logic
		if = { # Faith
			limit = {
				OR = {
					has_trait = holy_warrior
					has_trait = devoted
					has_trait = heresiarch
					has_trait = order_member
					has_trait = crusader_king
					has_trait = faith_warrior
				}
				NOT = { 
					faith = scope:fp2_2001_desperate_elder.faith
					has_trait = excommunicated 
				}
			}
			save_scope_as = fp2_2001_exclusive_option_faith
		}
		else_if = { # Greedy
			limit = {
				OR = {
					has_trait = greedy
					has_trait = avaricious
					has_trait = logistician	
				}
			}
			save_scope_as = fp2_2001_exclusive_option_greed
		}
	}

	option = { # Pay tribute to me
		name = fp2_struggle.2001.d
		custom_tooltip = fp2_struggle.2001.a.desc

		trigger	= {
			exists = scope:fp2_2001_exclusive_option_greed
			NOT = { exists = scope:fp2_2001_exclusive_option_faith }

			OR = { # Tricks autoformatter into showing trait icons (wasteful)
				has_trait = greedy
				has_trait = avaricious
				has_trait = logistician	
			}
		}

		stress_impact = { 
			compassionate = minor_stress_impact_gain 
			humble = minor_stress_impact_gain 
			content = minor_stress_impact_gain 
		}

		save_scope_value_as = {
			name = fp2_se_2001_eventchoiceramifications
			value = flag:demand_tribute
		}

		send_interface_toast = {
			type = event_toast_effect_good
			title = fp2_struggle.2001.a.notif
			left_icon = root
			right_icon = scope:fp2_2001_desperate_elder

			add_unpressed_claim = scope:fp2_2001_desperate_county
		}

		send_interface_toast = {
			type = event_stewardship_good_with_text
			title = fp2_struggle.2001.d.notif
			desc = fp2_struggle.2001.d.notif.desc
			left_icon = scope:fp2_2001_desperate_elder

			scope:fp2_2001_desperate_elder = {
				pay_treasury_or_gold = {
					target = root
					value = medium_treasury_or_gold_value
				}
			}
		}

		if = {
			limit = { exists = cp:councillor_steward }
			cp:councillor_steward = { 
				add_opinion = {
					target = root
					modifier = pleased_opinion
					opinion = 15
				} 
			}
		}

		hidden_effect = {
			trigger_event = {
				id = fp2_struggle.2002
				years = 5
			}
		}
		add_character_modifier = {
			modifier = fp2_2001_promise_reminder
			years = 5
		}

		ai_chance = {
			base = 0
			modifier = {
				add = 10
				exists = scope:fp2_se_2001_ai_war_winnable
				has_trait = brave
			}
			modifier = {
				add = 5
				exists = scope:fp2_se_2001_ai_war_winnable
				has_trait = compassionate
			}
			modifier = {
				add = 40
				exists = scope:fp2_se_2001_ai_war_winnable
				has_trait = greedy
			}
		}
	}

	option = {	# Are you willing to give up your god for it?
		trigger = { 
			exists = scope:fp2_2001_exclusive_option_faith

			OR = {
				has_trait = holy_warrior # Tricking the autoformatter into showing relevant trait
				has_trait = devoted
				has_trait = heresiarch
				has_trait = order_member
				has_trait = crusader_king
				has_trait = faith_warrior
			}
		}
		name = fp2_struggle.2001.b

		custom_tooltip = fp2_struggle.2001.a.desc
		if = { 
			limit = { exists = scope:2001_scoped_chaplain }
			custom_tooltip = fp2_struggle.2001.a.a.desc
		}

		send_interface_toast = {
			type = event_toast_effect_good
			title = fp2_struggle.2001.a.notif
			left_icon = root
			right_icon = scope:fp2_2001_desperate_elder

			add_unpressed_claim = scope:fp2_2001_desperate_county
		}

		send_interface_toast = {
			type = event_stewardship_good_with_text
			title = fp2_struggle.2001.b.notif
			desc = fp2_struggle.2001.b.notif.desc
			left_icon = scope:fp2_2001_desperate_elder 
		  
			if = {
				limit = { exists = scope:2001_scoped_chaplain }
				scope:2001_scoped_chaplain = {
					add_opinion = {
						target = root
						modifier = pleased_opinion
						opinion = 40
					}
				}
				save_scope_value_as = {
					name = fp2_se_2001_eventchoiceramifications
					value = flag:demand_conversion_chap # yes
				}
			}
			else = {
				save_scope_value_as = {
					name = fp2_se_2001_eventchoiceramifications
					value = flag:demand_conversion_no_chap # no
				}
			}
		}

		every_powerful_vassal = {
			limit = { faith = root.faith }
			custom = fp2_every_major_vassal_notifier
			add_opinion = {
				target = root
				modifier = respect_opinion
				opinion = 15
			}
		}

		scope:fp2_2001_desperate_county = { set_county_faith = root.faith }

		hidden_effect = {
			scope:fp2_2001_desperate_elder = { set_character_faith_with_conversion = root.faith }
			trigger_event = {
				id = fp2_struggle.2002
				years = 5
			}
		}
		add_character_modifier = {
			modifier = fp2_2001_promise_reminder
			years = 5
		}

		ai_chance = {
			base = 0
			modifier = {
				add = 15
				exists = scope:fp2_se_2001_ai_war_winnable
				has_trait = brave
			}
			modifier = {
				add = 5
				exists = scope:fp2_se_2001_ai_war_winnable
				has_trait = just
			}
			modifier = {
				add = 50
				exists = scope:fp2_se_2001_ai_war_winnable
				has_trait = zealous
			}
			modifier = {
				add = -5
				exists = scope:fp2_se_2001_ai_war_winnable
				has_trait = lazy
			}
		}
	}

	option = { # You have my word
		name = fp2_struggle.2001.a
		custom_tooltip = fp2_struggle.2001.b.desc # Three extra years for not attaching any strings

		stress_impact = { 
			craven = minor_stress_impact_gain 
			shy = minor_stress_impact_gain 
			lazy = minor_stress_impact_gain 
			arrogant = major_stress_impact_gain
		}
		if = {
			limit = {
				exists = scope:fp2_2001_exclusive_option_greed
				NOT = { exists = scope:fp2_2001_exclusive_option_faith }
			}
			stress_impact = {
				greedy = medium_stress_impact_gain
				avaricious = minor_stress_impact_gain
			}
		}

		send_interface_toast = {
			type = event_toast_effect_good
			title = fp2_struggle.2001.a.notif
			left_icon = root
			right_icon = scope:fp2_2001_desperate_elder

			add_unpressed_claim = scope:fp2_2001_desperate_county
		}

		every_powerful_vassal = {
			custom = fp2_every_major_vassal_notifier
			add_opinion = {
				target = root
				modifier = respect_opinion
				opinion = 15
			}
		}

		hidden_effect = {
			trigger_event = {
				id = fp2_struggle.2002
				years = 10
			}
		}
		add_character_modifier = {
			modifier = fp2_2001_promise_reminder
			years = 10
		}

		ai_chance = {
			base = 0
			modifier = {
				add = 25
				exists = scope:fp2_se_2001_ai_war_winnable
				has_trait = brave
			}
			modifier = {
				add = 15
				exists = scope:fp2_se_2001_ai_war_winnable
				has_trait = just
			}
			modifier = {
				add = 15
				exists = scope:fp2_se_2001_ai_war_winnable
				has_trait = compassionate
			}
			modifier = {
				add = -35
				exists = scope:fp2_se_2001_ai_war_winnable
				has_trait = arrogant
			}
			modifier = {
				add = -15
				exists = scope:fp2_se_2001_ai_war_winnable
				has_trait = lazy
			}
		}
	}

	option = { # Prove it to me, point your spears at your liege (rise up)
		name = fp2_struggle.2001.c
		custom_tooltip = fp2_struggle.2001.a.desc

		trigger = {
			scope:fp2_2001_desperate_county = {
				can_title_create_faction = {
					type = peasant_faction
					target = scope:fp2_2001_desperate_county.holder
				}
			}

			NOT = {
				exists = scope:fp2_2001_exclusive_option_greed
				exists = scope:fp2_2001_exclusive_option_faith
			}
		}
		
		stress_impact = { 
			craven = medium_stress_impact_gain
			content = minor_stress_impact_gain
		}

		save_scope_value_as = {
			name = fp2_se_2001_eventchoiceramifications
			value = flag:peasant_revolt
		}

		send_interface_toast = {
			type = event_toast_effect_good
			title = fp2_struggle.2001.a.notif
			left_icon = root
			right_icon = scope:fp2_2001_desperate_elder

			add_unpressed_claim = scope:fp2_2001_desperate_county
		}

		every_powerful_vassal = {
			custom = fp2_every_major_vassal_notifier
			add_opinion = {
				target = root
				modifier = respect_opinion
				opinion = 10
			}
		}

		scope:fp2_2001_desperate_county = { # Create faction
			title_create_faction  = {
				type = peasant_faction
				target = scope:fp2_2001_desperate_county.holder
			}
			holder = {
				every_targeting_faction = {  # go through all existing factions
					if = {
						limit = {
							any_faction_county_member = { this = scope:fp2_2001_desperate_county } # check if least one member belongs to the county
						}
						save_scope_as = fp2_se_2001_peasant_faction
					}
				}
			}
		}

		hidden_effect = {
			trigger_event = {
				id = fp2_struggle.2002
				years = 5
			}
		}
		add_character_modifier = {
			modifier = fp2_2001_promise_reminder
			years = 5
		}

		ai_chance = {
			base = 0
			modifier = {
				add = 15
				exists = scope:fp2_se_2001_ai_war_winnable
				has_trait = brave
			}
			modifier = {
				add = 25
				exists = scope:fp2_se_2001_ai_war_winnable
				has_trait = ambitious
			}
			modifier = {
				add = 10
				exists = scope:fp2_se_2001_ai_war_winnable
				has_trait = just
			}
			modifier = {
				add = -15
				exists = scope:fp2_se_2001_ai_war_winnable
				has_trait = arrogant
			}
			modifier = {
				add = -5
				exists = scope:fp2_se_2001_ai_war_winnable
				has_trait = lazy
			}
		}
	}

	option = { # Betray and inform ruler of treachery
		name = fp2_struggle.2001.f

		stress_impact = { 
			compassionate = major_stress_impact_gain 
			forgiving = major_stress_impact_gain 
		}

		scope:fp2_2001_desperate_elder = {
			death = {
				death_reason = death_execution
				killer = root
			}
		}
		
		if = {
			limit = { is_allied_to = scope:fp2_2001_desperate_county.holder } # You stood by your allies
			every_powerful_vassal = {
				custom = fp2_every_major_vassal_notifier
				add_opinion = {
					target = root
					modifier = respect_opinion
					opinion = 10
				}
			}

			if = {
				limit = { NOT = { has_trait = arrogant } }
				scope:fp2_2001_desperate_county.holder = {
					progress_towards_friend_effect = {
						REASON = friend_informed_ally_of_betrayal
						CHARACTER = root
						OPINION = 0
					}

					add_opinion = {
						target = root
						modifier = pleased_opinion
						opinion = 25
					}
				}
			}
		}
		else = {
			every_powerful_vassal = { # Your vassals question your integrity
				custom = fp2_every_major_vassal_notifier
				limit = { 
					NOR = {
						has_trait = arbitrary
						has_trait = sadistic
						has_trait = arrogant
					}
				}
				add_opinion = {
					target = root
					modifier = disgusted_opinion
					opinion = -10
				}
			}

			scope:fp2_2001_desperate_county.holder = {
				add_opinion = {
					target = root
					modifier = respect_opinion
					opinion = 40
				}
				progress_towards_friend_effect = {
					REASON = friend_informed_ally_of_betrayal
					CHARACTER = root
					OPINION = 0
				}
			}
		}

		ai_chance = {
			base = 0
			modifier = {
				add = 5
				has_trait = deceitful
				is_allied_to = scope:fp2_2001_desperate_county.holder
			}
			
			modifier = {
				add = -25
				NOT = { is_allied_to = scope:fp2_2001_desperate_county.holder }
				has_trait = brave
			}
			modifier = {
				add = -15
				NOT = { is_allied_to = scope:fp2_2001_desperate_county.holder }
				has_trait = just
			}
			modifier = {
				add = -25
				NOT = { is_allied_to = scope:fp2_2001_desperate_county.holder }
				has_trait = compassionate
			}
			modifier = {
				add = 35
				NOT = { is_allied_to = scope:fp2_2001_desperate_county.holder }
				has_trait = arrogant
			}
			modifier = {
				add = 10
				NOT = { is_allied_to = scope:fp2_2001_desperate_county.holder }
				has_trait = sadistic
			}
			modifier = {
				add = 15
				NOT = { is_allied_to = scope:fp2_2001_desperate_county.holder }
				has_trait = deceitful
			}
		}
	}

	option = { # Dismiss
		name = fp2_struggle.2001.e
		custom_tooltip = fp2_struggle.2001.e.desc
		stress_impact = { compassionate = minor_stress_impact_gain }

		scope:fp2_2001_desperate_county.holder.top_liege.capital_province.county = {
			if = {
				limit = { root = { is_allied_to = scope:fp2_2001_desperate_county.holder } }
				hidden_effect = { # Hides effect if allied
					add_county_modifier = {
						modifier = fp2_forsaken_turned_levies_modifier
						years = 6
					}
				}
			}
			else = {
				add_county_modifier = {
					modifier = fp2_forsaken_turned_levies_modifier
					years = 5
				}
			}
		}

		save_scope_as = did_not_call_next_event

		ai_chance = {
			base = 100
			modifier = {
				add = 25
				exists = scope:fp2_se_2001_ai_war_winnable
				has_trait = craven
			}
			modifier = {
				add = -45
				exists = scope:fp2_se_2001_ai_war_winnable
			}
		}
	}

	after = {
		if = {
			limit = { exists = scope:fp2_se_2001_peasant_faction }
			scope:fp2_2001_desperate_elder = { save_scope_as = peasant_leader }
			scope:fp2_2001_desperate_county = { save_scope_as = peasant_county }
			scope:fp2_se_2001_peasant_faction = {

				setup_peasant_leader_effect = yes

				faction_start_war = {}
				faction_spawn_member_county_armies_effect = {
					FACTION = scope:fp2_se_2001_peasant_faction
					ARMY_OWNER = scope:fp2_2001_desperate_elder
					PEASANT_ARMY_NAME = peasant_faction_event_troops
				}
			}
		}

		if = {
			limit = { 
				exists = scope:did_not_call_next_event 
				scope:fp2_2001_desperate_elder = { is_alive = yes }
			}
			scope:fp2_2001_desperate_elder = {
				silent_disappearance_effect = yes
			}
		}
	}
}

# QUEST FUNCTION, check if player managed to complete objective
fp2_struggle.2002 = {
	hidden = yes

	immediate = { # VICTORY STATE BELOW
		if = {
			limit = { scope:fp2_2001_desperate_county.holder.top_liege = root.top_liege } # check if lands belong to your state/kingdom/side
			send_interface_toast = {
				type = event_toast_effect_good
				title = fp2_struggle.2002.t.a
				left_icon = root
				right_icon = scope:fp2_2001_desperate_elder


				if = {
					limit = { exists = scope:fp2_se_2001_eventchoiceramifications }
					if = {
						limit = { scope:fp2_se_2001_eventchoiceramifications = flag:demand_conversion_chap } # You keet your promise to god
						add_piety = major_piety_gain
					}
					else_if = {
						limit = { scope:fp2_se_2001_eventchoiceramifications = flag:demand_conversion_no_chap } # Without a chap, this is more impressive but less pious
						add_piety = medium_piety_gain
						add_prestige = medium_prestige_gain
					}
					else_if = {
						limit = { scope:fp2_se_2001_eventchoiceramifications = flag:peasant_revolt } # You lead peasants into battle and won
						add_prestige = minor_prestige_gain
					}
					else = {
						debug_log = "Scope fp2_se_2001_eventchoiceramifications exists but has not been assigned a valid value!"
						debug_log_scopes = yes
					}
				}
	
				scope:fp2_2001_desperate_county = {
					add_county_modifier = {
						modifier = county_listened_to_locals_modifier
						years = 12
					}
					change_county_control = major_county_control_gain
				}
			}
		}
		else = { # FAILURE STATE BELOW
			send_interface_toast = {
				type = event_toast_effect_bad
				title = fp2_struggle.2002.t.b
				left_icon = root
				right_icon = scope:fp2_2001_desperate_elder

				add_prestige = minor_prestige_loss

				if = {
					limit = { exists = scope:fp2_se_2001_eventchoiceramifications }
					if = {
						limit = { scope:fp2_se_2001_eventchoiceramifications = flag:demand_conversion_chap } # You failed to keep your promise to god
						add_piety = medium_piety_loss
						scope:2001_scoped_chaplain = {
							add_opinion = {
								target = root
								modifier = impious_opinion
								opinion = -40
							}
						}
					}
					else_if = {
						limit = { scope:fp2_se_2001_eventchoiceramifications = flag:demand_conversion_no_chap } # Without a chap, this is more impressive but less pious
						add_piety = minor_piety_loss
						add_prestige = minor_prestige_loss
					}
					else_if = {
						limit = { scope:fp2_se_2001_eventchoiceramifications = flag:demand_tribute } # Being a weasel makes you look petty
						add_prestige = medium_prestige_loss
					}
					else_if = {
						limit = { scope:fp2_se_2001_eventchoiceramifications = flag:peasant_revolt } # You took their lives in exchange for freedom, yet returned nothing
						add_piety = minor_piety_loss
						add_prestige = major_prestige_loss
						show_as_tooltip = {
							scope:fp2_2001_desperate_county = { # This will happen anyways, but showing it creates more impact
								holder = {
									top_liege.capital_province.county = {
										add_county_modifier = {
											modifier = fp2_forsaken_turned_levies_modifier
											years = 8
										}
									}
								}
							}
						}
					}
					else = {
						debug_log = "Scope fp2_se_2001_eventchoiceramifications exists but has not been assigned a valid value!"
						debug_log_scopes = yes
					}
				}

				every_powerful_vassal = {
					add_opinion = {
						target = root
						modifier = disappointed_opinion
						opinion = -10
					}
				}

				hidden_effect = {
					scope:fp2_2001_desperate_county = {
						change_county_control = medium_county_control_gain
						holder = {
							top_liege.capital_province.county = {
								add_county_modifier = {
									modifier = fp2_forsaken_turned_levies_modifier
									years = 8
								}
							}
						}
					}
				}
			}
		}

		scope:fp2_2001_desperate_elder = {
			silent_disappearance_effect = yes
		}
	}
}

###################################
# Lost Migratory Birds
# By Hugo Cortell
###################################
scripted_trigger fp2_struggle_2003_check_has_city_scripted_trigger = {
	title_province = { has_holding_type = city_holding }
	exists = holder
}

fp2_struggle.2003 = {
	type = character_event
	title = fp2_struggle.2003.t
	desc = fp2_struggle.2003.desc
	theme = stewardship
	override_background = { reference = army_camp }
	cooldown = { years = 50 }
	left_portrait = root
	right_portrait = {
		character = scope:fp2_2003_merc_actor
		animation = loss_1 # Note: two_handed_1_aggressive could also be used
	}

	trigger = {
		has_fp2_dlc_trigger = yes
		exists = struggle:reconquista_struggle
		struggle:reconquista_struggle = {
			OR = {
				is_struggle_phase = struggle_reconquista_phase_shadows
				is_struggle_phase = struggle_reconquista_phase_hostility
			}
		}

		any_sub_realm_barony = { fp2_struggle_2003_check_has_city_scripted_trigger = yes }
	}

	immediate = {
		random_sub_realm_barony = { 
			limit = { fp2_struggle_2003_check_has_city_scripted_trigger = yes }
			county = { save_scope_as = fp2_2003_county_town }
		}

		create_character = {
			age = { 20 50 }
			location = root.capital_province
			gender_female_chance = root_faith_dominant_gender_female_chance
			trait = wrathful
			trait = greedy
			trait = impatient
			trait = callous
			trait = wounded_2
			trait = mortal
			culture = root.culture
			faith = root.faith

			dynasty = none
			after_creation = { 
				add_gold = { 0 minor_gold_value }
				add_prestige = { minor_prestige_loss minor_prestige_gain }
				add_piety = { medium_piety_loss minor_piety_gain }
				add_character_flag = single_combat_duel_armor
			}

			save_scope_as = fp2_2003_merc_actor
		}
	}

	option = { # Give them farming work
		name = fp2_struggle.2003.d
		flavor = fp2_struggle.2003.d.desc

		trigger = { 
			OR= {
				has_trait = lunatic_genetic
				has_trait = logistician
				has_trait = comfort_eater
				has_trait = improvident
				stewardship > extremely_high_skill_rating # TODO: Bug, having lunatic trait (with a horrible stewardship) causes stewardship to be used as reason for unlocked option.
			}
			gold > medium_gold_value # Locals need to be paid in advance
		}
		stress_impact = { greedy = major_stress_impact_gain }

		send_interface_toast = {
			title = fp2_struggle.2003.e.notif.c
			desc = fp2_struggle.2003.e.notif.c.desc

			remove_treasury_or_gold = medium_treasury_or_gold_value
			scope:fp2_2003_county_town = {
				add_county_modifier = {
					modifier = fp2_mercs_turned_farmers_modifier
					years = 20
				}
				holder = {
					add_character_modifier = {
						modifier = fp2_mercenary_acquaintances_modifier
						years = 8 # Bonus effect
					}
				}
			}
		}

		ai_chance = {
			base = 30
			modifier = {
				add = 1000
				has_trait = possessed_genetic
			}
		}
	}

	option = { # Offer them a stable job
		name = fp2_struggle.2003.b
		flavor = fp2_struggle.2003.b.desc

		trigger = { # Locks the lunatic option (remove this trigger if you want more than 4 options)
			OR = {
				NOR= {
					has_trait = lunatic_genetic
					has_trait = logistician
					has_trait = comfort_eater
					has_trait = improvident
					stewardship > extremely_high_skill_rating
				}
				gold < medium_gold_value # Peasants might need to be paid real gold, but mercs do not mind working on debt money
			}
		}

		stress_impact = { greedy = minor_stress_impact_gain }

		remove_treasury_or_gold = medium_treasury_or_gold_value
		send_interface_toast = {
			type = event_toast_effect_good
			title = fp2_veteran_mercenaries_as_instructors_modifier
			left_icon = root

			scope:fp2_2003_county_town = {
				add_county_modifier = {
					modifier = fp2_veteran_mercenaries_as_instructors_modifier
					years = 12
				}
				hidden_effect = {
					holder = {
						add_character_modifier = {
							modifier = fp2_mercenary_acquaintances_modifier
							years = 12
						}
					}
				}
			}
		}

		show_as_tooltip = {
			scope:fp2_2003_county_town = {
				holder = {
					add_character_modifier = {
						modifier = fp2_mercenary_acquaintances_modifier
						years = 12
					}
				}
			}
		}

		ai_chance = {
			base = 25
			modifier = {
				add = 5
				has_trait = ambitious
			}
			modifier = {
				add = 5
				has_trait = generous
			}
			modifier = {
				add = -50
				has_trait = greedy
			}
		}
	}

	option = { # Implore them to leave
		name = fp2_struggle.2003.a
		stress_impact = { shy = minor_stress_impact_gain }

		trigger = {
			NOT = { has_trait = lunatic_genetic } # Cuts down the options to four in case of lunacy event, lunatics do not negotiate.
		}

		duel = {
			skill = diplomacy
			value = high_skill_rating

			10 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -1.5
				}
				modifier = {
					add = 5
					has_trait = fickle
				}
				modifier = {
					add = 20
					has_trait = craven
				}
				modifier = {
					add = 15
					has_trait = lazy
				}
				modifier = {
					add = 10
					has_trait = wrathful
				}
				modifier = {
					add = 10
					has_trait = shy
				}
				modifier = {
					add = 2
					has_trait = trusting
				}
				modifier = {
					add = 3
					has_trait = stubborn
				}

				send_interface_toast = {
					type = event_toast_effect_bad
					title = fp2_struggle.2003.a.a.notif
					left_icon = root
	
					add_prestige = medium_prestige_loss

					scope:fp2_2003_county_town = {
						add_county_modifier = {
							modifier = recently_looted_modifier
							years = 5
						}
					}
				}
			}
			12 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 1.5
				}
				
				modifier = {
					add = 5
					has_trait = calm
				}
				modifier = {
					add = 5
					has_trait = vengeful
				}
				modifier = {
					add = 5
					has_trait = honest
				}
				modifier = {
					add = 10
					has_trait = gregarious
				}
				modifier = {
					add = 15
					has_trait = just
				}
				modifier = {
					add = 15
					has_trait = brave
				}

				send_interface_toast = {
					type = event_toast_effect_good
					title = fp2_struggle.2003.a.b.notif
					left_icon = root
				  
					add_prestige = medium_prestige_gain
					scope:fp2_2003_county_town = {
						add_county_modifier = {
							modifier = county_listened_to_locals_modifier
							years = 5
						}
					}
				}
			}
		}

		ai_chance = {
			base = 60
			modifier = {
				add = 5
				has_trait = just
			}
			modifier = {
				add = 25
				has_trait = gregarious
			}
			modifier = {
				add = -5
				has_trait = arrogant
			}
		}
	}

	option = { # Preemptive strike
		name = fp2_struggle.2003.c
		flavor = fp2_struggle.2003.c.desc

		stress_impact = { trusting = minor_stress_impact_gain } # Craven do not suffer a penalty, because they only plan the fight, not partake in it

		duel = {
			skill = martial
			value = high_skill_rating

			10 = {
				desc = fp2_struggle.2003.c.a

				compare_modifier = {
					value = scope:duel_value
					multiplier = -2.5
				}

				modifier = { # Relevant skills are those that could be used in urban warfare
					add = 5
					has_trait = fickle
				}
				modifier = {
					add = 1
					has_trait = just
				}
				modifier = {
					add = 1
					has_trait = arrogant
				}
				modifier = {
					add = 3
					has_trait = wrathful
				}
				modifier = {
					add = 5
					has_trait = arbitrary
				}
				modifier = {
					add = 3
					has_trait = lazy
				}

				modifier = {
					add = 5
					has_trait = open_terrain_expert
				}
				modifier = {
					add = 2
					has_trait = reckless
				}
				modifier = { # "what does an INN even look like anyway?"
					add = 3
					has_trait = reclusive
				}

				show_as_tooltip = {
					scope:fp2_2003_county_town = {
						add_county_modifier = {
							modifier = fp2_local_garrison_slaughtered_modifier
							years = 5
						}
						add_county_modifier = {
							modifier = recently_looted_modifier
							years = 5
						}
					}
				}

				hidden_effect = {
					send_interface_toast = {
						type = event_toast_effect_bad
						title = fp2_local_garrison_slaughtered_modifier
						left_icon = root
			
						scope:fp2_2003_county_town = { # Failure outcome
							add_county_modifier = {
								modifier = fp2_local_garrison_slaughtered_modifier
								years = 5
							}
							hidden_effect = {
								add_county_modifier = {
									modifier = recently_looted_modifier
									years = 5
								}
							}
						}
					}
				}
			}
			10 = {
				desc = fp2_struggle.2003.c.b

				compare_modifier = {
					value = scope:duel_value
					multiplier = 2.5
				}

				modifier = {
					add = 5
					has_trait = calm
				}
				modifier = {
					add = 5
					has_trait = diligent
				}
				modifier = {
					add = 3
					has_trait = callous
				}

				modifier = {
					add = 7
					OR = {
						has_trait = intellect_good_2
						has_trait = intellect_good_3
					}
				}
				modifier = {
					add = -15
					OR = {
						has_trait = intellect_bad_1
						has_trait = intellect_bad_2
					}
				}
				modifier = {
					add = -25
					OR = {
						has_trait = intellect_bad_3
						has_trait = dull
					}
				}
				modifier = {
					add = 10
					has_trait = shrewd
				}


				modifier = {
					add = 20
					has_trait = strategist
				}
				modifier = { # If you know how buildings are structured, you can raid them better
					add = 5
					has_trait = architect
				}
				modifier = {
					add = 5
					has_trait = flexible_leader
				}
				modifier = {
					add = 15
					has_trait = organizer
				}
				modifier = {
					add = 3
					has_trait = cautious_leader
				}

				add_gold = minor_gold_value
				add_prestige = medium_prestige_gain
				send_interface_toast = {
					type = event_toast_effect_good
					title = fp2_struggle.2003.c.b.notif
					left_icon = root
		
					scope:fp2_2003_county_town = { # Success
						add_county_modifier = {
							modifier = fp2_elite_tactics_for_civil_guards_modifier
							years = 5
						}
					}
				}
			}
		}

		ai_chance = {
			base = 15
			modifier = {
				add = 5
				has_trait = brave
			}
			modifier = {
				add = 15
				has_trait = wrathful
			}
			modifier = {
				add = 5
				has_trait = deceitful
			}
			modifier = {
				add = -25
				has_trait = trusting
			}
			modifier = {
				add = -10
				has_trait = craven
			}
		}
	}

	option = { # Let the local handle it
		name = fp2_struggle.2003.e
		flavor = fp2_struggle.2003.e.desc

		stress_impact = { 
			compassionate = major_stress_impact_gain
			just = medium_stress_impact_gain
			paranoid = minor_stress_impact_gain
		}

		random_list = {
			50 = { # Looted
				send_interface_toast = {
					type = event_toast_effect_bad
					title = fp2_struggle.2003.e.notif.a
					
					scope:fp2_2003_county_town = {
						add_county_modifier = {
							modifier = recently_looted_modifier
							years = 5
						}
					} 
				}
			}
			25 = { # Massacre
				send_interface_toast = {
					type = event_toast_effect_bad
					title = fp2_struggle.2003.e.notif.b
					desc = fp2_struggle.2003.e.notif.b.desc

					scope:fp2_2003_county_town = {
						add_county_modifier = {
							modifier = fp2_mercs_slaughtered_populance_modifier
							years = 5
						}
					}
				}
			}
			25 = { # Farming outcome
				send_interface_toast = {
					type = event_toast_effect_good
					title = fp2_struggle.2003.e.notif.c
					desc = fp2_struggle.2003.e.notif.c.desc

					scope:fp2_2003_county_town = {
						add_county_modifier = {
							modifier = fp2_mercs_turned_farmers_modifier
							years = 15
						}
					}
				}
			}
		}
	}

	after = {
		scope:fp2_2003_merc_actor = { silent_disappearance_effect = yes }
	}
}

###################################
# Ship building event
# By Hugo Cortell
###################################
fp2_struggle.2004 = {
	type = character_event
	title = fp2_struggle.2004.t
	desc = fp2_struggle.2004.desc

	theme = crown
	override_background = { reference = council_chamber }
	left_portrait = {
		character = root
		animation = personality_rational
	}
	right_portrait = {
		character = cp:councillor_steward
		animation = personality_content
	}
	lower_right_portrait = { character = cp:councillor_marshal }
	cooldown = { years = 150 }

	trigger = {
		has_fp2_dlc_trigger = yes
		current_year > 1025
		top_liege = root

		realm_size >= minor_realm_size
		any_sub_realm_county = {
			NOT = { has_county_modifier = fp2_successful_shipyards_modifier }
			is_coastal_county = yes
		}

		exists = cp:councillor_marshal
		cp:councillor_marshal	= { is_available_ai_adult = yes }
		exists = cp:councillor_steward
		cp:councillor_steward	= { 
			is_available_ai_adult = yes 
			NOT = { has_character_flag = fp2_2004_critical_success_achieved }
		}

		any_sub_realm_county = {
			is_coastal_county = yes
			NOT = { has_county_modifier = fp2_successful_shipyards_modifier }
		}
	}

	weight_multiplier  = {
		modifier = {
			add = 5
			current_year > 1066
		}
		modifier = {
			add = 25
			current_year > 1450 # Caravel time
		}
		modifier = {
			add = 25
			current_year > 1550
		}
	}
	immediate = {
		cp:councillor_marshal = { save_scope_as = 2004_scoped_marshal }
		cp:councillor_steward = {
			save_scope_as = 2004_scoped_steward 
			if = {
				limit = { has_character_flag = fp2_2004_critical_success_achieved }
				remove_character_flag = fp2_2004_critical_success_achieved # For debug
			}
		}

		random_sub_realm_county = { 
			limit = { is_coastal_county = yes }
			save_scope_as = fp2_2004_dockyards
		}
	}
	option = { # WE WILL BUILD BOATS OF PURE SILVER (MR addition)
		name = fp2_struggle.2004.c
		flavor = fp2_struggle.2004.c.desc

		remove_treasury_or_gold = major_treasury_or_gold_value
		scope:2004_scoped_steward = {
			add_opinion = {
				target = root
				modifier = dismissive_opinion
				opinion = -15
			} 
		}
		scope:2004_scoped_marshal = { 
			add_opinion = {
				target = root
				modifier = dismissive_opinion
				opinion = -20
			} 
		}

		scope:2004_scoped_steward = {
			duel = {
				skill = learning
				value = high_skill_rating

				25 = { # Failure Outcome
					compare_modifier = { 
						value = scope:duel_value
						multiplier = -1.5
      					min = -24
					}
					modifier = { # Someone is sneaking in iron powder to cheap out!
						add = 5
						has_trait = avaricious
					}

					custom_tooltip = fp2_struggle.2005.desc.alt.a
					scope:fp2_2004_dockyards = { 
						add_county_modifier = {
							modifier 	= fp2_successful_shipyards_modifier
							years 		= 20
						}
					}
				}
				5 = { # Success Outcome
					compare_modifier = {
						value = scope:duel_value
						multiplier = 1.5
      					min = -4
					}
					modifier = {
						add = 5
						has_trait = calm
					}
					modifier = {
						add = 15
						has_trait = diligent
					}
					modifier = {
						add = 2
						has_trait = ambitious
					}
					modifier = {
						add = 3
						has_trait = patient
					}
					modifier = {
						add = 25
						has_trait = shrewd
					}
					modifier = {
						add = 10
						has_trait = overseer
					}
					modifier = {
						add = 8
						has_trait = strategist
					}
					modifier = {
						add = 15
						has_trait = architect
					}
					modifier = {
						add = 10
						has_trait = scholar
					}
					modifier = {
						add = 15
						has_trait = military_engineer
					}
					modifier = {
						add = 3
						has_trait = logistician
					}
					modifier = {
						add = 6
						has_trait = journaller
					}
					modifier = { # Building a ship of silver means you must know your construction material
						add = 5
						has_trait = education_stewardship_1 # You sorta know how silver operates
					}
					modifier = {
						add = 8
						has_trait = education_stewardship_2 # You understand the properties of silver
					}
					modifier = {
						add = 10
						has_trait = education_stewardship_3 # You can bite silver and tell if it is real or not (others can only do it with gold)
					}
					modifier = {
						add = 15
						has_trait = education_stewardship_4 # Your tounge is capable of taking appart the anatomical structure of the silver thanks to your PhD in home economics
					}
					modifier = {
						add = 20
						has_trait = education_stewardship_5 # Like the above, except cooler, and my script comment has better spelling
					}

					root = { save_scope_as = fp2_2004_silver_boat_floats }
					show_as_tooltip = {
						root = { add_prestige = major_prestige_gain }
						scope:fp2_2004_dockyards = { 
							add_county_modifier = {
								modifier 	= fp2_successful_shipyards_modifier
								years 		= 45
							}
						}
					}
				}
			}
		}
		save_scope_as = fp2_2004_alt_option
		if = {
			limit = { is_developer_testing_trigger = yes }
			custom_tooltip = debug_generic_option_shortened_trigger_can_disable
			trigger_event = {
				id = fp2_struggle.2005
				days = 2
			}
		}
		else = {
			trigger_event = {
				id = fp2_struggle.2005
				years = { 4 10 }
			}
		}
	}

	option = { # I will sponsor your endeavour - Side with Steward
		name = fp2_struggle.2004.a

		remove_treasury_or_gold = major_treasury_or_gold_value

		scope:2004_scoped_steward = {
			add_opinion = {
				target = root
				modifier = grateful_opinion
				opinion = 35
			} 
		}
		scope:2004_scoped_marshal = { 
			add_opinion = {
				target = root
				modifier = disappointed_opinion
				opinion = -15
			} 
		}

		scope:2004_scoped_steward = {
			duel = {
				desc = outcome_in_a_few_years
				skill = learning
				value = very_high_skill_rating
	
				50 = {
					compare_modifier = {
						value = scope:duel_value
						multiplier = -2.5
					}
					desc = fp2_struggle.2004.a.a.desc

					modifier = {
						add = 10
						has_trait = lazy
					}
					modifier = {
						add = 10
						has_trait = fickle
					}
					modifier = {
						add = 5
						has_trait = stubborn
					}
					modifier = {
						add = 2
						has_trait = gregarious
					}
					modifier = {
						add = 30
						has_trait = dull
					}
					modifier = {
						add = 5
						has_trait = drunkard
					}
					modifier = {
						add = 7
						has_trait = irritable
					}
					modifier = {
						add = 3
						has_trait = rakish
					}
					modifier = {
						add = 10
						has_trait = profligate
					}

					show_as_tooltip = {
						root = {
							add_character_modifier = {
								modifier 		= fp2_advanced_maritime_technology_modifier
								years 			= 50
							}
						}
					}
				}
				50 = {
					compare_modifier = {
						value = scope:duel_value
						multiplier = 2.5
					}
					desc = fp2_struggle.2004.a.b.desc
					
					modifier = {
						add = 5
						has_trait = calm
					}
					modifier = {
						add = 15
						has_trait = diligent
					}
					modifier = {
						add = 2
						has_trait = ambitious
					}
					modifier = {
						add = 3
						has_trait = patient
					}
					modifier = {
						add = 25
						has_trait = shrewd
					}
					modifier = {
						add = 10
						has_trait = overseer
					}
					modifier = {
						add = 8
						has_trait = strategist
					}
					modifier = {
						add = 15
						has_trait = architect
					}
					modifier = {
						add = 10
						has_trait = scholar
					}
					modifier = {
						add = 15
						has_trait = military_engineer
					}
					modifier = {
						add = 3
						has_trait = logistician
					}
					modifier = {
						add = 6
						has_trait = journaller
					}

					add_character_flag = fp2_2004_critical_success_achieved
					show_as_tooltip = {
						root = {
							add_character_modifier = {
								modifier 		= fp2_advanced_maritime_technology_modifier
								years 			= 60
							}
						}
						scope:fp2_2004_dockyards = { 
							add_county_modifier = {
								modifier 	= fp2_successful_shipyards_modifier
								years 		= 60
							}
						}
					}
				}
			}
		}
		hidden_effect = {
			if = {
				limit = { is_developer_testing_trigger = yes }
				custom_tooltip = debug_generic_option_shortened_trigger_can_disable
				trigger_event = {
					id = fp2_struggle.2005
					days = 2
				}
			}
			else = {
				trigger_event = {
					id = fp2_struggle.2005
					years = { 5 9 }
				}
			}
		}

		ai_chance = {
			base = 0
			modifier = {
				add = 50
				treasury_or_gold > medium_treasury_or_gold_value
			}
			ai_value_modifier = {
				ai_boldness = 0.2
				ai_greed = -0.3
				ai_rationality = 0.2
			}
		}
	}

	option = { # No, it is a waste of money - Side with marshal
		name = fp2_struggle.2004.b
		flavor = fp2_struggle.2004.b.desc

		scope:2004_scoped_marshal = { 
			add_opinion = {
				target = root
				modifier = pleased_opinion
				opinion = 15
			} 
		}

		scope:2004_scoped_steward = { 
			add_opinion = {
				target = root
				modifier = disappointed_opinion
				opinion = -15
			} 
			add_opinion = {
				target = scope:2004_scoped_marshal
				modifier = angry_opinion
				opinion = -25
			}
		}

		ai_chance = { base = 50 }
	}
}

fp2_struggle.2005 = {
	type = character_event
	title = {
		first_valid = {
			triggered_desc = {
				trigger = {
					exists = scope:fp2_2004_alt_option
				}
				desc = {
					first_valid = {
						triggered_desc = {
							trigger = {
								exists = scope:fp2_2004_silver_boat_floats
							}
							desc = fp2_struggle.2005.desc.alt.b
						}
						desc = fp2_struggle.2005.desc.alt.a
					}
				}
			}
			triggered_desc = {
				trigger = {
					scope:2004_scoped_steward = { has_character_flag = fp2_2004_critical_success_achieved }
				}
				desc = fp2_struggle.2005.t.alt
			}
			desc = fp2_struggle.2005.t
		}
	}

	immediate = {
		if = {
			limit = { root = root } # Check if scoped port town is still under your control
			save_scope_as = port_under_control
		}

		# MIA checks
		if = { # Assign current steward
			limit = { exists = cp:councillor_steward }
			cp:councillor_steward = { save_scope_as = 2005_scoped_steward }
		}
		else_if = { # Otherwise assign chaplain
			limit = { exists = cp:councillor_court_chaplain }
			cp:councillor_court_chaplain = { save_scope_as = 2005_scoped_steward }
		}
		else = { # Fallback, get whoever is most qualified in court
			random_courtier_or_guest = {
				limit = { learning > high_skill_rating }
				random = {
					chance = 15
					add_character_flag = fp2_2004_critical_success_achieved
				}
				save_scope_as = 2005_scoped_steward
			}
			if = {
				limit = {
					NOT = { exists = scope:2005_scoped_steward }
				}
				random_courtier_or_guest = { save_scope_as = 2005_scoped_steward }
			}
		}

		if = {
			limit = {
				scope:2004_scoped_steward != scope:2005_scoped_steward
				OR = {
					scope:2005_scoped_steward = cp:councillor_steward
					scope:2005_scoped_steward = cp:councillor_court_chaplain
				}
			}
			if = {
				limit = { learning > high_skill_rating }
				random = {
					chance = 25
					add_character_flag = fp2_2004_critical_success_achieved
				}
				save_scope_as = 2005_scoped_steward
			}
		}
	}

	desc = {
		triggered_desc = { # Alt option
			trigger = { exists = scope:fp2_2004_alt_option }
			desc = {
				first_valid = {
					triggered_desc = {
						trigger = {
							exists = scope:fp2_2004_silver_boat_floats
						}
						desc = fp2_struggle.2005.desc.alt.b.desc
					}
					desc = fp2_struggle.2005.desc.alt.a.desc
				}
				triggered_desc = { # Lost dockyards
					trigger = { scope:fp2_2004_dockyards.holder.top_liege != root.top_liege }
					desc = fp2_struggle.2005.desc.cirt.a.notif
				}
			}
		}
		triggered_desc = {
			trigger = { NOT = { exists = scope:fp2_2004_alt_option } }
			desc = {
				triggered_desc = { # Crtitical success explanation
					trigger = {
						scope:2005_scoped_steward = { has_character_flag = fp2_2004_critical_success_achieved }
					}
					desc = fp2_struggle.2005.desc.cirt.notif
				}
				triggered_desc = { # Lost dockyards
					trigger = {
						scope:2005_scoped_steward = { has_character_flag = fp2_2004_critical_success_achieved }
						scope:fp2_2004_dockyards.holder.top_liege != root.top_liege
					}
					desc = fp2_struggle.2005.desc.cirt.a.notif
				}

				# Original (Steward) designer is MIA
				triggered_desc = {
					trigger = {
						scope:2004_scoped_steward != scope:2005_scoped_steward
					}
					desc = fp2_struggle.2005.desc.newdesigner.notif
				}

				triggered_desc = { # Intro (non-crit)
					trigger = {
						NOT = { scope:2005_scoped_steward = { has_character_flag = fp2_2004_critical_success_achieved } }
					}
					desc = fp2_struggle.2005.desc.intro
				}

				# Describe bottom of the ship
				random_valid = {
					desc = fp2_struggle.2005.desc.bottom.a
					desc = fp2_struggle.2005.desc.bottom.b
					desc = fp2_struggle.2005.desc.bottom.c
					desc = fp2_struggle.2005.desc.bottom.d
				}

				# Describe main feature(s)
				random_valid = {
					desc = fp2_struggle.2005.desc.unique.a
					desc = fp2_struggle.2005.desc.unique.b
					desc = fp2_struggle.2005.desc.unique.c
					desc = fp2_struggle.2005.desc.unique.d
					desc = fp2_struggle.2005.desc.unique.e
				}

				# Describe sails (updated to propulsion)
				random_valid = {
					desc = fp2_struggle.2005.desc.sails.a
					desc = fp2_struggle.2005.desc.sails.b
					desc = fp2_struggle.2005.desc.sails.c
					desc = fp2_struggle.2005.desc.sails.d
				}

				first_valid = {
					triggered_desc = {
						trigger = { scope:2005_scoped_steward = { has_character_flag = fp2_2004_critical_success_achieved } }
						desc = fp2_struggle.2005.desc.outro.crit
					}
					desc = fp2_struggle.2005.desc.outro
				}
			}
		}
	}

	theme = martial
	override_background = { reference = docks }
	left_portrait = {
		character = root
		triggered_animation = {
			trigger = {
				exists = scope:fp2_2004_alt_option
				NOT = { exists = scope:fp2_2004_silver_boat_floats }
			}
			animation = anger
		}
		triggered_animation = {
			trigger = { exists = scope:fp2_2004_alt_option }
			animation = ecstasy
		}
		animation = war_over_win
	}
	right_portrait = {
		character = scope:2005_scoped_steward
		animation = throne_room_writer
	}

	option = { # ALT Accept
		trigger = { 
			exists = scope:fp2_2004_alt_option
			exists = scope:fp2_2004_silver_boat_floats
		}
		name = fp2_struggle.2005.a

		add_prestige = major_prestige_gain
		scope:fp2_2004_dockyards = { 
			add_county_modifier = {
				modifier 	= fp2_successful_shipyards_modifier
				years 		= 45
			}
		}
	}

	option = { # ALT Accept (Failure Version)
		trigger = { 
			exists = scope:fp2_2004_alt_option
			NOT = { exists = scope:fp2_2004_silver_boat_floats }
		}
		name = artifact.4050.a # Reusage of loc key

		scope:fp2_2004_dockyards = { 
			add_county_modifier = {
				modifier 	= fp2_successful_shipyards_modifier
				years 		= 20
			}
		}
	}

	option = { # Accept
		trigger = {
			NOT = {
				exists = scope:fp2_2004_alt_option
				scope:2005_scoped_steward = { has_character_flag = fp2_2004_critical_success_achieved }
			}
		}
		name = fp2_struggle.2005.a

		add_character_modifier = {
			modifier 		= fp2_advanced_maritime_technology_modifier
			years 			= 50
		}
	}

	option = { # Crit Accept
		trigger = { 
			NOT = { exists = scope:fp2_2004_alt_option }
			scope:2005_scoped_steward = { has_character_flag = fp2_2004_critical_success_achieved }
		}
		name = {
			text = {
				first_valid = {
					triggered_desc = {
						trigger = { scope:fp2_2004_dockyards.holder.top_liege = top_liege }
						desc = fp2_struggle.2005.a
					}
					desc = fp2_struggle.2005.a.a
				}
			}
		}

		add_character_modifier = {
			modifier 		= fp2_advanced_maritime_technology_modifier
			years 			= 60
		}
		scope:fp2_2004_dockyards = { 
			add_county_modifier = {
				modifier 	= fp2_successful_shipyards_modifier
				years 		= 60
			}
		}
	}

	after = {
		if = {
			limit = {
				OR = {
					scope:2004_scoped_steward = { has_character_flag = fp2_2004_critical_success_achieved }
					scope:2005_scoped_steward = { has_character_flag = fp2_2004_critical_success_achieved }
				}
			}
			scope:2004_scoped_steward = { remove_character_flag = fp2_2004_critical_success_achieved }
			scope:2005_scoped_steward = { remove_character_flag = fp2_2004_critical_success_achieved }
		}
	}
}

###################################
# The Borders of Faith
# By Hugo Cortell
###################################
scripted_trigger fp2_event2006_check_if_right_vassal_target = {
	holder != root
	holder = {
		is_available_ai_adult = yes
		faith = root.faith
		NOT = { has_trait = cynical }
		OR = {
			any_secret = { type = secret_non_believer }
			AND = { # Fallback, get non-devout follower
				piety < 51
				NOT = { has_trait = zealous }
			}
		}
	}
}

fp2_struggle.2006 = {
	type = character_event
	title = fp2_struggle.2006.t
	desc = fp2_struggle.2006.desc
	cooldown = { years = 20 }

	theme = faith
	override_background = { reference = council_chamber }
	left_portrait = {
		character = root
		animation = shock
	}
	right_portrait = {
		character = scope:fp2_2006_vassal_in_crisis
		animation = stress
	}
	lower_left_portrait = {
		trigger = { exists = scope:2006_scoped_chaplain }
		character = scope:2006_scoped_chaplain
	}

	trigger = {
		has_fp2_dlc_trigger = yes
		root.top_liege = root
		any_sub_realm_county = {
			fp2_event2006_check_if_right_vassal_target = yes

			holder = {
				any_neighboring_top_liege_realm_owner = {
					faith != root.faith 
				}
			}
		}
	}

	immediate = {
		if = {
			limit = { exists = cp:councillor_court_chaplain }
			cp:councillor_court_chaplain = { save_scope_as = 2006_scoped_chaplain }
		}
		random_sub_realm_county = {
			limit = { fp2_event2006_check_if_right_vassal_target = yes }
			holder = {
				save_scope_as = fp2_2006_vassal_in_crisis
				random_neighboring_top_liege_realm_owner = {
					limit = { faith != root.faith }
					faith = { save_scope_as = fp2_2006_foreign_faith } 
				}
			}
		}
	}

	option = { # Im a witch! And you can be one too!
		trigger = {
			has_trait = witch
			OR = {
				NOT = { # Not witch
					scope:fp2_2006_vassal_in_crisis = {
						any_secret = { type = secret_witch }
					}
				}
				scope:fp2_2006_vassal_in_crisis = { # Witch but does not walk the path of witchery with you
					any_secret = {
						type = secret_witch
						NOT = { is_known_by = root }
					}
				}
			}
		}
		name = fp2_struggle.2006.e

		if = {
			limit = {
				any_secret = {
					type = secret_witch
				}
			}
			random_secret = {
				type = secret_witch
				reveal_to = scope:fp2_2006_vassal_in_crisis
			}
		}
		send_interface_toast = {
			type = event_witchcraft_good
			title = fp2_struggle.2006.e.notif.t
			left_icon = scope:fp2_2006_vassal_in_crisis
			
			scope:fp2_2006_vassal_in_crisis = {
				if = {
					limit = {
						any_secret = { type = secret_witch }
						has_trait = witch
					}
					custom_tooltip = fp2_struggle.2006.e.alreadywitch
				}
				else = {
					hidden_effect = { give_witch_secret_or_trait_effect = yes }
					show_as_tooltip = { add_trait = witch }
				}
				show_as_tooltip = {
					random_secret = {
						type = secret_witch
						reveal_to = root
					}
				}
				if = {
					limit = { can_set_relation_friend_trigger = { CHARACTER = root } }
					set_relation_friend = { reason = friend_guided_right_path target = root }
				}
				add_opinion = {
					target = root
					modifier = fp2_tolerated_me_opinion
				}
				if = {
					limit = {
						trait_is_criminal_in_faith_trigger = {
							TRAIT = witch
							GENDER_CHARACTER = scope:fp2_2006_vassal_in_crisis
							FAITH = scope:fp2_2006_vassal_in_crisis.faith
						}
						NOT = {
							trait_is_criminal_in_faith_trigger = {
								TRAIT = witch
								GENDER_CHARACTER = scope:fp2_2006_vassal_in_crisis
								FAITH = scope:fp2_2006_foreign_faith
							}
						}
					}
					hidden_effect = { set_character_faith_with_conversion = scope:fp2_2006_foreign_faith }
					custom_tooltip = fp2_struggle.2006.e.tacticalwitchfaithchange
				}

				hidden_effect = {
					if = {
						limit = {
							any_secret = {
								type = secret_witch
							}
						}
						random_secret = {
							type = secret_witch
							reveal_to = root
						}
					}
					root = {
						random_secret = {
							type = secret_witch
							reveal_to = scope:fp2_2006_vassal_in_crisis
						}
					}
				}
			}
		}
		
		ai_chance = {
			base = 80
			ai_value_modifier = {
				ai_honor = -0.3
				ai_rationality = 0.5
				ai_zeal = -0.9
			}
		}
	}

	option = { # (Threaten to) Denounce heretic
		trigger = {
			OR = {
				has_trait = schemer
				has_trait = devoted
				intrigue > medium_skill_rating
			}
		}
		name = fp2_struggle.2006.d
		stress_impact = { 
			compassionate = medium_stress_impact_gain 
			gallant = medium_stress_impact_gain 
		}

		add_dread = miniscule_dread_gain
		hidden_effect = {
			scope:fp2_2006_vassal_in_crisis = {
				if = {
					limit = { any_secret = { NOT = { secret_type = secret_non_believer } } }
					add_secret = { type = secret_non_believer }
				}
			}
		}

		add_hook = {
			target = scope:fp2_2006_vassal_in_crisis
			type = threat_hook
		}
		random_secret = {
			type = secret_non_believer
			reveal_to = root
		}

		scope:fp2_2006_vassal_in_crisis = {
			add_opinion = {
				target = root
				modifier = betrayed_me_opinion
				opinion = -40
			}
		}

		ai_chance = {
			base = 30
			ai_value_modifier = {
				ai_compassion = -0.5
				ai_honor = -0.8
				ai_rationality = 0.1
				ai_zeal = 0.3
				ai_vengefulness = 0.3
				ai_greed = 0.2
			}
	  	}
	}

	option = { # I will fix him myself
		name = fp2_struggle.2006.b
		stress_impact = {
			cynical = minor_stress_impact_gain
		}

		duel = {
			skill = learning
			value = medium_skill_rating

			15 = {
				desc = fp2_struggle.2006.b.a.desc
				compare_modifier = {
					value = scope:duel_value
					multiplier = -1.5
				}
				modifier = {
					add = 10
					has_trait = fickle
				}
				modifier = {
					add = 10
					has_trait = heresiarch
				}
				modifier = {
					add = 2
					has_trait = impotent
				}
				modifier = {
					add = 5
					has_trait = irritable
				}
				modifier = {
					add = 5
					has_trait = dull
				}
				modifier = {
					add = 10
					has_trait = depressed_genetic
				}
				modifier = {
					add = 10
					has_trait = arrogant
				}
				modifier = {
					add = 5
					has_trait = arbitrary
				}
				modifier = {
					add = 10
					has_trait = lazy
				}
				modifier = {
					add = 2
					has_trait = stubborn
				}
				modifier = {
					add = 5
					has_trait = craven
				}

				send_interface_toast = {
					type = event_toast_effect_bad
					title = fp2_struggle.2006.generic.notif.a.t
					left_icon = scope:fp2_2006_vassal_in_crisis

					scope:fp2_2006_vassal_in_crisis = {
						hidden_effect = { set_character_faith_with_conversion = scope:fp2_2006_foreign_faith }
						show_as_tooltip = { set_character_faith = scope:fp2_2006_foreign_faith }

						progress_towards_rival_effect = {
							REASON = rival_fraternising_enemy
							CHARACTER = root
							OPINION = 0
						}
						add_opinion = {
							target = root
							modifier = fp2_questioned_my_faith_opinion
						}
					}
				}
			}
			15 = {
				desc = fp2_struggle.2006.b.b.desc
				compare_modifier = {
					value = scope:duel_value
					multiplier = 1.5
				}
				modifier = {
					add = 10
					has_trait = calm
				}
				modifier = {
					add = 10
					has_trait = humble
				}
				modifier = {
					add = 3
					has_trait = forgiving
				}
				modifier = {
					add = 5
					has_trait = honest
				}
				modifier = {
					add = 10
					has_trait = humble
				}
				modifier = {
					add = 3
					has_trait = patient
				}
				modifier = {
					add = 20
					has_trait = zealous
				}
				modifier = {
					add = 4
					has_trait = compassionate
				}
				modifier = {
					add = 20
					has_trait = theologian # Could be it's own option, but I can't think of what argument could be used...
				}
				modifier = {
					add = 10
					has_trait = devoted
				}
				modifier = {
					add = 2
					has_trait = lifestyle_poet
				}
				modifier = {
					add = 10
					has_trait = saint
				}

				send_interface_toast = {
					type = event_toast_effect_good
					title = fp2_struggle.2006.generic.notif.b.t
					left_icon = scope:fp2_2006_vassal_in_crisis

					add_piety = medium_piety_gain
					progress_towards_friend_effect = {
						REASON = friend_guided_right_path
						CHARACTER = scope:fp2_2006_vassal_in_crisis
						OPINION = 0
					}
					if = {
						limit = {
							this != root
						}
						add_opinion = {
							target = root
							modifier = fp2_reassured_faith_opinion
						}
					}
				}
			}
		}

		ai_chance = {
			base = 45
			ai_value_modifier = {
				ai_compassion = 0.2
				ai_sociability = 0.3
				ai_zeal = 0.2
			}
	 	}
	}

	option = { # One-on-One time
		name = fp2_struggle.2006.c
		flavor = fp2_struggle.2006.c.desc

		trigger = { 
			NAND = {
				has_trait = witch
				OR = {
					has_trait = schemer
					has_trait = devoted
					intrigue > medium_skill_rating
				}
			}
		}
		stress_impact = { zealous = minor_stress_impact_gain }

		scope:fp2_2006_vassal_in_crisis = {
			progress_towards_friend_effect = {
				REASON = friend_religious_tolerance
				CHARACTER = root
				OPINION = 0
			}
			add_opinion = {
				target = root
				modifier = fp2_tolerated_me_opinion
			}
			random = {
				chance = 50
				hidden_effect = { set_character_faith_with_conversion = scope:fp2_2006_foreign_faith }
				show_as_tooltip = { set_character_faith = scope:fp2_2006_foreign_faith }
			}
		}

		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_compassion = 0.1
				ai_rationality = 0.6
				ai_zeal = -0.7
			}
	  	}	
	}

	option = { # Someone call a priest!
		name = fp2_struggle.2006.a
		flavor = fp2_struggle.2006.a.desc
		show_as_unavailable = { NOT = { exists = scope:2006_scoped_chaplain } } # Replaces trigger, teases player to possibility.
		stress_impact = {
			honest = medium_stress_impact_gain
			humble = minor_stress_impact_gain
			trusting = medium_stress_impact_gain
		}

		scope:fp2_2006_vassal_in_crisis = {
			add_opinion = {
				target = root
				modifier = betrayed_me_opinion
				opinion = -20
			}
		}
		scope:2006_scoped_chaplain = {
			duel = {
				skill = learning
				value = medium_skill_rating
	
				10 = {
					desc = fp2_struggle.2006.a.a
					compare_modifier = {
						value = scope:duel_value
						multiplier = -1.25
					}
					modifier = {
						add = 15
						scope:fp2_2006_vassal_in_crisis = { has_trait = paranoid }
					}
					modifier = {
						add = 10
						has_trait = fickle
					}
					modifier = {
						add = 10
						has_trait = heresiarch
					}
					modifier = {
						add = 2
						has_trait = impotent
					}
					modifier = {
						add = 5
						has_trait = irritable
					}
					modifier = {
						add = 5
						has_trait = dull
					}
					modifier = {
						add = 10
						has_trait = depressed_genetic
					}
					modifier = {
						add = 10
						has_trait = arrogant
					}
					modifier = {
						add = 5
						has_trait = arbitrary
					}
					modifier = {
						add = 10
						has_trait = lazy
					}
					modifier = {
						add = 2
						has_trait = stubborn
					}
					modifier = {
						add = 5
						has_trait = craven
					}
					modifier = {
						factor = 2
						scope:fp2_2006_vassal_in_crisis = { has_trait = paranoid }
					}
	
					root = {
						hidden_effect = {
							scope:fp2_2006_vassal_in_crisis = {
								if = {
									limit = { any_secret = { type = secret_non_believer } }
									progress_towards_rival_effect = { # "HE MUST BE ON TO ME!"
										REASON = rival_faith_tested
										CHARACTER = scope:2006_scoped_chaplain
										OPINION = 0
									}
									add_opinion = {
										target = scope:2006_scoped_chaplain
										modifier = fp2_questioned_my_faith_opinion
									}
								}
							}
						}
						send_interface_toast = {
							type = event_toast_effect_bad
							title = fp2_struggle.2006.generic.notif.a.t
							left_icon = scope:fp2_2006_vassal_in_crisis
							
							scope:fp2_2006_vassal_in_crisis = {
								show_as_tooltip = { set_character_faith = scope:fp2_2006_foreign_faith }
								hidden_effect = { set_character_faith_with_conversion = scope:fp2_2006_foreign_faith }

								add_opinion = {
									target = scope:2006_scoped_chaplain
									modifier = fp2_questioned_my_faith_opinion
									opinion = -35
								}
							}
						}
					}
				}
				5 = {
					trigger = { 
						scope:fp2_2006_vassal_in_crisis = {
							NOT = { has_trait = paranoid }
						}
					}
					desc = fp2_struggle.2006.a.b
					compare_modifier = {
						value = scope:duel_value
						multiplier = -1.25
					}
					modifier = {
						add = 10
						has_trait = fickle
					}
					modifier = {
						add = 10
						has_trait = heresiarch
					}
					modifier = {
						add = 2
						has_trait = impotent
					}
					modifier = {
						add = 5
						has_trait = irritable
					}
					modifier = {
						add = 5
						has_trait = dull
					}
					modifier = {
						add = 10
						has_trait = depressed_genetic
					}
					modifier = {
						add = 10
						has_trait = arrogant
					}
					modifier = {
						add = 5
						has_trait = arbitrary
					}
					modifier = {
						add = 10
						has_trait = lazy
					}
					modifier = {
						add = 2
						has_trait = stubborn
					}
					modifier = {
						add = 5
						has_trait = craven
					}
	
					root = {
						hidden_effect = {
							scope:fp2_2006_vassal_in_crisis = {
								if = {
									limit = { any_secret = { type = secret_non_believer } }
									progress_towards_rival_effect = { # "HE MUST BE ON TO ME!"
										REASON = rival_faith_tested
										CHARACTER = scope:2006_scoped_chaplain
										OPINION = 0
									}
									add_opinion = {
										target = scope:2006_scoped_chaplain
										modifier = fp2_questioned_my_faith_opinion
									}
								}
							}
						}
						send_interface_toast = {
							type = event_toast_effect_bad
							title = fp2_struggle.2006.generic.notif.a.t
							left_icon = scope:fp2_2006_vassal_in_crisis
							
							scope:fp2_2006_vassal_in_crisis = {
								remove_trait = trusting
								if = {
									limit = { is_ai = yes }
									add_stress = monumental_stress_gain # Unbalanced for players, fun when seeing it happen to unrelated AI
								}
								else = { add_stress = medium_stress_gain } # (there is no notification)
								add_opinion = {
									target = scope:2006_scoped_chaplain
									modifier = fp2_questioned_my_faith_opinion
									opinion = -25
								}
							}
						}
					}
				}
				20 = {
					desc = fp2_struggle.2006.a.c
					compare_modifier = {
						value = scope:duel_value
						multiplier = 1.5
					}
					modifier = {
						add = 10
						has_trait = calm
					}
					modifier = {
						add = 10
						has_trait = humble
					}
					modifier = {
						add = 3
						has_trait = forgiving
					}
					modifier = {
						add = 5
						has_trait = honest
					}
					modifier = {
						add = 10
						has_trait = humble
					}
					modifier = {
						add = 3
						has_trait = patient
					}
					modifier = {
						add = 20
						has_trait = zealous
					}
					modifier = {
						add = 4
						has_trait = compassionate
					}
					modifier = {
						add = 15
						has_trait = theologian
					}
					modifier = {
						add = 10
						has_trait = devoted
					}
					modifier = {
						add = 2
						has_trait = lifestyle_poet
					}
					modifier = {
						add = 10
						has_trait = saint
					}

					hidden_effect = {
						scope:fp2_2006_vassal_in_crisis = { add_piety = minor_piety_gain }
						scope:2006_scoped_chaplain = { add_piety = medium_piety_gain }
					}
					root = {
						send_interface_toast = {
							type = event_toast_effect_good
							title = fp2_struggle.2006.generic.notif.b.t
							left_icon = scope:fp2_2006_vassal_in_crisis
	
							scope:fp2_2006_vassal_in_crisis = {
								progress_towards_friend_effect = {
									REASON = friend_guided_right_path
									CHARACTER = scope:2006_scoped_chaplain
									OPINION = 0
								}
								add_opinion = {
									target = scope:2006_scoped_chaplain
									modifier = fp2_reassured_faith_opinion
								}
							}
						}
					}
				}
			}
		}

		ai_chance = {
  			base = 45
			ai_value_modifier = {
				ai_compassion = -0.1
				ai_energy = -0.1
				ai_honor = -0.1
				ai_rationality = 0.2
				ai_sociability = -0.2
				ai_zeal = 0.3
			}
		}
	}
}

###################################
# A Castle Worthy of Iberia
# By Hugo Cortell
###################################
scripted_trigger fp2_struggle_2007_can_build_castle_trigger = { # Ensures that the selected building spot adheres to the game's rules on holding placement.
	any_county_province = { has_holding = no }
	trigger_if = {
		limit = { any_county_province = { has_holding_type = castle_holding } }
		any_county_province = { has_holding_type = church_holding }
		any_county_province = { has_holding_type = city_holding }
	}
	exists = holder
	holder != scope:fp2_2007_scoped_steward
}

fp2_struggle.2007 = {
	type = character_event
	title = fp2_struggle.2007.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = { scope:fp2_2007_castle_holder = ROOT }
				desc = fp2_struggle.2007.desc.a
			}
			desc = fp2_struggle.2007.desc.b
		}
	}

	theme = realm
	cooldown = { years = 20 }
	override_background = { reference = garden }
	left_portrait = {
		character = root
		animation = personality_rational
	}
	right_portrait = {
		character = scope:fp2_2007_scoped_steward
		animation = chancellor
	}
	lower_left_portrait = scope:2007_vassal_sponsor
	lower_right_portrait = scope:fp2_2007_castle_holder

	trigger = {
		has_fp2_dlc_trigger = yes
		is_ai = no # Overpowered for AI, player only.
		struggle:reconquista_struggle = {
			OR = {
				is_struggle_phase = struggle_reconquista_phase_hostility
			}
		}

		root.top_liege = root
		exists = cp:councillor_steward
		cp:councillor_steward = { is_available_ai_adult = yes }
		
		any_vassal = { # Last minute pre RC fixes
			NOT = { 
				religion = root.religion
				this = cp:councillor_steward
			}
		}
		any_realm_county = { fp2_struggle_2007_can_build_castle_trigger = yes }

		save_temporary_scope_value_as = {
			name = fp2_2007_wealth_barrier
			value = {
				value = main_building_tier_1_cost
				multiply = 0.8
				round = yes
			}
		}
		OR = {
			gold > scope:fp2_2007_wealth_barrier
			OR = {
				has_trait = architect
				AND = {
					has_royal_court = yes
					employs_court_position = royal_architect_court_position
					any_court_position_holder = {
						type = royal_architect_court_position
						is_available_ai_adult = yes
					}
				}
			}
		}
	}

	immediate = {
		cp:councillor_steward = { save_scope_as = fp2_2007_scoped_steward }
		if = {
			limit = {
				any_court_position_holder = {
					type = royal_architect_court_position
					is_available_ai_adult = yes
				}
			}
			random_court_position_holder = {
				type = royal_architect_court_position
				save_scope_as = fp2_2007_roco_architect
			}
		}
		random_vassal = {
			limit = { 
				NOT = { 
					religion = root.religion
					this = scope:fp2_2007_scoped_steward
				}
			}
			save_scope_as = 2007_vassal_sponsor
		}

		random_realm_county = {
			limit = { fp2_struggle_2007_can_build_castle_trigger = yes }
			random_county_province = {
				limit = { has_holding = no }
				save_scope_as = fp2_2007_free_real_estate
			}
			holder = { save_scope_as = fp2_2007_castle_holder }
		}

		# Get Different Faith (updated to whole religion)
		struggle:reconquista_struggle = {
			random_involved_ruler = {
				limit = {
					NOT = { religion = root.religion }
					faith = { save_temporary_scope_as = temp_involved_faith }
					struggle:reconquista_struggle = { is_faith_involved_in_struggle = scope:temp_involved_faith }
				}
				religion = { save_scope_as = fp2_2007_foreign_faith }
			}
			if = { # Fallback
				limit = { NOT = { exists = scope:fp2_2007_foreign_faith } }
				get_random_faith_effect = { FORBIDROOTFAITH = yes }
				scope:random_faith.religion = { save_scope_as = fp2_2007_foreign_faith }
			}
		}

		# Get castileans or proto-castileans
		if = {
			limit = { culture = { has_cultural_parameter = architect_trait_prestige } }
			culture = { save_scope_as = fp2_2007_allegedprotocastilean }
		}

		save_scope_value_as = {
			name = fp2_2007_same_faith_construction_cost
			value = {
				value = main_building_tier_1_cost
				multiply = 0.75
				round = yes
			}
		}
		save_scope_value_as = {
			name = fp2_2007_different_faith_construction_cost
			value = {
				value = main_building_tier_1_cost
				multiply = 0.65
				round = yes
			}
		}
		save_scope_value_as = {
			name = fp2_2007_diy_construction_cost
			value = {
				value = main_building_tier_1_cost
				multiply = 0.6
				round = yes
			}
		}

		# Set dynamic loc keys for powerful vassals
		religion = { save_scope_as = dyloc_powerful_vassal_faith }
		culture = { save_scope_as = dyloc_powerful_vassal_culture }
	}

	option = { # Same Faith (or) Castilean architect
		name = {
			text = {
				first_valid = {
					triggered_desc = {
						trigger = { exists = scope:fp2_2007_allegedprotocastilean }
						desc = fp2_struggle.2007.a.castile
					}
					desc = fp2_struggle.2007.a
				}
			}
		}
		flavor = {
			first_valid = {
				triggered_desc = {
					trigger = { exists = scope:fp2_2007_allegedprotocastilean }
					desc = fp2_struggle.2007.a.castile.favor
				}
				desc = fp2_struggle.2007.a.major_vassal_flavor
			}
		}
		show_as_unavailable = { gold < scope:fp2_2007_same_faith_construction_cost }

		if = { # Proto-Castilean
			limit = { exists = scope:fp2_2007_allegedprotocastilean }
			every_powerful_vassal = {
				limit = { culture = root.culture }
				custom = fp2_every_major_same_culture_vassal_notifier
				add_opinion = {
					target = root
					modifier = pleased_opinion
					opinion = 10
				}
			}
		}
		show_as_tooltip = {
			remove_treasury_or_gold = scope:fp2_2007_same_faith_construction_cost
			scope:fp2_2007_free_real_estate = {
				begin_create_holding = {
					type = castle_holding
					refund_cost = {
						gold = 95
					}
				}
			}
			add_hook_if_possible_effect = { # General effect
				TARGET = scope:fp2_2007_castle_holder
				TYPE = indebted_hook
				YEARS = 8
			} # Hooks get their own notifications, therefore I will not show them on the main effect
		}
		hidden_effect = {
			send_interface_toast = {
				type = event_toast_effect_good
				title = fp2_struggle.2007.t
				left_icon = root
				right_icon = scope:fp2_2007_castle_holder
	
				remove_treasury_or_gold = scope:fp2_2007_same_faith_construction_cost
				custom_tooltip = fp2_struggle.2007.a.notif
				hidden_effect = {
					scope:fp2_2007_free_real_estate = {
						begin_create_holding = {
							type = castle_holding
							refund_cost = {
								gold = 95
							}
						}
					}
					add_hook_if_possible_effect = { # General effect
						TARGET = scope:fp2_2007_castle_holder
						TYPE = indebted_hook
						YEARS = 8
					}
				}
			}
		}
	}

	option = { # Foreign (different faith) architect
		name = fp2_struggle.2007.b
		flavor = fp2_struggle.2007.b.flavor
		show_as_unavailable = { gold < scope:fp2_2007_different_faith_construction_cost }
		hidden_effect = { scope:2007_vassal_sponsor = { remove_treasury_or_gold = medium_treasury_or_gold_value } }

		every_powerful_vassal = {
			custom = fp2_every_major_same_faith_vassal_notifier
			limit = { religion = root.religion }
			add_opinion = {
				target = root
				modifier = disappointed_opinion
				opinion = -15
			}
		}
		every_powerful_vassal = {
			custom = fp2_every_major_different_faith_vassal_notifier
			limit = { religion != root.religion }
			add_opinion = {
				target = root
				modifier = respect_opinion
				opinion = 15
			}
		}
		scope:fp2_2007_free_real_estate.county = {
			if = {
				limit = { religion = scope:fp2_2007_foreign_faith }
				add_county_modifier = {
					modifier = modifier_religious_understanding_modifier
					years = 12
				}
			}
			else_if = {
				limit = { religion != root.religion }
				add_county_modifier = {
					modifier = invested_in_province_modifier
					years = 5
				}
			}
		}

		show_as_tooltip = {
			remove_treasury_or_gold = scope:fp2_2007_different_faith_construction_cost
			scope:fp2_2007_free_real_estate = {
				begin_create_holding = {
					type = castle_holding
					refund_cost = {
						gold = 95
					}
				}
			}
			add_hook_if_possible_effect = {
				TARGET = scope:fp2_2007_castle_holder
				TYPE = indebted_hook
				YEARS = 8
			}
		}
		hidden_effect = {
			send_interface_toast = {
				type = event_toast_effect_good
				title = fp2_struggle.2007.t
				left_icon = scope:2007_vassal_sponsor
				right_icon = scope:fp2_2007_castle_holder
	
				remove_treasury_or_gold = scope:fp2_2007_different_faith_construction_cost
				custom_tooltip = fp2_struggle.2007.a.notif
				hidden_effect = {
					scope:fp2_2007_free_real_estate = {
						begin_create_holding = {
							type = castle_holding
							refund_cost = {
								gold = 95
							}
						}
					}
					add_hook_if_possible_effect = { # General effect
						TARGET = scope:fp2_2007_castle_holder
						TYPE = indebted_hook
						YEARS = 8
					}
				}
			}
		}
	}

	option = { # I will build it myself
		name = fp2_struggle.2007.c
		flavor = fp2_struggle.2007.c.flavor

		trigger = { has_trait = architect }

		duel = {
			skill = learning
			value = very_high_skill_rating

			60 = {
				desc = fp2_struggle.2007.c.notif.a.desc
				compare_modifier = {
					value = scope:duel_value
					multiplier = 1 # Should be -1 but it has already been balanced
				}

				send_interface_toast = {
					type = event_toast_effect_bad
					title = fp2_struggle.2007.c.notif.a.t
					left_icon = root
					right_icon = scope:fp2_2007_castle_holder

					add_prestige = major_prestige_loss
					reverse_add_opinion = {
						target = scope:fp2_2007_scoped_steward
						modifier = disappointed_opinion
						opinion = -10
					}
				}
			}
			40 = {
				desc = fp2_struggle.2007.c.notif.b.desc
				compare_modifier = {
					value = scope:duel_value
					multiplier = 1
				}
				modifier = {
					add = fp2_2007_calculate_architect_competence
					always = yes
				}

				show_as_tooltip = {
					remove_treasury_or_gold = scope:fp2_2007_diy_construction_cost
					if = {
						limit = { exists = scope:fp2_2007_allegedprotocastilean }
						add_prestige = minor_prestige_gain
					}
					
					scope:fp2_2007_free_real_estate = {
						begin_create_holding = {
							type = castle_holding
							refund_cost = {
								gold = medium_gold_value
							}
						}
					}
					add_hook_if_possible_effect = { # General effect
						TARGET = scope:fp2_2007_castle_holder
						TYPE = indebted_hook
						YEARS = 8
					}
				}
				hidden_effect = {
					send_interface_toast = {
						type = event_toast_effect_good
						title = fp2_struggle.2007.t
						left_icon = root
						right_icon = scope:fp2_2007_castle_holder
	
						remove_treasury_or_gold = scope:fp2_2007_diy_construction_cost
						if = {
							limit = { exists = scope:fp2_2007_allegedprotocastilean }
							add_prestige = minor_prestige_gain
						}
						custom_tooltip = fp2_struggle.2007.a.notif	
					}
					hidden_effect = {
						scope:fp2_2007_free_real_estate = {
							begin_create_holding = {
								type = castle_holding
								refund_cost = {
									gold = medium_gold_value
								}
							}
						}
						add_hook_if_possible_effect = {
							TARGET = scope:fp2_2007_castle_holder
							TYPE = indebted_hook
							YEARS = 8
						}
					}
				}
			}
		}
	}

	option = { # RoCo
		name = fp2_struggle.2007.c.roco

		trigger = { 
			NOT = { has_trait = architect }
			exists = scope:fp2_2007_roco_architect
		}
		scope:fp2_2007_roco_architect = {
			duel = {
				skill = learning
				value = very_high_skill_rating
	
				55 = {
					desc = fp2_struggle.2007.c.notif.a.desc
	
					compare_modifier = {
						value = scope:duel_value
						multiplier = 1
					}
	
					root = {
						send_interface_toast = {
							type = event_toast_effect_bad
							title = fp2_struggle.2007.c.notif.a.t
							left_icon = scope:fp2_2007_roco_architect
							right_icon = scope:fp2_2007_castle_holder
		
							add_prestige = medium_prestige_loss
						}
					}
					hidden_effect = { add_prestige = medium_prestige_loss }
				}
				45 = {
					compare_modifier = {
						value = scope:duel_value
						multiplier = 1
					}
					modifier = {
						add = fp2_2007_calculate_architect_competence
						always = yes
					}
					
					root = {
						show_as_tooltip = {
							remove_treasury_or_gold = scope:fp2_2007_diy_construction_cost
							scope:fp2_2007_free_real_estate = {
								begin_create_holding = {
									type = castle_holding
									refund_cost = {
										gold = minor_gold_value
									}
								}
							}
							add_hook_if_possible_effect = {
								TARGET = scope:fp2_2007_castle_holder
								TYPE = indebted_hook
								YEARS = 8
							}
						}
						hidden_effect = {
							send_interface_toast = {
								type = event_toast_effect_good
								title = fp2_struggle.2007.t
								left_icon = scope:fp2_2007_roco_architect
								right_icon = scope:fp2_2007_castle_holder
			
								remove_treasury_or_gold = scope:fp2_2007_diy_construction_cost
								custom_tooltip = fp2_struggle.2007.a.notif
							}
							hidden_effect = {
								scope:fp2_2007_free_real_estate = {
									begin_create_holding = {
										type = castle_holding
										refund_cost = {
											gold = minor_gold_value
										}
									}
								}
								add_hook_if_possible_effect = {
									TARGET = scope:fp2_2007_castle_holder
									TYPE = indebted_hook
									YEARS = 8
								}
							}
						}
					}
				}
			}
		}
	}

	option = { # Leave it be
		name = {
			text = {
				first_valid = {
					triggered_desc = {
						trigger = { scope:fp2_2007_castle_holder = root }
						desc = fp2_struggle.2007.d.alt
					}
					desc = fp2_struggle.2007.d
				}
			}
		}

		if = {
			limit = { scope:fp2_2007_castle_holder != root }
			reverse_add_opinion = {
				target = scope:fp2_2007_scoped_steward
				modifier = disappointed_opinion
				opinion = -15
			}
			reverse_add_opinion = {
				target = scope:fp2_2007_castle_holder
				modifier = disappointed_opinion
				opinion = -20
			}
		}
		if = {
			limit = { exists = cp:councillor_marshal }
			reverse_add_opinion = {
				target = cp:councillor_marshal
				modifier = disappointed_opinion
				opinion = -10
			}
		}
	}
}

###################################
# Misdeeds of The Chaplain
# By Hugo Cortell
###################################
scripted_trigger fp2_struggle_2008_check_actor_eligibility_scripted_trigger = {
	is_available_ai_adult = yes 
	intrigue > low_skill_rating

	NOT = {
		has_trait = just
		has_trait = compassionate
		has_trait = generous
		has_trait = content
		has_trait = honest
		has_relation_soulmate = root
	}

	trigger_if = { # Instead of an event weight, we just increase the reqs for friends to dicrease overhead
		limit = { 
			has_relation_friend = root
			has_relation_lover = root
		}
		OR = {
			has_trait = greedy
			has_trait = deceitful
			has_trait = callous
		}
	}
}

fp2_struggle.2008 = {
	type = character_event
	title = fp2_struggle.2008.t
	desc = fp2_struggle.2008.desc

	theme = secret
	cooldown = { years = 30 }
	override_background = { reference = study }
	left_portrait = {
		character = scope:fps_2008_misdeed_actor
		animation = fear
	}
	right_portrait = {
		character = root
		animation = disapproval
	}

	trigger = {
		has_fp2_dlc_trigger = yes
		root.top_liege = root

		trigger_if = {
			limit = { exists = struggle:reconquista_struggle }
			struggle:reconquista_struggle = {
				OR = {
					is_struggle_phase = struggle_reconquista_phase_shadows				
					is_struggle_phase = struggle_reconquista_phase_hostility
				}
			}
		}

		OR = { # This play changes depending on the actor
			AND = { # Chaplain
				exists = cp:councillor_court_chaplain
				cp:councillor_court_chaplain = { fp2_struggle_2008_check_actor_eligibility_scripted_trigger = yes }
			}
			AND = { # Steward
				exists = cp:councillor_steward
				cp:councillor_steward = { fp2_struggle_2008_check_actor_eligibility_scripted_trigger = yes }
			}
			AND = { # Spymaster
				exists = cp:councillor_spymaster
				cp:councillor_spymaster = { fp2_struggle_2008_check_actor_eligibility_scripted_trigger = yes }
			}
		}
	}

	immediate = {
		random_councillor = {
			limit = { 
				OR = {
					this = root.cp:councillor_court_chaplain
					this = root.cp:councillor_steward
					this = root.cp:councillor_spymaster
				}
				fp2_struggle_2008_check_actor_eligibility_scripted_trigger = yes
			}
			weight = { # Weight based on personality. In combination with the scripted trigger this means: Must be greedy, dishonourable, not incompetent.
				base = 1
				modifier = {
					ai_greed > 0
					factor = 1
				}
				modifier = {
					ai_honor < 0
					factor = 1
				}
			}
			save_scope_as = fps_2008_misdeed_actor
		}
		
		scope:fps_2008_misdeed_actor = {
			if = {
				limit = { has_council_position = councillor_steward }
				add_gold = medium_gold_value # Small detail
			}
			else = { add_gold = minor_gold_value }

			if = {
				limit = {
					faith = {
						exists = religious_head
						NOT = {
							religious_head = root
							religious_head = scope:fps_2008_misdeed_actor
						}
					}
				}
				faith.religious_head = {
					save_scope_as = fp2_2008_relevant_head_of_faith
				}
			}
		}
		root.capital_county = { save_scope_as = fp2_2008_capital }
	}

	option = { # Special (thanks QA!) option, denounce publicly (might get killed by mob)
		name = fp2_struggle.2008.d
		flavor = fp2_struggle.2008.d.flavor
		trigger = {
			OR = {
				has_trait = sadistic
				has_trait = schemer
				has_trait = peasant_leader
				has_trait = augustus
				has_trait = contrite
				has_trait = august
				has_trait = diplomat
			}
		}
		stress_impact = { 
			just = medium_stress_impact_gain 
			trusting = minor_stress_impact_gain
			temperate = minor_stress_impact_gain
			patient = minor_stress_impact_gain
			shy = minor_stress_impact_gain
			compassionate = minor_stress_impact_gain
		}

		every_powerful_vassal = {
			limit = { faith = root.faith }
			custom = fp2_every_major_vassal_notifier
			add_opinion = {
				target = root
				modifier = cruelty_opinion
				opinion = -20
			}
		}

		random_list = {
			85 = {
				hidden_effect = {
					scope:fps_2008_misdeed_actor = { save_temporary_scope_as = assassin } # Used for loc
					send_interface_toast = {
						type = event_toast_effect_good
						title = char_interaction.0050.a
						left_icon = scope:fps_2008_misdeed_actor
					  
						capital_county = {
							add_county_modifier = {
								modifier = governance_1054_satisfied_peasants_modifier
								years = 15
							}
						}
						scope:assassin = { custom_tooltip = hold_court.8221.imprison_alone } # This uses that loc
						hidden_effect = {
							rightfully_imprison_character_effect = { # The autoformatter was a bit (very, very) fiddly with this
								TARGET = scope:fps_2008_misdeed_actor
								IMPRISONER = root
							}
						}
					}
				}
				scope:fps_2008_misdeed_actor = {
					add_opinion = {
						target = root
						modifier = publicly_ridiculed
						opinion = -30
					}
				}
				show_as_tooltip = {
					rightfully_imprison_character_effect = {
						TARGET = scope:fps_2008_misdeed_actor
						IMPRISONER = root
					}
					capital_county = {
						add_county_modifier = {
							modifier = governance_1054_satisfied_peasants_modifier
							years = 15
						}
					}
				}
			}
			15 = {
				scope:fps_2008_misdeed_actor = {
					add_opinion = {
						target = root
						modifier = publicly_ridiculed
						opinion = -80
					}
				}
				if = {
					limit = { has_trait = sadistic } # Once again, rewarding physcos with little details
					send_interface_toast = {
						type = event_toast_effect_good
						title = char_interaction.0050.a
						left_icon = scope:fps_2008_misdeed_actor
					  
						scope:fps_2008_misdeed_actor = { pod_death_no_killer = { death_reason = death_beaten_by_mob } }
						capital_county = {
							add_county_modifier = {
								modifier = governance_1054_satisfied_peasants_modifier
								years = 30
							}
						}
					}
				}
				else = {
					send_interface_toast = {
						type = event_toast_effect_bad
						title = char_interaction.0050.a
						left_icon = scope:fps_2008_misdeed_actor
					  
						scope:fps_2008_misdeed_actor = { pod_death_no_killer = { death_reason = death_beaten_by_mob } }
						capital_county = {
							add_county_modifier = {
								modifier = governance_1054_satisfied_peasants_modifier
								years = 30
							}
						}
					}
				}
			}
		}
	}

	option = { # Imprison chaplain outright
		name = fp2_struggle.2008.a
		stress_impact = { trusting = minor_stress_impact_gain }

		rightfully_imprison_character_effect = {
			TARGET = scope:fps_2008_misdeed_actor
			IMPRISONER = root
		}
		if = {
			limit = {
				scope:fps_2008_misdeed_actor = cp:councillor_court_chaplain
				exists = scope:fp2_2008_relevant_head_of_faith 
			}
			scope:fps_2008_misdeed_actor.faith = {
				religious_head = {
					add_opinion = {
						target = root
						modifier = rude_opinion
						opinion = -10
					}
				}
			}
		}

		scope:fp2_2008_capital = { 
			add_county_modifier = {
				modifier = fp2_improved_administrative_checks_modifier
				years = 15
			}
		}

		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_honor = 0.85
				ai_zeal = 0.3
			}
		}
	}


	# Threaten, gain hook and modifier for work harder
	option = { # Combined general output (threaten into teaching you how to forge like they do)
		name = fp2_struggle.2008.b.a
		flavor = fp2_struggle.2008.b.flavor
		stress_impact = { 
			just = minor_stress_impact_gain
			honest = medium_stress_impact_gain
		}

		send_interface_toast = {
			type = event_toast_effect_good
			title = yearly_0001_improved_intrigue
			left_icon = ROOT
			right_icon = scope:fps_2008_misdeed_actor
		  
			add_intrigue_lifestyle_xp = major_lifestyle_experience # Originally it gave you the accomplished forger perk. Was removed because it let you bypass the learning tree.
		}
		reverse_add_opinion = {
			target = scope:fps_2008_misdeed_actor
			modifier = extorted_me_opinion
			opinion = -25
			years = 10
		}

		scope:fps_2008_misdeed_actor = {
			progress_towards_rival_effect = {
				REASON = rival_defrauded_realm
				CHARACTER = root
				OPINION = 0
			}
		}

		if = { # Has its own notification
			limit = {
				can_add_hook = {
					target = scope:fps_2008_misdeed_actor
					type = threat_hook
				}
			}
			add_hook = {
				target = scope:fps_2008_misdeed_actor
				type = threat_hook
				years = 7
			}
		}

		ai_chance = { base = 0 } # AI should never use these OP options
	}


	option = { # Go hand in hand stealing state money
		name = fp2_struggle.2008.c
		flavor = fp2_struggle.2008.c.flavor

		stress_impact = {
			just = medium_stress_impact_gain
			zealous = minor_stress_impact_gain
		}

		scope:fp2_2008_capital = { 
			add_county_modifier = {
				modifier = county_corruption_inefficient_tax_collection_modifier
				years = 15
			}
		}

		scope:fps_2008_misdeed_actor = {
			if = {
				limit = {
					can_add_hook = {
						target = root
						type = minor_crime_accomplice_hook
					}
				}

				if = {
					limit = { root = { scope:fps_2008_misdeed_actor = cp:councillor_steward } } # CPs cannot have CPs, therefore must be rescoped into root to access
					pay_short_term_gold = {
						target = root
						gold = minor_gold_value
					}
				}
				add_hook = {
					target = root
					type = minor_crime_accomplice_hook
					years = 15
				}
			}
		}
		if = {
			limit = {
				can_add_hook = {
					target = scope:fps_2008_misdeed_actor
					type = minor_crime_accomplice_hook
				}
			}
			add_hook = {
				target = scope:fps_2008_misdeed_actor
				type = minor_crime_accomplice_hook
				years = 15
			}
		}
		add_gold = medium_gold_value

		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_greed = 0.95
				ai_energy = 0.25
			}
		}
	}
}

###################################
# Thiefs of Garduna / Catching Thieves of Myth
# By Hugo Cortell
###################################
fp2_struggle.2009 = {
	type = character_event
	title = fp2_struggle.2009.t
	desc = fp2_struggle.2009.desc

	theme = intrigue_skulduggery_focus
	cooldown = { years = 150 } # Not actually necessary but adding anyway
	override_background = { reference = corridor_night }
	left_portrait = {
		character = scope:fp2_2009_marshal
		animation = marshal
		outfit_tags = { emotion_angry_decal } # WAD, the decal does render and functions as intended
	}
	lower_left_portrait = {
		character = root
	}
	right_portrait = {
		character = scope:fp2_2009_garduna_young_thief
		animation = fear
		hide_info = yes
		outfit_tags = {
			mena_stealth_hood
			religious_zoroastrian_high_clothes
		}
	}

	trigger = {
		is_ai = no
		has_fp2_dlc_trigger = yes
		top_liege = this
		exists = cp:councillor_marshal
		character_any_involvement_reconquista_struggle_trigger = yes

		exists = struggle:reconquista_struggle
		exists = primary_title
		struggle:reconquista_struggle = {
			any_involved_ruler = { # Redundancy check in response to errors on automated tests, should (theoretically) not be necessary
				this != root # Alternative point of failure could be "this" being null, but that would cause errors outside my event.
				exists = primary_title
				top_liege = this
				primary_title = { is_mercenary_company = no }
				is_landed = yes
				count > 1 # Redundancy check in response to more errors on nigtly. Now on the bottom of the block. Reduced by one to total 3.
			}
			
			OR = {
				is_struggle_phase = struggle_reconquista_phase_shadows
				is_struggle_phase = struggle_reconquista_phase_reprieve
			}
		}

		realm_size > 3 # Needed to get all the realms where corruption can happen
	}

	weight_multiplier = {
		base = 0.5
		modifier = {
			add = 0.5
			is_ai = no
		}
	}

	immediate = {
		struggle:reconquista_struggle = { # Struggle existance is already verified by event trigger
			random_involved_ruler = { 
				limit = {
					this != root # Otherwise you might be the other involved ruler
					exists = primary_title
					top_liege = this
					primary_title = { is_mercenary_company = no }
					is_landed = yes
				}
				save_scope_as = fp2_2009_involved_ruler 
			} 
		}
		cp:councillor_marshal = { save_scope_as = fp2_2009_marshal }
		create_character = {
			age = { 16 27 }
			location = root.location
			gender_female_chance = 30
			trait = education_intrigue_2
			trait = shy
			trait = honest
			trait = paranoid
			trait = mortal
			random_traits = yes
			diplomacy	= { 2 7 }
			martial		= { 3 6 }
			stewardship = { 4 7 }
			intrigue	= { 4 8 }
			culture = culture:basque
			faith = faith:innocence
			dynasty = none
			after_creation = { add_gold = minor_gold_value }

			save_scope_as = fp2_2009_garduna_young_thief
		}

		if = {
			limit = { 
				exists = global_var:fp2_struggle_2009_thief_king_char
				global_var:fp2_struggle_2009_thief_king_char = { is_available_ai_adult = yes }
			}
			global_var:fp2_struggle_2009_thief_king_char = { save_scope_as = fp2_2009_garduna_guild_master }
		}
		else = {
			create_character = { # Guild Master
				age = { 24 52 }
				location = scope:fp2_2009_involved_ruler.location
				gender_female_chance = {
					if = {
						limit = { scope:fp2_2009_involved_ruler.location.county.faith = { has_doctrine = doctrine_gender_male_dominated } }
						add = 0
					}
					else_if = {
						limit = { scope:fp2_2009_involved_ruler.location.county.faith = { has_doctrine = doctrine_gender_female_dominated } }
						add = 100
					}
					else = {
						add = 50
					}
				}
				trait = education_intrigue_4
				trait = deceitful
				trait = shrewd
				trait = mortal
				random_traits = yes
				diplomacy	= { 2 7 }
				martial		= { 3 9 }
				stewardship = { 4 10 }
				intrigue	= { 4 8 }
				culture = culture:basque
				faith = faith:innocence
				dynasty = none
				after_creation = { 
					add_gold = major_gold_value
					add_prestige = major_prestige_gain
					add_piety = minor_piety_gain
					random = {
						chance = 10
						add_trait = one_eyed
					}
					random = {
						chance = 10
						add_trait = one_legged
					}
					random = {
						chance = 5
						add_trait = schemer
					}
					random = {
						chance = 33
						add_trait = wild_oat
					}
					#if = {
					#	limit = { is_female = yes }
					#	give_nickname = nick_the_Queen_of_Thieves
					#}
					#else = { give_nickname = nick_the_King_of_Thieves }
				}

				save_scope_as = fp2_2009_garduna_guild_master
			}
		}
		set_global_variable = {
			name = fp2_struggle_2009_thief_king_char
			value = scope:fp2_2009_garduna_guild_master
		}

		if = {
			limit = {
				any_court_position_holder = {
					type = executioner_court_position
					is_available_ai_adult = yes
				}
			}
			random_court_position_holder = {
				type = executioner_court_position
				save_scope_as = fp2_2009_roco_executioner
			}
		}

		# Get locations
		root.capital_county = { save_scope_as = fp2_2009_capital_county }
		scope:fp2_2009_involved_ruler.capital_county = { save_scope_as = fp2_2009_involved_capital_county }
		random_sub_realm_county = {
			limit = { this != scope:fp2_2009_capital_county }
			save_scope_as = fp2_2009_random_flavor_county_ichi
		}
		random_sub_realm_county = {
			limit = { 
				NOT = {
					this = scope:fp2_2009_capital_county
					this = scope:fp2_2009_random_flavor_county_ichi
				} 
			}
			save_scope_as = fp2_2009_random_flavor_county_ni
		}

		# Logic for "Hire the guild" option, prevents the AI from acting un-wise
		if = { # Player has access by default
			limit = { is_ai = no }
			save_scope_as = fp2_2009_hire_guild_unlocked
		}
		else_if = { # Forbid AI on AI agression
			limit = {
				NOT = {
					is_ai = yes
					scope:fp2_2009_involved_ruler = { is_ai = yes }
				}
			}
			save_scope_as = fp2_2009_hire_guild_unlocked
		}
		else_if = { # Ensure AI on Player agression is justified
			limit = {
				is_ai = yes
				scope:fp2_2009_involved_ruler = { 
					is_ai = no 
					save_temporary_opinion_value_as = {
						name = opinion_of_root_temp_value
						target = root
					}
				}

				# AI behaviour must be on brand with personality and/or circumstance to ensure narrative cohesion
				scope:opinion_of_root_temp_value < -10
				OR = {
					has_trait = deceitful
					has_trait = wrathful
					has_trait = ambitious
					has_trait = vengeful
					has_trait = arrogant
					has_trait = callous
					is_at_war_with = scope:fp2_2009_involved_ruler
					has_relation_nemesis = scope:fp2_2009_involved_ruler
				}	
			}
			save_scope_as = fp2_2009_hire_guild_unlocked
		}
	}

	option = { # BECOME THE KING OF PIRA- err THIEVES!!1!
		name = fp2_struggle.2009.a
		flavor = fp2_struggle.2009.a.flavor
		trigger = {
			NOT = { age < 14 }
			OR = {
				has_trait = gallant
				has_trait = adventurer
				has_trait = berserker
				has_trait = peasant_leader
				has_trait = viking
				has_trait = reaver
				prowess > very_high_skill_rating
				has_trait = lunatic_genetic
			}
		}
		scope:fp2_2009_marshal = {
			add_opinion = {
				target = root
				modifier = impressed_opinion
				opinion = 20
			}
		}
		trigger_event = {
			id = fp2_struggle.2010
			days = { 6 31 }
		}

		stress_impact = {
			compassionate = minor_stress_impact_gain
			craven = minor_stress_impact_gain
			content = medium_stress_impact_gain
			eccentric = medium_stress_impact_loss
		}

		ai_chance = {
			base = 8 # Prevents too many kings of thieves from showing up
			modifier = {
				add = 25
				has_trait = just
			}
			ai_value_modifier = {
				ai_boldness = 0.7
				ai_compassion = -0.1
				ai_greed = 0.3
				ai_energy = 0.5
				ai_honor = -0.1
				ai_rationality = -0.2
				ai_sociability = 0.3
				ai_vengefulness = 0.5
			}
		}
	}

	option = { # Demand info
		name = fp2_struggle.2009.b

		hidden_effect = {
			scope:fp2_2009_garduna_young_thief = { add_trait = depressed_1 }
			save_scope_as = fp2_2009_thief_permanence_scope
		}

		every_sub_realm_county = {
			limit = {
				county_control < 100
			}
			custom = all_realm_county
			change_county_control = 5
		}
		add_courtier = scope:fp2_2009_garduna_young_thief
		scope:fp2_2009_garduna_young_thief = {
			custom_tooltip = fp2_struggle.2009.b.blues
			add_opinion = {
				target = root
				modifier = was_spared
				opinion = 20
			}
		}

		stress_impact = {
			wrathful = minor_stress_impact_gain
			vengeful = minor_stress_impact_gain
			sadistic = minor_stress_impact_gain
		}
		ai_chance = {
			base = 45
			ai_value_modifier = {
				ai_boldness = -0.1
				ai_compassion = 0.65
				ai_honor = 0.2
				ai_rationality = 0.9
			}
		}

		hidden_effect = {
			save_scope_value_as = {
				name = fp2_2009_event_outcome
				value = flag:cleared_out
			}
			trigger_event = { 
				id = fp2_struggle.2021
				days = { 450 3000 }
			}
		}
	}

	option = { # Ask for a cut
		name = fp2_struggle.2009.c
		trigger = {
			is_ai = no # Option disabled for AI rulers
			NOR = {
				has_trait = gallant
				has_trait = adventurer
				has_trait = berserker
				has_trait = peasant_leader
				has_trait = viking
				has_trait = reaver
				prowess > very_high_skill_rating
				has_trait = lunatic_genetic
			}
		}

		add_gold = medium_gold_value
		scope:fp2_2009_capital_county = { add_thieves_guild_modifier_effect = yes }
		scope:fp2_2009_random_flavor_county_ichi = { change_county_control = -15 }
		scope:fp2_2009_random_flavor_county_ni = { change_county_control = -15 }

		scope:fp2_2009_marshal = {
			if = {
				limit = { has_trait = just }
				add_opinion = {
					target = root
					modifier = disgusted_opinion
					opinion = -35
				}
			}
			else = {
				if = {
					limit = { has_trait = greedy }
					add_opinion = {
						target = root
						modifier = respect_opinion # Greedy people respect "the grind"
						opinion = 10
					}
				}
				else = {
					add_opinion = {
						target = root
						modifier = disappointed_opinion
						opinion = -15
					}
				}
			}
		}

		stress_impact = {
			generous = medium_stress_impact_gain
			content = minor_stress_impact_gain
			just = major_stress_impact_gain
		}

		hidden_effect = {
			save_scope_value_as = {
				name = fp2_2009_event_outcome
				value = flag:paid_off
			}
			trigger_event = { 
				id = fp2_struggle.2021
				days = { 450 3000 }
			}
		}
	}

	option = { # Hire the guild to mess with a foreign ruler (work for me)
		name = fp2_struggle.2009.d
		trigger = { exists = scope:fp2_2009_hire_guild_unlocked } # Prevents AI from acting un-intelligently

		scope:fp2_2009_involved_capital_county = { add_thieves_guild_modifier_effect = yes }
		pay_short_term_gold = {
			target = scope:fp2_2009_garduna_young_thief
			gold = minor_gold_value
			
		}

		# Notifies the player on the recieving end of an event outcome that involves them.
		scope:fp2_2009_involved_ruler = {  # Hopefuly this will encoureage interaction in MP games.
			trigger_event = { 
				id = fp2_struggle.2012
				days = { 1 2 }
			} 
		}

		stress_impact = {
			brave = minor_stress_impact_gain
			honest = medium_stress_impact_gain
			compassionate = minor_stress_impact_gain
		}
		ai_chance = {
			base = 25
			modifier = {
				add = 45
				is_at_war_with = scope:fp2_2009_involved_ruler
			}
			modifier = {
				add = 100 # hatred can cloud the mind
				has_relation_nemesis = scope:fp2_2009_involved_ruler
			}
			ai_value_modifier = {
				ai_boldness = 0.7
				ai_compassion = -0.2
				ai_greed = -0.1
				ai_honor = -0.4
				ai_rationality = 0.7
				ai_vengefulness = 0.95
			}
		}

		hidden_effect = {
			save_scope_value_as = {
				name = fp2_2009_event_outcome
				value = flag:worked_together
			}
			trigger_event = { 
				id = fp2_struggle.2021
				days = { 450 3000 }
			}
		}
	}

	option = { # Gift the thieve's the head to the foreign ruler
		name = fp2_struggle.2009.e

		scope:fp2_2009_garduna_young_thief = {
			if = {
				limit = { exists = scope:fp2_2009_roco_executioner } # ROCO flaire
				death = {
					death_reason = death_execution
					killer = scope:fp2_2009_roco_executioner
				}
			}
			else = {
				death = {
					death_reason = death_execution
					killer = scope:fp2_2009_marshal
				}
			}
			save_scope_as = fp2_2009_thief_permanence_scope
		}
		custom_tooltip = fp2_struggle.2009.e.a
		hidden_effect = {
			random_list = {
				55 = {} # nothing happens
				45 = {
					random_list = {
						33 = { scope:fp2_2009_random_flavor_county_ichi = { change_county_control = -15 } }
						33 = { scope:fp2_2009_random_flavor_county_ni = { change_county_control = -15 } }
						33 = { scope:fp2_2009_capital_county = { change_county_control = -15 } }
					}
				}
			}
		}

		scope:fp2_2009_involved_ruler = {
			if = {
				limit = {
					OR = {
						has_trait = wrathful
						has_trait = vengeful
						has_trait = sadistic
					}
				}
				add_opinion = {
					target = root
					modifier = gift_opinion
					opinion = 40
				}
				progress_towards_friend_effect = { # very nice
					REASON = friend_gave_severed_head
					CHARACTER = root
					OPINION = 0
				}
			}
			else = {
				add_opinion = {
					target = root
					modifier = gift_opinion # nice
					opinion = 30
				}
			}
		}

		# Notifies the player on the recieving end that they have recieved a delightful gift
		root = { save_scope_as = fp2_2009_has_gifted_head }
		scope:fp2_2009_involved_ruler = { 
			trigger_event = { 
				id = fp2_struggle.2012
				days = { 1 2 }
			} 
		}

		stress_impact = {
			compassionate = medium_stress_impact_gain
			forgiving = minor_stress_impact_gain
		}
		ai_chance = {
			base = 35
			ai_value_modifier = {
				ai_boldness = 0.2
				ai_compassion = -0.45
				ai_honor = 0.8
				ai_rationality = 0.1
				ai_sociability = 0.5
			}
		}

		hidden_effect = {
			save_scope_value_as = {
				name = fp2_2009_event_outcome
				value = flag:lobbed_head
			}
			trigger_event = { 
				id = fp2_struggle.2021
				days = { 450 3000 }
			}
		}
	}

	option = { # Debug option to quickly trigger 2021
		name = debug_generic_option
		trigger = { is_developer_testing_trigger = yes }

		custom_tooltip = debug_generic_option_shortened_trigger_can_disable
		hidden_effect = {
			save_scope_value_as = {
				name = fp2_2009_event_outcome
				value = flag:cleared_out # modify this with the flag you need
			}
			trigger_event = { id = fp2_struggle.2021 }
		}
	}

	after = {
		if = {
			limit = { NOT = { exists = scope:fp2_2009_thief_permanence_scope } }
			scope:fp2_2009_garduna_young_thief = { silent_disappearance_effect = yes }
		}
	}
}

fp2_struggle.2010 = { # 2009 duel follow-up
	type = character_event
	title = fp2_struggle.2010.t
	desc = fp2_struggle.2010.desc
	trigger = { scope:fp2_2009_garduna_guild_master = { is_available_ai_adult = yes } }

	theme = battle
	override_background = { reference = corridor_night }
	left_portrait = {
		character = root
		animation = throne_room_one_handed_passive_1
	}
	right_portrait = {
		character = scope:fp2_2009_garduna_guild_master
		animation = war_over_win
		outfit_tags = {
			western_stealth_hood
			sub_saharan_high_nobility
			mena_war_legwear
		}
	}

	option = { # Duel
		name = fp2_struggle.2010.b

		root = { save_scope_as = fp2_2010_root_in_duel } # Used in invalidation check for player's death
		scope:fp2_2009_garduna_guild_master = {
			set_variable = {
				name = signature_weapon
				value = flag:dagger
			}
		}
		configure_start_single_combat_effect = {
			SC_INITIATOR = root
			SC_ATTACKER = root
			SC_DEFENDER = scope:fp2_2009_garduna_guild_master
			FATALITY = always
			FIXED = no
			LOCALE = temple
			OUTPUT_EVENT = fp2_struggle.2011
			INVALIDATION_EVENT = fp2_struggle.2011 # If the thief dies, you still win. If you die, 2011 runs a check and fails to trigger.
		}

		ai_chance = { # Stress for craven was already taken when setting off in this quest
			base = 50
			ai_value_modifier = { ai_boldness = 0.5 }
		}
	}

	option = { # Pay protection money
		name = fp2_struggle.2010.c

		pay_treasury_or_gold = { # Cowardice tax (costs more than hireing them)
			target = scope:fp2_2009_garduna_guild_master
			value = major_treasury_or_gold_value
		}

		stress_impact = {
			brave = major_stress_impact_gain
			just = major_stress_impact_gain
			arrogant = major_stress_impact_gain
			vengeful = medium_stress_impact_gain
		}
		ai_chance = {
			base = 50
			modifier = { # Nobody wants to be indebted to a thief
				add = -25
				gold < major_gold_value
			}
			ai_value_modifier = { ai_greed = -0.5 }
		}

		hidden_effect = {
			save_scope_value_as = {
				name = fp2_2009_event_outcome
				value = flag:paid_off
			}
			trigger_event = { 
				id = fp2_struggle.2021
				days = { 450 3000 }
			}
		}
	}
}

fp2_struggle.2011 = { # You become the KING OF THIEVES
	hidden = yes
	immediate = {
		if = {
			limit = { 
				exists = scope:fp2_2011_reuse_gate
				root = scope:fp2_2010_root_in_duel 
			}
			send_interface_toast = {
				type = event_toast_effect_good
				desc = fp2_struggle.2011.desc
				title = fp2_struggle.2011.a
				right_icon = ROOT
			  
				if = { # Standard practice from EP1 onwards dictates that we ought not to overwrite positive nicknames (?)
					limit = {
						OR = {
							has_any_nickname = no
							has_bad_nickname = yes
						}
					}
					give_nickname = nick_the_Thief_Slayer
				}
				add_prestige = major_prestige_gain
				add_gold = minor_gold_value
			}
		}
		else = {
			save_scope_as = fp2_2011_reuse_gate
			trigger_event = { 
				id = fp2_struggle.2011
				days = 1
			} 
		}
	}
}

fp2_struggle.2012 = { # Displays letter notifying involved player/character that an action taken by 2009's root is affecting them
	type = letter_event
	sender = scope:fp2_2012_sender # Animation is WAD
	opening = {
		desc = {
			first_valid = {
				triggered_desc = {
					trigger = { exists = scope:fp2_2009_has_gifted_head }
					desc = fp2_struggle.2012.t.alt
				}
				desc = fp2_struggle.2012.t
			}
		}
	}
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = { exists = scope:fp2_2009_has_gifted_head }
				desc = fp2_struggle.2012.desc.alt
			}
			desc = fp2_struggle.2012.desc
		}
	}

	immediate = {
		# Logic for deciding who is the author of the letter
		if = {
			limit = { exists = scope:fp2_2009_has_gifted_head } # If the event is the alt version where you gift the head
			scope:fp2_2009_has_gifted_head = { save_scope_as = fp2_2012_sender }
		}
		else_if = {
			limit = { exists = cp:councillor_spymaster } # Else cycle through possible chancellors
			cp:councillor_spymaster = { save_scope_as = fp2_2012_sender }
		}
		else_if = {
			limit = { exists = cp:councillor_marshal }
			cp:councillor_marshal = { save_scope_as = fp2_2012_sender }
		}
		else_if = {
			limit = { exists = cp:councillor_court_chaplain }
			cp:councillor_court_chaplain = { save_scope_as = fp2_2012_sender }
		}
		else = { root = { save_scope_as = fp2_2012_sender } } # If all fails, you wrote the report yourself, about yourself, for yourself.
	}

	option = {
		name = fp2_struggle.2012.a
		trigger = { NOT = { exists = scope:fp2_2009_has_gifted_head } }

		show_as_tooltip = { scope:fp2_2009_involved_capital_county = { add_thieves_guild_modifier_effect = yes } } # Has already happened, only to display info
	}

	option = {
		name = fp2_struggle.2012.a.alt
		trigger = { exists = scope:fp2_2009_has_gifted_head }

		scope:fp2_2009_involved_capital_county = { change_county_control = 10 }
	}
}

###################################
# The Secret to Freedom
# By Hugo Cortell
###################################
fp2_struggle.2013 = {
	type = character_event
	title = fp2_struggle.2013.t
	desc = fp2_struggle.2013.desc
	theme = secret
	cooldown = { years = 2 }
	override_background = { 
		trigger = { scope:fp2_2013_prisoner_with_a_secret = { is_in_prison_type = house_arrest } }
		reference = sitting_room
	}
	override_background = { 
		trigger = { always = yes }
		reference = dungeon
	}
	left_portrait = {
		character = root
		animation = scheme
	}
	right_portrait = {
		character = scope:fp2_2013_prisoner_with_a_secret
		triggered_animation = {
			trigger = { scope:fp2_2013_prisoner_with_a_secret = { is_in_prison_type = house_arrest } }
  			animation = beg
  		}
		animation = prisondungeon
		override_imprisonment_visuals = yes
	}

	trigger = {
		has_fp2_dlc_trigger = yes
		any_prisoner = {
			save_temporary_scope_as = temp_prisoner_with_secret # Prevents prisoner from revealing their own secret, which would be cool, but would require new loc
			any_known_secret = {
				secret_owner = {
					NOT = { this = scope:temp_prisoner_with_secret }
					is_independent_ruler = yes 
					character_any_involvement_reconquista_struggle_trigger = yes
				} 
				NOT = { is_known_by = root }
			}
		}
	}

	immediate = {
		random_prisoner = {
			limit = {
				save_temporary_scope_as = temp_prisoner_with_secret
				any_known_secret = {
					secret_owner = {
						NOT = { this = scope:temp_prisoner_with_secret }
						is_independent_ruler = yes 
						character_any_involvement_reconquista_struggle_trigger = yes
					} 
					NOT = { is_known_by = root }
				} 
			}
			save_scope_as = fp2_2013_prisoner_with_a_secret
			every_known_secret = {
				limit = { 
					secret_owner = { 
						this != scope:fp2_2013_prisoner_with_a_secret
						top_liege = this
					} 
					NOT = { is_known_by = root }
				}
				secret_owner = { save_scope_as = fp2_2013_secret_owner }
				save_scope_as = fp2_2013_secret_to_tell
			}

			stress_impact = {
				brave = medium_stress_impact_gain
				gallant = medium_stress_impact_gain
				confider = major_stress_impact_gain
			}
		}
	}

	option = { # Agree
		name = fp2_struggle.2013.a

		show_as_tooltip = {
			custom_tooltip = fp2_struggle.2013.a.a
			scope:fp2_2013_prisoner_with_a_secret = { release_from_prison = yes }
		}
		hidden_effect = {
			send_interface_toast = {
				type = event_toast_effect_good
				title = witch.2010.message
				left_icon = ROOT
				right_icon = scope:fp2_2013_secret_owner
			  
				scope:fp2_2013_secret_to_tell = { reveal_to = root }
				scope:fp2_2013_prisoner_with_a_secret = { release_from_prison = yes }
			}
		}

		ai_chance = {
			base = 15
			ai_value_modifier = {
				ai_boldness = -0.1
				ai_compassion = 0.2
				ai_honor = 0.1
				ai_rationality = 0.4
				ai_sociability = 0.1
				ai_vengefulness = 0.1
			}
		}
	}

	option = { # Torture
		name = fp2_struggle.2013.b

		add_dread = minor_dread_gain
		duel = {
			skill = intrigue
			value = medium_skill_rating

			40 = { # Success
				modifier = {
					add = intrigue # Your intrigue level should make up for most of the 10 missing points to make this a 50 50
					always = yes
				}
				modifier = {
					add = 15 # Enjoy your job and it wont feel like work!
					has_trait = sadistic
				}
				modifier = {
					add = 35
					has_trait = torturer
				}
				modifier = {
					add = 5 # Iberia is home to many plants you should not rub against your skin, great for tickle-torture :D
					has_trait = lifestyle_herbalist
				}
				modifier = {
					add = 5
					scope:fp2_2013_prisoner_with_a_secret = { has_trait = lazy }
				}
				modifier = {
					add = 15 # Quickly changes their mind about wanting to resist torture
					scope:fp2_2013_prisoner_with_a_secret = { has_trait = fickle }
				}

				custom_tooltip = fp2_struggle.2013.a.a
				hidden_effect = {
					send_interface_toast = {
						type = event_toast_effect_good
						title = witch.2010.message
						left_icon = ROOT
						right_icon = scope:fp2_2013_secret_owner
					  
						scope:fp2_2013_secret_to_tell = { reveal_to = root }
					}
				}
			}
			60 = { # You fail
				desc = fp2_struggle.2013.b.b
				modifier = {
					add = scope:fp2_2013_prisoner_with_a_secret.prowess # This is a battle of your skill in torture (intrigue) against the will of your oponent (prowess, usually lower)
					always = yes
				}
				modifier = {
					add = 5
					scope:fp2_2013_prisoner_with_a_secret = { has_trait = brave }
				}
				modifier = {
					add = 5 # Being stubborn is as much a blessing as it is a curse, in this case, it is the former
					scope:fp2_2013_prisoner_with_a_secret = { has_trait = stubborn }
				}
				modifier = {
					add = 5
					scope:fp2_2013_prisoner_with_a_secret = { has_trait = diligent }
				}
				modifier = {
					add = 5 # They know nothing good can come from revealing information, what will the bargain with otherwise?
					scope:fp2_2013_prisoner_with_a_secret = { has_trait = paranoid }
				}
				modifier = {
					add = 2 # Maybe god is still on your side? Maybe it is a test?
					scope:fp2_2013_prisoner_with_a_secret = { has_trait = zealous }
				}
				modifier = {
					add = 2
					scope:fp2_2013_prisoner_with_a_secret = { has_trait = callous }
				}
				modifier = {
					add = 15 # I imagine this is sort of a lalatina moment
					scope:fp2_2013_prisoner_with_a_secret = { has_trait = flagellant }
				}
				modifier = {
					add = 10 # They are used to not revealing info under preassure, though torture is a bit more than they are used to...
					scope:fp2_2013_prisoner_with_a_secret = { has_trait = confider }
				}
				
				send_interface_toast = {
					type = event_toast_effect_bad
					title = ease_tension_toast.failure
					left_icon = ROOT
					right_icon = scope:fp2_2013_prisoner_with_a_secret
				}
			}
		}
		reverse_add_opinion = {
			target = scope:fp2_2013_prisoner_with_a_secret
			modifier = tortured_me
			opinion = -60 # 15 point reduction because there was a weak justification
			years = 30
		}
		scope:fp2_2013_prisoner_with_a_secret = {
			add_character_modifier = {
				modifier = recently_tortured
				years = 5
			}
		}

		stress_impact = {
			compassionate = major_stress_impact_gain
			just = medium_stress_impact_gain
			forgiving = medium_stress_impact_gain
		}
		ai_chance = {
			base = 15
			modifier = {
				add = 25
				has_trait = torturer
			}
			modifier = {
				add = 15
				has_trait = sadistic
			}
			ai_value_modifier = {
				ai_boldness = 0.8
				ai_compassion = -0.5
				ai_greed = 0.6
				ai_honor = -0.9
				ai_vengefulness = 0.2
			}
		}
	}

	option = { # Send as gift
		name = fp2_struggle.2013.c
		flavor = fp2_struggle.2013.c.desc
		trigger = { scope:fp2_2013_secret_owner = { is_ai = yes } }

		custom_tooltip = fp2_struggle.2013.c.a
		scope:fp2_2013_prisoner_with_a_secret = { release_from_prison = yes }
		trigger_event = {
			id = fp2_struggle.2014
			days = { 1 4 }
		}

		ai_chance = {
			base = 5
			ai_value_modifier = {
				ai_boldness = -0.1
				ai_compassion = 0.2
				ai_greed = -0.5
				ai_energy = -0.1
				ai_honor = 0.3
				ai_sociability = 0.3
				ai_vengefulness = -0.2
				ai_zeal = -0.1
			}
		}
	}

	option = { # Dismiss
		name = fp2_struggle.2013.d

		random = {
			chance = 5
			modifier = {
				add = 10
				has_trait = depressed
			}
			modifier = {
				add = 5
				health < fine_health
			}
			show_as_tooltip = { custom_tooltip = fp2_struggle.2013.a.a }
			hidden_effect = {
				if = {
					limit = { is_ai = no }
					send_interface_toast = {
						type = event_toast_effect_good
						title = witch.2010.message
						left_icon = ROOT
						right_icon = scope:fp2_2013_secret_owner
					  
						scope:fp2_2013_secret_to_tell = { reveal_to = root }
					}
				}
			}
		}

		ai_chance = {
			base = 65
			ai_value_modifier = {
				ai_boldness = -0.2
				ai_greed = -0.15
				ai_energy = -0.1
				ai_honor = 0.6
				ai_sociability = 0.1
				ai_vengefulness = -0.1
			}
		}
	}
}

fp2_struggle.2014 = {
	type = letter_event
	sender = scope:fp2_2013_secret_owner
	opening = fp2_struggle.2014.t
	desc = {
		desc = fp2_struggle.2014.desc.start
		first_valid = {
			triggered_desc = {
				trigger = { scope:fp2_2014_ai_secret_outcome = flag:prison }
				desc = fp2_struggle.2014.desc.heavy.outcome.prison
			}
			triggered_desc = {
				trigger = { scope:fp2_2014_ai_secret_outcome = flag:death }
				desc = fp2_struggle.2014.desc.heavy.outcome.death
			}
			desc = fp2_struggle.2014.desc.light
		}
	}

	trigger = {
		scope:fp2_2013_secret_owner = { is_available_ai_adult = yes }
		scope:fp2_2013_prisoner_with_a_secret = { is_available_ai_adult = yes }
	}

	on_trigger_fail = {
		if = {
			limit = { # Fallback - foreign ruler has died!
				NOT = { 
					scope:fp2_2013_secret_owner = { 
						is_alive = yes
						is_available_ai_adult = yes 
					} 
				} 
			} 
			send_interface_toast = {
				type = event_death_neutral
				desc = death_management.1007.t
				left_icon = scope:fp2_2013_secret_owner
			}
		}
		if = {
			limit = { # Fallback - prisoner has died!
				NOT = { scope:fp2_2013_prisoner_with_a_secret = { is_alive = yes } } 
			}
			send_interface_toast = {
				scope:fp2_2013_prisoner_with_a_secret = { save_temporary_scope_as = dead_character }
				type = event_death_neutral
				desc = death_management.1006.desc
				left_icon = scope:fp2_2013_prisoner_with_a_secret
			}
		}
	}

	immediate = { # LOGIC FOR AI RESPONSE
		save_scope_value_as = { # Calculate how "strong" a secret is
			name = fp2_2014_secret_strength
			value = {
				value = 0
				if = {
					limit = { scope:fp2_2013_secret_to_tell = { is_criminal_for = scope:fp2_2013_secret_owner } }
					add = 10
				}
				if = {
					limit = { scope:fp2_2013_secret_to_tell = { is_shunned_for = scope:fp2_2013_secret_owner } }
					add = 5
				}
				if = {
					limit = { scope:fp2_2013_secret_to_tell = { secret_is_always_interesting_trigger = yes } }
					add = 5
				}
			}
		}
		if = {						# IS THIS SECRET A THREAT TO ME?
			limit = { scope:fp2_2014_secret_strength >= 10 }
			scope:fp2_2013_secret_owner = {
				hidden_effect = {
					add_opinion = {
						target = scope:fp2_2013_prisoner_with_a_secret
						modifier = betrayed_me_opinion
						opinion = -50
					}
				}
				add_opinion = {
					target = root
					modifier = did_not_tell_my_secret
					opinion = 45
				}
				progress_towards_friend_effect = {
					REASON = friend_kept_my_secret
					CHARACTER = root
					OPINION = 0
				}
				if = {
					limit = { 
						has_dlc_feature = court_artifacts
						any_artifact = {
							artifact_owner = scope:fp2_2013_secret_owner # This should not need to be explicit, but for some reason scoping is being ignored
							POD_artifact_is_destructible_trigger = yes
							artifact_high_rarity_trigger = yes
						}
					}
					random_artifact = {
						limit = {
							artifact_owner = scope:fp2_2013_secret_owner
							POD_artifact_is_destructible_trigger = yes
							artifact_high_rarity_trigger = yes
						}
						set_owner = root # If it breaks, use set_artifact_owner
					}
				}

				save_opinion_value_as = {
					name = fp2_2014_opinion_of_swine
					target = scope:fp2_2013_prisoner_with_a_secret
				}
			}
			if = {					# YES, AND I MUST HIDE IT (prison outcome)
				limit = {
					scope:fp2_2013_secret_owner = {
						NAND = {
							has_trait = paranoid
							ai_compassion < 30	
						}	
					}
				}
				save_scope_value_as = {
					name = fp2_2014_ai_secret_outcome
					value = flag:prison
				}
				scope:fp2_2013_secret_owner = {
					rightfully_imprison_character_effect = {
						TARGET = scope:fp2_2013_prisoner_with_a_secret
						IMPRISONER = scope:fp2_2013_secret_owner
					}
				}
			}
			else = {				# YES, AND I WILL TAKE NO CHANCES (execution outcome)
				save_scope_value_as = {
					name = fp2_2014_ai_secret_outcome
					value = flag:death
				}

				scope:fp2_2013_prisoner_with_a_secret = {
					pod_death = {
						death_reason = death_torture
						killer = scope:fp2_2013_secret_owner
					}
				}
			}
		}
		else = {					# NO, ACTUALLY THIS IS NOT A BIG DEAL (release outcome)
			scope:fp2_2013_secret_owner = {
				hidden_effect = {
					add_opinion = {
						target = scope:fp2_2013_prisoner_with_a_secret
						modifier = betrayed_me_opinion
						opinion = -25
					}
				}
				add_opinion = {
					target = root
					modifier = did_not_tell_my_secret
					opinion = 25
				}
				if = {
					limit = { 
						has_dlc_feature = court_artifacts
						any_artifact = {
							artifact_owner = scope:fp2_2013_secret_owner
							POD_artifact_is_destructible_trigger = yes
							artifact_low_rarity_trigger = yes
						}
					}
					random_artifact = {
						limit = { 
							artifact_owner = scope:fp2_2013_secret_owner
							POD_artifact_is_destructible_trigger = yes
							artifact_low_rarity_trigger = yes
						}
						set_owner = root
					}
				}
				else = {
					progress_towards_friend_effect = {
						REASON = friend_protected_secrets
						CHARACTER = root
						OPINION = 0
					}
				}
			}
			save_scope_value_as = {
				name = fp2_2014_ai_secret_outcome
				value = flag:release
			}
		}
	}

	option = {
		name = {
			text = {
				first_valid = {
					triggered_desc = {
						trigger = { NOT = { scope:fp2_2014_ai_secret_outcome = flag:release } }
						desc = south_asia.0039.a
					}
					desc = fp2_struggle.2014.b
				}
			}
		}
	}
}

###################################
# Letter on The Back
# By Hugo Cortell
###################################
# (a post-it saying kick me)
###################################
scripted_trigger fp2_struggle_2015_vassal_check_trigger = {
	is_available_ai_adult = yes
	exists = location # Under no circumstance should it be necessary to need to check this
	NOT = { has_trait = compassionate }
}

fp2_struggle.2015 = {
	type = character_event
	title = fp2_struggle.2015.t
	desc = fp2_struggle.2015.desc
	cooldown = { years = 25 }

	theme = murder_scheme
	override_background = { reference = council_chamber }
	left_portrait = {
		character = root
		animation = chancellor
	}
	right_portrait = {
		character = scope:fp2_struggle_2015_peasant_to_murder
		animation = personality_forgiving
	}
	lower_right_portrait = scope:fp2_struggle_2015_murder_requester_vassal

	trigger = {
		is_ai = no # Murder schemes are heavy for performance
		has_fp2_dlc_trigger = yes
		root.top_liege = root

		any_powerful_vassal = { 
			fp2_struggle_2015_vassal_check_trigger = yes 
			opinion = { # Redundant second time around
				target = root
				value < 30
			}
		}
	}

	immediate = {
		random_vassal = { # From joe
			limit = { 
				is_powerful_vassal = yes
				fp2_struggle_2015_vassal_check_trigger = yes
				opinion = {
					target = root
					value < 30
				}
			}
			save_opinion_value_as = { 
				name = liege_opinion
				target = root
			}

			save_scope_as = fp2_struggle_2015_murder_requester_vassal # Makes sure that one exists, even if [ThreadIndex != UINT32_MAX] causes the loop to skip a beat
		}
		while = {
			limit = {
				any_powerful_vassal = {
					fp2_struggle_2015_vassal_check_trigger = yes
					opinion = {
						target = root
						value < scope:liege_opinion
					}
				}
			}
			random_vassal = {
				limit = {
					is_powerful_vassal = yes
					fp2_struggle_2015_vassal_check_trigger = yes
					opinion = { 
						target = root
						value < scope:liege_opinion
					}
				}
				save_opinion_value_as = {
					name = liege_opinion
					target = root
				}
				save_scope_as = fp2_struggle_2015_murder_requester_vassal
			}
		}

		create_character = {
			location = scope:fp2_struggle_2015_murder_requester_vassal.location
			template = generic_peasant_character
			diplomacy = { 5 8 } # High stat
			trait = trusting
			random_traits = yes
			faith = scope:fp2_struggle_2015_murder_requester_vassal.location.county.faith
			culture = scope:fp2_struggle_2015_murder_requester_vassal.location.county.culture
			save_scope_as = fp2_struggle_2015_peasant_to_murder
		}

		hidden_effect = {
			scope:fp2_struggle_2015_peasant_to_murder = {
				reverse_add_opinion = {
					target = scope:fp2_struggle_2015_murder_requester_vassal
					modifier = annoyed_opinion
					opinion = -100
				}
			}

			add_courtier = scope:fp2_struggle_2015_peasant_to_murder
		}
	}

	option = { # Comply and kill the unsuspecting courtier
		name = fp2_struggle.2015.a

		trigger = { is_ai = no }
		duel = {
			skill = intrigue
			value = average_skill_rating

			10 = {
				desc = fp2_struggle.2015.a.a
				compare_modifier = {
					value = scope:duel_value
					multiplier = -1.25
				}

				send_interface_toast = {
					type = event_intrigue_bad
					title = murder_outcome.2302.t
					left_icon = scope:fp2_struggle_2015_peasant_to_murder

					reverse_add_opinion = {
						target = scope:fp2_struggle_2015_murder_requester_vassal
						modifier = disappointed_opinion
						opinion = -15
					}

					remove_courtier_or_guest = scope:fp2_struggle_2015_peasant_to_murder
					custom_tooltip = fp2_struggle.2015.a.murder_scheme
					hidden_effect = {
						scope:fp2_struggle_2015_murder_requester_vassal = {
							start_scheme = { 
								type = murder
								target_character = scope:fp2_struggle_2015_peasant_to_murder
							}
						}
					}
				}
				reverse_add_opinion = {
					target = scope:fp2_struggle_2015_peasant_to_murder
					modifier = suspicion_opinion
					opinion = -20
				}

			}
			10 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 1.25
				}

				modifier = {
					add = {
						value = intrigue
						multiply = 2
						round = yes
					}
					always = yes
				}
				modifier = {
					add = 35
					has_trait = lifestyle_herbalist
				}
				modifier = {
					add = 5
					has_trait = drunkard # You know how to disguise drinks
				}
				modifier = {
					add = 15
					has_perk = swift_execution_perk
				}
				modifier = {
					add = 10 # They add up
					has_perk = a_job_done_right_perk
				}

				send_interface_toast = {
					type = event_intrigue_good
					title = fp2_struggle.2015.a.b
					left_icon = scope:fp2_struggle_2015_murder_requester_vassal

					scope:fp2_struggle_2015_peasant_to_murder = { 
						death = { 
							killer = ROOT
							death_reason = death_poison
						}
					}
					reverse_add_opinion = {
						target = scope:fp2_struggle_2015_murder_requester_vassal
						modifier = helped_me_in_time_of_need
						opinion = 40
					}
				}
				#add_secret = {
				#	type = secret_murder
				#	target = scope:fp2_struggle_2015_peasant_to_murder
				#}
				#random_secret = {
				#	limit = {
				#		secret_type = secret_murder
				#		secret_target = scope:fp2_struggle_2015_peasant_to_murder
				#	}
				#	save_scope_as = fp2_2015_murder_secret
				#}

				#if = { # AHA! YOU FOOL! I TRICKED YOU INTO COMMITING A CRIME!
				#	limit = {
				#		scope:fp2_struggle_2015_murder_requester_vassal = {
				#			OR = {
				#				has_relation_rival = ROOT
				#				has_secret_relation_rival = ROOT # ???
				#				has_relation_nemesis = ROOT
				#
				#				AND = {
				#					has_dread_level_towards = { 
				#						target = ROOT
				#						level <= 1
				#					}
				#					OR = {
				#						AND = {
				#							has_trait = deceitful
				#							opinion = { 
				#								target = root
				#								value < -25
				#							}
				#						}
				#						AND = {
				#							ai_boldness > 9
				#							ai_compassion < 1
				#							ai_honor < -29
				#							ai_vengefulness > -1
				#						}
				#					}
				#				}
				#			}
				#		}
				#	}
				#
				#	trigger_event = { # Usually I would use a notification but...
				#		id = fp2_struggle.2016 # The narrative impact of a full letter is greater, it makes sure the betrayal stings. This vassal wrote just to rub salt in your eyes.
				#		days = { 3 4 }
				#	} 
				#}
			}
		}

		stress_impact = {
			compassionate = medium_stress_impact_gain
			gallant = minor_stress_impact_gain
		}
	}

	option = { # Ignore the letter
		name = fp2_struggle.2015.b

		trigger = { is_ai = no }
		send_interface_toast = {
			type = event_toast_effect_good
			title = murder_outcome.4302.t
			left_icon = scope:fp2_struggle_2015_murder_requester_vassal
			right_icon = scope:fp2_struggle_2015_peasant_to_murder
		
			show_as_tooltip = { add_courtier = scope:fp2_struggle_2015_peasant_to_murder }
			reverse_add_opinion = {
				target = scope:fp2_struggle_2015_murder_requester_vassal
				modifier = broke_promise
			}
		}

		custom_tooltip = fp2_struggle.2015.a.murder_scheme
		hidden_effect = {
			scope:fp2_struggle_2015_murder_requester_vassal = {
				start_scheme = { 
					type = murder
					target_character = scope:fp2_struggle_2015_peasant_to_murder
				}
			}
		}
	}

	option = { # Warn the courtier about this (vassal may find out)
		name = fp2_struggle.2015.c

		random_list = {
			75 = { 
				desc = fp2_struggle.2015.c.b
				
				send_interface_toast = {
					type = event_intrigue_good
					title = fp2_struggle.2015.c.b
					left_icon = scope:fp2_struggle_2015_peasant_to_murder
					right_icon = scope:fp2_struggle_2015_murder_requester_vassal
				
					scope:fp2_struggle_2015_peasant_to_murder = { silent_disappearance_effect = yes }
					reverse_add_opinion = {
						target = scope:fp2_struggle_2015_murder_requester_vassal
						modifier = helped_me_in_time_of_need
						opinion = 25 # -15 points for suspicion (where is the body?)
					}
				}
			}
			25 = {
				desc = fp2_struggle.2015.c.a
				send_interface_toast = {
					type = event_intrigue_bad
					title = fp2_struggle.2015.c.a
					left_icon = scope:fp2_struggle_2015_peasant_to_murder
					right_icon = scope:fp2_struggle_2015_murder_requester_vassal
				  
					scope:fp2_struggle_2015_peasant_to_murder = { death = { death_reason = death_mysterious } }
					reverse_add_opinion = {
						target = scope:fp2_struggle_2015_murder_requester_vassal
						modifier = broke_promise
					}

					stress_impact = {
						forgiving = minor_stress_impact_gain
						humble = minor_stress_impact_gain
						just = medium_stress_impact_gain
						compassionate = medium_stress_impact_gain
						trusting = minor_stress_impact_gain
						gallant = minor_stress_impact_gain
					}
				}			  
			}
		}
	}
}

# fp2_struggle.2016 = {
	# type = letter_event
	# sender = scope:fp2_struggle_2015_murder_requester_vassal
	# opening = fp2_struggle.2016.t
	# desc = fp2_struggle.2016.desc

	# option = { # Tricked, backstabbed and quite possibly, out-smarted by your cunning vassal/rival
		# name = fp2_struggle.2016.a

		# hidden_effect = { scope:fp2_2015_murder_secret = { reveal_to = scope:fp2_struggle_2015_murder_requester_vassal } }
		# scope:fp2_struggle_2015_murder_requester_vassal = {
			# blackmail_target_with_secret_effect = {
				# SECRET = scope:fp2_2015_murder_secret
				# TARGET = ROOT
			# }
		# }
		# progress_towards_rival_effect = {
			# CHARACTER = scope:fp2_struggle_2015_murder_requester_vassal
			# REASON = rival_tricked_murder
			# OPINION = default_rival_opinion
		# }
		# add_opinion = {
			# target = scope:fp2_struggle_2015_murder_requester_vassal
			# modifier = betrayed_me_opinion
			# opinion = -60
		# }
	# }
# }

###################################
# RETURN OF THE THIEF KING
# By Hugo Cortell
###################################
# Directors liked the original very much
##########################################
fp2_struggle.2021 = { # Main event
	type = character_event
	title = fp2_struggle.2021.t
	desc = {
		desc = fp2_struggle.2021.desc
		first_valid = {
			triggered_desc = {
				trigger = { scope:fp2_2009_event_outcome = flag:cleared_out }
				desc = fp2_struggle.2021.desc.alt.cutout
			}
			triggered_desc = {
				trigger = { scope:fp2_2009_event_outcome = flag:paid_off }
				desc = fp2_struggle.2021.desc.alt.paidoff
			}
			triggered_desc = {
				trigger = { scope:fp2_2009_event_outcome = flag:worked_together }
				desc = fp2_struggle.2021.desc.alt.work
			}
			triggered_desc = {
				trigger = { scope:fp2_2009_event_outcome = flag:lobbed_head }
				desc = fp2_struggle.2021.desc.alt.behead
			}
		}
		desc = { desc = fp2_struggle.2021.desc.outro }
	}
	theme = secret
	override_background = { 
		trigger = { scope:fp2_2009_event_outcome = flag:cleared_out }
		reference = alley_day
	}
	override_background = { 
		trigger = { scope:fp2_2009_event_outcome = flag:paid_off }
		reference = tavern
	}
	override_background = { 
		trigger = { scope:fp2_2009_event_outcome = flag:worked_together }
		reference = throne_room
	}
	override_background = { 
		trigger = { scope:fp2_2009_event_outcome = flag:lobbed_head }
		reference = alley_night
	}
	left_portrait = {
		character = root
		animation = personality_rational
	}
	right_portrait = {
		character = scope:fp2_2009_garduna_guild_master
		animation = scheme
		outfit_tags = {
			western_stealth_hood
			sub_saharan_high_nobility
			mena_war_legwear
		}
	}

	trigger = {
		character_any_involvement_reconquista_struggle_trigger = yes # To check that the struggle is still going on
		exists = primary_title
		scope:fp2_2009_garduna_guild_master = { 
			is_available_ai_adult = yes
			OR = { # Is this char still looking for adventure or have they settled down?
				is_pool_character = yes
				is_pool_guest = yes
			}
		}
	}

	immediate = {
		title:c_napoli.title_province = { # Originally, the thieves were going to set up a guild there, but thats not very nice.
			county = {
				save_scope_as = fp2_2021_old_napoly
				holder.top_liege = {
					save_scope_as = fp2_2021_angry_italian # So instead you just get an opinion debuff for narrative impact.
				} # If this were not such a strange event, I would actually make it affect the character mechanically. But there is little excuse here.
			}
		}

		# Spy Network Logic, once upon a time used to be elegant.
		if = {
			limit = { exists = struggle:reconquista_struggle }
			struggle:reconquista_struggle = {
				if = {
					limit = { # Theoretically, effects which do not meet its conditions (the limit) are skipped over. However, the nightly has proven that wrong.
						any_involved_ruler = { # As such we take a _much_ more conservative approach of triple checking everything.
							exists = primary_title
							has_any_secrets = yes
							this != root
						}
					}
					random_involved_ruler = {
						limit = {
							exists = primary_title
							has_any_secrets = yes
							this != root
						}
						random_secret = { save_scope_as = fp2_2021_secreto_numero_ichi }
					}

					if = {
						limit = {
							any_involved_ruler = {
								exists = primary_title
								has_any_secrets = yes
								NOT = { 
									this = root
									any_secret = { this = scope:fp2_2021_secreto_numero_ichi }
								}
							}
						}
						random_involved_ruler = {
							limit = { 
								exists = primary_title
								has_any_secrets = yes
								NOT = { 
									this = root
									any_secret = { this = scope:fp2_2021_secreto_numero_ichi }
								}
							}
							random_secret = { save_scope_as = fp2_2021_secreto_numero_ni }
						}
					}
				}
			}
		}

		if = {
			limit = { exists = cp:councillor_spymaster }
			cp:councillor_spymaster = { save_scope_as = fp2_2021_spymaster }
		}

		hidden_effect = { # Hides exceptions from players, fix is not necessary
			scope:fp2_2009_garduna_guild_master = { 
				save_scope_as = dueltarget # For Loc
				move_to_pool_at = root.location # Fixes endless loop where the thief gets stretched across half the map
			}
		}
	}

	option = { # Send off to italy
		name = fp2_struggle.2021.a

		scope:fp2_2009_garduna_guild_master = {
			pay_short_term_gold = {
				target = ROOT
				gold = minor_gold_value
			}
		}
		custom_tooltip = fp2_struggle.2021.a.a
		scope:fp2_2021_angry_italian = {
			add_opinion = {
				target = root
				modifier = raided_me_opinion
				opinion = -40
			}
		}

		hidden_effect = { # Possible random outcomes
			random_list = {
				10 = { # "Retires", buys a house in italy and lives as an old man happily ever after (just like your dog went to a farm when it got old)
					scope:fp2_2009_garduna_guild_master = { silent_disappearance_effect = yes }

					modifier = {
						add = 30
						scope:fp2_2009_event_outcome = flag:lobbed_head
					}
					modifier = {
						add = 20
						scope:fp2_2009_event_outcome = flag:worked_together
					}
				}
				30 = { # He just sorta roams around italy
					scope:fp2_2009_garduna_guild_master = { move_to_pool_at = scope:fp2_2021_angry_italian.location }

					modifier = {
						add = 10
						scope:fp2_2009_event_outcome = flag:cleared_out
					}
				}
				10 = { # Joins napolitan court
					scope:fp2_2009_garduna_guild_master = { remove_nickname = yes } # Becomes a functional member of society
					scope:fp2_2021_angry_italian = {
						add_courtier = scope:fp2_2009_garduna_guild_master

						add_opinion = {
							target = scope:fp2_2009_garduna_guild_master
							modifier = impressed_opinion
							opinion = 20
						}
						reverse_add_opinion = {
							target = scope:fp2_2009_garduna_guild_master
							modifier = opinion_welcomed_with_tea
						}
					}

					modifier = {
						add = 20
						scope:fp2_2009_event_outcome = flag:paid_off
					}
				}
			}
		}
	}

	option = { # Recruit into court (cures courtier's depression if they were a member of the thief-king's gang)
		name = fp2_struggle.2021.b

		pay_short_term_gold = {
			target = scope:fp2_2009_garduna_guild_master
			gold = medium_gold_value
		}
		every_powerful_vassal = {
			limit = { NOT = { has_trait = forgiving } }
			custom = fp2_every_major_vassal_notifier
			add_opinion = {
				target = root
				modifier = suspicion_opinion
				opinion = -15
			}
		}
		add_courtier = scope:fp2_2009_garduna_guild_master
		if = {
			limit = { exists = scope:fp2_2009_garduna_young_thief }
			remove_trait = depressed_1 # My old boss survived! (though the rest are dead but shhh)
		}

		hidden_effect = {
			scope:fp2_2009_garduna_guild_master = {
				add_opinion = {
					target = root
					modifier = hired_me_opinion
					opinion = 15
				}

				if = { # There can only be one top dog, one master of the shadows.
					limit = { scope:fp2_2021_spymaster != scope:fp2_2009_garduna_young_thief }
					random = {
						chance = 25
						set_relation_rival = {
							target = scope:fp2_2021_spymaster
							reason = rival_garduna_young_thief
						}
					}
				}
			}
		}
	}

	option = { # Establish a spy network
		name = fp2_struggle.2021.c
		flavor = fp2_struggle.2021.c.flavor

		trigger = {
			OR = {
				exists = scope:fp2_2021_secreto_numero_ichi
				exists = scope:fp2_2021_secreto_numero_ni
			}
		}

		pay_short_term_gold = {
			target = scope:fp2_2009_garduna_guild_master
			gold = major_gold_value
		}

		custom_tooltip = fp2_struggle.2021.c.a # Perhaps it can mention the spymaster?
		hidden_effect = { # Note: You might end up learning secrets you already know, this is WAD
			if = {
				limit = { 
					exists = scope:fp2_2021_secreto_numero_ichi
					exists = scope:fp2_2021_secreto_numero_ni
				}
	
				send_interface_toast = {
					type = event_intrigue_good
					title = fp2_struggle.2021.c.spynet.a
					
					scope:fp2_2021_secreto_numero_ichi = { reveal_to = root }
					scope:fp2_2021_secreto_numero_ni = { reveal_to = root }
				}
			}
			else = {
				if = {
					limit = { exists = scope:fp2_2021_secreto_numero_ichi }
					send_interface_toast = {
						type = event_intrigue_good
						title = fp2_struggle.2021.c.spynet.a
						
						scope:fp2_2021_secreto_numero_ichi = { reveal_to = root }
					}
				}
				else_if = {
					limit = { exists = scope:fp2_2021_secreto_numero_ni }
					send_interface_toast = {
						type = event_intrigue_good
						title = fp2_struggle.2021.c.spynet.a
						
						scope:fp2_2021_secreto_numero_ni = { reveal_to = root }
					}
				}
			}
		}

		scope:fp2_2009_garduna_guild_master = { silent_disappearance_effect = yes }
	}

	option = { # Duel option (get title late)
		name = {
			text = {
				first_valid = {
					triggered_desc = {
						trigger = { scope:fp2_2009_event_outcome = flag:lobbed_head }
						desc = fp2_struggle.2021.d.alt
					}
					desc = fp2_struggle.2021.d
				}
			}
		}
		trigger = { NOT = { age < 14 } }

		custom_tooltip = fp2_struggle.2021.d.b
		show_as_tooltip = {
			if = {
				limit = {
					OR = {
						has_any_nickname = no
						has_bad_nickname = yes
					}
				}
				give_nickname = nick_the_Thief_Slayer
			}
		}
		ROOT = { save_scope_as = fp2_2021_root_in_duel }
		scope:fp2_2009_garduna_guild_master = {
			set_variable = {
				name = signature_weapon
				value = flag:dagger
			}
		}

		if = { # Changes the background to match, you cannot use conditional values on scripted effects
			limit = { scope:fp2_2009_event_outcome = flag:cleared_out }
			configure_start_single_combat_effect = {
				SC_INITIATOR = root
				SC_ATTACKER = root
				SC_DEFENDER = scope:fp2_2009_garduna_guild_master
				FATALITY = always
				FIXED = no
				LOCALE = alley_day
				OUTPUT_EVENT = fp2_struggle.2022
				INVALIDATION_EVENT = fp2_struggle.2022
			}
		}
		else_if = {
			limit = { scope:fp2_2009_event_outcome = flag:paid_off }
			configure_start_single_combat_effect = {
				SC_INITIATOR = root
				SC_ATTACKER = root
				SC_DEFENDER = scope:fp2_2009_garduna_guild_master
				FATALITY = always
				FIXED = no
				LOCALE = tavern
				OUTPUT_EVENT = fp2_struggle.2022
				INVALIDATION_EVENT = fp2_struggle.2022
			}
		}
		else_if = {
			limit = { scope:fp2_2009_event_outcome = flag:worked_together }
			configure_start_single_combat_effect = {
				SC_INITIATOR = root
				SC_ATTACKER = root
				SC_DEFENDER = scope:fp2_2009_garduna_guild_master
				FATALITY = always
				FIXED = no
				LOCALE = throne_room
				OUTPUT_EVENT = fp2_struggle.2022
				INVALIDATION_EVENT = fp2_struggle.2022
			}
		}
		else_if = {
			limit = { scope:fp2_2009_event_outcome = flag:lobbed_head }
			configure_start_single_combat_effect = {
				SC_INITIATOR = root
				SC_ATTACKER = root
				SC_DEFENDER = scope:fp2_2009_garduna_guild_master
				FATALITY = always
				FIXED = no
				LOCALE = alley_night
				OUTPUT_EVENT = fp2_struggle.2022
				INVALIDATION_EVENT = fp2_struggle.2022
			}
		}
	}

	after = { remove_global_variable = fp2_struggle_2009_thief_king_char }
}

fp2_struggle.2022 = { # You become the KING OF THIEVES again, well, late is better than never...
	hidden = yes
	immediate = {
		if = {
			limit = {
				exists = scope:fp2_2022_reuse_gate
				root = scope:fp2_2021_root_in_duel 
			}
			send_interface_toast = {
				type = event_toast_effect_good
				title = fp2_struggle.2021.d.a
				right_icon = ROOT
				if = {
					limit = {
						OR = {
							has_any_nickname = no
							has_bad_nickname = yes
						}
					}
					give_nickname = nick_the_Thief_Slayer
				}
				add_prestige = medium_prestige_gain # Penalty for finishing the job late
				add_gold = minor_gold_value
			}
		}
		else = {
			save_scope_as = fp2_2022_reuse_gate
			trigger_event = { 
				id = fp2_struggle.2022
				days = 1
			} 
		}
	}
}

###################################
# The Price of War
# by Veronica Pazos
###################################
# You pawn your crown to get some gold to help in your war
##############################################################
fp2_struggle.3001 = {
	type = character_event
	title = fp2_struggle.3001.t
	desc = {
		desc = fp2_struggle.3001.desc
		first_valid = {
			triggered_desc = { 
				trigger = {
					is_at_war = yes
				}
				desc = fp2_struggle.3001.desc_war_intro
			}
			triggered_desc = {
				trigger = {
					is_at_war = no
				}
				desc = fp2_struggle.3001.desc_no_war_intro
			}
		}
		desc = fp2_struggle.3001.desc_outro
	}

	theme = crown
	cooldown = { years = 5 } #in case you don't sell your crown you'll have to wait to get the chance again
	override_background = { reference = council_chamber }
	left_portrait = {
		character = root
		animation = worry
	}
	right_portrait = {
		character = cp:councillor_steward
		animation = personality_rational
	}
	
	trigger = {
		has_fp2_dlc_trigger = yes #dlc check
		is_available_even_at_war_adult = yes
		primary_title.tier >= tier_kingdom #so we make sure you have an actual crown
		OR = { #someone has to suggest this
			exists = cp:councillor_steward
			any_courtier = {
				stewardship >= medium_skill_rating
			}
		}
		gold < minor_gold_value #you don't have much gold
		NOT = { has_character_flag = sold_crown_charmod } #you haven't sold your crown before
		struggle:reconquista_struggle = {
			NOT = { is_struggle_phase = struggle_reconquista_phase_reprieve } #you're not in the compromise phase
		}
	}

	weight_multiplier  = { #more likely to trigger the poorer you are
		modifier = {
			add = 0.25
			gold <= 25
		}
		modifier = {
			add = 0.25
			gold <= 20
		}
		modifier = {
			add = 0.5
			gold <= 15
		}
		modifier = {
			add = 0.5
			gold <= 10
		}
	}
	
	immediate = {
		play_music_cue = "mx_cue_touching_moment" 
		if = {
			limit = {
				exists = cp:councillor_steward
			}
			cp:councillor_steward = { save_scope_as = struggle_3001_steward }
		}
		else = {
			random_courtier = {
				limit = {
					stewardship >= medium_skill_rating
				}
				save_scope_as = struggle_3001_steward
			}
		}
		if = {
			limit = {
				has_any_artifact = yes
				any_character_artifact = { artifact_type = helmet } #we check if you have a crown artifact
			}
			random_character_artifact = {
				limit = { artifact_type = helmet }
				save_scope_as = struggle_3001_crown_artifact
			}
		}
		if = { 
			limit = {
				is_married = yes
			}
			primary_spouse = {
				save_scope_as = struggle_3001_spouse
			}
		}
	}

	option = { #sell your own crown
		name = fp2_struggle.3001.a
		flavor = fp2_struggle.3001.a_flavour
		add_character_flag = sold_crown_charmod #you lose your crown
		#give_nickname = nick_the_crownless #now everyone knows
		add_gold = medium_gold_max_value
		add_prestige = major_prestige_loss
		stress_impact = {
			arrogant = medium_stress_impact_gain
			humble = minor_stress_loss
		}
		
		ai_chance = {
			base = 5
			modifier = {
				add = 5
				gold <= 15
			}
			ai_value_modifier = {
				ai_greed = 0.15
				ai_rationality = 0.2
			}
		}
	}
	
	option = { #sell artifact crown instead
		name = fp2_struggle.3001.b
		trigger = { #triggers if you actually have one
			any_character_artifact = {
				artifact_slot_type = helmet
			}
		}
		add_gold = medium_gold_value
		add_prestige = minor_prestige_loss
		destroy_artifact = scope:struggle_3001_crown_artifact
		stress_impact = {
			greedy = minor_stress_impact_gain
		}
		
		ai_chance = {
			base = 5
			modifier = {
				add = 5
				gold <= 15
			}
			ai_value_modifier = {
				ai_greed = -0.3
				ai_rationality = 0.2
			}
		}
	}
	
	option = { #but my spouse also has a crown...
		name = fp2_struggle.3001.c
		flavor = fp2_struggle.3001.c_flavour
		trigger = {
			is_married = yes #you have a spouse
			scope:struggle_3001_spouse = {
				NOT = { has_character_flag = sold_crown_charmod } #and you didn't sell their crown
			}
		}
		add_gold = medium_gold_value
		add_prestige = minor_prestige_loss
		if = {
			limit = {
				scope:struggle_3001_spouse = {
					has_trait = humble
				}
			}
			scope:struggle_3001_spouse = {
				add_opinion = {
					target = ROOT
					opinion = -25 #they are displeased
					modifier = struggle_3001_spouse_crown_modifier
				}
				add_character_flag = sold_crown_charmod #your spouse loses their crown
			}
		}
		else = {
			scope:struggle_3001_spouse = {
				add_opinion = {
					target = ROOT
					opinion = -75 #they REALLY hate you
					modifier = struggle_3001_spouse_crown_modifier
				}
				add_character_flag = sold_crown_charmod #your spouse loses their crown
			}
		}
		stress_impact = {
			generous = medium_stress_impact_gain
			compassionate = medium_stress_impact_gain
		}
		
		ai_chance = {
			base = 10
			modifier = {
				add = 5
				gold <= 15
			}
			ai_value_modifier = {
				ai_greed = 0.5
			}
		}
	}
	
	option = { #I'll be dead before losing my crown
		name = fp2_struggle.3001.d
		stress_impact = {
			base = medium_stress_gain #you really need money
		}
		
		ai_chance = {
			base = 5
		}
	}
}

###################################
# Order of the Hatchet
# By Veronica Pazos
###################################
# Order of the Hachet - Woman are defending your city
#######################################################
fp2_struggle.3011 = {
	orphan = yes
	type = character_event
	title = fp2_struggle.3011.t
	desc = {
		first_valid = {
			triggered_desc = { 
				trigger = {
					faith = { has_doctrine = doctrine_gender_female_dominated }
				}
				desc = fp2_struggle.3011.desc_men #reverse genre event
			}
			desc = fp2_struggle.3011.desc
		}
		desc = fp2_struggle.3011.desc_outro
	}

	theme = realm
	cooldown = { years = 20 }
	left_portrait = {
		character = root
		animation = personality_rational
	}
	right_portrait = {
		character = cp:councillor_marshal
		animation = marshal
	}
	lower_right_portrait = scope:bishop
	
	trigger = {
		has_fp2_dlc_trigger = yes
		character_any_involvement_reconquista_struggle_trigger = yes #there's an ongoing struggle (includes dlc check)
		is_available_even_at_war_adult = yes
		is_landed_or_landless_administrative = yes
		any_character_war = {
			war_days >= 30 #a battle has likely happened
		}
		exists = cp:councillor_marshal #someone tells you about the incident
		exists = cp:councillor_court_chaplain
		faith = {
			NOT = { has_doctrine = doctrine_gender_equal } #checks that this is unusual
		}
		OR = { #checks again that this makes sense, Ola Jentzsch's note 
			has_game_rule = default_gender_equality
			has_game_rule = inversed_gender_equality
		}
		struggle:iberian_struggle = { #there's a struggle going on
			OR = {
				is_struggle_phase = struggle_iberia_phase_hostility
				is_struggle_phase = struggle_iberia_phase_opportunity
			}
		}
		any_sub_realm_barony = { 
			exists = holder
			title_province = { has_holding_type = city_holding }
		}
	}

	weight_multiplier  = {
		base = 1
	}
	
	immediate = {
		cp:councillor_marshal = { save_scope_as = struggle_3011_marshal }
		cp:councillor_court_chaplain = { save_scope_as = bishop }
		random_sub_realm_barony = { 
			limit = {
				exists = holder
				title_province = { has_holding_type = city_holding }
			}
			county = { save_scope_as = struggle_3011_county_town }
		}
	}

	option = { #that's dope
		name = fp2_struggle.3011.a
		scope:struggle_3011_county_town = {
			add_county_modifier = {
				modifier = fp2_order_of_the_hachet_modifier
				years = 5
			}
		}
		scope:bishop = {
			add_opinion = {
				target = ROOT
				opinion = -25
				modifier = angry_opinion
			}
		}
		every_vassal = {
			custom = custom.every_zealous_callous_or_sadistic_vassal
			limit = {
				OR = {
					has_trait = zealous
					has_trait = callous
				}
			}
			add_opinion = {
				target = ROOT
				opinion = -10
				modifier = annoyed_opinion
			}
		}
		stress_impact = {
			zealous = medium_stress_impact_gain
		}
		
		ai_chance = {
        	base = 10
        	ai_value_modifier = {
           		ai_zeal = -1 #zealous AI will never pick this
				ai_compassion = 0.2
				ai_honor = 0.2
        	}
   		}
	}
	
	option = { #ridiculous
		name = {
			trigger = {
				faith = { has_doctrine = doctrine_gender_male_dominated }
			}
			text = fp2_struggle.3011.b
		}
		name = {
			trigger = {
				faith = { has_doctrine = doctrine_gender_female_dominated } 
			}
			text = fp2_struggle.3011.b_men
		}
		scope:bishop = {
			add_opinion = {
				target = ROOT
				opinion = 10
				modifier = grateful_opinion
			}
		}
		if = {
			limit = {
				faith = { has_doctrine = doctrine_gender_male_dominated }
			}
			every_courtier = {
				custom = custom.every_female_courtier
				limit = {
					is_female = yes
				}
				add_opinion = {
					target = ROOT
					opinion = -10
					modifier = insult_opinion
				}
			}
		}
		else_if = {
			limit = {
				faith = { has_doctrine = doctrine_gender_female_dominated }
			}
			every_courtier = {
				custom = custom.every_male_courtier
				limit = {
					is_male = yes
				}
				add_opinion = {
					target = ROOT
					opinion = -10
					modifier = insult_opinion
				}
			}
		}
		stress_impact = {
			cynical = medium_stress_impact_gain
		}
		
		ai_chance = {
        	base = 10
        	ai_value_modifier = {
           		ai_zeal = 0.2
           		ai_rationality = -0.2
        	}
   		}
	}
	
	option = { #witches!
		name = fp2_struggle.3011.c
		trigger = {
			has_trait = zealous
		}
		add_dread = medium_dread_gain
		add_character_modifier = {
			modifier = fp2_punished_order_of_the_hachet_modifier
			years = 5
		}
		
		ai_chance = { #zealous AI will pick this option 
        	base = 1
        	ai_value_modifier = {
           		ai_zeal = 0.8
           		ai_energy = -0.7
            	ai_vengefulness = 0.5
        	}
   		}
	}
	
	option = { #I shall save these damsels in distress!
		name = fp2_struggle.3011.d 
		trigger = {
			faith = { has_doctrine = doctrine_gender_male_dominated }
			OR = {
				has_trait = gallant
				has_trait = arrogant
				culture = {
					has_cultural_tradition = tradition_chanson_de_geste
				}
			}
		}
		random_list = { #how does that go
			75 = {
				add_stress = medium_stress_gain
			}
			25 = {
				add_stress = medium_stress_impact_loss
			}
		}
		
		ai_chance = {
        	base = 10
   		}
	}
}

###################################
# The Wrath of Heaven
# By Veronica Pazos
###################################
# "Lightning stones" in a siege
###################################
fp2_struggle.3021 = {
	type = character_event
	title = fp2_struggle.3021.t
	desc = fp2_struggle.3021.desc

	theme = martial
	left_portrait = {
		character = root
		animation = personality_cynical
	}
	right_portrait = {
		character = scope:struggle_3021_knight
		animation = shock
	}
	lower_right_portrait = scope:struggle_3021_courtier
	
	trigger = {
		has_fp2_dlc_trigger = yes
		character_any_involvement_reconquista_struggle_trigger = yes
		is_available_even_at_war_adult = yes
		NOT = { has_character_flag = had_event_struggle_3021 } #so you don't research the same thing again
		struggle:reconquista_struggle = { #there's some kind of hostility going on
			OR = {
				is_struggle_phase = struggle_reconquista_phase_hostility
			}
		}
		any_knight = { #someone sees this
			is_available_healthy_ai_adult = yes
		}
		any_courtier = { #someone will research this
			is_available_healthy_ai_adult = yes
			count > 0
		}
		any_directly_owned_province = { #we have a castle to use it on
			has_holding_type = castle_holding
			NOT = { has_province_modifier = fp2_lightning_stones_modifier }
		}
	}

	weight_multiplier  = {
		base = 1
		modifier = {
			add = 1
			is_at_war = yes
		}
	}
	
	immediate = {
		add_character_flag = had_event_struggle_3021
		random_knight = {
			limit = {
				is_available_healthy_ai_adult = yes
			}
			save_scope_as = struggle_3021_knight
		}
		every_courtier = { #get your courtiers
			limit = {
				is_available_ai_adult = yes
				NOT = { this = root.primary_spouse } #you shouldn't lose your spouse or heir because of this
				NOT = { this = root.player_heir }
				is_immortal = no
			}
			add_to_list = struggle_3021_courtier_list
		}
		ordered_in_list = { #sort through to pick the one with highest learning
			list = struggle_3021_courtier_list
			order_by = learning
			max = 1
			save_scope_as = struggle_3021_courtier
		}
		random_directly_owned_province = { #this is where we can try it
			limit = {
				has_holding_type = castle_holding
			}
			save_scope_as = lightning_stones_province
		}
	}
	
	option = { #we need to research this stuff
		name = fp2_struggle.3021.a 
		
		scope:struggle_3021_courtier = { #This is who is doing the research
			duel = {
				skill = learning #The skill needed for research
				value = average_skill_rating #Found in 00_basic_values.txt - An 8 in this case
				12 = { #Success - We keep the weight values fairly close to our skill values so they can be affected. 20 is a good max.
					compare_modifier = {
						value = scope:duel_value
						multiplier = 2 #This multiplies the *difference* between the skill and the target. Meaning folks with good skills will be much more likely to get it.
						min = -5 #This prevents truly terrible people from completely losing the chance to succeed.
					}
					desc = good_struggle_3021_courtier_desc
					root = {
						send_interface_toast = {
							title = good_stone_research_title
							left_icon = scope:struggle_3021_courtier
							scope:lightning_stones_province = {
								add_province_modifier = {
									modifier = fp2_lightning_stones_modifier
								}
							}
						}
					}
				}
				14 = { #Failure!
					compare_modifier = {
						value = scope:duel_value
						multiplier = -2 #This multiplies and inverts the *difference* between the skill and the target. Meaning folks with bad skills will be much more likely to get this.
					}
					desc = bad_struggle_3021_courtier_desc
					root = {
						send_interface_toast = { #send a toast
							title = bad_stone_research_title
							desc = bad_struggle_3021_courtier_desc
							left_icon = scope:struggle_3021_courtier
							scope:struggle_3021_courtier = {
								pod_death_no_killer = { death_reason = death_accident }
							}
						}
					}
				}
			}	
		}
		
		stress_impact = {
			zealous = medium_stress_impact_gain
		}
	}
	
	option = { #this is not the greatest idea
		name = fp2_struggle.3021.b
		reverse_add_opinion = {
			target = scope:struggle_3021_courtier
			modifier = insulted_opinion
			opinion = -15
		}
		stress_impact = {
			base = minor_stress_impact_loss
			zealous = medium_stress_impact_gain
			craven = minor_stress_impact_loss
			brave = medium_stress_impact_gain
		}
	}
	
	option = { #we can maybe use this in a feast
		name = fp2_struggle.3021.c
		trigger = {
			OR = {
				has_trait = vengeful
				has_trait = deceitful
				has_trait = arbitrary
				has_trait = callous
				intrigue >= high_skill_rating
				has_lifestyle = intrigue_lifestyle
			}
		}
		
		duel = {
			skill = learning
			target = scope:struggle_3021_courtier
			30 = { #it works
				compare_modifier = {
					value = scope:duel_value
					multiplier = 0.5
				}
				desc = good_struggle_3021_courtier_desc
				root = {
					send_interface_toast = {
						title = good_stone_research_title
						left_icon = scope:struggle_3021_courtier
						
						add_character_modifier = {
							modifier = fp2_lightning_stones_poison_modifier
							years = 5
						}
					}
				}
			}
			70 = { #it doesnt work
				compare_modifier = {
					value = scope:duel_value
				}
				desc = bad_struggle_3021_courtier_desc
				root = {
					send_interface_toast = { #send a toast
						title = bad_stone_research_title
						desc = bad_struggle_3021_courtier_desc
						left_icon = scope:struggle_3021_courtier
						
						scope:struggle_3021_courtier = {
							pod_death_no_killer = { death_reason = death_accident }
						}
					}
				}
			}
		}
		
		stress_impact = {
			forgiving = medium_stress_impact_gain
			honest = medium_stress_impact_gain
			compassionate = medium_stress_impact_gain
			zealous = medium_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_boldness = 0.2
				ai_vengefulness = 1
			}
		}
	}
	
	option = { #god's punihsment!
		name = fp2_struggle.3021.d
		trigger = {
			OR = {
				has_trait = zealous
				stress >= high_medium_stress
			}
		}
		add_piety = minor_piety_gain
		stress_impact = {
			zealous = minor_stress_loss
		}
	}
	
	option = { #lightning stones for the lightning stone god
		name = fp2_struggle.3021.e
		trigger = {
			religion = { is_in_family = rf_pagan }
		}
		add_piety = medium_piety_gain
	}
}
