﻿# scope = character
# Checks if the character is allowed to use regula units
regula_maa_allowed_trigger = {
	OR = {
		# Option 1: Landless adventurer with the unlock Famuli MAA flag
		has_realm_law_flag = unlocks_famuli_maa

		# Option 2: Regula religion and has the cultural female warriors flag
		AND = {
			is_regula_trigger = yes

			OR = {
				# In the event there is a culture divergence and the old
				# culture has female warriors, followers of the old culture should
				# still use female units even if the magister has moved away, as long as it is possible to
				culture_has_regula_female_warriors_trigger = yes
				# In the event the magistar has updated the official culture and we are directly affected, we should go along.
				AND = {
					is_regula_devoted_trigger = yes
					global_var:magister_character = {
						culture_has_regula_female_warriors_trigger = yes
					}
				}
			}
		}
	}
	NAND = {
		is_ai = yes
		has_game_rule = regula_famuli_maa_usage_never_famuli
	}
}

# Should we use Famuli artwork for basic MAA?
should_use_famuli_maa_graphics = {
	OR = {
		culture_has_regula_female_warriors_trigger = yes
		has_unit_gfx = famuli_unit_gfx
	}
}

# scope = character
# Checks if the character is allowed to use elite regula units
regula_maa_magister_only_trigger = {
	is_canon_regula_trigger = yes
	has_trait = magister_trait_group
	culture_has_regula_female_warriors_trigger = yes
}

# scope = character
# Checks if we are not allowed to use regula units and have
# to use default units - or - we have the option to use both because of cultural divergence from the orthodox
regula_maa_not_allowed_trigger = {
	# Holy Orders are always allowed some female units at minimum
	NOT = { is_regula_holy_order_character_trigger = yes }
	# No realm law/flag that enables Regula MAA
	NOT = { has_realm_law_flag = unlocks_famuli_maa }
	OR = {
		# No Magister
		NOT = { magister_alive_trigger = yes }
		# Not regula
		NOT = { is_regula_trigger = yes }
		# No Tenet in our personal culture letting us use the normal troops
		NOT = {
			culture_has_regula_female_warriors_trigger = yes
		}
	}
}

# scope = character
# Checks if we have any regional MAA that we could change for Famuli variants
regula_has_regional_maa_that_could_be_famuli = {
	# Sanity check
	regula_maa_allowed_trigger = yes

	# Check if we have any basic MAA regiments
	any_maa_regiment = {
		count > 0
		OR = {
			# Skirmishers
			is_maa_type = goedendag
			is_maa_type = horn_warrior
			is_maa_type = shomer
			is_maa_type = guinea_warrior
			is_maa_type = abudrar
			is_maa_type = guanch_vaulter
			is_maa_type = jomsviking_pirates
			is_maa_type = akritai
			is_maa_type = maa_bandits

			# Archers
			is_maa_type = longbowmen
			is_maa_type = metsanvartija
			is_maa_type = archers_of_the_nile
			is_maa_type = paiks
			is_maa_type = bush_hunter
			is_maa_type = vigmen
			is_maa_type = ballistrai
			is_maa_type = maa_poachers

			# Light Cavalry
			is_maa_type = chasseur
			is_maa_type = caballero
			is_maa_type = hobelar
			is_maa_type = mulaththamun
			is_maa_type = hussar
			is_maa_type = sahel_horsemen
			is_maa_type = tawashi
			is_maa_type = ayrudzi
			is_maa_type = maa_marauders

			# Pikemen
			is_maa_type = landsknecht
			is_maa_type = picchieri
			is_maa_type = schiltron
			is_maa_type = zupin_warrior
			is_maa_type = bondi
			is_maa_type = skoutatoi
			is_maa_type = maa_thieves

			# Heavy Infantry
			is_maa_type = huscarl
			is_maa_type = praetorian
			is_maa_type = ayyar
			is_maa_type = mubarizun
			is_maa_type = druzhina
			is_maa_type = garudas
			is_maa_type = khandayat
			is_maa_type = mountaineer
			is_maa_type = sarawit
			is_maa_type = zbrojnosh
			is_maa_type = teutonic_knights
			is_maa_type = varangian_veterans
			is_maa_type = varangian_guards

			# Heavy Cavalry
			is_maa_type = gendarme
			is_maa_type = monaspa
			is_maa_type = cataphract
			is_maa_type = tarkhan
			is_maa_type = conrois

			# Crossbowmen
			is_maa_type = crossbowmen

			# Misc
			is_maa_type = horse_archers
			is_maa_type = asawira
			is_maa_type = camel_rider
		}
	}
}

# scope = character
# Checks if we have any Famuli MAA
regula_has_famuli_maa = {
	any_maa_regiment = {
		count > 0
		regula_is_famuli_maa = yes
	}
}

# scope = regiment
# Checks if this MAA is a Famuli MAA
regula_is_famuli_maa = {
	OR = {
		# Basic Famuli MAA
		is_maa_type = sacerdos
		is_maa_type = infiltrator

		# Special/Elite
		is_maa_type = virgo
		is_maa_type = accolade_maa_virgo

		# Regional
		is_maa_type = valkyrie
		is_maa_type = gallowlasses
		is_maa_type = phylanx
		is_maa_type = toxotai
		is_maa_type = azraq
	}
}