﻿mgr_vassal_can_declare_war = {
	#Game rules
	OR = {
		is_ai = no
		NOT = { has_game_rule = no_ai_aggressiveness }
	}
	OR = {
		is_independent_ruler = yes
		AND = { #Otherwise sengoku is broken
			government_is_japanese_trigger = yes
			top_liege = { government_is_japanese_trigger = yes }
		}
		has_game_rule = default_external_vw
		AND = {
			has_game_rule = player_external_vw
			is_ai = no
		}
	}
}

matri_marriage_allowed = {
	custom_description = {
		text = GAME_RULE_MATRI_MARRIAGE_ALLOWED
		OR = {
			has_game_rule = default_matri
			AND = {
				has_game_rule = restricted_matri
				faith = {
					OR = {
						has_doctrine = doctrine_gender_equal
						has_doctrine = doctrine_gender_female_dominated
					}
				}
			}
			AND = {
				has_game_rule = more_restricted_matri
				faith = { has_doctrine = doctrine_gender_female_dominated }
			}
		}
	}
}

#When root is top liege
is_de_jure_vassal_of_ROOT_top_liege_trigger = {
	any_held_title = {
		#limit = { tier = prev.highest_held_title_tier }
		OR = {	
			de_jure_liege = {
				exists = holder
				holder = root
			}
			trigger_if = {
				limit = {
					tier = tier_duchy
				}
				de_jure_liege = { #king
					de_jure_liege = { #emperor
						exists = holder
						holder = root
					}
				}
			}
			trigger_if = {
				limit = {
					tier = tier_county
				}
				de_jure_liege = { #duke
					de_jure_liege = { #king
						OR = {
							AND = {
								exists = holder
								holder = root
							}
							de_jure_liege = { #emperor
								exists = holder
								holder = root
							}
						}
					}
				}
			}
		}
	}
}

is_protected_hre_vassal = {
	save_temporary_scope_as = checked
	OR = {
		title:e_france = {
			any_in_de_jure_hierarchy = { #any_de_jure_vassal_or_below
				this = scope:checked.primary_title
			}
		}

		title:e_italy = {
			any_in_de_jure_hierarchy = { #any_de_jure_vassal_or_below
				this = scope:checked.primary_title
			}
		}
	}
}

mgr_is_historical_empire = {
	OR = {
		this = title:e_hre
		this = title:e_byzantium
		this = title:e_roman_empire
		this = title:e_persia
		this = title:e_spain
	}
}

mgr_is_expanded_historical_empire = {
	OR = {
		mgr_is_historical_empire = yes
		this = title:e_arabia
		this = title:e_tibet
		this = title:e_mali
		this = title:e_rajastan
		this = title:e_kanem_bornu
		this = title:e_bengal
		this = title:e_deccan
		this = title:e_abyssinia
	}
}

mgr_can_seduce = {
	OR = {
		is_ai = no #Player always has agency
		has_game_rule = default_seduction
		has_game_rule = more_seduction
		AND = {
			has_game_rule = restricted_seduction
			OR = {
				has_trait = lustful
				has_trait = seducer
				has_trait = rakish
			}
			OR = {
				#Men have to be somewhat important to be eligible for this.
				is_lowborn = no
				is_female = yes
			}
			OR = { #Men actually have to be 'potent' to seduce.
				is_female = yes
				fertility >= 0.1
			}
			#Women must either be young or important
			OR = {
				is_female = no
				age < 45
				AND = {
					is_landed = yes
					primary_title.tier > tier_county
				}
			}
		}
		#'Realistic'
		AND = { 
			has_game_rule = less_seduction
			OR = {
				#Men have to be somewhat important to be eligible for this.
				is_lowborn = no
				is_female = yes
			}
			OR = { #Men actually have to be 'potent' to seduce.
				is_female = yes
				fertility >= 0.1
			}
			#Women must either be young or important. If old, they must have a seductive-type trait
			OR = {
				is_female = no
				age < 45
				AND = {
					is_landed = yes
					primary_title.tier > tier_county
					OR = {
						has_trait = lustful
						has_trait = seducer
						has_trait = rakish
					}
				}
			}
			NOR = { #Disabling traits
				has_trait = celibate
				has_trait = chaste
				#has_trait = devoted
				has_trait = eunuch
				has_trait = incapable
			}
			OR = {
				has_trait = lustful
				has_trait = seducer
				has_trait = rakish
				#Seduction for characters without lustful traits
				AND = { 
					#Marriage conditions
					OR = {
						is_married = no
						faith = { has_doctrine = tenet_polyamory }
						#If married, the following rules apply
						AND = {
							NOT = { has_trait = loyal } #Will never cheat even if they hate spouse
							NOT = { has_trait = chaste } #Will never cheat even if they hate spouse
							NOT = { #Loves spouse, no need to cheat
								OR = {
									opinion = {
										target = primary_spouse
										value >= medium_positive_opinion
									}
									#has_relation_lover = primary_spouse #allows multiple lovers if scorned too much
									has_relation_soulmate = primary_spouse
								}
							}
							OR = {
								opinion = {
									target = primary_spouse
									value <= medium_negative_opinion
								}
								has_trait = deceitful
								has_trait = adulterer #once a cheater...
								#has_trait = drunkard
								has_trait = disloyal
								has_trait = sadistic
								has_trait = callous
								has_trait = vengeful
							}
						}
					}
					is_concubine = no
					#Trait requirements
					OR = { 
						#ENABLING TRAITS#
						#Personality traits
						has_trait = deceitful
						#has_trait = impatient
						#has_trait = gluttonous
						has_trait = arbitrary
						has_trait = fickle

						#Non-personality traits
						#has_trait = schemer
						has_trait = adulterer
						has_trait = fornicator
						has_trait = lunatic_1
						has_trait = lunatic_genetic
						has_trait = deviant
						has_trait = lifestyle_reveler
						has_trait = drunkard
						AND = {
							OR = {
								has_trait = zealous
								has_trait = devoted
							}
							faith = {  has_doctrine = tenet_carnal_exaltation }
						}
						#Alternatively not having any of these is good enough too
						NOR = { 
							#Personality
							has_trait = shy
							has_trait = craven
							has_trait = patient
							has_trait = content
							has_trait = paranoid
							has_trait = temperate

							#Non-personality
							has_trait = reclusive
							has_trait = depressed_1
							has_trait = depressed_genetic
							has_trait = disfigured
							has_trait = beauty_bad_2
							has_trait = beauty_bad_3

							#These only apply if married. Otherwise they don't count.
							AND = {
								is_married = yes
								OR = {
									has_trait = loyal
									has_trait = honest
									has_trait = just
									has_trait = forgiving
								}
							}
						}
					}
					#Only one lover unless we have a lustful-type trait or a tenet that encourages multiple lovers
					OR = {
						AND = {
							num_of_relation_lover < 1
							num_of_relation_soulmate < 1
						}
						has_trait = lustful
						has_trait = seducer
						has_trait = rakish
						faith = { 
							OR = {
								has_doctrine = tenet_carnal_exaltation 
								has_doctrine = tenet_polyamory
							}
						}
					}
					#Zealous restrictions: Don't seduce unless accepted in faith
					OR = {
						AND = {
							NOT = { has_trait = zealous }
							NOT = { has_trait = devoted }
						}
						AND = {
							is_female = yes
							faith = { has_doctrine = doctrine_adultery_women_accepted }
						}
						AND = {
							is_male = yes
							faith = { has_doctrine = doctrine_adultery_men_accepted }
						}
					}
				}
			}
		}
	}
}

mgr_can_murder = {
	OR = {
		is_ai = no
		has_game_rule = default_intrigue
		AND = {
			OR = {
				has_game_rule = less_intrigue
				has_game_rule = restricted_intrigue
			}
			#Must have one of these traits
			OR = {
				AND = {
					has_education_intrigue_trigger = yes
					has_game_rule = less_intrigue
				}
				AND = {
					OR = {
						has_game_rule = less_intrigue
						has_trait = schemer
						has_trait = torturer
						has_trait = lunatic_1
						has_trait = lunatic_genetic
					}
					OR = {	
						has_trait = greedy
						has_trait = paranoid
					}
				}
				has_trait = deceitful
				has_trait = sadistic
				has_trait = vengeful
				has_trait = callous
			}
			#Cannot have one of these traits
			NOR = {
				has_trait = craven
				has_trait = compassionate
				has_trait = forgiving
			}
		}
	}
}