﻿advcm_fp1_check = {
	scope = culture
	
	is_valid = {
		has_fp1_dlc_trigger = yes
	}
}

advcm_fp3_check = {
	scope = character

	saved_scopes = { inno_flag }
	
	is_valid = {
		has_fp3_dlc_trigger = yes
		OR = {
			scope:inno_flag = flag:_fritware
			scope:inno_flag = flag:_mural_sextant
		}
	}
}

advcm_innovation_selected_culture = {
	scope = character
	
	saved_scopes = { innovation_culture }
	
	effect = {
		set_variable = {
			name = selected_culture
			value = scope:innovation_culture 
		}
	}
}

advcm_open_marriage = {
	scope = character
	
	saved_scopes = { target }
	
	effect = {
		open_interaction_window = {
			interaction = advcm_marriage_interaction
			actor = root
			recipient = scope:target
		}
	}
}

advcm_open_vassal_contract = {
	scope = character
	
	saved_scopes = { target }
	
	effect = {
		open_interaction_window = {
			interaction = advcm_modify_vassal_contract_interaction
			recipient = scope:target.liege
			actor = scope:target
		}
	}
}

advcm_traits_lists_builder = {
	
	effect = {
		every_trait_in_category = {
			category = fame
			add_to_global_variable_list = { name = advcm_fame_traits_list target = this }
		}

		every_trait_in_category = {
			category = health
			add_to_global_variable_list = { name = advcm_health_traits_list target = this }
		}

		every_trait_in_category = {
			category = lifestyle
			add_to_global_variable_list = { name = advcm_lifestyle_traits_list target = this }
		}

		every_trait_in_category = {
			category = commander
			add_to_global_variable_list = { name = advcm_commander_traits_list target = this }
		}

		every_trait_in_category = {
			category = winter_commander
			add_to_global_variable_list = { name = advcm_commander_traits_list target = this }
		}

		every_trait_in_category = {
			category = childhood
			add_to_global_variable_list = { name = advcm_other_traits_list target = this }
		}

		trait:confider ?= {
			add_to_global_variable_list = { name = advcm_other_traits_list target = this }
		}

		trait:beauty_bad_1 ?= {
			add_to_global_variable_list = { name = advcm_other_traits_list target = this }
		}

		trait:beauty_bad_2 ?= {
			add_to_global_variable_list = { name = advcm_other_traits_list target = this }
		}
		
		trait:beauty_bad_3 ?= {
			add_to_global_variable_list = { name = advcm_other_traits_list target = this }
		}

		trait:beauty_good_1 ?= {
			add_to_global_variable_list = { name = advcm_other_traits_list target = this }
		}

		trait:beauty_good_2 ?= {
			add_to_global_variable_list = { name = advcm_other_traits_list target = this }
		}

		trait:beauty_good_3 ?= {
			add_to_global_variable_list = { name = advcm_other_traits_list target = this }
		}

		trait:intellect_bad_1 ?= {
			add_to_global_variable_list = { name = advcm_other_traits_list target = this }
		}

		trait:intellect_bad_2 ?= {
			add_to_global_variable_list = { name = advcm_other_traits_list target = this }
		}

		trait:intellect_bad_3 ?= {
			add_to_global_variable_list = { name = advcm_other_traits_list target = this }
		}

		trait:intellect_good_1 ?= {
			add_to_global_variable_list = { name = advcm_other_traits_list target = this }
		}

		trait:intellect_good_2 ?= {
			add_to_global_variable_list = { name = advcm_other_traits_list target = this }
		}

		trait:intellect_good_3 ?= {
			add_to_global_variable_list = { name = advcm_other_traits_list target = this }
		}

		trait:physique_bad_1 ?= {
			add_to_global_variable_list = { name = advcm_other_traits_list target = this }
		}

		trait:physique_bad_2 ?= {
			add_to_global_variable_list = { name = advcm_other_traits_list target = this }
		}

		trait:physique_bad_3 ?= {
			add_to_global_variable_list = { name = advcm_other_traits_list target = this }
		}

		trait:physique_good_1 ?= {
			add_to_global_variable_list = { name = advcm_other_traits_list target = this }
		}

		trait:physique_good_2 ?= {
			add_to_global_variable_list = { name = advcm_other_traits_list target = this }
		}

		trait:physique_good_3 ?= {
			add_to_global_variable_list = { name = advcm_other_traits_list target = this }
		}

		trait:pure_blooded ?= {
			add_to_global_variable_list = { name = advcm_other_traits_list target = this }
		}

		trait:fecund ?= {
			add_to_global_variable_list = { name = advcm_other_traits_list target = this }
		}

		trait:strong ?= {
			add_to_global_variable_list = { name = advcm_other_traits_list target = this }
		}

		trait:shrewd ?= {
			add_to_global_variable_list = { name = advcm_other_traits_list target = this }
		}

		trait:clubfooted ?= {
			add_to_global_variable_list = { name = advcm_other_traits_list target = this }
		}

		trait:hunchbacked ?= {
			add_to_global_variable_list = { name = advcm_other_traits_list target = this }
		}

		trait:lisping ?= {
			add_to_global_variable_list = { name = advcm_other_traits_list target = this }
		}

		trait:stuttering ?= {
			add_to_global_variable_list = { name = advcm_other_traits_list target = this }
		}

		trait:dwarf ?= {
			add_to_global_variable_list = { name = advcm_other_traits_list target = this }
		}

		trait:giant ?= {
			add_to_global_variable_list = { name = advcm_other_traits_list target = this }
		}

		trait:inbred ?= {
			add_to_global_variable_list = { name = advcm_other_traits_list target = this }
		}


		trait:weak ?= {
			add_to_global_variable_list = { name = advcm_other_traits_list target = this }
		}

		trait:dull ?= {
			add_to_global_variable_list = { name = advcm_other_traits_list target = this }
		}

		trait:impotent ?= {
			add_to_global_variable_list = { name = advcm_other_traits_list target = this }
		}

		trait:spindly ?= {
			add_to_global_variable_list = { name = advcm_other_traits_list target = this }
		}

		trait:scaly ?= {
			add_to_global_variable_list = { name = advcm_other_traits_list target = this }
		}

		trait:albino ?= {
			add_to_global_variable_list = { name = advcm_other_traits_list target = this }
		}

		trait:wheezing ?= {
			add_to_global_variable_list = { name = advcm_other_traits_list target = this }
		}

		trait:bleeder ?= {
			add_to_global_variable_list = { name = advcm_other_traits_list target = this }
		}

		trait:infertile ?= {
			add_to_global_variable_list = { name = advcm_other_traits_list target = this }
		}

		trait:education_martial_prowess_1 ?= {
			add_to_global_variable_list = { name = advcm_other_traits_list target = this }
		}

		trait:education_martial_prowess_2 ?= {
			add_to_global_variable_list = { name = advcm_other_traits_list target = this }
		}

		trait:education_martial_prowess_3 ?= {
			add_to_global_variable_list = { name = advcm_other_traits_list target = this }
		}

		trait:education_martial_prowess_4 ?= {
			add_to_global_variable_list = { name = advcm_other_traits_list target = this }
		}

		every_trait_in_category = {
			category = court_type
			add_to_global_variable_list = { name = advcm_other_traits_list target = this }
		}

		trait:education_republican_knowledge_1 ?= {
			add_to_global_variable_list = { name = advcm_other_traits_list target = this }
		}

		trait:education_republican_knowledge_2 ?= {
			add_to_global_variable_list = { name = advcm_other_traits_list target = this }
		}

		trait:education_republican_knowledge_3 ?= {
			add_to_global_variable_list = { name = advcm_other_traits_list target = this }
		}

		trait:education_republican_knowledge_4 ?= {
			add_to_global_variable_list = { name = advcm_other_traits_list target = this }
		}

		trait:tourney_participant ?= {
			add_to_global_variable_list = { name = advcm_other_traits_list target = this }
		}

		trait:lifestyle_traveler ?= {
			add_to_global_variable_list = { name = advcm_other_traits_list target = this }
		}

		trait:fp3_struggle_detractor ?= {
			add_to_global_variable_list = { name = advcm_other_traits_list target = this }
		}

		trait:fp3_struggle_supporter ?= {
			add_to_global_variable_list = { name = advcm_other_traits_list target = this }
		}

		every_trait = {
			limit = {
				NOT = {
					any_trait_in_category = {
						category = education
						this = prev
					}

					any_trait_in_category = {
						category = personality
						this = prev
					}

					any_trait_in_category = {
						category = health
						this = prev
					}

					any_trait_in_category = {
						category = fame
						this = prev
					}

					any_trait_in_category = {
						category = winter_commander
						this = prev
					}

					any_trait_in_category = {
						category = commander
						this = prev
					}

					any_trait_in_category = {
						category = lifestyle
						this = prev
					}
				}
			}
			add_to_global_variable_list = { name = advcm_other_traits_list target = this }
		}
		
	}
}

advcm_trait_slow_comp_check = {
   
    is_valid = {
		exists = global_var:advcm_other_traits_list
		exists = global_var:advcm_commander_traits_list
		exists = global_var:advcm_lifestyle_traits_list
		exists = global_var:advcm_health_traits_list
		exists = global_var:advcm_fame_traits_list
	}

}

advcm_trait_list_cleanup = {
	effect = {
		clear_global_variable_list = advcm_other_traits_list
		clear_global_variable_list = advcm_commander_traits_list
		clear_global_variable_list = advcm_lifestyle_traits_list
		clear_global_variable_list = advcm_health_traits_list
		clear_global_variable_list = advcm_fame_traits_list
	}
}

advcm_add_trait = {
	scope = character
	
	saved_scopes = { trait }
	
	effect = {
		every_in_global_list = {
			variable = marked_characters

			hidden_effect = {
				add_trait = scope:trait
			}
		}
	}
}

advcm_remove_trait = {
	scope = character
	
	saved_scopes = { trait }
	
	effect = {
		every_in_global_list = {
			variable = marked_characters

			hidden_effect = {
				remove_trait = scope:trait
			}
		}
	}
}

advcm_set_trait_track = {
	scope = character
	
	saved_scopes = { trait_track }
	
	effect = {
	
		set_variable = { name = advcm_trait_track value = scope:trait_track }
		
	}
}

advcm_add_trait_xp = {
	scope = character

	saved_scopes = { trait advcm_trait_track }

	effect = {
		every_in_global_list = {
			variable = marked_characters

			hidden_effect = {

				if = {
					limit = {
						
						root.var:advcm_trait_track = flag:none
					}


					add_trait_xp = {
						trait = scope:trait
						value = 10
					}
				}

				else_if = {
					limit = {
						root.var:advcm_trait_track = flag:hunter
					}

					add_trait_xp = {
						trait = scope:trait
						track = hunter
						value = 10
					}
				}

				else_if = {
					limit = {
						root.var:advcm_trait_track = flag:falconer
					}

					add_trait_xp = {
						trait = scope:trait
						track = falconer
						value = 10
					}
				}

				else_if = {
					limit = {
						root.var:advcm_trait_track = flag:foot 
					}

					add_trait_xp = {
						trait = scope:trait
						track = foot
						value = 10
					}
				}

				else_if = {
					limit = {
						root.var:advcm_trait_track = flag:bow 
					}

					add_trait_xp = {
						trait = scope:trait
						track = bow
						value = 10
					}
				}

				else_if = {
					limit = {
						root.var:advcm_trait_track = flag:horse 
					}

					add_trait_xp = {
						trait = scope:trait
						track = horse
						value = 10
					}
				}

				else_if = {
					limit = {
						root.var:advcm_trait_track = flag:wit 
					}

					add_trait_xp = {
						trait = scope:trait
						track = wit
						value = 10
					}
				}

				else_if = {
					limit = {
						root.var:advcm_trait_track = flag:travel
					}

					add_trait_xp = {
						trait = scope:trait
						track = travel
						value = 10
					}
				}

				else_if = {
					limit = {
						root.var:advcm_trait_track = flag:danger
					}

					add_trait_xp = {
						trait = scope:trait
						track = danger
						value = 10
					}
				}

				
			}
		}
	}
}

advcm_sexuality_heterosexual = {
	scope = character
	
	effect = {
		every_living_character = {
			limit = { has_character_flag = marked_for_edit }
			
			hidden_effect = {
				set_sexuality = heterosexual
			}
		}
	}
}

advcm_sexuality_homosexual = {
	scope = character
	
	effect = {
		every_living_character = {
			limit = { has_character_flag = marked_for_edit }
			
			hidden_effect = {
				set_sexuality = homosexual
			}
		}
	}
}

advcm_sexuality_bisexual = {
	scope = character
	
	effect = {
		every_living_character = {
			limit = { has_character_flag = marked_for_edit }
			
			hidden_effect = {
				set_sexuality = bisexual
			}
		}
	}
}

advcm_sexuality_asexual = {
	scope = character
	
	effect = {
		every_living_character = {
			limit = { has_character_flag = marked_for_edit }
			
			hidden_effect = {
				set_sexuality = asexual
			}
		}
	}
}

advcm_clear_all_marks = {
	scope = character
	
	effect = {
		every_living_character = {
			limit = { has_character_flag = marked_for_edit }
			
			hidden_effect = {
				remove_character_flag = marked_for_edit
				remove_list_global_variable = { name = marked_characters target = this}
			}
		}
	}
}

advcm_tradition_dlc_check = {
	
	scope = character
	
	saved_scopes = { tradition }
	
	is_valid = {
		trigger_if = {
			limit = { scope:tradition = culture_tradition:tradition_fp1_coastal_warriors }
			has_fp1_dlc_trigger = yes
		}
		trigger_else_if = {
			limit = { scope:tradition = culture_tradition:tradition_fp1_performative_honour }
			
			has_fp1_dlc_trigger = yes
		}
		trigger_else_if = {
			limit = { scope:tradition = culture_tradition:tradition_fp1_northern_stories }
			
			has_fp1_dlc_trigger = yes
		}
		trigger_else_if = {
			limit = { scope:tradition = culture_tradition:tradition_fp1_trials_by_combat }
			
			has_fp1_dlc_trigger = yes
		}
		trigger_else_if = {
			limit = { scope:tradition = culture_tradition:tradition_fp1_the_right_to_prove }
			
			has_fp1_dlc_trigger = yes
		}
		trigger_else_if = {
			limit = { scope:tradition = culture_tradition:tradition_fp2_state_ransoming }
			
			has_fp2_dlc_trigger = yes
		}
		trigger_else_if = {
			limit = { scope:tradition = culture_tradition:tradition_fp2_strategy_gamers }
			
			has_fp2_dlc_trigger = yes
		}
		trigger_else_if = {
			limit = { scope:tradition = culture_tradition:tradition_fp2_malleable_subjects }
			
			has_fp2_dlc_trigger = yes
		}
		trigger_else_if = {
			limit = { scope:tradition = culture_tradition:tradition_fp2_ritualised_friendship }
			
			has_fp2_dlc_trigger = yes
		}
		trigger_else_if = {
			limit = { scope:tradition = culture_tradition:tradition_ep2_avid_falconers }
			
			has_dlc_feature = tours_and_tournaments
		}
		trigger_else_if = {
			limit = { scope:tradition = culture_tradition:tradition_fp3_frontier_warriors }
			
			has_fp3_dlc_trigger = yes
		}
		trigger_else_if = {
			limit = { scope:tradition = culture_tradition:tradition_fp3_irrigation_experts }
			
			has_fp3_dlc_trigger = yes
		}
		trigger_else_if = {
			limit = { scope:tradition = culture_tradition:tradition_fp3_beacon_of_learning }
			
			has_fp3_dlc_trigger = yes
		}
		trigger_else_if = {
			limit = { scope:tradition = culture_tradition:tradition_fp3_enlightened_magnates }
			
			has_fp3_dlc_trigger = yes
		}
		trigger_else_if = {
			limit = { scope:tradition = culture_tradition:tradition_fp3_jirga }
			
			has_fp3_dlc_trigger = yes
		}
		trigger_else_if = {
			limit = { scope:tradition = culture_tradition:tradition_fp3_pragmatic_creed }
			
			has_fp3_dlc_trigger = yes
		}
		trigger_else_if = {
			limit = { scope:tradition = culture_tradition:tradition_fp3_fierce_independence }
			
			has_fp3_dlc_trigger = yes
		}
		trigger_else_if = {
			limit = { scope:tradition = culture_tradition:tradition_debug }
			
			always = no
		}
		trigger_else = {
			
			always = yes
		}
	}
}

advcm_tradition_category_list_maker = {
	scope = character
	
	saved_scopes = { tradition }
	
	effect = {
		if = {
			limit = {
				scope:tradition = {
					has_tradition_category = realm
				}
			}

			add_to_global_variable_list = { name = advcm_realm_tradition_list target = scope:tradition}
		}
		else_if = {
			limit = {
				scope:tradition = {
					has_tradition_category = combat
				}
			}

			add_to_global_variable_list = { name = advcm_combat_tradition_list target = scope:tradition}
		}
		else_if = {
			limit = {
				scope:tradition = {
					has_tradition_category = societal
				}
			}

			add_to_global_variable_list = { name = advcm_societal_tradition_list target = scope:tradition}
		}
		else_if = {
			limit = {
				scope:tradition = {
					has_tradition_category = ritual
				}
			}

			add_to_global_variable_list = { name = advcm_ritual_tradition_list target = scope:tradition}
		}
		else_if = {
			limit = {
				scope:tradition = {
					has_tradition_category = regional
				}
			}

			add_to_global_variable_list = { name = advcm_regional_tradition_list target = scope:tradition}
		}
	}
}

advcm_add_tradition = {
	scope = character
	
	saved_scopes = { tradition }
	
	effect = {
		var:selected_culture = {
			add_culture_tradition = scope:tradition
		}
		
	}
}

advcm_remove_tradition = {
	scope = character
	
	saved_scopes = { tradition }
	
	effect = {
		var:selected_culture = {
			remove_culture_tradition = scope:tradition
		}
		
	}
}

advcm_culture_has_tradition = {
	
	scope = character
	
	saved_scopes = { tradition }
	
	is_valid = {
		var:selected_culture = { has_cultural_tradition = scope:tradition }
	}
}

advcm_add_legitimacy = {
	scope = character

	effect = {
		add_legitimacy = 100
	}
}
	
advcm_remove_legitimacy = {
	scope = character

	effect = {
		add_legitimacy = -100
	}
}