﻿# Determines who can command troops; filters who shows up in the list
# Root is the potential commander
# scope:army_owner is who owns the army to command
can_command_troops = {
	can_be_commander_basic_trigger = { ARMY_OWNER = scope:army_owner }
}

# Determines who can command troops; will still show up in the list, with a breakdown explaining why they can't command
# Root is the potential commander
# scope:army_owner is who owns the army to command
can_command_troops_now = {
	can_be_commander_now_trigger = { ARMY_OWNER = scope:army_owner }
}

# Determines if a barony should be handed to a GHW beneficiary, or instead have a baron generated. If true, goes to a beneficiary
# Root is barony province
# scope:faith is the faith controlling the GHW
ghw_give_barony_to_beneficiary = {
	has_holding_type = castle_holding
}

# Determines if a faith can be created, on top of the piety requirement, and the doctrine requirements
# Also handles reforming a faith, check for the unreformed doctrine to enable those additional checks
# Root is the faith creator
faith_creation = {
	trigger_if = {
		limit = {
			highest_held_title_tier = tier_county
			is_independent_ruler = no
		}
		custom_description = {
			text = "faith_creation_duchy_or_higher"
			highest_held_title_tier >= tier_duchy
		}
	}

	is_adult = yes
	custom_description = {
		text = "character_is_not_real_head"
		NOT = { faith.religious_head = root }
	}
	NOT = { exists = var:has_created_a_faith }



	trigger_if = {
		limit = { 
			has_game_rule = no_heresy_creation
			NOT = { faith = { has_doctrine_parameter = unreformed } }
		}
		custom_description = {
			text = "no_heresy_creation"
			always = no
		}
	}
	
	trigger_if = {
		limit = { 
			has_game_rule = no_pagan_reformation 
			faith = { has_doctrine_parameter = unreformed }
		}
		custom_description = {
			text = "no_pagan_reformation"
			always = no
		}
	}
	
	trigger_if = {
		limit = {
			NOT = { has_game_rule = no_pagan_reformation }
			faith = { has_doctrine_parameter = unreformed }
		}
		NOT = {
			custom_description = {
				text = faith_has_been_reformed
				object = faith
				exists = faith.var:has_been_reformed
			}
		}
		#For tooltip to show properly
		trigger_if = {
			limit = { has_game_rule = pagan_reformation_hs_1 }
			faith = {
				directly_controls_num_holy_sites = {
					CHARACTER = root
					COUNT = 1
				}
			}
		}
		trigger_else_if = {
			limit = { has_game_rule = pagan_reformation_hs_2 }
			faith = {
				directly_controls_num_holy_sites = {
					CHARACTER = root
					COUNT = 2
				}
			}
		}
		trigger_else_if = {
			limit = { has_game_rule = pagan_reformation_hs_3 }
			faith = {
				directly_controls_num_holy_sites = {
					CHARACTER = root
					COUNT = 3
				}
			}
		}
		trigger_else_if = {
			limit = { has_game_rule = pagan_reformation_hs_4 }
			faith = {
				directly_controls_num_holy_sites = {
					CHARACTER = root
					COUNT = 4
				}
			}
		}
		trigger_else_if = {
			limit = { has_game_rule = pagan_reformation_hs_5 }
			faith = {
				directly_controls_num_holy_sites = {
					CHARACTER = root
					COUNT = 5
				}
			}
		}
		trigger_else = { always = yes }
	}
}

# Determines if a character can convert faith via the convert faith UI, on top of the piety requirement
# Root is the faith creator
# scope:new_faith is the faith they want to convert to
faith_conversion = {
	is_adult = yes
	NOT = { faith.religious_head = root }
	is_in_ongoing_great_holy_war = no
}

# Determines if the mother of a character should spread the house to a bastard.
# Requirements: One of both parents should exists. One of both parents should have a house.
# Root is the bastard
should_mother_give_house_to_bastard = {
	should_mother_give_house_to_bastard_trigger = yes
}

# Determines if a character may be appointed as a knight. Checked during automatic knight assignment
# Root is the potential knight
can_be_knight = {
	can_be_knight_trigger = { ARMY_OWNER = root.court_owner }
}

# Determines if a character is allowed to be granted titles by another character
# Root is the target character
# scope:liege is the granter
allowed_to_be_granted_titles_by = {
	can_be_granted_titles_by = { RULER = scope:liege }
}

is_character_allowed_to_be_player = {
	OR = {
		has_game_rule = allow_unplayables
		custom_description = {
			text = "GAME_OVER_CANNOT_PLAY_THEOCRACY"
			NOT = { has_government = theocracy_government }
		}

		custom_description = {
			text = "GAME_OVER_CANNOT_PLAY_REPUBLIC"
			NOT = { has_government = republic_government }
		}
	}
}

# Determines if a secret is considered available for blackmail for use in the GUI (icon/tooltip listing a secret you know as usable for blackmail)
# Scopes the same as a secret_type's is_valid, plus:
# root -> the secret
# scope:target -> the target character
# scope:blackmailer -> the blackmailing character
# The GUI only checks secrets the character is a participant in, that you know of, that have not been spent by you, and that are not revealed
is_secret_available_for_blackmail = {
	is_blackmailable_secret_trigger = {
	 	PARTICIPANT = scope:target
	 	BLACKMAILER = scope:blackmailer
	}
}

# Is this character allowed to join factions in general. See also passes_faction_soft_block.
# Root: Character being evaluated
# scope:target: the target character of the faction
passes_faction_hard_block = {
	custom_description = {
		text = "FACTION_CANT_JOIN_IF_TARGET"
		NOT = { root = scope:target }
	}

	custom_description = {
		text = "FACTION_CANT_JOIN_CREATE_ADULT"
		is_adult = yes
	}
	
	custom_description = {
		text = "FACTION_CANT_JOIN_CREATE_ALLIED"
		trigger_if = {
			limit = { exists = scope:target }
			NOT = { is_allied_to = scope:target }
		}
	}

	custom_description = {
		text = "FACTION_CANT_JOIN_CREATE_HOOK"
		trigger_if = {
			limit = { exists = scope:target }
			scope:target = {
				NOT = { has_strong_hook = root }
			}		
		}
	}

	custom_description = {
		text = "FACTION_CANT_JOIN_CREATE_IMPRISONED"
		is_imprisoned = no		
	}	

	custom_description = {
		text = "FACTION_CANT_JOIN_CREATE_INCAPABLE"
		NOT = { has_trait = incapable }
	}
}

# Is this character allowed to join factions. It is a soft block because factions can set a toggle to ignore this block on the faction type.
# Root: Character being evaluated
passes_faction_soft_block = {
	custom_description = {
		text = "FACTION_SOFT_BLOCK_IS_NOT_COURT_CHAPLAIN"
		NOT = { has_council_position = councillor_court_chaplain }
	}
}

# Is this faction dangerous
# Root = Faction being evaluated
is_dangerous_faction = {
	is_dangerous_faction_trigger = yes
}

# Is the alliance reason still valid
# Root = First character of alliance reason
# scope:second = Second character of alliance reason
is_alliance_valid = {
	OR = {
		any_spouse = {
			this = scope:second
		}
		betrothed = scope:second
		is_parent_of = scope:second
		is_child_of = scope:second
		is_sibling_of = scope:second
		scope:second = {
			has_opinion_modifier = {
				modifier = perk_negotiated_alliance_opinion
				target = root
			}
		}
	}
}

# Can the character designate an heir? Used for the Realm screen
can_designate_heir = {
	can_designate_heir_trigger = yes
}


# Does the character care about having a council position? Used for powerful vassals that have no council position for whether they should get the opinion penalty
cares_about_powerful_vassal_council_position = {
	can_be_councillor_basics_trigger = yes
}

# Does the character approve of succession law changes? Used for the succession law change GUI to designate oppose vs. approve for powerful vassals
approves_of_succession_law_change = {
	opposes_succession_law_change_trigger = no
}

# Does the character get a second chance when rolling a natural death
has_natural_death_second_chance = {
	OR = {
		AND = {
			has_perk = know_thyself_perk
			NOT = { has_character_flag = know_thyself_has_triggered_delay }
		}
		has_character_flag = know_thyself_perk_delay_period
	}
}

# Can the character refund their perks? Scope is the character
can_refund_perks = {
	perk_points_assigned >= 1
	custom_description = {
		text = already_reset_perks
		NOT = {
			has_character_flag = has_refunded_perks
		}
	}
}

# Can the character join the defender in a holy war? Only characters' of the defender's faith are considered. Player characters are not considered.
# Scope is the potential joiner
# scope:attacker is the attacker
# scope:defender is the defender
can_defensively_join_holy_war = {

}

# Can a character be fire from being a councillor
# root = council owner
# scope:councillor = councillor attempting to be fired
can_fire_councillor = {
	custom_description = {
		text = blocked_from_remove_councillor
  		subject = root
  		object = scope:councillor
		OR = {
			NOT = { exists = scope:councillor }
			NOT = {
				scope:councillor = {
					is_blocked_from_being_fired_from_council_trigger = { COURT_OWNER = root }
				}
			}	
		}
	}
}

# Can this character go on raids?
# root: the potential raider
can_raid = {
	#Scripted trigger used so that we can call on the same conditions in script.
	can_raid_trigger = yes
}

# Can this character start a new raid right now? (can_raid will always get checked first)
# root: the potential raider
can_start_raid = {
	is_at_war = no
}

# Can this character cross water (sea, rivers) while on raid?
# root: the potential raider
can_raid_across_water = {
	culture = {
		OR = {
			has_innovation = innovation_longboats
			has_innovation = innovation_african_canoes
		}
	}
}

# Can this character traverse rivers using boats?
# root: the owner of the army
can_traverse_river = {
	culture = {
		OR = {
			has_innovation = innovation_longboats
			has_innovation = innovation_african_canoes
		}
	}
}

#Is this character hard blocked from backing a scheme?
#Scope it to potential backer
is_hard_blocked_from_schemes = {
	is_incapable = yes
}
