on_startup = {
	country_event = { id = peace_treaties_expanded_events.1 }
}

on_monthly_pulse = {
	events = {
		pte_events.3 # remove cultural hegemony, if invalid
		pte_events.10 # reset cultural hegemony event targets, if needed
	}
}

on_dependency_gained = {
	FROM = {
		country_event = { id = pte_events.3 } # remove cultural hegemony, if invalid
	}
}

on_primary_culture_changed = {
	country_event = { id = pte_events.3 } # remove cultural hegemony, if invalid
}

on_new_monarch = {
	# For PTE:
	if = {
		limit = {
			is_lesser_in_union = no
			valid_for_personal_unions_trigger = yes
			any_known_country = {
				valid_for_personal_unions_trigger = yes
				NOT = { has_country_flag = valid_to_claim_succession_war_against_@ROOT }
				ROOT = {
					OR = {
						dynasty = PREV
						has_ruler_flag = was_heir_from_@PREV
					}
				}
			}
		}
		every_known_country = {
			limit = {
				valid_for_personal_unions_trigger = yes
				NOT = { has_country_flag = valid_to_claim_succession_war_against_@ROOT }
				ROOT = {
					OR = {
						AND = {
							dynasty = PREV
							has_regency = no
							PREV = {
								OR = {
									has_regency = no
									AND = {
										has_heir = yes
										heir_dynasty = ROOT
									}
								}
							}
						}
						has_ruler_flag = was_heir_from_@PREV
					}
				}
			}
			set_country_flag = valid_to_claim_succession_war_against_@ROOT
		}
	}
}

on_new_heir = {
	# For PTE:
	if = {
		limit = {
			is_lesser_in_union = no
			valid_for_personal_unions_trigger = yes
			OR = {
				AND = {
					has_dlc = "Rights of Man"
					has_consort = yes
					OR = {
						can_heir_be_child_of_consort = yes
						NOT = { heir_age = 1 }
					}
					any_known_country = {
						has_given_consort_to = ROOT
						NOT = { has_country_flag = valid_to_claim_succession_war_against_@ROOT }
						ROOT = {
							NOT = { has_heir_flag = was_heir_from_@PREV }
						}
					}
				}
				AND = {
					NOT = { has_dlc = "Rights of Man" }
					NOT = { heir_age = 1 }
					num_of_royal_marriages = 1
					any_known_country = {
						marriage_with = ROOT
						NOT = { has_country_flag = valid_to_claim_succession_war_against_@ROOT }
						ROOT = {
							NOT = { has_heir_flag = was_heir_from_@PREV }
							heir_culture = PREV
							heir_religion = PREV
						}
					}
				}
			}
		}
		every_known_country = {
			limit = {
				NOT = { has_country_flag = valid_to_claim_succession_war_against_@ROOT }
				ROOT = {
					NOT = { has_heir_flag = was_heir_from_@PREV }
				}
				OR = {
					AND = {
						has_dlc = "Rights of Man"
						has_given_consort_to = ROOT
					}
					AND = {
						NOT = { has_dlc = "Rights of Man" }
						marriage_with = ROOT
						ROOT = {
							heir_culture = PREV
							heir_religion = PREV
						}
					}
				}
			}
			ROOT = {
				set_heir_flag = was_heir_from_@PREV
			}
		}
	}
}

# THIS = Raiding country, FROM = Sea province
on_raid_coast = {
	# For PTE:
	FROM = {
		every_neighbor_province = {
			limit = {
				has_port = yes
				is_empty = no
				has_province_modifier = slaves_raided
				NOT = { owned_by = ROOT }
				owner = {
					is_free_or_tributary_trigger = yes
					has_opinion_modifier = {
						who = ROOT
						modifier = slaves_raided
					}
					NOT = {
						has_opinion_modifier = {
							who = ROOT
							modifier = slaves_raided
							value = -24
						}
					}
				}
			}
			owner = {
				if = {
					limit = {
						NOT = {
							has_casus_belli = {
								target = ROOT
								type = cb_pte_stop_raiding
							}
						}
					}
					add_casus_belli = {
						target = ROOT
						type = cb_pte_stop_raiding
					}
				}
			}
		}
	}
}