﻿# More Personality Depth — AI personality archetype overrides
#
# Overrides 4 vanilla scripted_triggers that drive the "Economical archetype"
# line in the personality tooltip (Warlike / Cautious / Builder / Pious Builder).
#
# Vanilla checks `has_trait = X` for each personality trait — L1 (Quick-Tempered)
# counts the same as L3 (Furious) for archetype categorization. We replace those
# checks with `has_trait_xp = { trait = X value >= 50 }` so only L2+ traits push
# the character into a specific archetype.
#
# The AI-value path (e.g. `ai_boldness >= 50` AND `ai_greed >= 50`) is unchanged —
# L1 traits still contribute to AI values via their reduced (50%) modifiers, so
# characters can still reach archetypes via the gradual route. We're just removing
# the "shortcut" that L1 traits used to provide.
#
# Non-MPD traits (irritable, improvident, profligate, lunatic, conqueror,
# greatest_of_khans) remain plain `has_trait` checks — those traits don't have
# XP tracks.
#
# Source: common/scripted_triggers/00_ai_value_triggers.txt
# Keep in sync with vanilla — these are last-loaded-wins overrides.

# ─── ai_has_warlike_personality ───
ai_has_warlike_personality = {
	OR = {
		AND = {
			has_trait = despoiler_of_byzantium
			any_held_title = {
				tier <= tier_empire
				OR = {
					empire = title:e_byzantium
					empire = title:e_latin_empire
				}
			}
		}
		vassal_contract_has_flag = admin_ai_is_warlike
		house ?= {
			has_house_modifier = unity_house_organized_for_war_modifier
		}
		AND = {
			any_character_struggle = {
				trigger_if = {
					limit = { is_struggle_type = persian_struggle }
					is_struggle_phase = struggle_persia_phase_unrest
				}
				trigger_else = { always = no }
			}
			has_trait = fp3_struggle_detractor
		}
		AND = {
			government_has_flag = government_is_nomadic
			ai_has_cautious_personality = no
			economical_ai_guts_trigger = no
		}
		AND = {
			ai_boldness > 0
			ai_greed >= 0

			OR = {
				# MPD: L2+ required for trait shortcut into Warlike
				has_trait_xp = { trait = wrathful value >= 50 }
				has_trait_xp = { trait = impatient value >= 50 }
				has_trait_xp = { trait = sadistic value >= 50 }
				has_trait_xp = { trait = ambitious value >= 50 }
				has_trait_xp = { trait = vengeful value >= 50 }
				has_trait_xp = { trait = zealous value >= 50 }
				has_trait = irritable  # non-MPD coping trait, unchanged
				AND = {
					ai_boldness >= 50
					ai_greed >= 50
				}
				AND = {
					ai_boldness >= 25
					ai_greed >= 100
				}
				AND = {
					ai_boldness >= 100
					ai_greed >= 25
				}
				government_has_flag = government_is_tribal
				culture = { has_cultural_pillar = ethos_bellicose }
			}

			NOR = {
				ai_compassion >= 75
				# MPD: only L2+ counter-traits block the Warlike archetype
				has_trait_xp = { trait = compassionate value >= 50 }
				has_trait_xp = { trait = craven value >= 50 }
				has_trait_xp = { trait = calm value >= 50 }
				faith = { has_doctrine_parameter = pacifist }
				culture = { has_cultural_parameter = reduced_cost_for_conversion_to_pacifist_faith }
				house ?= {
					has_house_modifier = unity_house_focused_on_economy_modifier
				}
				vassal_contract_has_flag = admin_ai_is_builder
			}
		}
		has_variable = imperial_expedition_charged
		AND = {
			OR = {
				is_tributary = yes
				is_independent_ruler = no
			}
			overlord ?= { has_realm_law_flag = subjects_appear_more_warlike }
		}
		house ?= { has_house_aspiration_parameter = aspect_of_destruction }
	}
	NOR = {
		has_variable = conqueror
		house ?= {
			OR = {
				has_house_aspiration_parameter = aspect_of_creation
				has_house_aspiration_parameter = aspect_of_serenity
				has_house_aspiration_parameter = aspect_of_trickery
			}
		}
	}
}

# ─── ai_has_cautious_personality ───
ai_has_cautious_personality = {
	ai_boldness <= 0

	OR = {
		# MPD: L2+ required for trait shortcut into Cautious
		has_trait_xp = { trait = paranoid value >= 50 }
		has_trait_xp = { trait = craven value >= 50 }
		AND = {
			ai_boldness <= -25
			OR = {
				has_trait_xp = { trait = patient value >= 50 }
				has_trait_xp = { trait = calm value >= 50 }
				has_trait_xp = { trait = content value >= 50 }
				culture = { has_cultural_pillar = ethos_stoic }
				culture = { has_cultural_tradition = tradition_stalwart_defenders }
			}
		}
	}
	NOR = {
		# MPD: only L2+ fickle blocks Cautious
		has_trait_xp = { trait = fickle value >= 50 }
		has_trait = lunatic  # non-MPD trait, unchanged
		house ?= {
			OR = {
				has_house_modifier = unity_house_organized_for_war_modifier
				has_house_modifier = unity_house_focused_on_economy_modifier
				has_house_aspiration_parameter = aspect_of_creation
				has_house_aspiration_parameter = aspect_of_serenity
				has_house_aspiration_parameter = aspect_of_trickery
			}
		}
		AND = {
			any_character_struggle = {
				trigger_if = {
					limit = { is_struggle_type = persian_struggle }
					is_struggle_phase = struggle_persia_phase_unrest
				}
				trigger_else = { always = no }
			}
			has_trait = fp3_struggle_detractor
		}
		vassal_contract_has_flag = admin_ai_is_warlike
		vassal_contract_has_flag = admin_ai_is_builder
		has_variable = conqueror
	}
}

# ─── pious_ai_builder_trigger (used by ai_has_pious_builder_personality) ───
pious_ai_builder_trigger = {
	ai_zeal > 0
	ai_energy > 0
	OR = {
		has_focus = learning_theology_focus
		# MPD: L2+ required for trait shortcut into Pious Builder
		has_trait_xp = { trait = zealous value >= 50 }
		has_trait_xp = { trait = forgiving value >= 50 }
		has_trait = improvident  # non-MPD focus trait, unchanged
		has_trait_xp = { trait = humble value >= 50 }
		has_trait_xp = { trait = patient value >= 50 }
		has_trait_xp = { trait = diligent value >= 50 }
		has_trait_xp = { trait = generous value >= 50 }
		has_character_modifier = the_temple_builder_modifier
		government_has_flag = government_is_mandala
	}
	num_virtuous_traits >= 1
	num_sinful_traits = 0
	NAND = {
		# MPD: only L2+ counter-traits invalidate Pious Builder
		has_trait_xp = { trait = cynical value >= 50 }
		has_trait_xp = { trait = greedy value >= 50 }
		house = {
			has_house_modifier = unity_house_organized_for_war_modifier
		}
	}
}

# ─── economical_ai_guts_trigger (used by ai_has_economical_boom_personality) ───
economical_ai_guts_trigger = {
	ai_boldness > 0
	OR = {
		has_focus = stewardship_domain_focus
		# MPD: L2+ required for trait shortcut into Builder
		has_trait_xp = { trait = calm value >= 50 }
		has_trait_xp = { trait = patient value >= 50 }
		has_trait_xp = { trait = diligent value >= 50 }
		has_trait_xp = { trait = generous value >= 50 }
		has_trait_xp = { trait = stubborn value >= 50 }
		has_trait = profligate  # non-MPD focus trait, unchanged
		has_character_modifier = the_city_builder_modifier
		has_character_modifier = the_castle_builder_modifier
	}
	NAND = {
		# MPD: only L2+ counter-traits invalidate Builder
		has_trait_xp = { trait = greedy value >= 50 }
		has_trait_xp = { trait = impatient value >= 50 }
		house ?= {
			has_house_modifier = unity_house_organized_for_war_modifier
		}
	}
}
