﻿#################################################
# TRIGGER LIST 									#
#################################################

valid_confederation_member_trigger = {
	is_playable_character = yes
	is_tributary = no
	is_landed = yes
	is_independent_ruler = yes
	is_alive = yes
	NOR = {
		has_trait = conqueror
		has_trait = greatest_of_khans
		is_at_war_with = $CHARACTER$
		is_at_war_with = $CHARACTER$.top_liege
		custom_tooltip = {
			text = no_raiding_hostility_tt
			$CHARACTER$ = {
				is_causing_raid_hostility_towards = prev
			}
		}
	}
	highest_held_title_tier <= tier_duchy
	trigger_if = {
		limit = {
			government_has_flag = government_is_nomadic
		}
		custom_tooltip = {
			text = low_authority_tt
			OR = {
				has_realm_law = nomadic_authority_1
				has_realm_law = nomadic_authority_2
			}
		}
	}
	custom_tooltip = {
		OR = {
			government_has_flag = government_is_tribal
			government_has_flag = government_is_nomadic
		}
		text = is_nomadic_or_tribal_tt
	}
	is_confederation_member = no
}

confedration_foe_sub_trigger = {
	NOT = { is_allied_to = $CHARACTER$ }
	OR = {
		has_trait = conqueror
		has_trait = greatest_of_khans
		highest_held_title_tier >= tier_kingdom
		custom_tooltip = {
			text = call_for_confederation_decision_gurkhan
			is_gurkhan = yes
		}
		custom_tooltip = {
			text = considers_faith_evil_tt
			faith = {
				faith_hostility_level = {
					target = $CHARACTER$.faith
					value >= faith_evil_level
				}
			}
		}
	}
	trigger_if = {
		limit = {
			max_military_strength > 0
			$CHARACTER$.max_military_strength > 0
		}
		custom_tooltip = {
			text = superior_max_military_strength_tt
			confederation_worthy_foe_strength_ratio_value <= 0.5
		}
	}
}

confederation_foe_trigger = {
	save_temporary_scope_as = confederate

	#NEED TO UPDATE CUSTOM TOOLTIP WHENEVER THESE TRIGGERS ARE CHANGED
	custom_tooltip = {
		text = confederation_threat_tt
		#I'M FRICKING SERIOUS ABOUT THAT
		OR = {
			#Threat is in same de jure kingdom as capital county
			capital_county = {
				kingdom = {
					any_de_jure_county = {
						holder.top_liege = {
							confedration_foe_sub_trigger = { CHARACTER = $CHARACTER$ }
						}
					}
				}
			}
			#Threat borders you or your tributaries
			any_land_neighboring_realm_with_tributaries_owner = {
				confedration_foe_sub_trigger = { CHARACTER = $CHARACTER$ }
			}
			#You border threat's direct tributaries
			any_land_neighboring_realm_with_tributaries_owner = {
				exists = suzerain
				suzerain = {
					confedration_foe_sub_trigger = { CHARACTER = $CHARACTER$ }
				}
			}
			#You border threat's lower level tributaries
			any_land_neighboring_realm_with_tributaries_owner = {
				is_tributary = yes
				top_suzerain = {
					confedration_foe_sub_trigger = { CHARACTER = $CHARACTER$ }
				}
			}
		}
	}
}

confederation_neighboring_foe_trigger = {
	save_temporary_scope_as = confederate
	is_confederation_member = no
	OR = {
		#Threat borders you or your tributaries
		any_land_neighboring_realm_with_tributaries_owner = {
			confedration_foe_sub_trigger = { CHARACTER = $CHARACTER$ }
		}
		#You border threat's direct tributaries
		any_land_neighboring_realm_with_tributaries_owner = {
			exists = suzerain
			suzerain = {
				confedration_foe_sub_trigger = { CHARACTER = $CHARACTER$ }
			}
		}
		#You border threat's lower level tributaries
		any_land_neighboring_realm_with_tributaries_owner = {
			is_tributary = yes
			top_suzerain = {
				confedration_foe_sub_trigger = { CHARACTER = $CHARACTER$ }
			}
		}
	}
	
}

mpo_important_beheaded_warrior_trigger = {
	OR = {
		scope:beheaded_warrior = {
			is_consort_of = root
		}
		scope:beheaded_warrior = {
			is_close_family_of = root
		}
		has_variable = beheaded_warrior_powerful_vassal
		AND = {
			has_variable = beheaded_warrior_accolade
			var:beheaded_warrior_accolade = {
				accolade_rank >= 5
			}
		}
	}
}

mpo_keep_prisoners_heads_trigger = {
	OR = {
		faith.religion = faith:tengri_pagan.religion
		has_trait = greatest_of_khans
		has_trait = nomadic_philosophy
	}
}

mpo_valid_heir_friend_trigger = {
	age >= 12
	opinion = {
		target = $CHARACTER$
		value >= 50
	}
	NOR = {
		is_at_war_with = $CHARACTER$
		this = $CHARACTER$
		this = $CHARACTER$.player_heir
	}
	NOT = {
		has_relation_blood_brother = $CHARACTER$.player_heir
	}
	custom_description = {
		text = not_friends_with_player_heir_tt
		NOR = {
			has_relation_friend = $CHARACTER$.player_heir
			has_relation_best_friend = $CHARACTER$.player_heir
		}
	}
	custom_description = {
		text = not_bad_relation_with_player_heir_tt
		NOT = {
			has_any_bad_relationship_with_character_trigger = { CHARACTER = $CHARACTER$.player_heir }
		}
	}
	is_imprisoned = no
	is_incapable = no
	OR = {
		custom_description = {
			text = is_nomadic_tt
			government_has_flag = government_is_nomadic
		}
		has_trait = nomadic_philosophy
	}
	highest_held_title_tier >= tier_county
}

mpo_overrunner_becomes_tribal_trigger = {
	scope:target = {
		any_de_jure_county = {
			holder.top_liege = scope:defender
			add_to_temporary_list = target_counties
		}
	}
	OR = {
		#Defender is tribal and holds title
		AND = {
			scope:target = {
				holder ?= scope:defender
			}
			scope:defender = {
				government_has_flag = government_is_tribal
			}
		}
		#Defender is tribal and all counties they hold are tribal
		AND = {
			scope:defender = {
				government_has_flag = government_is_tribal
			}
			any_in_list = {
				list = target_counties
				count >= all
				any_county_province = {
					OR = {
						has_holding_type = tribal_holding
						has_holding_type = nomad_holding
						has_holding_type = herder_holding
					}
				}
			}
		}
		#New capital county will be tribal
		trigger_if = {
			limit = {
				scope:target = {
					title_capital_county = {
						holder.top_liege = scope:defender
					}
				}
			}
			scope:target = {
				title_capital_county = {
					holder.top_liege = scope:defender
					any_county_province = {
						is_county_capital = yes
						OR = {
							has_holding_type = tribal_holding
							has_holding_type = nomad_holding
							has_holding_type = herder_holding
						}
					}
				}
			}
		}
		#New potential duchy capitals are tribal
		trigger_else_if = {
			limit = {
				scope:target = {
					any_direct_de_jure_vassal_title = {
						tier = tier_duchy
						title_capital_county = {
							holder.top_liege = scope:defender
						}
					}
				}
			}
			scope:target = {
				any_direct_de_jure_vassal_title = {
					count = all
					tier = tier_duchy
					title_capital_county = {
						holder.top_liege = scope:defender
						any_county_province = {
							is_county_capital = yes
							has_holding = yes
							NOR = {
								has_holding_type = tribal_holding
								has_holding_type = nomad_holding
								has_holding_type = herder_holding
							}
						}
					}
				}
			}
		}
		#Every county is tribal
		trigger_else = {
			scope:target = {
				any_de_jure_county = {
					count >= all
					holder.top_liege = scope:defender
					any_county_province = {
						is_county_capital = yes
						NOR = {
							has_holding_type = tribal_holding
							has_holding_type = nomad_holding
							has_holding_type = herder_holding
						}
					}
				}
			}
		}
	}
}

mpo_overrunner_becomes_clan_trigger = {
	scope:attacker = {
		OR = {
			#Personal reasons to go clan
			faith.religion = religion:islam_religion
			culture = {
				OR = {
					has_cultural_pillar = heritage_arabic
					has_cultural_pillar = heritage_iranian
				}
			}
			#Person you're taking from has clan and presence in target region
			scope:defender = {
				government_has_flag = government_is_clan
				scope:target = {
					holder ?= scope:defender
				}
				scope:target = {
					title_capital_county = {
						holder.top_liege = scope:defender
						OR = {
							culture = { has_cultural_pillar = heritage_arabic }
							culture = { has_cultural_pillar = heritage_iranian }
							faith.religion = religion:islam_religion
						}
					}
				}
			}
			#Solid islamic presence in target region
			trigger_if = {
				limit = {
					scope:defender = {
						any_realm_de_jure_duchy = {
							kingdom = scope:target
							title_capital_county = {
								holder.top_liege = scope:defender
							}
						}
					}
				}
				scope:defender = {
					any_realm_de_jure_duchy = {
						count = all
						kingdom = scope:target
						title_capital_county = {
							holder.top_liege = scope:defender
							OR = {
								culture = { has_cultural_pillar = heritage_arabic }
								culture = { has_cultural_pillar = heritage_iranian }
								faith.religion = religion:islam_religion
							}
						}
						
					}
				}
			}
			#Every county is islamic
			trigger_else = {
				scope:target = {
					any_de_jure_county = {
						count = all
						holder.top_liege = scope:defender
						OR = {
							culture = { has_cultural_pillar = heritage_arabic }
							culture = { has_cultural_pillar = heritage_iranian }
							faith.religion = religion:islam_religion
						}
					}
				}
			}

		}
	}
}

mpo_overrunner_becomes_tribal_desc_trigger = {
	any_in_list = {
		list = target_titles
		tier = tier_kingdom
		any_de_jure_county = {
			holder.top_liege = scope:defender
			add_to_temporary_list = target_counties
		}
	}
	OR = {
		#Defender is tribal and holds title
		AND = {
			any_in_list = {
				list = target_titles
				tier = tier_kingdom
				holder ?= scope:defender
			}
			scope:defender = {
				government_has_flag = government_is_tribal
			}
		}
		#Defender is tribal and all counties they hold are tribal
		AND = {
			scope:defender = {
				government_has_flag = government_is_tribal
			}
			any_in_list = {
				list = target_counties
				count >= all
				any_county_province = {
					OR = {
						has_holding_type = tribal_holding
						has_holding_type = nomad_holding
						has_holding_type = herder_holding
					}
				}
			}
		}
		#New capital county will be tribal
		trigger_if = {
			limit = {
				any_in_list = {
					list = target_titles
					tier = tier_kingdom
					title_capital_county = {
						holder.top_liege = scope:defender
					}
				}
			}
			any_in_list = {
				list = target_titles
				tier = tier_kingdom
				title_capital_county = {
					holder.top_liege = scope:defender
					any_county_province = {
						is_county_capital = yes
						OR = {
							has_holding_type = tribal_holding
							has_holding_type = nomad_holding
							has_holding_type = herder_holding
						}
					}
				}
			}
		}
		#New potential duchy capitals are tribal
		trigger_else_if = {
			limit = {
				any_in_list = {
					list = target_titles
					tier = tier_kingdom
					any_direct_de_jure_vassal_title = {
						tier = tier_duchy
						title_capital_county = {
							holder.top_liege = scope:defender
						}
					}
				}
			}
			any_in_list = {
				list = target_titles
				tier = tier_kingdom
				any_direct_de_jure_vassal_title = {
					count = all
					tier = tier_duchy
					title_capital_county = {
						holder.top_liege = scope:defender
						any_county_province = {
							is_county_capital = yes
							has_holding = yes
							NOR = {
								has_holding_type = tribal_holding
								has_holding_type = nomad_holding
								has_holding_type = herder_holding
							}
						}
					}
				}
			}
		}
		#Every county is tribal
		trigger_else = {
			any_in_list = {
				list = target_titles
				tier = tier_kingdom
				any_de_jure_county = {
					count >= all
					holder.top_liege = scope:defender
					any_county_province = {
						is_county_capital = yes
						NOR = {
							has_holding_type = tribal_holding
							has_holding_type = nomad_holding
							has_holding_type = herder_holding
						}
					}
				}
			}
		}
	}
}

mpo_overrunner_becomes_clan_desc_trigger = {
	scope:attacker = {
		OR = {
			#Personal reasons to go clan
			faith.religion = religion:islam_religion
			culture = {
				OR = {
					has_cultural_pillar = heritage_arabic
					has_cultural_pillar = heritage_iranian
				}
			}
			#Person you're taking from has clan and presence in target region
			scope:defender = {
				government_has_flag = government_is_clan
				any_in_list = {
					list = target_titles
					tier = tier_kingdom
					holder ?= scope:defender
				}
				any_in_list = {
					list = target_titles
					tier = tier_kingdom
					title_capital_county = {
						holder.top_liege = scope:defender
						OR = {
							culture = { has_cultural_pillar = heritage_arabic }
							culture = { has_cultural_pillar = heritage_iranian }
							faith.religion = religion:islam_religion
						}
					}
				}
			}
			#Solid islamic presence in target region
			trigger_if = {
				limit = {
					scope:defender = {
						any_realm_de_jure_duchy = {
							kingdom = {
								is_in_list = target_titles
							}
							title_capital_county = {
								holder.top_liege = scope:defender
							}
						}
					}
				}
				scope:defender = {
					any_realm_de_jure_duchy = {
						count = all
						kingdom = {
							is_in_list = target_titles
						}
						title_capital_county = {
							holder.top_liege = scope:defender
							OR = {
								culture = { has_cultural_pillar = heritage_arabic }
								culture = { has_cultural_pillar = heritage_iranian }
								faith.religion = religion:islam_religion
							}
						}
						
					}
				}
			}
			#Every county is islamic
			trigger_else = {
				any_in_list = {
					list = target_titles
					tier = tier_kingdom
					any_de_jure_county = {
						count = all
						holder.top_liege = scope:defender
						OR = {
							culture = { has_cultural_pillar = heritage_arabic }
							culture = { has_cultural_pillar = heritage_iranian }
							faith.religion = religion:islam_religion
						}
					}
				}
			}

		}
	}
}

mpo_overrunning_willing_vassal_trigger = {
	is_ai = yes
	OR = {
		opinion = {
			target = liege
			value >= 50
		}
		culture = liege.culture
		is_obedient_to = liege
		AND = {
			is_close_family_of = liege
			opinion = {
				target = liege
				value > 0
			}
		}
	}
	highest_held_title_tier >= tier_county
	government_has_flag = government_is_nomadic
	highest_held_title_tier < tier_kingdom
	NOT = { government_has_flag = government_is_herder }
}

is_tsagaan_sar = {
	scope:activity = {
		has_activity_option = {
			category = special_type
			option = feast_type_tsagaan_sar
		}
	}
}
has_eligible_artifact_trigger = {
    any_artifact = {
        artifact_owner = root
        NOR = {
            has_variable = banner_house
            has_variable = banner_dynasty
            has_variable = 1025_treasure_map
        }
        count >= 2
    }
}

can_gift_anything_trigger = {
    OR = {
		short_term_gold >= miniscule_gold_value
        AND = {
            domicile ?= { herd >= twenty_percent_herd_value }
            involved_activity.activity_host = {
                domicile ?= { herd < max_herd }
            }
        }
       any_artifact = {
			artifact_owner = root
			NOR = {
				has_variable = banner_house
				has_variable = banner_dynasty
				has_variable = 1025_treasure_map
			}
			count >= 2
		}
    }
}

mpo_valid_dead_husband_trigger = {
	government_has_flag = government_is_nomadic
	is_married = yes
	is_male = yes
	primary_spouse = {
		is_adult = yes
		NOR = {
			is_imprisoned = yes
			has_contagious_deadly_disease_trigger = yes
			has_trait = incapable
			is_ruler = yes
			has_trait = celibate
			has_trait = devoted
		}
		save_temporary_scope_as = widow
	}
	trigger_if = {
		limit = {
			is_ruler = yes
		}
		OR = {
			NOT = {
				exists = primary_heir
			}
			primary_heir = {
				is_ai = yes
			}
			primary_heir = {
				mpo_valid_widow_marrier_trigger = yes
			}
		}
		
	}
}


mpo_valid_widow_marrier_trigger = {
	#Is a playable character or primary_heir
	OR = {
		root.primary_heir ?= this
		AND = {
			highest_held_title_tier >= tier_county
			is_playable_character = yes
			OR = {
				#Root is wandering landless
				root = {
					is_ruler = no
					NOT = {
						exists = liege
					}
				}
				#Is root's liege
				root.liege ?= this
				#Is root's top liege
				root.top_liege ?= this
				#root has no primary heir
				NOT = {
					exists = root.primary_heir
				}
				#root's primary heir is not of house
				NOT = {
					exists = root.primary_heir.house
				}
				AND = {
					exists = root.house
					NOT = {
						root.house = root.primary_heir.house
					}
				}
			}
			
		}
	}
	
	OR = {
		has_trait = nomadic_philosophy
		culture = {
			has_cultural_pillar = heritage_mongolic
		}
		culture = {
			has_cultural_pillar = heritage_turkic
		}
		faith.religion = faith:tengri_pagan.religion
	}
	#Can have multiple wives or concubines
	faith = {
		OR = {
			has_doctrine = doctrine_polygamy
			has_doctrine = doctrine_concubines
		}
	}
	is_male = yes
	is_adult = yes
	NOR = {
		has_trait = celibate
		has_trait = eunuch
		has_trait = devoted
	}
	#Has a free slot for a wife or concubine
	OR = {
		allowed_more_spouses = yes
		allowed_more_concubines = yes
	}
	#Can marry the widow
	NOT = {
		relation_with_character_is_incestuous_in_my_faith_trigger = { CHARACTER = scope:widow }
	}
}

mpo_nomads_camel_culture_trigger = {
	culture = {
		OR = {
			has_cultural_tradition = tradition_dryland_dwellers
			has_cultural_tradition = tradition_warriors_of_the_dry
			has_cultural_tradition = tradition_desert_ribat
			has_cultural_tradition = tradition_desert_nomads
			has_cultural_tradition = tradition_fp3_irrigation_experts
			has_cultural_tradition = tradition_mubarizuns
			has_cultural_tradition = tradition_saharan_nomads
		}
	}
}

mpo_nomads_sheep_culture_trigger = {
	culture = {
		OR = {
			has_cultural_tradition = tradition_amharic_highlanders
			has_cultural_tradition = tradition_dryland_dwellers
			has_cultural_tradition = tradition_hill_dwellers
			has_cultural_tradition = tradition_mountain_homes
			has_cultural_tradition = tradition_highland_warriors
			has_cultural_tradition = tradition_mountaineers
			has_cultural_tradition = tradition_culinary_art
			has_cultural_tradition = tradition_festivities
			has_cultural_tradition = tradition_sacred_mountains
			has_cultural_tradition = tradition_himalayan_settlers
			has_cultural_tradition = tradition_ep3_indomitable_azatani
			has_cultural_tradition = tradition_caucasian_wolves
			has_cultural_tradition = tradition_fp3_irrigation_experts
			has_cultural_tradition = tradition_mountain_herding
			has_cultural_tradition = tradition_horn_mountain_skirmishing
			has_cultural_tradition = tradition_mountaineer_ruralism
			has_cultural_tradition = tradition_upland_skirmishing
		}
	}
}
mpo_nomads_hunting_culture_trigger = {
	culture = {
		OR = {
			has_cultural_tradition = tradition_forest_folk
			has_cultural_tradition = tradition_jungle_dwellers
			has_cultural_tradition = tradition_wetlanders
			has_cultural_tradition = tradition_forest_fighters
			has_cultural_tradition = tradition_jungle_warriors
			has_cultural_tradition = tradition_ep2_avid_falconers
			has_cultural_tradition = tradition_hunters
			has_cultural_tradition = tradition_sacred_groves
			has_cultural_tradition = tradition_sacred_hunts
			has_cultural_tradition = tradition_bush_hunting
			has_cultural_tradition = tradition_forest_wardens
		}
	}
}
mpo_nomads_horse_culture_trigger = {
	culture = {
		OR = {
			has_cultural_tradition = tradition_pastoralists
			has_cultural_tradition = tradition_hit_and_run
			has_cultural_tradition = tradition_vegetarianism
			has_cultural_tradition = tradition_ep3_audacious_cadets
			has_cultural_tradition = tradition_fp3_fierce_independence
			has_cultural_tradition = tradition_fp3_frontier_warriors
			has_cultural_tradition = tradition_ep3_indomitable_azatani
			has_cultural_tradition = tradition_caucasian_wolves
			has_cultural_tradition = tradition_hussar
			has_cultural_tradition = tradition_roman_legacy
			has_cultural_tradition = tradition_horse_breeder
			has_cultural_tradition = tradition_chivalry
		}
	}
}

is_similar_age_trigger = {
	$CHARACTER$ = {
		age >= root.age_minus_ten
		age <= root.age_plus_ten
	}
}

mpo_lower_nomad_authority_trigger = {
	OR = {
		AND = {
			has_realm_law = nomadic_authority_1
			$CHARACTER$ = {
				OR = {
					has_realm_law = nomadic_authority_2
					has_realm_law = nomadic_authority_3
					has_realm_law = nomadic_authority_4
					has_realm_law = nomadic_authority_5
				}
			}
		}
		AND = {
			has_realm_law = nomadic_authority_2
			$CHARACTER$ = {
				OR = {
					has_realm_law = nomadic_authority_3
					has_realm_law = nomadic_authority_4
					has_realm_law = nomadic_authority_5
				}
			}
		}
		AND = {
			has_realm_law = nomadic_authority_3
			$CHARACTER$ = {
				OR = {
					has_realm_law = nomadic_authority_4
					has_realm_law = nomadic_authority_5
				}
			}
		}
		AND = {
			has_realm_law = nomadic_authority_4
			$CHARACTER$ = {
				has_realm_law = nomadic_authority_5
			}
		}
	}
}

mpo_can_recruit_nomad_maa_trigger = {
	OR = {
		government_has_flag = government_is_nomadic
		has_trait = nomadic_philosophy
	}
}

mpo_can_recruit_nomad_heavy_cavalry_maa_trigger = {
	OR = {
		AND = {
			government_has_flag = government_is_nomadic
			has_realm_law_flag = unlock_maa_nomad_lancers
		}
		AND = {
			NOT = {
				government_has_flag = government_is_nomadic
			}
			has_trait = nomadic_philosophy
		}
	}
}

can_have_tributaries_trigger = {
	has_realm_law_flag = can_have_tributaries
	is_independent_ruler = yes
	NOT = { government_has_flag = government_is_herder }
}

can_get_tributaries_peacefully_trigger = {
	can_have_tributaries_trigger = yes
	OR = {
		government_allows = obedience # nomads and steppe admins
		AND = {
			government_has_flag = government_is_celestial
			highest_held_title_tier = tier_hegemony
		}
		government_has_flag = government_is_mandala
	}	
}

mpo_valid_for_blood_brotherhood_trigger = {
	OR = {
		government_has_flag = government_is_nomadic
		has_trait = nomadic_philosophy
	}
}

mpo_can_be_blood_brothers_trigger = {
	#If one is a child, the other must be a child
	trigger_if = {
		limit = {
			$CHARACTER_1$ = {
				is_adult = no
			}
		}
		$CHARACTER_1$ = {
			is_adult = yes
		}
	}
	trigger_if = {
		limit = {
			$CHARACTER_2$ = {
				is_adult = no
			}
		}
		$CHARACTER_2$ = {
			is_adult = yes
		}
	}
	#They can't be related enough to be allies
	NOR = {
		#Ruler is married to other ruler.
		$CHARACTER_1$ = { is_spouse_of = $CHARACTER_2$ }
		#Ruler is relative of other ruler
		$CHARACTER_1$ = { is_parent_of = $CHARACTER_2$ }
		$CHARACTER_1$ = { is_grandparent_of = $CHARACTER_2$ }
		$CHARACTER_1$ = { is_great_grandparent_of = $CHARACTER_2$ }
		$CHARACTER_1$ = { is_child_of = $CHARACTER_2$ }
		$CHARACTER_1$ = { is_grandchild_of = $CHARACTER_2$ }
		$CHARACTER_1$ = { is_great_grandchild_of = $CHARACTER_2$ }
		$CHARACTER_1$ = { is_uncle_or_aunt_of = $CHARACTER_2$ }
		$CHARACTER_1$ = { is_nibling_of = $CHARACTER_2$ }
		$CHARACTER_1$ = { is_sibling_of = $CHARACTER_2$ }
	}

	# We can't do most of the standard checks for can_set_relation_best_friend_trigger, but we do the relevant ones individually.
	custom_tooltip = {
		text = make_blood_brother_interaction.tt.already_blood_brothers
		$CHARACTER_1$ = {
			NOT = { has_relation_blood_brother = $CHARACTER_2$ }
		}
	}
	trigger_if = {
		limit = {
			NOT = {
				$CHARACTER_1$ = { has_relation_blood_brother = $CHARACTER_2$ }
			}
		}
		custom_tooltip = {
			text =  make_blood_brother_interaction.tt.actor_has_blood_brother
			$CHARACTER_1$ = { num_of_relation_blood_brother = 0 }
		}
	}
	trigger_if = {
		limit = {
			NOT = {
				$CHARACTER_2$ = { has_relation_blood_brother = $CHARACTER_1$ }
			}
		}
		custom_tooltip = {
			text =  make_blood_brother_interaction.tt.recipient_has_blood_brother
			$CHARACTER_2$ = { num_of_relation_blood_brother = 0 }
		}
	}
	trigger_if = {
		limit = {
			$CHARACTER_1$ = {
				is_at_war = yes
			}
		}
		$CHARACTER_1$ = {
			NOR = {
				is_at_war_with = $CHARACTER_2$
				custom_tooltip = {
					text = make_blood_brother_at_war_with_recipient_ally
					any_war_enemy = {
						is_allied_to = $CHARACTER_2$
					}
				}
			}
		}
	}
	trigger_if = {
		limit = {
			$CHARACTER_2$ = {
				is_at_war = yes
			}
		}
		$CHARACTER_2$ = {
			NOR = {
				is_at_war_with = $CHARACTER_1$
				custom_tooltip = {
					text = make_blood_brother_at_war_with_actor_ally
					any_war_enemy = {
						is_allied_to = $CHARACTER_1$
					}
				}
			}
		}
	}
	#Can only do intergender if gender laws are equal or both are rulers
	trigger_if = {
		limit = {
			OR = {
				AND = {
					$CHARACTER_1$ = {
						is_male = yes
					}
					$CHARACTER_2$ = {
						is_female = yes
					}
				}
				AND = {
					$CHARACTER_2$ = {
						is_male = yes
					}
					$CHARACTER_1$ = {
						is_female = yes
					}
				}
			}
			$CHARACTER_1$.faith = {
				NOT = { has_doctrine_parameter = gender_equal_law }
			}
		}
		custom_tooltip = {
			text = make_blood_brother_interaction_intergender_req
			AND = {
				$CHARACTER_1$ = {
					is_ruler = yes
				}
				$CHARACTER_2$ = {
					is_ruler = yes
				}
			}
		}
	}
}

mpo_blood_brother_common_enemy_sub_trigger = {
	NOR = {
		this = scope:recipient
		this = scope:actor
	}
	OR = {
		#Rival of common foe
		has_relation_rival = scope:recipient
		#Is at war with common foe, you're not involved
		AND = {
			NOT = { has_variable = rebel_leader_peasants }
			save_temporary_scope_as = root_temp
			any_character_war = {
				is_war_leader = scope:root_temp
				is_war_leader = scope:recipient
			}
		}
		#Is in a faction against common foe
		any_targeting_faction = {
			any_faction_member = {
				this = scope:recipient
			}
		}
		#common foe is in a faction against recipient
		AND = {
			is_independent_ruler = no
			save_temporary_scope_as = rival_temp
			liege ?= {
				any_targeting_faction = {
					any_faction_member = { this = scope:rival_temp }
				}
			}
		}
		#Recipient is title claimant against common foe
		any_held_title = {
			save_temporary_scope_as = title_temp
			scope:recipient = { has_claim_on = scope:title_temp }
			NOT = {
				scope:actor = { has_claim_on = scope:title_temp }
			}
		}
		#common foe is title claimant against recipient
		any_claim = {
			save_temporary_scope_as = claim_temp
			holder ?= scope:recipient
			NOT = {
				scope:actor = { has_claim_on = scope:claim_temp }
			}
		}
		#Has house feud with common foe's house
		AND = {
			exists = house.house_head
			exists = scope:recipient.house
			exists = scope:actor.house
			NOR = {
				house = scope:actor.house
				house = scope:recipient.house
				scope:actor.house = scope:recipient.house
			}
			house = {
				any_house_relation = {
					has_house_relation_level = feud
					any_relation_house = { this = scope:recipient.house }
				}
			}
		}
	}
}

mpo_blood_brother_common_enemy_trigger = {
	scope:actor = {
		OR = {
			#You have a rival that recipient is also opposed to
			any_relation = {
				type = rival
				mpo_blood_brother_common_enemy_sub_trigger = yes
			}
			#You are at war with someone that recipient is also opposed to
			any_war_enemy = {
				NOT = { has_variable = rebel_leader_peasants }
				any_character_war = {
					is_war_leader = prev
					is_war_leader = scope:actor
				}
				mpo_blood_brother_common_enemy_sub_trigger = yes
			}
			#You are in a faction against someone that recipient is also opposed to
			liege ?= {
				any_targeting_faction = {
					any_faction_member = {
						this = scope:actor
					}
				}
				mpo_blood_brother_common_enemy_sub_trigger = yes
			}
			#You have a faction member that recipient is also opposed to
			any_targeting_faction = {
				any_faction_member = {
					mpo_blood_brother_common_enemy_sub_trigger = yes
				}
			}
			#You have a title claimant that recipient is also opposed to
			any_held_title = {
				NOT = {
					scope:recipient = {
						has_claim_on = prev
					}
				}
				any_claimant = {
					mpo_blood_brother_common_enemy_sub_trigger = yes
				}
			}
			#You are a title claimant against someone recipient is also opposed to
			any_claim = {
				exists = holder
				NOT = {
					scope:recipient = { has_claim_on = prev }
				}
				holder = {
					mpo_blood_brother_common_enemy_sub_trigger = yes
				}
			}
			#You have a house feud against someone recipient is also opposed to
			AND = {
				exists = house.house_head
				exists = scope:recipient.house
				NOT = {
					house = scope:recipient.house
				}
				house = {
					any_house_relation = {
						has_house_relation_level = feud
						any_relation_house = {
							house_head = { mpo_blood_brother_common_enemy_sub_trigger = yes }
						}
					}
				}
			}
		}
	}
}

mpo_blood_brother_reason_memory_trigger = {
	OR = {
		has_memory_type = was_adopted
		has_memory_type = adopted_a_child
		has_memory_type = friend_granted_my_claim
		has_memory_type = match_made
		has_memory_type = completed_pilgrimage_friend
		has_memory_type = noble_family_adopted
		has_memory_type = was_noble_family_adopted
		has_memory_type = adventurer_family_adopted
		has_memory_type = was_adventurer_family_adopted
		has_memory_type = saved_someone_from_a_bull_memory
		has_memory_type = knight_sacrificed_memory
		has_memory_type = saved_from_assault_memory
		has_memory_type = forgave_and_released_prisoner_memory
		has_memory_type = rescued_fallen_victim_memory
		has_memory_type = nice_fishing_trip
		has_memory_type = reading_aid
		has_memory_type = supported_illiterate
		has_memory_type = lost_my_addiction_memory
		has_memory_type = friend_despite_rivalry
		has_memory_type = witnessed_death_battle_good_killer
		has_memory_type = cared_for_by_host
		has_memory_type = hostage_oath_of_friendship
		has_memory_type = procured_estate_memory
		has_memory_type = evangelized_memory
		has_memory_type = was_evangelized_memory
		has_memory_type = pledged_marriage
	}
}

mpo_ideal_common_foe_trigger = {
	trigger_if = {
		limit = {
			highest_held_title_tier >= tier_kingdom
		}
		reverse_opinion = {
			target = scope:actor
			value <= 60
		}
	}
	trigger_else = {
		highest_held_title_tier >= tier_duchy
		reverse_opinion = {
			target = scope:actor
			value <= 20
		}
	}
}

mpo_blood_brother_august_trigger = {
	prestige_level >= $OTHER_BROTHER$.prestige_level
	OR = {
		prestige_level >= 4
		highest_held_title_tier >= tier_kingdom
		has_realm_law = nomadic_authority_4
		has_realm_law = nomadic_authority_5
	}
	OR = {
		highest_held_title_tier > $OTHER_BROTHER$.highest_held_title_tier
		AND = {
			OR = {
				has_realm_law = nomadic_authority_2
				has_realm_law = nomadic_authority_3
				has_realm_law = nomadic_authority_4
				has_realm_law = nomadic_authority_5
			}
			$OTHER_BROTHER$ = {
				has_realm_law = nomadic_authority_1
			}
		}
		AND = {
			OR = {
				has_realm_law = nomadic_authority_3
				has_realm_law = nomadic_authority_4
				has_realm_law = nomadic_authority_5
			}
			$OTHER_BROTHER$ = {
				has_realm_law = nomadic_authority_2
			}
		}
		AND = {
			OR = {
				has_realm_law = nomadic_authority_4
				has_realm_law = nomadic_authority_5
			}
			$OTHER_BROTHER$ = {
				has_realm_law = nomadic_authority_3
			}
		}
		AND = {
			has_realm_law = nomadic_authority_5
			$OTHER_BROTHER$ = {
				has_realm_law = nomadic_authority_4
			}
		}
	}
}

mpo_blood_brother_warrior_trigger = {
	can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = $OTHER_BROTHER$ }
	OR = {
		prowess >= monumentally_high_skill_rating
		AND = {
			prowess >= extremely_high_skill_rating
			OR = {
				has_trait = lifestyle_blademaster
				has_trait = education_martial_prowess_3
				has_trait = education_martial_prowess_4
				AND = {
					has_trait = tourney_participant
					OR = {
						has_trait_xp = {
							trait = tourney_participant
							value >= 50
							track = foot
						}
						has_trait_xp = {
							trait = tourney_participant
							value >= 50
							track = horse
						}
						has_trait_xp = {
							trait = tourney_participant
							value >= 50
							track = bow
						}
					}
				}
				has_trait = berserker
				has_trait = sadistic
				has_trait = vengeful
				has_trait = brave
				has_trait = wrathful
				has_trait = aggressive_attacker
				has_trait = reaver
			}
		}
		martial >= extremely_high_skill_rating
		AND = {
			OR = {
				prowess >= very_high_skill_rating
				has_trait = education_martial
				has_lifestyle = martial_lifestyle
			}
			dread >= 60
		}
	}
}

mpo_blood_brother_clever_trigger = {
	OR = {
		has_trait = intellect_good_3
		has_trait = shrewd
		learning > extremely_high_skill_rating
		stewardship > extremely_high_skill_rating
		intrigue > extremely_high_skill_rating
		diplomacy > extremely_high_skill_rating
	}
}
mpo_blood_brother_loving_trigger = {
	ai_compassion > low_negative_ai_value
	OR = {
		has_trait = trusting
		has_trait = compassionate
		has_trait = generous
		has_trait = loyal
		has_trait = gregarious
		has_trait = forgiving
		has_trait = family_first
	}
}

has_bad_season_nomadic_capital_root_trigger = {
	any_county_situation = {
		OR = {
			any_situation_sub_region = {
				sub_region_current_phase = situation_steppe_white_zud_season
				situation_sub_region_has_county = root.capital_county
			}
			any_situation_sub_region = {
				sub_region_current_phase = situation_steppe_cold_zud_season
				situation_sub_region_has_county = root.capital_county
			}
			any_situation_sub_region = {
				sub_region_current_phase = situation_steppe_severe_drought_season
				situation_sub_region_has_county = root.capital_county
			}
			any_situation_sub_region = {
				sub_region_current_phase = situation_steppe_havsarsan_zud_season
				situation_sub_region_has_county = root.capital_county
			}
		}
	}
}

has_zud_season_nomadic_capital_root_trigger = {
	any_character_situation = {
		OR = {
			any_situation_sub_region = {
				sub_region_current_phase = situation_steppe_white_zud_season
				situation_sub_region_has_county = root.capital_county
			}
			any_situation_sub_region = {
				sub_region_current_phase = situation_steppe_cold_zud_season
				situation_sub_region_has_county = root.capital_county
			}
			any_situation_sub_region = {
				sub_region_current_phase = situation_steppe_havsarsan_zud_season
				situation_sub_region_has_county = root.capital_county
			}
		}
	}
}

has_zud_season_in_county_trigger = {
	any_character_situation = {
		OR = {
			any_situation_sub_region = {
				sub_region_current_phase = situation_steppe_white_zud_season
				situation_sub_region_has_county = $COUNTY$
			}
			any_situation_sub_region = {
				sub_region_current_phase = situation_steppe_cold_zud_season
				situation_sub_region_has_county = $COUNTY$
			}
			any_situation_sub_region = {
				sub_region_current_phase = situation_steppe_havsarsan_zud_season
				situation_sub_region_has_county = $COUNTY$
			}
		}
	}
}

has_bad_season_nomadic_capital_character_trigger = {
	any_character_situation = {
		OR = {
			any_situation_sub_region = {
				sub_region_current_phase = situation_steppe_white_zud_season
				situation_sub_region_has_county = $CHARACTER$.capital_county
			}
			any_situation_sub_region = {
				sub_region_current_phase = situation_steppe_cold_zud_season
				situation_sub_region_has_county = $CHARACTER$.capital_county
			}
			any_situation_sub_region = {
				sub_region_current_phase = situation_steppe_severe_drought_season
				situation_sub_region_has_county = $CHARACTER$.capital_county
			}
			any_situation_sub_region = {
				sub_region_current_phase = situation_steppe_havsarsan_zud_season
				situation_sub_region_has_county = $CHARACTER$.capital_county
			}
		}
	}
}

has_bad_season_in_county_trigger = {
	any_county_situation = {
		OR = {
			any_situation_sub_region = {
				sub_region_current_phase = situation_steppe_white_zud_season
				situation_sub_region_has_county = $COUNTY$
			}
			any_situation_sub_region = {
				sub_region_current_phase = situation_steppe_cold_zud_season
				situation_sub_region_has_county = $COUNTY$
			}
			any_situation_sub_region = {
				sub_region_current_phase = situation_steppe_severe_drought_season
				situation_sub_region_has_county = $COUNTY$
			}
			any_situation_sub_region = {
				sub_region_current_phase = situation_steppe_havsarsan_zud_season
				situation_sub_region_has_county = $COUNTY$
			}
		}
	}
}

has_good_season_nomadic_capital_root_trigger = {
	any_character_situation = {
		OR = {
			any_situation_sub_region = {
				sub_region_current_phase = situation_steppe_abundant_grazing_season
				situation_sub_region_has_county = root.capital_county
			}
			any_situation_sub_region = {
				sub_region_current_phase = situation_steppe_warm_nights_season
				situation_sub_region_has_county = root.capital_county
			}
			any_situation_sub_region = {
				sub_region_current_phase = situation_steppe_sky_blessing_season
				situation_sub_region_has_county = root.capital_county
			
			}
		}
	}
}

has_good_season_nomadic_capital_character_trigger = {
	any_character_situation = {
		OR = {
			any_situation_sub_region = {
				sub_region_current_phase = situation_steppe_abundant_grazing_season
				situation_sub_region_has_county = $CHARACTER$.capital_county
			}
			any_situation_sub_region = {
				sub_region_current_phase = situation_steppe_warm_nights_season
				situation_sub_region_has_county = $CHARACTER$.capital_county
			}
			any_situation_sub_region = {
				sub_region_current_phase = situation_steppe_sky_blessing_season
				situation_sub_region_has_county = $CHARACTER$.capital_county
			}
		}
	}
}

has_good_season_in_county_trigger = {
	any_county_situation = {
		OR = {
			any_situation_sub_region = {
				sub_region_current_phase = situation_steppe_abundant_grazing_season
				situation_sub_region_has_county = $COUNTY$
			}
			any_situation_sub_region = {
				sub_region_current_phase = situation_steppe_warm_nights_season
				situation_sub_region_has_county = $COUNTY$
			}
			any_situation_sub_region = {
				sub_region_current_phase = situation_steppe_sky_blessing_season
				situation_sub_region_has_county = $COUNTY$
			
			}
		}
	}
}

great_steppe_not_in_sub_region_trigger = {
    situation:the_great_steppe ?= {
        NOT = {
            any_situation_sub_region = {
                situation_sub_region_has_geographical_region = geographical_region:$REGION$ 
            }
        }
    }
}

is_gurkhan = {
	trigger_if = {
		limit = { exists = situation:the_great_steppe }
		this = situation:the_great_steppe.situation_top_herd
	}
}

mpo_permafrost_building_trigger = {
	trigger_if = {
		limit = {
			county = {
				has_county_modifier = mpo_siberian_permafrost_modifier
			}		
		}
		culture ?= scope:holder.culture
		culture ?= {
			has_cultural_tradition = tradition_mpo_northern_tribes
		}
	}
}

has_raid_intent_protection = {
	scope:county.duchy = {
		any_in_de_jure_hierarchy = {
			tier = tier_county
			holder.top_liege = scope:county.holder.top_liege
			any_county_province = {
				has_building_with_flag = raid_protection_1
			}
		}
	}
}

has_raid_intent_immunity = {
	scope:county.duchy = {
		any_in_de_jure_hierarchy = {
			tier = tier_county
			holder.top_liege = scope:county.holder.top_liege
			any_county_province = {
				has_building_with_flag = raid_protection_2
			}
		}
	}
}

has_chaotic_succession_trigger = { # Used to set up right scopes for Important Action
	capital_county ?= {
		any_county_situation = {
			any_participant_group = {
				participant_group_type = nomad_rulers_capital
			}
			any_situation_sub_region = {
				save_temporary_scope_as = subregion
			}
		}
	}
	has_chaotic_succession_trigger_action = yes
}

has_chaotic_succession_trigger_action = { # Used in both Rules and Important Action
	save_temporary_scope_as = root_scope
	OR = {
		trigger_if = {
			limit = {
				exists = scope:subregion
			}
			custom_tooltip = {
				text = chaotic_succession_havsarsan_zud
				scope:subregion ?= {
					sub_region_current_phase = situation_steppe_havsarsan_zud_season
				}
			}
		}
		trigger_if = {
			limit = {
				mpo_current_disobedient_kurultai_value >= 1
			}
			custom_tooltip = {
				text = chaotic_succession_disobedient_kurultai
				always = yes
			}
		}
		trigger_else = {
			custom_tooltip = {
				text = chaotic_succession_disobedient_kurultai_none
				always = no
			}
		}
		trigger_if = {
			limit = {
				OR = {
					NOT = { exists = cp:councillor_kurultai_1 }
					NOT = { exists = cp:councillor_kurultai_2 }
					NOT = { exists = cp:councillor_kurultai_3 }
					NOT = { exists = cp:councillor_kurultai_4 }
				}
			}
			custom_tooltip = {
				text = is_kurultai_succession_chaotic_empty_kurultai
				always = yes
			}
		}
		trigger_else = {
			custom_tooltip = {
				text = is_kurultai_succession_chaotic_empty_kurultai_none
				always = no
			}
		}
	}
	trigger_if = {
		limit = {
			any_held_title = {
				has_variable = chaotic_succession_protection
			}
		}
		custom_tooltip = {
			text = chaotic_succession_protection_tt
			NOT = {
				any_held_title = {
					has_variable = chaotic_succession_protection
				}
			}
		}
	}
	trigger_if = {
		limit = {
			primary_title ?= {
				has_title_law = confederation_elective_succession_law
			}
		}
		custom_tooltip = {
			text = chaotic_succession_protection_title_law_tt
			NOT = {
				primary_title ?= {
					has_title_law = confederation_elective_succession_law
				}
			}
		}
	}
}

mpo_de_jure_shifting_triggers = {
	NOR = {
		target_is_de_jure_liege_or_above = root.primary_title
		any_de_jure_county_holder = {
			NOR = {
				root = { is_liege_or_above_of = prev }
				is_tributary_of_suzerain_or_above = root
				top_liege = {
					is_tributary_of_suzerain_or_above = root
				}
			}
		}
		any_de_jure_county = {
			NOT = {
				any_county_situation = {
					any_participant_group = {
						participant_group_type = nomad_rulers_capital
					}
				}
			}
		}
	}
	any_title_to_title_neighboring_$UPPER_TIER$ = {
		this = root.primary_title
	}
}

vassal_grant_de_jure_shift_trigger = {
	tier >= tier_duchy
	tier = scope:secondary_actor.highest_held_title_tier
	NOR = {
		target_is_de_jure_liege_or_above = scope:recipient.primary_title
		any_de_jure_county = {
			any_county_situation = {
				any_participant_group = {
					participant_group_type = nomad_rulers_capital
				}
			}
		}
		any_de_jure_county_holder = {
			NOR = {
				any_liege_or_above = {
					this = scope:recipient
				}
				is_tributary_of_suzerain_or_above = scope:recipient
				top_liege = {
					is_tributary_of_suzerain_or_above = scope:recipient
				}
			}
		}
	}
	switch = {
		trigger = scope:secondary_actor.highest_held_title_tier
		tier_kingdom = {
			any_title_to_title_neighboring_kingdom = {
				this = scope:recipient.primary_title
			}
		}
		tier_duchy = {
			any_title_to_title_neighboring_kingdom = {
				this = scope:recipient.primary_title
			}
		}
	}
}

higher_dominance_trigger = {
	$FIRST_TARGET$ = {
		switch = {
			trigger = has_realm_law
			nomadic_authority_5 = {
				$SECOND_TARGET$ = {
					OR = {
						has_realm_law = nomadic_authority_4
						has_realm_law = nomadic_authority_3
						has_realm_law = nomadic_authority_2
						has_realm_law = nomadic_authority_1
					}
				}
			}
			nomadic_authority_4 = {
				$SECOND_TARGET$ = {
					OR = {
						has_realm_law = nomadic_authority_3
						has_realm_law = nomadic_authority_2
						has_realm_law = nomadic_authority_1
					}
				}
			}
			nomadic_authority_3 = {
				$SECOND_TARGET$ = {
					OR = {
						has_realm_law = nomadic_authority_2
						has_realm_law = nomadic_authority_1
					}
				}
			}
			nomadic_authority_2 = {
				$SECOND_TARGET$ = {
					has_realm_law = nomadic_authority_1
				}
			}
		}
	}
}

higher_or_equal_dominance_trigger = {
	$FIRST_TARGET$ = {
		switch = {
			trigger = has_realm_law
			nomadic_authority_5 = {
				$SECOND_TARGET$ = {
					OR = {
						has_realm_law = nomadic_authority_5
						has_realm_law = nomadic_authority_4
						has_realm_law = nomadic_authority_3
						has_realm_law = nomadic_authority_2
						has_realm_law = nomadic_authority_1
					}
				}
			}
			nomadic_authority_4 = {
				$SECOND_TARGET$ = {
					OR = {
						has_realm_law = nomadic_authority_4
						has_realm_law = nomadic_authority_3
						has_realm_law = nomadic_authority_2
						has_realm_law = nomadic_authority_1
					}
				}
			}
			nomadic_authority_3 = {
				$SECOND_TARGET$ = {
					OR = {
						has_realm_law = nomadic_authority_3
						has_realm_law = nomadic_authority_2
						has_realm_law = nomadic_authority_1
					}
				}
			}
			nomadic_authority_2 = {
				$SECOND_TARGET$ = {
					OR = {
						has_realm_law = nomadic_authority_2
						has_realm_law = nomadic_authority_1
					}
				}
			}
			nomadic_authority_2 = {
				$SECOND_TARGET$ = {
					has_realm_law = nomadic_authority_1
				}
			}
		}
	}
}

#any_county scope
county_ready_for_abuse_trigger = {
	uses_county_fertility = yes
	any_county_situation = { this = situation:the_great_steppe }
	holder = {
		is_ai = yes
	}
	NOR = {
		holder = root
		holder = situation:the_great_steppe.situation_top_herd
		has_county_modifier = mpo_paiza_abused_county_modifier
	}
}

