﻿has_no_war_preventing_relation = {
	NOR = {
		has_relation_friend = root
		is_allied_to = root
		root = { has_truce = prev }
		any_warden_hostage = { is_close_family_of = root }
		any_close_family_member = { is_hostage_of = root }
		AND = {
			exists = root.faith.religious_head
			this = root.faith.religious_head
		}
	}
}

valid_scandinavian_adventurer = {
	culture = {
		NOT = { has_cultural_era_or_later = culture_era_early_medieval }
		has_cultural_pillar = heritage_north_germanic
	}
	is_available_ai_adult = yes
	is_ruler = no
	is_healthy = yes
	has_any_debilitating_illness = no
	is_hostage = no
	has_dynasty = yes
	NOR = {
		has_character_flag = already_attempted_scandi_invasion
		has_character_modifier = histmod_save_for_planned_war
	}
	trigger_if = {
		limit = {
			NOT = { has_character_flag = prioritised_scandinavian_adventurer }
		}
		OR = {
			can_have_children = yes
			any_child = { is_alive = yes }
		}
		save_temporary_scope_as = potential
		can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = scope:potential }
		NOR = {
			any_heir_title = {}
			any_pretender_title = {
				place_in_line_of_succession = {
					target = scope:potential
					value <= 2
				}
			}
		}
	}
	trigger_if = {
		limit = { exists = scope:adventurer_target }
		NOR = {
			has_truce = scope:adventurer_target.holder
			has_truce = scope:adventurer_target.holder.top_liege
		}
	}
	trigger_if = {
		limit = { is_married = yes }
		trigger_if = {
			limit = { is_female = yes }
			matrilinear_marriage = yes
		}
		trigger_else = {
			patrilinear_marriage = yes
		}
	}
	trigger_else = {
		can_marry_common_trigger = yes
	}
	trigger_if = {
		limit = {
			NOT = { has_character_flag = prioritised_scandinavian_adventurer }
		}
		NOR = {
			has_trait = content
			has_trait = craven
			has_trait = humble
		}
	}
	trigger_if = {
		limit = {
			exists = liege
			NOR = {
				has_character_flag = prioritised_scandinavian_adventurer
				has_character_modifier = ep3_lust_for_land_modifier
			}
		}
		NOR = {
			is_consort_of = liege
			has_relation_lover = liege
			has_relation_friend = liege
			is_councillor = yes
			has_trait = loyal
		}
	}
	trigger_if = {
		limit = {
			exists = liege
			OR = {
				is_knight = yes
				has_any_court_position = yes
			}
			NOR = {
				has_character_flag = prioritised_scandinavian_adventurer
				has_character_modifier = ep3_lust_for_land_modifier
			}
		}
		OR = {
			opinion = { target = liege value < 20 }
			has_trait = disloyal
			has_trait = ambitious
		}
	}
	trigger_if = {
		limit = {
			exists = primary_spouse
			NOT = { has_character_flag = prioritised_scandinavian_adventurer }
		}
		primary_spouse = {
			is_ruler = no
			NOR = {
				any_heir_title = {}
				any_pretender_title = {
					place_in_line_of_succession = {
						target = prev
						value <= 2
					}
				}
			}
		}
	}
	trigger_if = {
		limit = {
			has_character_flag = is_rollo
			has_game_rule = rollo_always_invades
		}
		trigger_if = {
			limit = { has_game_rule = rollo_exists_vanilla }
			current_year >= 880
		}
		trigger_else = {
			current_year >= 900
		}
	}
}

is_good_alliance_marriage_candidate = {
	age >= 8
	age <= 25
	OR = {
		is_child_of = $PROPOSER$
		is_sibling_of = $PROPOSER$
		is_grandchild_of = $PROPOSER$
		is_great_grandchild_of = $PROPOSER$
		is_nibling_of = $PROPOSER$
	}
	is_married = no
	is_concubine = no
	is_hostage = no
	is_courtier = yes
	liege ?= {
		OR = {
			this = $PROPOSER$
			AND = {
				is_ai = yes
				top_liege ?= $PROPOSER$
			}
		}
	}
	matchmaker ?= {
		OR = {
			this = $PROPOSER$
			AND = {
				is_ai = yes
				top_liege ?= $PROPOSER$
			}
		}
	}
	could_marry_character_trigger = { CHARACTER = $RECIPIENT$ }
	trigger_if = {
		limit = { is_adult = no }
		NOT = { has_trait = infertile }
	}
	trigger_else = {
		can_have_children = yes
		fertility >= 0.20
	}
	NOR = {
		age >= $RECIPIENT$.age_plus_3
		is_incapable = yes
		has_variable = is_in_marriage_introduction
		has_been_promised_grand_wedding = yes
		is_close_or_extended_family_of = $RECIPIENT$
		has_trait = pregnant
		has_trait = eunuch
		has_trait = dwarf
		has_trait = hunchbacked 
		has_trait = inbred
		has_trait = albino
		has_trait = scaly
		has_trait = leper
		has_trait = beauty_bad
		has_relation_lover = $PROPOSER$
		any_heir_title = {}
		any_pretender_title = {
			place_in_line_of_succession = {
				target = prev
				value <= 2
			}
		}
	}
}

can_be_histmod_conqueror = {
	is_adult = yes
	age <= 50
	ai_boldness >= 0
	gold >= 50
	OR = {
		domain_size >= 3
		ai_boldness >= high_positive_ai_value
	}
	NOR = {
		is_incapable = yes
		ai_has_cautious_personality = yes
		has_character_flag = used_to_be_conqueror
		has_trait = conqueror
		has_character_modifier = ai_weak_conqueror_modifier
	}
}

is_bad_genetic_trait_trigger = {
	OR = {
		this = trait:depressed_genetic
		this = trait:lunatic_genetic
		this = trait:possessed_genetic
		this = trait:beauty_bad_1
		this = trait:beauty_bad_2
		this = trait:beauty_bad_3
		this = trait:intellect_bad_1
		this = trait:intellect_bad_2
		this = trait:intellect_bad_3
		this = trait:physique_bad_1
		this = trait:physique_bad_2
		this = trait:physique_bad_3
		this = trait:clubfooted
		this = trait:hunchbacked
		this = trait:dwarf
		this = trait:inbred
		this = trait:spindly
		this = trait:scaly
		this = trait:albino
		this = trait:wheezing
		this = trait:bleeder
		this = trait:infertile
	}
}

