﻿
#####################################################################
# 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 = {
	save_scope_as = possible_conqueror
	if = {
		limit = {
			NOT = { has_game_rule = no_conquerors_frequency }
			ai_has_cautious_personality = no
			top_liege = this
			is_landed = yes
			is_adult = yes
			age <= 60
			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
				}
				mpo_has_gok_mongol_empire_trigger = yes
				has_character_flag = used_to_be_conqueror
			}
			any_neighboring_and_across_water_top_liege_realm_owner = {
				scope:possible_conqueror = {
					has_any_cb_on = prev
					current_military_strength >= prev.current_military_strength
				}
			}
			NOT = {
				any_owned_story = {
					story_type = story_take_mandate_of_heaven
				}
			}
			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
				age <= 35
			}
			OR = {
				AND = {
					is_ai = no
					NOT = { has_game_rule = no_conquerors_bonuses }
				}
				AND = {
					exists = global_var:active_conquerors 
					global_var:active_conquerors < 12
				}
			}
		}
		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
			}
		}
	}
}

ai_chance_to_become_mandala_godking_effect = {
	save_scope_as = possible_godking
	if = {
		limit = {
			top_overlord = this
			is_landed = yes
			age <= 50
			NOT = { is_incapable = yes }
			is_ai = yes
			is_at_war = no
			trigger_if = {
				limit = { exists = global_var:active_mandalas }
				global_var:active_mandalas < 5
			}
			any_neighboring_and_across_water_top_liege_realm_owner = {
				OR = {
					current_military_strength < scope:possible_godking.current_military_strength
					any_tributary = {
						in_diplomatic_range = scope:possible_godking
						current_military_strength < scope:possible_godking.current_military_strength
					}
				}	
			}
			#There aren't already 2 active Mandala Capitals in the dejure Kingdom
			less_than_max_amount_of_mandala_capitals_trigger = yes
		}

		random = {
			chance = {
				value = 50
				#If has Mandala Capital or Ruined Capital make into 100
				if = {
					limit = { has_mandala_capital_trigger = yes }
					add = 100
				}
				add = primary_title.tier
				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 = { stewardship >= 10 }
					add = {
						value = stewardship
						divide = 10
					}
				}
				if = {
					limit = { learning >= 10 }
					add = {
						value = learning
						divide = 10
					}
				}
				if = {
					limit = { has_trait = zealous }
					add = 1
				}
				if = {
					limit = { has_trait = pilgrim }
					add = 1
				}
				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 = { has_trait = cynical }
					add = -1
				}
				if = {
					limit = { gold >= massive_gold_value }
					add = 1
				}
				if = {
					limit = {
						house = { has_house_power_parameter = aspect_of_destruction }
						war_chest_gold >= war_chest_gold_maximum
					}
					add = 1
				}
				add = piety_level
				if = {
					limit = {
						OR = {
							has_trait = education_diplomacy_5
							has_trait = education_stewardship_5
							has_trait = education_intrigue_5
							has_trait = education_martial_5
						}
					}
					add = 1
				}
			}
			create_story = story_mandala
		}
	}
}
