﻿
#####################################################################
# 00_education_triggers
#####################################################################

#Takes RANK and OPERATOR
#OPERATOR can be "equals", "greater" or "less"
has_education_rank_trigger = {
	save_temporary_scope_value_as = {
		name = operator
		value = flag:$OPERATOR$
	}
	OR = {
		AND = {
			scope:operator = flag:equals
			OR = {
				has_trait_rank = {
					trait = education_diplomacy
					rank = $RANK$
				}
				has_trait_rank = {
					trait = education_martial
					rank = $RANK$
				}
				has_trait_rank = {
					trait = education_stewardship
					rank = $RANK$
				}
				has_trait_rank = {
					trait = education_intrigue
					rank = $RANK$
				}
				has_trait_rank = {
					trait = education_learning
					rank = $RANK$
				}
				has_trait_rank = {
					trait = education_nht_prowess
					rank = $RANK$
				}
				has_trait_rank = {
					trait = education_nht_leadership
					rank = $RANK$
				}
			}
		}
		AND = {
			scope:operator = flag:greater
			OR = {
				has_trait_rank = {
					trait = education_diplomacy
					rank > $RANK$
				}
				has_trait_rank = {
					trait = education_martial
					rank > $RANK$
				}
				has_trait_rank = {
					trait = education_stewardship
					rank > $RANK$
				}
				has_trait_rank = {
					trait = education_intrigue
					rank > $RANK$
				}
				has_trait_rank = {
					trait = education_learning
					rank > $RANK$
				}
				has_trait_rank = {
					trait = education_nht_prowess
					rank > $RANK$
				}
				has_trait_rank = {
					trait = education_nht_leadership
					rank > $RANK$
				}
			}
		}
		#AND = {
		#	scope:operator = flag:less
		#	OR = {
		#		has_trait_rank = {
		#			trait = education_diplomacy
		#			rank < $RANK$
		#		}
		#		has_trait_rank = {
		#			trait = education_martial
		#			rank < $RANK$
		#		}
		#		has_trait_rank = {
		#			trait = education_stewardship
		#			rank < $RANK$
		#		}
		#		has_trait_rank = {
		#			trait = education_intrigue
		#			rank < $RANK$
		#		}
		#		has_trait_rank = {
		#			trait = education_learning
		#			rank < $RANK$
		#		}
		#	}
		#}
	}
}

has_education_focus_trigger = {
 	OR = {
 		has_focus = education_diplomacy
 		has_focus = education_martial
 		has_focus = education_stewardship
 		has_focus = education_intrigue
 		has_focus = education_learning
 		has_focus = education_nht_prowess
 		has_focus = education_nht_leadership	
 	}
}

#Takes RANK
education_points_equals_education_rank = {
	OR = {
		education_points_and_focus_equals_education_rank = { RANK = $RANK$ FOCUS = diplomacy }
		education_points_and_focus_equals_education_rank = { RANK = $RANK$ FOCUS = martial }
		education_points_and_focus_equals_education_rank = { RANK = $RANK$ FOCUS = stewardship }
		education_points_and_focus_equals_education_rank = { RANK = $RANK$ FOCUS = intrigue }
		education_points_and_focus_equals_education_rank = { RANK = $RANK$ FOCUS = learning }
		education_points_and_focus_equals_education_rank = { RANK = $RANK$ FOCUS = nht_prowess }
		education_points_and_focus_equals_education_rank = { RANK = $RANK$ FOCUS = nht_leadership }		
	}
}


characters_have_same_education_group_trigger = {
	# First, we make sure that both characters have an education finalised.
	$CHARACTER_1$ = {
		OR = {
			has_trait = education_diplomacy
			has_trait = education_martial
			has_trait = education_stewardship
			has_trait = education_intrigue
			has_trait = education_learning
			has_trait = education_nht_prowess
			has_trait = education_nht_leadership
		}
	}
	$CHARACTER_2$ = {
		OR = {
			has_trait = education_diplomacy
			has_trait = education_martial
			has_trait = education_stewardship
			has_trait = education_intrigue
			has_trait = education_learning
			has_trait = education_nht_prowess
			has_trait = education_nht_leadership
		}
	}
	# Now check for the actual traits.
	$CHARACTER_1$ = {
		# Diplomacy.
		trigger_if = {
			limit = { has_trait = education_diplomacy }
			$CHARACTER_2$ = { has_trait = education_diplomacy}
		}
		# Martial.
		trigger_if = {
			limit = { has_trait = education_martial }
			$CHARACTER_2$ = { has_trait = education_martial }
		}
		# Stewardship.
		trigger_if = {
			limit = { has_trait = education_stewardship }
			$CHARACTER_2$ = { has_trait = education_stewardship }
		}
		# Intrigue.
		trigger_if = {
			limit = { has_trait = education_intrigue }
			$CHARACTER_2$ = { has_trait = education_intrigue }
		}
		# Learning.
		trigger_if = {
			limit = { has_trait = education_learning }
			$CHARACTER_2$ = { has_trait = education_learning }
		}
		##### More Lifestyles Modifications
		trigger_if = {
			limit = { has_trait = education_nht_prowess }
			$CHARACTER_2$ = { has_trait = education_nht_prowess }
		}
		trigger_if = {
			limit = { has_trait = education_nht_leadership }
			$CHARACTER_2$ = { has_trait = education_nht_leadership }
		}
	}
}




#####################################################################
# 00_general_trait_triggers
#####################################################################


#Checks whether scope character and compare_character has the same type of education.
has_same_education_as_compare_character_trigger = {
	OR = {
		AND = {
			OR = {
				has_trait = education_intrigue_1
				has_trait = education_intrigue_2
				has_trait = education_intrigue_3
				has_trait = education_intrigue_4
				has_trait = education_intrigue_5
			}
			scope:compare_character = {
				OR = {
					has_trait = education_intrigue_1
					has_trait = education_intrigue_2
					has_trait = education_intrigue_3
					has_trait = education_intrigue_4
					has_trait = education_intrigue_5
				}
			}
		}
		AND = {
			OR = {
				has_trait = education_diplomacy_1
				has_trait = education_diplomacy_2
				has_trait = education_diplomacy_3
				has_trait = education_diplomacy_4
				has_trait = education_diplomacy_5
			}
			scope:compare_character = {
				OR = {
					has_trait = education_diplomacy_1
					has_trait = education_diplomacy_2
					has_trait = education_diplomacy_3
					has_trait = education_diplomacy_4
					has_trait = education_diplomacy_5
				}
			}
		}
		AND = {
			OR = {
				has_trait = education_stewardship_1
				has_trait = education_stewardship_2
				has_trait = education_stewardship_3
				has_trait = education_stewardship_4
				has_trait = education_stewardship_5
			}
			scope:compare_character = {
				OR = {
					has_trait = education_stewardship_1
					has_trait = education_stewardship_2
					has_trait = education_stewardship_3
					has_trait = education_stewardship_4
					has_trait = education_stewardship_5
				}
			}
		}
		AND = {
			OR = {
				has_trait = education_martial_1
				has_trait = education_martial_2
				has_trait = education_martial_3
				has_trait = education_martial_4
				has_trait = education_martial_5
			}
			scope:compare_character = {
				OR = {
					has_trait = education_martial_1
					has_trait = education_martial_2
					has_trait = education_martial_3
					has_trait = education_martial_4
					has_trait = education_martial_5
				}
			}
		}
		AND = {
			OR = {
				has_trait = education_learning_1
				has_trait = education_learning_2
				has_trait = education_learning_3
				has_trait = education_learning_4
				has_trait = education_learning_5
			}
			scope:compare_character = {
				OR = {
					has_trait = education_learning_1
					has_trait = education_learning_2
					has_trait = education_learning_3
					has_trait = education_learning_4
					has_trait = education_learning_5
				}
			}
		}
		##### Start More Lifestyles Submod Modifications
		AND = {
			OR = {
				has_trait = education_nht_prowess_1
				has_trait = education_nht_prowess_2
				has_trait = education_nht_prowess_3
				has_trait = education_nht_prowess_4
				has_trait = education_nht_prowess_5
			}
			scope:compare_character = {
				OR = {
					has_trait = education_nht_prowess_1
					has_trait = education_nht_prowess_2
					has_trait = education_nht_prowess_3
					has_trait = education_nht_prowess_4
					has_trait = education_nht_prowess_5
				}
			}
		}
		AND = {
			OR = {
				has_trait = education_nht_leadership_1
				has_trait = education_nht_leadership_2
				has_trait = education_nht_leadership_3
				has_trait = education_nht_leadership_4
				has_trait = education_nht_leadership_5
			}
			scope:compare_character = {
				OR = {
					has_trait = education_nht_leadership_1
					has_trait = education_nht_leadership_2
					has_trait = education_nht_leadership_3
					has_trait = education_nht_leadership_4
					has_trait = education_nht_leadership_5
				}
			}
		}		
	}
}


has_same_education_as_root_trigger = {
	OR = {
		AND = {
			OR = {
				has_trait = education_intrigue_1
				has_trait = education_intrigue_2
				has_trait = education_intrigue_3
				has_trait = education_intrigue_4
				has_trait = education_intrigue_5
			}
			root = {
				OR = {
					has_trait = education_intrigue_1
					has_trait = education_intrigue_2
					has_trait = education_intrigue_3
					has_trait = education_intrigue_4
					has_trait = education_intrigue_5
				}
			}
		}
		AND = {
			OR = {
				has_trait = education_diplomacy_1
				has_trait = education_diplomacy_2
				has_trait = education_diplomacy_3
				has_trait = education_diplomacy_4
				has_trait = education_diplomacy_5
			}
			root = {
				OR = {
					has_trait = education_diplomacy_1
					has_trait = education_diplomacy_2
					has_trait = education_diplomacy_3
					has_trait = education_diplomacy_4
					has_trait = education_diplomacy_5
				}
			}
		}
		AND = {
			OR = {
				has_trait = education_stewardship_1
				has_trait = education_stewardship_2
				has_trait = education_stewardship_3
				has_trait = education_stewardship_4
				has_trait = education_stewardship_5
			}
			root = {
				OR = {
					has_trait = education_stewardship_1
					has_trait = education_stewardship_2
					has_trait = education_stewardship_3
					has_trait = education_stewardship_4
					has_trait = education_stewardship_5
				}
			}
		}
		AND = {
			OR = {
				has_trait = education_martial_1
				has_trait = education_martial_2
				has_trait = education_martial_3
				has_trait = education_martial_4
				has_trait = education_martial_5
			}
			root = {
				OR = {
					has_trait = education_martial_1
					has_trait = education_martial_2
					has_trait = education_martial_3
					has_trait = education_martial_4
					has_trait = education_martial_5
				}
			}
		}
		AND = {
			OR = {
				has_trait = education_learning_1
				has_trait = education_learning_2
				has_trait = education_learning_3
				has_trait = education_learning_4
				has_trait = education_learning_5
			}
			root = {
				OR = {
					has_trait = education_learning_1
					has_trait = education_learning_2
					has_trait = education_learning_3
					has_trait = education_learning_4
					has_trait = education_learning_5
				}
			}
		}
		##### Start More Lifestyles Submod Modifications
		AND = {
			OR = {
				has_trait = education_nht_prowess_1
				has_trait = education_nht_prowess_2
				has_trait = education_nht_prowess_3
				has_trait = education_nht_prowess_4
				has_trait = education_nht_prowess_5
			}
			root = {
				OR = {
					has_trait = education_nht_prowess_1
					has_trait = education_nht_prowess_2
					has_trait = education_nht_prowess_3
					has_trait = education_nht_prowess_4
					has_trait = education_nht_prowess_5
				}
			}
		}
		AND = {
			OR = {
				has_trait = education_nht_leadership_1
				has_trait = education_nht_leadership_2
				has_trait = education_nht_leadership_3
				has_trait = education_nht_leadership_4
				has_trait = education_nht_leadership_5
			}
			root = {
				OR = {
					has_trait = education_nht_leadership_1
					has_trait = education_nht_leadership_2
					has_trait = education_nht_leadership_3
					has_trait = education_nht_leadership_4
					has_trait = education_nht_leadership_5
				}
			}
		}
	}
}

has_same_education_trait_as_root_trigger = {
	OR = {
		AND = {
			has_trait = education_diplomacy
			root = { has_trait = education_diplomacy }
		}
		AND = {
			has_trait = education_martial
			root = { has_trait = education_martial }
		}
		AND = {
			has_trait = education_stewardship
			root = { has_trait = education_stewardship }
		}
		AND = {
			has_trait = education_intrigue
			root = { has_trait = education_intrigue }
		}
		AND = {
			has_trait = education_learning
			root = { has_trait = education_learning }
		}
		##### Start More Lifestyles Submod Modifications
		AND = {
			has_trait = education_nht_prowess
			root = { has_trait = education_nht_prowess }
		}
		AND = {
			has_trait = education_nht_leadership
			root = { has_trait = education_nht_leadership }
		}		
	}
}

has_same_education_trait_as_character_trigger = {
	OR = {
		AND = {
			has_trait = education_diplomacy
			$CHARACTER$ = { has_trait = education_diplomacy }
		}
		AND = {
			has_trait = education_martial
			$CHARACTER$ = { has_trait = education_martial }
		}
		AND = {
			has_trait = education_stewardship
			$CHARACTER$ = { has_trait = education_stewardship }
		}
		AND = {
			has_trait = education_intrigue
			$CHARACTER$ = { has_trait = education_intrigue }
		}
		AND = {
			has_trait = education_learning
			$CHARACTER$ = { has_trait = education_learning }
		}
		##### Start More Lifestyles Submod Modifications
		AND = {
			has_trait = education_nht_prowess
			$CHARACTER$ = { has_trait = education_nht_prowess }
		}
		AND = {
			has_trait = education_nht_leadership
			$CHARACTER$ = { has_trait = education_nht_leadership }
		}
	}
}

has_ward_guardian_education_match_compare_character_trigger = {
	OR = {
		AND = {
			has_focus = education_diplomacy
			scope:compare_character = {
				OR = {
					has_trait = education_diplomacy_1
					has_trait = education_diplomacy_2
					has_trait = education_diplomacy_3
					has_trait = education_diplomacy_4
				}
			}
		}
		AND = {
			has_focus = education_martial
			scope:compare_character = {
				OR = {
					has_trait = education_martial_1
					has_trait = education_martial_2
					has_trait = education_martial_3
					has_trait = education_martial_4
				}
			}
		}
		AND = {
			has_focus = education_stewardship
			scope:compare_character = {
				OR = {
					has_trait = education_stewardship_1
					has_trait = education_stewardship_2
					has_trait = education_stewardship_3
					has_trait = education_stewardship_4
				}
			}
		}
		AND = {
			has_focus = education_intrigue
			scope:compare_character = {
				OR = {
					has_trait = education_intrigue_1
					has_trait = education_intrigue_2
					has_trait = education_intrigue_3
					has_trait = education_intrigue_4
				}
			}
		}
		AND = {
			has_focus = education_learning
			scope:compare_character = {
				OR = {
					has_trait = education_learning_1
					has_trait = education_learning_2
					has_trait = education_learning_3
					has_trait = education_learning_4
				}
			}
		}
		##### Start More Lifestyles Submod Modifications
		AND = {
			has_focus = education_nht_leadership
			scope:compare_character = {
				OR = {
					has_trait = education_nht_leadership_1
					has_trait = education_nht_leadership_2
					has_trait = education_nht_leadership_3
					has_trait = education_nht_leadership_4
				}
			}
		}
		AND = {
			has_focus = education_nht_prowess
			scope:compare_character = {
				OR = {
					has_trait = education_nht_prowess_1
					has_trait = education_nht_prowess_2
					has_trait = education_nht_prowess_3
					has_trait = education_nht_prowess_4
				}
			}
		}		
	}
}

#####################################################################
# 03_bp2_scripted_triggers
#####################################################################

has_education_rank_1_trigger = {
	OR = {
		has_trait_rank = {
			trait = education_diplomacy
			rank = 1
		}
		has_trait_rank = {
			trait = education_martial
			rank = 1
		}
		has_trait_rank = {
			trait = education_stewardship
			rank = 1
		}
		has_trait_rank = {
			trait = education_intrigue
			rank = 1
		}
		has_trait_rank = {
			trait = education_learning
			rank = 1
		}
		has_trait_rank = {
			trait = education_nht_prowess
			rank = 1
		}
		has_trait_rank = {
			trait = education_nht_leadership
			rank = 1
		}
	}
}

has_education_rank_2_trigger = {
	OR = {
		has_trait_rank = {
			trait = education_diplomacy
			rank = 2
		}
		has_trait_rank = {
			trait = education_martial
			rank = 2
		}
		has_trait_rank = {
			trait = education_stewardship
			rank = 2
		}
		has_trait_rank = {
			trait = education_intrigue
			rank = 2
		}
		has_trait_rank = {
			trait = education_learning
			rank = 2
		}
		has_trait_rank = {
			trait = education_nht_prowess
			rank = 2
		}
		has_trait_rank = {
			trait = education_nht_leadership
			rank = 2
		}
	}
}

has_education_rank_3_trigger = {
	OR = {
		has_trait_rank = {
			trait = education_diplomacy
			rank = 3
		}
		has_trait_rank = {
			trait = education_martial
			rank = 3
		}
		has_trait_rank = {
			trait = education_stewardship
			rank = 3
		}
		has_trait_rank = {
			trait = education_intrigue
			rank = 3
		}
		has_trait_rank = {
			trait = education_learning
			rank = 3
		}
		has_trait_rank = {
			trait = education_nht_prowess
			rank = 3
		}
		has_trait_rank = {
			trait = education_nht_leadership
			rank = 3
		}
	}
}

has_education_rank_4_trigger = {
	OR = {
		has_trait_rank = {
			trait = education_diplomacy
			rank = 4
		}
		has_trait_rank = {
			trait = education_martial
			rank = 4
		}
		has_trait_rank = {
			trait = education_stewardship
			rank = 4
		}
		has_trait_rank = {
			trait = education_intrigue
			rank = 4
		}
		has_trait_rank = {
			trait = education_learning
			rank = 4
		}
		has_trait_rank = {
			trait = education_nht_prowess
			rank = 4
		}
		has_trait_rank = {
			trait = education_nht_leadership
			rank = 4
		}
	}
}

#####################################################################
# 04_ep2_tournament_triggers
#####################################################################

would_want_to_attend_tournament = {
	trigger_if = {
		limit = { is_landed = yes }
		OR = {
			government_has_flag = government_is_feudal
			government_has_flag = government_is_clan
		}
	}
	trigger_else = { is_clergy = no }
	OR = {
		is_ai = no
		has_trait = tourney_participant
		has_trait = education_martial
		has_trait = education_martial_prowess
		has_trait = education_nht_prowess
		has_trait = gregarious
		has_trait = brave
		prowess >= decent_skill_rating
		has_court_position = champion_court_position
		is_knight = yes
		number_of_commander_traits >= 1
		any_relation = { this = scope:inviter }
	}
}

#####################################################################
# 05_bp2_triggers
#####################################################################

is_available_adult_education_teacher = {
	is_available_healthy_ai_adult = yes
	age > 35
	OR = {
		has_trait = education_diplomacy_4
		has_trait = education_martial_4
		has_trait = education_stewardship_4
		has_trait = education_intrigue_4
		has_trait = education_learning_4
		has_trait = education_diplomacy_5
		has_trait = education_martial_5
		has_trait = education_stewardship_5
		has_trait = education_intrigue_5
		has_trait = education_learning_5
		has_trait = education_nht_prowess_4
		has_trait = education_nht_leadership_4
		has_trait = education_nht_prowess_5
		has_trait = education_nht_leadership_5		
	}
	OR = {
		diplomacy >= 12
		martial >= 12
		stewardship >= 12
		intrigue >= 12
		learning >= 12
	}
	trigger_if = {
		limit = {
			scope:location.county.faith = { has_doctrine = doctrine_gender_female_dominated }
		}
		is_female = yes
	}
	trigger_else_if = {
		limit = {
			scope:location.county.faith = { has_doctrine = doctrine_gender_male_dominated }
		}
		is_female = no
	}
	trigger_else = {
		always = yes
	}
}