
### HOUSE RELATIONS
house_relation_casus_belli_discount_value = 0.75
house_relation_personal_scheme_bonus_value = 15
house_relation_hostile_scheme_bonus_value = 15
house_relation_increased_marriage_acceptance = 25
house_relation_decreased_marriage_acceptance = -25
house_relation_less_likely_war_target = -150

house_relation_actions_to_improve_level_threshold_value = 10 # How many actions before House level changes
house_relation_actions_to_damage_level_threshold_value = { # Same as above, but negative
	value = house_relation_actions_to_improve_level_threshold_value
	multiply = -1
}

house_relation_improve_minor_value = 0.1
house_relation_improve_medium_value = 0.2
house_relation_improve_major_value = 0.3
house_relation_damage_minor_value = { # Same as above, but negative
	value = house_relation_improve_minor_value
	multiply = -1
}
house_relation_damage_medium_value = {
	value = house_relation_improve_medium_value
	multiply = -1
}
house_relation_damage_major_value = {
	value = house_relation_improve_major_value
	multiply = -1
}
house_relation_damage_massive_value = {
	value = house_relation_improve_major_value
	multiply = -2
}
house_relation_damage_monumental_value = {
	value = house_relation_improve_major_value
	multiply = -3
}

improve_house_relation_calculated_value = {
	value = house_relation_improve_major_value
	multiply = 4 #Since we know we are in Japan to use the interaction
}

# Imperial Grace loss values depending on phase
imperial_grace_loss_situation_dynastic_cycle_phase_stability = -1
imperial_grace_loss_situation_dynastic_cycle_phase_stability_expansion = -2
imperial_grace_loss_situation_dynastic_cycle_phase_stability_advancement = -1
imperial_grace_loss_situation_dynastic_cycle_phase_instability = -3
imperial_grace_loss_situation_dynastic_cycle_phase_instability_conquest = -3
imperial_grace_loss_situation_dynastic_cycle_phase_chaos = -5

# This value is used for the ai_expected_level param for mandate_legitimacy, but can also be used directly without a vassal scope
# It's set to max, unless Cycle is in Stability Era, then it is lower by 2 for the first 50 years and lower by 1 for another 50 years
dynastic_cycle_legitimacy_expectation = {
	value = 7 #max
	if = {
		limit = {
			situation:dynastic_cycle ?= {
				OR = {
					situation_current_phase = situation_dynastic_cycle_phase_stability_expansion
					situation_current_phase = situation_dynastic_cycle_phase_stability_advancement
				}
				has_variable = stability_phase_start_date
			}
		}
		if = {
			limit = {
				situation:dynastic_cycle = {
					var:stability_phase_start_date <= {
						value = current_date
						subtract = 18250
					}
				}
			}
			add = -2
		}
		if = {
			limit = {
				situation:dynastic_cycle = {
					var:stability_phase_start_date <= {
						value = current_date
						subtract = 36500
					}
				}
			}
			add = -1
		}
	}
}

celestial_investiture_trade_bonus_max = 50

grand_guardian_aptitude_modifier_scaling_value = {
	value = 1
	if = {
		limit = { exists = root }
		add = root.aptitude:grand_guardian_court_position
	}
	desc = MODIFIER_DEFINITION_MAIN_DESC_GRAND_GUARDIAN_APTITUDE
}

## IE LOC VALUES
child_exam_min_age = {
	value = 6
}

metropolitan_exam_final_entrants = {
	value = 10
}

metropolitan_exam_final_entrants_loc = {
	value = metropolitan_exam_final_entrants
}

## LOCAL EXAMINATION VALUES
examination_success_learning_value = {
	value = learning
	multiply = 1.2
	ceiling = yes
	max = 30
}

examination_success_stewardship_value = {
	value = stewardship
	multiply = 1.2
	ceiling = yes
	max = 30
}

examination_success_martial_value = {
	value = martial
	multiply = 1.2
	ceiling = yes
	max = 30
}

examination_success_increase_miniscule_value = 5
examination_success_increase_minor_value = 10
examination_success_increase_medium_value = 15
examination_success_increase_major_value = 20
examination_success_increase_massive_value = 25


examination_merit_reward_base_value = medium_merit_value

child_examination_success_chance_value = {
	value = 0
	# EXAM TYPE
	add = {
		value = learning
		multiply = 1.2
		ceiling = yes
		max = 30
		desc = learning_modifier
	}
	# A Confucian Education will improve your chances
	add = {
		if = {
			limit = { has_trait = confucian_education }
			add = 5
		}
		desc = confucian_education_modifier
	}
	# Having a Tutor will improve your chances
	add = {
		if = {
			limit = { employs_court_position = court_tutor_court_position }
			add = 15
		}
		desc = tutor_modifier
	}
	# Having lost a parent will improve your chances
	add = {
		if = {
			limit = {
				any_parent = {
					is_alive = no
					count = all
				}
			}
			add = 10
		}
		desc = mourned_parent_modifier
	}
	# Let's also add the child's age
	add = {
		value = age
		desc = age_modifier
	}
	add = {
		if = {
			limit = {
				has_trait = curious
			}
			add = 5
		}
		desc = curious_modifier
	}
	# VARIABLES
	# Nr of safe bets at examination
	add = {
		if = {
			limit = { var:safe_bets > 0 }
			value = var:safe_bets
			multiply = 5
		}
		desc = played_it_safe_modifier
	}
	# MODIFIERS
	if = {
		limit = {
			has_character_modifier = tgp_local_exam_initial_success
		}
		add = {
			value = examination_success_increase_medium_value
			desc = exam_success_chance.tgp_local_exam_initial_success
		}
	}
	if = {
		limit = {
			has_character_modifier = tgp_local_exam_impressed_examiner
		}
		add = {
			value = examination_success_increase_major_value
			desc = exam_success_chance.tgp_local_exam_impressed_examiner
		}
	}
	if = {
		limit = {
			has_character_modifier = tgp_local_exam_strong_finish
		}
		add = {
			value = examination_success_increase_massive_value
			desc = exam_success_chance.tgp_local_exam_strong_finish
		}
	}
}

dynasty_legacy_influence_career_discount_value = -0.1

# Referenced to in code for the Merit tooltip (DO NOT REMOVE)
# displayed in MERIT_PROGRESSBAR_MARKER_TOOLTIP, if you change the value here be sure to update the loc key as well
movement_power_character_individual_merit_value = {
	value = merit_level
	multiply = 10
}

relevant_family_members_metropolitan_value = {
	value = var:num_exam_family_passed_metropolitan
}

relevant_family_members_palace_value = {
	value = prev.var:num_exam_family_passed_palace
	ceiling = yes
	max = 3
}

meritocratic_province_military_max_value = 8
meritocratic_province_protectorate_max_value = {
	value = 5
}

meritocratic_province_industrial_max_value = 8
meritocratic_province_metropolitan_max_value = {
	value = 5
}

# dejure governorship value for sidegrade appointments
# this is the prominence value
# root - title considered for appointment
appointment_title_value = {
	value = 0
	# We value titles differently depending on if it is a civilian or military appointment
	if = {
		limit = {
			OR = {
				holder ?= { vassal_contract_has_flag = meritocratic_civil_appointment }
				holder ?= { vassal_contract_has_flag = celestial_civil_appointment }
			}
		}
		# General gold income
		if = {
			limit = {
				tier >= tier_duchy
			}
			add = {
				every_de_jure_county = {
					add = {
						value = title_province.monthly_income
						multiply = 24
					}
				}
				desc = appointment_title_value.county_income
			}
		}
		else = {
			add = {
				value = title_province.monthly_income
				multiply = 24
				desc = appointment_title_value.capital_income
			}
		}
		
		# Distance to capital
		add = {
			value = 500
			subtract = {
				value = "title_province.squared_distance(root.holder.top_liege.capital_province)"
				multiply = 0.0001
			}
			min = 0
			desc = appointment_title_value.distance_to_capital
		}
	}
	else_if = {
		limit = {
			holder ?= {
				OR = {
					vassal_contract_has_flag = meritocratic_military_appointment
					vassal_contract_has_flag = celestial_military_appointment
					vassal_contract_has_flag = celestial_grand_marshal_obligation
				}
			}
		}
		
		# Army size
		add = {
			every_owned_title_maa_regiment = {
				add = {
					value = maa_size
				}
			}
			desc = appointment_title_value.maa_size
		}

		# Province size (to make larger provinces more attractive)
		if = {
			limit = {
				tier >= tier_duchy
			}
			add = {
				every_de_jure_county = {
					add = 10
				}
				desc = appointment_title_value.counties
			}
		}
		add = {
			every_title_to_title_neighboring_county = {
				limit = {
					holder.top_liege != prev.holder.top_liege
				}
				add = {
					value = 10
				}
			}
			desc = appointment_title_value.neighboring_enemy_counties
		}
		# A protectorate is more attractive
		if = {
			limit = {
				holder = { vassal_contract_has_flag = celestial_province_protectorate }
			}
			multiply = {
				value = 2
				desc = appointment_title_value.protectorate
			}
		}
	}
	
	# Minister titles
	if = {
		limit = {
			holder ?= {
				tgp_is_any_minister = yes
			}
		}
		add = {
			value = holder.top_liege.capital_province.monthly_income
			multiply = 1000
			desc = appointment_title_value.capital_income
		}
		if = {
			limit = {
				title:h_china.holder = {
					has_diarchy_type = grand_secretariat
					OR = {
						AND = {
							has_realm_law = grand_chancellor_law
							root = title:e_minister_chancellor
						}
						AND = {
							has_realm_law = grand_marshal_law
							root = title:e_minister_grand_marshal
						}
						AND = {
							has_realm_law = grand_censor_law
							root = title:e_minister_censor
						}
					}
				}
			}
			add = {
				value = 1000
				desc = appointment_title_value.diarch
			}
		}
		if = {
			limit = {
				OR = {
					this = title:e_minister_chancellor
					this = title:e_minister_censor
					this = title:e_minister_grand_marshal
				}
			}
			add = {
				value = 3500
				desc = appointment_title_value.minister
			}
		}
		else_if = {
			limit = {
				OR = {
					this = title:e_minister_of_personnel
					this = title:e_minister_of_revenue
				}
			}
			add = {
				value = 3000
				desc = appointment_title_value.minister
			}
		}
		else_if = {
			limit = {
				OR = {
					this = title:e_minister_of_rites
					this = title:e_minister_of_war
				}
			}
			add = {
				value = 2500
				desc = appointment_title_value.minister
			}
		}
		else_if = {
			limit = {
				OR = {
					this = title:e_minister_of_justice
					this = title:e_minister_of_works
				}
			}
			add = {
				value = 2000
				desc = appointment_title_value.minister
			}
		}
	}
}

## Movement power
event_decrease_movement_power_minor_value = -5
event_decrease_movement_power_medium_value = -10
event_decrease_movement_power_major_value = -25
event_increase_movement_power_major_value = 25
event_increase_movement_power_medium_value = 10
event_increase_movement_power_minor_value = 5
event_increased_personal_movement_power_value = 15

# Events
subsidised_estate_value = {
	value = 0
	
	if = {
		limit = {
			has_variable = subsidised_estate_var
		}
		add = var:subsidised_estate_var
	}
	min = 1
	
	desc = MODIFIER_DEFINITION_SUBSIDISED_ESTATE
}

tgp_shared_bloc_cohesion_base_change_monthly_value = {
	value = 0
	add = {
		value = 0
		every_confederation_member_house = { add = -0.1 }
		max = 0
		desc = "HOUSE_BLOC_COHESION_FROM_SIZE_HOUSE"
	}
	add = {
		value = 0
		leading_house.house_head.top_liege ?= {
			every_sub_realm_county = {
				limit = { holder.house.house_confederation ?= root }
				add = -0.05
			}
		}
		max = 0
		desc = "HOUSE_BLOC_COHESION_FROM_SIZE"
	}
	# TODO GAIN FROM FESTIVAL MODIFIERS GOES HERE
}


## Boost/Penalize bloc for having conforming/diverging members.
#
# Scopes
# ------
# root: confederation/bloc
# house: Member house that we're checking
#
#
tgp_shared_bloc_cohesion_base_change_per_house_monthly_value = {
	value = 0
	leading_house ?= {
		if = {
			limit = {
				NOT = { this = scope:house }
			}
			if = {
				limit = {
					NOT = { has_same_house_aspiration_as = scope:house }
				}
				add = {
					value = -0.25
					desc = "HOUSE_BLOC_COHESION_MISMATCHED_ASPIRATION"
				}
			}
			else = {
				add = {
					value = 0.25
					if = { # Unlanded give less
						limit = {
							NOT = {
								scope:house = {
									any_house_member = {	
										is_landed = yes
										top_liege = root.leading_house.house_head.top_liege
									}
								}
							}
						}
						multiply = 0.5
					}
					desc = "HOUSE_BLOC_COHESION_MATCHED_ASPIRATION"
				}
			}
		}
	}
	scope:house.house_head = {
		if = {
			limit = {
				NOT = { has_same_government = root.leading_house.house_head }
			}
			add = {
				value = -1
				desc = "HOUSE_BLOC_COHESION_MISMATCHED_GOVERNMENT"
			}
		}
	}
	if = {
		limit = {
			leading_house.house_dynasty = { has_dynasty_perk = tgp_japan_legacy_1 }
			leading_house.house_dynasty = scope:house.house_dynasty
			scope:house != leading_house
		}
		add = {
			value = tgp_dynasty_legacy_bloc_cohesion_value
			desc = "HOUSE_BLOC_SAME_DYNASTY_LEGACY_PERK"
		}
	}
}

tgp_shared_bloc_cohesion_contribution_value = {
	value = scope:base_value
	divide = scope:num_relations
	divide = root.tgp_bloc_member_house_count_value
}

tgp_shared_bloc_cohesion_soft_cap_value = {
	value = 75
}

tgp_establish_soryo_administration_bloc_leader_count_value = {
	value = 0
	every_in_list = {
		list = bloc_leaders
		add = 1
	}
}

tgp_establish_soryo_administration_other_joiners_count_value = {
	value = 0
	every_in_list = {
		list = other_joiners
		add = 1
	}
}

#Aptitude Bonus for Dynasty Legacy
court_position_tgp_dynasty_legacy_aptitude_bonus = 10

#Bloc Joining Dynasty Legacy Bonus
tgp_legacy_japan_dynasty_bloc_bonus_value = 25
#Bloc Joining Dynasty Lifestyle Perk
tgp_join_bloc_interaction_lifestyle_perk_value = 15
#Bloc Cohesion Dynasty Legacy Bonus
tgp_dynasty_legacy_bloc_cohesion_value = 0.25
#Hosting Festival Discount Legacy Perk
tgp_dynasty_legacy_perk_festival_discount_value = 0.2

# House Bloc Cohesion
cohesion_gain_minor = 0.25
cohesion_gain_medium = 0.5
cohesion_gain_major = 1
cohesion_loss_minor = {
	value = cohesion_gain_minor
	multiply = -1
}
cohesion_loss_medium = {
	value = cohesion_gain_medium
	multiply = -1
}
cohesion_loss_major = {
	value = cohesion_gain_major
	multiply = -1
}

border_war_grace_period_days = {
	value = 1095	
}

border_war_grace_period_years = {
	value = border_war_grace_period_days
	divide = 365
	round = yes
}

steppe_admin_target_counties_tributaries = {
	value = 50
}

temp_num_qualifying_counties_count = {
	value = 0
	every_sub_realm_county = {
		limit = {
			holder = {
				is_governor_or_admin_count = yes
				government_has_flag = government_has_merit
			}
			title_province = {
				OR = {
					has_holding_type = castle_holding
					has_holding_type = church_holding
					has_holding_type = city_holding
					has_holding_type = temple_citadel_holding
				}
			}
		}
		add = 1
	}
}

meritocratic_conversion_county_count = {
	value = 30
}

return_to_steppe_county_requirement = {
	value = 10
}

maitreya_devotee_army_value = {
	value = 0
	if = {
		limit = {
			any_sub_realm_county = {
				faith = root.faith
				count <= 5
			}
		}
		add = 1000
	}
	else_if = {
		limit = {
			any_sub_realm_county = {
				faith = root.faith
				count <= 10
			}
		}
		add = 500
	}
	else_if = {
		limit = {
			any_sub_realm_county = {
				faith = root.faith
				count <= 20
			}
		}
		add = 400
	}
	else_if = {
		limit = {
			any_sub_realm_county = {
				faith = root.faith
				count <= 30
			}
		}
		add = 300
	}
	else_if = {
		limit = {
			any_sub_realm_county = {
				faith = root.faith
				count <= 50
			}
		}
		add = 200
	}
	else = {
		add = 100
	}
	multiply = {
		value = 0
		every_sub_realm_county = {
			limit = {
				faith = root.faith
			}
			add = 1
		}
	}
}

cranial_trophies_stolen_prestige_value = {
	value = 0
	if = {
		limit = {
			scope:dead_character.prestige > 0
		}
		add = scope:dead_character.prestige
	}
	multiply = 0.25
}

tgp_ai_concubine_soft_cap = {
	value = max_number_of_concubines
	multiply = 0.5
}

silk_road_downstream_primary_value = 15
silk_road_downstream_primary_negative_value = {
	value = silk_road_downstream_primary_value
	multiply = -1
}
silk_road_downstream_secondary_value = 10
silk_road_downstream_secondary_negative_value = {
	value = silk_road_downstream_secondary_value
	multiply = -1
}
silk_road_downstream_tertiary_value = 5
silk_road_downstream_tertiary_negative_value = {
	value = silk_road_downstream_tertiary_value
	multiply = -1
}

silk_road_steppe_market_built_value = 15
silk_road_steppe_resettlement_value = 5
silk_road_steppe_canal_built_primary_value = 30
silk_road_steppe_canal_built_secondary_value = 20
silk_road_steppe_canal_built_tertiary_value = 10

silk_road_stability_primary_value = 15
silk_road_stability_secondary_value = 10
silk_road_stability_tertiary_value = 5

silk_road_expand_steppe_value = 50
silk_road_expand_steppe_negative_value = {
	value = silk_road_expand_steppe_value
	multiply = -1
}
silk_road_raid_value = 10
silk_road_raid_negative_value = {
	value = silk_road_raid_value
	multiply = -1
}
silk_road_mongol_devastation_value = 15
silk_road_mongol_devastation_negative_value = {
	value = silk_road_mongol_devastation_value
	multiply = -1
}

silk_road_byzantium_destroyed_value = 50
silk_road_byzantium_destroyed_negative_value = {
	value = silk_road_byzantium_destroyed_value
	multiply = -1
}
silk_road_steppe_iranian_intermezzo_ending_value = 15
silk_road_steppe_iranian_intermezzo_unrest_value = 3
silk_road_steppe_iranian_intermezzo_unrest_negative_value = {
	value = silk_road_steppe_iranian_intermezzo_unrest_value
	multiply = -1
}

silk_road_steppe_china_consolidation_value = 1000
silk_road_steppe_china_consolidation_negative_value = {
	value = silk_road_steppe_china_consolidation_value
	multiply = -1
}

silk_road_steppe_china_stability_value = 5

innovation_cupellation_mine_tax_bonus_value = 0.15

innovation_champa_rice_tax_mult_value_1 = 0.02
innovation_champa_rice_levy_size_value_1 = 0.02
innovation_champa_rice_development_growth_factor_value_1 = 0.05
innovation_champa_rice_tax_mult_value_2 = 0.03
innovation_champa_rice_levy_size_value_2 = 0.03
innovation_champa_rice_development_growth_factor_value_2 = 0.05
innovation_champa_rice_tax_mult_value_3 = 0.04
innovation_champa_rice_levy_size_value_3 = 0.04
innovation_champa_rice_development_growth_factor_value_3 = 0.05
innovation_champa_rice_tax_mult_value_4 = 0.04
innovation_champa_rice_levy_size_value_4 = 0.04
innovation_champa_rice_development_growth_factor_value_4 = 0.05

innovation_block_printing_control_growth_value_1 = 0.02
innovation_block_printing_development_growth_value_1 = 0.02
innovation_block_printing_control_growth_value_2 = 0.03
innovation_block_printing_development_growth_value_2 = 0.03
innovation_block_printing_control_growth_value_3 = 0.04
innovation_block_printing_development_growth_value_3 = 0.04
innovation_block_printing_control_growth_value_4 = 0.05
innovation_block_printing_development_growth_value_4 = 0.05

innovation_coking_development_growth_value_1 = 0.02
innovation_coking_development_growth_value_2 = 0.03
innovation_coking_development_growth_value_3 = 0.04
innovation_coking_development_growth_value_4 = 0.05

tgp_chinese_decision_taoism_conversion_discount_value = 0.85

treasury_budget_law_change_legitimacy_loss_base = {
	value = monumental_legitimacy_loss
	if = {
		limit = { highest_held_title_tier = tier_hegemony }
		multiply = 1.5
	}
}

governor_trait_counter_bonus_value = 0.05
