# Migration values
migration_cooldown_value = 5 # Years

# Temp Tributary Protection after winning a war
temp_tributary_protection_value = 3 # Years

#ratio between attacker's military strength and defender's strength
confederation_worthy_foe_strength_ratio_value = {
	value = scope:confederate.max_military_strength
	divide = max_military_strength_plus_one_value
}

confederation_worthy_foe_strength_ratio_value_root = {
	value = root.max_military_strength
	divide = max_military_strength_plus_one_value
}

max_military_strength_plus_one_value = {
	value = max_military_strength
	add = 1
}

confederation_cb_cost_display_value = 200
confederation_cb_cost_value = {
	value = 1
	add = {
		value = confederation_cb_cost_display_value
		divide = 100
	}
}

#ratio between attacker's military strength and defender's strength
blood_brother_strength_ratio_value = {
	value = scope:actor.max_military_strength
	divide = { 
		value = scope:recipient.max_military_strength
		min = 1
	}
}
## Herd Values ##
# Used by Code, do not rename or remove
# Used to initialize how much Herd a nomad gets upon getting a domicile
# root = domicile owner, aka the ruling nomad leader
initial_nomad_herd = {
	value = 0
	add = {
		#ADDITIVE SOURCES
		add = {
			value = current_domain_fertility
			multiply = 8
		}
		every_vassal = {
			limit = {
				government_has_flag = government_is_nomadic
			}
			add = {
				value = 0
				add = {
					value = current_domain_fertility
					multiply = 4
				}
				every_vassal = {
					limit = {
						government_has_flag = government_is_nomadic
					}
					add = {
						value = current_domain_fertility
						multiply = 2
					}
				}
				multiply = {
					value = 140
					add = "this.opinion(root)"
					add = root.dread
					multiply = 0.01
					min = 0
					max = 2
				}
				multiply = primary_title.tier
				multiply = 0.2
				min = 100
				max = 4000
			}
		}
		every_vassal = {
			limit = {
				government_has_flag = government_is_herder
			}
			add = {
				value = current_domain_fertility
				multiply = 4
			}
		}
		every_tributary = {
			add = {
				value = realm_size
				multiply = primary_title.tier
				multiply = 10
				min = 100
				max = 2000
			}
		}
	}
}

# This will randomly be added on top of the initial nomad herd depending on your title tier
# This is the lower range
# root = domicile owner, aka the ruling nomad leader
initial_nomad_herd_title_min = {
	value = 0
	add = {
		switch = {
			trigger = primary_title.tier
			tier_barony = {
				value = 100 
			}
			tier_county = {
				value = 250 
			}
			tier_duchy = {
				value = 750
			}
			tier_kingdom = {
				value = 1250 
			}
			tier_empire = {
				value = 2500 
			}
		}
	}
}

# This will randomly be added on top of the initial nomad herd depending on your title tier
# This is the upper range
# root = domicile owner, aka the ruling nomad leader
initial_nomad_herd_title_max = {
	value = 0
	add = {
		switch = {
			trigger = primary_title.tier
			tier_barony = {
				value = 200 
			}
			tier_county = {
				value = 500
			}
			tier_duchy = {
				value = 1500 
			}
			tier_kingdom = {
				value = 2500 
			}
			tier_empire = {
				value = 5000 
			}
		}
	}
}

# Used on game start to give Nomads some starting gold
gold_value_scale_by_era = {
	value = 0
	if = {
		limit = {
			culture = { has_cultural_era_or_later = culture_era_late_medieval }
		}
		add = 3
	}
	else_if = {
		limit = {
			culture = { has_cultural_era_or_later = culture_era_high_medieval }
		}
		add = 1.5
	}
	else_if = {
		limit = {
			culture = { has_cultural_era_or_later = culture_era_early_medieval }
		}
		add = 1
	}
	else = {
		add = 0.75
	}
}


# Dynamic Herd values
# START of use only with a domicile scope
herd_value_scale_by_era = {
	value = 0
	if = {
		limit = {
			owner.culture ?= { has_cultural_era_or_later = culture_era_late_medieval }
		}
		add = 1.75
	}
	else_if = {
		limit = {
			owner.culture ?= { has_cultural_era_or_later = culture_era_high_medieval }
		}
		add = 1.25
	}
	else_if = {
		limit = {
			owner.culture ?= { has_cultural_era_or_later = culture_era_early_medieval }
		}
		add = 1
	}
	else = {
		add = 0.75
	}
}

herd_value_scale_by_tier = {
	value = 0
	if = {
		limit = { exists = owner.primary_title }
		add = {
			value = owner.primary_title.tier
			subtract = 1
		}
		multiply = 0.5
	}
	min = 1
}

herd_value_scale_owner_dominance = {
	value = owner.dominance_value
	multiply = 0.5
	min = 1
}

miniscule_herd_value_static = 25
miniscule_herd_value = {
	value = miniscule_herd_value_static
	multiply = herd_value_scale_by_era
	multiply = herd_value_scale_by_tier
	multiply = herd_value_scale_owner_dominance
}

minor_herd_value_static = 150
minor_herd_value = {
	value = minor_herd_value_static
	multiply = herd_value_scale_by_era
	multiply = herd_value_scale_by_tier
	multiply = herd_value_scale_owner_dominance
}

medium_herd_value_static = 300
medium_herd_value = {
	value = medium_herd_value_static
	multiply = herd_value_scale_by_era
	multiply = herd_value_scale_by_tier
	multiply = herd_value_scale_owner_dominance
}

major_herd_value_static = 600
major_herd_value = {
	value = major_herd_value_static
	multiply = herd_value_scale_by_era
	multiply = herd_value_scale_by_tier
	multiply = herd_value_scale_owner_dominance
}

massive_herd_value_static = 1200
massive_herd_value = {
	value = massive_herd_value_static
	multiply = herd_value_scale_by_era
	multiply = herd_value_scale_by_tier
	multiply = owner.dominance_value
}

monumental_herd_value_static = 2400
monumental_herd_value = {
	value = monumental_herd_value_static
	multiply = herd_value_scale_by_era
	multiply = herd_value_scale_by_tier
	multiply = owner.dominance_value
}

miniscule_herd_loss = {
	value = 0
	subtract = miniscule_herd_value
}
minor_herd_loss = {
	value = 0
	subtract = minor_herd_value
}
medium_herd_loss = {
	value = 0
	subtract = medium_herd_value
}
major_herd_loss = {
	value = 0
	subtract = major_herd_value
}
massive_herd_loss = {
	value = 0
	subtract = massive_herd_value
}
monumental_herd_loss = {
	value = 0
	subtract = monumental_herd_value
}

miniscule_herd_gain = {
	value = 0
	add = miniscule_herd_value
}
minor_herd_gain = {
	value = 0
	add = minor_herd_value
}
medium_herd_gain = {
	value = 0
	add = medium_herd_value
}
major_herd_gain = {
	value = 0
	add = major_herd_value
}
massive_herd_gain = {
	value = 0 
	add = massive_herd_value
}
monumental_herd_gain = {
	value = 0 
	add = monumental_herd_value
}

five_percent_herd_value = {
	value = max_herd
	multiply = 0.05
}
ten_percent_herd_value = {
	value = max_herd
	multiply = 0.1
}
fifteen_percent_herd_value = {
	value = max_herd
	multiply = 0.15
}
twenty_percent_herd_value = {
	value = max_herd
	multiply = 0.2
}
twentyfive_percent_herd_value = {
	value = max_herd
	multiply = 0.25
}
thirty_percent_herd_value = {
	value = max_herd
	multiply = 0.3
}
forty_percent_herd_value = {
	value = max_herd
	multiply = 0.4
}
fifty_percent_herd_value = {
	value = max_herd
	multiply = 0.5
}
sixty_percent_herd_value = {
	value = max_herd
	multiply = 0.6
}
seventy_percent_herd_value = {
	value = max_herd
	multiply = 0.7
}
eighty_percent_herd_value = {
	value = max_herd
	multiply = 0.8
}
ninety_percent_herd_value = {
	value = max_herd
	multiply = 0.9
}

five_percent_current_herd_value = {
	value = herd
	multiply = 0.05
}
ten_percent_current_herd_value = {
	value = herd
	multiply = 0.1
}
fifteen_percent_current_herd_value = {
	value = herd
	multiply = 0.15
}
twenty_percent_current_herd_value = {
	value = herd
	multiply = 0.2
}
twentyfive_percent_current_herd_value = {
	value = herd
	multiply = 0.25
}
thirty_percent_current_herd_value = {
	value = herd
	multiply = 0.3
}
forty_percent_current_herd_value = {
	value = herd
	multiply = 0.4
}
fifty_percent_current_herd_value = {
	value = herd
	multiply = 0.5
}
sixty_percent_current_herd_value = {
	value = herd
	multiply = 0.6
}
seventy_percent_current_herd_value = {
	value = herd
	multiply = 0.7
}
eighty_percent_current_herd_value = {
	value = herd
	multiply = 0.8
}
ninety_percent_current_herd_value = {
	value = herd
	multiply = 0.9
}

negative_seventy_five_percent_herd_value = {
	value = herd
	multiply = -0.75
}

ask_for_herd_base_value = {
	value = 0
	switch = {
		trigger = owner.primary_title.tier
		tier_barony = { add = miniscule_herd_value }
		tier_county = { add = minor_herd_value}
		tier_duchy = { add = minor_herd_value }
		tier_kingdom = { add = medium_herd_value }
		tier_empire = { add = medium_herd_value }
	}
}

ask_for_herd_double_value = {
	value = ask_for_herd_base_value
	multiply = 2
}

ask_for_herd_half_value = {
	value = ask_for_herd_base_value
	multiply = 0.5
}
# END of use only with domicile scope

# START of use only with a character scope
dominance_value = {
	value = 0
	if = {
		limit = { government_has_flag = government_is_nomadic }
		switch = {
			trigger = has_realm_law
			nomadic_authority_1 = {
				add = 1
			}
			nomadic_authority_2 = {
				add = 2
			}
			nomadic_authority_3 = {
				add = 3
			}
			nomadic_authority_4 = {
				add = 4
			}
			nomadic_authority_5 = {
				add = 5
			}
		}
	}

	min = 1
}

excess_herd_value = {
	value = domicile.herd
	subtract = domicile.max_herd
}

excess_herd_value_negative = {
	value = domicile.max_herd
	subtract = domicile.herd
}

nomadic_authority_requirement_scale_by_era = {
	value = 0
	if = {
		limit = {
			exists = culture
		}
		culture = {
			if = {
				limit = {
					has_cultural_era_or_later = culture_era_late_medieval
				}
				add = 3
			}
			else_if = {
				limit = {
					has_cultural_era_or_later = culture_era_high_medieval
				}
				add = 1.5
			}
			else_if = {
				limit = {
					has_cultural_era_or_later = culture_era_early_medieval
				}
				add = 1
			}
			else = {
				add = 0.75
			}
		}
	}
}

nomadic_authority_level_2_requirement = 2500

nomadic_authority_level_3_requirement = 10000

nomadic_authority_level_4_requirement = 30000

nomadic_authority_level_5_requirement = 75000
# END of use only with character scope

hunting_eagle_sell_value = {
    value = 24
    if = { # They are pretty valuable
        limit = {
            is_landless_adventurer = yes
        }
        add = massive_gold_laamps_value
    }
    else = {
        add = massive_gold_value
    }
    if = { # The younger, the better
        limit = {
            has_variable = eagle_age_variable
        }
        subtract = {
            value = {
                add = var:eagle_age_variable
                multiply = 4
            }
        }
    }
    if = { # Developed pets are worth more
        limit = {
            has_eagle_personality_trait_trigger = yes 
        }
        multiply = {
            value = {
                add = 1.2
                add = { #0.2 per level
                    value = 0.2
                    multiply = var:eagle_personality_level
                }
            }
        }
        if = {
            limit = {
                has_secondary_eagle_personality_trait_trigger = yes
            }
            multiply = 1.25
        }
    }
    if = { # Weak pets are worth less
        limit = {
            has_character_modifier = weak_eagle_modifier
        }
        multiply = 0.75
    }
    if = { # Very weak pets are worth less
        limit = {
            has_character_modifier = very_weak_eagle_modifier
        }
        multiply = 0.5
    }
    if = {
        limit = { # Can't get an eagle from a non-steppe location
            NOT = { location = { geographical_region = world_steppe } }
        }
        multiply = 2
    }
    #Better buyers in City Holding
	if = {
		limit = {
			location = { has_holding_type = city_holding }
		}
		multiply = { 1.15 1.25 }
	}
    # Some variance 
    multiply = { 0.8 1.1 }
}

nomad_contract_cooldown_value = 5

study_commander_trait_success_chance_very_good_value = 80
study_commander_trait_success_chance_good_value = 60
study_commander_trait_success_chance_fair_value = 40
study_commander_trait_success_chance_poor_value = 20

study_commander_trait_success_chance_value = {
	value = 40

	if = { # More likely to succeed if you've done it more times
		limit = {
			has_variable = study_commander_trait_tally
		}
		add = {
			value = var:study_commander_trait_tally
			multiply = 5
		}
	}

	# Traits
	if = {
		limit = {
			has_trait = diligent
		}
		add = 5
	}
	
	if = {
		limit = {
			has_trait = lazy
		}
		add = -5
	}
	if = {
		limit = {
			has_trait = intellect_bad
		}
		add = -10
	}
	if = {
		limit = {
			has_wounds_trigger =  yes
		}
		add = -10
	}
	if = {
		limit = {
			has_any_illness = yes
		}
		add = -10
	}
	if = {
		limit = {
			has_any_debilitating_illness = yes
		}
		add = -10
	}
	if = {
		limit = {
			has_trait = education_martial
		}
		add = 5
	}
	# —— 神圣血脉忠顺加成 ——
	if = {
		limit = {
			has_trait = bloodline_god_1
		}
		add = 100
	}
	if = {
		limit = {
			has_trait = bloodline_god_2
		}
		add = 500
	}
	if = {
		limit = {
			has_trait = bloodline_god_3
		}
		add = 1666
	}

	#Other
	if = {
		limit = {
			culture = { has_cultural_pillar = ethos_bellicose }
		}
		add = 5
	}
	if = {
		limit = {
			has_variable = study_commander_trait_success_chance_var
		}
		add = var:study_commander_trait_success_chance_var
	}

	max = 99
	min = 1
}

study_commander_trait_success_chance_value_neg = {
	value = study_commander_trait_success_chance_value
	multiply = -1
}

study_commander_trait_mentor_hire_cost = {
	value = 15 

	add = {
		value = number_of_commander_traits
		multiply = 5
	}

	add = {
		value = martial
		multiply = 2
	}

	if = {
		limit = {
			has_character_flag = commander_trait_mentor
		}
		multiply = 0.5 # Cheaper to hire
	}
}

##### Fertility #####

#Levels values
terrible_county_fertility_level = 10
bad_county_fertility_level = 20
medium_county_fertility_level = 40
good_county_fertility_level = 60
great_county_fertility_level = 80
max_county_fertility_level = 100

#Change Values
tiny_county_fertility_level_loss = -5
minor_county_fertility_level_loss = -10
medium_county_fertility_level_loss = -20
major_county_fertility_level_loss = -30
tiny_county_fertility_level_gain = 5
minor_county_fertility_level_gain = 10
medium_county_fertility_level_gain = 20
major_county_fertility_level_gain = 30

#Growth Values
tiny_county_fertility_growth_gain = 0.05
small_county_fertility_growth_gain = 0.1
medium_county_fertility_growth_gain = 0.2
large_county_fertility_growth_gain = 0.3
very_large_county_fertility_growth_gain = 0.5

tiny_county_fertility_growth_loss = -0.1
small_county_fertility_growth_loss = -0.2
medium_county_fertility_growth_loss = -0.3
large_county_fertility_growth_loss = -0.5
very_large_county_fertility_growth_loss = -0.8
fertility_dance_bonus_value = {
	value = minor_county_fertility_level_gain

	# Based on the county's fertility level
	# No bonuses if higher than 60
	if = {
		limit = {
			county_fertility <= bad_county_fertility_level 
		}
		multiply = 2.5
	}
	else_if = {
		limit = {
			county_fertility <= medium_county_fertility_level 
		}
		multiply = 2
	}
	else_if = {
		limit = {
			county_fertility <= good_county_fertility_level 
		}
		multiply = 1.5
	}

	# Based on the shaman's learning skill
	add = {
		add = 1
		add = {
			value = holder.court_position:court_astrologer_court_position.learning
			multiply = 0.3
		}
	}

	#Based on the player's piety level
	multiply = {
		add = 1
		add = {
			value = holder.piety_level
			multiply = 0.2
		}
	}
	
	max = {
		value = 100
		subtract = county_fertility
	}
}
fertility_dance_bonus_growth_value = {
	value = 1

	# Based on the county's fertility level
	# No bonuses if higher than 60
	if = {
		limit = {
			county_fertility <= bad_county_fertility_level 
		}
		multiply = 2.5
	}
	else_if = {
		limit = {
			county_fertility <= medium_county_fertility_level 
		}
		multiply = 2
	}
	else_if = {
		limit = {
			county_fertility <= good_county_fertility_level 
		}
		multiply = 1.5
	}

	# Based on the shaman's learning skill
	add = {
		add = 1
		add = {
			value = holder.court_position:court_astrologer_court_position.learning
			multiply = 0.3
		}
	}

	#Based on the player's learning skill
	add = {
		add = 1
		add = {
			value = holder.learning
			multiply = 0.3
		}
	}
}

mpo_paiza_abuse_khan_reaction_value = {
	value = 0
	add = {
		value = "scope:paiza_patron.opinion(scope:paiza_abuser)"
		divide = 10
	}
	add = {
		value = scope:paiza_patron.max_military_strength
		subtract = scope:paiza_abuser.max_military_strength
		divide = scope:paiza_patron.max_military_strength
		multiply = 10
	}

}

mpo_introduce_heir_prestige_cost = medium_prestige_value
mpo_introduce_heir_piety_cost = major_piety_value

age_compared_to_player_heir = {
	add = age
	subtract = root.player_heir.age
}

mpo_friendship_setup_positive_modifiers_value = {
	value = 0
	if = {
		limit = {
			scope:friendship_target = {
				opinion = {
					target = scope:heir
					value >= 25
				}
			}
		}
		add = 40
	}
	if = {
		limit = {
			scope:friendship_target = {
				opinion = {
					target = scope:heir
					value >= 75
				}
			}
		}
		add = 60
	}
	if = {
		limit = {
			scope:friendship_target = {
				is_allied_to = root
			}
		}
		add = 30
	}
	if = {
		limit = {
			scope:friendship_target = {
				OR = {
					culture = {
						this = scope:heir.culture
					}
					culture = {
						cultural_acceptance = {
							target = scope:heir.culture
							value >= 80
						}
					}
				}
			}
		}
		add = 40
	}
	if = {
		limit = {
			scope:friendship_target = {
				AND = {
					exists = house
					exists = scope:heir.house
					house = {
						this = root.house
					}
				}
			}
		}
		add = 40
	}
	if = {
		limit = {
			scope:friendship_target = {
				OR = {
					has_relation_friend = root
					has_relation_best_friend = root
					has_relation_soulmate = root
					has_relation_lover = root
					has_relation_blood_brother = root
				}
			}
		}
		add = 40
	}
}

mpo_friendship_setup_negative_modifiers_value = {
	value = 0
	if = {
		limit = {
			scope:friendship_target = {
				highest_held_title_tier >= tier_empire
			}
		}
		add = 40
	}
	if = {
		limit = {
			scope:friendship_target = {
				highest_held_title_tier >= tier_kingdom
			}
		}
		add = 40
	}
	if = {
		limit = {
			scope:friendship_target = {
				OR = {
					age_compared_to_player_heir >= 20
					age_compared_to_player_heir <= -20
				}
			}
		}
		add = 40
	}
	if = {
		limit = {
			scope:friendship_target = {
				save_temporary_scope_as = temp_target
				NOR = {
					knows_language_of_culture = scope:heir.culture
					scope:heir = {
						knows_language_of_culture = scope:temp_target.culture
					}
				}
			}
		}
		add = 60
	}
	if = {
		limit = {
			scope:friendship_target = {
				opinion = {
					target = scope:heir
					value <= 0
				}
				opinion = {
					target = scope:heir
					value > -40
				}
			}
		}
		add = 60
	}
	if = {
		limit = {
			scope:friendship_target = {
				opinion = {
					target = scope:heir
					value < -40
				}
			}
		}
		add = 200
	}
}

mpo_convert_capital_duchy_nomad_value = {
	value = 0
	if = {
		limit = {
			capital_county.kingdom = {
				any_de_jure_county = {
					count >= 20
					OR = {
						holder.liege = {
							this = root
						}
						holder = root
						holder.top_liege = {
							this = root
						}
					}
				}
			}
		}
		add = 100
	}
	if = {
		limit = {
			capital_county.kingdom = {
				any_de_jure_county = {
					count >= 35
					OR = {
						holder.liege = {
							this = root
						}
						holder = root
						holder.top_liege = {
							this = root
						}
					}
				}
			}
		}
		add = 100
	}
	if = {
		limit = {
			capital_county.kingdom = {
				any_de_jure_county = {
					count >= 50
					OR = {
						holder.liege = {
							this = root
						}
						holder = root
						holder.top_liege = {
							this = root
						}
					}
				}
			}
		}
		add = 100
	}
}

mpo_introduce_heir_prestige_cost = medium_prestige_value
mpo_introduce_heir_piety_cost = major_piety_value

age_compared_to_player_heir = {
	add = age
	subtract = root.player_heir.age
}

odds_steal_herd_scheme_misc_value = {
	value = 10
	add = {
		value = 0
		desc = scheme_odds.misc_modifiers

		if = {
			limit = {
				scope:target = {				
					has_opinion_modifier = {
						target = scope:owner
						modifier = attempted_to_steal_herd_crime
					}
				}
			}
			add = -50
		}
	}

	add = {
		value = scope:owner.prowess
		desc = scheme_odds.prowess.owner
	}

	if = {
		limit = {
			scope:owner = { has_trait = gallowsbait }
		}
		add = {
			value = 10
			desc = SCHEME_STEAL_HERD_GALLOWSBAIT
		}
	}

	# If it's a herder, even though you probably shouldn't be stealing from them anyways
	if = {
		limit = {
			scope:target = {
				government_has_flag = government_is_herder
			}
		}
		add = {
			value = -10 
			desc = scheme_odds.misc_is_herder
		}
	}
}

odds_steal_herd_scheme_misc_value = {
	value = 10
	add = {
		value = 0
		desc = scheme_odds.misc_modifiers

		if = {
			limit = {
				scope:target = {				
					has_opinion_modifier = {
						target = scope:owner
						modifier = attempted_to_steal_herd_crime
					}
				}
			}
			add = -50
		}
	}

	add = {
		value = scope:owner.prowess
		desc = scheme_odds.prowess.owner
	}

	if = {
		limit = {
			scope:owner = { has_trait = gallowsbait }
		}
		add = {
			value = 10
			desc = SCHEME_STEAL_HERD_GALLOWSBAIT
		}
	}

	# If it's a herder, even though you probably shouldn't be stealing from them anyways
	if = {
		limit = {
			scope:target = {
				government_has_flag = government_is_herder
			}
		}
		add = {
			value = -10 
			desc = scheme_odds.misc_is_herder
		}
	}
}

mpo_tsagaan_sar_gift_likely_value = {
	value = 25

	# Vassals should always gift
	if = { 
		limit = {
			is_vassal_of = scope:host
		}
		add = 20

		if = {
			limit = {
				is_powerful_vassal_of = scope:host
			}
			add = 10
		} 
	}

	# Employees should gift
	if = {
		limit = {
			is_councillor_of = scope:host
		}
		add = 25
	}
	if = {
		limit = {
			is_courtier_of = scope:host
			has_any_court_position = yes
		}
		add = 15
	}

	# Don't want to piss him/her off
	if = { 
		limit = {
			has_dread_level_towards = {
				target = scope:host
				level = 1
			}
		}
		add = 25
	}

	if = {
		limit = {
			has_dread_level_towards = {
				target = scope:host
				level = 2
			}
		}
		add = 35
	} 

	# Relation
	if = {
		limit = {
			has_any_good_relationship_with_character_trigger = { CHARACTER = scope:host }
		}
		add = 15

		if = {
			limit = {
				likes_character_trigger = { CHARACTER = scope:host }
			}
			add = 10
		}
	}

	if = {
		limit = {
			has_any_bad_relationship_with_character_trigger = { CHARACTER = scope:host }
		}
		
		add = -10

		if = {
			limit = {
				has_relation_rival = scope:host 
			}
			add = -10
		}

		if = {
			limit = {
				has_relation_nemesis = scope:host 
			}
			add = -20
		}
	}

	if = {
		limit = {
			is_any_family_relation_or_spouse_trigger = { CHARACTER = scope:host }
		}
		add = 15
	}

	# Respect 
	if = {
		limit = {
			has_opinion_modifier = {
				modifier = respect_opinion
				target = scope:host 
			}
		}
		add = 5
	}

	if = {
		limit = {
			has_opinion_modifier = {
				modifier = disrespect_opinion
				target = scope:host 
			}
		}
		add = -5
	}

	if = {
		limit = {
			is_allied_to = scope:host
		}
		add = 10
	}

	# Personality
	if = {
		limit = {
			has_trait = generous
		}
		add = 25
	}

	if = {
		limit = {
			OR = {
				has_trait = greedy
				has_trait = avaricious
			}
		}
		add = -25
	}

	if = {
		limit = {
			OR = {
				has_trait = arrogant
				has_trait = arbitrary
				has_trait = callous
				has_trait = sadistic
			}
		}
		add = -10
	}
	
	if = {
		limit = {
			OR = {
				has_trait = compassionate
				has_trait = gregarious
			}
		}
		add = 10
	}

	# I'm broke!
	if = {
		limit = {
			OR = {
				short_term_gold <= minor_gold_value
				domicile ?= { herd <= minor_herd_value }
			}
		}
		add = -25
	}
	if = {
		limit = {
			is_lowborn = yes
		}
		add = -50
	}

	if = {
		limit = {
			scope:host = {
				has_legitimacy = yes 
			}
		}

		add = {
			value = 5 
			multiply = scope:host.legitimacy_level
		}
	}

	add = {
		value = 10
		multiply = scope:host.prestige_level
	}

	add = {
		value = scope:host.tyranny
		multiply = -2
	}

	add = {
		value = "opinion(scope:host)"
		divide = 3
	}

	min = 0
	max = 100
}

mpo_tsagaan_sar_guest_count = {
	value = 0
	involved_activity = {
        every_attending_character = {
            limit = {
                is_adult = yes 
                NOT = { this = root }
				can_gift_anything_trigger = yes
            }
			add = 1
		}
	}
}

mpo_tsagaan_sar_guest_gifters = {
	involved_activity = {
        every_attending_character = {
            limit = {
                is_adult = yes 
                NOT = { this = root }
				can_gift_anything_trigger = yes
				var:tsagaan_sar_gift ?= flag:will_gift
            }
			add = 1
		}
	}
}

mpo_tsagaan_sar_guest_gifters_no = {
	involved_activity = {
        every_attending_character = {
            limit = {
                is_adult = yes 
                NOT = { this = root }
				can_gift_anything_trigger = yes
				var:tsagaan_sar_gift ?= flag:no_gift
            }
			add = 1
		}
	}
}

miniscule_gold_value = {
	value = tiny_gold_value
}

tiny_gold_value_double = {
	value = tiny_gold_value
	multiply = 2
}

mpo_zodiac_calculation_value_no_decimal = {
	value = current_year
	divide = 12
	floor = yes
}

mpo_zodiac_calculation_value = {
	value = current_year
	divide = 12
	subtract = mpo_zodiac_calculation_value_no_decimal # To just get the decimal
	multiply = 12
	round = yes	
}

### FERTILITY GAIN/LOSS VALUES

miniscule_county_fertility_value = 5
minor_county_fertility_value = 10
medium_county_fertility_value = 20
major_county_fertility_value = 30
extreme_county_fertility_value = 40
massive_county_fertility_value = 50
monumental_county_fertility_value = 75

miniscule_county_fertility_loss = -5
minor_county_fertility_loss = -10
medium_county_fertility_loss = -20
major_county_fertility_loss = -30
extreme_county_fertility_loss = -40
massive_county_fertility_loss = -50
monumental_county_fertility_loss = -75

miniscule_county_fertility_gain = 5
minor_county_fertility_gain = 10
medium_county_fertility_gain = 20
major_county_fertility_gain = 30
extreme_county_fertility_gain = 40
massive_county_fertility_gain = 50
monumental_county_fertility_gain = 75

herder_list_county_fertility_value = {
	value = 0
	every_in_list = {
		list = herder_list
		add = 1
	}
	multiply = medium_county_fertility_value
	max = 100
}

fishing_counties_gold_value = {
	value = 4
	every_in_list = {
		list = fishing_counties
		add = 2
	}
	max = 100
}

fishing_counties_gold_high_value = {
	value = 8
	every_in_list = {
		list = fishing_counties
		add = 4
	}
	max = 100
}

### OBEDIENCE VALUES

# Used by Code, do not rename or remove
# Used to determine how much obedience_value must reach in order for
# the root character to be considered 'obedient'
#
# root = the character we're calculating the threshold for
obedience_threshold = {
	value = {
		value = 50
		desc = BASE
	}
	if = {  # Duke
		limit = { obedience_target.primary_title.tier ?= tier_duchy }
		add = {
			value = 20
			desc = duchy
		}
	}
	else_if = {  # King
		limit = { obedience_target.primary_title.tier ?= tier_kingdom }
		add = {
			value = 50
			desc = kingdom
		}
	}
	else_if = {  # Emperor
		limit = { obedience_target.primary_title.tier ?= tier_empire }
		add = {
			value = 100
			desc = empire
		}
	}
	if = {  # Yeke Jarquchi / Chief Law Overseer bonus
		limit = { exists = overlord.court_position:yeke_jarquchi_court_position }
		add = {
			value = -1
			multiply = "overlord.court_position:yeke_jarquchi_court_position.aptitude(yeke_jarquchi_court_position)"
			min = -5
			max = 0
			desc = court_position_jarquchi_obedience_modifier
		}
	}
}

# Used by Code, do not rename or remove
# Used to determine if a character is obedient to another character
# Any resulting value greater than obedience_threshold above will
# make the root character 'obedient'
# Note: tributaries are considered independent
#
# root = the character for whom we are changing the obedience value
obedience_value = {
	value = {
		value = 0
		desc = BASE
	}
	if = {
		limit = {
			exists = obedience_target 
		}
		if = {
			limit = { # Herders are ALWAYS obedient -- we don't even run the rest of calculations
				government_has_flag = government_is_herder
			}
			add = {
				value = obedience_threshold
				add = 1000
				desc = obedience_value_herder
			}
		}
		else = {
			# Have you been overruled to NOT be obedient?
			if = {
				limit = {
					has_variable = not_obedient_humiliation_var
					var:not_obedient_humiliation_var = obedience_target
				}
				add = { value = -850 desc = not_obedient_humiliation_var_tt }
			}
			else_if = {
				limit = {
					has_variable = not_obedient_declined_call
					var:not_obedient_declined_call = obedience_target
				}
				add = { value = -850 desc = request_influence_war_recipient_declined_opinion }
			}
			else_if = { # If you're not overruled to be disobedient, do you have an obedience reason?
				limit = {
					has_obedience_reason = obedience_target
				}
				add = { value = 1000 desc = opinion_obedient_reason }
			}
			
			add = { # Opinion
				desc = obedience_value_opinion
				value = "opinion(obedience_target)"
			}
			# Lifestyle Perks 
			if = {
				limit = {
					obedience_target = { has_perk = loyalty_and_respect_perk }
					is_spouse_of = obedience_target
				}
				add = { value = 25 desc = obedience_value_loyalty_and_respect } # If you change this value remember changing it in the perk loc key as well
			}
			if = {
				limit = {
					obedience_target = { has_perk = honored_to_serve_perk }
					is_kurultai_trigger = yes
				}
				add = { value = 25 desc = obedience_value_honored_to_serve } # If you change this value remember changing it in the perk loc key as well
			}
			# Family
			if = {
				limit = { is_primary_heir_of = obedience_target }
				add = { value = 250 desc = obedience_value_heir }
			}
			else_if = { # You are not the preferred heir
				limit = {
					is_male = yes
					is_child_of = obedience_target
					obedience_target = {
						OR = {
							has_realm_law = male_only_law
							has_realm_law = male_preference_law
							has_realm_law = equal_law
						}
					}
				}
				add = { value = -100 desc = obedience_value_heir_not_preferred }
			}
			else_if = {
				limit = { is_spouse_of = obedience_target }
				add = { value = 50 desc = obedience_value_spouse }
			}
			else_if = {
				limit = { is_child_of = obedience_target }
				add = { value = 50 desc = obedience_value_child }
			}
			else_if = {
				limit = { is_concubine_of = obedience_target }
				add = { value = 25 desc = obedience_value_concubine }
			}
			else_if = {
				limit = { is_close_family_of = obedience_target }
				add = { value = 25 desc = obedience_value_close_family }
			}
			else_if = {
				limit = { is_extended_family_of = obedience_target }
				add = { value = 10 desc = obedience_value_extended_family }
			}

			#Yurts
			if = {
				limit = {
					exists = obedience_target.domicile
				}
				if = {
					limit = {
						OR = {
							has_council_position = councillor_kurultai_1
							has_council_position = councillor_kurultai_2
							has_council_position = councillor_kurultai_3
							has_council_position = councillor_kurultai_4
						}
					}
					obedience_target.domicile = {
						switch = {
							trigger = has_domicile_parameter
							nomad_yurt_kurultai_obedience_per_piety_lvl_1 = {
								add = { value = prev.obedience_target.piety_level desc = kurultai_mystical_yurt_01_domicile_building }
							}
							nomad_yurt_kurultai_obedience_per_piety_lvl_2 = {
								add = { value = prev.obedience_target.piety_level multiply = 2 desc = kurultai_mystical_yurt_01_domicile_building }
							}
						}
						switch = {
							trigger = has_domicile_parameter
							nomad_yurt_kurultai_more_loyal_lvl_1 = {
								add = { value = 6 desc = kurultai_yurt_01 }
							}
							nomad_yurt_kurultai_more_loyal_lvl_2 = {
								add = { value = 12 desc = kurultai_yurt_01 }
							}
							nomad_yurt_kurultai_more_loyal_lvl_3 = {
								add = { value = 18 desc = kurultai_yurt_01 }
							}
						}
					}
				}
				else_if = {
					limit = {
						is_courtier_of = obedience_target
					}
					obedience_target.domicile = {
						switch = {
							trigger = has_domicile_parameter
							loyal_soldiers_yurt_more_obedient_lvl_1 = {
								add = { value = 4 desc = loyal_soldiers_yurt_06_domicile_building }
							}
							loyal_soldiers_yurt_more_obedient_lvl_2 = {
								add = { value = 8 desc = loyal_soldiers_yurt_06_domicile_building }
							}
							loyal_soldiers_yurt_more_obedient_lvl_3 = {
								add = { value = 16 desc = loyal_soldiers_yurt_06_domicile_building }
							}
						}
					}
				}
				if = {
					limit = {
						obedience_target = {
							has_character_flag = established_paiza_system
						}
						any_equipped_character_artifact = {
							root = { can_benefit_from_artifact = prev }
							exists = var:paiza_patron
							var:paiza_patron = {
								this = obedience_target
								is_gurkhan = yes
							}
						}
					}
					obedience_target.domicile = {
						switch = {
							trigger = has_domicile_parameter
							nomad_yurt_paiza_obedience_bonus_lvl_1 = {
								add = { value = 8 desc = domicile_building_parameter_nomad_yurt_paiza_obedience_bonus_lvl_1 }
							}
							nomad_yurt_paiza_obedience_bonus_lvl_2 = {
								add = { value = 16 desc = domicile_building_parameter_nomad_yurt_paiza_obedience_bonus_lvl_2 }
							}
							nomad_yurt_paiza_obedience_bonus_lvl_3 = {
								add = { value = 24 desc = domicile_building_parameter_nomad_yurt_paiza_obedience_bonus_lvl_3 }
							}
						}
					}
				}
			}
			
			# Relationships
			if = {
				limit = { has_relation_blood_brother = obedience_target }
				add = { value = 1250 desc = obedience_value_blood_brother }
			}
			else_if = {
				limit = { has_relation_best_friend = obedience_target }
				add = { value = 1000 desc = obedience_value_best_friend }
			}
			else_if = {
				limit = { has_relation_friend = obedience_target }
				add = { value = 100 desc = obedience_value_friend }
			}
			else_if = {
				limit = { has_relation_ward = obedience_target }
				add = { value = 50 desc = obedience_value_ward }
			}
			else_if = {
				limit = { has_relation_guardian = obedience_target }
				add = { value = 50 desc = obedience_value_guardian }
			}
			else_if = {
				limit = { has_relation_rival = obedience_target }
				add = { value = -100 desc = obedience_value_rival }
			}
			else_if = {
				limit = { has_relation_nemesis = obedience_target }
				add = { value = -1000 desc = obedience_value_nemesis }
			}
			else_if = {
				limit = {
					NOR = {
						has_relation_lover = obedience_target
						has_relation_potential_lover = obedience_target
						has_relation_crush = obedience_target
						has_relation_potential_friend = obedience_target
					}
				}
				add = { value = -50 desc = obedience_value_not_good_relationship }
			}

			# Employment
			if = { # Is this person in your kurultai?
				limit = {
					this != obedience_target.primary_spouse
					is_councillor_of = obedience_target
				}
				add = { value = 25 desc = obedience_value_councillor }
			}
			else_if = { # They're not in your Kurultai
				limit = {
					NOT = {
						is_councillor_of = obedience_target
					}
					can_be_any_kurultai_trigger = { COURT_OWNER = obedience_target }
				}
				add = { value = -25 desc = obedience_value_no_kurultai }
			}
			if = { # Is this your Yeke Jarquchi?
				limit = {
					obedience_target.court_position:yeke_jarquchi_court_position ?= this
				}
				add = { value = 50 desc = obedience_value_yeke_jarquchi }
			}
			else_if = { # Is this your Court Astrologer?
				limit = {
					obedience_target.court_position:court_astrologer_court_position ?= this
				}
				add = { value = 25 desc = obedience_value_court_astrologer }
			}
			else_if = { # Or are they employed by you in any other way?
				limit = {
					is_courtier_of = obedience_target
					has_any_court_position = yes
				}
				add = { value = 15 desc = obedience_value_court_position }
			}
			else_if = { # You don't employ them
				limit = {
					is_courtier_of = obedience_target
					has_any_court_position = no
				}
				add = { value = -15 desc = obedience_value_no_court_position }
			}
			
			# Legitimacy
			if = {
				limit = {
					obedience_target = {
						has_nomadic_legitimacy = yes
						legitimacy_level >= 3
					}
				}
				add = { value = 25 desc = obedience_value_high_legitimacy }
			}
			else = {
				add = { value = -15 desc = obedience_value_low_legitimacy }
			}
			
			# Traits
			switch = {
				trigger = has_trait
				loyal = { add = { value = 25 desc = personality_traitdesc.trait.loyal } }
				craven = { add = { value = 25 desc = personality_traitdesc.trait.craven } }
				content = { add = { value = 10 desc = personality_traitdesc.trait.content } }
				humble = { add = { value = 10 desc = personality_traitdesc.trait.humble } }
				gregarious = { add = { value = 5 desc = personality_traitdesc.trait.gregarious } }
				diligent = { add = { value = 5 desc = personality_traitdesc.trait.diligent } }
				disloyal = { add = { value = -25 desc = personality_traitdesc.trait.disloyal } }
				deceitful = { add = { value = -25 desc = personality_traitdesc.trait.deceitful } }
				stubborn = { add = { value = -25 desc = personality_traitdesc.trait.stubborn } }
				arrogant = { add = { value = -20 desc = personality_traitdesc.trait.arrogant } }
				paranoid = { add = { value = -10 desc = personality_traitdesc.trait.paranoid } }
				ambitious = { add = { value = -10 desc = personality_traitdesc.trait.ambitious } }
				brave = { add = { value = -5 desc = personality_traitdesc.trait.brave } }
			}
			if = {
				limit = {
					obedience_target = { has_trait = bloodline_god_3 }
				}
				add = { value = 1666 desc = obedience_bloodline_god_3 }
			}
			if = {
				limit = {
					obedience_target = { has_trait = greatest_of_khans }
				}
				add = { value = 50 desc = obedience_greatest_of_khans }
			}
			else_if = {
				limit = {
					obedience_target = { has_trait = conqueror }
				}
				add = { value = 35 desc = obedience_conqueror_trait }
			}
			else_if = {
				limit = {
					obedience_target = { has_character_modifier = the_great_khan_modifier }
				}
				add = { value = 20 desc = obedience_greatest_of_khans_descendant }
			}

			# Other
			if = { # Children
				limit = { is_adult = no }
				if = {
					limit = { is_courtier_of = obedience_target }
					add = { value = 125 desc = obedience_value_child_courtier }
				}
				else = {
					add = { value = 100 desc = obedience_value_child_vassal }
					switch = {
						trigger = has_trait
						rowdy = { add = { value = -25 desc = personality_traitdesc.trait.rowdy } }
						bossy = { add = { value = -25 desc = personality_traitdesc.trait.bossy } }
						charming = { add = { value = 25 desc = personality_traitdesc.trait.charming } }
						curious = { add = { value = -25 desc = personality_traitdesc.trait.curious } }
						pensive = { add = { value = -25 desc = personality_traitdesc.trait.pensive } }
					}
				}
			}
			if = { # Low Prowess
				limit = {
					obedience_target.prowess <= this.prowess
				}
				add = { value = -15 desc = obedience_value_low_prowess }
			}

			if = { # Low Dread
				limit = {
					obedience_target.dread < this.dread
				}
				add = { value = -10 desc = obedience_value_low_dread }
			}
			else_if = { # High Dread
				limit = {
					obedience_target.dread > 10
					obedience_target.dread > this.dread 
				}
				add = { 
					value = obedience_target.dread 
					multiply = 0.5
					desc = obedience_value_high_dread 
				}
			} 
			else_if = {
				limit = {
					obedience_target.dread < 10
				}
				add = { value = -5 desc = obedience_value_insignificant_dread }
			}

			if = { # Truce
				limit = {
					has_truce = obedience_target
				}
				add = { value = 50 desc = obedience_value_truce }
			}

			if = { # Larger Herd
				limit = {
					exists = domicile
					domicile.herd >= 100
					domicile.herd > obedience_target.domicile.herd
				}
				add = { value = -500 desc = obedience_value_herd_size }
			}

			if = { # Larger army
				limit = {
					current_military_strength >= 100
					current_military_strength > obedience_target.current_military_strength
				}
				add = { value = -500 desc = obedience_value_military_might }
			}

			#CULTRADS
			if = {
				limit = {
					culture = {
						has_cultural_parameter = nomadic_loyal_soldiers_obedience
					}
				}
				add = { value = 25 desc = obedience_value_loyal_soldiers }
			}
		}
	}
}

excess_herd_opinion_value = {
	min = 10
	max = 50

	add = 10

	if = {
		limit = {
			excess_herd_value >= twenty_percent_over_herd_value
		}
		add = 10
	}
	if = {
		limit = {
			excess_herd_value >= forty_percent_over_herd_value
		}
		add = 10
	}
	if = {
		limit = {
			excess_herd_value >= sixty_percent_over_herd_value
		}
		add = 10
	}
	if = {
		limit = {
			excess_herd_value >= eighty_percent_over_herd_value
		}
		add = 10
	}
}

twenty_percent_over_herd_value = {
	value = domicile.max_herd
	add = domicile.twenty_percent_herd_value
}

forty_percent_over_herd_value = {
	value = domicile.max_herd
	add = domicile.forty_percent_herd_value
}

sixty_percent_over_herd_value = {
	value = domicile.max_herd
	add = domicile.sixty_percent_herd_value
}

eighty_percent_over_herd_value = {
	value = domicile.max_herd
	add = domicile.eighty_percent_herd_value
}

age_minus_ten = {
	value = age
	subtract = 10
}

age_plus_ten = {
	value = age
	add = 10
}

settlement_issue_control_reward = 25
settlement_issue_control_penalty = -25
settlement_issue_herd_reward = minor_herd_value_static
settlement_issue_fertility_reward = tiny_county_fertility_level_gain

mpo_expand_steppe_prestige_cost = major_prestige_value
mpo_expand_steppe_gold_cost = {
	value = medium_gold_value
}

################################################
### NOMAD MAA REFILL VALUES

herd_refill_value = {
	value = 0.75
	if = {
		limit = {
			trigger_if = {
				limit = { exists = scope:nomad_temp }
			}
			trigger_else = { always = no }
		}
		multiply = {
			add = scope:nomad_temp.martial
			subtract = 8
			divide = 100
			add = 1
		}
	}
}

herd_refill_value_tt = {
	value = 0.75
	multiply = {
		add = martial
		subtract = 8
		divide = 100
		add = 1
	}
}

martial_discount_herd_refill_value_tt = {
	add = martial
	subtract = 8
	multiply = -1
	divide = 100
}

replenishable_troops_with_herd_value = {
	value = replenishable_troops_value
	max = {
		add = scope:current_herd_max_value_scope
		multiply = herd_refill_value
	}
}

replenishable_troops_max_herd_value = {
	value = 0
	scope:actor = {
		every_maa_regiment = {
			add = {
				add = maa_max_troops_count
				subtract = maa_current_troops_count
				if = {
					limit = { maa_regiments_cost_more_to_reinforce_per_soldier_trigger = yes }
					multiply = maa_regiments_cost_more_to_reinforce_per_soldier_trigger_mult
				}
			}
		}
	}
	max = scope:actor.domicile.herd
	divide = herd_refill_value
	multiply = -1
}

replenishable_troops_payed_herd_tt_value = {
	value = 0
	every_maa_regiment = {
		add = {
			add = maa_max_troops_count
			subtract = maa_current_troops_count
			if = {
				limit = { maa_regiments_cost_more_to_reinforce_per_soldier_trigger = yes }
				multiply = maa_regiments_cost_more_to_reinforce_per_soldier_trigger_mult
			}
		}
	}
	divide = herd_refill_value_tt
	max = domicile.herd
}

replenishable_troops_max_herd_tt_value = {
	value = 0
	every_maa_regiment = {
		add = {
			add = maa_max_troops_count
			subtract = maa_current_troops_count
		}
	}
	max = {
		value = domicile.herd
		multiply = herd_refill_value_tt
	}
}

######################################################

high_skill_court_astrologer_cost = {
	value = medium_gold_value
}

low_skill_court_astrologer_cost = {
	value = minor_gold_value
}

high_skill_siege_engineer_cost = {
	value = medium_gold_value
}

low_skill_siege_engineer_cost = {
	value = minor_gold_value
}

high_skill_foreign_emissary_cost = {
	value = medium_gold_value
}

low_skill_foreign_emissary_cost = {
	value = minor_gold_value
}

######################################################

nomadic_cultural_maa_bonus_low_value = 0.1
nomadic_cultural_maa_bonus_medium_value = 0.2
nomadic_cultural_maa_bonus_high_value = 0.4

dominate_title_current_ally_strength = {
	value = root.current_military_strength
	every_tributary = {
		limit = {
			vassal_contract_has_flag = tributary_contract_tributary_forced_war_override
		}
		add = root.current_military_strength
	}
	every_ally = {
		add = root.current_military_strength
	}
}

dominate_title_current_enemy_strength = {
	value = 0
	root.primary_title.de_jure_liege ?= {
		every_de_jure_county_holder = {
			limit = {
				is_landed = yes
				NOR = {
					is_allied_to = root
					top_liege = root
					top_suzerain ?= root
					government_has_flag = government_is_herder
				}
				is_independent_ruler = yes
			}
			add = current_military_strength
		}
	}
}

mpo_de_jure_title_value = {
	value = root.highest_held_title_tier
	subtract = 1
}

sub_realm_with_tributaries_size = {
	value = {
		add = sub_realm_size
		every_tributary = {
			every_sub_realm_county = {
				add = 1
			}
			every_tributary = {
				every_sub_realm_county = {
					add = 1
				}
				every_tributary = {
					every_sub_realm_county = {
						add = 1
					}
					every_tributary = {
						every_sub_realm_county = {
							add = 1
						}
					}
				}
			}
		}
	}
}
mpo_greatest_of_khans_target_counties = {
	value = 50
}
mpo_greatest_of_khans_target_counties_tributaries = {
	value = 100
}

mpo_gok_world_conquest_target_counties = {
	value = 1000
}
mpo_gok_world_conquest_target_counties_tributaries = {
	value = 1500
}

ninety_percent_gold_value = {
	value = gold
	multiply = 0.9
}

negative_seventy_five_percent_prestige_value = {
	value = prestige
	multiply = -0.8
}

gok_obedient_vassals_strength_value = {
	value = 0
	every_in_list = {
		list = obedient_nomad_vassals
		limit = {
			any_character_war = {
				using_cb = mpo_great_war_of_defiance_cb
			}
		}
		add = 1
		if = {
			limit = {
				highest_held_title_tier >= tier_duchy
			}
			add = 2
		}
		if = {
			limit = {
				highest_held_title_tier >= tier_kingdom
			}
			add = 3
		}
	}
	min = 1
}

fought_gok_alone_value = {
	value = miniscule_dynasty_prestige_gain
	multiply = root.var:fought_for_gok_alone
	min = 1 
}

mpo_domicile_yurt_marriage_acceptance_value = {
	value = 0
	scope:actor.domicile ?= {
		switch = {
			trigger = has_domicile_parameter
			nomad_yurt_marriage_acceptance_lvl_1 = { add = 5 }
			nomad_yurt_marriage_acceptance_lvl_2 = { add = 10 }
			nomad_yurt_marriage_acceptance_lvl_3 = { add = 20 }
			nomad_yurt_marriage_acceptance_lvl_4 = { add = 30 }
		}
		switch = {
			trigger = has_domicile_parameter
			nomad_main_yurt_marriage_acceptance_lvl_1 = { add = 5 }
			nomad_main_yurt_marriage_acceptance_lvl_2 = { add = 10 }
			nomad_main_yurt_marriage_acceptance_lvl_3 = { add = 15 }
			nomad_main_yurt_marriage_acceptance_lvl_4 = { add = 20 }
		}
	}
}

potential_joiner_combined_value = {
	value = 0
	every_in_list = {
		list = potential_joiners
		add = 1
		if = {
			limit = {
				highest_held_title_tier >= tier_duchy
			}
			add = 2
		}
		if = {
			limit = {
				highest_held_title_tier >= tier_kingdom
			}
			add = 3
		}
	}
	min = 1
}


mpo_domicile_yurt_marriage_acceptance_value = {
	value = 0
	scope:actor.domicile ?= {
		switch = {
			trigger = has_domicile_parameter
			nomad_yurt_marriage_acceptance_lvl_1 = { add = 5 }
			nomad_yurt_marriage_acceptance_lvl_2 = { add = 10 }
			nomad_yurt_marriage_acceptance_lvl_3 = { add = 20 }
			nomad_yurt_marriage_acceptance_lvl_4 = { add = 30 }
		}
		switch = {
			trigger = has_domicile_parameter
			nomad_main_yurt_marriage_acceptance_lvl_1 = { add = 5 }
			nomad_main_yurt_marriage_acceptance_lvl_2 = { add = 10 }
			nomad_main_yurt_marriage_acceptance_lvl_3 = { add = 15 }
			nomad_main_yurt_marriage_acceptance_lvl_4 = { add = 20 }
		}
	}
}

sent_herd_opinion_value = {
	value = 5
	add = {
		if = {
			limit = {
				scope:actor.diplomacy > 0
			}
			add = {
				value = scope:actor.diplomacy
				multiply = 3
			}
		}
		if = {
			limit = {
				scope:recipient.ai_greed > 0
			}
			add = {
				value = scope:recipient.ai_greed
				divide = 3
			}
		}
		if = {
			limit = {
				scope:recipient.liege = scope:actor
			}
			divide = 1.5
		}
		if = {
			limit = {
				scope:recipient = scope:actor.faith.religious_head
			}
			divide = 3
		}
		if = {
			limit = {
				scope:actor.culture ?= {
					has_innovation = fp3_innovation_fritware
				}
			}
			multiply = 1.2
		}
		max = 100
	}
	if = {
		limit = {
			scope:actor.culture = { has_cultural_parameter = more_gift_opinion }
		}
		multiply = 1.2
	}
	if = {
		limit = {
			scope:actor = { has_perk = thoughtful_perk }
		}
		multiply = 2
	}
}

herd_gift_value = {
	value = scope:actor.domicile.minor_herd_value
	if = {
		limit = {
			scope:recipient.ai_greed > 0
		}
		add = {
			value = scope:recipient.ai_greed
			divide = 4
		}
	}

	if = {
		limit = {
			scope:actor = {
				exists = dynasty
				dynasty = {
					has_dynasty_perk = fp1_adventure_legacy_2
				}
			}
		}
		multiply = 0.5
	}
}

mpo_current_disobedient_kurultai_value = {
	value = 0
	every_councillor = {
		limit = {
			OR = {
				root.cp:councillor_kurultai_1 ?= this
				root.cp:councillor_kurultai_2 ?= this
				root.cp:councillor_kurultai_3 ?= this
				root.cp:councillor_kurultai_4 ?= this
			}
			is_obedient = no
		}
		add = 1
	}
	switch = {
		trigger = has_realm_law
		nomadic_authority_5 = {
			ordered_child = {
				order_by = age
				max = define:NKurultai|KURULTAI_SUCCESSION_CHILD_ELECTORS_DOMINANCE_5
				check_range_bounds = no
				limit = {
					age >= define:NKurultai|KURULTAI_SUCCESSION_CHILD_MINIMUM_AGE
					obedience_target = root
				}
				if = {
					limit = { 
						NOR = { 
							is_obedient_to = root 
							root.cp:councillor_kurultai_1 ?= this
							root.cp:councillor_kurultai_2 ?= this
							root.cp:councillor_kurultai_3 ?= this
							root.cp:councillor_kurultai_4 ?= this
						} 
					}
					add = 1
				}
			}
		}
		nomadic_authority_4 = {
			ordered_child = {
				order_by = age
				max = define:NKurultai|KURULTAI_SUCCESSION_CHILD_ELECTORS_DOMINANCE_4
				check_range_bounds = no
				limit = {
					age >= define:NKurultai|KURULTAI_SUCCESSION_CHILD_MINIMUM_AGE
					obedience_target = root
				}
				if = {
					limit = { 
						NOR = { 
							is_obedient_to = root 
							root.cp:councillor_kurultai_1 ?= this
							root.cp:councillor_kurultai_2 ?= this
							root.cp:councillor_kurultai_3 ?= this
							root.cp:councillor_kurultai_4 ?= this
						} 
					}
					add = 1
				}
			}
		}
		nomadic_authority_3 = {
			ordered_child = {
				order_by = age
				max = define:NKurultai|KURULTAI_SUCCESSION_CHILD_ELECTORS_DOMINANCE_3
				check_range_bounds = no
				limit = {
					age >= define:NKurultai|KURULTAI_SUCCESSION_CHILD_MINIMUM_AGE
					obedience_target = root
				}
				if = {
					limit = { 
						NOR = { 
							is_obedient_to = root 
							root.cp:councillor_kurultai_1 ?= this
							root.cp:councillor_kurultai_2 ?= this
							root.cp:councillor_kurultai_3 ?= this
							root.cp:councillor_kurultai_4 ?= this
						} 
					}
					add = 1
				}
			}
		}
		nomadic_authority_2 = {
			ordered_child = {
				order_by = age
				max = define:NKurultai|KURULTAI_SUCCESSION_CHILD_ELECTORS_DOMINANCE_2
				check_range_bounds = no
				limit = {
					age >= define:NKurultai|KURULTAI_SUCCESSION_CHILD_MINIMUM_AGE
					obedience_target = root
				}
				if = {
					limit = { 
						NOR = { 
							is_obedient_to = root 
							root.cp:councillor_kurultai_1 ?= this
							root.cp:councillor_kurultai_2 ?= this
							root.cp:councillor_kurultai_3 ?= this
							root.cp:councillor_kurultai_4 ?= this
						} 
					}
					add = 1
				}
			}
		}
		nomadic_authority_1 = {
			ordered_child = {
				order_by = age
				max = define:NKurultai|KURULTAI_SUCCESSION_CHILD_ELECTORS_DOMINANCE_1
				check_range_bounds = no
				limit = {
					age >= define:NKurultai|KURULTAI_SUCCESSION_CHILD_MINIMUM_AGE
					obedience_target = root
				}
				if = {
					limit = { 
						NOR = { 
							is_obedient_to = root 
							root.cp:councillor_kurultai_1 ?= this
							root.cp:councillor_kurultai_2 ?= this
							root.cp:councillor_kurultai_3 ?= this
							root.cp:councillor_kurultai_4 ?= this
						} 
					}
					add = 1
				}
			}
		}
	}
}

mpo_missing_kurultai_value = {
	value = 0
	if = {
		limit = {
			NOT = { exists = cp:councillor_kurultai_1 }
		}
		add = 1
	}
	if = {
		limit = {
			NOT = { exists = cp:councillor_kurultai_2 }
		}
		add = 1
	}
	if = {
		limit = {
			NOT = { exists = cp:councillor_kurultai_3 }
		}
		add = 1
	}
	if = {
		limit = {
			NOT = { exists = cp:councillor_kurultai_4 }
		}
		add = 1
	}
}

gok_era_scaling_value = {
	if = {
		limit = {
			current_date >= 1300
		}
		value = 5
	}
	else_if = {
		limit = {
			any_culture_global = {
				has_cultural_era_or_later = culture_era_late_medieval
			}
		}
		value = 3
	}
	else_if = {
		limit = {
			any_culture_global = {
				has_cultural_era_or_later = culture_era_high_medieval
			}
		}
		value = 2
	}
	else_if = {
		limit = {
			any_culture_global = {
				has_cultural_era_or_later = culture_era_early_medieval
			}
		}
		value = 1.5
	}
	else = {
		value = 1
	}
}

gok_nomadic_riders_small_value = {
	value = 12
	multiply = gok_era_scaling_value
}

gok_nomadic_riders_large_value = {
	value = 20
	multiply = gok_era_scaling_value
}

gok_maa_small_value = {
	value = 1
	multiply = gok_era_scaling_value
}

gok_maa_smallish_value = {
	value = 2
	multiply = gok_era_scaling_value
}

gok_maa_medium_value = {
	value = 3
	multiply = gok_era_scaling_value
}

gok_maa_largish_value = {
	value = 4
	multiply = gok_era_scaling_value
}

gok_maa_large_value = {
	value = 5
	multiply = gok_era_scaling_value
}

#These are the values that will have a HUGE impact on how strong the Greatest of Khans gets
#They provide troops when he subjugates lands through war or interaction

gok_subjugated_army_levy_value = {
	value = 200
	if = {
		limit = {
			scope:army_giver = {
				highest_held_title_tier >= tier_kingdom
			}
		}
		add = 300
	}
	if = {
		limit = {
			scope:army_giver = {
				highest_held_title_tier >= tier_empire
			}
		}
		add = 300
	}
	if = {
		limit = {
			scope:army_giver = {
				realm_size >= 1
			}
		}
		add = {
			value = scope:army_giver.sub_realm_size
			multiply = 20
		}
	}
	multiply = gok_era_scaling_value
}
gok_subjugated_army_maa_value_very_large = {
	value = 0
	if = {
		limit = {
			scope:army_giver = {
				realm_size >= 1
			}
		}
		add = {
			value = scope:army_giver.sub_realm_size
			divide = 5
		}
	}
	multiply = gok_era_scaling_value
	floor = yes
	max = 24
}
gok_subjugated_army_maa_value_large = {
	value = 0
	if = {
		limit = {
			scope:army_giver = {
				realm_size >= 1
			}
		}
		add = {
			value = scope:army_giver.sub_realm_size
			divide = 10
		}
	}
	multiply = gok_era_scaling_value
	floor = yes
	max = 16
}
gok_subjugated_army_maa_value_medium = {
	value = 0
	if = {
		limit = {
			scope:army_giver = {
				realm_size >= 1
			}
		}
		add = {
			value = scope:army_giver.sub_realm_size
			divide = 15
		}
	}
	multiply = gok_era_scaling_value
	floor = yes
	max = 12
}
gok_subjugated_army_maa_value_small = {
	value = 0
	if = {
		limit = {
			scope:army_giver = {
				realm_size >= 1
			}
		}
		add = {
			value = scope:army_giver.sub_realm_size
			divide = 20
		}
	}
	multiply = gok_era_scaling_value
	floor = yes
	max = 8
}
gok_subjugated_army_maa_value_very_small = {
	value = 0
	if = {
		limit = {
			scope:army_giver = {
				realm_size >= 1
			}
		}
		add = {
			value = scope:army_giver.sub_realm_size
			divide = 40
		}
	}
	multiply = gok_era_scaling_value
	floor = yes
	max = 4
}

gok_retribution_dread_value = {
	value = 0
	every_in_list = {
		list = devastation_area
		add = 2
	}
}

gok_retribution_herd_value = {
	value = 0
	every_in_list = {
		list = devastation_area
		add = scope:attacker.domicile.miniscule_herd_gain
	}
}

gok_retribution_gold_value = {
	value = 0
	every_in_list = {
		list = devastation_area
		add = {
			add = development_level
			multiply = 3
		}
	}
}
