﻿#EK NOTE: removed mongols, age equivalent
#####################################################################
# EFFECT LIST
#####################################################################
# !!! Remember to add all new effects with a short description here !!!

#remove_adultery_variables_effect

#####################################################################
# EFFECTS
#####################################################################

#Saves a scope value with the "strongest" ai value (not exact values but based on the low/medium/high values in 00_ai_values.txt)
strongest_ai_value_effect = {
	random_list = {
		1 = { #Positive boldness
			trigger = { ai_boldness > 0 }
			modifier = {
				ai_boldness >= low_positive_boldness
				factor = 100
			}
			modifier = {
				ai_boldness >= medium_positive_boldness
				factor = 100
			}
			modifier = {
				ai_boldness >= high_positive_boldness
				factor = 100
			}
			set_variable = {
				name = strongest_ai_value
				value = flag:positive_boldness
			}
		}
		1 = { #Positive compassion
			trigger = { ai_compassion > 0 }
			modifier = {
				ai_compassion >= low_positive_compassion
				factor = 100
			}
			modifier = {
				ai_compassion >= medium_positive_compassion
				factor = 100
			}
			modifier = {
				ai_compassion >= high_positive_compassion
				factor = 100
			}
			set_variable = {
				name = strongest_ai_value
				value = flag:positive_compassion
			}	
		}
		1 = { #Positive greed
			trigger = { ai_greed > 0 }
			modifier = {
				ai_greed >= low_positive_greed
				factor = 100
			}
			modifier = {
				ai_greed >= medium_positive_greed
				factor = 100
			}
			modifier = {
				ai_greed >= high_positive_greed
				factor = 100
			}
			set_variable = {
				name = strongest_ai_value
				value = flag:positive_greed
			}
		}
		1 = { #Positive energy
			trigger = { ai_energy > 0 }
			modifier = {
				ai_energy >= low_positive_energy
				factor = 100
			}
			modifier = {
				ai_energy >= medium_positive_energy
				factor = 100
			}
			modifier = {
				ai_energy >= high_positive_energy
				factor = 100
			}
			set_variable = {
				name = strongest_ai_value
				value = flag:positive_energy
			}
		}
		1 = { #Positive honor
			trigger = { ai_honor > 0 }
			modifier = {
				ai_honor >= low_positive_honor
				factor = 100
			}
			modifier = {
				ai_honor >= medium_positive_honor
				factor = 100
			}
			modifier = {
				ai_honor >= high_positive_honor
				factor = 100
			}
			set_variable = {
				name = strongest_ai_value
				value = flag:positive_honor
			}
		}
		1 = { #Positive rationality
			trigger = { ai_rationality > 0 }
			modifier = {
				ai_rationality >= low_positive_rationality
				factor = 100
			}
			modifier = {
				ai_rationality >= medium_positive_rationality
				factor = 100
			}
			modifier = {
				ai_rationality >= high_positive_rationality
				factor = 100
			}
			set_variable = {
				name = strongest_ai_value
				value = flag:positive_rationality
			}
		}
		1 = { #Positive vengefulness
			trigger = { ai_vengefulness > 0 }
			modifier = {
				ai_vengefulness >= low_positive_vengefulness
				factor = 100
			}
			modifier = {
				ai_vengefulness >= medium_positive_vengefulness
				factor = 100
			}
			modifier = {
				ai_vengefulness >= high_positive_vengefulness
				factor = 100
			}
			set_variable = {
				name = strongest_ai_value
				value = flag:positive_vengefulness
			}
		}
		1 = { #Positive zeal
			trigger = { ai_zeal > 0 }
			modifier = {
				ai_zeal >= low_positive_zeal
				factor = 100
			}
			modifier = {
				ai_zeal >= medium_positive_zeal
				factor = 100
			}
			modifier = {
				ai_zeal >= high_positive_zeal
				factor = 100
			}
			set_variable = {
				name = strongest_ai_value
				value = flag:positive_zeal
			}
		}
		1 = { #negative boldness
			trigger = { ai_boldness < 0 }
			modifier = {
				ai_boldness <= low_negative_boldness
				factor = 100
			}
			modifier = {
				ai_boldness <= medium_negative_boldness
				factor = 100
			}
			modifier = {
				ai_boldness <= high_negative_boldness
				factor = 100
			}
			set_variable = {
				name = strongest_ai_value
				value = flag:negative_boldness
			}
		}
		1 = { #negative compassion
			trigger = { ai_compassion < 0 }
			modifier = {
				ai_compassion <= low_negative_compassion
				factor = 100
			}
			modifier = {
				ai_compassion <= medium_negative_compassion
				factor = 100
			}
			modifier = {
				ai_compassion <= high_negative_compassion
				factor = 100
			}
			set_variable = {
				name = strongest_ai_value
				value = flag:negative_compassion
			}	
		}
		1 = { #negative greed
			trigger = { ai_greed < 0 }
			modifier = {
				ai_greed <= low_negative_greed
				factor = 100
			}
			modifier = {
				ai_greed <= medium_negative_greed
				factor = 100
			}
			modifier = {
				ai_greed <= high_negative_greed
				factor = 100
			}
			set_variable = {
				name = strongest_ai_value
				value = flag:negative_greed
			}
		}
		1 = { #negative energy
			trigger = { ai_energy < 0 }
			modifier = {
				ai_energy <= low_negative_energy
				factor = 100
			}
			modifier = {
				ai_energy <= medium_negative_energy
				factor = 100
			}
			modifier = {
				ai_energy <= high_negative_energy
				factor = 100
			}
			set_variable = {
				name = strongest_ai_value
				value = flag:negative_energy
			}
		}
		1 = { #negative honor
			trigger = { ai_honor < 0 }
			modifier = {
				ai_honor <= low_negative_honor
				factor = 100
			}
			modifier = {
				ai_honor <= medium_negative_honor
				factor = 100
			}
			modifier = {
				ai_honor <= high_negative_honor
				factor = 100
			}
			set_variable = {
				name = strongest_ai_value
				value = flag:negative_honor
			}
		}
		1 = { #negative rationality
			trigger = { ai_rationality < 0 }
			modifier = {
				ai_rationality <= low_negative_rationality
				factor = 100
			}
			modifier = {
				ai_rationality <= medium_negative_rationality
				factor = 100
			}
			modifier = {
				ai_rationality <= high_negative_rationality
				factor = 100
			}
			set_variable = {
				name = strongest_ai_value
				value = flag:negative_rationality
			}
		}
		1 = { #negative vengefulness
			trigger = { ai_vengefulness < 0 }
			modifier = {
				ai_vengefulness <= low_negative_vengefulness
				factor = 100
			}
			modifier = {
				ai_vengefulness <= medium_negative_vengefulness
				factor = 100
			}
			modifier = {
				ai_vengefulness <= high_negative_vengefulness
				factor = 100
			}
			set_variable = {
				name = strongest_ai_value
				value = flag:negative_vengefulness
			}
		}
		1 = { #negative zeal
			trigger = { ai_zeal < 0 }
			modifier = {
				ai_zeal <= low_negative_zeal
				factor = 100
			}
			modifier = {
				ai_zeal <= medium_negative_zeal
				factor = 100
			}
			modifier = {
				ai_zeal <= high_negative_zeal
				factor = 100
			}
			set_variable = {
				name = strongest_ai_value
				value = flag:negative_zeal
			}
		}
	}
}

ai_chance_to_become_conqueror_effect = {
	if = {
		limit = {
			NOT = { has_game_rule = no_conquerors_frequency }
			ai_has_cautious_personality = no
			is_independent_ruler = yes
			is_landed = yes
			is_adult = yes
			ek_human_age_equivalent <= 60 #EK EDIT
			NOT = { is_incapable = yes }
			ai_boldness >= 0
			ai_greed >= 0
			gold >= 50
			is_at_war = no
			highest_held_title_tier >= tier_duchy
			domain_size >= 3
			NOR = {
				any_ally = {
					is_ai = no # Would be annoying as conquerors don't help their allies
				}
				#EK EDIT: no mongols
				#has_title = title:e_mongol_empire
				has_character_flag = used_to_be_conqueror
			}
			any_neighboring_and_across_water_top_liege_realm_owner = {
				root = {
					has_any_cb_on = prev
					current_military_strength >= prev.current_military_strength
				}
			}
			trigger_if = {
				limit = {
					OR = {
						has_game_rule = strong_default_conquerors_frequency
						has_game_rule = strong_few_conquerors_frequency
						has_game_rule = strong_very_few_conquerors_frequency
						has_game_rule = strong_many_conquerors_frequency
					}
				}
				sub_realm_size >= 15
				domain_size >= 4
				current_military_strength >= 3000
				gold >= 500
				ek_human_age_equivalent <= 35
			}
			OR = {
				AND = {
					is_ai = no
					NOT = { has_game_rule = no_conquerors_bonuses }
				}
				AND = {
					exists = global_var:active_conquerors 
					global_var:active_conquerors < 12
				}
				# EK ADDITION: since we've commented out the vanilla conquerors, the active_conquerors var never exists. so, let's also allow the ai to become conqueror if there are none around
				NOT = { exists = global_var:active_conquerors }
				# EK ADDITION END
			}
		}
		random = {
			chance = {
				value = 0.25
				add = {
					value = primary_title.tier
					divide = 12
				}
				if = {
					limit = {
						martial >= 10
					}
					add = {
						value = martial
						divide = 5
					}
				}
				if = {
					limit = {
						intrigue >= 10
					}
					add = {
						value = intrigue
						divide = 10
					}
				}
				if = {
					limit = {
						diplomacy >= 10
					}
					add = {
						value = diplomacy
						divide = 10
					}
				}
				if = {
					limit = {
						has_trait = brave
					}
					add = 0.25
				}
				if = {
					limit = {
						has_trait = ambitious
					}
					add = 0.5
				}
				if = {
					limit = {
						has_trait = compassionate
					}
					add = -0.25
				}
				if = {
					limit = {
						has_trait = shy
					}
					add = -0.25
				}
				if = {
					limit = {
						has_trait = lazy
					}
					add = -0.25
				}
				if = {
					limit = {
						has_trait = content
					}
					add = -1
				}
				if = {
					limit = {
						has_trait = craven
					}
					add = -1
				}
				if = {
					limit = {
						ai_has_warlike_personality = yes
					}
					add = 0.25
				}
				if = {
					limit = {
						OR = {
							government_has_flag = government_is_tribal
							government_has_flag = government_is_clan
						}
					}
					add = 1.5
				}
				if = {
					limit = {
						government_has_flag = government_is_nomadic
					}
					add = 2
				}
				if = {
					limit = {
						government_has_flag = government_is_nomadic
						highest_held_title_tier >= tier_kingdom
						domicile.herd >= 10000
					}
					add = 2
				}
				if = {
					limit = {
						gold >= massive_gold_value
					}
					add = 0.25
				}
				if = {
					limit = {
						war_chest_gold >= war_chest_gold_maximum
					}
					add = 0.25
				}
				if = {
					limit = {
						culture = { has_cultural_pillar = ethos_bellicose }
					}
					add = 0.25
				}
				if = {
					limit = {
						prestige_level >= 3
					}
					add = 0.25
				}
				if = {
					limit = {
						faith = { has_doctrine = tenet_warmonger }
					}
					add = 0.25
				}
				if = {
					limit = {
						culture = { has_cultural_parameter = reduced_cost_for_conversion_to_pacifist_faith }
					}
					add = -0.25
				}
				if = {
					limit = {
						faith = { has_doctrine_parameter = pacifist_opinion_active }
					}
					add = -0.25
				}
				if = {
					limit = {
						ai_has_economical_boom_personality = yes
					}
					add = -0.25
				}
				if = {
					limit = {
						can_use_conquest_cbs_trigger = yes
					}
					add = 2
				}
				if = {
					limit = {
						can_use_conquest_cbs_trigger = no
					}
					add = -0.5
				}
				if = {
					limit = {
						can_use_conquest_cbs_trigger = yes
						primary_title.tier >= tier_kingdom
						prestige_level >= 2
						gold >= major_gold_value
					}
					add = 4
				}
				if = { # Caliphs/caliph-holders should often become conquerors
					limit = {
						faith = { has_doctrine = doctrine_temporal_head }
						OR = {
							this = faith.religious_head
							any_vassal_or_below = {
								this = faith.religious_head
							}
						}
					}
					add = 5
				}
				if = {
					limit = {
						primary_title = { has_title_law = princely_elective_succession_law }
					}
					add = -0.25
				}
				if = {
					limit = {
						has_trait = education_martial_5
					}
					add = 1
				}
				if = {
					limit = {
						is_ai = yes
						OR = {
							has_character_modifier = bp2_destined_modifier
							has_character_modifier = bp2_tool_of_fate_modifier
						}
					}
					add = 2
				}
				if = {
					limit = {
						is_ai = yes
						OR = {
							has_character_modifier = a_cultures_great_defender_modifier
							has_character_modifier = inspired_defenders_modifier
							has_character_modifier = uniter_and_conqueror_modifier
						}
					}
					add = 2
				}
				if = {
					limit = {
						is_ai = no
					}
					add = -2.5
				}
				if = {
					limit = {
						is_ai = no
						has_game_rule = hard_difficulty
					}
					add = -7.5
				}
				else_if = {
					limit = {
						is_ai = no
						has_game_rule = very_hard_difficulty
					}
					add = -50
				}
				if = {
					limit = {
						is_ai = yes
						AND = {
							exists = global_var:active_conquerors 
							global_var:active_conquerors >= 3
						}
					}
					add = -1
				}
				if = {
					limit = {
						is_ai = yes
						AND = {
							exists = global_var:active_conquerors 
							global_var:active_conquerors >= 5
						}
					}
					add = -3.5
				}
				if = {
					limit = {
						is_ai = yes
						AND = {
							exists = global_var:active_conquerors 
							global_var:active_conquerors >= 7
						}
					}
					add = -2
				}
				if = {
					limit = {
						is_ai = yes
						AND = {
							exists = global_var:active_conquerors 
							global_var:active_conquerors >= 10
						}
					}
					add = -2
				}
				if = {
					limit = {
						is_ai = no
						OR = {
							has_character_modifier = bp2_destined_modifier
							has_character_modifier = bp2_tool_of_fate_modifier
						}
					}
					multiply = 5
				}
				if = {
					limit = {
						is_ai = no
						OR = {
							has_character_modifier = a_cultures_great_defender_modifier
							has_character_modifier = inspired_defenders_modifier
							has_character_modifier = uniter_and_conqueror_modifier
						}
					}
					multiply = 5
				}
				if = {
					limit = {
						OR = {
							has_game_rule = few_conquerors_frequency
							has_game_rule = strong_few_conquerors_frequency
						}
					}
					multiply = 0.5
				}
				if = {
					limit = {
						OR = {
							has_game_rule = very_few_conquerors_frequency
							has_game_rule = strong_very_few_conquerors_frequency
						}
					}
					multiply = 0.1
				}
				if = {
					limit = {
						is_ai = yes
						has_game_rule = strong_many_conquerors_frequency
					}
					add = 0.5
				}
				if = {
					limit = {
						is_ai = yes
						OR = {
							has_game_rule = many_conquerors_frequency
							has_game_rule = strong_many_conquerors_frequency
						}
					}
					add = 0.5
					multiply = 2
				}
			}
			if = {
				limit = {
					is_ai = no
				}
				trigger_event = {
					id = conqueror.0001
					days = 10
				}
			}
			else = {
				trigger_event = conqueror.0001
			}
		}
	}
}
