﻿
##################################################
# General Triggers

eligible_for_fp1_dynasty_legacies_trigger = {
	has_fp1_dlc_trigger = yes
	OR = {
		# Technically, we could hardscript this to North Germanics/Normans/Estonians, but eh.
		culture = { has_innovation = innovation_longboats }
		# Converts should also get a chance to get in on the fun.
		religion = religion:germanic_religion
	}
}

fp1_can_raise_stele_trigger = {
	OR = {
		culture = { has_cultural_parameter = has_access_to_runestones }
		has_character_modifier = embraced_local_traditions_modifier
	}
	culture = {
		NOT = { has_cultural_era_or_later = culture_era_high_medieval }
	}
}

fp1_can_raise_stele_title_scope_trigger = {
	culture = {
		has_cultural_pillar = heritage_north_germanic
		NOT = { has_cultural_era_or_later = culture_era_high_medieval }
	}
}

fp1_county_has_stele_trigger = {
	OR = {
		has_county_modifier = fp1_stele_ancestors_strong
		has_county_modifier = fp1_stele_ancestors_weak
		has_county_modifier = fp1_stele_conquest_strong
		has_county_modifier = fp1_stele_conquest_weak
		has_county_modifier = fp1_stele_promotion_strong
		has_county_modifier = fp1_stele_promotion_weak
	}
}

fp1_eligible_for_yearly_events_trigger = {
	has_fp1_dlc_trigger = yes
	OR = {
		culture = { has_cultural_pillar = heritage_north_germanic }
		religion = religion:germanic_religion
	}
}

##################################################
# Cultural & Regional Triggers

fp1_is_norse = {
	OR = {
		culture = { has_cultural_pillar = heritage_north_germanic }
		culture = culture:norman
	}
}

fp1_is_norse_tribal = {
	fp1_is_norse = yes
	government_has_flag = government_is_tribal
}

fp1_is_coastal_norse_tribal = {
	# Standard checks.
	fp1_is_norse_tribal = yes
	# Do you have a relevant coastal county somewhere?
	any_sub_realm_county = { is_coastal_county = yes }
}

fp1_is_in_scandinavia = {
	capital_county.title_province = { geographical_region = world_europe_north }
}

fp1_is_in_scandinavian_colonies = {
	capital_county.title_province = {
		OR = {
			geographical_region = world_europe_west_britannia
			geographical_region = dlc_fp1_region_colonial_eastern_europe
		}
	}
}

fp1_is_in_scandinavia_or_colonies = {
	OR = {
		fp1_is_in_scandinavia = yes
		fp1_is_in_scandinavian_colonies = yes
	}
}

fp1_remove_stele_new_holder_trigger = {
	# Is there a rogue stone around?
	$TITLE$ = { exists = var:stele_commissioner }
	# And would the new holder want to tear down the stele?
	$NEW_HOLDER$ = {
		OR = {
			AND = {
				exists = dynasty
				# E.g., because they're a different family and won't maintain it.
				NOT = { dynasty = $PREVIOUS_HOLDER$.dynasty }
			}
			# Or because they're a subject of the runestone, which means it's memorialising their defeat.
			## ... Unless they're a ghost. Damned proctors, I guess.
			AND = {
				exists = $TITLE$.var:stele_container
				exists = $TITLE$.var:stele_scope_type
				# Remember not to compare a character with a title.
				$TITLE$.var:stele_scope_type = flag:character
				this = $TITLE$.var:stele_container
			}
		}
	}
}

is_vaguely_danish_bhakti_trigger = {
	OR = {
		has_culture = culture:danish
		culture = { has_name_list = name_list_danish }
		# We deliberately use the de jure rather than the geographical area to make this at least a *little* more fluid.
		AND = {
			is_playable_character = yes
			capital_county.kingdom = title:k_denmark
		}
	}
}

##################################################
# Varangian Adventure Triggers

fp1_va_eligible_for_scandinavian_troops_trigger = {
	# We only give these to North Germanics. I realise we check this elsewhere, but it makes it a bit easier to hijack the CB for other cultures via modding without weirdness.
	culture = {
		OR = {
			has_cultural_pillar = heritage_north_germanic
			this = culture:estonian
			any_parent_culture_or_above = {
				this = culture:estonian #Estonian
			}
		}
	}
	# Who hold at least one county in the initial de jure of the mainland Norse kingdoms.
	any_sub_realm_county = {
		OR = {
			title_province = { geographical_region = dlc_fp1_region_core_mainland_scandinavia }
			title:k_esthonia = {
				is_de_jure_liege_or_above_target = prev
			}
		}
		culture = scope:attacker.culture
		faith = scope:attacker.faith
	}
}

##################################################
# Illustration Triggers

fp1_should_use_norse_graphics_trigger = {
	culture = { has_building_gfx = norse_building_gfx }
}

fp1_should_use_extra_tribal_graphics_trigger = {
	should_use_tribal_realm_palace_graphics_trigger = yes
}

##################################################
# Shieldmaiden Triggers

suitable_shieldmaiden_gaoler_trigger = {
	#Must be a shieldmaiden.
	has_trait = shieldmaiden
	NOR = {
		#Filter out prisoners that the shieldmaiden would want to see freed.
		has_friendly_relationship_trigger = { CHARACTER = root }
		#And require that they don't hate their liege.
		has_relation_rival = scope:imprisoner
		#Make sure they don't really like root, in which case they'd let the escape slide.
		opinion = {
			target = root
			value >= high_positive_opinion
		}
		#Aaaaand the inverse for actually really hating their host, in which case they don't care about escapees.
		opinion = {
			target = scope:imprisoner
			value <= high_negative_opinion
		}
	}
}

##################################################
# Interaction Triggers

basic_can_have_trial_by_combat_trigger = {
	# This is referenced elsewhere, so we keep it separate in order to allow justification for TbCs outside of interactions.
	culture = { has_cultural_parameter = has_access_to_trials_by_combat }
}

can_have_trial_by_combat_trigger = {
	# First, evaluate culture to trim down our potentials list.
	scope:actor = { basic_can_have_trial_by_combat_trigger = yes }
	scope:recipient = { basic_can_have_trial_by_combat_trigger = yes }
}

eligible_knight_to_champion_trial_by_combat_trigger = {
	is_available_ai = yes
	can_start_single_combat_trigger = yes
}

trial_by_combat_shown_and_not_invalid_trigger = {
	# Scope:actor must be able to fight personally.
	scope:actor = { can_start_single_combat_trigger = yes }
	# Scope:actor cannot challenge someone they have a ceasefire against.
	scope:actor = {
		NOT = { has_truce = scope:recipient }
	}
	# Scope:actor *definitely* cannot challenge someone they're at war with.
	scope:actor = {
		NOT = { is_at_war_with = scope:recipient }
	}
}

trial_by_combat_is_valid_trigger = {
	# Calc some stuff that might invalidate elsewhere before the bout is sorted.
	trial_by_combat_shown_and_not_invalid_trigger = yes
	# Must have an imprisonment reason on the character.
	scope:actor = { has_imprisonment_reason = scope:recipient }
	# Scope:recipient must be able to fight or else have at least *one* designatable champion.
	scope:recipient = {
		trigger_if = {
			limit = {
				OR = {
					can_start_single_combat_eligibility_checks_trigger = no
					NOT = {
						can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = scope:recipient }
					}
				}
			}
			custom_description = {
				text = "fp1_tbc_no_available_champions"
				OR = {
					any_knight = { eligible_knight_to_champion_trial_by_combat_trigger = yes }
					# Can use champion court position too if available
					AND = {
						employs_court_position = champion_court_position
						any_court_position_holder = {
							type = champion_court_position 
							eligible_knight_to_champion_trial_by_combat_trigger = yes #trigger checks for prowess, and while its not mandatory that the champ has a high value, we don't want to trap them into having to use their prowess 3 champ to defend their life
						}
					}
				}
			}
		}
	}
	# Scope:recipient must not be banned from single combat.
	scope:recipient = {
		custom_description = {
			text = "fp1_tbc_recipient_banned_from_combat"
			can_start_single_combat_banned_checks_trigger = no
		}
	}
	# Neither of the characters can be imprisoned.
	scope:actor = { is_imprisoned = no }
	scope:recipient = { is_imprisoned = no }
}

##################################################
# Religious Triggers

gruesome_sacrifices_grand_blot_can_continue_trigger = {
	# Standard checks. Using a more lenient trigger here because we don't want to cancel the blot if you're in events or go on a hunt
	#is_available_at_peace_adult_lenient = yes
	scope:activity ?= {
		has_activity_type = activity_gruesome_festival
	}
}

fp1_valid_norse_faith_for_jomsvikings_trigger = {
	religion = religion:germanic_religion
	has_doctrine_parameter = unreformed
}

fp1_jomsvikings_have_not_existed_trigger = {
	# They've already been destroyed in 1066.
	game_start_date < 1000.1.1
	NOR = {
		# And otherwise can't currently be created.
		exists = global_var:jomsvikings_title
		# Nor should they have been made via decision or event.
		is_target_in_global_variable_list = {
			name = unavailable_unique_decisions
			target = flag:flag_forged_jomvikings
		}
	}
}

fp1_valid_county_for_jomsvikings_trigger = {
	tier = tier_county
	is_coastal_county = yes
	custom_description = {
		text = forge_the_jomsvikings_decision.tt.is_in_correct_region
		title_province = { geographical_region = dlc_fp1_region_non_scandinavian_southern_baltic }
	}
	any_county_province = {
		custom_description = {
			text = forge_the_jomsvikings_decision.tt.empty_castle_or_city
			OR = {
				has_holding = no
				has_holding_type = castle_holding
				has_holding_type = city_holding
			}
		}
	}
}

##################################################
# Achievement Triggers

fp1_achievement_culture_norse_trigger = {
	OR = {
		culture = { has_cultural_pillar = heritage_north_germanic }
		culture = culture:norman
	}
}

fp1_achievement_culture_norse_or_rus_trigger = {
	OR = {
		fp1_achievement_culture_norse_trigger = yes
		culture = culture:russian
	}
}

fp1_achievement_religious_norse_trigger = {
	religion = religion:germanic_religion
}

fp1_achievement_culture_plus_religion_norse_trigger = {
	fp1_achievement_culture_norse_trigger = yes
	fp1_achievement_religious_norse_trigger = yes
}

###################################################
# Jomsviking Triggers
fp1_ruler_eligible_for_jomsviking_coup = {
	# We never want to coup realms with players who might be affected, so just flat-out ban them.
	NOR = {
		is_ai = no
		any_vassal_or_below = { is_ai = no }
		any_liege_or_above = { is_ai = no }
	}
	# And anyone that's close family to/married to a player.
	NOR = {
		any_spouse = { is_ai = no }
		any_close_or_extended_family_member = { is_ai = no }
	}
	# Veto anyone following the unreformed Norse pagan faith.
	NOT = { faith = faith:norse_pagan }
	# For simplicity, exclude wars.
	is_at_war = no
}
