﻿# INFLUENCE

# MANDATE OF HEAVEN LEGITIMACY

# Tier Values
# These must be kept as simple as possible for performance's sake

mandate_of_heaven_level_1 = 0

# Gap of at least 60
mandate_of_heaven_level_2 = { # 60-240
	value = 30
	multiply = legitimacy_title_era_value
}

# Gap of at least 80
mandate_of_heaven_level_3 = { # 140-560
	value = 70
	multiply = legitimacy_title_era_value
}

# Gap of at least 100
mandate_of_heaven_level_4 = { # 240-960
	value = 120
	multiply = legitimacy_title_era_value
}

# Gap of at least 160
mandate_of_heaven_level_5 = { # 400-1600
	value = 200
	multiply = legitimacy_title_era_value
}

# Gap of at least 200
mandate_of_heaven_level_6 = { # 600-2400
	value = 300
	multiply = legitimacy_title_era_value
}

mandate_of_heaven_max = { # 690-2760
	value = mandate_of_heaven_level_6
	multiply = 1.15
	round_to = 100
}

# Situation

claim_mandate_china_county_percentage_value = {
	value = 0.51
}

claim_mandate_china_control_total_value = {
	value = 0
	title:h_china = {
		every_de_jure_county = { add = 1 }
	}
}

claim_mandate_china_control_held_value = {
	value = 0
	save_temporary_scope_as = holder_temp
	title:h_china = {
		every_de_jure_county = {
			limit = {
				holder.top_liege = {
					OR = {
						this = scope:holder_temp
						is_tributary_of_suzerain_or_above = scope:holder_temp
					}
				}
			}
			add = 1
		}
	}
}

claim_mandate_china_control_percent_value = {
	value = claim_mandate_china_control_held_value
	divide = claim_mandate_china_control_total_value
	multiply = 100
}

catalyst_hegemony_too_few_lands_value = 0.5
catalyst_hegemony_far_too_few_lands_value = 0.3

catalyst_imperial_examinations_gap_short_yearly_value = 6
catalyst_imperial_examinations_gap_long_yearly_value = 10

dynastic_cycle_hegemony_higher_court_position_salaries_value = 0.2
corruption_phase_governor_efficiency_penalty_value = 5

# Catalyst values
minimal_situation_catalyst_gain = 5
minor_situation_catalyst_gain = 10
medium_situation_catalyst_gain = 15
major_situation_catalyst_gain = 25
major_plus_situation_catalyst_gain = 35
massive_situation_catalyst_gain = 50
massive_plus_situation_catalyst_gain = 75
monumental_situation_catalyst_gain = 100
minimal_situation_catalyst_loss = {
	value = minimal_situation_catalyst_gain
	multiply = -1
}
minor_situation_catalyst_loss = {
	value = minor_situation_catalyst_gain
	multiply = -1
}
medium_situation_catalyst_loss = {
	value = medium_situation_catalyst_gain
	multiply = -1
}
major_situation_catalyst_loss = {
	value = major_situation_catalyst_gain
	multiply = -1
}
major_plus_situation_catalyst_loss = {
	value = major_plus_situation_catalyst_gain
	multiply = -1
}
massive_situation_catalyst_loss = {
	value = massive_situation_catalyst_gain
	multiply = -1
}
massive_plus_situation_catalyst_loss = {
	value = massive_plus_situation_catalyst_gain
	multiply = -1
}
monumental_situation_catalyst_loss = {
	value = monumental_situation_catalyst_gain
	multiply = -1
}

# "over time" values for balancing passage of time catalysts
minimal_situation_catalyst_over_time_gain = 1
minor_situation_catalyst_over_time_gain = 5
medium_situation_catalyst_over_time_gain = 10
major_situation_catalyst_over_time_gain = 20
massive_situation_catalyst_over_time_gain = 35
monumental_situation_catalyst_over_time_gain = 50
monumental_situation_catalyst_over_time_plus_gain = 75
extreme_situation_catalyst_over_time_gain = 100
major_situation_catalyst_over_time_loss = -10

below_legitimacy_catalyst_over_time_value = {
	value = 20
	# increasing the value in stability as you are expected to be more legitimate the longer you are stable
	situation:dynastic_cycle = {
		if = {
			limit = {
				OR = {
					situation_current_phase = situation_dynastic_cycle_phase_stability_expansion
					situation_current_phase = situation_dynastic_cycle_phase_stability_advancement
				}
			}
			# add extra if stability phase started 50 years ago
			if = {
				limit = {
					var:stability_phase_start_date <= {
						value = current_date
						subtract = 18250
					}
				}
				add = 10
			}
			# add extra if stability phase started 100 years ago
			else_if = {
				limit = {
					var:stability_phase_start_date <= {
						value = current_date
						subtract = 36500
					}
				}
				add = 30
			}
		}
	}
}

treasury_raided_loot_value = {
	value = title:h_china.holder.treasury
	divide = 100
	min = 10
}

treasury_siphoned_value = {
	value = scope:recipient.monthly_character_treasury_variable_income
	if = {
		limit = {
			scope:recipient = {
				is_in_same_movement_as = { TARGET = scope:actor }
			}
		}
		multiply = 0.5
	}
	if = {
		limit = {
			scope:actor = {
				has_trait = greedy
			}
		}
		multiply = 1.3
	}
	min = 1
	max = 25 #people would notice that large of a change in the books
}

# >= 0 – Hegemon favors advancement movement
# < 0  – Hegemon favors expansion movement
hegemon_favored_stability_phase_value = {
	value = 0
	#add/subtract relevant movement power
	if = {
		limit = {
			exists = situation:dynastic_cycle.situation_participant_group:advancement_movement.var:movement_power
		}
		add = situation:dynastic_cycle.situation_participant_group:advancement_movement.var:movement_power
	}
	if = {
		limit = {
			exists = situation:dynastic_cycle.situation_participant_group:expansion_movement.var:movement_power
		}
		subtract = situation:dynastic_cycle.situation_participant_group:expansion_movement.var:movement_power
	}
	#reset if the pro hegemon movement power is higher
	if = {
		limit = {
			exists = situation:dynastic_cycle.situation_participant_group:pro_hegemon_movement.var:movement_power
			trigger_if = {
				limit = {
					exists = situation:dynastic_cycle.situation_participant_group:advancement_movement.var:movement_power
				}
				situation:dynastic_cycle.situation_participant_group:advancement_movement.var:movement_power <= situation:dynastic_cycle.situation_participant_group:pro_hegemon_movement.var:movement_power
			}
			trigger_if = {
				limit = {
					exists = situation:dynastic_cycle.situation_participant_group:expansion_movement.var:movement_power
				}
				situation:dynastic_cycle.situation_participant_group:expansion_movement.var:movement_power <= situation:dynastic_cycle.situation_participant_group:pro_hegemon_movement.var:movement_power
			}
		}
		multiply = 0
	}
	#add hegemon personality
	if = {
		limit = {
			ai_has_builder_or_pious_builder_personality = yes
		}
		add = 1
	}
	if = {
		limit = {
			ai_has_warlike_personality = yes
		}
		add = -1
	}
	#reset if hegemon is player and modify after the decision is taken
	if = {
		limit = {
			is_ai = no
		}
		multiply = 0
		if = {
			limit = {
				has_variable = favor_era
			}
			if = {
				limit = {
					var:favor_era = flag:advancement 
				}
				add = 1
			}
			else = {
				add = -1
			}
		}
		if = {
			limit = {
				OR = {
					is_movement_in_power = { MOVEMENT = advancement_movement }
					AND = {
						is_movement_in_power = { MOVEMENT = conservative_movement }
						situation:dynastic_cycle ?= {
							situation_current_phase = situation_dynastic_cycle_phase_stability_expansion
						}
					}
					AND = {
						is_movement_in_power = { MOVEMENT = pro_hegemon_movement }
						situation:dynastic_cycle ?= {
							situation_current_phase = situation_dynastic_cycle_phase_stability_advancement
						}
					}
				}
			}
			add = 1
		}
		else_if = {
			limit = {
				OR = {
					is_movement_in_power = { MOVEMENT = expansion_movement }
					AND = {
						is_movement_in_power = { MOVEMENT = conservative_movement }
						situation:dynastic_cycle ?= {
							situation_current_phase = situation_dynastic_cycle_phase_stability_advancement
						}
					}
					AND = {
						is_movement_in_power = { MOVEMENT = pro_hegemon_movement }
						situation:dynastic_cycle ?= {
							situation_current_phase = situation_dynastic_cycle_phase_stability_expansion
						}
					}
				}
			}
			add = -1
		}
	}
}
# root = scope:situation_group_participant
# calculates a Movement power value
movement_power_value = {
	value = {
		every_situation_group_participant = {
			if = {
				limit = { exists = var:movement_power }
				add = {
					value = var:movement_power
					desc = movement_power_movement_members_name
				}
			}
		}
		if = {
			limit = {
				hegemon_favors_expansion_trigger = yes
				this = situation:dynastic_cycle.situation_participant_group:expansion_movement
			}
			add = {
				value = decent_movement_power_value
				desc = movement_power_movement_favored_era_name
			}
		}
		if = {
			limit = {
				hegemon_favors_advancement_trigger = yes
				this = situation:dynastic_cycle.situation_participant_group:advancement_movement
			}
			add = {
				value = decent_movement_power_value
				desc = movement_power_movement_favored_era_name
			}
		}
		if = {
			limit = {
				exists = var:movement_favored
			}
			add = {
				value = high_movement_power_value
				desc = movement_power_movement_favored_name
			}
		}
		# Temporary modifiers, the decrease/increase has to be updated yearly in update_modified_movement_power_effect
		if = {
			limit = {
				exists = var:movement_power_increased_scheme
			}
			add = {
				value = var:movement_power_increased_scheme
				desc = movement_power_increased_scheme_name
			}
		}
		if = {
			limit = {
				exists = var:movement_power_decreased_scheme
			}
			add = {
				value = var:movement_power_decreased_scheme
				desc = movement_power_decreased_scheme_name
			}
		}
		if = {
			limit = {
				exists = var:movement_power_increased_petition
			}
			add = {
				value = var:movement_power_increased_petition
				desc = movement_power_increased_petition_name
			}
		}
		if = {
			limit = {
				exists = var:movement_power_decreased_petition
			}
			add = {
				value = var:movement_power_decreased_petition
				desc = movement_power_decreased_petition_name
			}
		}
	}
}

# root = scope:character
# calculates a character's Movement power value (excluding disciples)
movement_power_character_individual_value = {
	value = {
		add = {
			value = age
			multiply = 0.5
			desc = MOVEMENT_POWER_AGE
		}
		add = {
			value = movement_power_character_individual_merit_value
			desc = MOVEMENT_POWER_MERIT
		}
		add = {
			value = influence_level
			multiply = 5
			desc = MOVEMENT_POWER_INFLUENCE
		}
		add = {
			value = 0
			every_maa_regiment = {
				add = 10
			}
			if = {
				limit = {
					situation:dynastic_cycle ?= {
						situation_current_phase = situation_dynastic_cycle_phase_stability_advancement
					}
				}
				multiply = 0.5
			}
			desc = MOVEMENT_POWER_MILITARY_STRENGTH
		}
		add = {
			value = primary_title.tier
			multiply = 5
			desc = MOVEMENT_POWER_TIER
		}
		if = {
			limit = {
				exists = top_liege
				is_diarch_of_target = top_liege
				top_liege = {
					has_diarchy_type = grand_secretariat
				}
			}
			add = {
				value = 100
				desc = MOVEMENT_POWER_GRAND_SECRETARIAT
			}
		}
		if = {
			limit = {
				exists = top_liege
				is_diarch_of_target = top_liege
				top_liege = {
					NOT = { has_diarchy_type = grand_secretariat }
				}
			}
			add = {
				value = 50
				desc = MOVEMENT_POWER_DIARCH
			}
		}
		if = {
			limit = {
				exists = top_liege
				is_councillor_of = top_liege
			}
			add = {
				value = 20
				desc = MOVEMENT_POWER_MINISTER
			}
		}
		if = {
			limit = { subject_contract_has_flag = celestial_investiture_politics }
			add = {
				value = subject_standing
				desc = MOVEMENT_POWER_IMPERIAL_GRACE
			}
		}
		# Domicile buildings
		if = {
			limit = { exists = domicile }
			add = {
				value = 0
				domicile = {
					if = {
						limit = { has_domicile_building_or_higher = east_asian_estate_movement_study_04 }
						add = estate_movement_power_bonus_4_value
					}
					else_if = {
						limit = { has_domicile_building_or_higher = east_asian_estate_movement_study_03 }
						add = estate_movement_power_bonus_3_value
					}
					else_if = {
						limit = { has_domicile_building_or_higher = east_asian_estate_movement_study_02 }
						add = estate_movement_power_bonus_2_value
					}
					else_if = {
						limit = { has_domicile_building_or_higher = east_asian_estate_movement_study_01 }
						add = estate_movement_power_bonus_1_value
					}
					if = {
						limit = { has_domicile_building_or_higher = east_asian_estate_meeting_houses_04 }
						add = estate_movement_power_bonus_4_value
					}
					else_if = {
						limit = { has_domicile_building_or_higher = east_asian_estate_meeting_houses_03 }
						add = estate_movement_power_bonus_3_value
					}
					else_if = {
						limit = { has_domicile_building_or_higher = east_asian_estate_meeting_houses_02 }
						add = estate_movement_power_bonus_2_value
					}
					else_if = {
						limit = { has_domicile_building_or_higher = east_asian_estate_meeting_houses_01 }
						add = estate_movement_power_bonus_1_value
					}
					if = {
						limit = { has_domicile_building_or_higher = east_asian_estate_teahouse_04 }
						add = estate_movement_power_bonus_4_value
					}
					else_if = {
						limit = { has_domicile_building_or_higher = east_asian_estate_teahouse_03 }
						add = estate_movement_power_bonus_3_value
					}
					else_if = {
						limit = { has_domicile_building_or_higher = east_asian_estate_teahouse_02 }
						add = estate_movement_power_bonus_2_value
					}
					else_if = {
						limit = { has_domicile_building_or_higher = east_asian_estate_teahouse_01 }
						add = estate_movement_power_bonus_1_value
					}
					if = {
						limit = { has_domicile_building_or_higher = east_asian_estate_guesthouse_04 }
						add = estate_movement_power_bonus_4_value
					}
					else_if = {
						limit = { has_domicile_building_or_higher = east_asian_estate_guesthouse_03 }
						add = estate_movement_power_bonus_3_value
					}
					else_if = {
						limit = { has_domicile_building_or_higher = east_asian_estate_guesthouse_02 }
						add = estate_movement_power_bonus_2_value
					}
					else_if = {
						limit = { has_domicile_building_or_higher = east_asian_estate_guesthouse_01 }
						add = estate_movement_power_bonus_1_value
					}
					
					if = {
						limit = { exists = owner.dynasty }
						if = {
							limit = { has_domicile_parameter = estate_movement_power_per_dynasty_prestige_level_bonus_1 }
							add = {
								value = estate_movement_power_per_dynasty_prestige_level_bonus_1_value
								multiply = owner.dynasty.dynasty_prestige_level
							}
						}
						else_if = {
							limit = { has_domicile_parameter = estate_movement_power_per_dynasty_prestige_level_bonus_2 }
							add = {
								value = estate_movement_power_per_dynasty_prestige_level_bonus_2_value
								multiply = owner.dynasty.dynasty_prestige_level
							}
						}
						else_if = {
							limit = { has_domicile_parameter = estate_movement_power_per_dynasty_prestige_level_bonus_3 }
							add = {
								value = estate_movement_power_per_dynasty_prestige_level_bonus_3_value
								multiply = owner.dynasty.dynasty_prestige_level
							}
						}
					}
				}
				desc = estate_buildings_desc
			}
		}
		# Family aspirations
		if = {
			limit = { exists = house }
			# Piety level
			add = {
				value = 0
				house = {
					if = {
						limit = { has_house_aspiration_parameter = movement_power_per_piety_level_5 }
						add = {
							value = movement_power_per_piety_level_bonus_5_value
							multiply = prev.piety_level
						}
					}
					else_if = {
						limit = { has_house_aspiration_parameter = movement_power_per_piety_level_4 }
						add = {
							value = movement_power_per_piety_level_bonus_4_value
							multiply = prev.piety_level
						}
					}
					else_if = {
						limit = { has_house_aspiration_parameter = movement_power_per_piety_level_3 }
						add = {
							value = movement_power_per_piety_level_bonus_3_value
							multiply = prev.piety_level
						}
					}
					else_if = {
						limit = { has_house_aspiration_parameter = movement_power_per_piety_level_2 }
						add = {
							value = movement_power_per_piety_level_bonus_2_value
							multiply = prev.piety_level
						}
					}
					else_if = {
						limit = { has_house_aspiration_parameter = movement_power_per_piety_level_1 }
						add = {
							value = movement_power_per_piety_level_bonus_1_value
							multiply = prev.piety_level
						}
					}
				}
				desc = PIETY_LEVEL_CONCEPT
			}
			# Prestige level
			add = {
				value = 0
				house = {
					if = {
						limit = { has_house_aspiration_parameter = movement_power_per_prestige_level_5 }
						add = {
							value = movement_power_per_prestige_level_bonus_5_value
							multiply = prev.prestige_level
						}
					}
					else_if = {
						limit = { has_house_aspiration_parameter = movement_power_per_prestige_level_4 }
						add = {
							value = movement_power_per_prestige_level_bonus_4_value
							multiply = prev.prestige_level
						}
					}
					else_if = {
						limit = { has_house_aspiration_parameter = movement_power_per_prestige_level_3 }
						add = {
							value = movement_power_per_prestige_level_bonus_3_value
							multiply = prev.prestige_level
						}
					}
					else_if = {
						limit = { has_house_aspiration_parameter = movement_power_per_prestige_level_2 }
						add = {
							value = movement_power_per_prestige_level_bonus_2_value
							multiply = prev.prestige_level
						}
					}
					else_if = {
						limit = { has_house_aspiration_parameter = movement_power_per_prestige_level_1 }
						add = {
							value = movement_power_per_prestige_level_bonus_1_value
							multiply = prev.prestige_level
						}
					}
				}
				desc = PRESTIGE_LEVEL_CONCEPT
			}
		}
		# Cycle dependent values
		if = {
			limit = {
				situation:dynastic_cycle ?= {
					situation_current_phase = situation_dynastic_cycle_phase_stability_advancement
				}
			}
			add = {
				value = "has_trait_xp(confucian_education)"
				desc = MOVEMENT_POWER_CONFUCIAN_EXP
			} 
			add = {
				value = "has_trait_xp(governor)"
				desc = MOVEMENT_POWER_GOVERNOR_EXP
			}
		}
		else = {
			add = {
				value = "has_trait_xp(confucian_education)"
				multiply = 0.5
				desc = MOVEMENT_POWER_CONFUCIAN_EXP
			} 
			add = {
				value = "has_trait_xp(governor)"
				multiply = 0.5
				desc = MOVEMENT_POWER_GOVERNOR_EXP
			}	
		}
		if = {
			limit = {
				exists = var:grand_campaign_won
			}
			add = {
				value = var:grand_campaign_won
				desc = movement_power_increased_grand_campaign_name
			}
		}
		if = {
			limit = {
				exists = var:grand_campaign_lost
			}
			add = {
				value = var:grand_campaign_lost
				desc = movement_power_decreased_grand_campaign_name
			}
		}
		# Dynasty Legacy
		if = {
			limit = {
				dynasty ?= {
					has_dynasty_perk = tgp_chinese_legacy_4
				}
			}
			add = {
				value = dynasty_legacy_movement_power_bonus_value
				desc = movement_power_chinese_legacy_4
			}
		}
		# Temporary modifiers, the decrease/increase has to be updated yearly in update_modified_movement_power_effect
		if = {
			limit = {
				exists = var:movement_power_increased_scheme
			}
			add = {
				value = var:movement_power_increased_scheme
				desc = movement_power_increased_scheme_name
			}
		}
		if = {
			limit = {
				exists = var:movement_power_decreased_scheme
			}
			add = {
				value = var:movement_power_decreased_scheme
				desc = movement_power_decreased_scheme_name
			}
		}
		if = {
			limit = {
				exists = var:movement_power_increased_event
			}
			add = {
				value = var:movement_power_increased_event
				desc = movement_power_increased_event_name
			}
		}
		if = {
			limit = {
				exists = var:movement_power_decreased_event
			}
			add = {
				value = var:movement_power_decreased_event
				desc = movement_power_decreased_event_name
			}
		}
		if = {
			limit = {
				exists = var:movement_power_decreased_diarchy
			}
			add = {
				value = var:movement_power_decreased_diarchy
				desc = movement_power_decreased_diarchy_name
			}
		}
		if = {
			limit = {
				has_character_modifier = tgp_personal_honors_modifier
			}
			add = {
				value = 300
				desc = tgp_personal_honors_modifier
			}
		}
		# Multipliers - Keep at the end!
		if = {
			limit = {
				has_court_position = favored_minister_court_position
			}
			multiply = {
				value = 1
				add = favored_minister_movement_power_bonus_value
				desc = favored_minister_desc
			}
		}
	}
}

# root = scope:character
# calculates a character's Movement power value contributing to the overall Movement power
movement_power_character_value = {
	value = {
		add = movement_power_character_individual_value
		add = {
			value = every_disciple_movement_power_value
			multiply = 0.25
			desc = every_disciple_movement_power_value_desc
		}
	}
}
#needed to sync with loc
movement_power_increased_scheme_decay_value = {
	value = -20
}
movement_power_decreased_scheme_decay_value = {
	value = 20
}
movement_power_increased_event_decay_value = {
	value = -5
}
movement_power_decreased_event_decay_value = {
	value = 5
}
movement_power_increased_petition_decay_value = {
	value = -20
}
movement_power_decreased_petition_decay_value = {
	value = 20
}
movement_power_decreased_diarchy_value = {
	value = var:movement_power_individual
	multiply = -0.5
}

low_movement_power_value = 20
mediocre_movement_power_value = 50
medium_movement_power_value = 100
decent_movement_power_value = 150
high_movement_power_value = 350
very_high_movement_power_value = 500
extremely_high_movement_power_value = 800
monumentally_high_movement_power_value = 1000

low_movement_power_gain = {
	value = low_movement_power_value
}
mediocre_movement_power_gain = {
	value = mediocre_movement_power_value
}
medium_movement_power_gain = {
	value = medium_movement_power_value
}
decent_movement_power_gain = {
	value = decent_movement_power_value
}
high_movement_power_gain = {
	value = high_movement_power_value
}
very_high_movement_power_gain = {
	value = very_high_movement_power_value
}
extremely_high_movement_power_gain = {
	value = extremely_high_movement_power_value
}
monumentally_high_movement_power_gain = {
	value = monumentally_high_movement_power_value
}

low_movement_power_loss = {
	value = low_movement_power_value
	multiply = -1
}
mediocre_movement_power_loss = {
	value = mediocre_movement_power_value
	multiply = -1
}
medium_movement_power_loss = {
	value = medium_movement_power_value
	multiply = -1
}
decent_movement_power_loss = {
	value = decent_movement_power_value
	multiply = -1
}
high_movement_power_loss = {
	value = high_movement_power_value
	multiply = -1
}
very_high_movement_power_loss = {
	value = very_high_movement_power_value
	multiply = -1
}
extremely_high_movement_power_loss = {
	value = extremely_high_movement_power_value
	multiply = -1
}
monumentally_high_movement_power_loss = {
	value = monumentally_high_movement_power_value
	multiply = -1
}
# petition_recipient = the hegemon or minister receiving the movement petition, set in the decision movement_petition_decision
# calculate how likely it is to accept a movement petition to display the value in the decision and events
movement_demands_acceptance_value = {
	value = -10
	# Opinion
	add = {
		value = "scope:petition_recipient.opinion(scope:petitioner)"
		multiply = 0.5
	}
	# petitioner's movement is in power
	if = {
		add = 10
		limit = {
			situation:dynastic_cycle = {
				any_participant_group = {
					participant_group_has_character = scope:petitioner
					trigger_if = {
						limit = {
							participant_group_type = expansion_movement
						}
						is_movement_in_power = { MOVEMENT = expansion_movement }
					}
					trigger_else_if = {
						limit = {
							participant_group_type = advancement_movement
						}
						is_movement_in_power = { MOVEMENT = advancement_movement }
					}
					trigger_else_if = {
						limit = {
							participant_group_type = pro_hegemon_movement
						}
						is_movement_in_power = { MOVEMENT = pro_hegemon_movement }
					}
					trigger_else_if = {
						limit = {
							participant_group_type = conservative_movement
						}
						is_movement_in_power = { MOVEMENT = conservative_movement }
					}
					trigger_else = {
						always = no
					}
				}
			}
		}
		desc = POWERFUL_MOVEMENT
	}
	# petition_recipient is my elder
	if = {
		limit = {
			scope:petitioner = {
				has_relation_disciple = scope:petition_recipient
			}
		}
		desc = is_actors_elder
		add = 20
	}
	# petitioner's merit level
	add = {
		value = 10
		multiply = scope:petitioner.merit_level
		desc = actors_merit_level_desc
	}
	
	# house power difference
	if = { # If you are from a powerful family
		limit = {
			scope:petitioner.house ?= {
				is_powerful_family = yes
			}
		}
		add = 15
		desc = your_house_is_powerful_reason
	}
	if = { # If you are from a dominant family
		limit = {
			scope:petitioner.house ?= {
				is_dominant_family = yes
			}
		}
		add = 25
		desc = your_house_is_dominant_reason
	}
	if = { # Difference in influence level
		limit = {
			scope:petitioner.influence_level != scope:petition_recipient.influence_level
		}
		add = {
			add = {
				add = 5
				multiply = scope:petitioner.influence_level
			}
			subtract = {
				add = 5
				multiply = scope:petition_recipient.influence_level
			}
		}
		desc = difference_in_influence_level_reason
	}
	if = {
		limit = {
			scope:petitioner = {
				is_powerful_vassal = yes
			}
		}
		add = 5
		desc = AI_POWERFUL_VASSAL
	}
	#petition types
	if = {
		limit = {
			OR = {
				scope:change_celestial_bureaucracy ?= yes
				scope:petitioner.var:movement_petition ?= flag:change_bureaucracy_laws
			}
		}
		add = 50
	}
	if = {
		limit = {
			OR = {
				scope:change_celestial_army_liege_law ?= yes
				scope:petitioner.var:movement_petition ?= flag:change_army_laws
			}
		}
		add = -20
	}
	if = {
		limit = {
			OR = {
				scope:change_province_type ?= yes
				scope:petitioner.var:movement_petition ?= flag:change_province_metropolitan
			}
			scope:hegemon = {
				any_vassal = {
					count < celestial_province_metropolitan_max_value
					vassal_contract_has_flag = celestial_province_metropolitan
				}
			}
		}
		add = 20
	}
	if = {
		limit = {
			OR = {
				scope:change_province_type ?= yes
				scope:petitioner.var:movement_petition ?= flag:change_province_metropolitan
			}
			scope:hegemon = {
				any_vassal = {
					count >= celestial_province_metropolitan_max_value
					vassal_contract_has_flag = celestial_province_metropolitan
				}
			}
		}
		add = -20
	}
	if = {
		limit = {
			OR = {
				scope:change_province_type ?= yes
				scope:petitioner.var:movement_petition ?= flag:change_province_industrial
			}
			scope:hegemon = {
				any_vassal = {
					count < celestial_province_industrial_max_value
					vassal_contract_has_flag = celestial_province_industrial
				}
			}
		}
		add = 20
	}
	if = {
		limit = {
			OR = {
				scope:change_province_type ?= yes
				scope:petitioner.var:movement_petition ?= flag:change_province_industrial
			}
			scope:hegemon = {
				any_vassal = {
					count >= celestial_province_industrial_max_value
					vassal_contract_has_flag = celestial_province_industrial
				}
			}
		}
		add = -20
	}
	if = {
		limit = {
			OR = {
				scope:change_province_type ?= yes
				scope:petitioner.var:movement_petition ?= flag:change_province_military
			}
			scope:hegemon = {
				any_vassal = {
					count < celestial_province_military_max_value
					vassal_contract_has_flag = celestial_province_military
				}
			}
		}
		add = 20
	}
	if = {
		limit = {
			OR = {
				scope:change_province_type ?= yes
				scope:petitioner.var:movement_petition ?= flag:change_province_military
			}
			scope:hegemon = {
				any_vassal = {
					count >= celestial_province_military_max_value
					vassal_contract_has_flag = celestial_province_military
				}
			}
		}
		add = -20
	}
	if = {
		limit = {
			OR = {
				scope:change_province_type ?= yes
				scope:petitioner.var:movement_petition ?= flag:change_province_protectorate
			}
			scope:hegemon = {
				any_vassal = {
					count < celestial_province_protectorate_max_value
					vassal_contract_has_flag = celestial_province_protectorate
				}
			}
		}
		add = 20
	}
	if = {
		limit = {
			OR = {
				scope:change_province_type ?= yes
				scope:petitioner.var:movement_petition ?= flag:change_province_protectorate
			}
			scope:hegemon = {
				any_vassal = {
					count >= celestial_province_protectorate_max_value
					vassal_contract_has_flag = celestial_province_protectorate
				}
			}
		}
		add = -20
	}
	if = {
		limit = {
			OR = {
				scope:hold_examinations ?= yes
				scope:petitioner.var:movement_petition ?= flag:hold_examinations
			}
			scope:hegemon.hegemon_favored_stability_phase_value >= 0
		}
		add = 50
	}
	if = {
		limit = {
			OR = {
				scope:hold_examinations ?= yes
				scope:petitioner.var:movement_petition ?= flag:hold_examinations
			}
			scope:hegemon.hegemon_favored_stability_phase_value < 0
		}
		add = -25
	}
	if = {
		limit = {
			OR = {
				scope:increase_budget ?= yes
				scope:petitioner.var:budget_change ?= flag:decrease_military
			}
			scope:hegemon = {
				NOR = {
					has_realm_law_flag = military_budget_law_minor_negative_impact #Unop: hegemon is a character scope
					has_realm_law_flag = military_budget_law_major_negative_impact #Unop: hegemon is a character scope
				}
			}
		}
		add = 25
	}
	if = {
		limit = {
			OR = {
				scope:increase_budget ?= yes
				scope:petitioner.var:budget_change ?= flag:decrease_salary
			}
			scope:hegemon = {
				NOR = {
					has_realm_law_flag = military_budget_law_minor_negative_impact #Unop: hegemon is a character scope
					has_realm_law_flag = military_budget_law_major_negative_impact #Unop: hegemon is a character scope
				}
			}
		}
		add = 25
	}
	if = {
		limit = {
			OR = {
				scope:increase_budget ?= yes
				scope:petitioner.var:budget_change ?= flag:decrease_ministry
			}
			scope:hegemon = {
				NOR = {
					has_realm_law_flag = ministry_budget_law_minor_negative_impact #Unop: hegemon is a character scope
					has_realm_law_flag = ministry_budget_law_major_negative_impact #Unop: hegemon is a character scope
				}
			}
		}
		add = 25
	}
	if = {
		limit = {
			OR = {
				scope:petitioner.var:movement_petition ?= flag:increase_budget_salary
				scope:petitioner.var:movement_petition ?= flag:increase_budget_ministry
				scope:petitioner.var:movement_petition ?= flag:increase_budget_military
			}
			scope:hegemon.treasury_years_since_budget_enact_date < 3
		}
		add = -25
	}
	#petition counter offer
	if = {
		limit = {
			scope:petitioner.var:movement_petition_persuasion ?= flag:give_influence
		}
		add = 50
	}
	if = {
		limit = {
			scope:petitioner.var:movement_petition_persuasion ?= flag:give_maa
			scope:hegemon.hegemon_favored_stability_phase_value >= 0
		}
		add = -25
	}
	if = {
		limit = {
			scope:petitioner.var:movement_petition_persuasion ?= flag:give_maa
			scope:hegemon.hegemon_favored_stability_phase_value < 0
		}
		add = 50
	}
	if = {
		limit = {
			scope:petitioner = {
				var:movement_petition_persuasion ?= flag:use_hook
				has_strong_usable_hook = scope:petition_recipient
			}
		}
		add = 50
	}
	if = {
		limit = {
			scope:petitioner = {
				var:movement_petition_persuasion ?= flag:use_hook
				has_usable_hook = scope:petition_recipient
			}
		}
		add = 25
	}
	if = {
		limit = {
			scope:petitioner.var:movement_petition_persuasion ?= flag:give_hook
		}
		add = 25
	}

	if = {
		limit = {
			scope:petitioner.var:budget_change ?= flag:decrease_salary
			scope:hegemon = {
				# Never decrease FROM these levels to lower, because they cost major legitimacy
				OR = {
					has_realm_law_flag = salary_budget_law_minor_negative_impact
					has_realm_law_flag = salary_budget_law_major_negative_impact
				}
			}
		}
		multiply = 0
	}
	if = {
		limit = {
			scope:petitioner.var:budget_change ?= flag:decrease_ministry
			scope:hegemon = {
				# Never decrease FROM these levels to lower, because they cost major legitimacy
				OR = {
					has_realm_law_flag = ministry_budget_law_minor_negative_impact
					has_realm_law_flag = ministry_budget_law_major_negative_impact
				}
			}
		}
		multiply = 0
	}
	if = {
		limit = {
			scope:petitioner.var:budget_change ?= flag:decrease_military
			scope:hegemon = {
				# Never decrease FROM these levels to lower, because they cost major legitimacy
				OR = {
					has_realm_law_flag = military_budget_law_minor_negative_impact
					has_realm_law_flag = military_budget_law_major_negative_impact
				}
			}
		}
		multiply = 0
	}
}

contribute_to_grand_campaign_value = {
	if = { # early-out clause
		limit = {
			OR = {
				current_military_strength <= 0 # only governors that can fight
				"capital_province.squared_distance(scope:great_project.great_project_location)" > squared_distance_large
			}
		}
		value = -1000
	}
	else = { # actual computation if we pass the early-out
		value = -10
		if = {
			limit = {
				current_military_strength >= 2000
			}
			add = 10
		}
		# you are a minister
		if = {
			limit = { tgp_is_any_minister = yes }
			add = {
				value = -25
				if = {
					limit = { has_title = title:e_minister_grand_marshal }
					add = 50 # this is literally your job
				}
			}
		}
		# you are a military governor
		if = {
			limit = {
				vassal_contract_has_flag = celestial_military_appointment
			}
			add = {
				value = 5
				if = {
					limit = {
						has_trait = ambitious
					}
					add = 5
				}
			}
		}
		# you are in expansion movement
		if = {
			limit = {
				top_participant_group:dynastic_cycle ?= {
					participant_group_type = expansion_movement
				}
			}
			add = 10
		}
		# Hegemon likes expansion
		if = {
			limit = {
				title:h_china.holder.hegemon_favored_stability_phase_value < 0
				top_participant_group:dynastic_cycle ?= {
					participant_group_type = pro_hegemon_movement
				}
			}
			add = 5
		}
	}
}

chinese_great_projects_contribution_ai_will_do_base_value = {
	value = -25

	if = {
		limit = { this = scope:great_project.great_project_owner }
		add = 25
	}
	# you are a governor
	if = {
		limit = { is_governor = yes }
		add = {
			value = 20
			if = {
				limit = { has_trait = ambitious }
				add = 20
			}
		}
	}
	# you are a minister
	if = {
		limit = { tgp_is_any_minister = yes }
		add = {
			value = 20
			if = {
				limit = { has_title = title:e_minister_of_works }
				add = 20 # this is literally your job
			}
		}
	}

	if = {
		limit = {
			any_character_situation = {
				situation_type = dynastic_cycle
				NOT = { situation_current_phase = situation_dynastic_cycle_phase_chaos }
			}
		}
		top_participant_group:dynastic_cycle ?= {
			# contributor is in pro-hegemon movement and the project owner is the hegemon
			if = {
				limit = {
					scope:great_project.great_project_owner = title:h_china.holder
					participant_group_type = pro_hegemon_movement
				}
				add = 25
			}
			# contributor is progressive
			else_if = {
				limit = { participant_group_type = advancement_movement }
				add = 15
			}
			# contributor doesn't much care for this sort of thing
			else_if = {
				limit = { participant_group_type = conservative_movement }
				add = -25
			}
		}
	}
	# reduce if the project is far away
	if = {
		limit = {
			"capital_province.squared_distance(scope:great_project.great_project_location)" > squared_distance_large
		}
		add = -25
	}

	add = {
		value = ai_honor
		multiply = 0.5
		min = 0 # don't reduce if dishonorable
	}
	add = {
		value = -0.25
		multiply = ai_greed
	}
	add = {
		value = 0.25
		multiply = ai_energy
	}

	if = {
		limit = {
			is_vassal_or_below_of = scope:great_project.great_project_owner
		}
		if = {
			limit = { has_trait = loyal }
			add = 20
		}
		else_if = {
			limit = { has_trait = disloyal }
			add = -20
		}
	}
	if = {
		limit = {
			is_at_war = yes
		}
		multiply = 0
	}
}

# Enable border wars if your realm size is equal or higher, otherwise disable it
border_war_sized_realm_value = {
	value = monumental_realm_size #160
}

# has to be the same as ai_accept in find_elder_interaction
find_elder_acceptance_value = {
	#age
	add = {
		value = scope:actor.age
		subtract = scope:secondary_recipient.age
		multiply = -0.5
		desc = actors_age_difference
	}
	if = {
		limit = {
			scope:actor.age >= 50
		}
		add = {
			value = -10
			desc = actors_age_old
		}
	}
	#opinion
	add = {
		value = "scope:secondary_recipient.opinion(scope:actor)"
		multiply = 0.5
	}
	#personality of the disciple
	if = {
		limit = {
			scope:actor ?= {
				num_sinful_traits > 0
			}
		}
		add = {
			value = scope:actor.num_sinful_traits
			multiply = 10
			desc = actor_has_sinful_traits
		}
	}
	if = {
		limit = {
			scope:actor ?= {
				num_virtuous_traits > 0
			}
		}
		add = {
			value = scope:actor.num_virtuous_traits
			multiply = 10
			desc = actor_has_virtuous_traits
		}
	}
	if = {
		limit = {
			scope:actor ?= {
				OR = {
					has_trait = confucian_education
					religion = religion:confucianism_religion
				}
			}
		}
		add = {
			value = 10
			desc = actor_has_confucian_education
		}
	}

	#a lot of other disciples
	if = {
		limit = {
			scope:secondary_recipient ?= {
				num_of_relation_disciple >= {
					value = scope:secondary_recipient.disciples_limit_value
					add = -1
				}
			}
		}
		add = {
			value = -20
			desc = secondary_recipient_has_disciples
		}
	}
	# Support your fellow movement members
	if = {
		limit = {
			scope:secondary_recipient ?= {
				is_in_same_movement_as = { TARGET = scope:actor }
			}
		}
		add = {
			value = 10
			if = {
				limit = {
					scope:secondary_recipient ?= {
						is_in_pro_hegemon_or_hegemon_movement = yes
					}
				}
				multiply = 1.5
			}
			desc = actor_and_secondary_recipient_in_same_movement
		}
	}
}

conservative_powerful_families_value = {
	every_powerful_family = {
		limit = {
			house_head = {
				top_participant_group:dynastic_cycle ?= {
					participant_group_type = conservative_movement
				}
			}
		}
		add = 1
	}
}

not_conservative_powerful_families_value = {
	every_powerful_family = {
		limit = {
			house_head = {
				top_participant_group:dynastic_cycle ?= {
					NOT = { participant_group_type = conservative_movement }
				}
			}
		}
		add = 1
	}
}

needed_conservative_powerful_families_value = {
	every_powerful_family = {
		add = 0.5
	}
	round = yes
}

conservative_ministers_value = {
	every_councillor = {
		limit = {
			top_participant_group:dynastic_cycle ?= {
				participant_group_type = conservative_movement
			}
		}
		add = 1
	}
}

not_conservative_ministers_value = {
	every_councillor = {
		limit = {
			top_participant_group:dynastic_cycle ?= {
				NOT = { participant_group_type = conservative_movement }
			}
		}
		add = 1
	}
}

needed_conservative_ministers_value = {
	every_councillor = {
		add = 0.5
	}
	round = yes
}
