namespace = Plus

#reserved: Plus.1000 to Plus.1099

#######################################
# WAYLIT SIEGE EVENTS
#
# Original events by waylit
# Re-written by Rylock
#######################################

# On start of siege, send an event to the defender
character_event = {
	id = Plus.1000
	
	is_triggered_only = yes
	hide_window = yes
	
	trigger = {
		siege = { is_attacker = yes }
		rebel = no
		NOR = {
			has_landed_title = e_rebels
			any_liege = {
				OR = {
					rebel = yes
					has_landed_title = e_rebels
				}
			}
		}
		location = {
			any_province_lord = {
				capital_scope = { province = PREVPREV }
				NOT = {
					any_demesne_title = {
						location = { province = PREVPREVPREV }
						is_occupied = yes
					}
				}
				OR = {
					siege = { is_attacker = no }
					any_courtier = { siege = { is_attacker = no } }
				}
				OR = {
					any_courtier = {
						NOT = { character = PREV }
						host = { character = PREVPREV }
						at_location = ROOT
						prisoner = no
						OR = {
							dynasty = PREV
							is_ruler = yes
							any_close_relative = { is_ruler = yes }
						}
						NOR = {
							has_character_modifier = left_at_siege
							has_character_modifier = stalwart_defender
							is_inaccessible_trigger = yes
						}
					}
					AND = {
						at_location = ROOT
						NOR = {
							has_character_modifier = left_at_siege
							has_character_modifier = stalwart_defender
							is_inaccessible_trigger = yes
						}
					}
				}
			}
		}
	}
	
	immediate = {
		location = {
			random_province_lord = {
				limit = {
					capital_scope = { province = PREVPREV }
					NOT = {
						any_demesne_title = {
							location = { province = PREVPREVPREV }
							is_occupied = yes
						}
					}
					OR = {
						siege = { is_attacker = no }
						any_courtier = { siege = { is_attacker = no } }
					}
					OR = {
						any_courtier = {
							NOT = { character = PREV }
							host = { character = PREVPREV }
							at_location = ROOT
							prisoner = no
							OR = {
								dynasty = PREV
								is_ruler = yes
								any_close_relative = { is_ruler = yes }
							}
							NOR = {
								has_character_modifier = left_at_siege
								has_character_modifier = stalwart_defender
								is_inaccessible_trigger = yes
							}
						}
						AND = {
							at_location = ROOT
							NOR = {
								has_character_modifier = left_at_siege
								has_character_modifier = stalwart_defender
								is_inaccessible_trigger = yes
							}
						}
					}
				}
				save_event_target_as = siege_ruler
				any_courtier = {
					limit = {
						ai = yes
						NOT = { character = PREV }
						host = { character = PREVPREV }
						at_location = ROOT
						prisoner = no
						OR = {
							dynasty = PREV
							is_ruler = yes
							any_close_relative = { is_ruler = yes }
						}
						NOR = {
							is_close_relative = PREV
							has_character_modifier = left_at_siege
							has_character_modifier = stalwart_defender
							is_inaccessible_trigger = yes
						}
					}
					set_character_flag = in_danger
					set_character_flag = siege_escape_@PREV
				}
				any_courtier = {
					limit = {
						ai = no
						NOT = { character = PREV }
						host = { character = PREVPREV }
						at_location = ROOT
						prisoner = no
						OR = {
							dynasty = PREV
							is_ruler = yes
							any_close_relative = { is_ruler = yes }
						}
						NOR = {
							is_close_relative = PREV
							has_character_modifier = left_at_siege
							has_character_modifier = stalwart_defender
							is_inaccessible_trigger = yes
						}
					}
					set_character_flag = in_danger
					character_event = { id = Plus.1002 }
				}
				if = {
					limit = {
						OR = {
							any_courtier = {
								NOT = { character = PREV }
								host = { character = PREVPREV }
								at_location = ROOT
								prisoner = no
								is_close_relative = PREV
								NOR = {
									has_character_modifier = left_at_siege
									has_character_modifier = stalwart_defender
									is_inaccessible_trigger = yes
								}
							}
							AND = {
								at_location = ROOT
								NOR = {
									has_character_modifier = left_at_siege
									has_character_modifier = stalwart_defender
									is_inaccessible_trigger = yes
								}
							}
						}
					}
					character_event = { id = Plus.1001 }
					break = yes
				}
				random_courtier = {
					limit = { has_character_flag = siege_escape_@PREV }
					character_event = { id = Plus.1003 }
				}
			}
		}
	}
}

# Ruler notified of capital being besieged, given options
character_event = {
	id = Plus.1001
	title = EVTNAME_Plus_1001
	picture = GFX_evt_escape_siege
	border = GFX_event_normal_frame_war
	
	desc = {
		text = EVTDESC_Plus_1001
		trigger = {
			at_location = FROM
			prisoner = no
			NOT = { trait = incapable }
			is_adult = yes
		}
	}
	desc = {
		text = EVTDESC_Plus_1001_prisoner
		trigger = {
			at_location = FROM
			prisoner = yes
		}
	}
	desc = {
		text = EVTDESC_Plus_1001_incapable
		trigger = {
			at_location = FROM
			prisoner = no
			trait = incapable
		}
	}
	desc = {
		text = EVTDESC_Plus_1001_child
		trigger = {
			at_location = FROM
			prisoner = no
			NOT = { trait = incapable }
			is_adult = no
		}
	}
	desc = {
		text = EVTDESC_Plus_1001_away
		trigger = {
			NOT = { at_location = FROM }
		}
	}

	is_triggered_only = yes
	
	immediate = {
		save_event_target_as = siege_ruler
		if = {
			limit = {
				OR = {
					NOT = { at_location = FROM }
					prisoner = yes
					trait = incapable
					is_adult = no
				}
			}
			any_courtier = {
				limit = {
					NOT = { character = ROOT }
					host = { character = ROOT }
					at_location = FROM
					prisoner = no
					is_close_relative = ROOT
					NOR = {
						has_character_modifier = left_at_siege
						has_character_modifier = stalwart_defender
						is_inaccessible_trigger = yes
					}
				}
				set_character_flag = in_danger
			}
		}
		if = {
			limit = {
				any_courtier = {
					NOT = { character = ROOT }
					host = { character = ROOT }
					at_location = FROM
					prisoner = no
					is_close_relative = ROOT
					NOR = {
						has_character_modifier = left_at_siege
						has_character_modifier = stalwart_defender
						is_inaccessible_trigger = yes
					}
				}
			}
			set_character_flag = has_family_present
		}
	}
	
	option = {
		# ruler is not present, prisoner, incapable, or child and cannot make decision
		# any family present will automatically flee
		name = {
			text = EVTOPTA_Plus_1001
			trigger = {
				NOT = { at_location = FROM }
			}
		}
		name = {
			text = EVTOPTA_Plus_1001_prisoner
			trigger = {
				at_location = FROM
				prisoner = yes
			}
		}
		name = {
			text = EVTOPTA_Plus_1001_incapable
			trigger = {
				at_location = FROM
				prisoner = no
				trait = incapable
			}
		}
		name = {
			text = EVTOPTA_Plus_1001_child
			trigger = {
				at_location = FROM
				prisoner = no
				NOT = { trait = incapable }
				is_adult = no
			}
		}
		if = {
			limit = {
				at_location = FROM
				prisoner = no
			}
			# attempts to flee
			escape_siege_effect = yes
		}
		any_courtier = {
			limit = {
				NOT = { character = ROOT }
				host = { character = ROOT }
				at_location = FROM
				prisoner = no
				is_close_relative = ROOT
				NOR = {
					has_character_modifier = left_at_siege
					has_character_modifier = stalwart_defender
					is_inaccessible_trigger = yes
				}
			}
			# attempts to flee
			tooltip = { escape_siege_effect = yes }
			set_character_flag = siege_escape_@event_target:siege_ruler
		}
		clr_character_flag = has_family_present
		hidden_tooltip = {
			random_courtier = {
				limit = { has_character_flag = siege_escape_@event_target:siege_ruler }
				character_event = { id = Plus.1003 }
			}
		}
	}
	option = {
		# ruler is present, flees on their own
		name = {
			text = EVTOPTB_Plus_1001_alone
			trigger = { NOT = { has_character_flag = has_family_present } }
		}
		name = {
			text = EVTOPTB_Plus_1001_family
			trigger = { has_character_flag = has_family_present }
		}
		ai_chance = {
			factor = 3
			modifier = {
				factor = 0
				NOT = { trait = craven }
			}
		}
		trigger = {
			at_location = FROM
			prisoner = no
			NOT = { trait = incapable }
			is_adult = yes
		}
		if = {
			limit = { has_character_flag = has_family_present }
			prestige = -50
			if = {
				limit = {
					NOT = { trait = brave }
					NOT = { trait = craven }
				}
				random = {
					chance = 25
					add_trait = craven
				}
			}
			if = {
				limit = { trait = brave }
				remove_trait = brave
			}
		}
		random_list = {
			12 = {
				modifier = {
					factor = 1.5
					trait = genius
				}
				modifier = {
					factor = 1.25
					OR = {
						trait = quick
						trait = shrewd
					}
				}
				modifier = {
					factor = 0.75
					trait = brave
				}
				modifier = {
					factor = 1.25
					trait = craven
				}
				modifier = {
					factor = 0.75
					trait = wounded
				}
				modifier = {
					factor = 0.5
					trait = infirm
				}
				modifier = {
					factor = 0.5
					is_maimed_trigger = yes
				}
				modifier = {
					factor = 0.9
					is_adult = yes
					NOT = { trait = incapable }
					NOT = { intrigue = 2 }
				}
				modifier = {
					factor = 0.9
					is_adult = yes
					NOT = { trait = incapable }
					NOT = { intrigue = 4 }
				}
				modifier = {
					factor = 0.9
					is_adult = yes
					NOT = { trait = incapable }
					NOT = { intrigue = 6 }
				}
				modifier = {
					factor = 0.9
					is_adult = yes
					NOT = { trait = incapable }
					NOT = { intrigue = 8 }
				}
				modifier = {
					factor = 1.1
					is_adult = yes
					NOT = { trait = incapable }
					intrigue = 10
				}
				modifier = {
					factor = 1.1
					is_adult = yes
					NOT = { trait = incapable }
					intrigue = 12
				}
				modifier = {
					factor = 1.1
					is_adult = yes
					NOT = { trait = incapable }
					intrigue = 14
				}
				modifier = {
					factor = 1.1
					is_adult = yes
					NOT = { trait = incapable }
					intrigue = 16
				}
				modifier = {
					factor = 1.1
					is_adult = yes
					NOT = { trait = incapable }
					intrigue = 18
				}
				custom_tooltip = {
					text = EVTTOOLTIPsiegehide
					hidden_tooltip = {
						add_trait = in_hiding
						set_character_flag = in_hiding_siege
					}
				}
			}
			1 = {
				custom_tooltip = {
					text = EVTTOOLTIPsiegeremain
					hidden_tooltip = {
						set_character_flag = has_siege_effect
						add_character_modifier = {
							name = left_at_siege
							duration = 180
						}
					}
				}
			}
		}
		any_courtier = {
			limit = {
				NOT = { character = ROOT }
				host = { character = ROOT }
				at_location = FROM
				prisoner = no
				is_close_relative = ROOT
				NOR = {
					has_character_modifier = left_at_siege
					has_character_modifier = stalwart_defender
					is_inaccessible_trigger = yes
				}
			}
			# left behind
			clr_character_flag = in_danger
			custom_tooltip = {
				text = EVTTOOLTIPsiegeremain
				hidden_tooltip = {
					set_character_flag = has_siege_effect
					add_character_modifier = { name = left_at_siege duration = 180 }
					opinion = { who = ROOT modifier = opinion_outraged years = 3 }
				}
			}
		}
		clr_character_flag = has_family_present
		hidden_tooltip = {
			random_courtier = {
				limit = { has_character_flag = siege_escape_@event_target:siege_ruler }
				character_event = { id = Plus.1003 }
			}
		}
	}
	option = {
		# ruler is present, flees with family
		name = EVTOPTC_Plus_1001
		ai_chance = {
			factor = 10
		}
		trigger = {
			at_location = FROM
			prisoner = no
			NOT = { trait = incapable }
			is_adult = yes
			has_character_flag = has_family_present
		}
		escape_siege_effect = yes
		any_courtier = {
			limit = {
				NOT = { character = ROOT }
				host = { character = ROOT }
				at_location = FROM
				prisoner = no
				is_close_relative = ROOT
				NOR = {
					has_character_modifier = left_at_siege
					has_character_modifier = stalwart_defender
					is_inaccessible_trigger = yes
				}
			}
			# attempts to flee
			tooltip = { escape_siege_effect = yes }
			set_character_flag = siege_escape_@event_target:siege_ruler
		}
		clr_character_flag = has_family_present
		hidden_tooltip = {
			random_courtier = {
				limit = { has_character_flag = siege_escape_@event_target:siege_ruler }
				character_event = { id = Plus.1003 }
			}
		}
	}
	option = {
		# ruler is present, stays to defend
		name = {
			text = EVTOPTD_Plus_1001_alone
			trigger = { NOT = { has_character_flag = has_family_present } }
		}
		name = {
			text = EVTOPTD_Plus_1001_family
			trigger = { has_character_flag = has_family_present }
		}
		ai_chance = {
			factor = 3
			modifier = {
				factor = 0.5
				tier = king
			}
			modifier = {
				factor = 0.25
				tier = emperor
			}
			modifier = {
				factor = 0
				trait = craven
			}
			modifier = {
				factor = 0
				NOR = {
					trait = brave
					trait = lunatic
					trait = possessed
					trait = proud
				}
			}
		}
		trigger = {
			at_location = FROM
			prisoner = no
			NOT = { trait = incapable }
			is_adult = yes
		}
		# stalwart defender
		prestige = 50
		set_character_flag = has_siege_effect
		set_character_flag = defending_the_castle
		add_character_modifier = {
			name = stalwart_defender
			duration = 180
		}
		if = {
			limit = {
				NOT = { trait = brave }
				NOT = { trait = craven }
			}
			random = {
				chance = 25
				add_trait = brave
			}
		}
		if = {
			limit = { trait = craven }
			remove_trait = craven
		}
		hidden_tooltip = {
			any_courtier = {
				limit = {
					NOT = { character = ROOT }
					host = { character = ROOT }
					at_location = FROM
					prisoner = no
					is_close_relative = ROOT
					OR = {
						in_command = yes
						trait = brave
						martial = 12
					}
					NOR = {
						has_character_modifier = left_at_siege
						has_character_modifier = stalwart_defender
						is_inaccessible_trigger = yes
					}
				}
				# stalwart defender
				prestige = 25
				set_character_flag = has_siege_effect
				add_character_modifier = {
					name = stalwart_defender
					duration = 180
				}
			}
		}
		any_courtier = {
			limit = {
				NOT = { character = ROOT }
				host = { character = ROOT }
				at_location = FROM
				prisoner = no
				is_close_relative = ROOT
				NOR = {
					in_command = yes
					trait = brave
					martial = 12
					has_character_modifier = left_at_siege
					has_character_modifier = stalwart_defender
					is_inaccessible_trigger = yes
				}
			}
			# attempts to flee
			tooltip = { escape_siege_effect = yes }
			set_character_flag = siege_escape_@event_target:siege_ruler
		}
		clr_character_flag = has_family_present
		hidden_tooltip = {
			random_courtier = {
				limit = { has_character_flag = siege_escape_@event_target:siege_ruler }
				character_event = { id = Plus.1003 }
			}
		}
	}
}

# Player courtier decides whether to flee siege
character_event = {
	id = Plus.1002
	title = EVTNAME_Plus_1001
	picture = GFX_evt_escape_siege
	border = GFX_event_normal_frame_war
	
	desc = {
		text = EVTDESC_Plus_1001
		trigger = {
			is_adult = yes
			NOT = { trait = incapable }
		}
	}
	desc = {
		text = EVTDESC_Plus_1001_incapable
		trigger = {
			trait = incapable
		}
	}
	desc = {
		text = EVTDESC_Plus_1001_child
		trigger = {
			is_adult = no
			NOT = { trait = incapable }
		}
	}
	
	is_triggered_only = yes
	
	option = {
		name = EVTOPTB_Plus_1001_alone # Flee!
		escape_siege_effect = yes
		clr_character_flag = in_danger
	}
	option = {
		name = EVTOPTD_Plus_1001_alone # Valiantly remain
		trigger = {
			is_adult = yes
			NOT = { trait = incapable }
		}
		prestige = 25
		add_character_modifier = {
			name = stalwart_defender
			duration = 180
		}
		if = {
			limit = {
				NOT = { trait = brave }
				NOT = { trait = craven }
			}
			random = {
				chance = 25
				add_trait = brave
			}
		}
		if = {
			limit = { trait = craven }
			random = {
				chance = 25
				remove_trait = craven
			}
		}
		clr_character_flag = in_danger
	}
}

# Randomized check for success
character_event = {
	id = Plus.1003
	
	is_triggered_only = yes
	hide_window = yes
	
	immediate = {
		escape_siege_effect = yes
		clr_character_flag = siege_escape_@event_target:siege_ruler
		clr_character_flag = in_danger
		location = {
			random_province_character = {
				limit = { has_character_flag = siege_escape_@event_target:siege_ruler }
				character_event = { id = Plus.1003 }
			}
		}
	}
}

# Escape from a siege where you have not hidden						
character_event = {
	id = Plus.1005 #formerly 1100099992
	title = "EVTNAME_Plus_1005"
	desc = "EVTDESC_Plus_1005"
	picture = "GFX_evt_siege"
	border = "GFX_event_normal_frame_war"

	is_triggered_only = yes
	
	only_rulers = yes
	min_age = 16
	is_patrician = no
	prisoner = no
	
	trigger = {
		siege = {
			is_attacker = no
			enemy = {
				leader = {
					NOT = { has_landed_title = e_rebels }
					rebel = no
				}
			}
		}
		location = { is_capital = yes }
		health = 4
		NOT = { trait = incapable }
		at_location = FROM
		has_character_modifier = stalwart_defender
		had_character_flag = { flag = defending_the_castle days = 20 }
	}

	option = { 
		name = "EVTOPTA_Plus_1005" #Slip out a postern door at midnight.
		ai_chance = { 
			factor = 0.75 
			modifier = {
				factor = 0.5
				trait = craven 
			}
			modifier = {
				factor = 2
				trait = brave 
			}
			modifier = {
				factor = 1.5
				trait = ambitious 
			}
			modifier = {
				factor = 0.75
				trait = slothful 
			}
		}
		
		hidden_tooltip = {
			clr_character_flag = defending_the_castle
			random = { 
				chance = 25
				if = {
					limit = { trait = craven }
					remove_trait = craven
				}
				add_trait = brave 
				character_event = { id = 38270 }
			}
			random = { 
				chance = 10
				if = {
					limit = { trait = slothful }
					remove_trait = slothful
					character_event = { id = 38298 }	
				}
			}
			random = { 
				chance = 10
				if = {
					limit = { trait = content }
					remove_trait = content
					character_event = { id = 38299 }	
				}
			}
		}
		random_list = {
			33 = {
				custom_tooltip = {
					text = EVTTOOLTIPsiegeescaped
				}
					hidden_tooltip = {
						character_event = { id = Plus.1007 }
					}
			}
			66 = {
				ROOT = { 
					custom_tooltip = {
						text = EVTTOOLTIPsiegecapturedenemy 
					}
					set_character_flag = captured 
				}
				hidden_tooltip = {
					ROOT = { character_event = { id = Plus.1006 } }		
					siege = { enemy = { leader = { character_event = { id = Plus.1010 } } } }
				}
			}	
		}
	}
	option = { 
		name = "EVTOPTB_Plus_1005" #Brave the sewers.
		ai_chance = { 
			factor = 0.5 
			modifier = {
				factor = 5
				trait = ambitious 
			}
			modifier = {
				factor = 20
				trait = brave 
			}
			modifier = {
				factor = 20
				trait = humble 
			}
			modifier = {
				factor = 0.5
				trait = craven 
			}
			modifier = {
				factor = 0.75
				trait = slothful 
			}
		}		
		hidden_tooltip = {
			clr_character_flag = defending_the_castle
			random = { 
				chance = 25
				if = { 
					limit = { trait = craven }
					remove_trait = craven
				}
				add_trait = brave
				character_event = { id = 38270 }
			}
			random = { 
				chance = 25
				if = { 
					limit = { trait = proud }
					remove_trait = proud
				}
				add_trait = humble
				character_event = { id = 38260 }				
			}
			random = { 
				chance = 10
				remove_trait = slothful
				character_event = { id = 38298 }
			}
			random = { 
				chance = 10
				remove_trait = content
				character_event = { id = 38299 }
			}
			random = { 
				chance = 10
				give_ill_effect = yes
				character_event = { id = 38290 }
			}
			random = { 
				chance = 5
				add_trait = wounded
				character_event = { id = 38280 }
			}
			random = { 
				chance = 5
				give_pneumonic_effect = yes
				character_event = { id = 38290 }
			}
			random = { 
				chance = 5
				add_trait = infirm
				character_event = { id = 38284 }
			}
			random = { 
				chance = 1
				add_maimed_trait_effect = yes
				character_event = { id = 38281 }
			}
		}
		custom_tooltip = { text = "dis_chance" }
		hidden_tooltip = {
			random = { 
				chance = 1
				give_has_tuberculosis_effect = yes
			}
			random = { 
				chance = 1
				give_has_bubonic_plague_effect = yes
			}
			random = { 
				chance = 1
				give_has_typhoid_fever_effect = yes
			}
			random = { 
				chance = 1
				give_food_poisoning_effect = yes
			}
			random = { 
				chance = 1
				give_has_small_pox_effect = yes
			}
			random = { 
				chance = 1
				give_has_measles_effect = yes
			}
			random = { 
				chance = 1
				add_trait = leper
			}
		}
		random_list = {
			75 = {
				custom_tooltip = {
					text = EVTTOOLTIPsiegeescaped
				}
				hidden_tooltip = {
					character_event = { id = Plus.1008 }
				}
			}
			25 = {
				ROOT = { 
					custom_tooltip = { 
						text = EVTTOOLTIPsiegecapturedenemy 
					}
					set_character_flag = captured 
				}
				hidden_tooltip = {
					ROOT = { character_event = { id = Plus.1006 } }
					siege = { enemy = { leader = { character_event = { id = Plus.1010 } } } } 
				}
		 
			}
		}
	}
	option = { 
		name = "EVTOPTC_Plus_1005" #Just give me a rope...
		trigger = {
			NOR = {
				is_weak_trigger = yes
				is_ill = yes
			}
		}
		ai_chance = { 
			factor = 0.1 
			modifier = {
				factor = 5
				trait = ambitious 
			}
			modifier = {
				factor = 20
				trait = lunatic 
			}
			modifier = {
				factor = 20
				trait = possessed 
			}
			modifier = {
				factor = 10
				trait = brave 
			}
			modifier = {
				factor = 0.5
				trait = craven 
			}
			modifier = {
				factor = 0.5
				trait = slothful 
			}
			modifier = {
				factor = 0.1
				trait = clubfooted
			}
		}
		clr_character_flag = defending_the_castle
		hidden_tooltip = {
			random = { 
				chance = 50
				if = {
					limit = { trait = craven }
					remove_trait = craven
				}
				add_trait = brave 
				character_event = { id = 38270 }
			}
			random = {
				chance = 50
				if = {
					limit = { trait = humble }
					remove_trait = humble
				}
				add_trait = proud 
				character_event = { id = 38261 }
			}
			random = { 
				chance = 20
				add_trait = lunatic
				character_event = { id = 38304 }
			}
			random = { 
				chance = 20
					if = {
						limit = { trait = paranoid }
						remove_trait = paranoid
					}
					add_trait = trusting
					character_event = { id = 38250 }
			}
			random = { 
				chance = 20
				if = {
					limit = { trait = slothful }
					remove_trait = slothful
					character_event = { id = 38298 }
				}
				if = {
					limit = { trait = content }
					remove_trait = content
					character_event = { id = 38299 }
				}
			}
			random = { 
				chance = 5
				add_trait = wounded
				character_event = { id = 38280 }
			}
			random = { 
				chance = 10
				add_maimed_trait_effect = yes
				character_event = { id = 38281 }
			}
		}
		random_list = {
			70 = {
				custom_tooltip = { 
					text = EVTTOOLTIPsiegeescaped
				}
				hidden_tooltip = {
					character_event = { id = Plus.1009 }
				}
			}
			20 = {
				ROOT = { 
					custom_tooltip = { 
						text = EVTTOOLTIPsiegecapturedenemy
					}
					set_character_flag = captured 
				}		
				hidden_tooltip = {
					ROOT = { character_event = { id = Plus.1006 } }
					siege = { enemy = { leader = { character_event = { id = Plus.1010 } } } }
				}
			}
			10 = {
				ROOT = { death = { death_reason = death_battle } }
			}
		}
	}
	option = {
		name = "EVTOPTD_Plus_1005" #I think it's better we wait.
		ai_chance = {
			factor = 5 
			modifier = {
				factor = 2
				trait = content 
			}
			modifier = {
				factor = 2
				trait = patient 
			}
			modifier = {
				factor = 2
				trait = craven 
			}
			modifier = {
				factor = 0.5
				trait = ambitious 
			}
			modifier = {
				factor = 0.1
				trait = brave
			}
			modifier = {
				factor = 2
				trait = slothful 
			}
		}
		hidden_tooltip = {
			clr_character_flag = defending_the_castle
			random = { 
				chance = 25
				if = {
					limit = { trait = wroth }
					remove_trait = wroth
				}
				add_trait = patient
				character_event = { id = 38264 }
			}
			if = {
				limit = {
					NOR = {
						trait = stressed
						trait = depressed
					}
				}
				random = {
					chance = 25
					add_trait = stressed
					hidden_tooltip = {
						character_event = {
							id = 38282 #Notify Stressed
						}
					}
				}
			}
			random = { 
				chance = 5
				if = {
					limit = { trait = brave }
					remove_trait = brave
				}
				add_trait = craven
				character_event = { id = 38257 }
			}
			random = { 
				chance = 5
				if = {
					limit = { trait = greedy }
					remove_trait = greedy
				}
				add_trait = temperate
				character_event = { id = 38276 }
			}
			random = { 
				chance = 5
				if = {
					limit = { trait = trusting }
					remove_trait = trusting
				}
				add_trait = paranoid
				character_event = { id = 38275 }
			}
		}
	}
}
		
# Captured by the enemy while trying to flee the castle
character_event = {
	id = Plus.1006 #formerly 1100099993
	title = "EVTNAME_Plus_1005"
	desc = "EVTDESC_Plus_1006"
	picture = "GFX_evt_into_the_dungeon"
	border = "GFX_event_normal_frame_war"
	
	is_triggered_only = yes
	
	option = {
		name = "CURSES"
		remove_character_modifier = stalwart_defender
		ROOT = {
			custom_tooltip = { 
				text = EVTTOOLWAYfamilyhatesyou
			}
		}		
	}
}

# Successful escape by postern door
character_event = {
	id = Plus.1007 #formerly 1100099994
	title = "EVTNAME_Plus_1005"
	desc = "EVTDESC_Plus_1007"
	picture = "GFX_evt_escape_siege"
	border = "GFX_event_normal_frame_war"
	
	is_triggered_only = yes
	
	trigger = { is_alive = yes }

	option = {
		name = "EVTTOOLTIPsiegeescaped"
		add_trait = in_hiding
		set_character_flag = in_hiding_siege
		hidden_tooltip = {
			remove_character_modifier = left_at_siege
			remove_character_modifier = stalwart_defender
		}		
		add_character_modifier = {
			name = escaped_siege
			duration = 365
		}
		any_courtier = {
			limit = {
				is_close_relative = ROOT
				in_command = no
				at_location = ROOT
				NOT = { is_inaccessible_trigger = yes }
			}
			opinion = {
				modifier = left_behind
				who = ROOT
				months = 12
			}
		}
	}
}

# Successful escape by sewer
character_event = {
	id = Plus.1008 #formerly 1100099995
	title = "EVTNAME_Plus_1005"
	desc = "EVTDESC_Plus_1008"
	picture = "GFX_evt_escape_siege"
	border = "GFX_event_normal_frame_war"
	
	is_triggered_only = yes
	
	trigger = { is_alive = yes }

	option = {
		name = "EVTTOOLTIPsiegeescaped"
		add_trait = in_hiding
		set_character_flag = in_hiding_siege
		hidden_tooltip = {
			remove_character_modifier = left_at_siege
			remove_character_modifier = stalwart_defender
		}
		add_character_modifier = {
			name = escaped_siege
			duration = 365
		}
		any_courtier = {
			limit = {
				is_close_relative = ROOT
				in_command = no
				at_location = ROOT
				NOT = { is_inaccessible_trigger = yes }
			}
			opinion = {
				modifier = left_behind
				who = ROOT
				months = 12
			}
		}
	}
}

# Successful escape by wall
character_event = {
	id = Plus.1009 #formerly 1100099996
	title = "EVTNAME_Plus_1005"
	desc = "EVTDESC_Plus_1009"
	picture = "GFX_evt_escape_siege"
	border = "GFX_event_normal_frame_war"
	
	is_triggered_only = yes
	
	trigger = { is_alive = yes }

	option = {
		name = "EVTTOOLTIPsiegeescaped"
		add_trait = in_hiding
		set_character_flag = in_hiding_siege
		hidden_tooltip = {
			remove_character_modifier = left_at_siege
			remove_character_modifier = stalwart_defender
		}
		add_character_modifier = {
			name = escaped_siege
			duration = 365
		}
		any_courtier = {
			limit = {
				is_close_relative = ROOT
				in_command = no
				at_location = ROOT
				NOT = { is_inaccessible_trigger = yes }
			}
			opinion = {
				modifier = left_behind
				who = ROOT
				months = 12
			}
		}
	}
}
	
# Notify siege leader that ruler was captured
character_event = {
	id = Plus.1010 #formerly 1100099997
	title = "EVTNAME_Plus_1005"
	desc = "EVTDESC_Plus_1010"
	picture = "GFX_evt_into_the_dungeon"
	border = "GFX_event_normal_frame_war"
	
	is_triggered_only = yes
	
	option = {
		name = "EVTOPTA_Plus_1010"
		siege = {
			enemy = {
				leader = {
					if = {
						limit = { 
							has_character_flag = captured 
							NOT = { is_inaccessible_trigger = yes }
						}
						imprison = ROOT 
						clr_character_flag = captured
						hidden_tooltip = {
							remove_character_modifier = left_at_siege
							remove_character_modifier = stalwart_defender
							any_courtier = {
								limit = {
									is_close_relative = ROOT
									in_command = no
									at_location = ROOT
									NOT = { is_inaccessible_trigger = yes }
								}
								opinion = {
									modifier = left_behind
									who = ROOT
									months = 12
								}
							}
						}
					}
				}
			}
		}	
	}
}

### SIEGE SUCCESS EVENTS -- IMPRISONMENT

# Unit leader at the siege gets the main imprisonment event (if not unreformed pagan)
character_event = {
	id = Plus.1020
	
	is_triggered_only = yes
	hide_window = yes
	
	trigger = {
		rebel = no
		NOR = {
			has_landed_title = e_rebels
			has_landed_title = e_mexikha
			any_liege = { has_landed_title = e_mexikha }
		}
		OR = {
			is_pagan_religion = no
			is_reformed_pagan_religion = yes
			FROM = { holder_scope = { religion = ROOT } }
		}
		FROM = {
			holder_scope = {
				war_with = ROOT
				NOT = { character = ROOT }
				capital_holding = { title = PREVPREV }
			}
		}
	}
	
	immediate = {
		FROM = { save_event_target_as = siege_holding }
		FROM = { holder_scope = { save_event_target_as = siege_owner } }
		location = { save_event_target_as = siege_province }
		
		if = {
			limit = {
				is_ruler = no
				liege = { war_with = event_target:siege_owner }
			}
			event_target:siege_owner = {
				if = {
					limit = {
						OR = {
							at_location = ROOT
							any_courtier = {
								at_location = ROOT
								in_command = no
								prisoner = no
								OR = {
									is_ruler = yes
									dynasty = PREV
									any_close_relative = { is_ruler = yes }
								}
							}
						}
					}
					ROOT = {
						liege = {
							character_event = { id = Plus.1021 } # not present but family present
						}
					}
				}
				if = {
					limit = {
						any_courtier = {
							prisoner = yes
							host = { character = PREVPREV }
						}
					}
					ROOT = {
						liege = {
							character_event = { id = Plus.1024 } # prisoners present
						}
					}
				}
			}
		}
		if = {
			limit = {
				is_ruler = yes
			}
			event_target:siege_owner = {
				if = {
					limit = {
						OR = {
							at_location = ROOT
							any_courtier = {
								at_location = ROOT
								in_command = no
								prisoner = no
								OR = {
									is_ruler = yes
									dynasty = PREV
									any_close_relative = { is_ruler = yes }
								}
							}
						}
					}
					ROOT = {
						character_event = { id = Plus.1021 } # not present but family present
					}
				}
				if = {
					limit = {
						any_courtier = {
							prisoner = yes
							host = { character = PREVPREV }
						}
					}
					ROOT = {
						character_event = { id = Plus.1024 } # prisoners present
					}
				}
			}
		}
	}
}

# Siege resolution - normal
character_event = {
	id = Plus.1021
	desc = EVTDESC_Plus_1021
	picture = GFX_evt_siege
	border = GFX_event_normal_frame_war
	
	desc = {
		text = EVTDESC_Plus_1021
		trigger = {
			event_target:siege_owner = {
				at_location = FROM
				NOT = { is_inaccessible_trigger = yes }
			}
		}
	}
	desc = {
		text = EVTDESC_Plus_1022
		trigger = {
			event_target:siege_owner = {
				at_location = FROM
				is_inaccessible_trigger = yes
			}
		}
	}
	desc = {
		text = EVTDESC_Plus_1023
		trigger = {
			event_target:siege_owner = {
				NOT = { at_location = FROM }
			}
		}
	}

	hide_from = yes
	is_triggered_only = yes
	
	immediate = {
		save_event_target_as = siege_attacker
	}
	
	option = {
		trigger = {
			event_target:siege_owner = { at_location = FROM }
		}
		name = {
			text = EVTOPTA_Plus_1021 #Take him prisoner at once
			trigger = { event_target:siege_owner = { NOT = { is_inaccessible_trigger = yes } } }
		}
		name = {
			text = EVTOPTA_Plus_1022 #Find him -- he's the only one we want
			trigger = { event_target:siege_owner = { is_inaccessible_trigger = yes } }
		}
		ai_chance = {
			factor = 10
			modifier = {
				factor = 50  
				event_target:siege_owner = { primary_title = { higher_tier_than = COUNT } }
			}
			modifier = {
				factor = 100  
				event_target:siege_owner = { primary_title = { higher_tier_than = DUKE } }
			}
			modifier = {
				factor = 0.25  
				event_target:siege_owner = { primary_title = { lower_tier_than = COUNT } }
			}
			modifier = {
				factor = 2
				trait = cruel
			}
			modifier = {
				factor = 2
				trait = greedy
			}
			modifier = {
				factor = 2
				trait = envious
			}
			modifier = {
				factor = 10
				trait = impaler
			}
			modifier = {
				factor = 10
				trait = wroth
			}
			modifier = {
				factor = 0.25
				trait = charitable
			}
			modifier = {
				factor = 1.5
				trait = just
			}

		}
		if = {
			limit = {
				NOT = { trait = just }
				event_target:siege_owner = {
					any_courtier = {
						at_location = FROM
						prisoner = no
						in_command = no
						OR = {
							is_ruler = yes
							dynasty = PREV
							any_close_relative = { is_ruler = yes }
						}
					}
				}
			}
			random = { 
				chance = 5
				if = {
					limit = {
						NOT = { trait = just }
						NOT = { trait = arbitrary }
					}
					add_trait = just
					character_event = { id = 38267 } # I am Just!
				}
				if = {
					limit = { trait = arbitrary }
					remove_trait = arbitrary
				}				
			}
		}
		any_character = {
			limit = { character = event_target:siege_owner }
			siege_capture_check_effect = yes
		}
	}
	option = {
		name = {
			text = EVTOPTB_Plus_1021 #Imprison him and anyone else we find
			trigger = {
				event_target:siege_owner = {
					at_location = FROM
					NOT = { is_inaccessible_trigger = yes }
				}
			}
		}
		name = {
			text = EVTOPTB_Plus_1022 #Find him and anyone else of importance
			trigger = {
				event_target:siege_owner = {
					at_location = FROM
					is_inaccessible_trigger = yes
				}
			}
		}
		name = {
			text = EVTOPTA_Plus_1023 #Grab anyone of importance we can find
			trigger = {
				event_target:siege_owner = {
					NOT = { at_location = FROM }
				}
			}
		}
		trigger = {
			event_target:siege_owner = {
				any_courtier = {
					at_location = FROM
					prisoner = no
					in_command = no
					OR = {
						is_ruler = yes
						dynasty = PREV
						any_close_relative = { is_ruler = yes }
					}
				}
			}
		}
		ai_chance = {
			factor = 0.5
			modifier = {
				factor = 0.1
				event_target:siege_owner = { primary_title = { lower_tier_than = COUNT } }
			}
			modifier = {
				factor = 40
				event_target:siege_owner = { 
					any_dynasty_member = { primary_title = { higher_tier_than = COUNT } }
				}
			}
			modifier = {
				factor = 100
				event_target:siege_owner = { 
					any_dynasty_member = { primary_title = { higher_tier_than = DUKE } }
				}
			}
			modifier = {
				factor = 8
				trait = cruel
			}
			modifier = {
				factor = 8
				trait = greedy
			}
			modifier = {
				factor = 0
				trait = kind
			}
			modifier = {
				factor = 20
				trait = impaler
			}
			modifier = {
				factor = 20
				trait = wroth
			}	
		}
		if = {
			limit = { NOT = { trait = greedy } }
			random = { 			
				chance = 10
				if = {
					limit = {
						NOT = { trait = greedy }
						NOT = { trait = charitable }
					}
					add_trait = greedy
					character_event = { id = 38252 } # I am greedy!
				}
				if = {
					limit = { trait = charitable }
					remove_trait = charitable
				}
			}
		}
		any_character = {
			limit = {
				at_location = FROM
				character = event_target:siege_owner
			}
			siege_capture_check_effect = yes
			any_courtier = {
				limit = {
					NOT = { character = event_target:siege_owner }
					host = { character = event_target:siege_owner }
					at_location = FROM
					prisoner = no
					in_command = no
					OR = {
						is_ruler = yes
						dynasty = PREV
						any_close_relative = { is_ruler = yes }
					}
				}
				set_character_flag = siege_capture_@event_target:siege_owner
				show_portrait = yes
				tooltip = { siege_capture_check_effect = yes }
			}
			hidden_tooltip = {
				random_courtier = {
					limit = { has_character_flag = siege_capture_@event_target:siege_owner }
					character_event = { id = Plus.1034 }
				}
			}
		}
	}
	option = {
		name = {
			text = EVTOPTC_Plus_1021 #Kill him and anyone else within
			trigger = {
				event_target:siege_owner = {
					at_location = FROM
					NOT = { is_inaccessible_trigger = yes }
				}
			}
		}
		name = {
			text = EVTOPTC_Plus_1022 #Kill everyone we can find
			trigger = {
				event_target:siege_owner = {
					OR = {
						NOT = { at_location = FROM }
						is_inaccessible_trigger = yes
					}
				}
			}
		}
		trigger = {
			NOR = {
				trait = just
				trait = kind
			}
		}
		ai_chance = {
			factor = 0.5
			modifier = {
				factor = 0
				event_target:siege_owner = {
					ROOT = {
						independent = no
						liege = {
							OR = {
								is_close_relative = PREVPREV
								dynasty = PREVPREV
							}
						}
					}
				}
			}
			modifier = {
				factor = 0
				event_target:siege_owner = { is_close_relative = ROOT }
			}
			modifier = {
				factor = 0.1
				event_target:siege_owner = { dynasty = ROOT }
			}
			modifier = {
				factor = 20
				trait = cruel
			}
			modifier = {
				factor = 10
				trait = arbitrary
			}
			modifier = {
				factor = 0.5
				trait = diligent
			}
			modifier = {
				factor = 20
				trait = impaler
			}
			modifier = {
				factor = 20
				trait = wroth
			}
			modifier = {
				factor = 0.3
				trait = charitable
			}
			modifier = {
				factor = 0.3
				trait = humble
			}
			modifier = {
				factor = 0.5
				trait = honest
			}
		}
		if = {
			limit = { NOT  = { lifestyle_traits = 1 } }
			random = {
				chance = 50
				add_trait = impaler
			}
		}
		if = {
			limit = { NOT = { trait = cruel } }
			random = { 			
				chance = 50
				add_trait = cruel
				hidden_tooltip = { character_event = { id = 38259 } } # notify cruel
			}
		}
		if = {
			limit = { NOT = { trait = arbitrary } }
			random = { 			
				chance = 20
				add_trait = arbitrary
				hidden_tooltip = { character_event = { id = 38266 } } # notify arbitrary
			}
		}
		if = {
			limit = { religion = event_target:siege_owner }
			if = {
				limit = {
					trait = dishonorable4
				}
				remove_trait = dishonorable4
				add_trait = dishonorable5
			}
			if = {
				limit = {
					trait = dishonorable3
				}
				remove_trait = dishonorable3
				add_trait = dishonorable4
			}
			if = {
				limit = {
					trait = dishonorable2
				}
				remove_trait = dishonorable2
				add_trait = dishonorable3
			}
			if = {
				limit = {
					trait = dishonorable1
				}
				remove_trait = dishonorable1
				add_trait = dishonorable2
			}
			if = {
				limit = {
					trait = dyn_dishonorable4
				}
				remove_trait = dyn_dishonorable4
				add_trait = dishonorable5
			}
			if = {
				limit = {
					trait = dyn_dishonorable3
				}
				remove_trait = dyn_dishonorable3
				add_trait = dishonorable4
			}
			if = {
				limit = {
					trait = dyn_dishonorable2
				}
				remove_trait = dyn_dishonorable2
				add_trait = dishonorable3
			}
			if = {
				limit = {
					trait = dyn_dishonorable1
				}
				remove_trait = dyn_dishonorable1
				add_trait = dishonorable2
			}
			if = {
				limit = {
					NOT = { trait = dishonorable1 }
					NOT = { trait = dishonorable2 }
					NOT = { trait = dishonorable3 }
					NOT = { trait = dishonorable4 }
					NOT = { trait = dishonorable5 }
					NOT = { trait = dishonorable6 }
					NOT = { trait = dishonorable7 }
					NOT = { trait = dishonorable8 }
					NOT = { trait = dishonorable9 }
					NOT = { trait = dishonorable10 }
					NOT = { trait = dyn_dishonorable1 }
					NOT = { trait = dyn_dishonorable2 }
					NOT = { trait = dyn_dishonorable3 }
					NOT = { trait = dyn_dishonorable4 }
					NOT = { trait = dyn_dishonorable5 }
					NOT = { trait = dyn_dishonorable6 }
					NOT = { trait = dyn_dishonorable7 }
					NOT = { trait = dyn_dishonorable8 }
					NOT = { trait = dyn_dishonorable9 }
					NOT = { trait = dyn_dishonorable10 }
				}
				add_trait = dishonorable1
			}
		}
		any_character = {
			limit = {
				at_location = FROM
				character = event_target:siege_owner
			}
			siege_kill_check_effect = yes
			any_courtier = {
				limit = {
					NOT = { character = event_target:siege_owner }
					host = { character = event_target:siege_owner }
					at_location = FROM
					prisoner = no
					in_command = no
					OR = {
						is_ruler = yes
						dynasty = PREV
						any_close_relative = { is_ruler = yes }
					}
				}
				set_character_flag = siege_kill_@event_target:siege_owner
				show_portrait = yes
				tooltip = { siege_kill_check_effect = yes }
			}
			hidden_tooltip = {
				random_courtier = {
					limit = { has_character_flag = siege_kill_@event_target:siege_owner }
					character_event = { id = Plus.1035 }
				}
			}
		}
	}
	option = {
		name = {
			text = EVTOPTD_Plus_1021 #Leave him and his family be.
			trigger = {
				event_target:siege_owner = {
					at_location = FROM
				}
			}
		}
		name = {
			text = EVTOPTC_Plus_1023 #Leave them be.
			trigger = {
				event_target:siege_owner = {
					NOT = { at_location = FROM }
				}
			}
		}
		ai_chance = {
			factor = 1
			modifier = {
				factor = 10
				trait = kind
			}
			modifier = {
				factor = 3
				trait = charitable
			}
			modifier = {
				factor = 3
				trait = humble
			}
			modifier = {
				factor = 0.5
				trait = wroth
			}
			modifier = {
				factor = 0.5
				trait = greedy
			}
			modifier = {
				factor = 0.5
				trait = cruel
			}	
		}
		if = {
			limit = { NOT = { trait = kind } }
			random = { 			
				chance = 10
				if = {
					limit = {
						NOT = { trait = kind }
						NOT = { trait = cruel }
					}
					add_trait = kind
					hidden_tooltip = { character_event = { id = 38268 } } # notify kind
				}
				if = {
					limit = { trait = cruel }
					remove_trait = cruel
				}
			}
		}
		if = {
			limit = { NOT = { trait = charitable } }
			random = { 			
				chance = 10
				if = {
					limit = {
						NOT = { trait = charitable }
						NOT = { trait = greedy }
					}
					add_trait = charitable
					character_event = { id = 38273 } # I am charitable!
				}
				if = {
					limit = { trait = greedy }
					remove_trait = greedy
				}
			}
		}
		any_character = {
			limit = {
				character = event_target:siege_owner
				at_location = FROM
			}
			opinion = { who = ROOT modifier = opinion_relieved months = 12 }
		}
		any_character = {
			limit = {
				NOT = { character = event_target:siege_owner }
				host = { character = event_target:siege_owner }
				at_location = FROM
				prisoner = no
				in_command = no
				OR = {
					is_ruler = yes
					dynasty = PREV
					any_close_relative = { is_ruler = yes }
				}
			}
			opinion = { who = ROOT modifier = opinion_relieved months = 12 }
		}
	}
}

# Attacker gets the option to release any prisoners within
character_event = {
	id = Plus.1024
	desc = EVTDESC_Plus_1024
	picture = GFX_evt_into_the_dungeon
	border = GFX_event_normal_frame_war
	
	hide_from = yes
	is_triggered_only = yes
	
	option = {
		name = EVTOPTA_Plus_1024 #Release all prisoners
		trigger = {
			event_target:siege_owner = {
				war_with = ROOT
				any_courtier = {
					prisoner = yes
					host = { character = event_target:siege_owner }
				}
			}
		}
		ai_chance = { 
			factor = 0.25
			modifier = {
				factor = 2
				trait = kind
			}
			modifier = {
				factor = 2
				trait = trusting
			}
			modifier = {
				factor = 0
				OR = {
					trait = cruel
					trait = greedy
				}
			}
			modifier = {
				factor = 2
				trait = charitable
			}
			modifier = {
				factor = 0.5
				trait = wroth
			}
			modifier = {
				factor = 0.5
				trait = cynical
			}
			modifier = {
				factor = 0.5
				trait = paranoid
			}
		}
		random = {
			chance = 10
			if = {
				limit = {
					NOT = { trait = kind }
					NOT = { trait = cruel }
				}
				add_trait = kind
				hidden_tooltip = { character_event = { id = 38268 } } # I am kind!
			}
			if = {
				limit = { trait = cruel }
				remove_trait = cruel
			}
		}
		random = {
			chance = 10
			if = {
				limit = {
					NOT = { trait = charitable }
					NOT = { trait = greedy }
				}
				add_trait = charitable
				hidden_tooltip = { character_event = { id = 38273 } } # I am charitable!
			}
			if = {
				limit = { trait = greedy }
				remove_trait = greedy
			}
		}
		event_target:siege_owner = {
			any_courtier = {
				limit = {
					prisoner = yes
					host = { character = event_target:siege_owner }
				}
				prisoner = no
			}
		}	
	}
	option = {
		name = EVTOPTB_Plus_1024 #Transfer them to my dungeon!
		trigger = {
			event_target:siege_owner = {
				war_with = ROOT
				any_courtier = {
					prisoner = yes
					host = { character = event_target:siege_owner }
				}
				NOT = {
					any_courtier = {
						prisoner = yes
						host = { character = event_target:siege_owner }
						OR = {
							dynasty = ROOT
							is_close_relative = ROOT
						}
					}
				}
			}
		}
		ai_chance = { 
			factor = 0.1 
			modifier = {
				factor = 0
				OR = {
					trait = kind
					trait = charitable
				}
			}
			modifier = {
				factor = 0.1
				trait = just
			}
			modifier = {
				factor = 10
				trait = ambitious
			}
			modifier = {
				factor = 10
				trait = cruel
			}
			modifier = {
				factor = 10
				trait = greedy
			}
			modifier = {
				factor = 5
				trait = wroth
			}
			modifier = {
				factor = 5
				trait = cynical
			}
			modifier = {
				factor = 5
				trait = paranoid
			} 
		}
		random = {
			chance = 10
			if = {
				limit = {
					NOT = { trait = kind }
					NOT = { trait = cruel }
				}
				add_trait = cruel
				hidden_tooltip = { character_event = { id = 38259 } } # I am cruel!
			}
			if = {
				limit = { trait = kind }
				remove_trait = kind
			}
		}
		random = {
			chance = 10
			if = {
				limit = {
					NOT = { trait = charitable }
					NOT = { trait = greedy }
				}
				add_trait = greedy
				hidden_tooltip = { character_event = { id = 38252 } } # I am greedy!
			}
			if = {
				limit = { trait = charitable }
				remove_trait = charitable
			}
		}
		event_target:siege_owner = {
			any_courtier = {
				limit = {
					prisoner = yes
					host = { character = event_target:siege_owner }
				}
				custom_tooltip = {
					text = MOVED_TO_MY_DUNGEON
					hidden_tooltip = {
						prisoner = no
						imprison = ROOT
					}
				}
				opinion = {
					who = ROOT
					modifier = opinion_angry
					months = 60
				}
			}
		}	
	}
	option = {
		name = EVTOPTC_Plus_1024 #Release anyone within whom we have common cause
		trigger = {
			event_target:siege_owner = {
				war_with = ROOT
				any_courtier = {
					prisoner = yes
					host = { character = event_target:siege_owner }
					war_with = PREV
				}
				any_courtier = {
					prisoner = yes
					host = { character = event_target:siege_owner }
					NOT = { war_with = PREV }
				}
			}
		}
		ai_chance = { 
			factor = 1.5 
			modifier = {
				factor = 2
				trait = kind
			}
			modifier = {
				factor = 2
				trait = trusting
			}
			modifier = {
				factor = 2
				trait = just
			}
			modifier = {
				factor = 0.5
				trait = cruel
			}
			modifier = {
				factor = 0.5
				trait = wroth
			}
			modifier = {
				factor = 0.5
				trait = cynical
			}
			modifier = {
				factor = 0.5
				trait = paranoid
			} 
		}
		random = { 		
			chance = 10
			if = {
				limit = {
					NOT = { trait = just }
					NOT = { trait = arbitrary }
				}
				add_trait = just
				character_event = { id = 38267 } #I am just!
			}
			if = {
				limit = { trait = arbitrary }
				remove_trait = arbitrary
			}
		}
		event_target:siege_owner = {
			any_courtier = {
				limit = {
					prisoner = yes
					host = { character = event_target:siege_owner }
					war_with = PREV
				}
				prisoner = no
			}
		}
	}
	option = {
		name = EVTOPTD_Plus_1024 #Release only my relatives
		trigger = {
			event_target:siege_owner = {
				war_with = ROOT
				any_courtier = {
					prisoner = yes
					host = { character = event_target:siege_owner }
					OR = {
						is_close_relative = ROOT
						dynasty = ROOT
					}
				}
				any_courtier = {
					prisoner = yes
					host = { character = event_target:siege_owner }
					NOR = {
						is_close_relative = ROOT
						dynasty = ROOT
					}
				}
			}
		}
		ai_chance = { 
			factor = 0.75
			modifier = {
				factor = 0.9
				trait = kind
			}
			modifier = {
				factor = 0.9
				trait = trusting
			}
			modifier = {
				factor = 0.75
				trait = just
			}
			modifier = {
				factor = 1.5
				trait = cruel
			}
			modifier = {
				factor = 1.5
				trait = wroth
			}
			modifier = {
				factor = 2
				trait = cynical
			}
			modifier = {
				factor = 2
				trait = paranoid
			}
		}
		random = {
			chance = 10
			if = {
				limit = {
					NOT = { trait = paranoid }
					NOT = { trait = trusting }
				}
				add_trait = paranoid
				character_event = { id = 38275 } # I am paranoid!
			}
			if = {
				limit = { trait = trusting }
				remove_trait = trusting
			}
		}
		event_target:siege_owner = {
			any_courtier = {
				limit = {
					prisoner = yes
					host = { character = event_target:siege_owner }
					OR = {
						is_close_relative = ROOT
						dynasty = ROOT
					}
				}
				prisoner = no
			}
		}
	}
	option = {
		name = EVTOPTE_Plus_1024 #Leave them	
		trigger = {
			event_target:siege_owner = {
				war_with = ROOT
				any_courtier = {
					prisoner = yes
					host = { character = event_target:siege_owner }
				}
			}
		}
		ai_chance = { 
			factor = 0.01 
			modifier = {
				factor = 0.1
				trait = kind
			}
			modifier = {
				factor = 0.1
				trait = just
			}
			modifier = {
				factor = 10
				trait = ambitious
			}
			modifier = {
				factor = 10
				trait = cruel
			}
			modifier = {
				factor = 10
				trait = wroth
			}
			modifier = {
				factor = 10
				trait = cynical
			}
			modifier = {
				factor = 10
				trait = paranoid
			} 
		}
		random = {
			chance = 20
			if = {
				limit = {
					NOT = { trait = cruel }
					NOT = { trait = kind }
				}
				add_trait = cruel
				character_event = { id = 38259 } # I am cruel!
			}
			if = {
				limit = { trait = kind }
				remove_trait = kind
			}
		}
		event_target:siege_owner = {
			any_courtier = {
				limit = {
					prisoner = yes
					host = { character = event_target:siege_owner }
				}
				opinion = {
					who = ROOT
					modifier = left_to_rot
					months = 60
				}
			}
		}
	}
}

# When liberating a friendly castle
character_event = {
	id = Plus.1025
	
	is_triggered_only = yes
	hide_window = yes
	
	trigger = {
		rebel = no
		is_looting = no
		NOR = {
			has_landed_title = e_rebels
			has_landed_title = e_mexikha
			any_liege = { has_landed_title = e_mexikha }
		}
		FROM = {
			holder_scope = {
				NOT = { war_with = ROOT }
				NOT = { character = ROOT }
			}
		}
	}
	
	immediate = {
		prestige = 10
		FROM = { 
			holder_scope = {
				if = {
					limit = { at_location = ROOT }
					opinion = {
						who = ROOT
						modifier = liberated
						months = 12
					}
					remove_character_modifier = stalwart_defender
					remove_character_modifier = left_at_siege
				}
				any_courtier = { 
					if = {
						limit = { 
							at_location = ROOT 
							NOT = { war_with = ROOT }
						}
						opinion = {
							who = ROOT
							modifier = liberated
							months = 12
						}
						remove_character_modifier = stalwart_defender
						remove_character_modifier = left_at_siege
					}
				}
			}
		}
	}
}

# Character notified that they were killed by siege
character_event = {
	id = Plus.1026
	desc = "EVTDESC_Plus_1026"
	picture = "GFX_evt_siege"
	border = "GFX_event_normal_frame_war"
	
	is_triggered_only = yes
	
	option = {
		name = "EVTOPTA_Plus_1026"
		death = { death_reason = death_battle killer = event_target:siege_attacker }
		hidden_tooltip = {
			event_target:siege_attacker = {
				ROOT = { save_event_target_as = kinslayer_target }
				add_kinslayer_trait_effect = yes
				if = {
					limit = { is_married = ROOT }
					ROOT = {
						any_dynasty_member = {
							limit = {
								is_alive = yes
								NOT = { character = event_target:siege_attacker }
								NOT = { has_opinion_modifier = { who = event_target:siege_attacker modifier = executed_kin } }
							}
							opinion = {
								who = event_target:siege_attacker
								modifier = executed_kin
								months = 1200
							}
						}
					}
				}
			}
			ROOT = {
				if = {
					limit = {
						NOT = { mother = { character = event_target:siege_attacker } }
					}
					mother = {
						opinion = {
							who = event_target:siege_attacker
							modifier = executed_kin
							months = 120
						}
					}
				}
				if = {
					limit = {
						NOT = { father = { character = event_target:siege_attacker } }
					}
					father = {
						opinion = {
							who = event_target:siege_attacker
							modifier = executed_kin
							months = 120
						}
					}
				}
				any_sibling = {
					limit = {
						NOT = { character = event_target:siege_attacker }
					}
					opinion = {
						who = event_target:siege_attacker
						modifier = executed_kin
						months = 120
					}
				}
				any_child = {
					limit = {
						NOT = { character = event_target:siege_attacker }
					}
					opinion = {
						who = event_target:siege_attacker
						modifier = executed_kin
						months = 120
					}
				}
			}
		}
	}
}

# Character notified that they were taken prisoner during siege
character_event = {
	id = Plus.1027
	desc = "EVTDESC_Plus_1027"
	picture = "GFX_evt_into_the_dungeon"
	border = "GFX_event_normal_frame_war"

	is_triggered_only = yes
	
	option = {
		name = "CURSES"
		log = "EVTDESC_Plus_1027"
		imprison = event_target:siege_attacker
	}
}

# Unit leader at the siege gets the main imprisonment event (if unreformed pagan)
character_event = {
	id = Plus.1030
	
	is_triggered_only = yes
	hide_window = yes
	
	trigger = {
		rebel = no
		NOR = {
			has_landed_title = e_rebels
			has_landed_title = e_mexikha
			any_liege = { has_landed_title = e_mexikha }
		}
		is_pagan_religion = yes
		is_reformed_pagan_religion = no
		FROM = {
			holder_scope = {
				NOT = { religion = ROOT }
				war_with = ROOT
				NOT = { character = ROOT }
				capital_holding = { title = PREVPREV }
			}
		}
	}
	
	immediate = {
		FROM = { save_event_target_as = siege_holding }
		FROM = { holder_scope = { save_event_target_as = siege_owner } }
		location = { save_event_target_as = siege_province }
		
		top_liege = {
			any_realm_character = {
				limit = {
					is_adult = yes
					at_location = ROOT
					prisoner = no
				}
				set_character_flag = wants_to_loot
			}
		}
		
		if = {
			limit = {
				is_ruler = no
				liege = { war_with = event_target:siege_owner }
			}
			liege = {
				character_event = { id = Plus.1031 } # Base post-looting event
			}
			event_target:siege_owner = {
				if = {
					limit = {
						any_courtier = {
							prisoner = yes
							host = { character = event_target:siege_owner }
						}
					}
					ROOT = {
						liege = {
							character_event = { id = Plus.1024 } # prisoners present
						}
					}
				}
			}
		}
		if = {
			limit = {
				is_ruler = yes
			}
			character_event = { id = Plus.1031 } # Base post-looting event
			event_target:siege_owner = {
				if = {
					limit = {
						any_courtier = {
							prisoner = yes
							host = { character = event_target:siege_owner }
						}
					}
					ROOT = {
						character_event = { id = Plus.1024 } # prisoners present
					}
				}
			}
		}
	}
}

# Post-looting event for unreformed pagans
character_event = {
	id = Plus.1031
	desc = EVTDESC_Plus_1031
	picture = GFX_evt_siege
	border = GFX_event_normal_frame_war

	is_triggered_only = yes
	hide_from = yes
	
	immediate = {
		save_event_target_as = siege_attacker
	}
	
	option = {
		name = EVTOPTA_Plus_1031 #I want prisoners
		trigger = {
			event_target:siege_owner = {
				OR = {
					at_location = FROM
					any_courtier = {
						at_location = FROM
						prisoner = no
						OR = {
							is_ruler = yes
							is_consort = yes
							any_close_relative = { is_ruler = yes }
							wealth = 25
							AND = {
								is_female = yes
								is_adult = yes
								NOR = {
									age = 28
									dynasty = none
									trait = ugly
								}
							}
						}
					}
				}
			}
		}
		ai_chance = {
			factor = 40
			modifier = {
				factor = 2
				trait = greedy
			}
			modifier = {
				factor = 1.5
				trait = envious
			}
			modifier = {
				factor = 0.5
				NOT = { prestige = 250 }
			}
		}
		prestige = -25
		custom_tooltip = {
			text = MEN_ARE_ANGERED
			hidden_tooltip = {
				top_liege = {
					any_realm_character = {
						limit = { has_character_flag = wants_to_loot }
						opinion = {
							who = ROOT
							modifier = not_allowed_to_loot
							months = 24
						}
					}
				}
			}
		}
		any_character = {
			limit = {
				at_location = FROM
				character = event_target:siege_owner
			}
			siege_capture_check_effect = yes
			any_courtier = {
				limit = {
					NOT = { character = event_target:siege_owner }
					host = { character = event_target:siege_owner }
					at_location = FROM
					prisoner = no
					OR = {
						is_ruler = yes
						is_consort = yes
						any_close_relative = { is_ruler = yes }
						wealth = 25
						AND = {
							is_female = yes
							is_adult = yes
							NOR = {
								age = 28
								dynasty = none
								trait = ugly
							}
						}
					}
				}
				set_character_flag = siege_capture_@event_target:siege_owner
				show_portrait = yes
				tooltip = { siege_capture_check_effect = yes }
			}
			hidden_tooltip = {
				random_courtier = {
					limit = { has_character_flag = siege_capture_@event_target:siege_owner }
					character_event = { id = Plus.1034 }
				}
			}
		}
		hidden_tooltip = {
			top_liege = {
				any_realm_character = {
					limit = { has_character_flag = wants_to_loot }
					clr_character_flag = wants_to_loot
				}
			}
		}
	}
	option = {
		name = EVTOPTB_Plus_1031 #Let them celebrate
		ai_chance = {
			factor = 40
			modifier = {
				factor = 1.5
				trait = lustful
			}
			modifier = {
				factor = 2
				trait = diligent
			}
			modifier = {
				factor = 1.5
				trait = kind
			}
		}
		any_character = {
			limit = {
				at_location = FROM
				character = event_target:siege_owner
			}
			siege_pagan_capture_check_effect = yes
			any_courtier = {
				limit = {
					NOT = { character = event_target:siege_owner }
					host = { character = event_target:siege_owner }
					at_location = FROM
					prisoner = no
					OR = {
						is_ruler = yes
						is_consort = yes
						any_close_relative = { is_ruler = yes }
						wealth = 25
						AND = {
							is_female = yes
							is_adult = yes
							NOR = {
								age = 28
								dynasty = none
								trait = ugly
							}
						}
					}
				}
				set_character_flag = siege_pagan_capture_@event_target:siege_owner
				show_portrait = yes
				tooltip = { siege_pagan_capture_check_effect = yes }
			}
			hidden_tooltip = {
				random_courtier = {
					limit = { has_character_flag = siege_pagan_capture_@event_target:siege_owner }
					character_event = { id = Plus.1036 }
				}
			}
		}
		hidden_tooltip = {
			top_liege = {
				any_realm_character = {
					limit = { has_character_flag = wants_to_loot }
					clr_character_flag = wants_to_loot
				}
			}
		}
	}
	option = {
		name = EVTOPTC_Plus_1031 #Tonight we offer sacrifices!
		trigger = {
			event_target:siege_owner = {
				OR = {
					at_location = FROM
					any_courtier = {
						at_location = FROM
						prisoner = no
						OR = {
							is_ruler = yes
							is_consort = yes
							any_close_relative = { is_ruler = yes }
							wealth = 25
							AND = {
								is_female = yes
								is_adult = yes
								NOR = {
									age = 28
									dynasty = none
									trait = ugly
								}
							}
						}
					}
				}
			}
		}
		ai_chance = {
			factor = 20
			modifier = {
				factor = 4
				trait = zealous
			}
			modifier = {
				factor = 0.5
				trait = cynical
			}
		}
		piety = 25
		custom_tooltip = {
			text = MEN_ARE_PLEASED
			hidden_tooltip = {	
				top_liege = {
					any_realm_character = {
						limit = { has_character_flag = wants_to_loot }
						opinion = {
							who = ROOT
							modifier = loot_sacrifice
							months = 24
						}
					}
				}
			}
		}
		custom_tooltip = {
			text = ENEMY_REALM_HORRIFIED
			hidden_tooltip = {
				event_target:siege_owner = {
					top_liege = {
						opinion = {
							who = ROOT
							modifier = opinion_barbarian
							months = 60
						}
						any_realm_character = {
							limit = {
								NOT = { religion_group = ROOT }
								NOT = { character = PREV }
							}
							opinion = {
								who = ROOT
								modifier = opinion_barbarian
								months = 60
							}
						}
					}
				}
			}
		}
		any_character = {
			limit = {
				at_location = FROM
				character = event_target:siege_owner
			}
			siege_pagan_sacrifice_check_effect = yes
			any_courtier = {
				limit = {
					NOT = { character = event_target:siege_owner }
					host = { character = event_target:siege_owner }
					at_location = FROM
					prisoner = no
					OR = {
						is_ruler = yes
						is_consort = yes
						any_close_relative = { is_ruler = yes }
						wealth = 25
						AND = {
							is_female = yes
							is_adult = yes
							NOR = {
								age = 28
								dynasty = none
								trait = ugly
							}
						}
					}
				}
				set_character_flag = siege_pagan_sacrifice_@event_target:siege_owner
				show_portrait = yes
				tooltip = { siege_pagan_sacrifice_check_effect = yes }
			}
			hidden_tooltip = {
				random_courtier = {
					limit = { has_character_flag = siege_pagan_capture_@event_target:siege_owner }
					character_event = { id = Plus.1037 }
				}
			}
		}
		hidden_tooltip = {
			top_liege = {
				any_realm_character = {
					limit = { has_character_flag = wants_to_loot }
					clr_character_flag = wants_to_loot
				}
			}
		}
	}
}

# Character notified they were injured after a siege
character_event = {
	id = Plus.1032
	desc = "EVTDESC_Plus_1032"
	picture = "GFX_evt_bloody_man"
	border = "GFX_event_normal_frame_war"

	is_triggered_only = yes
	
	option = {
		name = "EVTOPTA_Plus_1032"
		random_list = {
			50 = {
				add_trait = wounded
			}
			30 = {
				health = -0.5
				if = {
					limit = { is_female = yes }
					random = {
						chance = 50
						add_trait = scarred_female
					}
				}
				if = {
					limit = { is_female = no }
					random = {
						chance = 50
						add_trait = scarred
					}
				}
				if = {
					limit = {
						is_female = yes
						is_adult = yes
						NOT = { age = 60 }
						NOT = { trait = syphilitic }
					}
					random = {
						chance = 30
						add_trait = syphilitic
					}
				}
				if = {
					limit = {
						is_female = yes
						is_adult = yes
						NOT = { age = 45 }
						fertility = 0.33
					}
					random = {
						chance = 30
						impregnate = 0
					}
				}
			}
			20 = {
				add_maimed_trait_effect = yes
			}
		}
	}
}

# Character notified that they were sacrificed at the siege
character_event = {
	id = Plus.1033
	desc = "EVTDESC_Plus_1033"
	picture = "GFX_evt_viking_battle_oldgods"
	border = "GFX_event_normal_frame_war"
	
	is_triggered_only = yes
	
	option = {
		name = "EVTOPTA_Plus_1026"
		death = {
			death_reason = death_sacrificed
			killer = event_target:siege_attacker
		}
		hidden_tooltip = {
			ROOT = {
				if = {
					limit = {
						NOT = { mother = { character = event_target:siege_attacker } }
					}
					mother = {
						opinion = {
							who = event_target:siege_attacker
							modifier = executed_kin
							months = 120
						}
					}
				}
				if = {
					limit = {
						NOT = { father = { character = event_target:siege_attacker } }
					}
					father = {
						opinion = {
							who = event_target:siege_attacker
							modifier = executed_kin
							months = 120
						}
					}
				}
				any_sibling = {
					limit = {
						NOT = { character = event_target:siege_attacker }
					}
					opinion = {
						who = event_target:siege_attacker
						modifier = executed_kin
						months = 120
					}
				}
				any_child = {
					limit = {
						NOT = { character = event_target:siege_attacker }
					}
					opinion = {
						who = event_target:siege_attacker
						modifier = executed_kin
						months = 120
					}
				}
			}
		}
	}
}

# Recursive checks (to ensure randomized results)
character_event = {
	id = Plus.1034
	
	hide_window = yes
	is_triggered_only = yes
	
	immediate = {
		clr_character_flag = siege_capture_@event_target:siege_owner
		siege_capture_check_effect = yes
		location = {
			random_province_character = {
				limit = { has_character_flag = siege_capture_@event_target:siege_owner }
				character_event = { id = Plus.1034 }
			}
		}
	}
}

character_event = {
	id = Plus.1035
	
	hide_window = yes
	is_triggered_only = yes
	
	immediate = {
		clr_character_flag = siege_kill_@event_target:siege_owner
		siege_kill_check_effect = yes
		location = {
			random_province_character = {
				limit = { has_character_flag = siege_kill_@event_target:siege_owner }
				character_event = { id = Plus.1035 }
			}
		}
	}
}

character_event = {
	id = Plus.1036
	
	hide_window = yes
	is_triggered_only = yes
	
	immediate = {
		clr_character_flag = siege_pagan_capture_@event_target:siege_owner
		siege_pagan_capture_check_effect = yes
		location = {
			random_province_character = {
				limit = { has_character_flag = siege_pagan_capture_@event_target:siege_owner }
				character_event = { id = Plus.1036 }
			}
		}
	}
}

character_event = {
	id = Plus.1037
	
	hide_window = yes
	is_triggered_only = yes
	
	immediate = {
		clr_character_flag = siege_pagan_sacrifice_@event_target:siege_owner
		siege_pagan_sacrifice_check_effect = yes
		location = {
			random_province_character = {
				limit = { has_character_flag = siege_pagan_sacrifice_@event_target:siege_owner }
				character_event = { id = Plus.1037 }
			}
		}
	}
}

