	###########################################
#                                         #
# ZE Alliance Events                      #
# ID ZE.8000-ZE.8099                      #
#                                         #
###########################################

# Written by Markus Olsén

namespace = ZE

# A friendly visit from spouse can result in non-aggression pact
character_event = {
	id = ZE.8000
	picture = GFX_evt_feast
	border = GFX_event_normal_frame_diplomacy
	desc = EVTDESC_ZE_8000

	is_triggered_only = yes # on_yearly_pulse, random_events

	only_independent = yes
	only_capable = yes
	prisoner = no
	war = no

	trigger = {
		mercenary = no
		controls_religion = no
		holy_order = no
		is_inaccessible_trigger = no

		primary_title = {
			is_landless_type_title = no
		}

		any_independent_ruler = {
			is_married = yes
			is_landed = yes
			is_within_diplo_range = ROOT

			trigger_if = {
				limit = { NOT = { religion = ROOT } }

				religion_group = ROOT

				NOR = {
					religion_group = pagan_group
					religion_group = muslim
					is_heresy_of = ROOT
					is_parent_religion = ROOT
				}
			}

			any_spouse = {
				is_inaccessible_or_incapable_trigger = no
				NOT = { is_rival = ROOT }

				trigger_if = {
					limit = { NOT = { religion = ROOT } }

					religion_group = ROOT

					NOR = {
						religion_group = pagan_group
						religion_group = muslim
						is_heresy_of = ROOT
						is_parent_religion = ROOT
					}
				}
			}

			NOR = {
				has_non_aggression_pact_with = ROOT
				reverse_has_truce = ROOT
				is_rival = ROOT
			}

			war = no
			is_inaccessible_or_incapable_trigger = no
			controls_religion = no
			holy_order = no
			mercenary = no

			opinion = {
				who = ROOT
				value >= -25
			}

			primary_title = {
				is_landless_type_title = no
			}

			any_realm_province = {
				has_province_flag = contingent_territory
				held_under_PREV = yes

				OR = {
					any_neighbor_province = {
						has_province_flag = contingent_territory
						owner = { same_realm = ROOT }
					}

					ROOT = {
						any_realm_province = {
							has_province_flag = contingent_territory
							held_under_PREV = yes

							distance = {
								where = PREVPREV
								value < 100
							}
						}
					}
				}
			}
		}
	}

	immediate = {
		capital_scope = {
			save_event_target_as = capital
		}

		random_independent_ruler = {
			limit = {
				is_married = yes
				is_landed = yes
				is_within_diplo_range = ROOT

				trigger_if = {
					limit = { NOT = { religion = ROOT } }

					religion_group = ROOT

					NOR = {
						religion_group = pagan_group
						religion_group = muslim
						is_heresy_of = ROOT
						is_parent_religion = ROOT
					}
				}

				any_spouse = {
					is_inaccessible_or_incapable_trigger = no
					NOT = { is_rival = ROOT }

					trigger_if = {
						limit = { NOT = { religion = ROOT } }

						religion_group = ROOT

						NOR = {
							religion_group = pagan_group
							religion_group = muslim
							is_heresy_of = ROOT
							is_parent_religion = ROOT
						}
					}
				}

				NOR = {
					has_non_aggression_pact_with = ROOT
					reverse_has_truce = ROOT
					is_rival = ROOT
				}

				war = no
				is_inaccessible_or_incapable_trigger = no
				controls_religion = no
				holy_order = no
				mercenary = no

				primary_title = {
					is_landless_type_title = no
				}

				opinion = {
					who = ROOT
					value >= -25
				}

				any_realm_province = {
					has_province_flag = contingent_territory
					held_under_PREV = yes

					OR = {
						any_neighbor_province = {
							has_province_flag = contingent_territory
							owner = { same_realm = ROOT }
						}

						ROOT = {
							any_realm_province = {
								has_province_flag = contingent_territory
								held_under_PREV = yes

								distance = {
									where = PREVPREV
									value < 100
								}
							}
						}
					}
				}
			}

			save_event_target_as = target_ruler

			random_spouse = {
				limit = {
					is_incapable = no
					is_inaccessible_trigger = no
					prisoner = no
					NOT = { is_rival = ROOT }

					trigger_if = {
						limit = { NOT = { religion = ROOT } }

						religion_group = ROOT

						NOR = {
							religion_group = pagan_group
							religion_group = muslim
							is_heresy_of = ROOT
							is_parent_religion = ROOT
						}
					}
				}

				save_event_target_as = target_spouse
			}
		}
	}

	option = {
		name = EVTOPTA_ZE_8000

		event_target:target_ruler = {
			show_scope_change = no

			letter_event = {
				id = ZE.8001
				days = 3
				tooltip = EVTOPTA_ZE_8000_TOOLTIP
			}
		}

		ai_chance = { factor = 90 }
	}

	option = {
		name = EVTOPTB_ZE_8000

		ai_chance = { factor = 10 }
	}
}

# Suggestion to form non-aggression pact
letter_event = {
	id = ZE.8001
	desc = EVTDESC_ZE_8001

	is_triggered_only = yes

	# Accept
	option = {
		name = EVTOPTA_ZE_8001

		custom_tooltip = {
			text = EVTOPTA_ZE_8001_TOOLTIP

			FROM = {
				letter_event = {
					id = ZE.8002
					days = 3
				}

				opinion = {
					name = in_non_aggression_pact
					years = 3
					who = ROOT
					origin_description = EVTTITLE_ZE_8001
				}
			}

			opinion = {
				name = in_non_aggression_pact
				years = 3
				who = FROM
				origin_description = EVTTITLE_ZE_8001
			}
		}

		ai_chance = { factor = 70 }
	}

	# Decline
	option = {
		name = EVTOPTB_ZE_8001

		custom_tooltip = {
			text = EVTOPTB_ZE_8001_TOOLTIP

			FROM = {
				letter_event = {
					id = ZE.8003
					days = 3
				}
			}
		}

		ai_chance = { factor = 30 }
	}
}

# Respone that accepted the offer
letter_event = {
	id = ZE.8002
	desc = EVTDESC_ZE_8002

	is_triggered_only = yes

	ai = no

	option = {
		name = EVTOPTA_ZE_8002

		custom_tooltip = { text = EVTOPTA_ZE_8002_TOOLTIP }
	}
}

# Respone that declined the offer
letter_event = {
	id = ZE.8003
	desc = EVTDESC_ZE_8003

	is_triggered_only = yes

	ai = no

	option = {
		name = EVTOPTA_ZE_8003
	}
}

# Imposter noble is behaving badly in other realm
character_event = {
	id = ZE.8010
	picture = GFX_evt_council
	border = GFX_event_normal_frame_diplomacy
	desc = EVTDESC_ZE_8010

	is_triggered_only = yes

	only_independent = yes
	only_capable = yes
	prisoner = no

	trigger = {
		mercenary = no
		is_tributary = no
		is_inaccessible_trigger = no

		OR = {
			any_non_aggression_pact_character = {
				independent = yes
				is_within_diplo_range = ROOT
				mercenary = no
				is_tributary = no
			}

			any_allied_character = {
				independent = yes
				is_within_diplo_range = ROOT
				mercenary = no
				is_tributary = no
			}
		}
	}

	immediate = {
		capital_scope = {
			save_event_target_as = capital
		}

		if = {
			limit = {
				any_allied_character = {
					independent = yes
					is_within_diplo_range = ROOT
					mercenary = no
					is_tributary = no
				}
			}

			random_allied_character = {
				limit = {
					independent = yes
					is_within_diplo_range = ROOT
					mercenary = no
					is_tributary = no
				}

				save_event_target_as = target_ruler

				capital_scope = {
					save_event_target_as = target_ruler_capital
				}
			}
		}
		else = {
			random_non_aggression_pact_character = {
				limit = {
					independent = yes
					is_within_diplo_range = ROOT
					mercenary = no
					is_tributary = no
				}

				save_event_target_as = target_ruler

				capital_scope = {
					save_event_target_as = target_ruler_capital
				}
			}
		}
	}

	# Write a formal complaint to ruler
	option = {
		name = EVTOPTA_ZE_8010

		prestige = 50

		event_target:target_ruler = {
			show_scope_change = no

			letter_event = {
				id = ZE.8011
				days = 3
				tooltip = EVTOPTA_ZE_8010_TOOLTIP
			}
		}

		ai_chance = { factor = 90 }
	}

	# Ignore your courtiers complaints
	option = {
		name = EVTOPTB_ZE_8010

		custom_tooltip = {
			text = EVTOPTB_ZE_8010_TOOLTIP

			any_courtier = {
				opinion = {
					name = opinion_disappointed
					who = ROOT
					years = 2
				}
			}
		}

		ai_chance = { factor = 10 }
	}

	# Take care of him
	option = {
		name = EVTOPTC_ZE_8010
		tooltip_info = intrigue

		trigger = { intrigue >= 15 }

		custom_tooltip = { text = EVTOPTC_ZE_8010_TOOLTIP }
	}
}

# Complaint sent to ruler where noble claim to be from
letter_event = {
	id = ZE.8011
	desc = EVTDESC_ZE_8011

	is_triggered_only = yes

	# Explain he's not from our capital
	option = {
		name = EVTOPTA_ZE_8011
		tooltip_info = diplomacy

		trigger = { diplomacy >= 15 }

		FROM = {
			show_scope_change = no

			letter_event = {
				id = ZE.8012
				days = 3
				tooltip = EVTOPTA_ZE_8011_TOOLTIP
			}
		}

		ai_chance = { factor = 70 }
	}

	# Take blame
	option = {
		name = EVTOPTB_ZE_8011

		prestige = -100

		FROM = {
			show_scope_change = no

			letter_event = {
				id = ZE.8016
				days = 3
				tooltip = EVTOPTB_ZE_8011_TOOLTIP
			}
		}

		ai_chance = { factor = 20 }
	}

	# Answer rudely
	option = {
		name = EVTOPTC_ZE_8011

		prestige = 100

		FROM = {
			show_scope_change = no

			letter_event = {
				id = ZE.8013
				days = 3
				tooltip = EVTOPTC_ZE_8011_TOOLTIP
			}
		}

		ai_chance = { factor = 10 }
	}
}

# Explanation and word of warning about imposter
letter_event = {
	id = ZE.8012
	desc = EVTDESC_ZE_8012

	is_triggered_only = yes

	# Deal with impostor and apologize
	option = {
		name = EVTOPTA_ZE_8012

		prestige = -100

		FROM = {
			show_scope_change = no

			letter_event = {
				id = ZE.8014
				days = 3
				tooltip = EVTOPTA_ZE_8012_TOOLTIP
			}
		}

		ai_chance = { factor = 60 }
	}

	# Persist in accusation, break pact
	option = {
		name = EVTOPTB_ZE_8012

		custom_tooltip = {
			text = EVTOPTA_ZE_8013_TOOLTIP

			if = {
				limit = { is_allied_with = FROM }
				break_alliance = FROM
			}

			remove_opinion = {
				name = in_non_aggression_pact
				who = FROM
			}

			FROM = {
				letter_event = {
					id = ZE.8015
					days = 3
				}
			}

			opinion = {
				name = broken_non_aggression_pact
				who = FROM
				years = 3
			}
		}

		ai_chance = { factor = 10 }
	}

	# Leave it
	option = {
		name = EVTOPTC_ZE_8012

		reverse_opinion = {
			name = insulted
			who = FROM
			years = 3
		}

		ai_chance = { factor = 30 }
	}
}

# Rude answer to the initiator ridiculing them
letter_event = {
	id = ZE.8013
	desc = EVTDESC_ZE_8013

	is_triggered_only = yes

	option = {
		name = EVTOPTA_ZE_8013

		custom_tooltip = {
			text = EVTOPTA_ZE_8013_TOOLTIP

			if = {
				limit = { is_allied_with = FROM }
				break_alliance = FROM
			}

			remove_opinion = {
				name = in_non_aggression_pact
				who = FROM
			}

			opinion = {
				name = broken_non_aggression_pact
				who = FROM
				years = 3
			}
		}

		ai_chance = { factor = 60 }
	}

	# Let it slide
	option = {
		name = EVTOPTB_ZE_8013

		prestige = -200

		ai_chance = { factor = 40 }
	}
}

# Apology sent by initiator
letter_event = {
	id = ZE.8014
	desc = EVTDESC_ZE_8014

	is_triggered_only = yes

	# OK
	option = {
		name = EVTOPTA_ZE_8014

		prestige = 150

		opinion = {
			name = opinion_improved_relations
			who = FROM
			years = 2
		}
	}
}

# Rude answer by initiator
letter_event = {
	id = ZE.8015
	desc = EVTDESC_ZE_8015

	is_triggered_only = yes

	# End non aggression/alliance

	option = {
		name = EVTOPTA_ZE_8015

		custom_tooltip = {
			text = EVTOPTA_ZE_8013_TOOLTIP

			if = {
				limit = { is_allied_with = FROM }
				break_alliance = FROM
			}

			remove_opinion = {
				name = in_non_aggression_pact
				who = FROM
			}

			opinion = {
				name = broken_non_aggression_pact
				who = FROM
				years = 3
			}
		}
	}
}

# Taking the blame
letter_event = {
	id = ZE.8016
	desc = EVTDESC_ZE_8016

	is_triggered_only = yes

	# Liege is pleased
	option = {
		name = EVTOPTA_ZE_8016

		opinion = {
			name = opinion_improved_relations
			who = FROM
			years = 2
		}
	}
}