﻿
#EK NOTE: no d_sunni
###TRIGGER LIST
#opposing_ai_values_trigger		- Checks if one character has a positive value and another character has a negative value for the same ai value.

#Needs TARGET and the name of the VALUE
opposing_ai_values_trigger = {
	OR = {
		AND = {
			ai_$VALUE$ < 0
			$TARGET$ = { ai_$VALUE$ > 0 }
		}
		AND = {
			ai_$VALUE$ > 0
			$TARGET$ = { ai_$VALUE$ < 0 }
		}
	}	
}

ai_has_warlike_personality = {
	OR = {
		#EK DISABLED: No Byzantium
		#AND = {
		#	has_trait = despoiler_of_byzantium
		#	any_held_title = {
		#		OR = {
		#			empire = title:e_byzantium
		#			empire = title:e_latin_empire
		#		}
		#	}
		#}
		vassal_contract_has_flag = admin_ai_is_warlike # Admin vassals with the "Frontier" administration consider it their job to expand
		AND = { # The unity decision "Organize House Members for War" forces AI house members to adopt this stance
			exists = house
			house = {
				has_house_modifier = unity_house_organized_for_war_modifier
			}
		}
		AND = { # They are Detractors during the FP3 Struggle in the Unrest Phase
			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 = { # Nomads are not 'unpredictable', they are Warlike instead
			government_has_flag = government_is_nomadic
			ai_has_cautious_personality = no
			economical_ai_guts_trigger = no
		}
		AND = {
			ai_boldness > 0
			ai_greed >= 0
			
			OR = {
				has_trait = wrathful
				has_trait = impatient
				has_trait = sadistic
				has_trait = ambitious
				has_trait = vengeful
				has_trait = zealous
				has_trait = irritable
				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
				has_trait = compassionate
				has_trait = craven
				has_trait = calm
				faith = { has_doctrine_parameter = pacifist_opinion_active }
				culture = { has_cultural_parameter = reduced_cost_for_conversion_to_pacifist_faith }
				AND = {
					exists = house
					house = {
						has_house_modifier = unity_house_focused_on_economy_modifier
					}
				}
				vassal_contract_has_flag = admin_ai_is_builder
			}
		}
		# Or we're on the warpath.
		has_variable = imperial_expedition_charged
	}
	ai_has_conqueror_personality = no
}

ai_has_cautious_personality = {
	ai_boldness <= 0
	
	OR = {
		has_trait = paranoid
		has_trait = craven
		AND = {
			ai_boldness <= -25
			OR = {
				has_trait = patient
				has_trait = calm
				has_trait = content
				culture = { has_cultural_pillar = ethos_stoic }
				culture = { has_cultural_tradition = tradition_stalwart_defenders }
			}
		}
	}
	NOR = {
		has_trait = fickle
		has_trait = lunatic
		AND = {
			exists = house
			house = {
				OR = {
					has_house_modifier = unity_house_organized_for_war_modifier
					has_house_modifier = unity_house_focused_on_economy_modifier
				}
			}
		}
		AND = { # They are Detractors during the FP3 Struggle in the Unrest Phase
			any_character_struggle = {
				is_struggle_type = persian_struggle
				is_struggle_phase = struggle_persia_phase_unrest
			}
			has_trait = fp3_struggle_detractor
		}
		vassal_contract_has_flag = admin_ai_is_warlike
		vassal_contract_has_flag = admin_ai_is_builder
	}
	ai_has_conqueror_personality = no
}

ai_has_economical_boom_personality = {
	OR = {
		vassal_contract_has_flag = admin_ai_is_builder # Admin vassals with the "Civilian" administration consider it their job to improve the economy
		AND = { # The unity decision "Encourage House to Improve the Economy" forces AI house members to adopt this stance
			exists = house
			house = {
				has_house_modifier = unity_house_focused_on_economy_modifier
			}
		}
		AND = {
			economical_ai_guts_trigger = yes
			ai_has_warlike_personality = no
		}
	}
	ai_has_conqueror_personality = no
}

economical_ai_guts_trigger = {
	ai_boldness > 0
	OR = {
		has_focus = stewardship_domain_focus # Only this focus, which is 33% of all stewardship focused characters in the world
		has_trait = calm
		has_trait = patient
		has_trait = diligent
		has_trait = generous
		has_trait = stubborn
		has_trait = profligate
		has_trait = improvident
		has_character_modifier = the_city_builder_modifier
		has_character_modifier = the_castle_builder_modifier
		has_character_modifier = the_temple_builder_modifier
	}
	NAND = {
		has_trait = greedy
		has_trait = impatient
		AND = {
			exists = house
			house = {
				has_house_modifier = unity_house_organized_for_war_modifier
			}
		}
	}
}

ai_wants_low_unity = {
	government_has_flag = government_is_clan
	# To actively decrease Unity, the AI needs the following personality
	OR = {
		AND = {
			OR = {
				has_trait_malicious_trigger = yes
				has_trait_dominant_trigger = yes
			}
			has_trait_submissive_trigger = no
			has_trait_benevolent_trigger = no
		}
		ai_has_warlike_personality = yes
		ai_has_conqueror_personality = yes
		has_character_flag = agenda_towards_escalation
	}
}

ai_wants_high_unity = {
	government_has_flag = government_is_clan
	# We'll make sure that the AI only wants to actively increase Unity if they have a matching personality
	OR = {
		AND = {
			OR = {
				has_trait_benevolent_trigger = yes
				has_trait_submissive_trigger = yes
			}
			has_trait_malicious_trigger = no
		}
		ai_has_economical_boom_personality = yes
		#EK DISABLED
		#AND = {
		#	NOT = { has_trait = fp3_struggle_detractor }
		#	# House is the most recent Caliphs house
		#	exists = struggle:persian_struggle
		#	trigger_if = {
		#		limit = { exists = title:d_sunni.holder }
		#		house = title:d_sunni.holder.house
		#	}
		#	trigger_else = { house = title:d_sunni.previous_holder.house }
		#}
		#EK DISABLED END
		has_character_flag = agenda_towards_deescalation
	}
	
	# And to make sure the AI doesn't want to increase and decrease Unity at the same time
	ai_wants_low_unity = no
}

ai_has_conqueror_personality = {
	OR = {
		has_trait = conqueror
		#EK DISABLED: no great khans
		#has_trait = greatest_of_khans
		#has_character_modifier = the_great_khan_modifier
		any_owned_story = {
			story_type = story_conqueror
		}
	}
}

ai_should_get_conqueror_bonuses = {
	AND = {
		OR = {
			has_game_rule = default_conquerors_bonuses
			has_game_rule = extreme_conquerors_bonuses
			has_game_rule = random_conquerors_bonuses
			has_game_rule = reduced_random_conquerors_bonuses
		}
		ai_has_conqueror_personality = yes
	}
}

ai_should_get_extreme_conqueror_bonuses = {
	AND = {
		has_character_modifier = ai_extreme_conqueror_modifier
		ai_has_conqueror_personality = yes
	}
}

ai_should_focus_on_building_in_their_capital = {
	is_landed = yes
	highest_held_title_tier >= tier_county
	ai_has_conqueror_personality = no
	NOT = { government_has_flag = government_is_nomadic }
	exists = capital_county
	exists = culture
	OR = {
		capital_county.title_province.free_building_slots > 0
		AND = {
			culture = { has_innovation = innovation_ledger }
			capital_county.title_province.combined_building_level <= 4
		}
		AND = {
			culture = { has_innovation = innovation_baliffs }
			capital_county.title_province.combined_building_level <= 6
		}
		AND = {
			culture = { has_innovation = innovation_guilds }
			capital_county.title_province.combined_building_level <= 9
		}
		AND = {
			culture = { has_innovation = innovation_cranes }
			capital_county.title_province.combined_building_level <= 12
		}
	}
}
