###########################################
#                                         #
# Special Chronicle Events                #
#                                         #
# ID CM.10000-CM.11999                    #
#                                         #
###########################################

namespace = CM

# When chronicle is begun (On Action on_chronicle_start)
character_event = {
	id = CM.10000

	is_triggered_only = yes # on_chronicle_start
	hide_window = yes

	immediate = {
		chronicle = {
			entry = CHRONICLE_START
			picture = GFX_evt_monk
		}
	}
}

# When chronicle is transferred to new character (On Action on_chronicle_owner_change)
character_event = {
	id = CM.10001

	is_triggered_only = yes # on_chronicle_owner_change
	hide_window = yes

	immediate = {
		if = {
			limit = {
				FROM = {
					is_dying = yes
				}
			}

			if = {
				limit = { culture = FROM }

				if = {
					limit = { religion = FROM }

					chronicle = {
						entry = CHRONICLE_PLAYER_INHERITANCE_NORMAL
						portrait = [Root.GetID]
						picture = GFX_evt_coronation
					}
				}
				else = {
					chronicle = {
						entry = CHRONICLE_PLAYER_INHERITANCE_NEW_RELIGION
						portrait = [Root.GetID]
						picture = GFX_evt_coronation
					}
				}
			}
			else = {
				if = {
					limit = { religion = FROM }

					chronicle = {
						entry = CHRONICLE_PLAYER_INHERITANCE_NEW_CULTURE
						portrait = [Root.GetID]
						picture = GFX_evt_coronation
					}
				}
				else = {
					chronicle = {
						entry = CHRONICLE_PLAYER_INHERITANCE_NEW_CULTURE_AND_RELIGION
						portrait = [Root.GetID]
						picture = GFX_evt_coronation
					}
				}
			}
		}

		else = {
			if = {
				limit = { has_character_flag = beneficiary_check_potential_player_character }

				chronicle = {
					entry = CHRONICLE_BECAME_LORD_OF_CRUSADER_KINGDOM
					portrait = [Root.GetID]
					picture = GFX_evt_western_knights_byzantine
				}
			}
			else_if = {
				limit = {
					OR = {
						trait = crusader_king
						trait = crusader_queen
					}
				}

				chronicle = {
					entry = CHRONICLE_BECAME_RULER_OF_CRUSADER_KINGDOM
					portrait = [Root.GetID]
					picture = GFX_evt_western_knights_byzantine
				}
			}
			else = {
				chronicle = {
					entry = CHRONICLE_PLAYER_INHERITANCE_LANDLESS
					portrait = [Root.GetID]
					picture = GFX_evt_emissary
				}
			}
		}
	}
}

#############################
# Various chronicle events  #
#############################

# From on action on_death - check who died and create appropriate chronicle entries
character_event = {
	id = CM.10010

	is_triggered_only = yes # on_death
	hide_window = yes

	trigger = {
		any_player = {
			OR = {
				vassal_of = ROOT
				is_married = ROOT
				is_child_of = ROOT
				rightful_religious_head = ROOT

				player_heir = {
					character = ROOT
				}
			}
		}
	}

	immediate = {
		any_player = {
			limit = {
				# Not used for primary heir which is handled in chronicle owner transfer event CM.10001
				current_heir = {
					NOT = { character = ROOT }
				}
			}

			if = {
				limit = { is_married = ROOT }

				chronicle = {
					entry = CHRONICLE_DEATH_OF_SPOUSE
					portrait = [Root.GetID]
				}
			}
			else_if = {
				limit = { is_child_of = ROOT }

				chronicle = {
					entry = CHRONICLE_DEATH_OF_PARENT
					portrait = [Root.GetID]
				}
			}
			else_if = {
				limit = {
					player_heir = {
						character = ROOT
					}
				}

				chronicle = {
					entry = CHRONICLE_DEATH_OF_HEIR
					portrait = [Root.GetID]
				}
			}
			else_if = {
				limit = { vassal_of = ROOT }

				chronicle = {
					entry = CHRONICLE_DEATH_OF_LIEGE
					portrait = [Root.GetID]
				}
			}
			else_if = {
				limit = { rightful_religious_head = ROOT }

				chronicle = {
					entry = CHRONICLE_DEATH_OF_RELIGION_HEAD
					portrait = [Root.GetID]
				}
			}
		}
	}
}

# From on action on_birth - check who was born and create appropriate chronicle entries
character_event = {
	id = CM.10011

	is_triggered_only = yes # on_birth
	hide_window = yes

	trigger = {
		OR = {
			father = { ai = no }
			mother = { ai = no }
		}
	}

	immediate = {
		character_event = {
			id = CM.19011 # Delay to allow for naming of child.
			days = 2
		}
	}
}

character_event = {
	id = CM.19011

	is_triggered_only = yes
	hide_window = yes

	trigger = {
		OR = {
			father = { ai = no }
			mother = { ai = no }
		}
	}

	immediate = {
		father = {
			if = {
				limit = {
					ai = no

					trigger_if = {
						limit = { num_of_children > 1 }

						NOT = {
							any_child = {
								NOT = { character = FROM }
								same_sex = FROM
							}
						}
					}
				}

				chronicle = {
					entry = CHRONICLE_BIRTH_FATHER
					portrait = [Root.GetID]
				}
			}
		}

		mother = {
			if = {
				limit = {
					ai = no

					trigger_if = {
						limit = { num_of_children > 1 }

						NOT = {
							any_child = {
								NOT = { character = FROM }
								same_sex = FROM
							}
						}
					}
				}

				chronicle = {
					entry = CHRONICLE_BIRTH_MOTHER
					portrait = [Root.GetID]
				}
			}
		}
	}
}

# War
character_event = {
	id = CM.10012

	is_triggered_only = yes # on_war_started
	hide_window = yes

	trigger = {
		OR = {
			ai = no
			FROM = { ai = no }
		}
	}

	immediate = {
		FROM = {
			if = {
				limit = { ai = no }

				chronicle = {
					entry = CHRONICLE_WAR_DECLARED_ATTACKER
					portrait = [Prev.GetID]
				}
			}
		}

		if = {
			limit = { ai = no }

			chronicle = {
				entry = CHRONICLE_WAR_DECLARED_DEFENDER
				portrait = [From.GetID]
			}
		}
	}
}

# Joined ally in war
character_event = {
	id = CM.10013

	is_triggered_only = yes # ASK_TO_JOIN_WAR_INTERACTION_ACCEPT_EVENT
	hide_window = yes

	ai = no

	immediate = {
		chronicle = {
			entry = CHRONICLE_JOINED_ALLY_IN_WAR
			portrait = [From.GetID]
		}
	}
}

# Answered call to arms
character_event = {
	id = CM.10014

	is_triggered_only = yes # CALL_ALLY_INTERACTION_ACCEPT_EVENT
	hide_window = yes

	trigger = {
		FROM = { ai = no }
	}

	immediate = {
		FROM = {
			chronicle = {
				entry = CHRONICLE_JOINED_ALLY_IN_WAR_2
				portrait = [Prev.GetID]
			}
		}
	}
}

# On crusade creation
# Called from 'on_crusade_creation'
# new_character is the targetted enemy
# ROOT is the religious head
# FROM is the attacked kingdom title
character_event = {
	id = CM.10015

	is_triggered_only = yes # on_crusade_creation
	hide_window = yes

	immediate = {
		ROOT = {
			if = {
				limit = { ai = no }

				chronicle = {
					entry = CHRONICLE_FRIENDLY_CRUSADE_STARTED
					portrait = [Root.GetID]
				}
			}
		}

		any_player = {
			if = {
				limit = { religion = ROOT }

				chronicle = {
					entry = CHRONICLE_FRIENDLY_CRUSADE_STARTED
					portrait = [Root.GetID]
				}
			}
			else_if = {
				limit = { religion = new_character }

				chronicle = {
					entry = CHRONICLE_UNFRIENDLY_CRUSADE_STARTED
					portrait = [Root.GetID]
				}
			}
		}
	}
}

# On crusade success
# ROOT is the target title
# new_character is the Enemy
# FROM is the taker
character_event = {
	id = CM.10016

	is_triggered_only = yes # on_crusade_success
	hide_window = yes

	immediate = {
		if = {
			limit = {
				FROM = {
					religion_head = { is_alive = yes }
				}
			}

			any_player = {
				limit = {
					OR = {
						religion = FROM
						religion = new_character
					}

					trigger_if = {
						limit = { character = FROM }
						FROM = { uses_new_crusade = yes }
					}
				}

				chronicle = {
					entry = CHRONICLE_CRUSADE_WON
					portrait = [From.RelHead.GetID]
				}
			}

			FROM = {
				if = {
					limit = {
						ai = no
						uses_new_crusade = no
					}

					chronicle = {
						entry = CHRONICLE_CRUSADE_WON_AND_I_GOT_THE_TITLE
						portrait = [From.GetID]
					}
				}
			}
		}

		# Crusade ended inconclusively as the religious head no longer exist
		else = {
			any_player = {
				limit = {
					OR = {
						religion = FROM
						religion = new_character
					}
				}

				chronicle = {
					entry = CHRONICLE_CRUSADE_LOST_NO_HEAD
				}
			}
		}
	}
}

# On crusade failure
# ROOT is the target title
# new_character is the Enemy
# FROM is the Pope/Caliph
character_event = {
	id = CM.10017

	is_triggered_only = yes # on_crusade_failure
	hide_window = yes

	immediate = {
		any_player = {
			limit = {
				OR = {
					religion = FROM
					religion = new_character
				}
			}

			chronicle = {
				entry = CHRONICLE_CRUSADE_LOST
				portrait = [New.GetID]
			}
		}
	}
}

# Aztec first contact
character_event = {
	id = CM.10018

	is_triggered_only = yes
	hide_window = yes

	immediate = {
		any_player = {
			limit = {
				capital_scope = {
					OR = {
						region = custom_north_sea_zone
						region = custom_atlantic_zone
					}
				}
			}

			character_event = { id = CM.10019 }
		}
	}
}

character_event = {
	id = CM.10019

	is_triggered_only = yes
	hide_window = yes

	immediate = {
		chronicle = {
			entry = CHRONICLE_AZTECS_FIRST_CONTACT
			portrait = [From.GetID]
		}
	}
}

# Aztec Invasion
character_event = {
	id = CM.10020

	is_triggered_only = yes
	hide_window = yes

	immediate = {
		chronicle = {
			entry = CHRONICLE_AZTEC_INVASION
			portrait = [From.GetID]
		}
	}
}

# Creates new higher level title
# On create title - ROOT is the creating character, FROM is the title
character_event = {
	id = CM.10021

	is_triggered_only = yes # on_create_title
	hide_window = yes

	ai = no

	trigger = {
		FROM = { is_primary_holder_title = yes }

		NOT = {
			any_demesne_title = {
				is_primary_holder_title_tier = yes
				NOT = { title = FROM }
			}
		}
	}

	immediate = {
		chronicle = {
			entry = CHRONICLE_CREATED_TITLE
			portrait = [Root.GetID]
		}
	}
}

# Usurps new higher level title
# On usurp title ROOT is the character, FROM is the title, FROMFROM is the old holder
character_event = {
	id = CM.10022

	is_triggered_only = yes
	hide_window = yes

	ai = no

	trigger = {
		FROM = { is_primary_holder_title = yes }

		NOT = {
			any_demesne_title = {
				is_primary_holder_title_tier = yes
				NOT = { title = FROM }
			}
		}
	}

	immediate = {
		chronicle = {
			entry = CHRONICLE_USURPED_TITLE
			portrait = [Root.GetID]
		}
	}
}

# Marriage
character_event = {
	id = CM.10023

	is_triggered_only = yes # on_marriage
	hide_window = yes

	trigger = {
		FROM = { ai = no }
	}

	immediate = {
		new_character = {
			mother_even_if_dead = { save_event_target_as = new_spouse_mother }
			father_even_if_dead = { save_event_target_as = new_spouse_father }
		}

		if = {
			limit = {
				event_target:new_spouse_mother = {
					trigger_if = {
						limit = {
							event_target:new_spouse_father = { always = yes }
						}

						higher_real_tier_than = event_target:new_spouse_father
					}
				}
			}

			FROM = {
				chronicle = {
					entry = CHRONICLE_MARRIED_MOTHER_IMPORTANT
					portrait = [New.GetID]
				}
			}
		}
		else_if = {
			limit = {
				event_target:new_spouse_father = {
					trigger_if = {
						limit = {
							event_target:new_spouse_mother = { always = yes }
						}

						NOT = { lower_real_tier_than = event_target:new_spouse_mother }
					}
				}
			}

			FROM = {
				chronicle = {
					entry = CHRONICLE_MARRIED_FATHER_IMPORTANT
					portrait = [New.GetID]
				}
			}
		}
		else = {
			FROM = {
				chronicle = {
					entry = CHRONICLE_MARRIED_NO_PARENT
					portrait = [New.GetID]
				}
			}
		}
	}
}


# From on action on_became_imprisoned - check who was imprisoned and create appropriate chronicle entries
character_event = {
	id = CM.10024

	hide_window = yes

	is_triggered_only = yes # on_became_imprisoned

	trigger = {
		any_player = {
			OR = {
				character = ROOT
				vassal_of = ROOT
				is_married = ROOT
				is_child_of = ROOT
				rightful_religious_head = ROOT

				player_heir = {
					character = ROOT
				}
			}
		}
	}

	immediate = {
		if = {
			limit = { ai = no }

			chronicle = {
				entry = CHRONICLE_PLAYER_IMPRISONED
				portrait = [Root.GetID]
			}
		}

		any_player = {
			if = {
				limit = { is_married = ROOT }

				chronicle = {
					entry = CHRONICLE_SPOUSE_IMPRISONED
					portrait = [Root.GetID]
				}
			}
			else_if = {
				limit = {
					current_heir = {
						character = ROOT
					}
				}

				chronicle = {
					entry = CHRONICLE_HEIR_IMPRISONED
					portrait = [Root.GetID]
				}
			}
			else_if = {
				limit = { is_child_of = ROOT }

				chronicle = {
					entry = CHRONICLE_PARENT_IMPRISONED
					portrait = [Root.GetID]
				}
			}
			else_if = {
				limit = { rightful_religious_head = ROOT }

				chronicle = {
					entry = CHRONICLE_RELIGION_HEAD_IMPRISONED
					portrait = [Root.GetID]
				}
			}
			else_if = {
				limit = { vassal_of = ROOT }

				chronicle = {
					entry = CHRONICLE_LIEGE_IMPRISONED
					portrait = [Root.GetID]
				}
			}
		}
	}
}

# From on action on_released_from_prison - check who was released and create appropriate chronicle entries
character_event = {
	id = CM.10025

	is_triggered_only = yes # on_released_from_prison
	hide_window = yes

	trigger = {
		any_player = {
			OR = {
				character = ROOT
				vassal_of = ROOT
				is_married = ROOT
				is_child_of = ROOT
				rightful_religious_head = ROOT

				player_heir = {
					character = ROOT
				}
			}
		}
	}

	immediate = {
		if = {
			limit = { ai = no }

			chronicle = {
				entry = CHRONICLE_PLAYER_RELEASED
				portrait = [Root.GetID]
			}
		}

		any_player = {
			if = {
				limit = { is_married = ROOT }

				chronicle = {
					entry = CHRONICLE_SPOUSE_RELEASED
					portrait = [Root.GetID]
				}
			}
			else_if = {
				limit = {
					current_heir = {
						character = ROOT
					}
				}

				chronicle = {
					entry = CHRONICLE_HEIR_RELEASED
					portrait = [Root.GetID]
				}
			}
			else_if = {
				limit = { is_child_of = ROOT }

				chronicle = {
					entry = CHRONICLE_PARENT_RELEASED
					portrait = [Root.GetID]
				}
			}
			else_if = {
				limit = { rightful_religious_head = ROOT }

				chronicle = {
					entry = CHRONICLE_RELIGION_HEAD_RELEASED
					portrait = [Root.GetID]
				}
			}
			else_if = {
				limit = { vassal_of = ROOT }

				chronicle = {
					entry = CHRONICLE_LIEGE_RELEASED
					portrait = [Root.GetID]
				}
			}
		}
	}
}

# When a character converts to a new religion - On action: on_character_convert_religion
character_event = {
	id = CM.10026

	is_triggered_only = yes # on_character_convert_culture
	hide_window = yes

	trigger = {
		OR = {
			ai = no

			any_player = {
				vassal_of = ROOT
				is_liege_of = ROOT
			}
		}
	}

	immediate = {
		if = {
			limit = { ai = no }

			chronicle = {
				entry = CHRONICLE_PLAYER_CONVERTED_RELIGION
				portrait = [Root.GetID]
			}
		}

		any_player = {
			if = {
				limit = { vassal_of = ROOT }

				chronicle = {
					entry = CHRONICLE_LIEGE_CONVERTED_RELIGION
					portrait = [Root.GetID]
				}
			}
			else_if = {
				limit = {
					is_liege_of = ROOT

					trigger_if = {
						limit = { real_tier = KING }
						ROOT = { real_tier = DUKE }
					}
					trigger_else = {
						real_tier = EMPEROR
						ROOT = { real_tier = KING }
					}
				}

				chronicle = {
					entry = CHRONICLE_MAJOR_VASSAL_CONVERTED_RELIGION
					portrait = [Root.GetID]
				}
			}
		}
	}
}

# When a character converts to a new culture - On action: on_character_convert_culture
character_event = {
	id = CM.10027

	is_triggered_only = yes # on_character_convert_culture
	hide_window = yes

	ai = no

	immediate = {
		chronicle = {
			entry = CHRONICLE_PLAYER_CONVERTED_CULTURE
			portrait = [Root.GetID]
		}
	}
}

# When a character acquires a nickname - On action: on_acquire_nickname
character_event = {
	id = CM.10028

	is_triggered_only = yes # on_acquire_nickname
	hide_window = yes

	ai = no

	immediate = {
		chronicle = {
			entry = CHRONICLE_PLAYER_ACQUIRED_NICKNAME
			portrait = [Root.GetID]
		}
	}
}

# Won battle - On action: on_battle_won
character_event = {
	id = CM.10029

	is_triggered_only = yes # on_major_battle_won
	hide_window = yes

	ai = no

	immediate = {
		chronicle = {
			entry = CHRONICLE_WON_BATTLE_FOUGHT
			portrait = [Root.GetID]
		}
	}
}

# Lost battle - On action: on_battle_lost
character_event = {
	id = CM.10030

	is_triggered_only = yes# on_major_battle_lost
	hide_window = yes

	ai = no

	immediate = {
		chronicle = {
			entry = CHRONICLE_LOST_BATTLE_FOUGHT
			portrait = [Root.GetID]
		}
	}
}

# Won battle but didn't participate myself
character_event = {
	id = CM.10031

	is_triggered_only = yes # on_major_battle_won_leader
	hide_window = yes

	trigger = {
		top_liege = {
			ai = no
			NOT = { at_location = ROOT }
			war_with = FROM
		}
	}

	immediate = {
		top_liege = {
			chronicle = {
				entry = CHRONICLE_WON_BATTLE_BUT_DIDNT_FIGHT
				portrait = [Root.GetID] # The commander
			}
		}
	}
}

# Lost battle but didn't participate myself
character_event = {
	id = CM.10032

	is_triggered_only = yes # on_major_battle_lost_leader
	hide_window = yes

	ai = yes

	trigger = {
		top_liege = {
			ai = no
			NOT = { at_location = ROOT }
			war_with = FROM
		}
	}

	immediate = {
		top_liege = {
			chronicle = {
				entry = CHRONICLE_LOST_BATTLE_BUT_DIDNT_FIGHT
				portrait = [Root.GetID] # The commander
			}
		}
	}
}

# Personally captured major settlement
character_event = {
	id = CM.10033

	is_triggered_only = yes # on_siege_won_leader
	hide_window = yes

	ai = no

	immediate = {
		chronicle = {
			entry = CHRONICLE_CAPTURED_MAJOR_SETTLEMENT_MYSELF
			picture = GFX_evt_victory_arch_byzantine
		}
	}
}

# My forces captured major settlement
character_event = {
	id = CM.10034

	is_triggered_only = yes # on_siege_won_leader
	hide_window = yes

	ai = yes

	trigger = {
		FROM = {
			OR = {
				title = b_roma
				title = b_constantinople
				title = b_bagdad
				title = b_indraprastha
				title = b_jerusalem
				title = b_mecca
				title = b_alexandria
				title = b_cordoba

				trigger_if = {
					limit = { title = b_venezia }
					year >= 900
				}
				trigger_else_if = {
					limit = { title = b_koln }
					year >= 1164
				}
				trigger_else_if = {
					limit = { title = b_paris }
					year >= 1200
				}
			}
		}

		top_liege = {
			ai = no
			NOT = { at_location = ROOT }
		}
	}

	immediate = {
		top_liege = {
			chronicle = {
				entry = CHRONICLE_MY_FORCES_CAPTURED_MAJOR_SETTLEMENT
				portrait = [Root.GetID] # The commander
			}
		}
	}
}

# Enemy forces captured major settlement
character_event = {
	id = CM.10035

	is_triggered_only = yes # on_siege_over_winner
	hide_window = yes

	ai = yes

	trigger = {
		FROM = {
			owner = {
				top_liege = {
					ai = no
				}
			}

			OR = {
				title = b_roma
				title = b_constantinople
				title = b_bagdad
				title = b_indraprastha
				title = b_jerusalem
				title = b_mecca
				title = b_alexandria
				title = b_cordoba

				trigger_if = {
					limit = { title = b_venezia }
					year >= 900
				}
				trigger_else_if = {
					limit = { title = b_koln }
					year >= 1164
				}
				trigger_else_if = {
					limit = { title = b_paris }
					year >= 1200
				}
			}

		}
	}

	immediate = {
		FROM = {
			owner = {
				top_liege = {
					chronicle = {
						entry = CHRONICLE_ENEMY_FORCES_CAPTURED_MAJOR_SETTLEMENT
						portrait = [Root.GetID] # The owner of the enemy forces
					}
				}
			}
		}
	}
}

# Marriage of player heir  - ROOT is employer. FROM is employers "employee". new_character is the other spouse.
character_event = {
	id = CM.10036

	is_triggered_only = yes # on_marriage
	hide_window = yes

	trigger = {
		any_player = {
			player_heir = {
				character = FROM
			}
		}
	}

	immediate = {
		new_character = {
			mother_even_if_dead = { save_event_target_as = new_spouse_mother }
			father_even_if_dead = { save_event_target_as = new_spouse_father }
		}

		if = {
			limit = {
				event_target:new_spouse_mother = {
					trigger_if = {
						limit = {
							event_target:new_spouse_father = { always = yes }
						}

						higher_real_tier_than = event_target:new_spouse_father
					}
				}
			}

			any_player = {
				limit = {
					player_heir = {
						character = FROM
					}
				}

				chronicle = {
					entry = CHRONICLE_MARRIED_MOTHER_IMPORTANT
					portrait = [New.GetID]
				}
			}
		}
		else_if = {
			limit = {
				event_target:new_spouse_father = {
					trigger_if = {
						limit = {
							event_target:new_spouse_mother = { always = yes }
						}

						NOT = { lower_real_tier_than = event_target:new_spouse_mother }
					}
				}
			}

			any_player = {
				limit = {
					player_heir = {
						character = FROM
					}
				}

				chronicle = {
					entry = CHRONICLE_MARRIED_FATHER_IMPORTANT
					portrait = [New.GetID]
				}
			}
		}
		else = {
			any_player = {
				limit = {
					player_heir = {
						character = FROM
					}
				}

				chronicle = {
					entry = CHRONICLE_MARRIED_NO_PARENT
					portrait = [New.GetID]
				}
			}
		}
	}
}

# Divorce
character_event = {
	id = CM.10037

	is_triggered_only = yes # on_divorce
	hide_window = yes

	trigger = {
		OR = {
			ai = no
			FROM = {ai = no }
		}
	}

	immediate = {
		# Chronicle entries with a religious head
		if = {
			limit = {
				new_character = {
					always = yes
				}
			}

			if = {
				limit = { ai = no }

				chronicle = {
					entry = CHRONICLE_DIVORCED
					portrait = [From.GetID]
				}
			}

			FROM = {
				if = {
					limit = { ai = no }

					chronicle = {
						entry = CHRONICLE_DIVORCED
						portrait = [From.GetID]
					}
				}
			}
		}
		# Chronicle entries without a religious head
		else = {
			if = {
				limit = { ai = no }

				chronicle = {
					entry = CHRONICLE_DIVORCED_NO_HEAD
					portrait = [From.GetID]
				}
			}

			FROM = {
				if = {
					limit = { ai = no }

					chronicle = {
						entry = CHRONICLE_DIVORCED_NO_HEAD
						portrait = [From.GetID]
					}
				}
			}
		}
	}
}

# Peace, attacker won
character_event = {
	id = CM.10038

	is_triggered_only = yes # on_war_ended_victory
	hide_window = yes

	trigger = {
		OR = {
			ai = no
			FROM = { ai = no }
		}
	}

	immediate = {
		FROM = {
			if = {
				limit = { ai = no }

				chronicle = {
					entry = CHRONICLE_WAR_WON
					portrait = [Prev.GetID]
				}
			}
		}

		if = {
			limit = { ai = no }

			chronicle = {
				entry = CHRONICLE_WAR_WON
				portrait = [From.GetID]
			}
		}
	}
}

# Inherit major title
# ROOT is the character
# FROM is the title
# FROMFROM is the old holder
character_event = {
	id = CM.10039

	is_triggered_only = yes # on_new_holder_inheritance
	hide_window = yes

	ai = no

	trigger = {
		NOT = { higher_real_tier_than = FROM }
	}

	immediate = {
		chronicle = {
			entry = CHRONICLE_INHERIT_MAJOR_TITLE
			picture = GFX_evt_throne_room
		}
	}
}

# Peace, whitepeace
character_event = {
	id = CM.10040

	is_triggered_only = yes # on_war_ended_whitepeace
	hide_window = yes

	trigger = {
		OR = {
			ai = no
			FROM = { ai = no }
		}
	}

	immediate = {
		FROM = {
			if = {
				limit = { ai = no }

				chronicle = {
					entry = CHRONICLE_WAR_WHITEPEACE
					portrait = [Prev.GetID]
				}
			}
		}

		if = {
			limit = { ai = no }

			chronicle = {
				entry = CHRONICLE_WAR_WHITEPEACE
				portrait = [From.GetID]
			}
		}
	}
}

# Peace, defender won
character_event = {
	id = CM.10041

	is_triggered_only = yes # on_war_ended_defeat
	hide_window = yes


	trigger = {
		OR = {
			ai = no
			FROM = { ai = no }
		}
	}

	immediate = {
		FROM = {
			if = {
				limit = { ai = no }

				chronicle = {
					entry = CHRONICLE_WAR_LOST
					portrait = [Prev.GetID]
				}
			}
		}

		if = {
			limit = { ai = no }

			chronicle = {
				entry = CHRONICLE_WAR_LOST
				portrait = [From.GetID]
			}
		}
	}
}

#############################################################################################
# Random content if chronicle is empty at year end (On Action on_create_chronicle_if_empty) #
#############################################################################################

# Dragon Sighted
character_event = {
	id = CM.10500

	is_triggered_only = yes # on_create_chronicle_if_empty, random_events
	hide_window = yes

	immediate = {
		random_realm_province = {
			limit = { held_under_PREV = yes }
			save_event_target_as = target_province
		}

		chronicle = {
			entry = CHRONICLE_FILL0001
			type = MONSTER_SIGHTED
		}
	}
}

# Giant sighted
character_event = {
	id = CM.10502

	is_triggered_only = yes # on_create_chronicle_if_empty, random_events
	hide_window = yes

	immediate = {
		random_realm_province = {
			limit = { held_under_PREV = yes }
			save_event_target_as = target_province
		}

		chronicle = {
			entry = CHRONICLE_FILL0002
			type = MONSTER_SIGHTED
		}
	}
}

# Sea serpents sighted
character_event = {
	id = CM.10504

	is_triggered_only = yes # on_create_chronicle_if_empty, random_events
	hide_window = yes

	immediate = {
		random_realm_province = {
			limit = { held_under_PREV = yes }
			save_event_target_as = target_province
		}

		chronicle = {
			entry = CHRONICLE_FILL0003
			type = MONSTER_SIGHTED
		}
	}
}

# Strange shapes seen dancing on the moon
character_event = {
	id = CM.10506

	is_triggered_only = yes # on_create_chronicle_if_empty, random_events
	hide_window = yes

	immediate = {
		chronicle = {
			entry = CHRONICLE_FILL0004
			type = MONSTER_SIGHTED
		}
	}
}

# Ten feet tall woman
character_event = {
	id = CM.10507

	is_triggered_only = yes # on_create_chronicle_if_empty, random_events
	hide_window = yes

	immediate = {
		random_realm_province = {
			limit = { held_under_PREV = yes }
			save_event_target_as = target_province
		}

		chronicle = {
			entry = CHRONICLE_FILL0005
			type = MONSTER_SIGHTED
		}
	}
}

# Raining blood
character_event = {
	id = CM.10509

	is_triggered_only = yes # on_create_chronicle_if_empty, random_events
	hide_window = yes

	immediate = {
		random_realm_province = {
			limit = { held_under_PREV = yes }
			save_event_target_as = target_province
		}

		chronicle = {
			entry = CHRONICLE_FILL0006
			type = FREAK_NATURAL_EVENT
		}
	}
}

# Strange plague kills rabbits
character_event = {
	id = CM.10511

	is_triggered_only = yes # on_create_chronicle_if_empty, random_events
	hide_window = yes

	immediate = {
		random_realm_province = {
			limit = { held_under_PREV = yes }
			save_event_target_as = target_province
		}

		chronicle = {
			entry = CHRONICLE_FILL0007
			type = FREAK_NATURAL_EVENT
		}
	}
}

# Earthquake
character_event = {
	id = CM.10513

	is_triggered_only = yes # on_create_chronicle_if_empty, random_events
	hide_window = yes

	immediate = {
		random_realm_province = {
			limit = { held_under_PREV = yes }
			save_event_target_as = target_province
		}

		chronicle = {
			entry = CHRONICLE_FILL0008
			type = NATURAL_DISASTER
		}
	}
}

# Flood
character_event = {
	id = CM.10515

	is_triggered_only = yes # on_create_chronicle_if_empty, random_events
	hide_window = yes

	immediate = {
		random_realm_province = {
			limit = { held_under_PREV = yes }
			save_event_target_as = target_province
		}

		chronicle = {
			entry = CHRONICLE_FILL0009
			type = NATURAL_DISASTER
		}
	}
}

# Two suns were seen
character_event = {
	id = CM.10517

	is_triggered_only = yes # on_create_chronicle_if_empty, random_events
	hide_window = yes

	immediate = {
		random_realm_province = {
			limit = { held_under_PREV = yes }
			save_event_target_as = target_province
		}

		chronicle = {
			entry = CHRONICLE_FILL0010
			type = FREAK_NATURAL_EVENT
		}
	}
}

# Goat with three heads was born
character_event = {
	id = CM.10519

	is_triggered_only = yes # on_create_chronicle_if_empty, random_events
	hide_window = yes

	immediate = {
		random_realm_province = {
			limit = { held_under_PREV = yes }
			save_event_target_as = target_province
		}

		chronicle = {
			entry = CHRONICLE_FILL0011
			type = MONSTER_SIGHTED
		}
	}
}

# Bird invasion
character_event = {
	id = CM.10521

	is_triggered_only = yes # on_create_chronicle_if_empty, random_events
	hide_window = yes

	immediate = {
		random_realm_province = {
			limit = { held_under_PREV = yes }
			save_event_target_as = target_province
		}

		chronicle = {
			entry = CHRONICLE_FILL0012
			type = FREAK_NATURAL_EVENT
		}
	}
}

# Many children born in province
character_event = {
	id = CM.10523

	is_triggered_only = yes # on_create_chronicle_if_empty, random_events
	hide_window = yes

	immediate = {
		random_realm_province = {
			limit = { held_under_PREV = yes }
			save_event_target_as = target_province
		}

		chronicle = {
			entry = CHRONICLE_FILL0013
			type = POPULATION_EVENT
		}
	}
}

# Province celebrates beloved ruler
character_event = {
	id = CM.10525

	is_triggered_only = yes # on_create_chronicle_if_empty, random_events
	hide_window = yes

	immediate = {
		random_realm_province = {
			limit = { held_under_PREV = yes }
			save_event_target_as = target_province
		}

		chronicle = {
			entry = CHRONICLE_FILL0014
			type = POPULATION_EVENT
		}
	}
}

# A star falls from the sky
character_event = {
	id = CM.10527

	is_triggered_only = yes # on_create_chronicle_if_empty, random_events
	hide_window = yes

	immediate = {
		random_realm_province = {
			limit = { held_under_PREV = yes }
			save_event_target_as = target_province
		}

		chronicle = {
			entry = CHRONICLE_FILL0015
			type = FREAK_NATURAL_EVENT
		}
	}
}

# Bountiful harvest
character_event = {
	id = CM.10529

	is_triggered_only = yes # on_create_chronicle_if_empty, random_events
	hide_window = yes

	immediate = {
		chronicle = {
			entry = CHRONICLE_FILL0016
			type = POPULATION_EVENT
		}
	}
}