
# Can't reference a named value that hasn't been defined yet, so this file is late in the load order
# Feel free to use other files as well, but be careful about load order
# Please remove the example formulas once there's a few real formulas




#GOLD

#Based on income + limits

tiny_gold_value = { #To be used as flavor (paying a stablehand, throwing coins in a wishing well)
	value = monthly_character_income
	multiply = tiny_income_multiplier_value # 1.2 months
	min = tiny_gold_min_value
	max = tiny_gold_max_value

	#Rounds up to the closest number divisible by 5
	divide = 5
	ceiling = yes
	multiply = 5
}

tiny_gold_value_static_max = { #To be used as flavor (paying a stablehand, throwing coins in a wishing well)
	value = monthly_character_income
	multiply = tiny_income_multiplier_value # 1.2 months
	min = tiny_gold_min_value
	max = tiny_gold_max_value_static

	#Rounds up to the closest number divisible by 5
	divide = 5
	ceiling = yes
	multiply = 5
}

minor_gold_value = { #To be used as a run-of-the-mill amount
	value = monthly_character_income
	multiply = minor_income_multiplier_value # 3 months
	min = minor_gold_min_value
	max = minor_gold_max_value

	#Rounds up to the closest number divisible by 5
	divide = 5
	ceiling = yes
	multiply = 5
}

minor_gold_value_static_max = { #To be used as a run-of-the-mill amount
	value = monthly_character_income
	multiply = minor_income_multiplier_value # 3 months
	min = minor_gold_min_value
	max = minor_gold_max_value_static

	#Rounds up to the closest number divisible by 5
	divide = 5
	ceiling = yes
	multiply = 5
}

medium_gold_value = {
	value = monthly_character_income
	multiply = medium_income_multiplier_value # 6 months
	min = medium_gold_min_value
	max = medium_gold_max_value

	#Rounds up to the closest number divisible by 5
	divide = 5
	ceiling = yes
	multiply = 5
}

medium_gold_value_static_max = {
	value = monthly_character_income
	multiply = medium_income_multiplier_value # 6 months
	min = medium_gold_min_value
	max = medium_gold_max_value_static

	#Rounds up to the closest number divisible by 5
	divide = 5
	ceiling = yes
	multiply = 5
}

major_gold_value = {
	value = monthly_character_income
	multiply = major_income_multiplier_value # 12 months, a year
	min = major_gold_min_value
	max = major_gold_max_value

	#Rounds up to the closest number divisible by 5
	divide = 5
	ceiling = yes
	multiply = 5
}

major_gold_value_static_max  = {
	value = monthly_character_income
	multiply = major_income_multiplier_value # 12 months, a year
	min = major_gold_min_value
	max = major_gold_max_value_static

	#Rounds up to the closest number divisible by 5
	divide = 5
	ceiling = yes
	multiply = 5
}

massive_gold_value = { #Highest gold to be used in events, very rare
	value = monthly_character_income
	multiply = massive_income_multiplier_value # 18 months, one and a half years
	min = massive_gold_min_value
	max = massive_gold_max_value

	#Rounds up to the closest number divisible by 5
	divide = 5
	ceiling = yes
	multiply = 5
}

massive_gold_value_static_max  = { #Highest gold to be used in events, very rare
	value = monthly_character_income
	multiply = massive_income_multiplier_value # 18 months, one and a half years
	min = massive_gold_min_value
	max = massive_gold_max_value_static

	#Rounds up to the closest number divisible by 5
	divide = 5
	ceiling = yes
	multiply = 5
}

monumental_gold_value = { # Only to be used in extreme cases, primarily for player-initiated actions.
	value = monthly_character_income
	multiply = monumental_income_multiplier_value # 36 months, three years
	min = monumental_gold_min_value
	max = monumental_gold_max_value

	#Rounds up to the closest number divisible by 5
	divide = 5
	ceiling = yes
	multiply = 5
}

monumental_gold_value_static_max = { # Only to be used in extreme cases, primarily for player-initiated actions.
	value = monthly_character_income
	multiply = monumental_income_multiplier_value # 36 months, three years
	min = monumental_gold_min_value
	max = monumental_gold_max_value_static

	#Rounds up to the closest number divisible by 5
	divide = 5
	ceiling = yes
	multiply = 5
}

## Negative Gold Values 
tiny_gold_value_negative = {
	value = tiny_gold_value 
	multiply = -1
}

minor_gold_value_negative = {
	value = minor_gold_value 
	multiply = -1
}

medium_gold_value_negative = {
	value = medium_gold_value 
	multiply = -1
}

major_gold_value_negative = {
	value = major_gold_value 
	multiply = -1
}

massive_gold_value_negative = {
	value = massive_gold_value 
	multiply = -1
}

monumental_gold_value_negative = {
	value = monumental_gold_value 
	multiply = -1
}
## End negative gold values

tiny_gold_loss = {
	add = tiny_gold_value
	multiply = -1
}

minor_gold_loss = {
	add = minor_gold_value
	multiply = -1
}

medium_gold_loss = {
	add = medium_gold_value
	multiply = -1
}

major_gold_loss = {
	add = major_gold_value
	multiply = -1
}

massive_gold_loss = {
	add = massive_gold_value
	multiply = -1
}

monumental_gold_loss = {
	add = monumental_gold_value
	multiply = -1
}

gift_interaction_cutoff = {
	value = yearly_character_income
	multiply = 3
	min = 10
	max = 300
}

head_of_faith_gold_value = {
	value = monthly_character_income
	multiply = massive_income_multiplier_value
	min = massive_gold_min_value
	max = monumental_gold_max_value
}

minor_treasury_value = {
	value = yearly_character_income
	multiply = 1
}

medium_treasury_value = {
	value = yearly_character_income
	multiply = 3
}

major_treasury_value = {
	value = yearly_character_income
	multiply = 5
}

massive_treasury_value = {
	value = yearly_character_income
	multiply = 7
}

monumental_treasury_value = {
	value = yearly_character_income
	multiply = 10
}

seek_indulgences_major_criminal_trait_value = {
	value = head_of_faith_gold_value
	multiply = 2.5
}
seek_indulgences_medium_criminal_trait_value = {
	value = head_of_faith_gold_value
	multiply = 2.0
}
seek_indulgences_minor_criminal_trait_value = {
	value = head_of_faith_gold_value
	multiply = 1.5
}
seek_indulgences_buy_piety_value = {
	value = head_of_faith_gold_value
	multiply = 1.0
}

holy_order_gold_value = {
	value = monthly_character_income
	multiply = major_income_multiplier_value
	min = medium_gold_max_value
	max = massive_gold_max_value
}

create_duchy_title_value = {
	add = 300
	multiply = {
	    value = 1
		#Legitimacy discounts
		if = {
			limit = { legitimacy_level = 5 }
			subtract = 0.35
		}
		if = {
			limit = { legitimacy_level = 4 }
			subtract = 0.25
		}
		if = {
			limit = { legitimacy_level = 3 }
			subtract = 0.2
		}
		if = {
			limit = { legitimacy_level = 2 }
			subtract = 0.15
		}
	    if = {
	        limit = { has_perk = ducal_conquest_perk } # Ducal Conquest
	        subtract = 0.2
	    }
	    if = {
	        limit = {
	        	culture = { has_innovation = innovation_divine_right } # Divine Right
	        }
	        subtract = 0.2
	    }
	    if = {
	        limit = { government_has_flag = government_is_tribal } # Tribal
	        subtract = 0.5
	    }
	    if = {
	        limit = {
	        	faith = { has_doctrine = tenet_pursuit_of_power } # Pursuit of Power
	        }
	        subtract = 0.5
	    }
	    if = {
	    	limit = {
	    		culture = { has_cultural_pillar = ethos_courtly } # Courtly
	    	}
	    	subtract = 0.15
	    }
	    if = {
	    	limit = {
	    		culture = { has_cultural_tradition = tradition_legalistic } # Legalistic
	    	}
	    	subtract = 0.3
	    }
	    if = {
	    	limit = {
	    		dynasty = { has_dynasty_perk = law_legacy_2 } # Faithful Magistrates
	    	}
	    	subtract = 0.2
	    }
	    min = 0.2 # 80% max discount from defines
	}
}

create_kingdom_title_value = {
	add = 600
	multiply = {
	    value = 1
		#Legitimacy discounts
		if = {
			limit = { legitimacy_level = 5 }
			subtract = 0.35
		}
		if = {
			limit = { legitimacy_level = 4 }
			subtract = 0.25
		}
		if = {
			limit = { legitimacy_level = 3 }
			subtract = 0.2
		}
		if = {
			limit = { legitimacy_level = 2 }
			subtract = 0.15
		}
	    if = {
	        limit = { has_perk = ducal_conquest_perk } # Ducal Conquest
	        subtract = 0.2
	    }
	    if = {
	        limit = {
	        	culture = { has_innovation = innovation_divine_right } # Divine Right
	        }
	        subtract = 0.2
	    }
	    if = {
	        limit = { government_has_flag = government_is_tribal } # Tribal
	        subtract = 0.5
	    }
	    if = {
	        limit = {
	        	faith = { has_doctrine = tenet_pursuit_of_power } # Pursuit of Power
	        }
	        subtract = 0.5
	    }
	    if = {
	    	limit = {
	    		culture = { has_cultural_pillar = ethos_courtly } # Courtly
	    	}
	    	subtract = 0.15
	    }
	    if = {
	    	limit = {
	    		culture = { has_cultural_tradition = tradition_legalistic } # Legalistic
	    	}
	    	subtract = 0.3
	    }
	    if = {
	    	limit = {
	    		dynasty = { has_dynasty_perk = law_legacy_2 } # Faithful Magistrates
	    	}
	    	subtract = 0.2
	    }
	    min = 0.2 # 80% max discount from defines
	}
}

create_empire_title_value = {
	add = 1200
	multiply = {
	    value = 1
		#Legitimacy discounts
		if = {
			limit = { legitimacy_level = 5 }
			subtract = 0.35
		}
		if = {
			limit = { legitimacy_level = 4 }
			subtract = 0.25
		}
		if = {
			limit = { legitimacy_level = 3 }
			subtract = 0.2
		}
		if = {
			limit = { legitimacy_level = 2 }
			subtract = 0.15
		}
	    if = {
	        limit = { has_perk = ducal_conquest_perk } # Ducal Conquest
	        subtract = 0.2
	    }
	    if = {
	        limit = {
	        	culture = { has_innovation = innovation_divine_right } # Divine Right
	        }
	        subtract = 0.2
	    }
	    if = {
	        limit = { government_has_flag = government_is_tribal } # Tribal
	        subtract = 0.5
	    }
	    if = {
	        limit = {
	        	faith = { has_doctrine = tenet_pursuit_of_power } # Pursuit of Power
	        }
	        subtract = 0.5
	    }
	    if = {
	    	limit = {
	    		culture = { has_cultural_pillar = ethos_courtly } # Courtly
	    	}
	    	subtract = 0.15
	    }
	    if = {
	    	limit = {
	    		culture = { has_cultural_tradition = tradition_legalistic } # Legalistic
	    	}
	    	subtract = 0.3
	    }
	    if = {
	    	limit = {
	    		dynasty = { has_dynasty_perk = law_legacy_2 } # Faithful Magistrates
	    	}
	    	subtract = 0.2
	    }
	    min = 0.2 # 80% max discount from defines
	}
}


#DUEL
duel_skill_multiplier_base = { #How many more skill points an extremely skilled character has than the averagely skilled character
	add = extremely_high_skill_rating
	subtract = medium_skill_rating
}

#When used in a duel_value compare modifier, where the duel character has extremely good skill and the target has avarage skill, these modifiers will add...

#10
tiny_positive_duel_skill_multiplier = {
	add = 10
	divide = duel_skill_multiplier_base
}

#25
low_positive_duel_skill_multiplier = {
	add = 25
	divide = duel_skill_multiplier_base
}

#50
medium_positive_duel_skill_multiplier = {
	add = 50
	divide = duel_skill_multiplier_base
}

#75
high_positive_duel_skill_multiplier = {
	add = 75
	divide = duel_skill_multiplier_base
}

#10
tiny_negative_duel_skill_multiplier = {
	add = -10
	divide = duel_skill_multiplier_base
}

#-25
low_negative_duel_skill_multiplier = {
	add = -25
	divide = duel_skill_multiplier_base
}

#-50
medium_negative_duel_skill_multiplier = {
	add = -50
	divide = duel_skill_multiplier_base
}

#-75
high_negative_duel_skill_multiplier = {
	add = -75
	divide = duel_skill_multiplier_base
}


# Referenced by code. Amount of gold gained by the winning side per 1000 men who died in battle (hard casualties)
# Root is the winner main participant
# scope:enemy_battle_owner is the main enemy participant
# scope:combat is the combat itself
battle_winner_gold_gain = {
	value = 0
	
	if = { # Cultural tradition
		limit = {
			culture = {
				has_cultural_parameter = gain_gold_from_battles
			}
		}
		add = 10
	}
	
	if = { # Bonus for legacy
		limit = {
			exists = dynasty
			dynasty = {
				has_dynasty_perk = fp1_pillage_legacy_4
			}
		}
		add = 50
	}

	if = { # Master of Spoils Camp Officer
		limit = {
			employs_court_position = master_of_spoils_camp_officer			
		}
		add = {
			value = court_position:master_of_spoils_camp_officer.aptitude:master_of_spoils_camp_officer
			add = 1
			multiply = 10
		}
	}
}

# Referenced by code. Amount of prestige gained by the winning side per 1000 men who died in battle (hard casualties)
# Root is the winner main participant
# scope:enemy_battle_owner is the main enemy participant
# scope:combat is the combat itself
battle_winner_prestige_gain = {
	value = 75
	
	if = { # Bonus for tribals
		limit = {
			government_has_flag = government_is_tribal
		}
		add = 75
	}
	
	if = { # Leading the troops yourself adds a bit
		limit = {
			OR = {
				scope:combat = {
					combat_attacker = {
						exists = side_commander
						side_commander = {
							this = root
						}
					}
				}
				scope:combat = {
					combat_defender = {
						exists = side_commander
						side_commander = {
							this = root
						}
					}
				}
			}
		}
		add = 40
	}
	
	if = { # Bonus for legacy
		limit = {
			exists = dynasty
			dynasty = {
				has_dynasty_perk = fp1_pillage_legacy_1
			}
		}
		multiply = 2
	}
	
	if = { # Cultural tradition
		limit = {
			culture = {
				has_cultural_parameter = less_prestige_from_battles
			}
		}
		multiply = 0.1
	}

	# Fighting Peasants Rebellion
	if = {
		limit = {
			scope:enemy_battle_owner = { has_variable = rebel_leader_peasants }
		}
		multiply = 0.25 # to test
	}

	if = { # Reduced for LAAMPs
		limit = {
			is_landless_adventurer = yes
		}
		multiply = 0.75
	}

	if = { # Master of Spoils Camp Officer
		limit = {
			employs_court_position = master_of_spoils_camp_officer			
		}
		add = {
			value = court_position:master_of_spoils_camp_officer.aptitude:master_of_spoils_camp_officer
			add = 1
			multiply = 10
		}
	}

	if = { # BP3 - Kings of the Wilds Perk
		limit = {
			has_perk = personal_touch_perk
			landless_inspector_king_of_the_wilds = yes
		}
		multiply = 1.5
	}
}

# Referenced by code. Amount of piety gained by the winning side per 1000 men who died in battle (hard casualties)
# Root is the winner main participant
# scope:enemy_battle_owner is the main enemy participant
# scope:combat is the combat itself
battle_winner_piety_gain = {
	value = 0
	if = {
		limit = {
			faith = {
				faith_hostility_level = {
					target = scope:enemy_battle_owner.faith
					value >= religious_cb_enabled_hostility_level
				}
			}
		}
		value = 35
		
		if = { # Bonus for tribals
			limit = {
				government_has_flag = government_is_tribal
			}
			add = 50
		}
		
		if = { # Leading the troops yourself adds a bit
			limit = {
				OR = {
					scope:combat = {
						combat_attacker = {
							exists = side_commander
							side_commander = {
								this = root
							}
						}
					}
					scope:combat = {
						combat_defender = {
							exists = side_commander
							side_commander = {
								this = root
							}
						}
					}
				}
			}
			add = 20
		}

		if = { # Master of Spoils Camp Officer
			limit = {
				employs_court_position = master_of_spoils_camp_officer			
			}
			add = {
				value = court_position:master_of_spoils_camp_officer.aptitude:master_of_spoils_camp_officer
				add = 1
				multiply = 10
			}
		}
	}

	# Fighting Peasants Rebellion
	if = {
		limit = {
			scope:enemy_battle_owner = { has_variable = rebel_leader_peasants }
		}
		multiply = 0.25 # to test
	}

	if = { # Reduced for LAAMPs
		limit = {
			is_landless_adventurer = yes
		}
		multiply = 0.75
	}
}

# Referenced by code. Chance 0-100 that a randomly created ruler will be female
# Root is the new liege or previous holder of the title
random_ruler_chance_for_female = {
	value = 0
	faith = {
		if = {
			limit = { has_dominant_ruling_gender = dummy_female } # if faith allows females to rule, then add 50% chance
			add = 50
		}
		if = {
			limit = { NOT = { has_dominant_ruling_gender = dummy_male } } # if faith forbids males to rule, then add 50% chance
			add = 50
		}
	}
}

# Referenced by code. Chance 0-100 that a randomly created ruler for a temple will be female
# Root is the new liege or previous holder of the title
random_theocratic_ruler_chance_for_female = {
	value = 0
	faith = {
		if = {
			limit = { has_doctrine = doctrine_clerical_gender_female_only }
			add = 100
		}
		if = {
			limit = { has_doctrine = doctrine_clerical_gender_male_only }
			add = 0
		}
		if = {
			limit = { has_doctrine = doctrine_clerical_gender_either }
			add = 50
		}
	}
}

age_compared_to_root_plus_ten = {
	add = age
	subtract = root.age
	add = 10
}

age_compared_to_root_minus_ten = {
	add = age
	subtract = root.age
	subtract = 10
}

age_compared_to_root_plus_ten_always_adult = {
	add = age
	subtract = root.age
	add = 10
	if = {
		limit = {
			is_male = yes
		}
		min = define:NCharacter|MALE_ADULT_AGE
	}
	if = {
		limit = {
			is_female = yes
		}
		min = define:NCharacter|FEMALE_ADULT_AGE
	}
}

age_compared_to_root_minus_ten_always_adult = {
	add = age
	subtract = root.age
	subtract = 10
	if = {
		limit = {
			is_male = yes
		}
		min = define:NCharacter|MALE_ADULT_AGE
	}
	if = {
		limit = {
			is_female = yes
		}
		min = define:NCharacter|FEMALE_ADULT_AGE
	}
}


#EXAMPLES
example_total_family_age = {
	add = age
	add = father.age
	add = mother.age
	modulo = 10
}

example_fancy_gold = {
	add = gold
	multiply = 3
	divide = 2
	subtract = 500
	max = 2500
	min = 1000
}

example_age_based_gold = {
	add = 1000
	if = {
		limit = { age > 30 }
		divide = 2
	}
	else_if = {
		limit = { age < 20 }
		divide = 4
	}
	else = {
		divide = 8
	}
}

genetic_character_value = {
	value = 0
	#BEAUTY
	if = {
		limit = { has_trait = beauty_bad_1 }
		add = -1
	}
	if = {
		limit = { has_trait = beauty_bad_2 }
		add = -2
	}
	if = {
		limit = { has_trait = beauty_bad_3 }
		add = -3
	}
	if = {
		limit = { has_trait = beauty_good_1 }
		add = 1
	}
	if = {
		limit = { has_trait = beauty_good_2 }
		add = 2
	}
	if = {
		limit = { has_trait = beauty_good_3 }
		add = 3
	}
	#INTELLECT
	if = {
		limit = { has_trait = intellect_bad_1 }
		add = -1
	}
	if = {
		limit = { has_trait = intellect_bad_2 }
		add = -2
	}
	if = {
		limit = { has_trait = intellect_bad_3 }
		add = -3
	}
	if = {
		limit = { has_trait = intellect_good_1 }
		add = 1
	}
	if = {
		limit = { has_trait = intellect_good_2 }
		add = 2
	}
	if = {
		limit = { has_trait = intellect_good_3 }
		add = 3
	}
	#PHYSIQUE
	if = {
		limit = { has_trait = physique_bad_1 }
		add = -1
	}
	if = {
		limit = { has_trait = physique_bad_2 }
		add = -2
	}
	if = {
		limit = { has_trait = physique_bad_3 }
		add = -3
	}
	if = {
		limit = { has_trait = physique_good_1 }
		add = 1
	}
	if = {
		limit = { has_trait = physique_good_2 }
		add = 2
	}
	if = {
		limit = { has_trait = physique_good_3 }
		add = 3
	}
	#MISC GOOD GENETIC
	if = {
		limit = { has_trait = fecund }
		add = 1
	}
	#MISC BAD GENETIC
	if = {
		limit = { has_trait = clubfooted }
		add = -1
	}
	if = {
		limit = { has_trait = hunchbacked }
		add = -1
	}
	if = {
		limit = { has_trait = lisping }
		add = -1
	}
	if = {
		limit = { has_trait = stuttering }
		add = -1
	}
	if = {
		limit = { has_trait = giant }
		add = -1
	}
	if = {
		limit = { has_trait = inbred }
		add = -3
	}
	if = {
		limit = { has_trait = spindly }
		add = -1
	}
	if = {
		limit = { has_trait = scaly }
		add = -1
	}
	if = {
		limit = { has_trait = albino }
		add = -1
	}
	if = {
		limit = { has_trait = wheezing }
		add = -1
	}
	if = {
		limit = { has_trait = bleeder }
		add = -1
	}
	if = {
		limit = { has_trait = infertile }
		add = -1
	}
	if = {
		limit = { has_trait = depressed_genetic }
		add = -1
	}
	if = {
		limit = { has_trait = lunatic_genetic }
		add = -1
	}
	if = {
		limit = { has_trait = possessed_genetic }
		add = -1
	}
}

individual_recruit_guest_interaction_cost = {
	add = 15
	
	###CLAIMS###
	if = {
		limit = {
			save_temporary_scope_as = claim_holder
			any_claim = {
				courtier_or_guest_claim_trigger = { RULER = scope:claim_holder.host }
			}
		}
		if = {
			limit = {
				save_temporary_scope_as = claim_holder
				any_claim = {
					courtier_or_guest_claim_trigger = { RULER = scope:claim_holder.host }
					tier >= tier_duchy
				}
			}
			add = 50
		}
		else_if = {
			limit = {
				save_temporary_scope_as = claim_holder
				any_claim = {
					courtier_or_guest_claim_trigger = { RULER = scope:claim_holder.host }
					tier = tier_county
				}
			}
			add = 25
		}
	}

	###DYNASTY###
	if = {
		limit = { exists = dynasty }
		add = {
			value = dynasty.dynasty_prestige_level #0-10
			multiply = 5 #Max 50
		}
	}

	###GENETIC TRAITS###
	add = {
		value = genetic_character_value
		multiply = 3
		min = -15
		max = 15
	}

	###COMMANDER TRAITS###
	if = {
		limit = { number_of_commander_traits >= 1 }
		add = {
			value = number_of_commander_traits
			multiply = 5
			min = 0
		}
		
	}

	###COURT PHYSICIAN TRAITS###
	if = {
		limit = {
			OR = {
				AND = {
					has_trait = lifestyle_physician
					has_trait_xp = {
						trait = lifestyle_physician
						value >= 100
					}
				}
				AND = {
					has_trait = lifestyle_mystic
					has_trait_xp = {
						trait = lifestyle_mystic
						value >= 100
					}
				}
			}
		}
		add = 20
	}
	else_if = {
		limit = {
			OR = {
				has_trait = lifestyle_herbalist
				AND = {
					has_trait = lifestyle_physician
					has_trait_xp = {
						trait = lifestyle_physician
						value >= 50
					}
				}
				AND = {
					has_trait = lifestyle_mystic
					has_trait_xp = {
						trait = lifestyle_mystic
						value >= 50
					}
				}
			}
		}
		add = 15
	}
	else_if = {
		limit = {
			OR = {
				has_trait = lifestyle_physician
				has_trait = lifestyle_mystic
			}
		}
		add = 10
	}

	###SKILLS###
	if = {
		limit = { diplomacy >= good_skill_level }
		add = 5
	}
	if = {
		limit = { martial >= good_skill_level }
		add = 5
	}
	if = {
		limit = { stewardship >= good_skill_level }
		add = 5
	}
	if = {
		limit = { intrigue >= good_skill_level }
		add = 5
	}
	if = {
		limit = { learning >= good_skill_level }
		add = 5
	}
	if = {
		limit = { prowess >= good_skill_level }
		add = 5
	}

	###PERSONALITY MULTIPLIER###
	if = {
		limit = {
			OR = {
				ai_greed >= high_positive_ai_value
				has_trait = arrogant
			}
		}
		multiply = 1.2
	}
	else_if = {
		limit = {
			OR = {
				ai_greed <= high_negative_ai_value
				has_trait = humble
			}
		}
		multiply = 0.8
	}

	###AMENITIES MULTIPLIER###
	if = {
		limit = {
			host = {
				has_royal_court = yes
				has_dlc_feature = royal_court
				court_owner = {
					amenity_level = { type = court_servants value = medium_amenity_level }
				}
			}
		}
		multiply = 0.8
	}
	else_if = {
		limit = {
			host = {
				has_royal_court = yes
				has_dlc_feature = royal_court
				court_owner = {
					amenity_level = { type = court_servants value = high_amenity_level }
				}
			}
		}
		multiply = 0.7
	}
	else_if = {
		limit = {
			host = {
				has_royal_court = yes
				has_dlc_feature = royal_court
				court_owner = {
					amenity_level = { type = court_servants value = very_high_amenity_level }
				}
			}
		}
		multiply = 0.6
	}
	else_if = {
		limit = {
			host = {
				has_royal_court = yes
				has_dlc_feature = royal_court
				court_owner = {
					amenity_level = { type = court_servants value = max_amenity_level }
				}
			}
		}
		multiply = 0.5
	}

	min = 10

	#Rounds up to the closest number divisible by 5
	divide = 5
	ceiling = yes
	multiply = 5
	
	if = { # Cultural Traditions
		limit = {
			host = {
				culture = {
					has_cultural_parameter = cheaper_guest_recruitment
				}
			}
		}
		multiply = 0.8
		min = 8
	}
	
	if = { # Dynasty legacy
		limit = {
			host = {
				exists = dynasty
				dynasty = {
					has_dynasty_perk = erudition_legacy_1
				}
			}
		}
		multiply = 0.7
		min = 7
	}
	
	
	if = { # Tribal rulers pay less
		limit = {
			host = {
				government_has_flag = government_is_tribal
			}
		}
		multiply = 0.5
		min = 10
	}

}

recruit_guest_interaction_cost = {
	value = 0
	every_traveling_family_member = {
		add = individual_recruit_guest_interaction_cost
	}
}
recruit_guest_interaction_cost_with_list = {
	value = 0
	every_in_list = {
		list = recruiting_family
		add = individual_recruit_guest_interaction_cost
	}
}

root_attraction_based_female_chance = {
	if = {
		limit = {
			root = {
				is_attracted_to_women = yes
				is_attracted_to_men = no
			}
		}
		add = 100
	}
	else_if = {
		limit = {
			root = {
				is_attracted_to_women = yes
				is_attracted_to_men = yes
			}
		}
		add = 50
	}
	else = {
		add = 0
	}
}

scope_attraction_based_female_chance = {
	if = {
		limit = {
			scope:attraction_check = {
				is_attracted_to_women = yes
				is_attracted_to_men = no
			}
		}
		add = 100
	}
	else_if = {
		limit = {
			scope:attraction_check = {
				is_attracted_to_women = yes
				is_attracted_to_men = yes
			}
		}
		add = 50
	}
	else = {
		add = 0
	}
}

root_faith_clergy_gender_female_chance = {
	if = {
		limit = {
			root.faith = { has_doctrine_parameter = clergy_must_be_male }
		}
		add =  0
	}
	else_if = {
		limit = {
			root.faith = { has_doctrine_parameter = clergy_must_be_female }
		}
		add =  100
	}
	else = {
	 	add = 50
	}
}

scope_value_target_soldier_female_chance = {
	if = {
		limit = {
			NOT = {
				dummy_female = {
					can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = scope:value_target }
				}
			}
			dummy_male = {
				can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = scope:value_target }
			}
		}
		add =  0
	}
	else_if = {
		limit = {
			dummy_female = {
				can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = scope:value_target }
			}
			NOT = {
				dummy_male = {
					can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = scope:value_target }
				}
			}
		}
		add =  100
	}
	else = {
	 	add = 50
	}
}

root_soldier_female_chance = {
	if = {
		limit = {
			NOT = { dummy_female = { can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = root } } }
			dummy_male = { can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = root } }
		}
		add =  0
	}
	else_if = {
		limit = {
			dummy_female = { can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = root } }
			NOT = { dummy_male = { can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = root } } }
		}
		add =  100
	}
	else = {
	 	add = 50
	}
}

root_non_combatant_female_chance = {
	if = {
		limit = {
			NOT = { dummy_female = { can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = root } } }
			dummy_male = { can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = root } }
		}
		add =  100
	}
	else_if = {
		limit = {
			dummy_female = { can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = root } }
			NOT = { dummy_male = { can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = root } } }
		}
		add =  0
	}
	else = {
	 	add = 50
	}
}

actor_soldier_female_chance = {
	if = {
		limit = {
			NOT = { dummy_female = { can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = scope:actor } } }
			dummy_male = { can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = scope:actor } }
		}
		add =  0
	}
	else_if = {
		limit = {
			dummy_female = { can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = scope:actor } }
			NOT = { dummy_male = { can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = scope:actor } } }
		}
		add =  100
	}
	else = {
	 	add = 50
	}
}

recipient_soldier_female_chance = {
	if = {
		limit = {
			NOT = { dummy_female = { can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = scope:recipient } } }
			dummy_male = { can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = scope:recipient } }
		}
		add =  0
	}
	else_if = {
		limit = {
			dummy_female = { can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = scope:recipient } }
			NOT = { dummy_male = { can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = scope:recipient } } }
		}
		add =  100
	}
	else = {
	 	add = 50
	}
}

root_faith_dominant_gender_female_chance = {
	if = {
		limit = { root.faith = { has_doctrine = doctrine_gender_male_dominated } }
		add = 0
	}
	else_if = {
		limit = { root.faith = { has_doctrine = doctrine_gender_female_dominated } }
		add = 100
	}
	else = {
		add = 50
	}
}

activity_location_faith_dominant_gender_female_chance = {
	if = {
		limit = { scope:activity.activity_location.faith = { has_doctrine = doctrine_gender_male_dominated } }
		add = 0
	}
	else_if = {
		limit = { scope:activity.activity_location.faith = { has_doctrine = doctrine_gender_female_dominated } }
		add = 100
	}
	else = {
		add = 50
	}
}

location_faith_dominant_gender_female_chance = {
	if = {
		limit = { location.faith = { has_doctrine = doctrine_gender_male_dominated } }
		add = 0
	}
	else_if = {
		limit = { location.faith = { has_doctrine = doctrine_gender_female_dominated } }
		add = 100
	}
	else = {
		add = 50
	}
}

root_faith_dominant_gender_female_reversed_chance = {
	if = {
		limit = { root.faith = { has_doctrine = doctrine_gender_male_dominated } }
		add = 100
	}
	else_if = {
		limit = { root.faith = { has_doctrine = doctrine_gender_female_dominated } }
		add = 0
	}
	else = {
		add = 50
	}
}

root_faith_dominant_gender_adjusted_female_chance = {
	if = {
		limit = { root.faith = { has_doctrine = doctrine_gender_male_dominated } }
		add = 20
	}
	else_if = {
		limit = { root.faith = { has_doctrine = doctrine_gender_female_dominated } }
		add = 80
	}
	else = {
		add = 50
	}
}

root_self_based_female_chance = {
	if = {
		limit = {
			root = {
				is_female = yes
			}
		}
		add = 100
	}
	else = {
		add = 0
	}
}

marriage_gender_adjusted_female_chance = {
	if = {
		limit = {
			allowed_to_marry_same_sex_trigger = yes
			is_female = yes
			is_attracted_to_women = yes
			is_attracted_to_men = no
			OR = { #Already have an heir of their dynasty or don't care
				AND = {
					exists = primary_heir
					exists = dynasty
					dynasty = primary_heir.dynasty
				}
				is_lowborn = yes
			}
		}
		add = 100
	}
	else_if = {
		limit = {
			allowed_to_marry_same_sex_trigger = yes
			is_female = yes
			is_attracted_to_women = yes
			is_attracted_to_men = yes
			OR = { #Already have an heir of their dynasty or don't care
				AND = {
					exists = primary_heir
					exists = dynasty
					dynasty = primary_heir.dynasty
				}
				is_lowborn = yes
			}
		}
		add = 50
	}
	else_if = {
		limit = {
			is_female = yes
		}
		add = 0
	}
	else_if = {
		limit = {
			allowed_to_marry_same_sex_trigger = yes
			is_male = yes
			is_attracted_to_men = yes
			is_attracted_to_women = no
			OR = { #Already have an heir of their dynasty or don't care
				AND = {
					exists = primary_heir
					exists = dynasty
					dynasty = primary_heir.dynasty
				}
				is_lowborn = yes
			}
		}
		add = 0
	}
	else_if = {
		limit = {
			allowed_to_marry_same_sex_trigger = yes
			is_male = yes
			is_attracted_to_men = yes
			is_attracted_to_women = yes
			OR = { #Already have an heir of their dynasty or don't care
				AND = {
					exists = primary_heir
					exists = dynasty
					dynasty = primary_heir.dynasty
				}
				is_lowborn = yes
			}
		}
		add = 50
	}
	else = {
		add = 100
	}
}

root_sexuality_female_chance = {
	if = {
		limit = {
			root = {
				is_attracted_to_women = yes
				is_attracted_to_men = no
			}
		}
		add = 100
	}
	else_if = {
		limit = {
			root = {
				is_attracted_to_women = no
				is_attracted_to_men = yes
			}
		}
		add = 0
	}
	else = { # Asexual/bi
		add = 50
	}
}

# Referenced by code when auto-assigning perks. Root is a character. Supports the use of randomization
num_perk_points = {
	add = age
	subtract = 16
	
	divide = 3
	min = 0
	max = 20
}

stewardship_wealth_5002_investment_duration = 30
stewardship_wealth_5002_good_tax_increase = 0.1
stewardship_wealth_5002_great_tax_increase = 0.2

stewardship_wealth_5002_payment = {
	value = capital_province.monthly_income
	multiply = 12
	multiply = stewardship_wealth_5002_investment_duration
	multiply = stewardship_wealth_5002_good_tax_increase #Now we're at the amount of extra tax you'd make
	divide = 3

	#Rounds up to the closest number divisible by 5
	divide = 5
	ceiling = yes
	multiply = 5
}

stewardship_wealth_5002_one_time_gain = {
	value = stewardship_wealth_5002_payment
	divide = 2

	#Rounds up to the closest number divisible by 5
	divide = 5
	ceiling = yes
	multiply = 5
}

infidelity_event_delay = 3

half_monthly_character_income = {
	value = monthly_character_income
	multiply = 0.5
}

monthly_character_income_minus_expenses = {
	value = monthly_character_income
	subtract = monthly_character_expenses
}

monthly_character_expenses_plus_fourty_percent = {
	value = monthly_character_expenses
	multiply = 1.4
}

monthly_character_expenses_times_three = {
	value = monthly_character_expenses
	multiply = 3
}

ai_war_chest_desired_gold_value = {
	value = yearly_character_income
	multiply = 3
	min = 100
	max = 2000
}

ai_inspiration_desired_gold_value = {
	value = yearly_character_income
	min = basic_fund_inspiration_cost
	max = 2000
}

ai_war_chest_defender_holy_war_gold_value = {
	value = yearly_character_income
	multiply = 2
	min = 50
	max = 2000
}

steward_convert_culture_value = {
	value = yearly_character_income
	multiply = 5
	min = 150
}

steward_increase_development_value = {
	value = yearly_character_income
	multiply = 3
	min = 100
}

minimum_ai_gold_value_for_tyranny_wars = {
	value = yearly_character_income
	min = 10
}

comfortable_ai_gold_value_for_tyranny_wars = {
	value = yearly_character_income
	multiply = 3
	min = 25
}

uncomfortable_ai_bancruptcy_for_wars = {
	value = yearly_character_income
	multiply = -2
}

very_uncomfortable_ai_bancruptcy_for_wars = {
	value = yearly_character_income
	multiply = -4
}

ai_economic_preference_value = {
	value = 1
	if = {
		limit = {
			scope:holder.capital_province = this
			free_building_slots <= 0
		}
		add = 1
	}
	if = {
		limit = {
			has_building_or_higher = tax_assessor_01
			free_building_slots <= 0
		}
		add = 1
	}
}

dislikes_maa_value = -9
compensate_conflict_maa_bonus = 9
likes_maa_value = 1
stationed_maa_bonus = 3
non_stationed_maa_bonus = -3
really_likes_maa_value = 2
stacking_bonus_value = 4
anti_synergy_penalty_value = -9

fp2_2007_calculate_architect_competence = { # Intended for use with fp2_2007 in specific, not for general architects.
	value = 0
	if = { limit = { culture = { has_cultural_parameter = architect_trait_prestige } } add = 15 } # Collapsed into one line for compactness
	if = { limit = { has_trait = organizer } 			add = 2 }
	if = { limit = { has_trait = logistician } 			add = 5 }
	if = { limit = { has_trait = military_engineer }	add = 15 }
	if = { limit = { has_trait = strategist } 			add = 4 }
	if = { limit = { has_trait = shrewd } 				add = 5 }
	if = { limit = { has_trait = diligent } 			add = 5 }
	if = { limit = { has_trait = temperate } 			add = 3 }
	if = { limit = { has_trait = patient } 				add = 2 }
	if = { limit = { has_trait = paranoid } 			add = 2 }
	if = { limit = { has_trait = scholar } 				add = 1 }
	if = { limit = { has_trait = architect } 			add = 12 }
	if = { limit = { has_trait = content } 				subtract = 1 }
	if = { limit = { has_trait = fickle } 				subtract = 5 }
	if = { limit = { has_trait = arrogant } 			subtract = 10 }
	if = { limit = { has_trait = lazy } 				subtract = 4 }
	if = { limit = { has_trait = impatient } 			subtract = 5 }
	if = { limit = { has_trait = greedy } 				subtract = 2 }
	if = { limit = { has_trait = avaricious } 			subtract = 1 }
	if = { limit = { has_trait = dull } 				subtract = 10 }
}

activity_host_faith_dominant_gender_adjusted_female_chance = {
	if = {
		limit = {
			scope:activity.activity_host.faith = { has_doctrine = doctrine_gender_male_dominated }
		}
		add = 20
	}
	else_if = {
		limit = {
			scope:activity.activity_host.faith = { has_doctrine = doctrine_gender_female_dominated }
		}
		add = 80
	}
	else = { add = 50 }
}

activity_host_clergy_gender_female_chance = {
	if = {
		limit = {
			scope:activity.activity_host.faith = { has_doctrine_parameter = clergy_must_be_male }
		}
		add =  0
	}
	else_if = {
		limit = {
			scope:activity.activity_host.faith = { has_doctrine_parameter = clergy_must_be_female }
		}
		add =  100
	}
	else = { add = 50 }
}

five_times_monumental_value = {
	add = monumental_gold_value
	multiply = 5
}
