namespace = ep3_laamps

####
# ep3_laamps.0001-0003 - Become Adventurer - Conquest
# ep3_laamps.0010-0012 - Become Adventurer - Succession
# ep3_laamps.0020-0021 - Become Adventurer - Exile
# ep3_laamps.0030-0032 - Become Adventurer - Voluntary
# ep3_laamps.0040-0042 - Become Adventurer - Revocation
# ep3_laamps.0050-0051 - Become Adventurer - Runaway
# ep3_laamps.0100-0102 - Become Landed - Purchase
# ep3_laamps.0200-0201 - Become Landed - Sponsored Invasion
# ep3_laamps.0300-0302 - Become Landed - Negotiated
# ep3_laamps.0400-0412 - Become Landed - Seize Realm
##
# 5000-5998 - Generalist LAAMP events
###

#  //\         /\\
# || * \ . . / * ||
#  \\____\X/____//
#   / *  /O\  * \
#   \__/  "  \__/
#      BRÖTHER
# I CRAVE THE LAAMP

scripted_effect adventurer_prestige_reset_effect = {
	hidden_effect = {
		#Save Prestige
		save_scope_value_as = {
			name = prestige_amount
			value = {
				value = prestige
				add = -100
			}
		}
		#Invert it, then take it away
		add_prestige = {
			value = scope:prestige_amount
			multiply = -1
		}
		#Take away 3 prestige levels
		add_prestige_level = -3
	}
	# Tooltips
	custom_tooltip = lose_all_prestige_tt
	custom_tooltip = lose_all_prestige_level_tt
}

##################################################
# Become Adventurer - Conquest
# by Joe Parkin
# 0001-0002
##################################################

# Big comeback

scripted_trigger ep3_laamp_conquest_title_trigger = {
	OR = {
		recent_history = { type = conquest days = 1 }
		recent_history = { type = conquest_holy_war days = 1 }
		recent_history = { type = conquest_claim days = 1 }
		recent_history = { type = conquest_populist days = 1 }
	}
	previous_holder ?= scope:adventurer
}

# Conquest loser event
ep3_laamps.0001 = {
	type = character_event
	window = fullscreen_event
	title = {
		desc = {
			first_valid = {
				triggered_desc = {
					trigger = { is_female = yes }
					desc = ep3_laamps.0001.t.female
				}
				desc = ep3_laamps.0001.t.male
			}
		}
	}
	desc = {
		desc = ep3_laamps.0001.intro
		first_valid = {
			triggered_desc = {
				trigger = { exists = scope:war_memory }
				desc = ep3_laamps.0001.memory
			}
			desc = ep3_laamps.0001.fallback
		}
		desc = ep3_laamps.0001.desc
	}
	theme = realm
	left_portrait = {
		character = root
		animation = stress
	}
	lower_left_portrait = scope:alt_1
	lower_center_portrait = scope:alt_2
	lower_right_portrait = scope:alt_3
	override_background = { reference = ep3_fullscreen_adventurer_negative }
	cooldown = { days = 5 }

	trigger = {
		is_ai = no
		NOT = { has_character_flag = become_laamp_event_cooldown }
	}

	immediate = {
		play_music_cue = adventure_begin_cue
		add_character_flag = {
			flag = become_laamp_event_cooldown
			days = 5
		}
		clear_saved_scope = lost_primary_title
		# Save highest lost title for loc
		ordered_in_list = {
			list = target_titles
			limit = { ep3_laamp_conquest_title_trigger = yes }
			order_by = tier
			position = 0
			save_scope_as = lost_primary_title
		}
		if = {
			limit = {
				NOT = { exists = scope:lost_primary_title }
				exists = scope:conquered
			}
			clear_saved_scope = lost_primary_title
			scope:conquered = { save_scope_as = lost_primary_title }
		}
		# Find alternative rulers to play as
		find_playable_relatives_effect = yes
		# Portrait scopes
		if = {
			limit = {
				NOR = {
					exists = scope:alt_3
					scope:alt_1 ?= scope:winner
					scope:alt_2 ?= scope:winner
				}
			}
			scope:winner = { save_scope_as = alt_3 }
		}
		# Make Adventurer
		create_landless_adventurer_title_effect = {
			REASON = flag:conquest
			FLAVOR_CHAR = scope:attacker
		}
		adventurer_prestige_reset_effect = yes
	}

	option = {
		name = ep3_laamps.0001.a
		add_unpressed_claim = scope:lost_primary_title
		add_internal_flag = special
		if = {
			limit = {
				NOT = { has_relation_rival = scope:winner }
			}
			set_relation_rival = {
				target = scope:winner
				reason = rival_conquered_me
			}
		}
		scope:winner = { trigger_event = ep3_laamps.0003 }
	}
	option = {
		name = ep3_laamps.0001.b
		trigger = { exists = scope:alt_1 }
		laamp_switch_playable_character_effect = { NEW_CHARACTER = scope:alt_1 }
	}
	option = {
		name = ep3_laamps.0001.c
		trigger = { exists = scope:alt_2 }
		laamp_switch_playable_character_effect = { NEW_CHARACTER = scope:alt_2 }
	}
	option = {
		name = ep3_laamps.0001.d
		trigger = {
			scope:alt_3 ?= { playable_relative_trigger = yes }
		}
		laamp_switch_playable_character_effect = { NEW_CHARACTER = scope:alt_3 }
	}
	option = {
		name = ep3_laamps.0001.e
		laamp_game_over_option_effect = yes
	}
}

# Setup event
ep3_laamps.0002 = {
	type = character_event
	hidden = yes

	trigger = {
		has_ep3_dlc_trigger = yes
		is_valid_for_laampdom = yes
	}

	on_trigger_fail = {
		if = { # Ensures depose_effect always deposes, while other event origins do not
			limit = { exists = scope:allow_imprisoned_landless }
			depose = yes
		}
	}

	immediate = {
		save_scope_as = adventurer
		# AI chance
		if = {
			limit = {
				is_ai = yes
				ai_can_valid_to_create_laamp_trigger = yes
			}
			if = {
				limit = { is_landed = yes }
				depose = yes
			}
			save_scope_value_as = {
				name = ai_laamp_chance
				value = ep3_laamp_chance_score_value
			}
			random = {
				chance = scope:ai_laamp_chance
				# Plus for our memory variable.
				clear_saved_scope = lost_primary_title
				ordered_in_list = {
					list = target_titles
					order_by = tier
					position = 0
					save_scope_as = lost_primary_title
				}
				if = {
					limit = { exists = var:deposed_primary_title }
					create_landless_adventurer_title_effect = {
						REASON = flag:deposition
						FLAVOR_CHAR = scope:attacker
					}
				}
				else = {
					create_landless_adventurer_title_effect = {
						REASON = flag:conquest
						FLAVOR_CHAR = scope:attacker
					}
				}
				scope:winner = { trigger_event = ep3_laamps.0003 }
			}
		}
		# Player event
		else = {
			if = {
				limit = {
					scope:new_holder ?= {
						any_held_title = { ep3_laamp_conquest_title_trigger = yes }
					}
				}
				trigger_event = { id = ep3_laamps.0001 }
			}
			else_if = { # Land already taken (e.g. by a war)
				limit = { is_landed = no }
				trigger_event = { id = ep3_laamps.0004 }
			}
			else = { # Still have land (e.g. in an event)
				trigger_event = { id = ep3_laamps.0005 }
			}
		}
	}
}

# Winner event
ep3_laamps.0003 = {
	type = letter_event
	opening = ep3_laamps.0003.opening
	desc = ep3_laamps.0003.desc
	sender = scope:adventurer

	trigger = { is_ai = no }

	immediate = {
		if = {
			limit = {
				NOT = { has_relation_rival = scope:adventurer }
			}
			set_relation_rival = {
				target = scope:adventurer
				reason = rival_conquered_me
			}
		}
		scope:adventurer = { create_landless_adventurer_title_tooltip_effect = yes }
	}

	option = {
		name = ep3_laamps.0003.a
	}
}

# Deposition loser event
ep3_laamps.0004 = {
	type = character_event
	window = fullscreen_event
	title = {
		desc = {
			first_valid = {
				triggered_desc = {
					trigger = { is_female = yes }
					desc = ep3_laamps.0001.t.female
				}
				desc = ep3_laamps.0001.t.male
			}
		}
	}
	desc = ep3_laamps.0004.desc
	theme = realm
	left_portrait = {
		character = root
		animation = stress
	}
	lower_left_portrait = scope:alt_1
	lower_center_portrait = scope:alt_2
	lower_right_portrait = scope:alt_3
	override_background = { reference = ep3_fullscreen_adventurer_negative }

	trigger = {
		is_ai = no
		exists = var:deposed_primary_title
		NOT = { has_character_flag = become_laamp_event_cooldown }
	}

	immediate = {
		play_music_cue = adventure_begin_cue
		add_character_flag = {
			flag = become_laamp_event_cooldown
			days = 5
		}
		clear_saved_scope = lost_primary_title
		var:deposed_primary_title ?= {
			# Save highest lost title for loc
			save_scope_as = conquered
			# And for memory variables.
			save_scope_as = lost_primary_title
			save_scope_as = heir
		}
		# Create Adventurer
		hidden_effect = {
			create_landless_adventurer_title_effect = {
				REASON = flag:deposition
				FLAVOR_CHAR = scope:attacker
			}
		}
		# Find alternative rulers to play as
		find_playable_relatives_effect = yes
		# Portrait scopes
		if = {
			limit = {
				NOT = { exists = scope:alt_3 }
			}
			if = {
				limit = { exists = scope:conquered.holder }
				scope:conquered.holder = { save_scope_as = alt_3 }
			}
			else_if = {
				limit = {
					NOR = {
						scope:alt_1 ?= scope:winner
						scope:alt_2 ?= scope:winner
					}
				}
				scope:winner ?= { save_scope_as = alt_3 }
			}
		}
	}
	
	option = {
		name = ep3_laamps.0001.a
		create_landless_adventurer_title_tooltip_effect = yes
		add_internal_flag = special
		scope:winner = { trigger_event = ep3_laamps.0003 }
	}
	option = {
		name = ep3_laamps.0001.b
		trigger = { exists = scope:alt_1 }
		laamp_switch_playable_character_effect = { NEW_CHARACTER = scope:alt_1 }
	}
	option = {
		name = ep3_laamps.0001.c
		trigger = { exists = scope:alt_2 }
		laamp_switch_playable_character_effect = { NEW_CHARACTER = scope:alt_2 }
	}
	option = {
		name = ep3_laamps.0001.d
		trigger = {
			scope:alt_3 ?= { playable_relative_trigger = yes }
		}
		laamp_switch_playable_character_effect = { NEW_CHARACTER = scope:alt_3 }
	}
	option = {
		name = ep3_laamps.0001.e
		laamp_game_over_option_effect = yes
		hidden_effect = { move_to_pool = yes }
	}
}

# Depose loser event
ep3_laamps.0005 = {
	type = character_event
	window = fullscreen_event
	title = {
		desc = {
			first_valid = {
				triggered_desc = {
					trigger = { is_female = yes }
					desc = ep3_laamps.0001.t.female
				}
				desc = ep3_laamps.0001.t.male
			}
		}
	}
	desc = ep3_laamps.0004.desc
	theme = realm
	left_portrait = {
		character = root
		animation = stress
	}
	lower_left_portrait = scope:alt_1
	lower_center_portrait = scope:alt_2
	lower_right_portrait = scope:alt_3
	override_background = { reference = ep3_fullscreen_adventurer_negative }

	trigger = {
		is_ai = no
		exists = var:deposed_primary_title
		NOT = { has_character_flag = become_laamp_event_cooldown }
	}

	immediate = {
		play_music_cue = adventure_begin_cue
		add_character_flag = {
			flag = become_laamp_event_cooldown
			days = 5
		}
		clear_saved_scope = lost_primary_title
		var:deposed_primary_title ?= {
			# Save highest lost title for loc
			save_scope_as = conquered
			# And for memory variables.
			save_scope_as = lost_primary_title
		}
		# Find alternative rulers to play as
		find_playable_relatives_effect = yes
		# Portrait scopes
		if = {
			limit = {
				NOT = { exists = scope:alt_3 }
			}
			if = {
				limit = { exists = scope:conquered.holder }
				scope:conquered.holder = { save_scope_as = alt_3 }
			}
			else_if = {
				limit = {
					NOR = {
						scope:alt_1 ?= scope:winner
						scope:alt_2 ?= scope:winner
					}
				}
				scope:winner ?= { save_scope_as = alt_3 }
			}
		}
		scope:conquered.current_heir = { save_scope_as = heir }
	}
	
	option = {
		name = ep3_laamps.0001.a
		show_as_tooltip = { depose = yes } # depose not actually used as it is immediate gameover
		hidden_effect = {
			create_title_and_vassal_change = {
				type = conquest
				save_scope_as = change
				add_claim_on_loss = yes
			}
			every_held_title = {
				title_tier >= county
				change_title_holder_include_vassals = {
					holder = scope:heir
					change = scope:change
				}
			}
			resolve_title_and_vassal_change = scope:change
			# Create Adventurer
			create_landless_adventurer_title_effect = {
				REASON = flag:deposition
				FLAVOR_CHAR = scope:attacker
			}
		}
		create_landless_adventurer_title_tooltip_effect = yes
		add_internal_flag = special
		scope:winner = { trigger_event = ep3_laamps.0003 }
	}
	option = {
		name = ep3_laamps.0001.b
		trigger = { exists = scope:alt_1 }
		show_as_tooltip = { depose = yes }
		laamp_switch_playable_character_effect = { NEW_CHARACTER = scope:alt_1 }
		hidden_effect = {
			depose = yes
			move_to_pool = yes
		}
	}
	option = {
		name = ep3_laamps.0001.c
		trigger = { exists = scope:alt_2 }
		show_as_tooltip = { depose = yes }
		laamp_switch_playable_character_effect = { NEW_CHARACTER = scope:alt_2 }
		hidden_effect = {
			depose = yes
			move_to_pool = yes
		}
	}
	option = {
		name = ep3_laamps.0001.d
		trigger = {
			scope:alt_3 ?= { playable_relative_trigger = yes }
		}
		show_as_tooltip = { depose = yes }
		laamp_switch_playable_character_effect = { NEW_CHARACTER = scope:alt_3 }
		hidden_effect = {
			depose = yes
			move_to_pool = yes
		}
	}
	option = {
		name = ep3_laamps.0001.e
		show_as_tooltip = { depose = yes }
		laamp_game_over_option_effect = yes
		hidden_effect = {
			depose = yes
			move_to_pool = yes
		}
	}
}

##################################################
# Become Adventurer - Succession
# by Joe Parkin
# 0010-0012
##################################################

# My sibling is more interesting than me

scripted_trigger ep3_laamp_inheritor_title_trigger = {
	recent_history = {
		type = inheritance
		days = 5
	}
	previous_holder = scope:deceased
}

# Player event
ep3_laamps.0010 = {
	type = character_event
	window = fullscreen_event
	title = ep3_laamps.0010.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					any_sibling = { count >= 2 }
				}
				desc = ep3_laamps.0010.multi
			}
			desc = ep3_laamps.0010.single
		}
		desc = ep3_laamps.0010.desc
		triggered_desc = {
			trigger = { exists = scope:inheritor_1 }
			desc = ep3_laamps.0010.inheritor_1
		}
		triggered_desc = {
			trigger = { exists = scope:inheritor_2 }
			desc = ep3_laamps.0010.inheritor_2
		}
		triggered_desc = {
			trigger = { exists = scope:inheritor_3 }
			desc = ep3_laamps.0010.inheritor_3
		}
		desc = ep3_laamps.0010.laamp
	}
	theme = realm
	left_portrait = {
		character = root
		animation = personality_cynical
	}
	right_portrait = {
		character = scope:potential_laamp
		animation = marshal
		outfit_tags = { military_outfit }
	}
	lower_right_portrait = scope:deceased
	override_background = { reference = ep3_fullscreen_adventurer_positive }
	cooldown = { years = 25 }

	trigger = {
		is_ai = no
		NOT = { has_character_flag = become_laamp_event_cooldown }
	}

	immediate = {
		play_music_cue = adventure_begin_cue
		add_character_flag = {
			flag = become_laamp_event_cooldown
			days = 5
		}
		# Save highest inherited title
		ordered_held_title = {
			limit = { ep3_laamp_inheritor_title_trigger = yes }
			order_by = tier
			position = 0
			save_scope_as = inherited
		}
		# Save inheritors for loc
		every_sibling = {
			limit = {
				any_held_title = { ep3_laamp_inheritor_title_trigger = yes }
			}
			add_to_list = inheritors
		}
		ordered_in_list = {
			list = inheritors
			order_by = age
			max = 3
			check_range_bounds = no
			if = {
				limit = { exists = scope:inheritor_2 }
				save_scope_as = inheritor_3
			}
			else_if = {
				limit = { exists = scope:inheritor_1 }
				save_scope_as = inheritor_2
			}
			else = { save_scope_as = inheritor_1 }
			ordered_held_title = {
				limit = { ep3_laamp_inheritor_title_trigger = yes }
				order_by = tier
				position = 0
				if = {
					limit = { exists = scope:inherited_2 }
					save_scope_as = inherited_3
				}
				else_if = {
					limit = { exists = scope:inherited_1 }
					save_scope_as = inherited_2
				}
				else = { save_scope_as = inherited_1 }
			}
		}
		scope:potential_laamp = {
			create_landless_adventurer_title_effect = {
				REASON = flag:succession
				FLAVOR_CHAR = root
			}
			adventurer_prestige_reset_effect = yes
		}
	}

	option = {
		name = ep3_laamps.0010.a
	}

	option = {
		name = ep3_laamps.0010.b
		add_internal_flag = special
		set_player_character = scope:potential_laamp
	}
}

# Setup event - heir
ep3_laamps.0011 = {
	type = character_event
	hidden = yes

	trigger = {
		save_temporary_scope_as = heir_temp
		any_sibling = {
			ep3_laamp_interesting_sibling_trigger = { COMPARISON = scope:heir_temp }
		}
	}

	immediate = {
		save_scope_as = heir
		# Save potential laamp
		ordered_sibling = {
			limit = {
				ep3_laamp_interesting_sibling_trigger = { COMPARISON = scope:heir }
			}
			order_by = ep3_laamp_chance_score_value
			save_scope_as = potential_laamp
		}
		random = {
			chance = 0
			modifier = { # Bonus for players
				is_ai = no
				add = 25
			}
			modifier = { add = scope:potential_laamp.ep3_laamp_chance_score_value }
			if = {
				limit = {
					is_ai = yes
					ai_can_valid_to_create_laamp_trigger = yes
				}
				scope:potential_laamp = {
					create_landless_adventurer_title_effect = {
						REASON = flag:succession
						FLAVOR_CHAR = scope:heir
					}
				}
				if = { # Debug tracking
					limit = { exists = global_var:ai_succession_laamp_count }
					change_global_variable = {
						name = ai_succession_laamp_count
						add = 1
					}
				}
				else = {
					set_global_variable = {
						name = ai_succession_laamp_count
						value = 1
					}
				}
				debug_log = "AI became adventurer by succession"
				debug_log_scopes = yes
			}
			else = { trigger_event = ep3_laamps.0010 }
		}
	}
}

# Setup event - deceased
ep3_laamps.0012 = {
	hidden = yes
	type = character_event

	trigger = {
		has_ep3_dlc_trigger = yes
		is_landed = yes
		player_heir ?= {
			save_temporary_scope_as = heir_temp
			any_sibling = {
				ep3_laamp_interesting_sibling_trigger = { COMPARISON = scope:heir_temp }
			}
		}
	}

	immediate = {
		save_scope_as = deceased
		player_heir = {
			trigger_event = {
				id = ep3_laamps.0011
				days = 5
			}
		}
	}
}

##################################################
# Become Adventurer - Banish
# by Joe Parkin
# 0020-0021
##################################################

# I have been banished

# Banished event
ep3_laamps.0020 = {
	type = character_event
	window = fullscreen_event
	title = ep3_laamps.0020.t
	desc = ep3_laamps.0020.desc
	theme = realm
	left_portrait = {
		character = root
		animation = marshal
	}
	lower_left_portrait = scope:alt_1
	lower_center_portrait = scope:alt_2
	lower_right_portrait = scope:alt_3
	override_background = { reference = ep3_fullscreen_adventurer_negative }
	cooldown = { days = 5 }

	trigger = {
		NOT = { has_character_flag = become_laamp_event_cooldown }
	}

	immediate = {
		play_music_cue = adventure_begin_cue
		add_character_flag = {
			flag = become_laamp_event_cooldown
			days = 5
		}
		save_scope_as = adventurer
		liege = { save_scope_as = liege }
		# Save highest lost title for loc
		clear_saved_scope = lost_primary_title
		ordered_held_title = {
			order_by = tier
			position = 0
			save_scope_as = revoked
			# Plus for our memory variable.
			save_scope_as = lost_primary_title
		}
		find_playable_relatives_effect = yes
		# Portrait scopes
		if = {
			limit = {
				NOR = {
					exists = scope:alt_3
					scope:alt_1 ?= scope:banisher
					scope:alt_2 ?= scope:banisher
				}
			}
			scope:banisher = { save_scope_as = alt_3 }
		}
		adventurer_prestige_reset_effect = yes
	}

	option = {
		name = ep3_laamps.0020.a
		show_as_tooltip = { banish = yes }
		hidden_effect = {
			create_title_and_vassal_change = {
				type = revoked
				save_scope_as = change
				add_claim_on_loss = no
			}
			every_held_title = {
				title_tier >= county
				change_title_holder_include_vassals = {
					holder = scope:liege
					change = scope:change
				}
			}
			resolve_title_and_vassal_change = scope:change
			# Create Adventurer
			create_landless_adventurer_title_effect = {
				REASON = flag:exile
				FLAVOR_CHAR = scope:banisher
			}
		}
		create_landless_adventurer_title_tooltip_effect = yes
		add_internal_flag = special
		add_unpressed_claim = scope:lost_primary_title
		scope:banisher = {
			trigger_event = {
				id = ep3_laamps.0022
				days = 5
			}
		}
		scope:liege = {
			if = {
				limit = {
					this != scope:banisher
				}
				trigger_event = {
					id = ep3_laamps.0022
					days = 5
				}
			}
		}
	}

	option = {
		name = ep3_laamps.0001.b
		trigger = { exists = scope:alt_1 }
		show_as_tooltip = { banish = yes }
		laamp_switch_playable_character_effect = { NEW_CHARACTER = scope:alt_1 }
		hidden_effect = {
			if = {
				limit = {
					government_allows = administrative
				}
				force_step_down_landed_titles = yes
			}
			banish = yes
		}
	}
	option = {
		name = ep3_laamps.0001.c
		trigger = { exists = scope:alt_2 }
		show_as_tooltip = { banish = yes }
		laamp_switch_playable_character_effect = { NEW_CHARACTER = scope:alt_2 }
		hidden_effect = {
			if = {
				limit = {
					government_allows = administrative
				}
				force_step_down_landed_titles = yes
			}
			banish = yes
		}
	}
	option = {
		name = ep3_laamps.0001.d
		trigger = {
			scope:alt_3 ?= { playable_relative_trigger = yes }
		}
		show_as_tooltip = { banish = yes }
		laamp_switch_playable_character_effect = { NEW_CHARACTER = scope:alt_3 }
		hidden_effect = {
			if = {
				limit = {
					government_allows = administrative
				}
				force_step_down_landed_titles = yes
			}
			banish = yes
		}
	}
	option = {
		name = ep3_laamps.0001.e
		show_as_tooltip = { banish = yes }
		laamp_game_over_option_effect = yes
		hidden_effect = {
			if = {
				limit = {
					government_allows = administrative
				}
				force_step_down_landed_titles = yes
			}
			banish = yes
		}
	}
}

# Setup event
ep3_laamps.0021 = {
	type = character_event
	hidden = yes

	trigger = {
		has_ep3_dlc_trigger = yes
		is_valid_for_laampdom = yes
	}

	on_trigger_fail = {
		if = {
			limit = {
				government_allows = administrative
			}
			force_step_down_landed_titles = yes
		}
		banish = yes
	}

	immediate = {
		save_scope_as = adventurer
		liege = { save_scope_as = liege }
		clear_saved_scope = lost_primary_title
		# Save highest lost title for loc
		ordered_held_title = {
			order_by = tier
			position = 0
			save_scope_as = revoked
			# Plus for our memory variable.
			save_scope_as = lost_primary_title
		}
		add_character_flag = {
			flag = block_for_prison_release_notification
			days = 1
		}
		# AI chance
		if = {
			limit = {
				is_ai = yes
				ai_can_valid_to_create_laamp_trigger = yes
			}
			random = {
				chance = 0
				modifier = { add = ep3_laamp_chance_score_value }
				# Plus for our memory variable.
				add_character_flag = {
					flag = block_for_prison_release_message
					days = 1
				}
				create_title_and_vassal_change = {
					type = revoked
					save_scope_as = change
					add_claim_on_loss = no
				}
				every_held_title = {
					title_tier >= county
					change_title_holder_include_vassals = {
						holder = scope:liege
						change = scope:change
					}
				}
				resolve_title_and_vassal_change = scope:change
				create_landless_adventurer_title_effect = {
					REASON = flag:exile
					FLAVOR_CHAR = scope:actor
				}
				adventurer_prestige_reset_effect = yes
				add_unpressed_claim = scope:lost_primary_title
				scope:banisher = {
					trigger_event = {
						id = ep3_laamps.0022
						days = 5
					}
				}
				scope:liege = {
					if = {
						limit = {
							this != scope:banisher
						}
						trigger_event = {
							id = ep3_laamps.0022
							days = 5
						}
					}
				}
			}
			if = {
				limit = {
					NOT = {
						government_has_flag = government_is_landless_adventurer
					}
				}
				if = {
					limit = {
						government_allows = administrative
					}
					force_step_down_landed_titles = yes
				}
				banish = yes
			}
		}
		# Player event
		else = {
			trigger_event = { id = ep3_laamps.0020 }
		}
	}
}

# Banisher event
ep3_laamps.0022 = {
	type = letter_event
	opening = ep3_laamps.0003.opening
	desc = ep3_laamps.0022.desc
	sender = scope:adventurer

	trigger = { is_ai = no }

	immediate = {
		scope:adventurer = { create_landless_adventurer_title_tooltip_effect = yes }
	}

	option = {
		name = ep3_laamps.0022.a
	}
}

##################################################
# Become Adventurer - Voluntary
# by Joe Parkin
# 0030-0031
##################################################

# Adventure awaits

ep3_laamps.0030 = {
	type = character_event
	window = fullscreen_event
	title = ep3_laamps.0030.t
	desc = {
		desc = ep3_laamps.0030.desc
		first_valid = {
			triggered_desc = {
				trigger = { exists = scope:laamp_heir }
				desc = ep3_laamps.0030.heir
			}
			triggered_desc = {
				trigger = { exists = scope:laamp_liege }
				desc = ep3_laamps.0030.liege
			}
			desc = ep3_laamps.0030.new
		}
	}
	theme = realm
	left_portrait = {
		character = root
		animation = marshal
	}
	lower_right_portrait = scope:laamp_inheritor
	override_background = { reference = ep3_fullscreen_adventurer_positive }
	cooldown = { days = 5 }

	trigger = { exists = scope:laamp_inheritor }

	immediate = {
		play_music_cue = adventure_begin_cue
		# Save scopes for loc
		primary_title = { save_scope_as = old_primary_title }
		capital_province = { save_scope_as = old_capital_province }
		if = {
			limit = { top_liege != this }
			liege = { save_scope_as = old_liege }
		}
		# Transfer landed titles
		every_held_title = {
			title_tier > barony
			limit = {
				OR = {
					is_landless_type_title = no
					is_nomad_title = yes
				}
			}
			add_to_list = target_titles
		}
		create_title_and_vassal_change = {
			type = conquest
			save_scope_as = change
			add_claim_on_loss = no
		}
		hidden_effect = {
			every_in_list = {
				list = target_titles
				change_title_holder_include_vassals = {
					holder = scope:laamp_inheritor
					change = scope:change
				}
			}
			resolve_title_and_vassal_change = scope:change
		}
		# Create Adventurer
		create_landless_adventurer_title_effect = {
			REASON = flag:voluntary
			FLAVOR_CHAR = scope:laamp_inheritor
		}
		scope:laamp_inheritor = {
			# Tooltip for player
			custom_tooltip = become_landless_adventurer_decision_title_scope_tt
			# Create a loving family so inheritance isn't so borked
			if = {
				limit = { has_character_flag = new_laamp_inheritor }
				trigger_event = game_rule.1001
				remove_character_flag = new_laamp_inheritor
			}
		}
		scope:old_liege ?= { trigger_event = ep3_laamps.0032 }
		adventurer_prestige_reset_effect = yes
		hidden_effect = {
			every_held_title = {
				limit = {
					is_noble_family_title = yes
				}
				root = { destroy_title = prev }
			}
		}
	}

	option = {
		name = ep3_laamps.0030.a
		create_landless_adventurer_title_tooltip_effect = yes
		add_prestige = medium_prestige_gain
		add_character_modifier = {
			modifier = ep3_voluntary_laamp_character_modifier
			years = 5
		}
	}
}

# Liege event
ep3_laamps.0032 = {
	type = letter_event
	opening = ep3_laamps.0032.opening
	desc = ep3_laamps.0032.desc
	sender = scope:adventurer

	trigger = { is_ai = no }

	immediate = {
		scope:adventurer = { create_landless_adventurer_title_tooltip_effect = yes }
	}

	option = {
		name = ep3_laamps.0032.a
	}
}

ep3_laamps.1030 = {
		type = character_event
		window = fullscreen_event
		title = ep3_laamps.1030.t
		desc = {
			desc = ep3_laamps.1030.desc
			first_valid = {
				triggered_desc = {
					trigger = { exists = scope:laamp_heir }
					desc = ep3_laamps.1030.heir
				}
				triggered_desc = {
					trigger = { exists = scope:laamp_liege }
					desc = ep3_laamps.1030.liege
				}
				desc = ep3_laamps.1030.new
			}
		}
		theme = realm
		left_portrait = {
			character = root
			animation = marshal
		}
		lower_right_portrait = scope:laamp_inheritor
		override_background = { reference = ep3_fullscreen_adventurer_positive }
		cooldown = { days = 5 }
	
		trigger = { exists = scope:laamp_inheritor }
	
		immediate = {
			# Save scopes for loc
			primary_title = { save_scope_as = old_primary_title }
			capital_province = { save_scope_as = old_capital_province }
			if = {
				limit = { top_liege != this }
				liege = { save_scope_as = old_liege }
			}
			# Transfer landed titles
			every_held_title = {
				title_tier > barony
				limit = {
					OR = {
						is_landless_type_title = no
						is_nomad_title = yes
					}
				}
				add_to_list = target_titles
			}
			create_title_and_vassal_change = {
				type = conquest
				save_scope_as = change
				add_claim_on_loss = no
			}
			hidden_effect = {
				every_in_list = {
					list = target_titles
					change_title_holder_include_vassals = {
						holder = scope:laamp_inheritor
						change = scope:change
					}
				}
				resolve_title_and_vassal_change = scope:change
			}
			# Create Adventurer
			create_landless_minority_title_effect = {
				REASON = flag:voluntary
				FLAVOR_CHAR = scope:laamp_inheritor
			}
			scope:laamp_inheritor = {
				# Tooltip for player
				custom_tooltip = become_landless_adventurer_decision_title_scope_tt
				# Create a loving family so inheritance isn't so borked
				if = {
					limit = { has_character_flag = new_laamp_inheritor }
					trigger_event = game_rule.1001
					remove_character_flag = new_laamp_inheritor
				}
			}
			scope:old_liege ?= { trigger_event = ep3_laamps.1032 }
			adventurer_prestige_reset_effect = yes
			hidden_effect = {
				every_held_title = {
					limit = {
						is_noble_family_title = yes
					}
					root = { destroy_title = prev }
				}
			}
		}
	
		option = {
			name = ep3_laamps.1030.a
			create_landless_minority_title_tooltip_effect = yes
			add_prestige = medium_prestige_gain
			add_character_modifier = {
				modifier = ep3_voluntary_laamp_character_modifier
				years = 5
			}
		}
	}
	
	# Liege event
	ep3_laamps.1032 = {
		type = letter_event
		opening = ep3_laamps.1032.opening
		desc = ep3_laamps.1032.desc
		sender = scope:minority_leader
	
		trigger = { is_ai = no }
	
		immediate = {
			scope:minority_leader = { create_landless_minority_title_tooltip_effect = yes }
		}
	
		option = {
			name = ep3_laamps.1032.a
		}
	}

##################################################
# Become Adventurer - Revocation
# by Joe Parkin
# 0040-0041
##################################################

# Come back

scripted_trigger ep3_laamp_revoked_title_trigger = {
	recent_history = { type = revoked days = 1 }
	previous_holder = root
}

ep3_laamps.0040 = {
	type = character_event
	window = fullscreen_event
	title = ep3_laamps.0040.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:actor = { is_close_family_of = root }
				}
				desc = ep3_laamps.0040.family
			}
			desc = ep3_laamps.0040.other
		}
		desc = ep3_laamps.0040.desc
	}
	theme = realm
	left_portrait = {
		character = root
		animation = marshal
	}
	lower_left_portrait = scope:alt_1
	lower_center_portrait = scope:alt_2
	lower_right_portrait = scope:alt_3
	override_background = { reference = ep3_fullscreen_adventurer_negative }
	cooldown = { days = 5 }

	# The AI was managing to get this event somehow.
	trigger = {
		is_ai = no
		NOT = { has_character_flag = become_laamp_event_cooldown }
	}

	immediate = {
		play_music_cue = adventure_begin_cue
		add_character_flag = {
			flag = become_laamp_event_cooldown
			days = 5
		}
		# Find alternative rulers to play as
		find_playable_relatives_effect = yes
		# Portrait scopes
		if = {
			limit = {
				NOR = {
					exists = scope:alt_3
					scope:alt_1 ?= scope:actor
					scope:alt_2 ?= scope:actor
				}
			}
			scope:actor = { save_scope_as = alt_3 }
		}
		# Create Adventurer
		hidden_effect = {
			create_landless_adventurer_title_effect = {
				REASON = flag:revocation
				FLAVOR_CHAR = scope:actor
			}
		}
		adventurer_prestige_reset_effect = yes
	}

	option = {
		name = ep3_laamps.0040.a
		create_landless_adventurer_title_tooltip_effect = yes
		add_internal_flag = special
		scope:actor = { trigger_event = ep3_laamps.0042 }
	}

	option = {
		name = ep3_laamps.0001.b
		trigger = { exists = scope:alt_1 }
		laamp_switch_playable_character_effect = { NEW_CHARACTER = scope:alt_1 }
	}
	option = {
		name = ep3_laamps.0001.c
		trigger = { exists = scope:alt_2 }
		laamp_switch_playable_character_effect = { NEW_CHARACTER = scope:alt_2 }
	}
	option = {
		name = ep3_laamps.0001.d
		trigger = {
			exists = scope:alt_3
			scope:alt_3 = { playable_relative_trigger = yes }
		}
		laamp_switch_playable_character_effect = { NEW_CHARACTER = scope:alt_3 }
	}
	option = {
		name = ep3_laamps.0001.e
		laamp_game_over_option_effect = yes
	}
}

# Setup event
ep3_laamps.0041 = {
	type = character_event
	hidden = yes

	trigger = {
		has_ep3_dlc_trigger = yes
		is_landed = no
		is_valid_for_laampdom = yes
	}

	immediate = {
		save_scope_as = adventurer
		# AI chance
		if = {
			limit = {
				is_ai = yes
				ai_can_valid_to_create_laamp_trigger = yes
				trigger_if = { # Don't fill the adventurer pool with revoked counts
					limit = {
						scope:lost_primary_title.tier <= tier_county
					}
					global_variable_list_size = {
						name = laamps_tally
						value < seventyfive_percent_of_max_desired_laamps_value
					}
				}
			}
			random = {
				chance = 0
				modifier = { add = ep3_laamp_chance_score_value }
				create_landless_adventurer_title_effect = {
					REASON = flag:revocation
					FLAVOR_CHAR = scope:actor
				}
				scope:actor = { trigger_event = ep3_laamps.0042 }
			}
		}
		# Player event
		else = {
			trigger_event = { id = ep3_laamps.0040 }
		}
	}
}

# Revoker event
ep3_laamps.0042 = {
	type = letter_event
	opening = ep3_laamps.0003.opening
	desc = ep3_laamps.0042.desc
	sender = scope:adventurer

	trigger = { is_ai = no }

	immediate = {
		create_landless_adventurer_title_tooltip_effect = yes
	}

	option = {
		name = ep3_laamps.0042.a
	}
}

##################################################
# Become Adventurer - Runaway
# by Joe Parkin
# 0050-0051
##################################################

# Close family

scripted_trigger ep3_laamp_runaway_child_trigger = {
	is_ai = yes
	liege ?= {
		this = root
		is_landed = yes
		highest_held_title_tier >= tier_duchy
	}
	NOT = { root.primary_heir ?= this }
	is_valid_for_laampdom = yes
	age <= 25
	NOT = { has_character_flag = failed_laamp_runaway }
	save_temporary_scope_as = runaway_temp
	# Less important kids as rank increases
	liege ?= {
		primary_title = { 
			trigger_if = {
				limit = { tier = tier_empire }
				place_in_line_of_succession = { target = scope:runaway_temp value < 6 }
			}
			trigger_else_if = {
				limit = { tier = tier_kingdom }
				place_in_line_of_succession = { target = scope:runaway_temp value < 4 }
			}
			trigger_else = {
				place_in_line_of_succession = { target = scope:runaway_temp value < 2 }
			}
		}
	}
}

ep3_laamps.0050 = {
	type = character_event
	title = ep3_laamps.0050.t
	desc = ep3_laamps.0050.desc
	theme = family
	left_portrait = {
		character = root
		animation = worry
	}
	right_portrait = {
		character = scope:potential_laamp
		animation = war_over_win
	}
	cooldown = { years = 10 }

	trigger = {
		has_ep3_dlc_trigger = yes
		is_landed_or_landless_administrative = yes
		any_close_family_member = { ep3_laamp_runaway_child_trigger = yes }
		OR = {
			is_ai = no
			ai_can_valid_to_create_laamp_trigger = yes
		}
		NOT = { has_character_flag = become_laamp_event_cooldown }
	}

	weight_multiplier = {
		base = 1
		modifier = {
			is_ai = no
			add = 1
		}
		modifier = {
			highest_held_title_tier > tier_county # 2
			add = {
				value = 2
				subtract = highest_held_title_tier
			}
		}
		modifier = {
			any_child = {
				ep3_laamp_runaway_child_trigger = yes
				ep3_laamp_interesting_enough_to_be_a_laamp_trigger = { COMPARISON = root }
			}
			add = 1
		}
		modifier = {
			add = 1
			exists = var:runaway_laamp_encourager
		}
	}

	immediate = {
		add_character_flag = {
			flag = become_laamp_event_cooldown
			days = 5
		}
		var:runaway_laamp_encourager ?= { save_scope_as = encouraged_laamp }
		every_close_family_member = {
			limit = { ep3_laamp_runaway_child_trigger = yes }
			add_to_list = potential_runaways
		}
		ordered_in_list = {
			list = potential_runaways
			order_by = ep3_laamp_chance_score_value
			save_scope_as = potential_laamp
			save_scope_as = adventurer
		}
	}
 	
	option = { # Encourage
		name = ep3_laamps.0050.a
		trigger = { is_ai = no }
		hidden_effect = {
			scope:potential_laamp = {
				create_landless_adventurer_title_effect = {
					REASON = flag:runaway_allowed
					FLAVOR_CHAR = root
				}
			}
		}
		add_internal_flag = special
		set_player_character = scope:potential_laamp
		scope:potential_laamp = { 
			create_landless_adventurer_title_tooltip_effect = yes 
		}
		stress_impact = {
			arrogant = medium_stress_impact_gain
			craven = minor_stress_impact_gain
		}
	}

	option = { # Allow
		name = ep3_laamps.0050.b
		reverse_add_opinion = {
			target = scope:potential_laamp
			modifier = allowed_runaway_laamp_opinion
		}
		scope:potential_laamp = {
			create_landless_adventurer_title_effect = {
				REASON = flag:runaway_allowed
				FLAVOR_CHAR = root
			}
			adventurer_prestige_reset_effect = yes
		}
		set_variable = {
			name = runaway_laamp_encourager
			value = scope:potential_laamp
		}
		stress_impact = {
			arrogant = medium_stress_impact_gain
			craven = minor_stress_impact_gain
		}
		ai_chance = {
			base = 0
			ai_value_modifier = {
				ai_boldness = 0.25
				ai_energy = 0.25
			}
			opinion_modifier = {
				opinion_target = scope:potential_laamp
				multiplier = -0.25
			}
			modifier = {
				add = 50
				culture = {
					has_cultural_parameter = more_likely_to_be_laamps
				}
			}
			modifier = {
				add = 150
				culture = {
					has_cultural_parameter = much_more_likely_to_be_laamps
				}
			}
		}
	}

	option = { # Forbid
		name = ep3_laamps.0050.c
		reverse_add_opinion = {
			target = scope:potential_laamp
			modifier = forbidden_runaway_laamp_opinion
		}
		duel = {
			target = scope:potential_laamp
			skill = intrigue
			10 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				min = 5
				add_prestige = minor_prestige_loss
				scope:potential_laamp = { add_character_flag = failed_laamp_runaway }
			}
			10 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				min = 5
				scope:potential_laamp = { create_landless_adventurer_title_tooltip_effect = yes }
				trigger_event = {
					id = ep3_laamps.0051
					days = 1
				}
			}
		}
		stress_impact = {
			brave = medium_stress_impact_gain
		}
		ai_chance = {
			base = 25
			opinion_modifier = {
				opinion_target = scope:potential_laamp
				multiplier = 0.25
			}
		}
	}
}

ep3_laamps.0051 = {
	type = character_event
	title = ep3_laamps.0050.t
	desc = ep3_laamps.0051.desc
	theme = family
	left_portrait = {
		character = root
		animation = stress
	}
	lower_right_portrait = scope:potential_laamp

	trigger = {
		has_ep3_dlc_trigger = yes
		scope:potential_laamp = { ep3_laamp_runaway_child_trigger = yes }
	}

	immediate = {
		# Create Adventurer
		scope:potential_laamp = {
			create_landless_adventurer_title_effect = {
				REASON = flag:runaway_forbidden
				FLAVOR_CHAR = root
			}
			adventurer_prestige_reset_effect = yes
		}
		add_prestige = minor_prestige_loss
	}
 	
	option = {
		name = ep3_laamps.0051.a
	}

	option = {
		name = ep3_laamps.0051.b
		trigger = {
			is_ai = no
			scope:potential_laamp = { is_playable_character = yes } # For Safety
		}
		add_internal_flag = special
		set_player_character = scope:potential_laamp
	}
}

##################################################
# Become Landed - Purchase
# by Joe Parkin
# 0100-0102
##################################################

ep3_laamps.0100 = {
	type = character_event
	title = ep3_laamps.0100.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = { government_has_flag = government_is_nomadic }
				desc = ep3_laamps.0100.desc_nomadic
			}
			desc = ep3_laamps.0100.desc
		}
		first_valid = {
			triggered_desc = {
				trigger = { scope:new_liege ?= scope:recipient }
				desc = ep3_laamps.0100.liege
			}
			triggered_desc = {
				trigger = { exists = scope:new_liege }
				desc = ep3_laamps.0100.fellow_vassal
			}
			desc = ep3_laamps.0100.independent
		}
		first_valid = {
			triggered_desc = {
				trigger = {
					NOT = { government_has_flag = government_is_nomadic }
					exists = scope:new_liege
				}
				desc = ep3_laamps.0100.unpopular
			}
			triggered_desc = {
				trigger = {
					NOT = { government_has_flag = government_is_nomadic }
				}
				desc = ep3_laamps.0100.fallback
			}
		}
	}
	theme = crown
	left_portrait = {
		character = root
		animation = war_over_tie
	}
	right_portrait = {
		character = scope:recipient
		animation = steward
	}
	lower_left_portrait = {
		trigger = {
			scope:recipient != scope:new_liege
		}
		character = scope:new_liege
	}

	trigger = {
		has_ep3_dlc_trigger = yes
	}

	immediate = {
		purchase_land_interaction_effect = yes
		scope:recipient = { trigger_event = ep3_laamps.0101 }
	}
 	
	option = {
		name = ep3_laamps.0100.a
		if = { # Vassal obligations
			limit = { scope:vassal_obligation = yes }
			vassal_contract_set_obligation_level = { type = feudal_government_taxes level = 4 }
			vassal_contract_set_obligation_level = { type = feudal_government_levies level = 4 }
		}
	}
}

ep3_laamps.0101 = {
	type = letter_event
	opening = ep3_laamps.0101.opening
	desc = {
		desc = ep3_laamps.0101.desc
		first_valid = {
			triggered_desc = {
				trigger = { scope:new_liege ?= scope:recipient }
				desc = ep3_laamps.0101.liege
			}
			triggered_desc = {
				trigger = { exists = scope:new_liege }
				desc = ep3_laamps.0101.fellow_vassal
			}
			desc = ep3_laamps.0100.independent
		}
	}
	sender = scope:actor

	trigger = {
		has_ep3_dlc_trigger = yes
	}

	immediate = {
		show_as_tooltip = { purchase_land_interaction_effect = yes }
		if = {
			limit = {
				top_liege != this
				scope:actor.liege != root
			}
			hidden_effect = {
				liege = {
					send_interface_message = {
						type = event_landless_adventurer_neutral
						title = ep3_laamps.0101.liege_message.title
						left_icon = scope:actor
						right_icon = scope:recipient
						show_as_tooltip = { purchase_land_interaction_effect = yes }
					}
				}
			}
		}
	}
 	
	option = {
		name = ep3_laamps.0101.a
		trigger = { scope:new_liege ?= scope:recipient }
	}

	option = {
		name = ep3_laamps.0101.b
		trigger = {
			exists = scope:new_liege
			NOT = { scope:new_liege ?= scope:recipient }
		}
	}

	option = {
		name = ep3_laamps.0101.c
		trigger = {
			NOT = { exists = scope:new_liege }
		}
	}
}

ep3_laamps.0102 = {
	type = letter_event
	opening = ep3_laamps.0102.opening
	desc = ep3_laamps.0102.desc
	sender = scope:actor

	trigger = {
		has_ep3_dlc_trigger = yes
	}

	option = {
		name = ep3_laamps.0102.a
	}
}

##################################################
# Become Landed - Invasion
# by Joe Parkin
# 0200-0201
##################################################

# Interaction

ep3_laamps.0200 = {
	type = letter_event
	opening = ep3_laamps.0101.opening
	desc = ep3_laamps.0200.desc
	sender = scope:recipient

	trigger = {
		has_ep3_dlc_trigger = yes
	}

	immediate = {
		if = {
			limit = { scope:offer_gold = yes }
			show_as_tooltip = {
				pay_short_term_gold = {
					gold = scope:recipient.request_laamp_invasion_sponsorship_gold_cost
					target = scope:recipient
				}
			}
			hidden_effect = {
				scope:recipient = { add_short_term_gold = scope:recipient.request_laamp_invasion_sponsorship_gold_cost }
			}
		}
		scope:recipient = {
			if = {
				limit = {
					scope:request_soldiers = yes
					scope:join_war = yes
				}
				custom_tooltip = adventurer_invasion_supporter_tt
			}
			else_if = {
				limit = { scope:request_soldiers = yes }
				custom_tooltip = adventurer_invasion_supporter_soldiers_tt
			}
			else = { custom_tooltip = adventurer_invasion_supporter_join_tt }
		}
		scope:actor = { custom_tooltip = adventurer_invasion_supporter_victory_tt }
	}
 	
	option = {
		name = ep3_laamps.0200.a
	}
}

ep3_laamps.0201 = {
	type = letter_event
	opening = ep3_laamps.0201.opening
	desc = ep3_laamps.0201.desc
	sender = scope:recipient

	trigger = {
		has_ep3_dlc_trigger = yes
	}
 	
	option = {
		name = ep3_laamps.0201.a
	}
}

##################################################
# Become Landed - Negotiated
# by Joe Parkin
# 0300-0302
##################################################

ep3_laamps.0300 = {
	type = character_event
	title = ep3_laamps.0300.t
	desc = {
		desc = ep3_laamps.0300.desc
		first_valid = {
			triggered_desc = {
				trigger = { scope:new_liege ?= scope:actor }
				desc = ep3_laamps.0300.liege
			}
			triggered_desc = {
				trigger = { exists = scope:new_liege }
				desc = ep3_laamps.0300.fellow_vassal
			}
			desc = ep3_laamps.0300.independent
		}
		first_valid = {
			triggered_desc = {
				trigger = { exists = scope:new_liege }
				desc = ep3_laamps.0300.unpopular
			}
			desc = ep3_laamps.0300.fallback
		}
	}
	theme = realm
	left_portrait = {
		character = root
		animation = worry
	}
	lower_right_portrait = scope:recipient
	lower_left_portrait = {
		trigger = {
			scope:actor != scope:new_liege
		}
		character = scope:new_liege
	}

	trigger = {
		has_ep3_dlc_trigger = yes
	}

	immediate = {
		negotiate_settlement_interaction_effect = yes
		scope:recipient = { trigger_event = ep3_laamps.0301 }
	}
 	
	option = {
		name = ep3_laamps.0300.a
	}
}

ep3_laamps.0301 = {
	type = letter_event
	opening = ep3_laamps.0301.opening
	desc = {
		desc = ep3_laamps.0301.desc
		first_valid = {
			triggered_desc = {
				trigger = { scope:new_liege ?= scope:actor }
				desc = ep3_laamps.0301.liege
			}
			triggered_desc = {
				trigger = { exists = scope:new_liege }
				desc = ep3_laamps.0301.fellow_vassal
			}
			desc = ep3_laamps.0300.independent
		}
	}
	sender = scope:actor

	trigger = {
		has_ep3_dlc_trigger = yes
	}

	immediate = {
		show_as_tooltip = { negotiate_settlement_interaction_effect = yes }
		if = {
			limit = {
				top_liege != this
				scope:recipient.liege != scope:actor
			}
			hidden_effect = {
				liege = {
					send_interface_message = {
						type = event_landless_adventurer_neutral
						title = ep3_laamps.0301.liege_message.title
						left_icon = scope:actor
						right_icon = scope:recipient
						show_as_tooltip = { negotiate_settlement_interaction_effect = yes }
					}
				}
			}
		}
	}
 	
	option = {
		name = ep3_laamps.0301.a
		trigger = { scope:new_liege ?= scope:actor }
	}

	option = {
		name = ep3_laamps.0301.b
		trigger = {
			exists = scope:new_liege
			NOT = { scope:new_liege ?= scope:actor }
		}
	}

	option = {
		name = ep3_laamps.0301.c
		trigger = {
			NOT = { exists = scope:new_liege }
		}
	}
}

ep3_laamps.0302 = {
	type = letter_event
	opening = ep3_laamps.0302.opening
	desc = ep3_laamps.0302.desc
	sender = scope:actor

	trigger = {
		has_ep3_dlc_trigger = yes
	}

	option = {
		name = ep3_laamps.0302.a
	}
}

##################################################
# Become Landed - Seize Realm
# by Joe Parkin
# 0401-0412
##################################################

### SUCCESS
ep3_laamps.0401 = {
	type = character_event
	title = ep3_laamps.0401.t
	desc = {
		desc = ep3_laamps.0401.desc
		first_valid = {
			triggered_desc = {
				trigger = { exists = scope:imprison  }
				desc = ep3_laamps.0401.imprison
			}
			triggered_desc = {
				trigger = { exists = scope:death }
				desc = ep3_laamps.0401.death
			}
			desc = ep3_laamps.0401.outro
		}
	}
	theme = claim_throne_scheme
	override_background = { reference = throne_room_scope }
	left_portrait = {
		character = root
		animation = marshal
	}
	right_portrait = {
		character = scope:target
		animation = prisonhouse
		override_imprisonment_visuals = yes
	}

	trigger = { exists = scope:scheme_successful }

	immediate = {
		scope:target = { trigger_event = ep3_laamps.0410 }
		seize_realm_scheme_success_effect = yes
	}

	option = { 
		name = ep3_laamps.0401.a
	}

	after = {
		
	}
}

### FAILURE
ep3_laamps.0402 = {
	type = character_event
	title = ep3_laamps.0402.t
	desc = {
		desc = ep3_laamps.0402.desc
		first_valid = {
			triggered_desc = {
				trigger = { exists = scope:imprison }
				desc = ep3_laamps.0402.imprison
			}
			triggered_desc = {
				trigger = { exists = scope:death }
				desc = ep3_laamps.0402.death
			}
			desc = ep3_laamps.0402.outro
		}
	}
	theme = claim_throne_scheme
	override_background = {
		trigger = { exists = scope:imprison }
		reference = dungeon_scope
	}
	override_background = {
		trigger = { exists = scope:death }
		reference = throne_room_scope
	}
	override_background = {
		trigger = {
			NOR = {
				exists = scope:imprison
				exists = scope:death
			}
		}
		reference = army_camp
	}
	left_portrait = {
		character = root
		triggered_animation = {
			trigger = { exists = scope:imprison }
			animation = prisonhouse
		}
		triggered_animation = {
			trigger = { exists = scope:death }
			animation = loss_1
		}
		triggered_animation = {
			trigger = {
				NOR = {
					exists = scope:imprison
					exists = scope:death
				}
			}
			animation = stress
		}
		override_imprisonment_visuals = yes
		outfit_tags = { prison }
	}
	right_portrait = {
		character = scope:target
		animation = war_over_win
		trigger = {
			OR = {
				exists = scope:imprison
				exists = scope:death
			}
		}
	}
	lower_right_portrait = {
		character = scope:target
		trigger = {
			NOR = {
				exists = scope:imprison
				exists = scope:death
			}
		}
	}

	trigger = {
		NOT = { exists = scope:scheme_successful }
	}

	immediate = {
		scope:target = { trigger_event = ep3_laamps.0411 }
		seize_realm_scheme_failure_effect = yes
	}

	option = {
		name = ep3_laamps.0402.a
		trigger = {
			NOR = {
				exists = scope:imprison
				exists = scope:death
			}
		}
		stress_impact = {
			base = medium_stress_impact_gain
			ambitious = medium_stress_impact_gain
			arrogant = minor_stress_impact_gain
			diligent = minor_stress_impact_gain
			impatient = minor_stress_impact_gain
			stubborn = minor_stress_impact_gain
			lazy = minor_stress_impact_loss
			craven = minor_stress_impact_loss
			honest = minor_stress_impact_loss
		}
	}

	option = {
		name = ep3_laamps.0402.b
		trigger = { exists = scope:imprison }
		stress_impact = {
			base = medium_stress_impact_gain
			ambitious = medium_stress_impact_gain
			arrogant = minor_stress_impact_gain
			diligent = minor_stress_impact_gain
			impatient = minor_stress_impact_gain
			stubborn = minor_stress_impact_gain
			lazy = minor_stress_impact_loss
			craven = minor_stress_impact_loss
			honest = minor_stress_impact_loss
		}
	}

	option = {
		name = ep3_laamps.0402.c
		trigger = { exists = scope:death }
	}
}

### SUCCESS - TARGET
ep3_laamps.0410 = {
	type = character_event
	title = ep3_laamps.0410.t
	desc = {
		desc = ep3_laamps.0410.desc
		first_valid = {
			triggered_desc = {
				trigger = { exists = scope:death }
				desc = ep3_laamps.0410.death
			}
			triggered_desc = {
				trigger = { exists = scope:imprison }
				desc = ep3_laamps.0410.imprison
			}
			desc = ep3_laamps.0410.outro
		}
	}
	theme = claim_throne_scheme
	override_background = {
		trigger = { exists = scope:imprison }
		reference = dungeon_scope
	}
	override_background = {
		trigger = { NOT = { exists = scope:imprison } }
		reference = throne_room_scope
	}

	left_portrait = {
		character = scope:owner
		animation = war_over_win
	}
	right_portrait = {
		character = scope:target
		animation = fear
		override_imprisonment_visuals = yes
		trigger = {
			OR = {
				exists = scope:imprison
				exists = scope:death
			}
		}
	}
	lower_right_portrait = {
		character = scope:target
		trigger = {
			NOR = {
				exists = scope:imprison
				exists = scope:death
			}
		}
	}

	immediate = {
		show_as_tooltip = { seize_realm_scheme_success_effect = yes }
	}

	option = {
		name = ep3_laamps.0410.a
		trigger = { exists = scope:imprison }
	}

	option = {
		name = ep3_laamps.0410.b
		trigger = { exists = scope:death }
	}

	option = {
		name = ep3_laamps.0410.c
		trigger = {
			NOR = {
				exists = scope:imprison
				exists = scope:death
			}
		}
	}
}

### FAILURE - TARGET
ep3_laamps.0411 = {
	type = character_event
	title = ep3_laamps.0411.t
	desc = {
		desc = ep3_laamps.0411.desc
		first_valid = {
			triggered_desc = {
				trigger = { exists = scope:imprison }
				desc = ep3_laamps.0411.imprison
			}
			desc = ep3_laamps.0411.outro
		}
	}
	theme = claim_throne_scheme
	override_background = {
		trigger = { exists = scope:imprison }
		reference = dungeon_scope
	}
	override_background = {
		trigger = { NOT = { exists = scope:imprison } }
		reference = throne_room_scope
	}
	left_portrait = {
		character = scope:target
		animation = war_over_win
	}
	right_portrait = {
		character = scope:owner
		animation = fear
		override_imprisonment_visuals = yes
		trigger = {
			OR = {
				exists = scope:imprison
				exists = scope:death
			}
		}
	}
	lower_right_portrait = {
		character = scope:owner
		trigger = {
			NOR = {
				exists = scope:imprison
				exists = scope:death
			}
		}
	}

	immediate = {
		show_as_tooltip = { seize_realm_scheme_failure_effect = yes }
	}

	option = {
		name = ep3_laamps.0411.a
		trigger = { exists = scope:imprison }
	}

	option = {
		name = ep3_laamps.0411.b
		trigger = { exists = scope:death }
	}

	option = {
		name = ep3_laamps.0411.c
		trigger = {
			NOR = {
				exists = scope:imprison
				exists = scope:death
			}
		}
	}
}

##################################################
# Become Landed - Maintenance
# by Joe Parkin
# 0800
##################################################

scripted_trigger grantable_close_family_trigger = {
	is_adult = yes
	is_playable_character = no
	is_ai = yes
	house = scope:adventurer.house
	is_imprisoned = no
	trigger_if = {
		limit = { is_clergy = yes }
		faith = { has_doctrine_parameter = theocracy_temple_ownership }
	}
	NOR = {
		has_trait = incapable
		has_trait = devoted
		has_trait = order_member
		this = scope:adventurer
		this = scope:adventurer.player_heir
		is_spouse_of = scope:adventurer
		scope:alt_1 ?= this
		scope:alt_2 ?= this
		scope:alt_3 ?= this
		scope:previous_holder ?= this
	}
}

scripted_trigger grantable_claimant_trigger = {
	is_adult = yes
	is_playable_character = no
	is_ai = yes
	is_imprisoned = no
	trigger_if = {
		limit = { is_clergy = yes }
		faith = { has_doctrine_parameter = theocracy_temple_ownership }
	}
	NOR = {
		has_trait = incapable
		has_trait = devoted
		has_trait = order_member
		this = scope:adventurer
		is_spouse_of = scope:adventurer
		is_close_family_of = scope:adventurer
		scope:alt_1 ?= this
		scope:alt_2 ?= this
		scope:alt_3 ?= this
		scope:previous_holder ?= this
	}
}

scripted_trigger grantable_gender_preference_trigger = {
	trigger_if = {
		limit = { is_male = yes }
		scope:adventurer = {
			OR = {
				has_realm_law = male_only_law
				has_realm_law = male_preference_law
			}
		}
	}
	trigger_else_if = {
		limit = { is_female = yes }
		scope:adventurer = {
			OR = {
				has_realm_law = female_only_law
				has_realm_law = female_preference_law
			}
		}
	}
	trigger_else = { always = yes }
}

scripted_effect grant_land_to_beneficiary_effect = {
	save_scope_as = beneficiary
	if = {
		limit = { is_close_family_of = scope:adventurer }
		add_opinion = {
			target = scope:adventurer
			modifier = renounced_land_to_me_opinion
			opinion = 25
		}
		every_in_list = {
			list = family_list
			limit = {
				this != scope:beneficiary
			}
			if = {
				limit = {
					has_strong_claim_on = scope:new_title
					NOT = {
						scope:beneficiary = { has_strong_claim_on = scope:new_title }
					}
				}
				add_opinion = {
					target = scope:adventurer
					modifier = renounced_land_to_weaker_claim_opinion
					opinion = -30
				}
			}
			else = {
				add_opinion = {
					target = scope:adventurer
					modifier = renounced_land_to_other_opinion
					opinion = -15
				}
			}
		}
	}
	else = {
		add_opinion = {
			target = scope:adventurer
			modifier = renounced_land_to_me_opinion
			opinion = 50
		}
		if = {
			limit = { scope:beneficiary.house != scope:adventurer.house }
			every_in_list = {
				list = family_list
				add_opinion = {
					target = scope:adventurer
					modifier = renounced_land_outside_family_opinion
					opinion = -50
				}
			}
		}
		every_in_list = {
			list = claimant_list
			limit = {
				this != scope:beneficiary
			}
			if = {
				limit = {
					has_strong_claim_on = scope:new_title
					NOT = {
						scope:beneficiary = { has_strong_claim_on = scope:new_title }
					}
				}
				add_opinion = {
					target = root
					modifier = renounced_land_to_weaker_claim_opinion
					opinion = -50
				}
			}
			else = {
				add_opinion = {
					target = root
					modifier = renounced_land_to_other_opinion
					opinion = -25
				}
			}
		}
	}
	send_interface_message = {
		type = msg_titles_renounced_to_me
		title = adventurer_titles_renounced_title
		desc = adventurer_titles_renounced_to_me_desc
		left_icon = scope:adventurer
		scope:adventurer = {
			send_interface_message = {
				type = msg_titles_renounced_by_me
				title = adventurer_titles_renounced_title
				desc = adventurer_titles_renounced_by_me_desc
				left_icon = scope:beneficiary
				create_title_and_vassal_change = {
					type = granted
					save_scope_as = change
					add_claim_on_loss = no
				}
				scope:new_capital = {
					change_title_holder_include_vassals = {
						holder = scope:beneficiary
						change = scope:change
						take_baronies = no
					}
				}
				hidden_effect = {
					scope:beneficiary = {
						becomes_independent = { change = scope:change }
					}
				}
				every_held_title = {
					limit = {
						NOT = { has_variable = adventurer_creation_reason }
						is_noble_family_title = no
						is_landless_type_title = no
						this != scope:new_capital
					}
					if = {
						limit = { tier >= scope:new_title.tier }
						change_title_holder_include_vassals = {
							holder = scope:beneficiary
							change = scope:change
							take_baronies = no
						}
					}
					else = {
						hidden_effect = {
							change_title_holder_include_vassals = {
								holder = scope:beneficiary
								change = scope:change
								take_baronies = no
							}
						}
					}
				}
			}
		}
		resolve_title_and_vassal_change = scope:change
	}
	scope:adventurer = { custom_tooltip = ep3_laamps.0800.claim.tt }
}

scripted_effect transfer_crusader_king_trait_effect = {
	if = {
		limit = {
			has_character_flag = laamp_is_crusader_king
			has_trait = crusader_king
		}
		remove_trait = crusader_king
		$BENEFICIARY$ = { add_trait = crusader_king }
	}
}

ep3_laamps.0800 = { # Player adventurer has gained a landed title
	type = character_event
	title = ep3_laamps.0800.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = { scope:transfer_type = flag:inheritance }
				desc = ep3_laamps.0800.inherited
			}
			triggered_desc = {
				trigger = { scope:transfer_type = flag:abdication }
				desc = ep3_laamps.0800.abdication
			}
			triggered_desc = {
				trigger = { scope:transfer_type = flag:granted }
				desc = ep3_laamps.0800.granted
			}
			triggered_desc = {
				trigger = { scope:transfer_type = flag:election }
				desc = ep3_laamps.0800.election
			}
			triggered_desc = {
				trigger = { scope:transfer_type = flag:faction_demand }
				desc = ep3_laamps.0800.faction
			}
			triggered_desc = {
				trigger = { scope:transfer_type = flag:conquest_claim }
				desc = ep3_laamps.0800.claim_war
			}
			triggered_desc = {
				trigger = { scope:transfer_type = flag:conquest_holy_war }
				desc = ep3_laamps.0800.holy_war
			}
			desc = ep3_laamps.0800.conquest
		}
		first_valid = {
			triggered_desc = {
				trigger = { exists = scope:new_liege }
				desc = ep3_laamps.0800.vassal
			}
			desc = ep3_laamps.0800.independent
		}
		desc = ep3_laamps.0800.desc
	}
	theme = realm
	left_portrait = {
		character = scope:adventurer
		animation = war_over_win
	}
	lower_left_portrait = scope:alt_1
	lower_center_portrait = scope:alt_2
	lower_right_portrait = scope:portrait_scope
	cooldown = { days = 1 } # Do not change this
	orphan = yes

	trigger = {
		has_ep3_dlc_trigger = yes
		is_landed = yes
		government_has_flag = government_is_landless_adventurer
		NOT = { has_variable = became_landed_through_separatist_uprising_var } # It feels repetitive to get this event after choosing to become landed
		NOT = { #Used in the New England event chain
			has_character_flag = siward_flag
		}
	}

	immediate = {
		save_scope_as = adventurer
		# SAVE LANDED TITLES
		every_held_title = {
			title_tier >= county
			limit = {
				NOR = {
					has_variable = adventurer_creation_reason
					is_landless_type_title = yes
				}
			}
			add_to_list = landed_titles
		}
		# SAVE TITLES
		ordered_in_list = {
			list = landed_titles
			order_by = tier
			save_scope_as = new_title
			save_scope_as = target
			previous_holder ?= { save_scope_as = previous_holder }
		}
		capital_county = { save_scope_as = new_capital }
		every_in_list = {
			list = landed_titles
			limit = { tier = scope:new_title.tier }
			save_scope_as = tooltip_title
			show_as_tooltip = {
				scope:adventurer = { get_title = scope:tooltip_title }
			}
		}
		# SAVE LIEGE IF RELEVANT
		if = {
			limit = { top_liege != this }
			liege = { save_scope_as = new_liege }
		}
		# FIND RELATIVES TO GRANT TO
		hidden_effect = {
			if = {
				limit = {
					any_close_family_member = { grantable_close_family_trigger = yes }
				}
				while = {
					count = 3
					random_close_family_member = {
						limit = {
							grantable_close_family_trigger = yes
							OR = {
								has_relation_friend = scope:adventurer
								has_relation_lover = scope:adventurer
							}
							grantable_gender_preference_trigger = yes
						}
						alternative_limit = {
							grantable_close_family_trigger = yes
							has_strong_claim_on = scope:new_title
							grantable_gender_preference_trigger = yes
						}
						alternative_limit = {
							grantable_close_family_trigger = yes
							OR = {
								has_relation_friend = scope:adventurer
								has_relation_lover = scope:adventurer
							}
						}
						alternative_limit = {
							grantable_close_family_trigger = yes
							has_strong_claim_on = scope:new_title
						}
						alternative_limit = {
							grantable_close_family_trigger = yes
							grantable_gender_preference_trigger = yes
						}
						alternative_limit = { grantable_close_family_trigger = yes }
						weight = {
							base = 1
							modifier = {
								is_child_of = scope:adventurer
								add = 10
							}
							modifier = {
								is_sibling_of = scope:adventurer
								add = 5
							}
						}
						if = {
							limit = { NOT = { exists = scope:alt_1 } }
							save_scope_as = alt_1
						}
						else_if = {
							limit = { NOT = { exists = scope:alt_2 } }
							save_scope_as = alt_2
						}
						else_if = {
							limit = { NOT = { exists = scope:alt_3 } }
							save_scope_as = alt_3
						}
						add_to_list = family_list
					}
				}
			}
			### FIND CLAIMANTS TO GRANT TO
			if = {
				limit = {
					NOT = { exists = scope:alt_3 }
				}
				scope:new_title = {
					while = {
						count = 3
						random_claimant = {
							limit = {
								grantable_claimant_trigger = yes
								OR = {
									has_relation_friend = scope:adventurer
									has_relation_lover = scope:adventurer
									is_extended_family_of = scope:adventurer
								}
								grantable_gender_preference_trigger = yes
							}
							alternative_limit = {
								grantable_claimant_trigger = yes
								has_strong_claim_on = scope:new_title
								grantable_gender_preference_trigger = yes
							}
							alternative_limit = {
								grantable_claimant_trigger = yes
								OR = {
									has_relation_friend = scope:adventurer
									has_relation_lover = scope:adventurer
									is_extended_family_of = scope:adventurer
								}
							}
							alternative_limit = {
								grantable_claimant_trigger = yes
								has_strong_claim_on = scope:new_title
								grantable_gender_preference_trigger = yes
							}
							alternative_limit = {
								grantable_claimant_trigger = yes
								grantable_gender_preference_trigger = yes
							}
							alternative_limit = { grantable_claimant_trigger = yes }
							if = {
								limit = { NOT = { exists = scope:alt_1 } }
								save_scope_as = alt_1
							}
							else_if = {
								limit = { NOT = { exists = scope:alt_2 } }
								save_scope_as = alt_2
							}
							else_if = {
								limit = { NOT = { exists = scope:alt_3 } }
								save_scope_as = alt_3
							}
							add_to_list = claimant_list
						}
					}
				}
			}
		}
		# Portrait scopes
		if = {
			limit = {
				exists = scope:new_liege
				NOT = { exists = scope:alt_3 }
			}
			scope:new_liege = { save_scope_as = portrait_scope }
		}
		else = {
			scope:alt_3 ?= { save_scope_as = portrait_scope }
		}
	}
 	
	option = { # Become Landed
		name = ep3_laamps.0800.a
		if = {
			limit = {
				NOT = { has_trait = adventurer }
			}
			add_trait = adventurer
		}
		hidden_effect = {
			every_courtier = {
				set_variable = {
					name = former_camp_leader
					value = root
				}
				add_trait = adventurer_follower
			}
		}
		ep3_become_landed_transfer_effect = {
			TITLE_RECEIVER = root
			TITLE_LIST = landed_titles
			TYPE = granted
			REASON = flag:granted
			ENNOBLED_ADVENTURER = flag:yes
		}
		if = {
			limit = {
				has_character_modifier = ep3_lust_for_land_modifier
			}
			remove_character_modifier = ep3_lust_for_land_modifier
		}
	}
	option = { # Give to 1
		name = {
			text = ep3_laamps.0800.b
			trigger = { scope:alt_1 = { is_close_family_of = scope:adventurer } }
		}
		name = {
			text = ep3_laamps.0800.b.claimant
			trigger = { NOT = { scope:alt_1 = { is_close_family_of = scope:adventurer } } }
		}
		trigger = { exists = scope:alt_1 }
		scope:alt_1 = { grant_land_to_beneficiary_effect = yes }
		transfer_crusader_king_trait_effect = { BENEFICIARY = scope:alt_1 }
	}
	option = { # Give to 2
		name = {
			text = ep3_laamps.0800.c
			trigger = { scope:alt_2 = { is_close_family_of = scope:adventurer } }
		}
		name = {
			text = ep3_laamps.0800.c.claimant
			trigger = { NOT = { scope:alt_2 = { is_close_family_of = scope:adventurer } } }
		}
		trigger = { exists = scope:alt_2 }
		scope:alt_2 = { grant_land_to_beneficiary_effect = yes }
		transfer_crusader_king_trait_effect = { BENEFICIARY = scope:alt_2 }
	}
	option = { # Give to 3
		name = {
			text = ep3_laamps.0800.d
			trigger = { scope:alt_3 = { is_close_family_of = scope:adventurer } }
		}
		name = {
			text = ep3_laamps.0800.d.claimant
			trigger = { NOT = { scope:alt_3 = { is_close_family_of = scope:adventurer } } }
		}
		trigger = { exists = scope:alt_3 }
		scope:alt_3 = { grant_land_to_beneficiary_effect = yes }
		transfer_crusader_king_trait_effect = { BENEFICIARY = scope:alt_3 }
	}
	option = { # Give to liege/random dude
		name = {
			text = ep3_laamps.0800.e.liege
			trigger = { exists = scope:new_liege }
		}
		name = {
			text = ep3_laamps.0800.e
			trigger = { NOT = { exists = scope:new_liege } }
		}
		trigger = {
			OR = {
				NOT = { exists = scope:alt_1 }
				exists = scope:new_liege
			}
		}
		if = {
			limit = { exists = scope:new_liege }
			scope:new_liege = { grant_land_to_beneficiary_effect = yes }
			transfer_crusader_king_trait_effect = { BENEFICIARY = scope:new_liege }
		}
		else = {
			hidden_effect_new_object = {
				create_character = {
					template = laamp_inheritor_template
					culture = scope:new_capital.culture
					faith = scope:new_capital.faith
					dynasty = generate
					location = scope:new_capital.title_province
					after_creation = { save_scope_as = land_grantee }
				}
				scope:land_grantee = { grant_land_to_beneficiary_effect = yes }
			}
			custom_tooltip = become_landless_adventurer_decision_title_created_tt
		}
		transfer_crusader_king_trait_effect = { BENEFICIARY = scope:land_grantee }
	}

	after = { remove_character_flag = laamp_is_crusader_king }
}

##################################################
# The Roads We Walk
# by Ewan Cowhig Croft
# 1001 - 1010
##################################################

scripted_effect ep3_laamps_1001_pick_best_skill_effect = {
	if = {
		limit = {
			NOT = { exists = scope:pick_$PICK$ }
			calc_true_if = {
				amount >= $POSITION$
				$SKILL_1$ >= $SKILL_2$
				$SKILL_1$ >= $SKILL_3$
				$SKILL_1$ >= $SKILL_4$
				$SKILL_1$ >= $SKILL_5$
				$SKILL_1$ >= $SKILL_6$
			}
		}
		save_scope_value_as = {
			name = $SKILL_1$_char
			value = yes
		}
		save_scope_value_as = {
			name = pick_$PICK$
			value = flag:$SKILL_1$
		}
	}
}

scripted_effect ep3_laamps_1001_pick_best_skill_wrapper_effect = {
	# Diplomacy.
	if = {
		limit = {
			NOR = {
				exists = scope:diplomacy_char
				scope:pick_1 ?= flag:diplomacy
				scope:pick_2 ?= flag:diplomacy
				scope:pick_3 ?= flag:diplomacy
			}
		}
		ep3_laamps_1001_pick_best_skill_effect = {
			SKILL_1 = diplomacy
			POSITION = $POSITION$
			SKILL_2 = martial
			SKILL_3 = stewardship
			SKILL_4 = intrigue
			SKILL_5 = learning
			SKILL_6 = prowess
			PICK = $PICK$
		}
	}
	# Martial.
	if = {
		limit = {
			NOR = {
				exists = scope:martial_char
				scope:pick_1 ?= flag:martial
				scope:pick_2 ?= flag:martial
				scope:pick_3 ?= flag:martial
			}
		}
		ep3_laamps_1001_pick_best_skill_effect = {
			SKILL_1 = martial
			POSITION = $POSITION$
			SKILL_2 = diplomacy
			SKILL_3 = stewardship
			SKILL_4 = intrigue
			SKILL_5 = learning
			SKILL_6 = prowess
			PICK = $PICK$
		}
	}
	# Stewardship.
	if = {
		limit = {
			NOR = {
				exists = scope:stewardship_char
				scope:pick_1 ?= flag:stewardship
				scope:pick_2 ?= flag:stewardship
				scope:pick_3 ?= flag:stewardship
			}
		}
		ep3_laamps_1001_pick_best_skill_effect = {
			SKILL_1 = stewardship
			POSITION = $POSITION$
			SKILL_2 = diplomacy
			SKILL_3 = martial
			SKILL_4 = intrigue
			SKILL_5 = learning
			SKILL_6 = prowess
			PICK = $PICK$
		}
	}
	# Intrigue.
	if = {
		limit = {
			NOR = {
				exists = scope:intrigue_char
				scope:pick_1 ?= flag:intrigue
				scope:pick_2 ?= flag:intrigue
				scope:pick_3 ?= flag:intrigue
			}
		}
		ep3_laamps_1001_pick_best_skill_effect = {
			SKILL_1 = intrigue
			POSITION = $POSITION$
			SKILL_2 = diplomacy
			SKILL_3 = martial
			SKILL_4 = stewardship
			SKILL_5 = learning
			SKILL_6 = prowess
			PICK = $PICK$
		}
	}
	# Learning.
	if = {
		limit = {
			NOR = {
				exists = scope:learning_char
				scope:pick_1 ?= flag:learning
				scope:pick_2 ?= flag:learning
				scope:pick_3 ?= flag:learning
			}
		}
		ep3_laamps_1001_pick_best_skill_effect = {
			SKILL_1 = learning
			POSITION = $POSITION$
			SKILL_2 = diplomacy
			SKILL_3 = martial
			SKILL_4 = stewardship
			SKILL_5 = intrigue
			SKILL_6 = prowess
			PICK = $PICK$
		}
	}
	# Prowess.
	if = {
		limit = {
			NOR = {
				exists = scope:prowess_char
				scope:pick_1 ?= flag:prowess
				scope:pick_2 ?= flag:prowess
				scope:pick_3 ?= flag:prowess
			}
		}
		ep3_laamps_1001_pick_best_skill_effect = {
			SKILL_1 = prowess
			POSITION = $POSITION$
			SKILL_2 = diplomacy
			SKILL_3 = martial
			SKILL_4 = stewardship
			SKILL_5 = intrigue
			SKILL_6 = learning
			PICK = $PICK$
		}
	}
}

scripted_effect ep3_laamps_1001_generate_diplomacy_char_effect = {
	create_character = {
		template = pool_repopulate_diplomacy
		dynasty = none
		culture = root.location.culture
		faith = root.location.faith
		location = root.location
		save_scope_as = diplomacy_1
		diplomacy = {
			min_template_high_skill
			max_template_high_skill
		}
		martial = {
			min_template_average_skill
			max_template_average_skill
		}
		stewardship = {
			min_template_average_skill
			max_template_average_skill
		}
		intrigue = {
			min_template_average_skill
			max_template_average_skill
		}
		learning = {
			min_template_average_skill
			max_template_average_skill
		}
		prowess = {
			min_template_average_skill
			max_template_average_skill
		}
		after_creation = { add_to_list = spawned_chars_list }
	}
	create_character = {
		template = pool_repopulate_diplomacy
		dynasty = none
		culture = root.location.culture
		faith = root.location.faith
		location = root.location
		save_scope_as = diplomacy_2
		diplomacy = {
			min_template_high_skill
			max_template_high_skill
		}
		martial = {
			min_template_average_skill
			max_template_average_skill
		}
		stewardship = {
			min_template_average_skill
			max_template_average_skill
		}
		intrigue = {
			min_template_average_skill
			max_template_average_skill
		}
		learning = {
			min_template_average_skill
			max_template_average_skill
		}
		prowess = {
			min_template_average_skill
			max_template_average_skill
		}
		after_creation = { add_to_list = spawned_chars_list }
	}
}
scripted_effect ep3_laamps_1001_generate_martial_char_effect = {
	create_character = {
		template = pool_repopulate_martial
		dynasty = none
		culture = root.location.culture
		faith = root.location.faith
		location = root.location
		save_scope_as = martial_1
		diplomacy = {
			min_template_average_skill
			max_template_average_skill
		}
		martial = {
			min_template_high_skill
			max_template_high_skill
		}
		stewardship = {
			min_template_average_skill
			max_template_average_skill
		}
		intrigue = {
			min_template_average_skill
			max_template_average_skill
		}
		learning = {
			min_template_average_skill
			max_template_average_skill
		}
		prowess = {
			min_template_average_skill
			max_template_average_skill
		}
		after_creation = { add_to_list = spawned_chars_list }
	}
	create_character = {
		template = pool_repopulate_martial
		dynasty = none
		culture = root.location.culture
		faith = root.location.faith
		location = root.location
		save_scope_as = martial_2
		diplomacy = {
			min_template_average_skill
			max_template_average_skill
		}
		martial = {
			min_template_high_skill
			max_template_high_skill
		}
		stewardship = {
			min_template_average_skill
			max_template_average_skill
		}
		intrigue = {
			min_template_average_skill
			max_template_average_skill
		}
		learning = {
			min_template_average_skill
			max_template_average_skill
		}
		prowess = {
			min_template_average_skill
			max_template_average_skill
		}
		after_creation = { add_to_list = spawned_chars_list }
	}
}
scripted_effect ep3_laamps_1001_generate_stewardship_char_effect = {
	create_character = {
		template = pool_repopulate_stewardship
		dynasty = none
		culture = root.location.culture
		faith = root.location.faith
		location = root.location
		save_scope_as = stewardship_1
		diplomacy = {
			min_template_average_skill
			max_template_average_skill
		}
		martial = {
			min_template_average_skill
			max_template_average_skill
		}
		stewardship = {
			min_template_high_skill
			max_template_high_skill
		}
		intrigue = {
			min_template_average_skill
			max_template_average_skill
		}
		learning = {
			min_template_average_skill
			max_template_average_skill
		}
		prowess = {
			min_template_average_skill
			max_template_average_skill
		}
		after_creation = { add_to_list = spawned_chars_list }
	}
	create_character = {
		template = pool_repopulate_stewardship
		dynasty = none
		culture = root.location.culture
		faith = root.location.faith
		location = root.location
		save_scope_as = stewardship_2
		diplomacy = {
			min_template_average_skill
			max_template_average_skill
		}
		martial = {
			min_template_average_skill
			max_template_average_skill
		}
		stewardship = {
			min_template_high_skill
			max_template_high_skill
		}
		intrigue = {
			min_template_average_skill
			max_template_average_skill
		}
		learning = {
			min_template_average_skill
			max_template_average_skill
		}
		prowess = {
			min_template_average_skill
			max_template_average_skill
		}
		after_creation = { add_to_list = spawned_chars_list }
	}
}
scripted_effect ep3_laamps_1001_generate_intrigue_char_effect = {
	create_character = {
		template = pool_repopulate_intrigue
		dynasty = none
		culture = root.location.culture
		faith = root.location.faith
		location = root.location
		save_scope_as = intrigue_1
		diplomacy = {
			min_template_average_skill
			max_template_average_skill
		}
		martial = {
			min_template_average_skill
			max_template_average_skill
		}
		stewardship = {
			min_template_average_skill
			max_template_average_skill
		}
		intrigue = {
			min_template_high_skill
			max_template_high_skill
		}
		learning = {
			min_template_average_skill
			max_template_average_skill
		}
		prowess = {
			min_template_average_skill
			max_template_average_skill
		}
		after_creation = { add_to_list = spawned_chars_list }
	}
	create_character = {
		template = pool_repopulate_intrigue
		dynasty = none
		culture = root.location.culture
		faith = root.location.faith
		location = root.location
		save_scope_as = intrigue_2
		diplomacy = {
			min_template_average_skill
			max_template_average_skill
		}
		martial = {
			min_template_average_skill
			max_template_average_skill
		}
		stewardship = {
			min_template_average_skill
			max_template_average_skill
		}
		intrigue = {
			min_template_high_skill
			max_template_high_skill
		}
		learning = {
			min_template_average_skill
			max_template_average_skill
		}
		prowess = {
			min_template_average_skill
			max_template_average_skill
		}
		after_creation = { add_to_list = spawned_chars_list }
	}
}
scripted_effect ep3_laamps_1001_generate_learning_char_effect = {
	create_character = {
		template = pool_repopulate_learning
		dynasty = none
		culture = root.location.culture
		faith = root.location.faith
		location = root.location
		save_scope_as = learning_1
		diplomacy = {
			min_template_average_skill
			max_template_average_skill
		}
		martial = {
			min_template_average_skill
			max_template_average_skill
		}
		stewardship = {
			min_template_average_skill
			max_template_average_skill
		}
		intrigue = {
			min_template_average_skill
			max_template_average_skill
		}
		learning = {
			min_template_high_skill
			max_template_high_skill
		}
		prowess = {
			min_template_average_skill
			max_template_average_skill
		}
		after_creation = { add_to_list = spawned_chars_list }
	}
	create_character = {
		template = pool_repopulate_learning
		dynasty = none
		culture = root.location.culture
		faith = root.location.faith
		location = root.location
		save_scope_as = learning_2
		diplomacy = {
			min_template_average_skill
			max_template_average_skill
		}
		martial = {
			min_template_average_skill
			max_template_average_skill
		}
		stewardship = {
			min_template_average_skill
			max_template_average_skill
		}
		intrigue = {
			min_template_average_skill
			max_template_average_skill
		}
		learning = {
			min_template_high_skill
			max_template_high_skill
		}
		prowess = {
			min_template_average_skill
			max_template_average_skill
		}
		after_creation = { add_to_list = spawned_chars_list }
	}
}
scripted_effect ep3_laamps_1001_generate_prowess_char_effect = {
	create_character = {
		template = pool_repopulate_prowess
		dynasty = none
		culture = root.location.culture
		faith = root.location.faith
		location = root.location
		save_scope_as = prowess_1
		diplomacy = {
			min_template_average_skill
			max_template_average_skill
		}
		martial = {
			min_template_average_skill
			max_template_average_skill
		}
		stewardship = {
			min_template_average_skill
			max_template_average_skill
		}
		intrigue = {
			min_template_average_skill
			max_template_average_skill
		}
		learning = {
			min_template_average_skill
			max_template_average_skill
		}
		prowess = {
			min_template_high_skill
			max_template_high_skill
		}
		after_creation = { add_to_list = spawned_chars_list }
	}
	create_character = {
		template = pool_repopulate_prowess
		dynasty = none
		culture = root.location.culture
		faith = root.location.faith
		location = root.location
		save_scope_as = prowess_2
		diplomacy = {
			min_template_average_skill
			max_template_average_skill
		}
		martial = {
			min_template_average_skill
			max_template_average_skill
		}
		stewardship = {
			min_template_average_skill
			max_template_average_skill
		}
		intrigue = {
			min_template_average_skill
			max_template_average_skill
		}
		learning = {
			min_template_average_skill
			max_template_average_skill
		}
		prowess = {
			min_template_high_skill
			max_template_high_skill
		}
		after_creation = { add_to_list = spawned_chars_list }
	}
}

scripted_effect ep3_laamps_1001_boost_courtier_opinion_effect = {
	hidden_effect = {
		# Improve their opinion of us.
		reverse_add_opinion = {
			target = scope:$SKILL$_1
			modifier = respect_opinion
			opinion = 100
		}
		reverse_add_opinion = {
			target = scope:$SKILL$_2
			modifier = respect_opinion
			opinion = 100
		}
		# And, just in case, make sure we like them.
		add_opinion = {
			target = scope:$SKILL$_1
			modifier = respect_opinion
			opinion = 100
		}
		add_opinion = {
			target = scope:$SKILL$_2
			modifier = respect_opinion
			opinion = 100
		}
	}
}

scripted_effect ep3_laamps_1001_add_courtiers_effect = {
	# Nab our dudes.
	add_courtier = scope:$SKILL$_1
	add_courtier = scope:$SKILL$_2
}

scripted_trigger ep3_laamps_1001_basic_trigger = {
	NOR = {
		has_character_flag = special_laamp_char
		has_character_flag = got_starting_courtiers
	}
	# In case you become a laamp then immediately become landed again.
	has_government = landless_adventurer_government
}

#	We generate some starting courtiers for you so that you don't get irredeemably screwed at a basic laamp.
ep3_laamps.1001 = {
	type = character_event
	title = ep3_laamps.1001.t
	desc = {
		desc = ep3_laamps.1001.desc.intro
		first_valid = {
			triggered_desc = {
				trigger = { has_trait = blind }
				desc = ep3_laamps.1001.desc.blind
			}
			desc = ep3_laamps.1001.desc.at_least_one_working_eye
		}
	}
	theme = friendly
	left_portrait = {
		character = root
		animation = personality_rational
	}
	override_background = { reference = wilderness }

	trigger = {
		ep3_laamps_1001_basic_trigger = yes
		# Must be on land or else we don't know where to take our locals from.
		exists = location.county
	}

	on_trigger_fail = {
		if = {
			limit = { ep3_laamps_1001_basic_trigger = yes }
			trigger_event = {
				id = ep3_laamps.1001
				months = { 1 3 }
			}
		}
	}

	cooldown = { years = 20 }

	immediate = {
		# Alright, let's grab our best skills — we care about prowess so we need to do this the manual way.
		## First best.
		ep3_laamps_1001_pick_best_skill_wrapper_effect = { POSITION = 5 PICK = 1 }
		## Second best.
		ep3_laamps_1001_pick_best_skill_wrapper_effect = { POSITION = 4 PICK = 2 }
		## Third best.
		ep3_laamps_1001_pick_best_skill_wrapper_effect = { POSITION = 3 PICK = 3 }
		# Cool, now if we're the player, we generate our characters straight away so that we can display them in tooltips.
		if = {
			limit = { is_ai = no }
			if = {
				limit = { exists = scope:diplomacy_char }
				ep3_laamps_1001_generate_diplomacy_char_effect = yes
				ep3_laamps_1001_boost_courtier_opinion_effect = { SKILL = diplomacy }
			}
			if = {
				limit = { exists = scope:martial_char }
				ep3_laamps_1001_generate_martial_char_effect = yes
				ep3_laamps_1001_boost_courtier_opinion_effect = { SKILL = martial }
			}
			if = {
				limit = { exists = scope:stewardship_char }
				ep3_laamps_1001_generate_stewardship_char_effect = yes
				ep3_laamps_1001_boost_courtier_opinion_effect = { SKILL = stewardship }
			}
			if = {
				limit = { exists = scope:intrigue_char }
				ep3_laamps_1001_generate_intrigue_char_effect = yes
				ep3_laamps_1001_boost_courtier_opinion_effect = { SKILL = intrigue }
			}
			if = {
				limit = { exists = scope:learning_char }
				ep3_laamps_1001_generate_learning_char_effect = yes
				ep3_laamps_1001_boost_courtier_opinion_effect = { SKILL = learning }
			}
			if = {
				limit = { exists = scope:prowess_char }
				ep3_laamps_1001_generate_prowess_char_effect = yes
				ep3_laamps_1001_boost_courtier_opinion_effect = { SKILL = prowess }
			}
		}
		add_character_flag = got_starting_courtiers
		# Plus, nicknamify as many as we can.
		hidden_effect = {
			every_in_list = {
				list = spawned_chars_list
				assign_random_nickname_effect = yes
			}
		}
	}

	# Diplomacy.
	option = {
		name = ep3_laamps.1001.a
		trigger = { exists = scope:diplomacy_char }
		skill = diplomacy

		# Label what this means.
		custom_tooltip = ep3_laamps.1001.a.tt
		# For the player, we just add their pregenerated courtiers.
		if = {
			limit = { is_ai = no }
			ep3_laamps_1001_add_courtiers_effect = { SKILL = diplomacy }
		}
		# For the AI, generate their characters here.
		else = {
			ep3_laamps_1001_generate_diplomacy_char_effect = yes
			ep3_laamps_1001_add_courtiers_effect = { SKILL = diplomacy }
			ep3_laamps_1001_boost_courtier_opinion_effect = { SKILL = diplomacy }
		}

		# No stress for mechanical events.
		ai_chance = {
			base = 1
			# AI pick best skill, always.
			modifier = {
				add = 1000
				highest_skill = diplomacy
				diplomacy >= prowess
			}
		}
	}
	
	# Martial.
	option = {
		name = ep3_laamps.1001.b
		trigger = { exists = scope:martial_char }
		skill = martial

		# Label what this means.
		custom_tooltip = ep3_laamps.1001.b.tt
		# For the player, we just add their pregenerated courtiers.
		if = {
			limit = { is_ai = no }
			ep3_laamps_1001_add_courtiers_effect = { SKILL = martial }
		}
		# For the AI, generate their characters here.
		else = {
			ep3_laamps_1001_generate_martial_char_effect = yes
			ep3_laamps_1001_add_courtiers_effect = { SKILL = martial }
		}

		# No stress for mechanical events.
		ai_chance = {
			base = 1
			# AI pick best skill, always.
			modifier = {
				add = 1000
				highest_skill = martial
				martial >= prowess
			}
			modifier = {
				add = 150
				culture = {
					has_cultural_parameter = much_more_likely_to_be_laamps
				}
			}
			modifier = {
				add = 50
				culture = {
					has_cultural_parameter = more_likely_to_be_laamps
				}
			}
		}
	}
	
	# Stewardship.
	option = {
		name = ep3_laamps.1001.c
		trigger = { exists = scope:stewardship_char }
		skill = stewardship

		# Label what this means.
		custom_tooltip = ep3_laamps.1001.c.tt
		# For the player, we just add their pregenerated courtiers.
		if = {
			limit = { is_ai = no }
			ep3_laamps_1001_add_courtiers_effect = { SKILL = stewardship }
		}
		# For the AI, generate their characters here.
		else = {
			ep3_laamps_1001_generate_stewardship_char_effect = yes
			ep3_laamps_1001_add_courtiers_effect = { SKILL = stewardship }
		}

		# No stress for mechanical events.
		ai_chance = {
			base = 1
			# AI pick best skill, always.
			modifier = {
				add = 1000
				highest_skill = stewardship
				stewardship >= prowess
			}
		}
	}
	
	# Intrigue.
	option = {
		name = ep3_laamps.1001.d
		trigger = { exists = scope:intrigue_char }
		skill = intrigue

		# Label what this means.
		custom_tooltip = ep3_laamps.1001.d.tt
		# For the player, we just add their pregenerated courtiers.
		if = {
			limit = { is_ai = no }
			ep3_laamps_1001_add_courtiers_effect = { SKILL = intrigue }
		}
		# For the AI, generate their characters here.
		else = {
			ep3_laamps_1001_generate_intrigue_char_effect = yes
			ep3_laamps_1001_add_courtiers_effect = { SKILL = intrigue }
		}

		# No stress for mechanical events.
		ai_chance = {
			base = 1
			# AI pick best skill, always.
			modifier = {
				add = 1000
				highest_skill = intrigue
				intrigue >= prowess
			}
		}
	}
	
	# Learning.
	option = {
		name = ep3_laamps.1001.e
		trigger = { exists = scope:learning_char }
		skill = learning

		# Label what this means.
		custom_tooltip = ep3_laamps.1001.e.tt
		# For the player, we just add their pregenerated courtiers.
		if = {
			limit = { is_ai = no }
			ep3_laamps_1001_add_courtiers_effect = { SKILL = learning }
		}
		# For the AI, generate their characters here.
		else = {
			ep3_laamps_1001_generate_learning_char_effect = yes
			ep3_laamps_1001_add_courtiers_effect = { SKILL = learning }
		}

		# No stress for mechanical events.
		ai_chance = {
			base = 1
			# AI pick best skill, always.
			modifier = {
				add = 1000
				highest_skill = learning
				learning >= prowess
			}
		}
	}
	
	# Prowess.
	option = {
		name = ep3_laamps.1001.f
		trigger = { exists = scope:prowess_char }
		skill = prowess

		# Label what this means.
		custom_tooltip = ep3_laamps.1001.f.tt
		# For the player, we just add their pregenerated courtiers.
		if = {
			limit = { is_ai = no }
			ep3_laamps_1001_add_courtiers_effect = { SKILL = prowess }
		}
		# For the AI, generate their characters here.
		else = {
			ep3_laamps_1001_generate_prowess_char_effect = yes
			ep3_laamps_1001_add_courtiers_effect = { SKILL = prowess }
		}

		# No stress for mechanical events.
		ai_chance = {
			base = 1
			# AI pick best skill, always.
			modifier = {
				add = 1000
				prowess >= diplomacy
				prowess >= martial
				prowess >= stewardship
				prowess >= intrigue
				prowess >= learning
			}
			modifier = {
				add = 150
				culture = {
					has_cultural_parameter = much_more_likely_to_be_laamps
				}
			}
			modifier = {
				add = 50
				culture = {
					has_cultural_parameter = more_likely_to_be_laamps
				}
			}
		}
	}
	
	# Larry Loner of the Clan McNoMates.
	option = {
		name = ep3_laamps.1001.g

		if = {
			limit = {
				any_courtier = { count <= 0 }
			}
			custom_tooltip = ep3_laamps.1001.g.tt.difficulty
		}
		else = { custom_tooltip = ep3_laamps.1001.g.tt.followers }

		# No stress for mechanical events.
		ai_chance = {
			# Player opt out.
			base = 0
		}
	}
}

# Error suppression for the history files.
ep3_laamps.1002 = {
	hidden = yes
	orphan = yes

	immediate = { set_variable = special_laamp_char }
}

##################################################
# Sworn by the Sword
# by Ewan Cowhig Croft
# 1011 - 1020
##################################################

#	You extract an oath of loyalty from one of your knights.
ep3_laamps.1011 = {
	type = character_event
	title = ep3_laamps.1011.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = { exists = scope:tiles_misc }
				desc = ep3_laamps.1011.desc.four_plus_titles
			}
			triggered_desc = {
				trigger = { exists = scope:title_3 }
				desc = ep3_laamps.1011.desc.three_titles
			}
			triggered_desc = {
				trigger = { exists = scope:title_2 }
				desc = ep3_laamps.1011.desc.two_titles
			}
			triggered_desc = {
				trigger = { exists = scope:title_1 }
				desc = ep3_laamps.1011.desc.one_title
			}
		}
		desc = ep3_laamps.1011.desc.midtro
		first_valid = {
			triggered_desc = {
				trigger = { has_character_flag = has_sworn_sword_before }
				desc = ep3_laamps.1011.desc.prior_swords
			}
			desc = ep3_laamps.1011.desc.first_sword
		}
		desc = ep3_laamps.1011.desc.outro
	}
	theme = realm
	left_portrait = {
		character = scope:actor
		animation = personality_bold
	}
	right_portrait = {
		character = scope:recipient
		animation = throne_room_kneel_1
	}
	override_background = { reference = feast }

	immediate = {
		# Grab our random claims, as appropriate.
		if = {
			# We don't care about doing this for the robots.
			limit = { is_ai = no }
			ordered_claim = {
				limit = { tier >= tier_kingdom }
				order_by = {
					# Our basics.
					value = tier
					# If we once held them, boost them up the rankings.
					if = {
						limit = {
							any_past_holder = { this = root }
						}
						multiply = 10
					}
					# And if a relative holds them, boost those up too.
					else_if = {
						limit = {
							holder ?= { is_close_or_extended_family_of = root }
						}
						multiply = 5
					}
				}
				max = 4
				check_range_bounds = no
				# First title.
				if = {
					limit = {
						NOT = { exists = scope:title_1 }
					}
					save_scope_as = title_1
				}
				# Second title.
				else_if = {
					limit = {
						NOT = {
							this = scope:title_1
							exists = scope:title_2
						}
					}
					save_scope_as = title_2
				}
				# Third title.
				else_if = {
					limit = {
						NOT = {
							this = scope:title_1
							this = scope:title_2
							exists = scope:title_3
						}
					}
					save_scope_as = title_3
				}
				# Are there any other titles?
				else_if = {
					limit = {
						NOT = {
							this = scope:title_1
							this = scope:title_2
							this = scope:title_3
						}
					}
					save_scope_value_as = {
						name = tiles_misc
						value = yes
					}
				}
			}
		}
		# Add our hook.
		add_hook = {
			type = loyalty_hook
			target = scope:recipient
		}
		# And register that we've taken the event once before.
		add_character_flag = has_sworn_sword_before
	}

	# Mutual loyalty hook.
	option = {
		name = ep3_laamps.1011.a

		scope:recipient = {
			add_hook = {
				type = follower_oath_strong_hook
				target = scope:actor
			}
			add_opinion = {
				target = scope:actor
				modifier = trust_opinion
				opinion = 100
			}
		}

		stress_impact = {
			just = major_stress_impact_loss
			arbitrary = major_stress_impact_gain
		}
		ai_chance = {
			base = 1
			ai_value_modifier = { ai_honor = 2 }
		}
	}
	
	# One-way + weak hook.
	option = {
		name = ep3_laamps.1011.b

		scope:recipient = {
			add_hook = {
				type = follower_oath_hook
				target = scope:actor
			}
			add_opinion = {
				target = scope:actor
				modifier = respect_opinion
				opinion = 30
			}
		}

		ai_chance = {
			base = 1
			ai_value_modifier = { ai_rationality = 2 }
		}
	}
}

##################################################
# Camp Purpose Maintenance
# by Ewan Cowhig Croft
# 1021 - 1030
##################################################

#	Destroy any inappropriate buildings and upgrades.
ep3_laamps.1021 = {
	hidden = yes

	immediate = {
		if = {
			limit = {
				domicile = { 
					OR = {
						has_domicile_building = supply_tent_reserve_provisions
						has_domicile_construction = supply_tent_reserve_provisions
					}
				}
				NOT = { has_realm_law_flag = unlocks_supply_tent_reserve_provisions }
			}
			domicile = { remove_domicile_building = supply_tent_reserve_provisions }
		}
		if = {
			limit = {
				domicile = { 
					OR = {
						has_domicile_building = supply_tent_reserve_water
						has_domicile_construction = supply_tent_reserve_water
					}
				}
				NOT = { has_realm_law_flag = unlocks_supply_tent_reserve_water }
			}
			domicile = { remove_domicile_building = supply_tent_reserve_water }
		}
		if = {
			limit = {
				domicile = {
					OR = {
						has_domicile_building = supply_tent_climbing_gear
						has_domicile_construction = supply_tent_climbing_gear
					}
				}
				NOT = { has_realm_law_flag = unlocks_supply_tent_climbing_gear }
			}
			domicile = { remove_domicile_building = supply_tent_climbing_gear }
		}
		if = {
			limit = {
				domicile = {
					OR = {
						has_domicile_building = supply_tent_subdued_gear
						has_domicile_construction = supply_tent_subdued_gear
					}
				}
				NOT = { has_realm_law_flag = unlocks_supply_tent_subdued_gear }
			}
			domicile = { remove_domicile_building = supply_tent_subdued_gear }
		}
		if = {
			limit = {
				domicile = {
					OR = {
						has_domicile_building = barber_tent_reference_corpus
						has_domicile_construction = barber_tent_reference_corpus
					}
				}
				NOT = { has_realm_law_flag = unlocks_barber_tent_reference_corpus }
			}
			domicile = { remove_domicile_building = barber_tent_reference_corpus }
		}
		if = {
			limit = {
				domicile = {
					OR = {
						has_domicile_building = barber_tent_morticians_tools
						has_domicile_construction = barber_tent_morticians_tools
					}
				}
				NOT = { has_realm_law_flag = unlocks_barber_tent_morticians_tools }
			}
			domicile = { remove_domicile_building = barber_tent_morticians_tools }
		}
		if = {
			limit = {
				domicile = {
					OR = {
						has_domicile_building = baggage_train_siege_engineers
						has_domicile_construction = baggage_train_siege_engineers
					}
				}
				NOT = { has_realm_law_flag = unlocks_baggage_train_siege_engineers }
			}
			domicile = { remove_domicile_building = baggage_train_siege_engineers }
		}
		if = {
			limit = {
				domicile = {
					OR = {
						has_domicile_building = baggage_train_scribes
						has_domicile_construction = baggage_train_scribes
					}
				}
				NOT = { has_realm_law_flag = unlocks_baggage_train_scribes }
			}
			domicile = { remove_domicile_building = baggage_train_scribes }
		}
		if = {
			limit = {
				domicile = {
					OR = {
						has_domicile_building = baggage_train_proof_of_claims
						has_domicile_construction = baggage_train_proof_of_claims
					}
				}
				NOT = { has_realm_law_flag = unlocks_baggage_train_proof_of_claims }
			}
			domicile = { remove_domicile_building = baggage_train_proof_of_claims }
		}
		if = {
			limit = {
				domicile = {
					OR = {
						has_domicile_building = baggage_train_ransom_cages
						has_domicile_construction = baggage_train_ransom_cages
					}
				}
				NOT = { has_realm_law_flag = unlocks_baggage_train_ransom_cages }
			}
			domicile = { remove_domicile_building = baggage_train_ransom_cages }
		}
		if = {
			limit = {
				domicile = {
					OR = {
						has_domicile_building = baggage_train_negotiators
						has_domicile_construction = baggage_train_negotiators
					}
				}
				NOT = { has_realm_law_flag = unlocks_baggage_train_negotiators }
			}
			domicile = { remove_domicile_building = baggage_train_negotiators }
		}
		if = {
			limit = {
				domicile = {
					OR = {
						has_domicile_building = baggage_train_ascetics
						has_domicile_construction = baggage_train_ascetics
					}
				}
				NOT = { has_realm_law_flag = unlocks_baggage_train_ascetics }
			}
			domicile = { remove_domicile_building = baggage_train_ascetics }
		}
		if = {
			limit = {
				domicile = {
					OR = {
						has_domicile_building = camp_fire_local_hangers_on
						has_domicile_construction = camp_fire_local_hangers_on
					}
				}
				NOT = { has_realm_law_flag = unlocks_camp_fire_local_hangers_on }
			}
			domicile = { remove_domicile_building = camp_fire_local_hangers_on }
		}
		if = {
			limit = {
				domicile = {
					OR = {
						has_domicile_building = camp_fire_future_dreams
						has_domicile_construction = camp_fire_future_dreams
					}
				}
				NOT = { has_realm_law_flag = unlocks_camp_fire_future_dreams }
			}
			domicile = { remove_domicile_building = camp_fire_future_dreams }
		}
		if = {
			limit = {
				domicile = {
					OR = {
						has_domicile_building = camp_fire_nightly_debates
						has_domicile_construction = camp_fire_nightly_debates
					}
				}
				NOT = { has_realm_law_flag = unlocks_camp_fire_nightly_debates }
			}
			domicile = { remove_domicile_building = camp_fire_nightly_debates }
		}
		if = {
			limit = {
				domicile = {
					OR = {
						has_domicile_building = camp_fire_juicy_rumors
						has_domicile_construction = camp_fire_juicy_rumors
					}
				}
				NOT = { has_realm_law_flag = unlocks_camp_fire_juicy_rumors }
			}
			domicile = { remove_domicile_building = camp_fire_juicy_rumors }
		}
		if = {
			limit = {
				domicile = {
					OR = {
						has_domicile_building = proving_grounds_lockwagon
						has_domicile_construction = proving_grounds_lockwagon
					}
				}
				NOT = { has_realm_law_flag = unlocks_proving_grounds_lockwagon }
			}
			domicile = { remove_domicile_building = proving_grounds_lockwagon }
		}
		if = {
			limit = {
				domicile = {
					OR = {
						has_domicile_building = proving_grounds_martial_study
						has_domicile_construction = proving_grounds_martial_study
					}
				}
				NOT = { has_realm_law_flag = unlocks_proving_grounds_martial_study }
			}
			domicile = { remove_domicile_building = proving_grounds_martial_study }
		}
		if = {
			limit = {
				domicile = {
					OR = {
						has_domicile_building = proving_grounds_the_stick_game
						has_domicile_construction = proving_grounds_the_stick_game
					}
				}
				NOT = { has_realm_law_flag = unlocks_proving_grounds_the_stick_game }
			}
			domicile = { remove_domicile_building = proving_grounds_the_stick_game }
		}
		if = {
			limit = {
				domicile = {
					OR = {
						has_domicile_building = proving_grounds_bodyguard_drills
						has_domicile_construction = proving_grounds_bodyguard_drills
					}
				}
				NOT = { has_realm_law_flag = unlocks_proving_grounds_bodyguard_drills }
			}
			domicile = { remove_domicile_building = proving_grounds_bodyguard_drills }
		}
		if = {
			limit = {
				domicile = {
					OR = {
						has_domicile_building = camp_perimeter_extra_watch
						has_domicile_construction = camp_perimeter_extra_watch
					}
				}
				NOT = { has_realm_law_flag = unlocks_camp_perimeter_extra_watch }
			}
			domicile = { remove_domicile_building = camp_perimeter_extra_watch }
		}
		if = {
			limit = {
				domicile = {
					OR = {
						has_domicile_building = camp_perimeter_palisade
						has_domicile_construction = camp_perimeter_palisade
					}
				}
				NOT = { has_realm_law_flag = unlocks_camp_perimeter_palisade }
			}
			domicile = { remove_domicile_building = camp_perimeter_palisade }
		}
		if = {
			limit = {
				domicile = {
					OR = {
						has_domicile_building = camp_perimeter_ditch
						has_domicile_construction = camp_perimeter_ditch
					}
				}
				NOT = { has_realm_law_flag = unlocks_camp_perimeter_ditch }
			}
			domicile = { remove_domicile_building = camp_perimeter_ditch }
		}
	}
}

##################################################
# General LAAMP events
# by Nick Meredith
# 5000-5998
##################################################

# Poach for food
ep3_laamps.5000 = { 
	type = character_event
	title = ep3_laamps.5000.t
	desc = {
		desc = ep3_laamps.5000.desc
		first_valid = {
			triggered_desc = {
				trigger = {
					domicile = {
						provisions < provisions_privation_threshold_low
					}	
				}
				desc = ep3_laamps.5000.provisionslow
			}
			desc = ep3_laamps.5000.provisionsok
		}
		desc = ep3_laamps.5000.ending
	}
	theme = landless_adventurer
	left_portrait = {
		character = root
		animation = thinking
	}
	right_portrait = {
		character = scope:hunter
		animation = personality_rational
	}
	lower_center_portrait = {
		character = scope:local_lord
	}
	cooldown = { years = 10 }
	
	trigger = {
		#Standard checks
		has_ep3_dlc_trigger = yes
		has_government = landless_adventurer_government
		is_available = yes
		
		#Ensure we have a hunter
		any_courtier = {
			can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = root }
			age > 16
		}
		is_location_valid_for_travel_event_on_land = yes
		#Ensure we're in a place that's held by someone
		exists = location.county.holder

		is_vegetarian_trigger = no
	}
	
	weight_multiplier = {
		base = 1
		modifier = {
			factor = 2
			domicile = {
				provisions < provisions_privation_threshold_low
			}
		}
		modifier = {
			factor = 3
			location = {
				has_building_or_higher = royal_forest_01
			}
		}
		modifier = {
			factor = 1.5
			location = {
				has_holding = yes
			}
		}
	}
	
	immediate = {
		random_courtier = {
			limit = {
				can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = root }
				age > 16
			}
			save_scope_as = hunter
		}
		location.county.holder = {
			save_scope_as = local_lord
		}
		location = {
			save_scope_as = location
		}
	}
	
	#Petition them for rights to hunt
	option = { 
		name = ep3_laamps.5000.a

		flavor = ep3_laamps.5000.a.tt

		duel = {
			target = scope:local_lord
			skill = diplomacy

			40 = { #They agree
				desc = ep3_laamps.5000.a.success

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

				send_interface_toast = {
					type = event_toast_effect_good
					title = ep3_laamps.5000.a.success
					left_icon = root
					right_icon = scope:local_lord

					domicile ?= {
						change_provisions = medium_provisions_gain
					}
				}
			}

			40 = { #They agree, but insist on you paying
				desc = ep3_laamps.5000.a.failure

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

				send_interface_toast = {
					type = event_toast_effect_good
					title = ep3_laamps.5000.a.failure
					left_icon = root
					right_icon = scope:local_lord

					pay_short_term_gold = {
						target = scope:local_lord
						gold = 10
					}

					domicile ?= {
						change_provisions = medium_provisions_gain
					}
				}
			}

			10 = { #They refuse
				desc = ep3_laamps.5000.a.critfailure

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

				send_interface_toast = {
					type = event_toast_effect_bad
					title = ep3_laamps.5000.a.critfailure
					left_icon = root
					right_icon = scope:local_lord

					add_prestige = minor_prestige_loss
					add_stress = minor_stress_gain
				}
			}
		}

		stress_impact = {
			honest = miniscule_stress_impact_loss
			deceitful = medium_stress_impact_gain
		}

		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_boldness = 0.5 
			}
		}
	}
	
	#Risk it for the biscuit
	option = { 
		name = ep3_laamps.5000.b

		scope:hunter = {
			duel = {
				value = decent_skill_rating
				skill = prowess

				45 = { #They poach successfully
					desc = ep3_laamps.5000.b.success
					compare_modifier = {
						value = scope:duel_value
						multiplier = 3.5
						min = -49
					}
					min = 5
					root = {
						send_interface_toast = {
							type = event_toast_effect_good
							title = ep3_laamps.5000.b.success
							left_icon = root
							right_icon = scope:local_lord
							domicile ?= { change_provisions = medium_provisions_gain }
						}
					}
				}

				45 = { #They are caught and fined
					desc = ep3_laamps.5000.b.failure
					compare_modifier = {
						value = scope:duel_value
						multiplier = -3.5
						min = -49
					}
					min = 5
					root = {
						send_interface_toast = {
							type = event_toast_effect_bad
							title = ep3_laamps.5000.b.failure
							left_icon = root
							right_icon = scope:local_lord
							pay_short_term_gold = {
								target = scope:local_lord
								gold = 10
							}
							domicile ?= { change_provisions = minor_provisions_gain }
						}
					}
				}

				10 = { #They are caught and imprisoned!
					desc = ep3_laamps.5000.b.critfailure
					compare_modifier = {
						value = scope:duel_value
						multiplier = -3.5
						min = -49
					}
					min = 1
					root = {
						send_interface_toast = {
							type = event_toast_effect_bad
							title = ep3_laamps.5000.b.critfailure
							left_icon = root
							right_icon = scope:local_lord

							scope:local_lord = {
								imprison = {
									target = scope:hunter
									type = dungeon
								}
							}
						}
					}
				}
			}
		}

		stress_impact = {
			honest = medium_stress_impact_gain
			deceitful = miniscule_stress_impact_loss
		}

		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_greed = 1
			}
		}
	}
	
	#Forage for berries n stuff
	option = { 
		name = ep3_laamps.5000.c

		random_list = {
			10 = { #You find provisions
				desc = ep3_laamps.5000.c.success

				send_interface_toast = {
					type = event_toast_effect_good
					title = ep3_laamps.5000.c.success
					left_icon = root
					right_icon = scope:hunter

					domicile ?= {
						change_provisions = {
							value = { miniscule_provisions_gain minor_provisions_gain }
						}
					}
				}
			}

			5 = { #You don't find provisions
				desc = ep3_laamps.5000.c.failure

				send_interface_toast = {
					type = event_toast_effect_bad
					title = ep3_laamps.5000.c.failure
					left_icon = root
					right_icon = scope:hunter

					add_stress = minor_stress_gain
					add_character_modifier = {
						modifier = ep3_supply_issues_modifier
						years = 5
					}
				}
			}
		}

		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_greed = -0.5
			}
		}
	}
}

# Meet a wandering priest
ep3_laamps.5005 = { 
	type = character_event
	title = ep3_laamps.5005.t
	desc = {
		desc = ep3_laamps.5005.desc
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:priest.faith = root.faith
				}
				desc = ep3_laamps.5005.samefaith
			}
			desc = ep3_laamps.5005.difffaith
		}
	}
	theme = landless_adventurer
	override_background = { reference = bp1_bonfire }
	left_portrait = {
		character = root
		animation = shock
	}
	right_portrait = {
		character = scope:priest
		animation = obsequious_bow
	}
	cooldown = { years = 10 }
	
	trigger = {
		#Standard checks
		has_ep3_dlc_trigger = yes
		has_government = landless_adventurer_government
		is_location_valid_for_travel_event_on_land = yes
		#Ensure we're in a place that's held by someone
		exists = location.county.holder
	}
	
	weight_multiplier = {
		base = 1
		modifier = {
			factor = 3
			OR = {
				faith = { has_doctrine = tenet_mendicant_preachers } 
				location.county.holder.faith = { has_doctrine = tenet_mendicant_preachers } 
			}
		}
	}
	
	immediate = {
		create_character = {
			template = mendicant_mystic_character
			gender_female_chance = root_soldier_female_chance
			age = { 35 65 }
			location = root.location
			culture = root.location.county.culture
			faith = root.location.county.faith
			save_scope_as = priest
			after_creation = {
				add_character_flag = created
			}
		}
		location.county.holder = {
			save_scope_as = location_holder
		}
		location = {
			save_scope_as = location
		}
		# Plus give 'em a nickname.
		hidden_effect = {
			scope:priest = { assign_random_nickname_effect = yes }
		}
	}
	
	#Ask him to join your followers
	option = { 
		name = ep3_laamps.5005.a

		duel = {
			target = scope:priest
			skill = diplomacy

			50 = { #They agree
				desc = ep3_laamps.5005.a.success

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

				send_interface_toast = {
					type = event_toast_effect_good
					title = ep3_laamps.5005.a.success
					left_icon = root
					right_icon = scope:priest

					add_courtier = scope:priest

					if = {
						limit = {
							scope:priest.faith = root.faith
						}
						add_character_modifier = {
							modifier = ep3_priest_friend_same_modifier
							years = 5
						}
					}
					else = {
						add_character_modifier = {
							modifier = ep3_priest_friend_different_modifier
							years = 5
						}
					}
				}
			}

			50 = { #They don't want to stay
				desc = ep3_laamps.5005.a.failure

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

				send_interface_toast = {
					type = event_toast_effect_bad
					title = ep3_laamps.5005.a.failure
					left_icon = root
					right_icon = scope:priest

					add_stress = miniscule_stress_gain
				}
			}
		}

		stress_impact = {
			generous = miniscule_stress_impact_loss
			callous = medium_stress_impact_gain
		}

		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_boldness = 0.5 
			}
		}
	}
	
	#Invite him to sit and stay a night
	option = { 
		name = ep3_laamps.5005.b

		if = {
			limit = {
				NOT = {
					has_trait = lifestyle_traveler
				}
			}
			add_trait = lifestyle_traveler
			add_trait_xp = {
				trait = lifestyle_traveler
				track = travel
				value = {
					integer_range = {
						min = 10
						max = 25
					}
				}
			}
		}
		else = {
			add_trait_xp = {
				trait = lifestyle_traveler
				track = travel
				value = {
					integer_range = {
						min = 10
						max = 25
					}
				}
			}
		}

		stress_impact = {
			paranoid = minor_stress_impact_gain
			trusting = miniscule_stress_impact_loss
		}

		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_compassion = 1
			}
		}
	}
	
	#Turn him away
	option = { 
		name = ep3_laamps.5005.c

		trigger = {
			scope:priest.faith = root.faith
		}

		flavor = ep3_laamps.5005.c.tt

		every_courtier = {
			limit = {
				faith != scope:priest.faith
			}
			custom = every_non_faith_follower
			add_opinion = {
				modifier = pleased_opinion
				target = root
				opinion = 15
			}
		}

		add_character_modifier = {
			modifier = ep3_ungodly_hospitality_modifier
			years = 5
		}

		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_honor = -1
			}
		}
	}

	#Turn him away, since he's a heretic
	option = { 
		name = ep3_laamps.5005.d

		trigger = {
			scope:priest.faith != root.faith
		}

		add_piety = medium_piety_value

		add_character_modifier = {
			modifier = ep3_inflexible_worshipper_modifier
			years = 10
		}

		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_zeal = 1
			}
		}
	}

	after = {
		scope:priest ?= {
			silent_disappearance_ai_if_created_effect = yes
		}
	}
}

# The rough life begins to hurt
ep3_laamps.5010 = { 
	type = character_event
	title = ep3_laamps.5010.t
	desc = ep3_laamps.5010.desc
	theme = landless_adventurer
	left_portrait = {
		character = root
		animation = thinking
	}
	right_portrait = {
		character = scope:follower
		animation = pain
	}
	cooldown = { years = 10 }
	
	trigger = {
		#Standard checks
		has_ep3_dlc_trigger = yes
		has_government = landless_adventurer_government
		age < 65 #Just for loc tonality
		is_location_valid_for_travel_event_on_land = yes
		any_courtier = {
			is_valid_active_event_recurrer_trigger = { LIEGE = ROOT }
			is_adult = yes # is an adult
			age < 65 # but not too old, so wincing in pain isn't just from being real old
		}
	}
	
	immediate = {
		random_courtier = {
			limit = {
				is_valid_active_event_recurrer_trigger = { LIEGE = ROOT }
				is_adult = yes # is an adult
				age < 65 # but not too old, so wincing in pain isn't just from being real old
			}
			save_scope_as = follower
		}
		location = {
			save_scope_as = location
		}
		if = {
			limit = {
				domicile = { has_domicile_building = camp_main_01 }
			}
			save_scope_value_as = {
				name = gold_cost
				value = {
					value = camp_main_02_domicile_building_gold_cost_value
					multiply = 0.5
					ceiling = yes
				}
			}
		}
		else_if = {
			limit = {
				domicile = { has_domicile_building = camp_main_02 }
			}
			save_scope_value_as = {
				name = gold_cost
				value = {
					value = camp_main_03_domicile_building_gold_cost_value
					multiply = 0.5
					ceiling = yes
				}
			}
		}
		else = {
			save_scope_value_as = {
				name = gold_cost
				value = {
					value = camp_main_04_domicile_building_gold_cost_value
					multiply = 0.5
					ceiling = yes
				}
			}
		}
	}
	
	#Buy some beds at an inn for the night
	option = { 
		name = ep3_laamps.5010.a

		remove_short_term_gold = minor_gold_value

		add_character_modifier = {
			modifier = ep3_rested_and_refreshed_modifier
			years = 5
		}

		every_courtier = {
			custom = every_follower_custom
			add_opinion = {
				modifier = grateful_opinion
				target = root
				opinion = 15
			}
			add_character_modifier = {
				modifier = ep3_rested_and_refreshed_modifier
				years = 5
			}
		}		

		stress_impact = {
			base = medium_stress_impact_loss
			generous = miniscule_stress_impact_loss
			greedy = medium_stress_impact_gain
			compassionate = miniscule_stress_impact_loss
			callous = medium_stress_impact_gain
		}

		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_compassion = 1 
			}
		}
	}
	
	#Build a Pavilion upgrade at a discount
	option = { 
		name = ep3_laamps.5010.b
		trigger = {
			NOT = {
				domicile = { has_domicile_building = camp_main_04 }
			}
			gold >= scope:gold_cost
		}
		show_as_unavailable = {
			NOT = {
				domicile = { has_domicile_building = camp_main_04 }
			}
			gold <= scope:gold_cost
		}
		custom_tooltip = ep3_laamps.5010.b.tt
		remove_short_term_gold = scope:gold_cost
		domicile = {
			if = {
				limit = { has_domicile_building_or_higher = camp_main_01 }
				switch = {
					trigger = has_domicile_building
					camp_main_01 = { add_domicile_building = camp_main_02 }
					camp_main_02 = { add_domicile_building = camp_main_03 }
					camp_main_03 = { add_domicile_building = camp_main_04 }
				}
			}
		}
		stress_impact = {
			ambitious = miniscule_stress_impact_loss
			content = minor_stress_impact_gain
		}

		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_boldness = 1
			}
		}
	}
	
	#Soldier on
	option = { 
		name = ep3_laamps.5010.c

		random_list = {
			10 = { #It works out
				desc = ep3_laamps.5010.c.success
				modifier = {
					add = 2
					scope:location = {
						OR = {
							terrain = farmlands
							terrain = plains
							terrain = oasis
							terrain = forest
						}
					}
				}
				send_interface_toast = {
					type = event_toast_effect_good
					title = ep3_laamps.5010.c.success
					left_icon = root
					right_icon = scope:follower

					add_stress = minor_stress_loss
				}
			}

			5 = { #It doesn't work out
				desc = ep3_laamps.5010.c.failure
				modifier = {
					add = 5
					age > 35
				}
				modifier = {
					add = 5
					age > 50
				}
				modifier = {
					add = 2
					scope:location = {
						OR = {
							terrain = desert
							terrain = mountains
							terrain = desert_mountains
							terrain = wetlands
						}
					}
				}
				send_interface_toast = {
					type = event_toast_effect_bad
					title = ep3_laamps.5010.c.failure
					left_icon = root
					right_icon = scope:hunter

					add_stress = minor_stress_gain
					add_character_modifier = {
						modifier = ep3_cricked_neck_modifier
						years = 5
					}
				}
			}
		}

		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_greed = 1
			}
		}
	}
}

# Offer a life to hardened fighters
ep3_laamps.5015 = { 
	type = character_event
	title = ep3_laamps.5015.t
	desc = ep3_laamps.5015.desc
	theme = landless_adventurer
	left_portrait = {
		character = root
		animation = interested
	}
	right_portrait = {
		character = scope:knight
		animation = beg
	}
	artifact = {
		target = scope:newly_created_artifact
		position = lower_center_portrait
	}
	cooldown = { years = 35 }
	
	trigger = {
		#Standard checks
		has_ep3_dlc_trigger = yes
		has_government = landless_adventurer_government
		is_location_valid_for_travel_event_on_land = yes
	}

	weight_multiplier = {
		base = 1
		modifier = {
			factor = 2
			domicile = {
				provisions > provisions_threshold_good_value
			}
		}
		modifier = {
			factor = 2
			location.county = {
				county_control < full_county_control
			}
		}
	}

	immediate = {
		location = {
			save_scope_as = location
		}
		if = {
			limit = {
				any_pool_character = {
					province = root.location
					is_available_ai_adult = yes
					NOT = {
						has_any_good_relationship_with_root_trigger = yes
					}
					can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = root }
				}
			}
			random_pool_character = {
				province = root.location
				limit = {
					is_available_ai_adult = yes
					NOT = {
						has_any_good_relationship_with_root_trigger = yes
					}
					can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = root }
				}
				save_scope_as = knight
			}
		}
		else = {
			create_character = {
				template = honorable_soldier_character
				location = root.location
				culture = location.culture
				faith = location.faith
				gender_female_chance = root_soldier_female_chance
				dynasty = none
				save_scope_as = knight
				after_creation = {
					add_character_flag = created
				}
			}
		}
		hidden_effect = {
			if = {
				limit = {
					OR = {
						has_trait = callous
						has_trait = sadistic
						has_trait = gallowsbait
					}
				}
				scope:knight = {
					create_artifact_brooch_effect = {
						OWNER = scope:knight
						SMITH = scope:knight
					}
					add_gold = { 15 35 }
				}
				scope:newly_created_artifact = {
					add_artifact_modifier = artifact_prowess_2_modifier
					add_artifact_modifier = artifact_knight_effectiveness_2_modifier
					set_artifact_rarity = masterwork
				}
			}
			scope:knight = {
				change_current_weight = -100
				# Plus give 'em a nickname.
				assign_random_nickname_effect = yes
			}
		}
	}

	#Rob him
	option = { 
		name = ep3_laamps.5015.a

		trigger = {
			OR = {
				has_trait = callous
				has_trait = sadistic
				has_trait = gallowsbait
			}
		}

		flavor = ep3_laamps.5015.a.tt

		scope:knight = {
			pay_short_term_gold = {
				target = root
				gold = {
					value = scope:knight.gold
					min = 5
				}
			}
		}

		scope:newly_created_artifact = {
			set_owner = root
		}

		if = {
			limit = {
				has_trait = gallowsbait
			}
			add_trait_xp = {
				trait = gallowsbait
				track = bandit
				value = {
					integer_range = {
						min = 5
						max = 15
					}
				}
			}
		}
		else = {
			add_trait = gallowsbait
			add_trait_xp = {
				trait = gallowsbait
				track = bandit
				value = {
					integer_range = {
						min = 5
						max = 15
					}
				}
			}
		}

		stress_impact = {
			base = miniscule_stress_impact_loss
			compassionate = medium_stress_impact_gain
			just = medium_stress_impact_gain
		}

		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_greed = 1
				ai_compassion = -1
			}
		}
	}

	#Bring 'em all
	option = { 
		name = ep3_laamps.5015.b

		trigger = {
			maa_regiments_count >= 1
		}

		domicile = {
			change_provisions = minor_provisions_loss
		}

		reinforce_soldiers_regiment_effect = yes

		add_courtier = scope:knight
		scope:knight = {
			set_knight_status = force
		}

		remove_short_term_gold = { 10 30 }

		stress_impact = {
			generous = miniscule_stress_impact_loss
			greedy = medium_stress_impact_gain
			compassionate = miniscule_stress_impact_loss
			callous = medium_stress_impact_gain
		}

		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_compassion = 1 
			}
		}
	}
	
	#Hire the fella as a knight
	option = { 
		name = ep3_laamps.5015.c

		add_courtier = scope:knight
		scope:knight = {
			set_knight_status = force
		}

		stress_impact = {
			generous = miniscule_stress_impact_loss
			paranoid = minor_stress_impact_gain
		}

		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_boldness = 1
			}
		}
	}
	
	#Offer them a place to rest, but only that
	option = { 
		name = ep3_laamps.5015.d

		domicile = {
			change_provisions = microscopic_provisions_loss
		}

		random = {
			chance = 25
			send_interface_toast = {
				type = event_toast_effect_good
				title = ep3_laamps.5015.c.success
				left_icon = root

				add_character_modifier = {
					modifier = ep3_friend_to_old_soldiers_modifier
					years = 30
				}
			}
		}

		stress_impact = {
			greedy = miniscule_stress_impact_loss
			generous = minor_stress_impact_gain
		}

		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_greed = 1
			}
		}
	}
	after = {
		scope:knight = {
			silent_disappearance_ai_if_created_effect = yes
		}
	}
}

# Learn new local recipes
ep3_laamps.5020 = { 
	type = character_event
	title = ep3_laamps.5020.t
	desc = ep3_laamps.5020.desc
	theme = landless_adventurer
	left_portrait = {
		character = root
		animation = thinking
	}
	right_portrait = {
		character = scope:cook
		animation = personality_compassionate
	}
	cooldown = { years = 10 }
	
	trigger = {
		#Standard checks
		has_ep3_dlc_trigger = yes
		has_government = landless_adventurer_government
		is_location_valid_for_travel_event_on_land = yes
		culture != location.culture
		any_courtier = {
			is_available_ai_adult = yes
			count >= 1
		}
		culture = {
			cultural_acceptance = {
				target = root.location.culture
				value <= 75
			}
		}
	}

	weight_multiplier = {
		base = 1
		modifier = {
			factor = 2
			domicile = {
				provisions < provisions_threshold_good_value
			}
		}
	}

	immediate = {
		location = {
			save_scope_as = location
		}
		location.culture = {
			save_scope_as = local_culture
		}
		culture = {
			save_scope_as = culture
		}
		random_courtier = {
			limit = {
				is_available_ai_adult = yes
			}
			save_scope_as = cook
		}
		save_scope_value_as = {
			name = food_range
			value = {
				integer_range = {
					min = 1
					max = 20
				}
			}
		}
	}

	#Suggest a *special* new addition
	option = { 
		name = ep3_laamps.5020.a

		trigger = {
			has_trait = cannibal
		}

		flavor = ep3_laamps.5020.a.tt

		random = {
			chance = 50

			send_interface_toast = {
				type = event_toast_effect_good
				title = ep3_laamps.5020.a.tt
				left_icon = root
				right_icon = scope:cook

				scope:cook = {
					add_secret = { type = secret_cannibal }
					random_secret = {
						type = secret_cannibal
						reveal_to = root
					}
					add_opinion = {
						target = root
						modifier = impressed_opinion
						opinion = 40
					}
				}
				random_secret = {
					type = secret_cannibal
					reveal_to = scope:cook
				}
			}
		}

		add_character_modifier = {
			modifier = ep3_new_tastes_cannibal_modifier
			years = 10
		}

		stress_impact = {
			base = medium_stress_impact_loss
		}

		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_boldness = 1
			}
		}
	}

	#Suggest fusion cuisine
	option = { 
		name = ep3_laamps.5020.b

		trigger = {
			custom_tooltip = {
				text = ep3_laamps.5020.tt
				OR = {
					has_trait = lifestyle_traveler
					has_trait = eccentric
					has_trait = gluttonous
				}
			}
		}

		show_as_unavailable = {
			always = yes
		}

		trait = lifestyle_traveler
		trait = eccentric
		trait = gluttonous

		domicile = {
			change_provisions = medium_provisions_gain
		}

		add_character_modifier = {
			modifier = ep3_expanded_culinary_horizons_modifier
			years = 15
		}

		every_courtier = {
			custom = every_follower_custom
			add_character_modifier = {
				modifier = ep3_new_tastes_modifier
				years = 10
			}
		}

		stress_impact = {
			base = minor_stress_impact_loss
			gluttonous = medium_stress_impact_loss
			inappetetic = medium_stress_impact_gain
		}

		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_greed = 1
			}
		}
	}

	#Try some of this local cuisine
	option = { 
		name = ep3_laamps.5020.c

		random_list = {
			45 = {
				desc = ep3_laamps.5020.c.success
				modifier = { #This is for fuzzying up the random list so it randomises it a bit
					add = scope:food_range
				}
				send_interface_toast = {
					type = event_toast_effect_good
					title = ep3_laamps.5020.c.success
					left_icon = root

					domicile = {
						change_provisions = medium_provisions_gain
					}
					add_character_modifier = {
						modifier = ep3_new_tastes_modifier
						years = 10
					}
					scope:cook = {
						add_opinion = {
							target = root
							modifier = pleased_opinion
							opinion = 15
						}
					}
					culture = {
						change_cultural_acceptance = {
							target = scope:local_culture
							value = miniscule_positive_culture_acceptance
							desc = cultural_acceptance_gain_food_acceptance
						}
					}
				}
			}
			55 = {
				desc = ep3_laamps.5020.c.failure
				send_interface_toast = {
					type = event_toast_effect_bad
					title = ep3_laamps.5020.c.failure
					left_icon = root

					add_stress = minor_stress_gain
				}
			}
		}

		stress_impact = {
			gluttonous = minor_stress_impact_loss
			arrogant = minor_stress_impact_gain
			humble = miniscule_stress_impact_loss
			inappetetic = medium_stress_impact_gain
		}

		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_compassion = 1 
			}
		}
	}
	
	#Refuse to try it
	option = { 
		name = ep3_laamps.5020.d

		random = {
			chance = 30
			modifier = {
				is_ai = yes
				add = -29
			}
			send_interface_toast = {
				type = event_toast_effect_good
				title = ep3_laamps.5020.d.tt
				left_icon = root

				give_nickname = nick_the_narrow_minded 
			}
		}

		stress_impact = {
			generous = miniscule_stress_impact_loss
			paranoid = minor_stress_impact_gain
		}

		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_boldness = 1
			}
		}
	}
}


scripted_trigger 5025_can_spawn_contract_trigger = {
	can_create_criminal_contract_trigger = { LAAMP = $LAAMP$ EMPLOYER = $EMPLOYER$ }
	can_create_diplomacy_contract_trigger = { LAAMP = $LAAMP$ EMPLOYER = $EMPLOYER$ }
	can_create_hireling_contract_trigger = { LAAMP = $LAAMP$ EMPLOYER = $EMPLOYER$ }
	can_create_justicar_contract_trigger = { LAAMP = $LAAMP$ EMPLOYER = $EMPLOYER$ }
	can_create_learning_contract_trigger = { LAAMP = $LAAMP$ EMPLOYER = $EMPLOYER$ }
	can_create_intrigue_contract_trigger = { LAAMP = $LAAMP$ EMPLOYER = $EMPLOYER$ }
	can_create_stewardship_contract_trigger = { LAAMP = $LAAMP$ EMPLOYER = $EMPLOYER$ }
	can_create_transport_contract_trigger = { LAAMP = $LAAMP$ EMPLOYER = $EMPLOYER$ }
}

# What is your purpose?
ep3_laamps.5025 = { 
	type = character_event
	title = ep3_laamps.5025.t
	desc = ep3_laamps.5025.desc
	theme = landless_adventurer
	left_portrait = {
		character = root
		animation = thinking
	}
	cooldown = { years = 30 }
	
	trigger = {
		#Standard checks
		has_ep3_dlc_trigger = yes
		has_government = landless_adventurer_government
	}

	immediate = {
		if = {
			limit = { exists = location.barony.holder }
			location.barony.holder = {
				save_scope_as = local_lord
				save_scope_as = bg_override_char
				#Find potential employers
				if = {
					limit = {
						5025_can_spawn_contract_trigger = { LAAMP = root EMPLOYER = scope:local_lord }
					}
					add_to_temporary_list = potential_employers_list
				}
				every_vassal_or_below ?= {
					limit = {
						save_temporary_scope_as = vassal_check
						5025_can_spawn_contract_trigger = { LAAMP = root EMPLOYER = scope:vassal_check }
					}
					add_to_temporary_list = potential_contract_employers 
				}
			}
			#Can we _actually_ spawn two contracts?
			if = {
				limit = {
					any_in_list = {
						list = potential_contract_employers
						count >= 2 
					}
				}
				save_scope_as = spawn_task_contract_option_available
			}
		}
	}

	#I wanna be landed!
	option = { 
		name = ep3_laamps.5025.a

		add_character_modifier = {
			modifier = ep3_lust_for_land_modifier
			years = 35
		}

		stress_impact = {
			greedy = miniscule_stress_impact_loss
			ambitious = minor_stress_impact_loss
			humble = medium_stress_impact_gain
		}

		ai_chance = {
			base = 100
			modifier = {
				factor = 0
				has_trait = humble
			}
			ai_value_modifier = {
				ai_greed = 1
			}
		}
	}

	#I like being landless :)
	option = { 
		name = ep3_laamps.5025.b
		flavor = ep3_laamps.5025.b.flavor

		if = {
			limit = {
				NOT = {
					has_trait = lifestyle_traveler
				}
			}
			add_trait = lifestyle_traveler
			add_trait_xp = {
				trait = lifestyle_traveler
				track = travel
				value = {
					integer_range = {
						min = 10
						max = 30
					}
				}
			}
		}
		else = {
			add_trait_xp = {
				trait = lifestyle_traveler
				track = travel
				value = {
					integer_range = {
						min = 10
						max = 30
					}
				}
			}
		}

		#Can we _actually_ spawn contracts...
		if = {
			limit = { exists = scope:spawn_task_contract_option_available }
			add_prestige = minor_prestige_gain
			custom_tooltip = ep3_laamps.5025.b.tt
			contract_passive_spawn_effect = {
				SPAWN_CONTRACTS = 2
			}
		}
		else = {
			add_prestige = medium_prestige_gain
		}

		stress_impact = {
			ambitious = medium_stress_impact_gain
			humble = minor_stress_impact_loss
		}

		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_boldness = -1
			}
		}
	}
	
	#It's best to keep options open
	option = { 
		name = ep3_laamps.5025.c

		flavor = ep3_laamps.5025.c.flavor

		if = {
			limit = {
				NOT = {
					has_trait = flexible_leader
				}
			}
			random = {
				chance = 65
				send_interface_toast = {
					type = event_toast_effect_good
					title = ep3_laamps.5025.c.toast
					left_icon = root

					add_trait = flexible_leader 
				}
			}
		}
		else = {
			add_stress = medium_stress_loss
		}

		domicile = {
			change_provisions = medium_provisions_gain
		}

		stress_impact = {
			fickle = medium_stress_impact_loss
			stubborn = medium_stress_impact_gain
		}

		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_rationality = 1
			}
		}
	}
}

# Local tavern owner disrespects you
ep3_laamps.5030 = { 
	type = character_event
	title = ep3_laamps.5030.t
	desc = ep3_laamps.5030.desc
	theme = landless_adventurer
	left_portrait = {
		character = root
		animation = anger
	}
	right_portrait = {
		character = scope:innkeeper
		animation = dismissal
	}
	cooldown = { years = 10 }
	override_background = { reference = tavern }

	trigger = {
		#Standard checks
		has_ep3_dlc_trigger = yes
		has_government = landless_adventurer_government
		is_location_valid_for_travel_event_on_land = yes
	}

	weight_multiplier = {
		base = 1
		modifier = {
			factor = 2
			domicile = {
				provisions < provisions_threshold_good_value
			}
		}
	}

	immediate = {
		location = {
			save_scope_as = location
		}
		if = {
			limit = {
				any_pool_character = {
					province = root.location
					is_available_ai_adult = yes
					NOT = {
						has_any_good_relationship_with_root_trigger = yes
					}
				}
			}
			random_pool_character = {
				province = root.location
				limit = {
					is_available_ai_adult = yes
					NOT = {
						has_any_good_relationship_with_root_trigger = yes
					}
				}
				save_scope_as = innkeeper
			}
		}
		else = {
			create_character = {
				template = servant_character
				location = root.location
				culture = location.culture
				faith = location.faith
				gender_female_chance = {
					if = {
						limit = { root.faith = { has_doctrine = doctrine_gender_male_dominated } }
						add = 100
					}
					else_if = {
						limit = { root.faith = { has_doctrine = doctrine_gender_female_dominated } }
						add = 0
					}
					else = {
						add = 50
					}
				}
				dynasty = none
				save_scope_as = innkeeper
				after_creation = {
					add_character_flag = created
				}
			}
		}
	}

	#Ah, forget about it, give me a drink
	option = { 
		name = ep3_laamps.5030.a

		trigger = {
			has_trait = drunkard
		}

		remove_short_term_gold = tiny_gold_value

		add_character_modifier = {
			modifier = legend_hangover_modifier
			years = 3
		}

		stress_impact = {
			base = major_stress_impact_loss
		}

		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_greed = 1
			}
		}
	}

	#Don't you know who I am?
	option = { 
		name = ep3_laamps.5030.b

		trigger = {		
			dynasty = {
				dynasty_prestige_level >= medium_dynasty_prestige_level
			}
		}

		reason = ep3_laamps.5030.a.tt

		flavor = ep3_laamps.5030.b.tt

		add_internal_flag = special

		add_prestige = medium_prestige_gain

		add_character_modifier = {
			modifier = ep3_comfortable_bed_modifier
			years = 10
		}

		every_courtier = {
			custom = every_follower_custom
			add_opinion = {
				target = root
				modifier = pleased_opinion
				opinion = 35
			}
		}

		stress_impact = {
			base = minor_stress_impact_loss
			arrogant = minor_stress_impact_loss
			humble = medium_stress_impact_gain
		}

		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_boldness = 1
			}
		}
	}

	#Threaten them
	option = { 
		name = ep3_laamps.5030.c

		add_internal_flag = dangerous

		add_dread = medium_dread_gain

		random_list = {
			55 = { #They hand it over
				desc = ep3_laamps.5030.c.success

				send_interface_toast = {
					type = event_toast_effect_good
					title = ep3_laamps.5030.c.success
					left_icon = root
					right_icon = scope:innkeeper

					remove_short_term_gold = tiny_gold_value
					add_character_modifier = {
						modifier = ep3_comfortable_bed_modifier
						years = 10
					}
				}
			}
			25 = { #You have to threaten them further
				desc = ep3_laamps.5030.c.failure
				send_interface_toast = {
					type = event_toast_effect_bad
					title = ep3_laamps.5030.c.failure
					left_icon = root
					right_icon = scope:innkeeper

					if = {
						limit = {
							has_trait = gallowsbait
						}
						add_trait_xp = {
							trait = gallowsbait
							track = bandit
							value = {
								integer_range = {
									min = 10
									max = 20
								}
							}
						}
					}
					else = {
						add_trait = gallowsbait
						add_trait_xp = {
							trait = gallowsbait
							track = bandit
							value = {
								integer_range = {
									min = 10
									max = 20
								}
							}
						}
					}
				}
			}
			5 = { #It goes a little too far
				desc = ep3_laamps.5030.c.critfailure

				send_interface_toast = {
					type = event_toast_effect_bad
					title = ep3_laamps.5030.c.critfailure
					left_icon = root
					right_icon = scope:innkeeper

					scope:innkeeper = {
						death = { killer = ROOT death_reason = death_murder }
					}

					add_secret = {
						type = secret_murder
						target = scope:innkeeper
					}

					if = {
						limit = {
							has_trait = gallowsbait
						}
						add_trait_xp = {
							trait = gallowsbait
							track = marauder
							value = {
								integer_range = {
									min = 25
									max = 40
								}
							}
						}
					}
					else = {
						add_trait = gallowsbait
						add_trait_xp = {
							trait = gallowsbait
							track = marauder
							value = {
								integer_range = {
									min = 25
									max = 40
								}
							}
						}
					}
				}
			}
		}

		stress_impact = {
			generous = miniscule_stress_impact_loss
			paranoid = minor_stress_impact_gain
		}

		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_honor = -1
			}
		}
	}

	#Try to barter
	option = { 
		name = ep3_laamps.5030.d

		duel = {
			target = scope:innkeeper
			skill = diplomacy
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				desc = ep3_laamps.5030.d.success
				min = 5
				send_interface_toast = {
					type = event_toast_effect_good
					title = ep3_laamps.5030.d.success
					left_icon = root
					right_icon = scope:innkeeper

					remove_short_term_gold = minor_gold_value
					add_character_modifier = {
						modifier = ep3_comfortable_bed_modifier
						years = 10
					}
				}
			}
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				desc = ep3_laamps.5030.d.failure
				min = 5
				send_interface_toast = {
					type = event_toast_effect_bad
					title = ep3_laamps.5030.d.failure
					left_icon = root
					right_icon = scope:innkeeper

					add_stress = minor_stress_gain
				}
			}
		}

		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_compassion = 1 
			}
		}
	}

	#Take the insult
	option = { 
		name = tournament_events.0161.c
		
		stress_impact = {
			base = minor_stress_gain
			arrogant = minor_stress_impact_gain
		}

		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_compassion = 1 
			}
		}
	}
	
	after = {
		scope:innkeeper = {
			silent_disappearance_ai_if_created_effect = yes
		}
	}
}

# Hire a local guide
ep3_laamps.5035 = {
	type = character_event
	title = ep3_laamps.5035.t
	desc = ep3_laamps.5035.desc
	theme = landless_adventurer
	override_background = {
		reference = terrain 
	}
	left_portrait = {
		character = root
		animation = chancellor
	}
	right_portrait = {
		character = scope:guide
		animation = scheme
	}
	artifact = {
		target = scope:newly_created_map
		position = lower_right_portrait
	}
	artifact = {
		trigger = {
			exists = scope:random_artifact
		}
		target = scope:random_artifact
		position = lower_left_portrait
	}
	cooldown = { years = 50 }

	trigger = {
		static_group_filter = {
			group = ep3_laamps.5035
			match = 0.75
		}
		#Standard checks
		has_ep3_dlc_trigger = yes
		has_government = landless_adventurer_government
		is_location_valid_for_travel_event_on_land = yes
	}

	weight_multiplier = {
		base = 1
		modifier = {
			factor = 2
			location = {
				OR = {
					terrain = mountains
					terrain = wetlands
					terrain = desert_mountains
					terrain = jungle
				}
			}
		}
	}

	immediate = {
		location = {
			save_scope_as = location
		}
		if = { #Grab a random, inexpensive artifact if you have it
			limit = {
				any_character_artifact = {
					NOT = {
						has_artifact_modifier = artifact_guide_map_modifier
					}
					artifact_can_be_gift_to_trigger = { RECIPIENT = scope:guide }
				}
			}
			random_character_artifact = {
				limit = {
					NOT = {
						has_artifact_modifier = artifact_guide_map_modifier
					}
					artifact_can_be_gift_to_trigger = { RECIPIENT = scope:guide }
				}
				weight = {
					base = 1
					modifier = {
						rarity = common
						add = 2
					}
				}
				save_scope_as = random_artifact
			}
		}
		if = {
			limit = {
				any_pool_character = {
					province = root.location
					is_available_ai_adult = yes
					NOT = {
						has_any_good_relationship_with_root_trigger = yes
					}
				}
			}
			random_pool_character = {
				province = root.location
				limit = {
					is_available_ai_adult = yes
					NOT = {
						has_any_good_relationship_with_root_trigger = yes
					}
				}
				save_scope_as = guide
			}
		}
		else = {
			create_character = {
				template = anatolian_guide_character
				location = root.location
				culture = location.culture
				faith = location.faith
				gender_female_chance = 50
				dynasty = none
				save_scope_as = guide
				after_creation = {
					add_character_flag = created
				}
			}
			# Plus give 'em a nickname.
			hidden_effect = {
				scope:guide = { assign_random_nickname_effect = yes }
			}
		}
		hidden_effect = {
			scope:guide = {
				create_artifact = {
					name = guide_map
					description = guide_map_desc
					modifier = artifact_guide_map_modifier
					type = miscellaneous
					visuals = pocket_map
					history = {
						type = created_before_history
						actor = scope:guide
					}
					save_scope_as = newly_created_map
				}
			}
			scope:newly_created_map = {
				set_artifact_rarity = masterwork
				set_max_durability = 25
			}
		}
	}

	#Recruit them permanently
	option = { 
		name = ep3_laamps.5035.a

		pay_short_term_gold = {
			target = scope:guide
			gold = medium_gold_value
		}

		add_courtier = scope:guide

		court_position_grant_effect = {
			EMPLOYER = root
			POS = travel_leader
			CANDIDATE = scope:guide
		}

		stress_impact = {
			trusting = minor_stress_impact_loss
			paranoid = minor_stress_impact_gain
		}

		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_greed = -1
			}
		}
	}

	#Buy maps off them
	option = { 
		name = ep3_laamps.5035.b

		pay_short_term_gold = {
			target = scope:guide
			gold = medium_gold_value
		}

		scope:newly_created_map = {
			set_owner = root
		}

		stress_impact = {
			trusting = minor_stress_impact_gain
			paranoid = minor_stress_impact_loss
		}

		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_boldness = -1
			}
		}
	}

	#Trust their guidance
	option = { 
		name = ep3_laamps.5035.c

		pay_short_term_gold = {
			target = scope:guide
			gold = tiny_gold_value
		}

		random_list = {
			60 = { #The guide's info is correct
				desc = ep3_laamps.5035.c.success

				send_interface_toast = {
					type = event_toast_effect_good
					title = ep3_laamps.5035.c.success
					left_icon = root
					right_icon = scope:guide

					add_character_modifier = {
						modifier = ep3_well_guided_modifier
						years = 10
					}
				}
			}
			40 = { #The guide's info is sketchy
				desc = ep3_laamps.5035.c.failure
				send_interface_toast = {
					type = event_toast_effect_bad
					title = ep3_laamps.5035.c.failure
					left_icon = root
					right_icon = scope:guide

					add_character_modifier = {
						modifier = ep3_sketchy_guides_modifier
						years = 3
					}
				}
			}
			10 = { #The guide's info leads you into a trap!
				desc = ep3_laamps.5035.c.critfailure
				send_interface_toast = {
					type = event_toast_effect_bad
					title = ep3_laamps.5035.c.critfailure
					left_icon = root
					right_icon = scope:guide

					increase_wounds_no_death_effect = { REASON = fight }
					remove_short_term_gold = minor_gold_value
					scope:random_artifact ?= {
						set_owner = scope:guide
					}
				}
			}
		}

		stress_impact = {
			generous = miniscule_stress_impact_loss
			paranoid = minor_stress_impact_gain
		}

		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_honor = -1
			}
		}
	}

	#Reject them
	option = { 
		name = ep3_laamps.5035.d

		flavor = ep3_laamps.5035.d.tt

		random = {
			chance = 45
			send_interface_toast = {
				type = event_toast_effect_bad
				title = ep3_laamps.5035.d.toast
				left_icon = root

				domicile = {
					change_provisions = minor_provisions_loss
				}
			}
		}

		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_greed = 1 
			}
		}
	}
}

# Scouting reveals some potential hidden treasures
ep3_laamps.5040 = {
	type = character_event
	title = ep3_laamps.5040.t
	desc = ep3_laamps.5040.desc
	theme = landless_adventurer
	left_portrait = {
		character = root
		animation = jockey_idle
		camera = camera_event_horse_very_left
	}
	cooldown = { years = 10 }
	override_background = { reference = ep3_campfire }

	trigger = {
		#Standard checks
		has_ep3_dlc_trigger = yes
		has_government = landless_adventurer_government
		is_location_valid_for_travel_event_on_land = yes
	}

	immediate = {
		location = {
			save_scope_as = location
		}
		if = {
			limit = {
				any_pool_character = {
					province = root.location
					is_available_ai_adult = yes
					NOT = {
						has_any_good_relationship_with_root_trigger = yes
					}
				}
			}
			random_pool_character = {
				province = root.location
				limit = {
					is_available_ai_adult = yes
					NOT = {
						has_any_good_relationship_with_root_trigger = yes
					}
				}
				save_scope_as = merchant
			}
		}
		else = {
			create_character = {
				template = anatolian_guide_character
				location = root.location
				culture = location.culture
				faith = location.faith
				dynasty = none
				save_scope_as = merchant
				after_creation = {
					add_character_flag = created
				}
			}
			# Plus give 'em a nickname.
			hidden_effect = {
				scope:merchant = { assign_random_nickname_effect = yes }
			}
		}
	}

	#Go searching in the ruins
	option = { 
		name = ep3_laamps.5040.a

		random_list = {
			37 = { #You uncover a dusty sword
				desc = ep3_laamps.5040.a.bigsuccess
				random_dummy_gender_effect = yes
				create_artifact_weapon_effect = {
					OWNER = root
					CREATOR = scope:dummy_gender
					SET_WEAPON_TYPE = flag:artifact_weapon_type_sword
				}
				send_interface_toast = {
					type = event_toast_effect_good
					title = ep3_laamps.5040.a.bigsuccess
					left_icon = root
					right_icon = scope:newly_created_artifact
					custom_tooltip = ep3_laamps.5040.a.bigsuccess.tt	
				}
			}
			64 = { #You discover a small trinket
				desc = ep3_laamps.5040.a.success
				generate_trinket_effect = {
					TRINKET_RECEIVER = root
					TRINKET_GIVER = root
					GRAB_ALL_TRINKETS = yes
					HISTORY_TYPE = discovered
				}
				send_interface_toast = {
					type = event_toast_effect_good
					title = ep3_laamps.5040.a.success
					left_icon = root
					right_icon = scope:new_trinket
					custom_tooltip = ep3_laamps.5040.a.success.tt
				}
			}
			43 = { #You come up with nothing
				desc = ep3_laamps.5040.a.failure
				send_interface_toast = {
					type = event_toast_effect_bad
					title = ep3_laamps.5040.a.failure
					left_icon = root

					custom_tooltip = ep3_laamps.5040.a.failure.tt
				}
			}
		}

		stress_impact = {
			trusting = miniscule_stress_impact_loss
			paranoid = minor_stress_impact_gain
			brave = miniscule_stress_impact_loss
			craven = medium_stress_impact_gain
		}

		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_boldness = 1
			}
		}
	}

	#Buy supplies
	option = { 
		name = ep3_laamps.5040.b

		domicile = {
			change_provisions = {
				value = { minor_provisions_gain medium_provisions_gain }
			}
		}

		stress_impact = {
			greedy = minor_stress_impact_gain
			generous = minor_stress_impact_loss
		}

		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_greed = -1
			}
		}
	}
	after = {
		scope:merchant = {
			silent_disappearance_ai_if_created_effect = yes
		}
	}
}

# Meet local lord
ep3_laamps.5045 = {
	type = character_event
	title = ep3_laamps.5045.t
	desc = ep3_laamps.5045.desc
	theme = landless_adventurer
	left_portrait = {
		character = root
		animation = thinking
	}
	right_portrait = {
		character = scope:local_lord
		animation = scheme
	}
	cooldown = { years = 10 }
	override_background = { reference = council_chamber }

	trigger = {
		#Standard checks
		has_ep3_dlc_trigger = yes
		has_government = landless_adventurer_government
		is_location_valid_for_travel_event_on_land = yes
		location.barony.holder ?= {
			is_available_ai_adult = yes
			highest_held_title_tier <= root.prestige_level
		}
		NOT = { #Just ensure _you_ aren't a bandit for loc reasons
			has_trait_xp = {
				trait = gallowsbait
				track = bandit
				value >= 30
			}
		}
	}

	immediate = {
		location = {
			save_scope_as = location
		}
		location.barony = {
			save_scope_as = location_title
		}
		location.barony.holder = {
			save_scope_as = local_lord
			save_scope_as = bg_override_char
			#Find potential employers
			if = {
				limit = {
					5025_can_spawn_contract_trigger = { LAAMP = root EMPLOYER = scope:local_lord }
				}
				add_to_temporary_list = potential_employers_list
			}
			every_vassal_or_below ?= {
				limit = {
					save_temporary_scope_as = vassal_check
					5025_can_spawn_contract_trigger = { LAAMP = root EMPLOYER = scope:vassal_check }
				}
				add_to_temporary_list = potential_contract_employers 
			}
		}
		#Can we _actually_ spawn two contracts?
		if = {
			limit = {
				any_in_list = {
					list = potential_contract_employers
					count >= 2 
				}
			}
			save_scope_as = spawn_task_contract_option_available
		}
		if = {
			limit = {
				scope:local_lord = {
					highest_held_title_tier > tier_duchy
					any_held_title = {
						title_tier = county
						is_landless_type_title = no
						count >= 1
					}
				}
			}
			scope:local_lord = {
				ordered_county = {
					limit = {
						tier = tier_county
						holder = scope:local_lord
						is_landless_type_title = no
					}
					#Least developed county as a rough approximation of backwaters
					order_by = {
						value = development_level
						multiply = -1
					}

					save_scope_as = lord_title
				}
			}
		}
	}

	#Ask for land
	option = {
		name = ep3_laamps.5045.a

		trigger = {
			scope:local_lord = {
				highest_held_title_tier > tier_duchy
				any_held_title = {
					title_tier = county
					count >= 1
				}
			}
			prestige_level >= 2
			has_character_modifier = ep3_lust_for_land_modifier
		}

		custom_tooltip = ep3_laamps.5045.a.tt

		add_internal_flag = special

		duel = {
			target = scope:local_lord
			skill = diplomacy

			300 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				desc = ep3_laamps.5045.a.success
				min = 5
				send_interface_toast = {
					type = event_toast_effect_good
					title = ep3_laamps.5045.a.success
					left_icon = root
					right_icon = scope:local_lord

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

					change_liege = {
						liege = scope:local_lord
						change = scope:change
					}

					scope:lord_title = {
						change_title_holder = {
							holder = root
							change = scope:change
						}
					}

					resolve_title_and_vassal_change = scope:change

					scope:local_lord = {
						add_hook = {
							target = root
							type = loyalty_hook
						}
					}
				}
			}

			70 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				desc = ep3_laamps.5045.a.failure
				min = 5
				send_interface_toast = {
					type = event_toast_effect_bad
					title = ep3_laamps.5045.a.failure
					left_icon = root
					right_icon = scope:local_lord
				}
			}
		}

		stress_impact = {
			ambitious = miniscule_stress_impact_loss
			content = minor_stress_impact_gain
			diligent = miniscule_stress_impact_loss
			lazy = minor_stress_impact_gain
		}

		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_boldness = 1
			}
		}
	}

	#Ask for gold
	option = { 
		name = ep3_laamps.5045.b

		add_gold = { 5 20 }

		scope:local_lord = {
			add_hook = {
				target = root
				type = favor_hook
			}
		}

		stress_impact = {
			greedy = miniscule_stress_impact_loss
		}

		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_greed = 1
			}
		}
	}

	#Ask for provisions
	option = { 
		name = ep3_laamps.5045.c

		domicile = {
			change_provisions = {
				value = { miniscule_provisions_gain minor_provisions_gain }
			}
		}

		scope:local_lord = {
			add_hook = {
				target = root
				type = favor_hook
			}
		}

		stress_impact = {
			ambitious = minor_stress_impact_gain
			content = miniscule_stress_impact_loss
			greedy = miniscule_stress_impact_loss
		}

		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_greed = 1
			}
		}
	}

	#Ask for work
	option = { 
		name = ep3_laamps.5045.d
		trigger = { exists = scope:spawn_task_contract_option_available }
		reverse_add_opinion = {
			target = scope:local_lord
			modifier = impressed_opinion
			opinion = 40
		}

		custom_tooltip = ep3_laamps.5025.b.tt #Re-used
		contract_passive_spawn_effect = {
			SPAWN_CONTRACTS = 2
		}

		stress_impact = {
			ambitious = miniscule_stress_impact_loss
			content = minor_stress_impact_gain
			brave = miniscule_stress_impact_loss
			craven = minor_stress_impact_gain
		}

		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_honor = 1
			}
		}
	}
}

##################################################
# Hereweard embarks on his destiny
# by Nick Meredith
# 5999-6999
##################################################

# Hereward hears of trouble in England
ep3_laamps.5999 = {
	type = character_event
	title = ep3_laamps.5999.t
	desc = ep3_laamps.5999.desc
	theme = realm
	left_portrait = {
		character = root
		animation = interested
	}
	lower_right_portrait = scope:william
	lower_center_portrait = scope:harald
	lower_left_portrait = scope:harold

	trigger = {
		has_ep3_dlc_trigger = yes
	}

	immediate = {
		character:140 = {
			if = {
				limit = {
					is_alive = yes
				}
				save_scope_as = william
			}
		}
		character:122 = {
			if = {
				limit = {
					is_alive = yes
				}
				save_scope_as = harold
			}
		}
		character:102531 = {
			if = {
				limit = {
					is_alive = yes
				}
				save_scope_as = harald
			}		
		}
		character:364 = {
			if = {
				limit = {
					is_alive = yes
				}
				save_scope_as = flanders #I can't be bothered spelling Boujewijingjn ok
			}		
		}
		character:114 = {
			save_scope_as = edward			
		}
		location = {
			save_scope_as = location
		}
	}
 	
	option = { #Let's wait and see
		name = ep3_laamps.5999.a

		add_character_modifier = {
			modifier = ep3_foreign_affairs_modifier
			years = 5
		}

		stress_impact = {
			ambitious = miniscule_stress_impact_loss
		}

		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_boldness = 1
				ai_energy = 1
			}
		}
	}

	option = { #England concerns me no longer
		name = ep3_laamps.5999.b
		custom_tooltip = ep3_laamps.5999.b.tt
		contract_passive_spawn_effect = {
			SPAWN_CONTRACTS = 1
		}

		stress_impact = {
			ambitious = minor_stress_impact_gain
		}

		ai_chance = {
			base = 25
			ai_value_modifier = {
				ai_boldness = -1
				ai_energy = -1
			}
		}
	}
}

# Hereward sets off
ep3_laamps.6000 = {
	type = character_event
	title = ep3_laamps.6000.t
	desc = {
		desc = ep3_laamps.6000.intro
		first_valid = {
			triggered_desc = {
				trigger = {	scope:brother = { is_alive = yes } }
				desc = ep3_laamps.6000.body.alive
			}
			desc = ep3_laamps.6000.body.dead
		}
		desc = ep3_laamps.6000.desc
		first_valid = {
			triggered_desc = {
				trigger = {	scope:brother = { is_alive = yes } }
				desc = ep3_laamps.6000.closing.alive
			}
			desc = ep3_laamps.6000.closing.dead
		}
	}
	theme = realm
	left_portrait = {
		character = root
		animation = chancellor
	}
	lower_right_portrait = scope:william
	lower_center_portrait = scope:brother
	lower_left_portrait = scope:harold

	trigger = {
		has_ep3_dlc_trigger = yes
	}

	immediate = {
		character:140 = {
			save_scope_as = william
		}
		character:122 = {
			save_scope_as = harold
		}
		father = {
			save_scope_as = father
		}
		random_sibling = { #Hereweard only has one sibling
			even_if_dead = yes
			save_scope_as = brother
		}
		province:1537 = {
			save_scope_as = ely
		}
	}
 	
	option = { #Set sail at once!
		name = {
			text = ep3_laamps.6000.a.dead
			trigger = {
				scope:brother = { is_alive = no }
			}
		}
		name = {
			text = ep3_laamps.6000.a
			trigger = {
				scope:brother = { is_alive = yes }
			}
		}

		flavor = ep3_laamps.6000.a.flavor

		custom_tooltip = ep3_laamps.6000.a.tt

		every_character_active_contract = { invalidate_contract = yes }
		add_character_flag = laamp_stay_same_kingdom

		start_travel_plan = {
			destination = province:1537 #Ely
			players_use_planner = no
			on_start_on_action = on_travel_relocation_start
			on_arrival_on_action = on_travel_relocation_end
			on_arrival_event = ep3_laamps.6001
			on_arrival_destinations = last
			return_trip = no # One way
			travel_with_domicile = yes
		}

		stress_impact = {
			ambitious = minor_stress_impact_loss
		}

		ai_chance = {
			# Hereward will always do the thing.
			base = 1000
		}
	}

	option = { #It is time to forget
		name = ep3_laamps.6000.b

		custom_tooltip = ep3_laamps.6000.b.tt

		add_character_modifier = {
			modifier = ep3_the_restful_modifier
			years = 15
		}
		add_opinion = {
			target = scope:william
			modifier = demanded_eviction_opinion
		}

		stress_impact = {
			ambitious = minor_stress_impact_gain
		}

		ai_chance = {
			# Hereward will always do the thing.
			base = 0
		}
	}
}
#
## Hereward arrives, finds his brother dead
#ep3_laamps.6001 = {
#	type = character_event
#	title = ep3_laamps.6001.t
#	desc = ep3_laamps.6001.desc
#	theme = death
#	left_portrait = {
#		character = root
#		animation = random_weapon_aggressive
#	}
#	right_portrait = {
#		character = scope:frederick
#		animation = inspect_weapon
#	}
#	lower_center_portrait = scope:brother
#	override_effect_2d = {
#		reference = fog	
#	}
#	override_effect_2d = {
#		reference = fog	
#	}
#
#	trigger = {
#		has_ep3_dlc_trigger = yes
#	}
#
#	immediate = {
#		random_sibling = { #Hereweard only has one sibling
#			limit = {
#				is_alive = yes
#			}
#			save_scope_as = brother
#		}
#		province:1537 = {
#			save_scope_as = ely
#		}
#		if = { #Either grab Frederick de Warenne, real-life killer of Hereward's brother...
#			limit = {
#				character:175 = {
#					is_alive = yes
#					is_available_healthy_ai_adult = yes
#				}
#			}
#			character:175 = {
#				save_scope_as = frederick
#			}
#		}
#		else = { #...or make another Frederick
#			create_character = {
#				location = scope:ely
#				template = knight
#				culture = culture:norman
#				faith = faith:roman_catholic
#				save_scope_as = frederick
#			}			
#		}
#		hidden_effect = { #Finally, kill Oslac
#			scope:brother = {
#				death = {
#					death_reason = death_murder
#					killer = scope:frederick
#				}
#			}
#		}
#	}
# 	
#	option = { #Initiate the duel
#		name = ep3_laamps.6001.a
#
#		custom_tooltip = ep3_laamps.6001.b.two.tt
#
#		configure_start_single_combat_effect = {
#			SC_INITIATOR = root
#			SC_ATTACKER = root
#			SC_DEFENDER = scope:frederick
#			FATALITY = always
#			FIXED = sc_attacker #Hereward should _always_ win
#			LOCALE = wilderness_scope
#			OUTPUT_EVENT = ep3_laamps.6002
#			INVALIDATION_EVENT = fp1_yearly.2002 #Re-use this, though SHOULD never invalidate
#		}
#
#		stress_impact = {
#			vengeful = minor_stress_impact_loss
#		}
#
#		ai_chance = {
#			base = 100
#			ai_value_modifier = {
#				ai_boldness = 1
#				ai_energy = 1
#			}
#		}
#	}
#
#	option = { #Give them a chance to run
#		name = ep3_laamps.6001.b
#
#		random_list = {
#			1 = {
#				desc = ep3_laamps.6001.b.one
#				show_chance = no
#
#				custom_tooltip = ep3_laamps.6001.b.one.tt
#
#				configure_start_single_combat_effect = {
#					SC_INITIATOR = root
#					SC_ATTACKER = root
#					SC_DEFENDER = scope:frederick
#					FATALITY = always
#					FIXED = sc_attacker #We win these, boys
#					LOCALE = wilderness_scope
#					OUTPUT_EVENT = ep3_laamps.6002
#					INVALIDATION_EVENT = fp1_yearly.2002 #Re-use this, though SHOULD never invalidate
#				}
#			}
#			1 = {
#				desc = ep3_laamps.6001.b.two
#				show_chance = no
#
#				custom_tooltip = ep3_laamps.6001.b.two.tt
#
#				configure_start_single_combat_effect = { #Ah, the illusion of choice!
#					SC_INITIATOR = root
#					SC_ATTACKER = root
#					SC_DEFENDER = scope:frederick
#					FATALITY = always
#					FIXED = sc_attacker #We win these, boys
#					LOCALE = wilderness_scope
#					OUTPUT_EVENT = ep3_laamps.6002
#					INVALIDATION_EVENT = fp1_yearly.2002 #Re-use this, though SHOULD never invalidate
#				}
#			}
#		}
#
#		stress_impact = {
#			wrathful = minor_stress_impact_gain
#		}
#
#		ai_chance = {
#			base = 25
#			ai_value_modifier = {
#				ai_boldness = -1
#				ai_energy = -1
#			}
#		}
#	}
#
#	after = { trigger_event = ep3_laamps.9983 }
#}
#
#ep3_laamps.6002 = {
#	type = character_event
#	hidden = yes
#
#	immediate = {
#		trigger_event = { id = ep3_laamps.6003 days = 1 }
#	}
#}
#
## Hereward swears revenge
#ep3_laamps.6003 = {
#	type = character_event
#	title = ep3_laamps.6003.t
#	desc = ep3_laamps.6003.desc
#	theme = death
#	left_portrait = {
#		character = root
#		animation = grief
#	}
#	lower_right_portrait = {
#		trigger = {
#			character:172 = {
#				is_alive = yes
#			}
#		}
#		character = character:172
#	}
#
#	trigger = {
#		has_ep3_dlc_trigger = yes
#	}
#
#	immediate = {
#		if = { #If Frederick's brother still exists, Nemesis'em
#			limit = {
#				character:172 = {
#					is_alive = yes
#				}
#			}
#			character:172 = {
#				set_relation_nemesis = {
#					target = root
#					reason = nemesis_killed_brother
#				}
#			}
#		}
#	}
# 	
#	option = { #Swear vengeance
#		name = ep3_laamps.6003.a
#
#		add_trait_xp = {
#			trait = the_wake
#			value = 15
#		}
#
#		stress_impact = {
#			base = medium_stress_impact_loss
#		}
#
#		ai_chance = {
#			base = 100
#			ai_value_modifier = {
#				ai_boldness = 1
#				ai_energy = 1
#			}
#		}
#	}
#
#	option = { #Rifle through Fred's pockets
#		name = ep3_laamps.6003.b
#
#		flavor = ep3_laamps.6003.b.flavor
#
#		add_gold = minor_gold_value
#
#		random = {
#			chance = 50
#
#			create_artifact = {
#				name = warenne_coin
#				description = warenne_coin_description
#				history = {
#					type = created_before_history
#				}
#				type = miscellaneous
#				visuals = brooch
#				modifier = artifact_knight_effectiveness_2_modifier
#				modifier = artifact_raid_speed_4_modifier
#				modifier = artifact_pursue_efficiency_1_modifier
#				save_scope_as = new_trinket
#			}
#
#
#			send_interface_toast = {
#				title = stewardship_general.2001.tt #Re-using this
#				left_icon = root
#				right_icon = scope:new_trinket
#				show_as_tooltip = {
#					scope:new_trinket = { set_owner = root }
#				}
#			}
#		}
#
#		ai_chance = {
#			base = 25
#			ai_value_modifier = {
#				ai_boldness = -1
#				ai_energy = -1
#			}
#		}
#	}
#
#	after = {
#		trigger_event = {
#			id = ep3_laamps.6005
#			days = { 25 45 }
#		}
#	}
#}
#
## Hereward sets up a camp in the fens near Ely
#ep3_laamps.6005 = {
#	type = character_event
#	title = ep3_laamps.6005.t
#	desc = ep3_laamps.6005.desc
#	theme = realm
#	override_background = { reference = wilderness_wetlands }
#	left_portrait = {
#		character = root
#		animation = personality_honorable
#	}
#
#	trigger = {
#		has_ep3_dlc_trigger = yes
#	}
#
#	immediate = {
#		#Save William
#		character:140 = {
#			save_scope_as = william
#		}
#
#		#Save our location; should be Ely
#		location = { save_scope_as = location }
#
#		#Set up The Fens
#		ep3_the_fens_list_effect = yes
#
#		every_in_list = {
#			list = the_fens
#			custom = every_fenland_holding
#			add_province_modifier = {
#				modifier = ep3_dangerous_fenland_modifier
#				years = 15
#			}
#		}
#
#		#Create the character here
#		create_character = {
#			location = root.capital_province
#			template = wetlands_commander_character
#			culture = root.culture
#			faith = root.faith
#			save_scope_as = wetlands_commander
#		}
#
#		## Used in the after:
#		# Make a list of every Anglo-Saxon lord
#		scope:william = {
#			every_vassal = {
#				limit = {
#					has_culture = culture:anglo_saxon
#				}
#				add_to_list = aethelings
#			}
#		}
#
#		# Pick the most powerful Anglo-Saxon lord
#		# Most likely Eadwin Aelfgarson
#		ordered_in_list = {
#			list = aethelings
#			order_by = max_military_strength
#			save_scope_as = powerful_vassal
#		}
#
#		domicile = {
#			change_provisions = minor_provisions_gain
#		}
#	}
# 	
#	option = { #Raid to acquire wealth
#		name = ep3_laamps.6005.a
#
#		flavor = ep3_laamps.6005.a.tt
#
#		add_gold = medium_gold_value
#
#		scope:ely = {
#			add_province_modifier = {
#				modifier = ep3_plundered_modifier
#				years = 5
#			}
#		}
#
#		ai_chance = {
#			base = 100
#			ai_value_modifier = {
#				ai_boldness = -1
#				ai_energy = -1
#			}
#		}
#	}
#
#	option = { #Recruit a local knight
#		name = ep3_laamps.6005.b
#
#		flavor = ep3_laamps.6005.b.tt
#
#		add_courtier = scope:wetlands_commander
#
#		ai_chance = {
#			base = 25
#			ai_value_modifier = {
#				ai_boldness = 1
#				ai_energy = 1
#			}
#		}
#	}
#
#	after = {
#		if = {
#			limit = {
#				exists = scope:powerful_vassal
#			}
#			trigger_event = {
#				id = ep3_laamps.6010
#				days = { 60 120 }
#			}
#		}
#	}
#}
#
## The Aethelings are disgruntled; go to visit the most powerful one?
#ep3_laamps.6010 = {
#	type = letter_event
#	opening = ep3_laamps.6010.t
#	desc = ep3_laamps.6010.desc
#	sender = scope:powerful_vassal
#
#	trigger = {
#		has_ep3_dlc_trigger = yes
#	}
#
#	immediate = {
#		# Make a list of every Anglo-Saxon lord
#		scope:william = {
#			every_vassal = {
#				limit = {
#					has_culture = culture:anglo_saxon
#				}
#				add_to_list = aethelings
#			}
#		}
#
#		# Pick the most powerful Anglo-Saxon lord
#		# Most likely Eadwin Aelfgarson
#		ordered_in_list = {
#			list = aethelings
#			order_by = max_military_strength
#			save_scope_as = powerful_vassal
#		}
#
#		scope:powerful_vassal.capital_province = {
#			save_scope_as = powerful_vassal_capital
#		}
#	}
#
#	option = { #Yes!
#		name = ep3_laamps.6010.a
#
#		flavor = ep3_laamps.6010.a.flavor
#
#		custom_tooltip = ep3_laamps.6010.a.tt
#
#		every_character_active_contract = { invalidate_contract = yes }
#
#		start_travel_plan = {
#			destination = scope:powerful_vassal_capital
#			players_use_planner = no
#			on_arrival_event = ep3_laamps.6015
#			on_arrival_destinations = last
#			return_trip = no
#		}
#
#		#Just to ensure we get the right one
#		scope:powerful_vassal = {
#			add_character_flag = temp_powerful_vassal_flag
#		}
#
#		ai_chance = {
#			base = 100
#		}		
#	}
#
#	option = { #...no.
#		name = ep3_laamps.6010.b
#
#		reverse_add_opinion = {
#			target = scope:powerful_vassal
#			modifier = annoyed_opinion
#			opinion = -35
#		}
#
#		ai_chance = {
#			base = 0
#		}
#	}
#}
#
## You meet with the Aetheling
#ep3_laamps.6015 = {
#	type = character_event
#	title = ep3_laamps.6015.t
#	desc = ep3_laamps.6015.desc
#	theme = realm
#	left_portrait = {
#		character = root
#		animation = thinking
#	}
#	right_portrait = {
#		character = scope:powerful_vassal
#		animation = worry
#	}
#
#	trigger = {
#		has_ep3_dlc_trigger = yes
#	}
#
#	immediate = {
#		character:140 = {
#			save_scope_as = william
#		}
#
#		scope:william = {
#			random_vassal = {
#				limit = {
#					has_character_flag = temp_powerful_vassal_flag
#				}
#				save_scope_as = powerful_vassal
#			}
#		}
#	}
# 	
#	option = { #You have my support
#		name = ep3_laamps.6015.a
#
#		scope:william = {
#			every_vassal = {
#				limit = {
#					culture = culture:norman
#				}
#				custom = every_direct_vassal_william
#				add_opinion = {
#					target = root
#					modifier = revanchist_opinion
#					opinion = -35
#				}
#			}
#			every_vassal_or_below = {
#				limit = {
#					culture = culture:anglo_saxon
#				}
#				custom = every_anglo_noble
#				add_opinion = {
#					target = root
#					modifier = revanchist_opinion
#					opinion = 35
#				}
#			}
#		}
#
#		scope:powerful_vassal = {
#			add_character_flag = happy_flag
#		}
#
#		add_diplomacy_skill = 1
#
#		reverse_add_opinion = {
#			target = scope:powerful_vassal
#			modifier = pleased_opinion
#			opinion = 50
#		}
#
#		ai_chance = {
#			base = 100
#			ai_value_modifier = {
#				ai_boldness = 1
#				ai_energy = 1
#			}
#		}
#	}
#
#	option = { #I need time to decide
#		name = ep3_laamps.6015.b
#
#		scope:powerful_vassal = {
#			add_character_flag = annoyed_flag
#		}
#
#		add_character_modifier = {
#			modifier = ep3_hereward_caution_modifier
#			years = 5
#		}
#
#		reverse_add_opinion = {
#			target = scope:powerful_vassal
#			modifier = annoyed_opinion
#			opinion = -5
#		}
#
#		ai_chance = {
#			base = 50
#			ai_value_modifier = {
#				ai_boldness = -1
#				ai_rationality = 0.5
#			}
#		}
#	}
#
#	after = {
#		trigger_event = {
#			id = ep3_laamps.6016
#			days = 1
#		}
#	}
#}
#
## Bad news arrives
#ep3_laamps.6016 = {
#	type = character_event
#	title = ep3_laamps.6016.t
#	desc = {
#		first_valid = {
#			triggered_desc = {
#				trigger = { 
#					scope:powerful_vassal = {
#						has_character_flag = annoyed_flag
#					}
#				}
#				desc = ep3_laamps.6016.frustrated
#			}
#			triggered_desc = {
#				trigger = { 
#					scope:powerful_vassal = {
#						has_character_flag = happy_flag
#					}
#				}
#				desc = ep3_laamps.6016.happy
#			}
#		}
#		desc = ep3_laamps.6016.ending
#	}
#	theme = realm
#	left_portrait = {
#		character = root
#		animation = thinking
#	}
#	right_portrait = {
#		character = scope:powerful_vassal
#		animation = worry
#	}
#
#	trigger = {
#		has_ep3_dlc_trigger = yes
#	}
#
#	immediate = {
#		character:140 = {
#			save_scope_as = william
#		}
#	}
#
#	option = { #You have my support
#		name = ep3_laamps.6016.a
#
#		custom_tooltip = ep3_laamps.6016.a.tt
#
#		ai_chance = {
#			base = 100
#		}
#	}
#
#	after = {
#		trigger_event = ep3_laamps.6020 #Start the Harrying of the North
#
#		if = {
#			limit = {
#				scope:william = {
#					is_ai = no
#				}
#			}
#			scope:william = {
#				trigger_event = ep3_laamps.6021
#			}
#		}
#		if = {
#			limit = {
#				exists = domicile
#				location != domicile.domicile_location
#			}
#			start_travel_plan = {
#				destination = root.domicile.domicile_location
#				players_use_planner = no
#				on_start_on_action = on_travel_relocation_start
#				on_arrival_on_action = on_travel_relocation_end
#				on_arrival_destinations = last
#				return_trip = no # One way
#			}
#		}
#	}
#}
#
## The Harrying of the North begins
#ep3_laamps.6020 = {
#	type = character_event
#	window = fullscreen_event
#	title = ep3_laamps.6020.t
#	desc = ep3_laamps.6020.desc
#	theme = realm
#	override_background = { reference = ep3_fullscreen_harrying_of_the_north }
#
#	trigger = {
#		has_ep3_dlc_trigger = yes
#	}
#
#	immediate = {
#		play_music_cue = mx_cue_war_declared
#
#		character:140 = {
#			save_scope_as = william
#		}
#
#		# Make a list of every Anglo-Saxon lord
#		scope:william = {
#			every_vassal = {
#				limit = {
#					has_culture = culture:anglo_saxon
#				}
#				add_to_list = aethelings
#			}
#		}
#	}
# 	
#	option = { #Oh lort here we go
#		name = ep3_laamps.6020.a
#
#		every_in_list = {
#			list = aethelings
#			custom = every_aetheling
#			every_realm_county = {
#				custom = every_county
#				change_county_control = 25
#				add_county_modifier = {
#					modifier = ep3_harried_modifier
#					years = 15
#				}
#			}
#		}
#
#		scope:william = {
#			add_character_modifier = {
#				modifier = ep3_the_conqueror_modifier
#				years = 15
#			}
#			create_story = story_cycle_harrying_of_the_north
#		}
#
#		ai_chance = {
#			base = 100
#			ai_value_modifier = {
#				ai_boldness = 1
#				ai_energy = 1
#			}
#		}
#	}
#}
#
## The Harrying of the North begins - William perspective
## This one doesn't trigger the harrying story cycle, that's held within .6020
#ep3_laamps.6021 = {
#	type = character_event
#	window = fullscreen_event
#	title = ep3_laamps.6020.t
#	desc = ep3_laamps.6021.desc
#	theme = realm
#	override_background = { reference = ep3_fullscreen_harrying_of_the_north }
#
#	trigger = {
#		has_ep3_dlc_trigger = yes
#	}
#
#	immediate = {
#		play_music_cue = mx_cue_war_declared
#
#		character:140 = {
#			save_scope_as = william
#		}
#
#		# Make a list of every Anglo-Saxon lord
#		scope:william = {
#			every_vassal = {
#				limit = {
#					has_culture = culture:anglo_saxon
#				}
#				add_to_list = aethelings
#			}
#		}
#	}
# 	
#	option = { #Oh lort here we go
#		name = ep3_laamps.6020.a
#
#		show_as_tooltip = {
#			every_in_list = {
#				list = aethelings
#				custom = every_aetheling
#				every_realm_county = {
#					custom = every_county
#					change_county_control = 25
#					add_county_modifier = {
#						modifier = ep3_harried_modifier
#						years = 15
#					}
#				}
#			}
#		}
#
#		show_as_tooltip = {
#			scope:william = {
#				add_character_modifier = {
#					modifier = ep3_the_conqueror_modifier
#					years = 15
#				}
#			}
#		}
#
#		ai_chance = {
#			base = 100
#			ai_value_modifier = {
#				ai_boldness = 1
#				ai_energy = 1
#			}
#		}
#	}
#}

##################################################
# Unique LAAMP Events
# by Nick Meredith
# 7000 - 7999
##################################################

## Eadgar becomes a LAAMP
#ep3_laamps.7000 = {
#	type = character_event
#	title = ep3_laamps.7000.t
#	desc = ep3_laamps.7000.desc
#	theme = realm
#	left_portrait = {
#		character = root
#		animation = thinking
#	}
#	lower_center_portrait = scope:william
#
#	trigger = {
#		has_ep3_dlc_trigger = yes
#	}
#
#	immediate = {
#		title:k_england = {
#			save_scope_as = england
#			holder = { save_scope_as = william }
#		}
#		location = {
#			save_scope_as = location
#		}
#		primary_heir = {
#			save_scope_as = heir
#		}
#	}
# 	
#	option = { #I'll go to Scotland
#		name = ep3_laamps.7000.a
#
#		hidden_effect = {
#			create_title_and_vassal_change = {
#				type = granted
#				save_scope_as = change
#				add_claim_on_loss = no
#			}
#			every_held_title = {
#				change_title_holder_include_vassals = {
#					holder = scope:heir
#					change = scope:change
#				}
#			}
#			resolve_title_and_vassal_change = scope:change
#		}
#
#		create_landless_adventurer_title_effect = {
#			REASON = flag:voluntary
#			FLAVOR_CHAR = scope:heir
#		}
#
#		add_trait = gallivanter
#
#		start_travel_plan = {
#			destination = province:1741 #St Johnston
#			players_use_planner = no
#			on_start_on_action = on_travel_relocation_start
#			on_arrival_on_action = on_travel_relocation_end
#			on_arrival_destinations = last
#			travel_with_domicile = yes
#			return_trip = no # One way
#		}
#
#		stress_impact = {
#			ambitious = minor_stress_impact_loss
#		}
#
#		ai_chance = {
#			base = 100
#			ai_value_modifier = {
#				ai_boldness = 1
#				ai_energy = 0.5
#			}
#		}
#	}
#
#	option = { #Norman Italy sounds like fun
#		name = ep3_laamps.7000.b
#
#		hidden_effect = {
#			create_title_and_vassal_change = {
#				type = granted
#				save_scope_as = change
#				add_claim_on_loss = no
#			}
#			every_held_title = {
#				change_title_holder_include_vassals = {
#					holder = scope:heir
#					change = scope:change
#				}
#			}
#			resolve_title_and_vassal_change = scope:change
#		}
#
#		create_landless_adventurer_title_effect = {
#			REASON = flag:voluntary
#			FLAVOR_CHAR = scope:heir
#		}
#
#		add_trait = gallivanter
#
#		start_travel_plan = {
#			destination = province:2619 #Trani
#			players_use_planner = no
#			on_start_on_action = on_travel_relocation_start
#			on_arrival_on_action = on_travel_relocation_end
#			on_arrival_destinations = last
#			travel_with_domicile = yes
#			return_trip = no # One way
#		}
#
#		stress_impact = {
#			ambitious = minor_stress_impact_loss
#		}
#
#		ai_chance = {
#			base = 75
#			ai_value_modifier = {
#				ai_boldness = 1
#				ai_energy = 1
#			}
#		}
#	}
#
#	option = { #Maybe I'll stay
#		name = ep3_laamps.7000.c
#
#		add_prestige = major_prestige_gain
#
#		stress_impact = {
#			ambitious = minor_stress_impact_gain
#		}
#
#		ai_chance = {
#			base = 25
#			ai_value_modifier = {
#				ai_boldness = -1
#				ai_energy = -1
#			}
#		}
#	}
#}
#
# Siward Barn turns up at Hereward's camp
# From Hereward's perspective
ep3_laamps.7001 = {
	type = character_event
	title = ep3_laamps.7001.t
	desc = ep3_laamps.7001.desc
	theme = realm
	left_portrait = {
		character = root
		animation = thinking
	}
	right_portrait = {
		character = scope:siward
		animation = marshal
	}
	cooldown = { years = 200 } #Should never happen again

	trigger = {
		has_ep3_dlc_trigger = yes
		has_government = landless_adventurer_government
		character:90028 = {
			exists = this
		}
		character:161266 = {
			exists = this
		}
	}

	immediate = {
		character:161266 = {
			save_scope_as = siward
			move_to_pool_at = root.location
		}
		location = {
			save_scope_as = location
		}
		ep3_harrying_widget_setup_effect = yes
	}
 	
	option = { #Of course, come on in!
		name = ep3_laamps.7001.a

		add_courtier = scope:siward

		ep3_increase_resistance_effect = { AMOUNT = harrying_medium_increase_value }

		random = {
			chance = {
				value = 5
				if = {
					limit = { is_ai = no }
					add = 95
				}
			}
			trigger_event = {
				id = ep3_laamps.7002
				days = { 150 200 }
			}
		}

		stress_impact = {
			ambitious = minor_stress_impact_loss
			gregarious = minor_stress_impact_loss
		}

		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_boldness = 1
				ai_energy = 1
			}
		}
	}

	option = { #We're full
		name = ep3_laamps.7001.b

		reverse_add_opinion = {
			target = scope:siward
			modifier = annoyed_opinion
			opinion = -20
		}

		stress_impact = {
			compassionate = minor_stress_impact_gain
			callous = minor_stress_impact_loss
		}

		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_boldness = -1
				ai_energy = -1
			}
		}
	}
}

scripted_effect ep3_laamps_7002_ai_siward_leaves_effect = {
	scope:siward = {
		create_landless_adventurer_title_effect = {
			REASON = flag:voluntary
			FLAVOR_CHAR = scope:siward
		}
		start_travel_plan = {
			destination = province:5296 #Bata
			players_use_planner = no
			on_start_on_action = on_travel_relocation_start
			on_arrival_on_action = on_travel_relocation_end
			on_arrival_destinations = last
			on_arrival_event = ep3_laamps.7003
			travel_with_domicile = yes
			return_trip = no # One way
		}
	}
}

# Siward Barn leaves Hereward's camp
# From Hereward's perspective
ep3_laamps.7002 = {
	type = character_event
	title = ep3_laamps.7002.t
	desc = ep3_laamps.7002.desc
	theme = realm
	left_portrait = {
		character = root
		animation = worry
	}
	right_portrait = {
		character = scope:siward
		animation = personality_honorable
	}

	trigger = {
		has_ep3_dlc_trigger = yes
		character:90028 = {
			exists = this
		}
		character:161266 = {
			exists = this
			location = root.location
		}
		title:e_byzantium = {
			exists = this
		}
		title:k_england = {
			exists = this
		}
		title:c_zichia.holder = {
			NOT = {
				this = title:e_byzantium.holder
			}
		}
	}

	immediate = {
		hidden_effect = {
			scope:siward = { #Give him some gold so he can buy land
				add_gold = 300
			}
		}
		title:e_byzantium.holder = {
			save_scope_as = emperor
		}
		title:k_england.holder = {
			save_scope_as = king_england
		}
	}

	option = { #Go with my blessing
		name = ep3_laamps.7002.a

		ep3_laamps_7002_ai_siward_leaves_effect = yes

		stress_impact = {
			compassionate = minor_stress_impact_loss
		}

		ai_chance = {
			ai_value_modifier = {
				ai_boldness = 1
				ai_energy = 1
			}
		}
	}

	option = { #I SHALL BECOME YOU
		name = ep3_laamps.7002.b

		trigger = {
			is_ai = no
		}

		add_internal_flag = dangerous

		scope:siward = {
			create_landless_adventurer_title_effect = {
				REASON = flag:voluntary
				FLAVOR_CHAR = scope:siward
			}
			start_travel_plan = {
				destination = province:496 #Constantinople
				players_use_planner = no
				on_start_on_action = on_travel_relocation_start
				on_arrival_on_action = on_travel_relocation_end
				on_arrival_destinations = last
				on_arrival_event = ep3_laamps.7003
				travel_with_domicile = yes
				return_trip = no # One way
			}
		}

		set_player_character = scope:siward

		ai_chance = {
			base = 0
		}
	}

	option = { #Duel to stay.
		name = bp1_yearly.1020.a

		duel = {
			skill = diplomacy
			target = scope:siward
			# He stays.
			60 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				min = 5
				desc = ep3_laamps.7002.c.success
				send_interface_toast = {
					title = ep3_laamps.7002.c.success
					left_icon = scope:siward
					reverse_add_opinion = {
						target = scope:siward
						modifier = respect_opinion
						opinion = 30
					}
				}
			}
			# He goes.
			40 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				min = 5
				desc = ep3_laamps.7002.c.failure
				send_interface_toast = {
					title = ep3_laamps.7002.c.failure
					left_icon = scope:siward
					ep3_laamps_7002_ai_siward_leaves_effect = yes
				}
			}
		}

		ai_chance = {
			ai_value_modifier = {
				ai_sociability = 1
				ai_rationality = 1
			}
		}
	}

	after = {
		scope:siward = { add_character_modifier = laamp_provisions_forgiveness_travel_modifier }
	}
}

# Siward Barn arrives in Constantinople
ep3_laamps.7003 = {
	type = character_event
	title = ep3_laamps.7003.t
	desc = ep3_laamps.7003.desc
	theme = realm
	override_background = { reference = ep3_constantinople }
	left_portrait = {
		character = root
		animation = thinking
	}
	right_portrait = {
		character = scope:emperor
		animation = scheme
	}

	trigger = {
		has_ep3_dlc_trigger = yes
	}

	immediate = {
		title:e_byzantium.holder = {
			save_scope_as = emperor
		}
		title:c_zichia = {
			save_scope_as = zichia
		}
	}

	option = { #Oh boy I'd love to do a realmy thing!
		name = ep3_laamps.7003.a

		custom_tooltip = ep3_laamps.7003.a.tt

		start_travel_plan = {
			destination = province:5296 #Bata
			players_use_planner = no
			on_start_on_action = on_travel_relocation_start
			on_arrival_on_action = on_travel_relocation_end
			on_arrival_destinations = last
			on_arrival_event = ep3_laamps.7004
			travel_with_domicile = yes
			return_trip = no # One way
		}

		stress_impact = {
			ambitious = minor_stress_impact_loss
		}

		ai_chance = { #50% chance for AI
			base = 50
		}
	}

	option = { #Nah I'd rather stay here
		name = ep3_laamps.7003.b

		add_character_modifier = {
			modifier = ep3_culturally_greek_modifier
			years = 20
		}

		reverse_add_opinion = {
			target = scope:emperor
			modifier = disappointed_opinion
			opinion = -5
		}

		ai_chance = { #50% chance for AI
			base = 50
		}
	}
}

scripted_effect new_england_holding_names_effect = {
	random_list = {
	    100 = { set_title_name = b_london }
	    100 = { set_title_name = b_southwark }
	    100 = { set_title_name = b_woxbrigge }
	    100 = { set_title_name = b_gore }
	    100 = { set_title_name = b_brentford }
	    100 = { set_title_name = b_colchester }
	    100 = { set_title_name = b_maldon }
	    100 = { set_title_name = b_chelmsford }
	    100 = { set_title_name = b_dunmow }
	    100 = { set_title_name = b_bedford }
	    100 = { set_title_name = b_ampthill }
	    100 = { set_title_name = b_luton }
	    100 = { set_title_name = b_berkhamsted }
	    100 = { set_title_name = b_saint_albans }
	    100 = { set_title_name = b_hertford }
	    100 = { set_title_name = b_buckingham }
	    100 = { set_title_name = b_aylesbury }
	    100 = { set_title_name = b_newport }
	    100 = { set_title_name = b_wycombe }
	    100 = { set_title_name = b_bamburgh }
	    100 = { set_title_name = b_rothbury }
	    100 = { set_title_name = b_lindisfarne }
	    100 = { set_title_name = b_hexham }
	    100 = { set_title_name = b_durham }
	    100 = { set_title_name = b_hartlepool }
	    100 = { set_title_name = b_darlington }
	    100 = { set_title_name = b_carlisle }
	    100 = { set_title_name = b_whitehaven }
	    100 = { set_title_name = b_furness }
	    100 = { set_title_name = b_wigton }
	    100 = { set_title_name = b_lancaster }
	    100 = { set_title_name = b_salford }
	    100 = { set_title_name = b_west_derby }
	    100 = { set_title_name = b_kendal }
	    100 = { set_title_name = b_appleby }
	    100 = { set_title_name = b_chester }
	    100 = { set_title_name = b_northwich }
	    100 = { set_title_name = b_macclesfield }
	    100 = { set_title_name = b_derby }
	    100 = { set_title_name = b_chesterfield }
	    100 = { set_title_name = b_castleton }
	    100 = { set_title_name = b_york }
	    100 = { set_title_name = b_scarborough }
	    100 = { set_title_name = b_whitby }
	    100 = { set_title_name = b_richmond }
	    100 = { set_title_name = b_yarlestre }
	    100 = { set_title_name = b_pockington }
	    100 = { set_title_name = b_cottingham }
	    100 = { set_title_name = b_bridlington }
	    100 = { set_title_name = b_leeds }
	    100 = { set_title_name = b_doncaster }
	    100 = { set_title_name = b_halifax }
	    100 = { set_title_name = b_sheffield }
	    100 = { set_title_name = b_bolton }
	    100 = { set_title_name = b_ripon }
	    100 = { set_title_name = b_lincoln }
	    100 = { set_title_name = b_stamford }
	    100 = { set_title_name = b_boston }
	    100 = { set_title_name = b_bolingsbroke }
	    100 = { set_title_name = b_grimsby }
	    100 = { set_title_name = b_norwich }
	    100 = { set_title_name = b_thetford }
	    100 = { set_title_name = b_walsingham }
	    100 = { set_title_name = b_lynn }
	    100 = { set_title_name = b_ipswich }
	    100 = { set_title_name = b_sudbury }
	    100 = { set_title_name = b_blything }
	    100 = { set_title_name = b_beodericsworth }
	    100 = { set_title_name = b_cambridge }
	    100 = { set_title_name = b_radfield }
	    100 = { set_title_name = b_papworth }
	    100 = { set_title_name = b_ely }
	    100 = { set_title_name = b_warwick }
	    100 = { set_title_name = b_coventry }
	    100 = { set_title_name = b_birmingham }
	    100 = { set_title_name = b_leicester }
	    100 = { set_title_name = b_melton }
	    100 = { set_title_name = b_bosworth }
	    100 = { set_title_name = b_rutland }
	    100 = { set_title_name = b_nottingham }
	    100 = { set_title_name = b_newark }
	    100 = { set_title_name = b_retford }
	    100 = { set_title_name = b_stafford }
	    100 = { set_title_name = b_wolverhampton }
	    100 = { set_title_name = b_stoke_on_trent }
	    100 = { set_title_name = b_worcester }
	    100 = { set_title_name = b_evesham }
	    100 = { set_title_name = b_kidderminster }
	    100 = { set_title_name = b_hurstingstone }
	    100 = { set_title_name = b_norman_cross }
	    100 = { set_title_name = b_leightonstone }
	    100 = { set_title_name = b_northampton }
	    100 = { set_title_name = b_peterborough }
	    100 = { set_title_name = b_kettering }
	    100 = { set_title_name = b_shrewsbury }
	    100 = { set_title_name = b_ludlow }
	    100 = { set_title_name = b_bishops_castle }
	    100 = { set_title_name = b_gloucester }
	    100 = { set_title_name = b_bristol }
	    100 = { set_title_name = b_winchcombe }
	    100 = { set_title_name = b_salisbury }
	    100 = { set_title_name = b_wilton }
	    100 = { set_title_name = b_ramsbury }
	    100 = { set_title_name = b_malmesbury }
	    100 = { set_title_name = b_oxford }
	    100 = { set_title_name = b_banbury }
	    100 = { set_title_name = b_witney }
	    100 = { set_title_name = b_reading }
	    100 = { set_title_name = b_newbury }
	    100 = { set_title_name = b_abingdon }
	    100 = { set_title_name = b_dover }
	    100 = { set_title_name = b_canterbury }
	    100 = { set_title_name = b_rochester }
	    100 = { set_title_name = b_tonbridge }
	    100 = { set_title_name = b_chertsey }
	    100 = { set_title_name = b_guildford }
	    100 = { set_title_name = b_kingston }
	    100 = { set_title_name = b_tandbridge }
	    100 = { set_title_name = b_lewes }
	    100 = { set_title_name = b_chichester }
	    100 = { set_title_name = b_arun }
	    100 = { set_title_name = b_hastings }
	    100 = { set_title_name = b_winchester }
	    100 = { set_title_name = b_southampton }
	    100 = { set_title_name = b_portsmouth }
	    100 = { set_title_name = b_basingstoke }
	    100 = { set_title_name = b_christchurch }
	    100 = { set_title_name = b_carisbrooke }
	    100 = { set_title_name = b_wareham }
	    100 = { set_title_name = b_poole }
	    100 = { set_title_name = b_shaftesbury }
	    100 = { set_title_name = b_lyme }
	    100 = { set_title_name = b_bath }
	    100 = { set_title_name = b_winterstoke }
	    100 = { set_title_name = b_ilchester }
	    100 = { set_title_name = b_taunton }
	    100 = { set_title_name = b_exeter }
	    100 = { set_title_name = b_totnes }
	    100 = { set_title_name = b_okehampton }
	    100 = { set_title_name = b_barnstaple }
	    100 = { set_title_name = b_launceston }
	    100 = { set_title_name = b_tintagel }
	    100 = { set_title_name = b_helston }
	}
}

# Siward Barn arrives in Bata
ep3_laamps.7004 = {
	type = character_event
	title = ep3_laamps.7004.t
	desc = ep3_laamps.7004.desc
	theme = realm
	left_portrait = {
		character = root
		animation = thinking
	}
	right_portrait = {
		character = scope:title_holder
		animation = scheme
	}

	trigger = {
		has_ep3_dlc_trigger = yes
	}

	immediate = {
		scope:zichia.holder.top_liege = {
			save_scope_as = title_holder
		}
		hidden_effect = {
			add_unpressed_claim = title:c_zichia
		}
		title:c_zichia = {
			add_to_list = landed_titles
		}
		scope:zichia.holder = {
			every_realm_province = {
				barony = { add_to_list = zichia_names }
			}
		}
	}

	option = { #OK, I'll pay
		name = ep3_laamps.7004.a

		add_character_flag = { #Bypass usual event
			flag = siward_flag
			years = 1
		}

		pay_short_term_gold = {
			target = scope:title_holder
			gold = 100
		}

		hidden_effect = { #For tooltip reasons
			ep3_become_landed_transfer_effect = {
				TITLE_RECEIVER = root
				TITLE_LIST = landed_titles
				TYPE = granted
				REASON = flag:granted
				ENNOBLED_ADVENTURER = flag:yes
			}
			every_in_list = {
				list = zichia_names
				new_england_holding_names_effect = yes
			}
		}

		custom_tooltip = destroy_laamp_effect.tt.domicile_liquidated

		show_as_tooltip = {
			get_title = title:c_zichia
			add_character_modifier = {
				modifier = ep3_ennobled_adventurer_modifier_1
				years = 10
			}
			## Nomad.
			if = {
				limit = {
					OR = {
						government_has_flag = government_is_nomadic
						scope:new_liege ?= { government_has_flag = government_is_nomadic }
						scope:old_government ?= flag:nomad
						scope:new_capital.capital_province = {
							OR = {
								has_holding_type = nomad_holding
								has_holding_type = herder_holding
							}
						}
					}
				}
				change_government = nomad_government
			}
			## Administrative.
			else_if = {
				limit = {
					scope:new_liege ?= { government_has_flag = government_is_administrative }
				}
				change_government = administrative_government
			}
			## Clan.
			else_if = {
				limit = {
					scope:new_liege ?= { government_has_flag = government_is_clan }
				}
				change_government = clan_government
			}
			## Tribal.
			else_if = {
				limit = {
					scope:new_liege ?= { government_has_flag = government_is_tribal }
				}
				change_government = tribal_government
			}
			## Else feudal.
			else = { change_government = feudal_government }
		}

		hidden_effect = {
			## Nomad.
			if = {
				limit = {
					OR = {
						government_has_flag = government_is_nomadic
						scope:new_liege ?= { government_has_flag = government_is_nomadic }
						scope:old_government ?= flag:nomad
						scope:new_capital.capital_province = {
							OR = {
								has_holding_type = nomad_holding
								has_holding_type = herder_holding
							}
						}
					}
				}
				change_government = nomad_government
			}
			## Administrative.
			else_if = {
				limit = {
					scope:new_liege ?= { government_has_flag = government_is_administrative }
				}
				change_government = administrative_government
			}
			## Clan.
			else_if = {
				limit = {
					scope:new_liege ?= { government_has_flag = government_is_clan }
				}
				change_government = clan_government
			}
			## Tribal.
			else_if = {
				limit = {
					scope:new_liege ?= { government_has_flag = government_is_tribal }
				}
				change_government = tribal_government
			}
			## Else feudal.
			else = { change_government = feudal_government }
		}

		scope:zichia = {
			set_title_name = c_new_england
			set_color_from_title = title:k_england
		}

		stress_impact = {
			ambitious = minor_stress_impact_loss
			greedy = medium_stress_impact_gain
		}

		ai_chance = { #50% chance for AI
			base = 50
		}
	}

	option = { #I'll take it by force!
		name = ep3_laamps.7004.b

		start_war = {
			cb = county_conquest_cb
			target = title:c_zichia.holder
			target_title = title:c_zichia
		}

		stress_impact = {
			ambitious = minor_stress_impact_loss
			greedy = minor_stress_impact_loss
			craven = medium_stress_impact_gain
		}

		ai_chance = { #50% chance for AI
			base = 50
		}
	}
}


##################################################
# Pool Weightings
# by Ewan Cowhig Croft
# 9971 - 9979
##################################################

#	The way pool population works causes a massive over-bias of Jewish (and certain other minority) characters in the first couple of decades, and those then get pulled in as assorted criminals and such by a lot of laamp content. This can lead to chains of rather unfortunate numbers of said-chars put into the role of Designated Bastard time after time, which looks dodgy as all hell. Thus, whenever the player moves from place to place as a laamp in the very early game, we need to flood their local pool with characters until the world fills up suitably with actual random gen characters.
ep3_laamps.9971 = {
	hidden = yes

	trigger = {
		is_ai = no
		has_government = landless_adventurer_government
		years_from_game_start <= 25
	}

	immediate = {
		while = {
			count = 5
			create_character = {
				template = default_mystic_character
				location = root.location
				culture = root.location.culture
				faith = root.location.faith
				gender_female_chance = 50
			}
			create_character = {
				template = wise_woman_character
				location = root.location
				culture = root.location.culture
				faith = root.location.faith
				gender_female_chance = 50
			}
			create_character = {
				template = merchant_template
				location = root.location
				culture = root.location.culture
				faith = root.location.faith
				gender_female_chance = 50
			}
			create_character = {
				template = hunter_template
				location = root.location
				culture = root.location.culture
				faith = root.location.faith
				gender_female_chance = 50
			}
			create_character = {
				template = generic_peasant_character
				location = root.location
				culture = root.location.culture
				faith = root.location.faith
				gender_female_chance = 50
			}
			create_character = {
				template = bandit_character_generic
				location = root.location
				culture = root.location.culture
				faith = root.location.faith
				gender_female_chance = 50
			}
		}
	}
}

##################################################
# Passive Contract Spawn
# by Ewan Cowhig Croft
# 9981 - 9989
##################################################

#	Spawn a contract every now and then whilst we remain in the same location, up to a reasonable limit.
ep3_laamps.9981 = {
	hidden = yes

	trigger = {
		var:contract_passive_spawn_location ?= location.kingdom
		trigger_if = {
			limit = { has_variable = contract_passive_spawn_tally }
			var:contract_passive_spawn_tally < 3
		}
		# Make sure we don't do this if we've got lots of contracts already spawned here.
		any_character_task_contract = {
			count <= 4
			task_contract_location = {
				"squared_distance(root.location)" <= squared_distance_medium
			}
		}
	}

	on_trigger_fail = {
		if = {
			limit = { var:contract_passive_spawn_location ?= location.kingdom }
			trigger_event = {
				id = ep3_laamps.9981
				months = { 8 12 }
			}
		}
	}

	immediate = {
		# spawn a contract
		contract_passive_spawn_effect = {
			SPAWN_CONTRACTS = 1
		}
		# And fire us again in a bit.
		if = {
			limit = { 
				var:contract_passive_spawn_tally < 2
			}
			trigger_event = {
				id = ep3_laamps.9981
				months = 1
			}
		}
		else = {
			trigger_event = {
				id = ep3_laamps.9981
				months = 2
			}
		}
	}
}

#	Populate adventurer contracts on succession.
ep3_laamps.9982 = {
	hidden = yes

	trigger = {
		is_ai = no
		government_has_flag = government_is_landless_adventurer
	}

	immediate = {
		populate_location_with_contracts_effect = {
			AREA_CHAR = root
			AMOUNT = 3
		}
	}
}



#	Keep giving Hereward regular work within England.
ep3_laamps.9983 = {
	hidden = yes

	trigger = {
		# Must be within England.
		domicile.domicile_location.county = {
			save_temporary_scope_as = title_temp
			title:k_england = { is_de_jure_liege_or_above_target = scope:title_temp }
		}
		# Make sure we don't do this if we've got lots of contracts already spawned here.
		any_character_task_contract = {
			count <= 6
			task_contract_location = { "squared_distance(root.location)" <= squared_distance_medium }
		}
	}

	on_trigger_fail = {
		if = {
			limit = { var:contract_passive_spawn_location ?= location.kingdom }
			trigger_event = {
				id = ep3_laamps.9981
				months = 6
			}
		}
	}

	immediate = {
		# Spawn some contracts.
		contract_passive_spawn_effect = {
			SPAWN_CONTRACTS = 2
		}
		# And fire us again in a bit.
		trigger_event = {
			id = ep3_laamps.9981
			months = { 8 12 }
		}
	}
}

##################################################
# Become Landed - Maintenance
# by Joe Parkin
# 9991 - 9999
##################################################

ep3_laamps.9999 = { # Error suppression
	scope = none
	orphan = yes
	hidden = yes
	trigger = {
		exists = var:ascended_throne_reason
		exists = var:lost_title_reason
	}
	immediate = {
		set_variable = {
			name = lost_title_reason
			value = flag:negotiated
		}
		# Contract animations.
		if = {
			limit = { exists = var:animation }
			# Nothing.
		}
	}
}
