﻿#Events for authority lifestyle focus


##################################################

#AUTHORITY REGULAR EVENTS
	# 1031		- Mercenaries are being misbehaving at an inn, by Linnéa Thimrén
	# 2040-2042	- Fight between my soldiers (Diplomacy skill challenge), Sean Hughes
	# 2050-2057 - An Extra Hand: Find a right-hand (wo)man, Sean Hughes
	# 3000		- Displaying/Teaching Authority to Someone, by Milla Isaksson

#AUTHORITY SPECIAL EVENTS
	# 1100-1104	- Soldier and Officer Fighting, by Mathilda Bjarnehed
	# 1501-1504	- Deal with Deserters, by Linnéa Thimrén

##################################################

#############################
# AUTHORITY: REGULAR EVENTS #
#############################

namespace = martial_authority

##################################################
# Mercenaries are being misbehaving at an inn
	# by Linnéa Thimrén
##################################################

martial_authority.1031 = {
	type = character_event
	title = martial_authority.1031.t
	desc = martial_authority.1031.desc
	theme = martial_authority_focus
	override_background = {
		event_background = tavern
	}

	left_portrait = {
		character = scope:scoped_mercenary
		animation = dismissal
	}
	
	trigger = {
		OR = {
			is_ai = no
			is_adult = yes
			has_lifestyle = martial_lifestyle
		}
		NOT = { has_character_flag = had_mercenary_disruption_event }
		is_ruler = yes
		is_landed = yes
		exists = capital_county
		any_independent_ruler = {
			has_government = mercenary_government
		}
	}

	weight_multiplier = {
		base = 1
		upweight_for_focus_modifier = { FOCUS = martial_authority_focus }
	}

	immediate = {
		play_music_cue = "mx_cue_meadandwine"
		add_character_flag = {
			flag = had_mercenary_disruption_event
			days = 3650
		}
		capital_county = {
			save_scope_as = county_to_save
		}
		random_independent_ruler = {
			limit = {
				has_government = mercenary_government
				culture = root.culture
			}
			alternative_limit = {
				has_government = mercenary_government
				faith = root.faith
			}
			alternative_limit = {
				has_government = mercenary_government
			}
			save_scope_as = scoped_mercenary
		}
	}

	option = {
		name = martial_authority.1031.a
		trigger = {
			OR = {
				is_ai = no
				short_term_gold >= major_gold_value_check
			}
		}
		
		ai_chance = {
			base = 50
			modifier = {
				add = 20
				OR = {
					has_trait = generous
					has_trait = craven
					has_trait = shy
				}
			}
		}
		remove_short_term_gold = major_gold_value
		add_character_modifier = {
			modifier = generous_to_mercenaries
		}
		add_martial_lifestyle_xp = minor_lifestyle_xp
		stress_impact = {
			greedy = minor_stress_impact_gain
		}
	}
	
	option = {
		name = martial_authority.1031.b
		scope:county_to_save = {
			add_county_modifier = {
				modifier = warfare_expunged_bandits_modifier
				years = 10
			}
		}
		ai_chance = {
			base = 50
			modifier = {
				add = 20
				OR = {
					has_trait = just
					has_trait = greedy
				}
			}
		}
		add_martial_lifestyle_xp = minor_lifestyle_xp
		stress_impact = {
			just = minor_stress_impact_gain
		}
	}
	option = {
		name = martial_authority.1031.c
		trigger = {
			prowess >= high_skill_rating
		}
		skill = prowess
		scope:county_to_save = {
			add_county_modifier = {
				modifier = warfare_expunged_bandits_modifier
				years = 10
			}
		}
		if = {
			limit = {
				OR = {
					has_trait = sadistic
					has_trait = wrathful
				}
			}
			add_dread = medium_dread_gain
		}
		else_if = {
			limit = {
				NOT = {
					OR = {
						has_trait = sadistic
						has_trait = wrathful
					}
				}
			}
			add_character_modifier = {
				modifier = respected_by_mercenaries
			}
		}
		ai_chance = {
			base = 50
			modifier = {
				add = 30
				OR = {
					has_trait = brave
					has_trait = wrathful
					has_trait = sadistic
					has_trait = vengeful
				}
			}
		}
		add_martial_lifestyle_xp = medium_lifestyle_xp
		stress_impact = {
			calm = minor_stress_impact_gain
			compassionate = minor_stress_impact_gain
			forgiving = minor_stress_impact_gain
		}
	}
}

##################################################
# Internal Dispute (Diplomacy Skill Challenge)
# by Sean Hughes
# 2040-2042
##################################################

#Find a courtier who would fight in your army.
scripted_trigger martial_authority_2040_first_trigger = {
	is_ai = yes
	is_available_healthy_adult = yes

	age <= 35
	can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = this }

	save_temporary_scope_as = first

	root = {
		any_knight = {
			martial_authority_2040_second_trigger = yes
		}
	}
}

#Find another courtier who is disliked by the first one.
scripted_trigger martial_authority_2040_second_trigger = {
	is_ai = yes
	is_available_healthy_adult = yes

	age <= 40

	NOT = { this = scope:first }
	reverse_opinion = {
		target = scope:first
		value <= neutral_opinion
	}
}

martial_authority.2040 = {
	type = character_event
	title = martial_authority.2040.t
	desc = martial_authority.2040.desc
	theme = martial_authority_focus
	override_background = {
		event_background = army_camp
	}
	
	left_portrait = {
		character = scope:first
		animation = anger
	}
	right_portrait = {
		character = scope:second
		animation = rage
	}

	trigger = {
		NOT = { has_character_flag = had_event_martial_authority_2040 } #Can only happen once every 5 years.

		#Only trigger if we've been at war for at least a few days.
		days_of_continuous_war >= 5
		is_available_adult_or_is_commanding = yes

		any_knight = {
			martial_authority_2040_first_trigger = yes
		}
		any_knight = {
			martial_authority_2040_second_trigger = yes
		}
	}
	
	weight_multiplier = {
		base = 1
		modifier = {
			add = { #-1 at 5 diplomacy, 0 at 10 diplomacy, 1 at 15 diplomacy etc.
				value = diplomacy
				subtract = medium_skill_rating
				multiply = 0.2
			}
		}
		upweight_for_focus_modifier = { FOCUS = martial_authority_focus }
	}

	immediate = {
		add_character_flag = {
			flag = had_event_martial_authority_2040
			days = 1825
		}

		random_knight = {
			limit = {
				martial_authority_2040_first_trigger = yes
			}
			save_scope_as = first
		}
		random_knight = {
			limit = {
				martial_authority_2040_second_trigger = yes
			}
			assign_quirk_effect = yes
			save_scope_as = second
		}
	}

	#Attempt to get the men to calm down and work together
	option = {
		name = martial_authority.2040.a
		duel = {
			skill = diplomacy
			value = 10
			50 = {		
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				desc = martial_authority.2040.a.success
				trigger_event = martial_authority.2041 #The men calm down.
				show_as_tooltip = {
					add_prestige = medium_prestige_gain
					add_martial_lifestyle_xp = medium_lifestyle_xp
					reverse_add_opinion = {
						target = scope:first
						modifier = respect_opinion
						opinion = low_positive_opinion
					}
					reverse_add_opinion = {
						target = scope:second
						modifier = respect_opinion
						opinion = low_positive_opinion
					}
				}
			}
			50 = {		
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				desc = martial_authority.2040.a.failure
				trigger_event = martial_authority.2042 #A brawl breaks out!
				show_as_tooltip = {
					add_prestige = minor_prestige_loss
				}
				custom_tooltip = martial_authority.2040.a.failure.tt
			}
		}
		stress_impact = {
			shy = medium_stress_impact_gain
			callous = minor_stress_impact_gain
			sadistic = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_boldness = 100
				ai_compassion = 100
			}
			# Rational characters know when they have a good chance of winning the duel
			compare_modifier = {
				trigger = {
					ai_rationality >= 10
				}
				value = {
					value = diplomacy
					add = -10
				}
				multiplier = 1000 # -10,000 at 0 Stewardship, +0 at 10 Stewardship, +10,000 at 20 Stewardship
			}
		}
	}

	#Have the soldiers whipped
	option = {
		name = martial_authority.2040.b
		add_dread = medium_dread_gain
		scope:first = {
			increase_wounds_effect = { REASON = whipping }
			add_opinion = {
				target = root
				modifier = angry_opinion
				opinion = low_negative_opinion
			}
		}
		scope:second = {
			increase_wounds_effect = { REASON = whipping }
			add_opinion = {
				target = root
				modifier = angry_opinion
				opinion = low_negative_opinion
			}
		}
		add_martial_lifestyle_xp = minor_lifestyle_xp
			stress_impact = {
				compassionate = medium_stress_impact_gain
				calm = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_honor = -100
				ai_vengefulness = 100
				ai_compassion = -200
			}
		}
	}

	#Leave the men to their petty quarrel
	option = {
		name = {
			text = martial_authority.2040.c
			trigger = {		
				NOR = {
					has_trait = hashishiyah
					has_trait = drunkard
				}
			}
		}
		name = {
			text = martial_authority.2040.c.hashishiyah
			trigger = { has_trait = hashishiyah }
		}
		name = {
			text = martial_authority.2040.c.drunkard
			trigger = { has_trait = drunkard }
		}
		add_prestige = miniscule_prestige_loss
		
		if = {
			limit = {
				OR = {
					has_trait = hashishiyah
					has_trait = drunkard
				}
			}
			add_stress = medium_stress_impact_loss
		}
		else = {
			stress_impact = {
				diligent = minor_stress_impact_gain
				just = minor_stress_impact_gain
				reclusive = minor_stress_impact_loss
			}
		}

		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_compassion = -100
				ai_energy = -100
			}
		}
	}
}

#Men calm down
martial_authority.2041 = {
	type = character_event
	title = martial_authority.2041.t
		desc = martial_authority.2041.desc
		theme = martial_authority_focus
	override_background = {
		event_background = army_camp
	}
	
	left_portrait = {
		character = scope:first
		animation = shame
	}
	right_portrait = {
		character = scope:second
		animation = worry
	}

	option = {
		name = martial_authority.2041.a
		add_prestige = medium_prestige_gain
			reverse_add_opinion = {
			target = scope:first
			modifier = respect_opinion
			opinion = low_positive_opinion
		}
		reverse_add_opinion = {
			target = scope:second
			modifier = respect_opinion
			opinion = low_positive_opinion
		}
		add_martial_lifestyle_xp = medium_lifestyle_xp
	}
}

#Brawl breaks out!
martial_authority.2042 = {
	type = character_event
	title = martial_authority.2042.t
		desc = martial_authority.2042.desc
	theme = martial_authority_focus
	override_background = {
		event_background = army_camp
	}
	
	left_portrait = {
		character = scope:first
		animation = anger
	}
	right_portrait = {
		character = scope:second
		animation = rage
	}

	immediate = {
		play_music_cue = "mx_cue_combat_3"
	}
	
	option = {
		name = martial_authority.2042.a
		duel = {
			skill = prowess
			value = 15
			50 = {		
				compare_modifier = {
					value = scope:duel_value
					multiplier = 4
					min = -49
				}
				desc = martial_authority.2042.a.success
				send_interface_toast = {
					type = event_toast_effect_good
					title = martial_authority.2042.a.success
					left_icon = root
					add_prestige = medium_prestige_gain
					add_martial_lifestyle_xp = medium_lifestyle_xp
				}
			}
			50 = {		
				compare_modifier = {
					value = scope:duel_value
					multiplier = -4
					min = -49
				}
				desc = martial_authority.2042.a.failure
				send_interface_toast = {
					type = event_toast_effect_bad
					title = martial_authority.2042.a.failure
					left_icon = root
					increase_wounds_effect = { REASON = fight }
					add_martial_lifestyle_xp = miniscule_lifestyle_xp
				}
			}
		}

		stress_impact = {
				#Rare opportunity for certain character types to 'blow off some steam' and lose stress here, at risk of wounds.
				wrathful = medium_stress_loss
				vengeful = medium_stress_loss
				sadistic = medium_stress_loss

				#Most characters won't want to do this, though.
				craven = major_stress_impact_gain
				calm = medium_stress_impact_gain
				patient = minor_stress_impact_gain
				forgiving = minor_stress_impact_gain
				compassionate = minor_stress_impact_gain
		}
			
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_boldness = 100
				ai_vengefulness = 100
				ai_energy = 100
				ai_rationality = -100
			}
			# Rational characters know when they have a good chance of winning the duel
			compare_modifier = {
				trigger = {
					ai_rationality >= 10
				}
				value = {
					value = prowess
					add = -15
				}
				multiplier = 1500 # -22,500 at 0 Prowess, +0 at 15 Prowess, +7,500 at 20 Prowess
			}
		}
	}

	option = {
		name = martial_authority.2042.b
		add_prestige = minor_prestige_loss
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_compassion = 100
				ai_rationality = 100
			}
		}
	}
}

##################################################
# An Extra Hand: Find a right-hand (wo)man
# by Sean Hughes
# 2050 - 2057
##################################################

scripted_trigger martial_authority_2050_can_be_right_hand_person_trigger = {
	is_available_ai_adult = yes
	# Must not be the kind of person to ignore/defy your will.
	NOT = {
		has_trait = greedy
		has_trait = ambitious
		has_trait = lazy
		has_trait = arbitrary
	}
	opinion = {
		target = root
		value >= -15
	}

	# Not a baron; they're too insignificant!
	NOT = {
		highest_held_title_tier = 1
	}

	# Not your marshal (since they appear elsewhere in the event).
	NOR = {
		is_councillor_of = root
		has_council_position = councillor_marshal
	}

	# Not somebody else's right-hand person.
	NOT = { has_variable = is_right_hand_person_of }
}

# Gain a Right-Hand Person
martial_authority.2050 = {
	type = character_event
	title = martial_authority.2050.t
	desc = {
		desc = martial_authority.2050.desc.opening
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:right_hand_person = {
						is_vassal_of = root
						is_landed = yes
					}
				}
				desc = martial_authority.2050.desc.vassal
			}
			triggered_desc = {
				trigger = {
					scope:right_hand_person = {
						is_knight_of = root
					}
				}
				desc = martial_authority.2050.desc.knight
			}
			desc = martial_authority.2050.desc.courtier
		}
		desc = martial_authority.2050.desc.ending
	}
	theme = martial_authority_focus
	
	left_portrait = scope:right_hand_person
	right_portrait = scope:marshal
	
	trigger = {
		has_focus = martial_authority_focus # Restricted to Authority lifestyle, because it's not really sensible for Chivalry or Strategy
		NOT = { has_variable = right_hand_person } # Does not already have a right-hand person.
		NOT = { has_character_flag = had_event_martial_authority_2050 } #Can only happen once every 5 years.

		# A valid character to become our right-hand person must exist.
		OR = {
			any_vassal = {
				martial_authority_2050_can_be_right_hand_person_trigger = yes
			}
			any_knight = {
				martial_authority_2050_can_be_right_hand_person_trigger = yes
			}
			any_courtier = {
				martial_authority_2050_can_be_right_hand_person_trigger = yes
			}
		}
	}

	weight_multiplier = {
		base = 1
	}

	immediate = {
		add_character_flag = {
			flag = had_event_martial_authority_2050
			years = 5
		}

		every_vassal = {
			limit = {
				martial_authority_2050_can_be_right_hand_person_trigger = yes
			}
			add_to_temporary_list = potential_right_hand_people
		}
		every_knight = {
			limit = {
				martial_authority_2050_can_be_right_hand_person_trigger = yes
			}
			add_to_temporary_list = potential_right_hand_people
		}
		every_courtier = {
			limit = {
				martial_authority_2050_can_be_right_hand_person_trigger = yes
			}
			add_to_temporary_list = potential_right_hand_people
		}

		ordered_in_list = {
			list = potential_right_hand_people

			order_by = {
				value = {

					add = 1

					# More likely to pick somebody who has some amount of standing in your realm...
					if = {
						limit = {
							is_vassal_of = root
						}
						add = 15
						add = {
							add = highest_held_title_tier
							multiply = 2
						}
					}
					else_if = {
						limit = {
							is_knight_of = root
						}
						add = 10
					}

					# ...but less likely to pick somebody who is already very important.
					if = {
						limit = {
							OR = {
								is_councillor_of = root
								is_consort_of = root
								is_player_heir_of = root
							}
						}
						add = -25
					}
					else_if = {
						limit = {
							OR = {
								is_powerful_vassal_of = root
								is_player_heir_of = root
							}
						}
						add = -10
					}

					# More likely to pick someone who has respect for the 'rule of law'
					if = {
						limit = { has_trait = just }
						add = 10
					}
					if = {
						limit = { has_trait = content }
						add = 5
					}
					if = {
						limit = { has_trait = diligent }
						add = 5
					}
					if = {
						limit = { has_trait = arrogant }
						add = -5
					}
					if = {
						limit = { has_trait = fickle }
						add = -5
					}

					# More likely to pick someone who is friendly to you.
					if = {
						limit = {
							opinion = {
								target = root
								value >= 10
							}
						}
						add = 10
					}
					if = {
						limit = {
							opinion = {
								target = root
								value >= 25
							}
						}
						add = 5
					}

					# But not too friendly, otherwise the event is kind of inconsequential.
					if = {
						limit = {
							opinion = {
								target = root
								value >= 80
							}
						}
						add = -10
					}

					# Trait compatibility has a large impact on who gets picked.
					add = {
						add = 0
						if = {
							limit = {
								trait_compatibility = {
									target = root
									value >= high_positive_trait_compatibility
								}
							}
							add = 50
						}
						else_if = {
							limit = {
								trait_compatibility = {
									target = root
									value >= medium_positive_trait_compatibility
								}
							}
							add = 35
						}
						else_if = {
							limit = {
								trait_compatibility = {
									target = root
									value >= low_positive_trait_compatibility
								}
							}
							add = 15
						}
						else_if = {
							limit = {
								trait_compatibility = {
									target = root
									value >= low_negative_trait_compatibility
								}
							}
							add = -10
						}
						else = {
							add = -30
						}

						# Attraction Multiplier
						if = {
							limit = {
								root = {
									is_attracted_to_gender_of = this
								}
								is_attracted_to_gender_of = root
							}
							multiply = 1.5
						}
					}

					# Slightly more likely to pick someone close to you in age.
					if = {
						limit = {
							age < age_compared_to_root_plus_ten
							age > age_compared_to_root_minus_ten
						}
						add = 5
					}
				}
			}
			save_scope_as = right_hand_person
		}

		# Save variables (for localization and death events).
		set_variable = {
			name = right_hand_person
			value = scope:right_hand_person
		}
		scope:right_hand_person = {
			set_variable = {
				name = is_right_hand_person_of
				value = root
			}
		}		

		# Save other relevant scopes.
		if = {
			limit = {
				exists = cp:councillor_marshal
			}
			cp:councillor_marshal = {
				save_scope_as = marshal
			}
		}
	}

	option = {
		name = martial_authority.2050.a

		# Gain semi-permanent character modifier (until RHP is unable or unwilling to continue serving you).
		add_character_modifier = {
			modifier = martial_authority_2050_right_hand_person_modifier
		}

		# Mutual Opinion Increase with RHM.
		scope:right_hand_person = {
			add_opinion = {
				modifier = pleased_opinion
				target = root
				opinion = 10
			}

		}
		hidden_effect = {
			add_opinion = {
				modifier = pleased_opinion
				target = scope:right_hand_person
				opinion = 10
			}
			if = {
				limit = {
					NOT = { has_relation_potential_friend = scope:right_hand_person}
				}	
				set_relation_potential_friend = scope:right_hand_person
			}
		}
		primary_title = { #Scope change here to avoid tooltip grouping.
			custom_tooltip = martial_authority.2050.a.tt
		}

		stress_impact = {
			shy = medium_stress_gain
			paranoid = medium_stress_gain
		}

		trigger_event = {
			id = martial_authority.2051
			years = { 2 3 }
		}
	}

	option = {
		name = martial_authority.2050.b
		trigger = {
			exists = scope:marshal
		}

		# Larger Mutual opinion increase with Marshal.
		scope:marshal = {
			add_opinion = {
				modifier = trust_opinion
				target = root
				opinion = 20
			}
		}
		hidden_effect = {
			add_opinion = {
				modifier = trust_opinion
				target = scope:marshal
				opinion = 20
			}
		}

		# Remove unused event variables
		remove_variable = right_hand_person
		scope:right_hand_person = {
			remove_variable = is_right_hand_person_of
		}		
	}
	
	option = {
		name = martial_authority.2050.c

		# Gain large amount of Prestige at the cost of Stress.
		add_prestige = major_prestige_gain
		stress_impact = {
			base = medium_stress_gain
			diligent = minor_stress_loss
			lazy = minor_stress_gain
			humble = minor_stress_gain
		}

		# Remove unused event variables
		remove_variable = right_hand_person
		scope:right_hand_person = {
			remove_variable = is_right_hand_person_of
		}
	}
}

# Become friends with your Right-Hand Person.
martial_authority.2051 = {
	type = character_event
	title = martial_authority.2051.t
	desc = martial_authority.2051.desc
	left_portrait = scope:right_hand_person
	theme = martial_authority_focus
	
	trigger = {
		exists = var:right_hand_person
		var:right_hand_person = {
			is_alive = yes
			is_imprisoned = no
			opinion = {
				target = root
				value >= 15
			}
		}
		can_set_relation_friend_trigger = { CHARACTER = var:right_hand_person }
		NOR = {
			has_relation_lover = var:right_hand_person
			has_relation_soulmate = var:right_hand_person
		}
	}

	weight_multiplier = {
		base = 1
	}

	immediate = {
		# Transition right-hand person variable into an event scope.
		var:right_hand_person = {
			save_scope_as = right_hand_person
		}
	}

	option = {
		name = martial_authority.2051.a
		set_relation_friend = scope:right_hand_person
	}

	option = {
		name = martial_authority.2051.b
		trigger = {
			can_set_relation_lover_trigger = { CHARACTER = var:right_hand_person }
		}

		set_relation_lover = scope:right_hand_person
	}
	
	option = {
		name = martial_authority.2051.c
		add_prestige = minor_prestige_gain
		scope:right_hand_person = {
			add_opinion = {
				modifier = respect_opinion
				target = root
				opinion = 10
			}
		}
	}
}


# Right-Hand Person Imprisoned (by you)
martial_authority.2052 = {
	hidden = yes
	
	trigger = {
		exists = var:right_hand_person
	}

	immediate = {
	
	}
}

# Right-Hand Person Imprisoned (by someone else)
martial_authority.2053 = {
	hidden = yes
	
	trigger = {

	}

	immediate = {
	
	}
}

# Right-Hand Person Released from Prison
martial_authority.2054 = {
	hidden = yes
	
	trigger = {

	}

	immediate = {
	
	}
}

# Right-Hand Person Dies
martial_authority.2055 = {
	hidden = yes
	
	trigger = {

	}

	immediate = {
	
	}
}

# Right-Hand Person Leaves Service
martial_authority.2056 = {
	hidden = yes
	
	trigger = {

	}

	immediate = {
	
	}
}

# I Die (Cleans up variables on Right-Hand Person)
martial_authority.2057 = {
	hidden = yes
	
	trigger = {

	}

	immediate = {
	
	}
}

################################################################################################################################
################################################################################################################################

#############################
# AUTHORITY: SPECIAL EVENTS #
#############################

namespace = martial_authority_special

##############################
# Soldier & Officer fighting # by Mathilda Bjarnehed
##############################

martial_authority_special.1100 = {
	type = character_event
	title = martial_authority_special.1100.t
	desc = {
		desc = martial_authority_special.1100.start.desc
		first_valid = {
			desc = martial_authority_special.1100.heavy_infantry.desc
			desc = martial_authority_special.1100.cavalry.desc
			desc = martial_authority_special.1100.archer.desc
			desc = martial_authority_special.1100.skirmisher.desc
			desc = martial_authority_special.1100.pikemen.desc
		}
		desc = martial_authority_special.1100.end.desc
	}
	
	theme = martial_authority_focus
	override_background = {
		event_background = alley_night
	}

	left_portrait = {
		character = scope:officer
		animation = anger
	}

	trigger = {
		has_focus = martial_authority_focus
		NOT = { has_character_flag = had_event_martial_authority_special_1100 }
		num_of_relation_soldier_friend = 0
		any_knight = {
			basic_is_available_ai = yes
			ai_compassion <= low_positive_ai_value
		}
		OR = {
			exists = capital_province
			exists = location
		}
	}

	weight_multiplier = {
		base = 1
	}

	immediate = {
		hidden_effect = {
			add_character_flag = {
				flag = is_in_martial_special_event
				days = 200
			}
			add_character_flag = had_event_martial_authority_special_1100
			#Pick an officer
			random_knight = {
				limit = {
					basic_is_available_ai = yes
					ai_compassion <= low_positive_ai_value
				}
				weight = {
					base = 1
					modifier = {
						add = {
							value = ai_compassion
							multiply = -2
							if = {
								limit = { ai_compassion <= medium_negative_ai_value }
								multiply = 3
							}
						}
					}
					modifier = {
						add = {
							value = ai_boldness
							multiply = 1
						}
					}
				}
				save_scope_as = officer
			}
			#Create a hidden soldier
			if = {
				limit = {
					exists = root.capital_province
				}
				create_character = {
					gender_female_chance = root_soldier_female_chance
					location = root.capital_province
					template = soldier_friend_character
					save_scope_as = soldier_friend
					dynasty = generate
				}
			}
			else = {
				create_character = {
					gender_female_chance = root_soldier_female_chance
					location = root.location
					template = soldier_friend_character
					save_scope_as = soldier_friend
					dynasty = generate
				}
			}
		}
	}
	
	#Defend the soldier (fist fight)
	option = {
		name = martial_authority_special.1100.a

		duel = {
			skill = prowess
			target = scope:officer
			7 = {		
				compare_modifier = {
					value = scope:duel_value
					multiplier = 1
					min = -14
				}
				desc = martial_authority_special.1100.a.success.tt
				
				show_as_tooltip = {
					add_martial_lifestyle_perk_points = 1
				}
				trigger_event = martial_authority_special.1101
			}
			10 = {		
				compare_modifier = {
					value = scope:duel_value
					multiplier = -0.7
					min = -9
				}
				desc = martial_authority_special.1100.a.failure.tt
				trigger_event = martial_authority_special.1102
				show_as_tooltip = {
					martial_authority_special_1100_a_failure_effect = yes
				}
			}
		}

		stress_impact = {
			lazy = minor_stress_impact_gain
			craven = medium_stress_impact_gain
			sadistic = minor_stress_impact_gain
		}

		ai_chance = {
			base = 100
			ai_boldness_target_modifier = { VALUE = 50 }
			ai_compassion_target_modifier = { VALUE = 50 }
			modifier = {
				factor = 0
				has_trait_rank = {
					trait = wounded
					rank >= 3
				}
			}
		}
	}

	#Inspiring speech
	option = {
		name = martial_authority_special.1100.b
		trigger = { diplomacy >= high_skill_rating }
		skill = diplomacy
		show_as_tooltip = {
			add_martial_lifestyle_perk_points = 1
		}
		reverse_add_opinion = {
			target = scope:officer
			modifier = respect_opinion
			opinion = low_positive_opinion
		}

		trigger_event = martial_authority_special.1103

		ai_chance = {
			base = 100
			ai_compassion_target_modifier = { VALUE = 50 }
		}

		stress_impact = {
			shy = minor_stress_impact_gain
			sadistic = minor_stress_impact_gain
		}
	}
	
	#Punish them both
	option = {
		name = martial_authority_special.1100.c

		add_dread = medium_dread_gain

		scope:officer = {
			increase_wounds_no_death_effect = { REASON = beaten }

			add_opinion = {
				target = root
				modifier = cruelty_opinion
				opinion = low_negative_opinion
			}
		}

		hidden_effect = {
			remove_character_flag = is_in_martial_special_event
		}

		ai_chance = {
			base = 50
			ai_compassion_target_modifier = { VALUE = -100 }
		}

		stress_impact = {
			compassionate = medium_stress_impact_gain
		}
	}

	#Claim the idea as your own
	option = {
		name = martial_authority_special.1100.d

		add_character_modifier = {
			modifier = innovative_strategy_modifier
			years = 15
		}

		hidden_effect = {
			remove_character_flag = is_in_martial_special_event
		}

		stress_impact = {
			honest = medium_stress_impact_gain
			compassionate = minor_stress_impact_gain
		}

		ai_chance = {
			base = 50
			ai_honor_target_modifier = { VALUE = -60 }
			ai_compassion_target_modifier = { VALUE = -40 }
		}
	}
}

#You won the duel
martial_authority_special.1101 = {
	type = character_event
	title = martial_authority_special.1100.t
	desc = {
		desc = martial_authority_special.1101.desc
		desc = martial_authority_special.1101.end.desc
	}
	
	theme = martial_authority_focus
	override_background = {
		event_background = alley_night
	}

	left_portrait = {
		character = scope:officer
		animation = shame
	}
	right_portrait = {
		character = scope:soldier_friend
		animation = happiness
	}

	immediate = {
		martial_authority_special_1100_soldier_friend_effects_effect = yes
	}

	#Use their strategy
	option = {
		name = martial_authority_special.1101.a
		add_character_modifier = {
			modifier = innovative_strategy_modifier
			years = 15
		}
		add_martial_lifestyle_xp = medium_lifestyle_xp
	}

	#Talk it over
	option = {
		name = martial_authority_special.1101.b
		add_martial_lifestyle_perk_points = 1
	}
	
	after = {
		hidden_effect = {
			remove_character_flag = is_in_martial_special_event
		}
	}
}

#Duel lost
martial_authority_special.1102 = {
	type = character_event
	title = martial_authority_special.1100.t
	desc = martial_authority_special.1102.desc
	
	theme = martial_authority_focus
	override_background = {
		event_background = alley_night
	}

	left_portrait = {
		character = scope:officer
		animation = dismissal
	}

	immediate = {
		martial_authority_special_1100_a_failure_effect = yes
	}

	option = {
		name = martial_authority_special.1102.a
		add_character_modifier = {
			modifier = fought_a_seasoned_warrior
			days = 1825
		}
		add_martial_lifestyle_xp = minor_lifestyle_xp
	}

	after = {
		hidden_effect = {
			remove_character_flag = is_in_martial_special_event
		}
	}
}

#Your speech worked
martial_authority_special.1103 = {
	type = character_event
	title = martial_authority_special.1100.t
	desc = {
		desc = martial_authority_special.1103.desc
		desc = martial_authority_special.1101.end.desc
	}
	theme = martial_authority_focus
	override_background = {
		event_background = alley_night
	}

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

	immediate = {
		martial_authority_special_1100_soldier_friend_effects_effect = yes
	}

	#Use their strategy
	option = {
		name = martial_authority_special.1101.a
		add_character_modifier = {
			modifier = innovative_strategy_modifier
			years = 15
		}
		add_martial_lifestyle_xp = medium_lifestyle_xp
	}

	#Talk it over
	option = {
		name = martial_authority_special.1101.b
		add_martial_lifestyle_perk_points = 1
	}
	
	after = {
		hidden_effect = {
			remove_character_flag = is_in_martial_special_event
		}
	}
}

######################
# Deserting Soldiers # by Linnéa Thimrén
######################

#You see deserters sneaking away into the night, apprehend or let go?
martial_authority_special.1501 = {
	type = character_event
	title = martial_authority_special.1501.t
	desc = martial_authority_special.1501.desc
	
	theme = martial_authority_focus
	override_background = {
		event_background = alley_night
	}

	left_portrait = scope:deserting_soldier
	
	trigger = {
		has_focus = martial_authority_focus
		NOT = { has_character_flag = had_event_martial_authority_special_1501 }
		NOT = { has_character_flag = is_in_martial_special_event }
	}

	weight_multiplier = {
		base = 1
	}

	immediate = {
		add_character_flag = {
			flag = is_in_martial_special_event
			days = 100
		}
		add_character_flag = had_event_martial_authority_special_1501
		if = {
			limit = {
				any_relation = {
					type = soldier_friend
					is_councillor = no
				}
			}
			hidden_effect = {
				random = {
					chance = 25
					random_relation = {
						type = soldier_friend
						limit = {
							is_councillor = no
						}
						save_scope_as = deserting_soldier # Oh no, your soldier_friend is among the deserters!
					}
				}
			}
		}
		if = {
			limit = {
				NOT = { exists = scope:deserting_soldier }
			}
			random_courtier_or_guest = {
				limit = {
					NOT = { this = root }
					is_councillor = no
					is_close_family_or_spouse_of_root_trigger = no
					is_ai = yes
					is_adult = yes
					is_knight_of = root
				}
				save_scope_as = deserting_soldier
			}
		}
		if = {
			limit = {
				NOT = { exists = scope:deserting_soldier }
			}
			create_character = {
				employer = root
				age = { 20 40 }
				martial = { 10 12 }
				trait = craven
				trait = education_martial_2
				culture = root.culture
				faith = root.faith
				gender_female_chance = root_soldier_female_chance
				save_scope_as = deserting_soldier
			}
		}
	}

	option = {
		name = martial_authority_special.1501.a
		custom_tooltip = martial_lifestyle_perk_indication
		duel = {
			skill = martial
			target = scope:deserting_soldier
			20 = {	
				desc = martial_authority_special.1501.a.success
				compare_modifier = {
					value = scope:duel_value
					multiplier = 1
					min = 1
				}
				trigger_event = {
					id = martial_authority_special.1502
					days = { 6 12 }
				}
			}
			5 = {
				desc = martial_authority_special.1501.a.failure
				compare_modifier = {
					value = scope:duel_value
					multiplier = -0.25
					min = -4
				}
				add_character_flag = {
					flag = scuffle_lost
					days = 50
				}
				if = {
					limit = {
						has_trait_rank = {
							trait = wounded
							rank < 1
						}
					}
					send_interface_toast = {
						type = event_toast_effect_bad
						title = martial_authority_special.1501.a.failure
						left_icon = root
						increase_wounds_effect = { REASON = training_accident }
					}
				}
				else_if = {
					limit = {
						has_trait_rank = {
							trait = wounded
							rank >= 1
						}
					}
					send_interface_toast = {
						type = event_toast_effect_bad
						title = martial_authority_special.1501.a.failure
						left_icon = root
						add_prestige = medium_prestige_loss
					}
				}
			}
		}
		
		stress_impact = {
			compassionate = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
		}
	}

	option = {
		name = martial_authority_special.1501.b
		scope:deserting_soldier = {
			hidden_effect = { # removes soldier_friend and adds them as a friend so that they will not be used in future warfare events
				remove_relation_soldier_friend = root
				if = {
					limit = {
						can_set_relation_friend_trigger = { CHARACTER = root }
					}
					set_relation_friend = root
				}
			}
			add_opinion = {
				target = root
				modifier = was_spared
			}
		}
		if = {
		  	limit = {
		  		can_add_hook = {
					type = favor_hook
					target = scope:deserting_soldier
				}
		  	}
			add_hook = {
				type = favor_hook
				target = scope:deserting_soldier
			}
		}
		if = {
			limit = {
				scope:deserting_soldier = { is_courtier_of = root }
			}
			remove_courtier_or_guest = scope:deserting_soldier
		}
		else_if = {
			limit = {
				 scope:deserting_soldier = { is_foreign_court_guest_of = root }
			}
			scope:deserting_soldier = { return_to_court = yes }
		}
		add_martial_lifestyle_xp = miniscule_lifestyle_xp
		stress_impact = {
			callous = minor_stress_impact_gain
			wrathful = minor_stress_impact_gain
			diligent = minor_stress_impact_gain
			brave = minor_stress_impact_gain
			vengeful = minor_stress_impact_gain
		}
		ai_chance = {
			base = 0
			modifier = {
				add = 40
				has_trait = compassionate
			}
		}
	}
}

#The deserters are apprehended, how do you proceed?
martial_authority_special.1502 = {
	type = character_event
	title = martial_authority_special.1501.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					has_character_flag = scuffle_lost
				}
				desc = martial_authority_special.1502.desc_scuffle_lost
			}
			desc = martial_authority_special.1502.desc_scuffle
		}
		desc = martial_authority_special.1502.desc
	}
	
	theme = martial_authority_focus
	override_background = {
		event_background = alley_night
	}
	left_portrait = scope:deserting_soldier
	
	trigger = {
		scope:deserting_soldier = {
			is_alive = yes
		}
	}

	immediate = {
	}

	option = {
		name = martial_authority_special.1502.a
		add_dread = medium_dread_gain
		show_as_tooltip = {
			add_martial_lifestyle_perk_points = 1
		}
		add_character_modifier = {
			modifier = upset_troops_modifier
			days = 1825
		}
		scope:deserting_soldier = {
			death = {
				killer = root
				death_reason = death_punishment
			}
		}
		add_character_flag = won_execution
		trigger_event = {
			id = martial_authority_special.1503
			days = { 3 10 }
		}
		stress_impact = {
			temperate = minor_stress_impact_gain
			calm = minor_stress_impact_gain
			just = minor_stress_impact_gain
			vengeful = minor_stress_impact_gain
			compassionate = minor_stress_impact_gain
			forgiving = minor_stress_impact_gain
		}
		ai_chance = {
			base = 30
			modifier = {
				add = 20
				OR = {
					has_trait = wrathful
					has_trait = callous
					has_trait = arrogant
				}
			}
		}
	}

	option = {
		name = martial_authority_special.1502.b
		random_list = {
			80 = {
				show_as_tooltip = {
					add_martial_lifestyle_perk_points = 1
				}
				add_character_flag = won_latrine
				trigger_event = {
					id = martial_authority_special.1503
					days = { 3 10 }
				}
			}
			20 = {
				custom_tooltip = martial_authority_special.1502.b.tt
				add_character_flag = lost_latrine
				trigger_event = {
					id = martial_authority_special.1504
					days = { 3 10 }
				}
			}
		}
		stress_impact = {
			sadistic = minor_stress_impact_gain
		}
		ai_chance = {
			base = 35
			modifier = {
				add = 20
				OR = {
					has_trait = just
					has_trait = diligent
				}
			}
		}
	}
	
	option = {
		name = martial_authority_special.1502.c
		duel = {
			skill = diplomacy
			value = decent_skill_rating
			20 = {		
				compare_modifier = {
					value = scope:duel_value
					multiplier = 0.5
					min = -19
				}
				show_as_tooltip = {
					add_martial_lifestyle_perk_points = 1
				}
				add_character_flag = won_diplomacy
				trigger_event = {
					id = martial_authority_special.1503
					days = { 3 10 }
				}
			}
			5 = {		
				compare_modifier = {
					value = scope:duel_value
					multiplier = -0.25
					min = -4
				}
				custom_tooltip = martial_authority_special.1502.c.tt
				add_character_flag = lost_diplomacy
				trigger_event = {
					id = martial_authority_special.1504
					days = { 3 10 }
				}
			}
		}
		stress_impact = {
			wrathful = minor_stress_impact_gain
			sadistic = minor_stress_impact_gain
			vengeful = minor_stress_impact_gain
		}
		ai_chance = {
			base = 35
			modifier = {
				add = 20
				has_trait = gregarious
			}
			compare_modifier = {
				value = diplomacy
				target = root
				step = 2
				multiplier = 4
			}
		}
	}
	option = {
		name = martial_authority_special.1502.d
		trigger = {
			has_trait = sadistic
		}
		trait = sadistic
		add_dread = major_dread_gain
		add_martial_lifestyle_xp = minor_lifestyle_xp
		scope:deserting_soldier = {
			death = {
				killer = root
				death_reason = death_punishment
			}
		}
		stress_impact = {
			just = minor_stress_impact_gain
			compassionate = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
		}
	}
}

#END - good outcome
martial_authority_special.1503 = {
	type = character_event
	title = martial_authority_special.1501.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					has_character_flag = won_execution
				}
				desc = martial_authority_special.1503.desc_execution
			}
			triggered_desc = {
				trigger = {
					has_character_flag = won_latrine
				}
				desc = martial_authority_special.1503.desc_latrine
			}
			triggered_desc = {
				trigger = {
					has_character_flag = won_diplomacy
				}
				desc = martial_authority_special.1503.desc_diplomacy
			}
		}
	}
	
	theme = martial_authority_focus
	override_background = {
		event_background = armory
	}
	left_portrait = scope:deserting_soldier

	immediate = {
		if = {
			limit = {
				has_character_flag = won_execution
			}
			custom_tooltip = martial_authority_special.1503.a.tt_execution
		}
	}

	option = {
		name = martial_authority_special.1503.a
		add_martial_lifestyle_perk_points = 1
	}
	after = {
		remove_character_flag = is_in_martial_special_event
		remove_character_flag = won_execution
		remove_character_flag = won_latrine
		remove_character_flag = won_diplomacy
		remove_character_flag = scuffle_lost
	}
}

#END - bad outcome
martial_authority_special.1504 = {
	type = character_event
	title = martial_authority_special.1501.t
	desc = {
		desc = martial_authority_special.1504.desc_opening
		first_valid = {
			triggered_desc = {
				trigger = {
					has_character_flag = lost_latrine
				}
				desc = martial_authority_special.1504.desc_latrine
			}
			triggered_desc = {
				trigger = {
					has_character_flag = lost_diplomacy
				}
				desc = martial_authority_special.1504.desc_diplomacy
			}
		}
	}
	
	theme = martial_authority_focus
	override_background = {
		event_background = armory
	}
	left_portrait = scope:deserting_soldier
	

	immediate = {
	}

	option = {
		name = martial_authority_special.1504.a
		if = {
			limit = {
				has_character_flag = lost_latrine
			}
			add_character_modifier = {
				modifier = hightened_troop_morale_modifier
				days = 1825
			}
		}
		if = {
			limit = {
				has_character_flag = lost_diplomacy
			}
			add_character_modifier = {
				modifier = gave_inspiring_speech
				days = 1825
			}
		}
	}
	after = {
		remove_character_flag = is_in_martial_special_event
		remove_character_flag = lost_latrine
		remove_character_flag = lost_diplomacy
		remove_character_flag = scuffle_lost
	}
}


##########################################################################
# Displaying/Teaching Authority to Someone (Find a way to impress someone)
##########################################################################
# by Milla Isaksson
#####################

scripted_trigger martial_authority_special_friend_trigger = {	
	OR = {
		AND = {
			OR = {
				has_trait = overseer
				AND = {
					exists = root.var:right_hand_person
					this = root.var:right_hand_person
				}
			}
			is_available_ai_adult = yes
		}
		AND = {
			is_child_of = ROOT
			age >= 10
			is_available_ai = yes
		}
	}
}

martial_authority_special.3000 = {
	type = character_event
	title = martial_authority_special.3000.t
	desc = martial_authority_special.3000.desc

	
	left_portrait = scope:martial_authority_friend
	theme = martial_authority_focus
	

	trigger = {
		NOT = { has_character_flag = had_event_martial_authority_3000 } #Can only happen once every 5 years
		OR = {
			any_vassal = {
				martial_authority_special_friend_trigger = yes
			}
			any_knight = {
				martial_authority_special_friend_trigger = yes
			}
			any_courtier_or_guest = {
				martial_authority_special_friend_trigger = yes
			}
		}

		exists = capital_province
	}
	
	immediate = {
		add_character_flag = {
			flag = had_event_martial_authority_3000
			days = 1825
		}

		if = {
			limit = {
				NOT = {
					any_relation = {
						type = friend
						lifestyle_friend_trigger = { CHARACTER = root FOCUS = martial_authority_focus }
					}
				}
			}
			potential_lifestyle_friend_saving_effect = { FOCUS = martial_authority_focus SCOPE_NAME = martial_authority_friend }

		}
		else = {
			random_relation = {
				type = friend
				limit = {
					lifestyle_friend_trigger = { CHARACTER = root FOCUS = martial_authority_focus }
					exists = root.var:right_hand_person
					this = root.var:right_hand_person
				}
				alternative_limit = {
					lifestyle_friend_trigger = { CHARACTER = root FOCUS = martial_authority_focus }
				}
				save_scope_as = martial_authority_friend
			}
		}
	}

	option = { # Talk about the importance of communication
		name = martial_authority_special.3000.a
		
		add_martial_lifestyle_xp = minor_lifestyle_xp
		
		reverse_add_opinion = {
			target = scope:martial_authority_friend
			modifier = respect_opinion
			opinion = low_positive_opinion
		}		

		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_honor = 0.5
			}
			modifier = {
				factor = 1.5
				has_trait_extroverted_trigger = yes
			}
		}
	}

	option = { # Take a walk among your soldiers
		name = martial_authority_special.3000.b

		add_martial_lifestyle_xp = minor_lifestyle_xp
		
		capital_province = {
			add_province_modifier = { modifier = respected_figurehead years = 2 }
		}

		ai_chance = {
			base = 100
			modifier = {
				factor = 1.5
				has_trait_benevolent_trigger = yes
			}
		}
	}
}

