﻿impress_intent_vassalization_acceptance_value = { # values synced with offer_vassalization_interaction
	value = -50
	#Perks
	if = {
		limit = {
			has_perk = true_ruler_perk
		}
		add = true_ruler_value
	}
	#Events
	if = {
		limit = {
			 has_character_modifier = event_bonus_to_vassal_accept
		}
		add = 20
	}
	#Cultural Acceptance
	if = {
		limit = {
			NOT = { has_same_culture_as = scope:impress_check }
			culture = {
				cultural_acceptance = { target = scope:impress_check.culture value <= 90 }
			}
		}
		add = offer_vassalage_acceptance_value
	}
	#Different faith, no pluralism.
	if = { 
		limit = {
			scope:impress_check = {
				NOR = { #Of two different faiths AND the potential vassal's faith is not pluralistic.
					faith = root.faith
					faith = { has_doctrine = doctrine_pluralism_pluralistic }
				}
			}
		}
		add = {
			value = -40
			if = {
				limit = {
					scope:impress_check.faith = {
						faith_hostility_level = {
							target = root.faith
							value >= faith_hostile_level
						}
					}
				}
				add = -40
			}
			if = {
				limit = {
					scope:impress_check.faith = {
						faith_hostility_level = {
							target = root.faith
							value >= faith_evil_level
						}
					}
				}
				add = -40
			}
		}
	}
	#Different faith, pluralism.
	if = {
		limit = {
			scope:impress_check = {
				NOT = {
					faith = root.faith
				}
				faith = { has_doctrine = doctrine_pluralism_pluralistic }
			}
			NOT = {
				root.faith = { has_doctrine = doctrine_pluralism_pluralistic }
			}
		}
		add = {
			value = -20
			if = {
				limit = {
					scope:impress_check.faith = {
						faith_hostility_level = {
							target = root.faith
							value >= faith_hostile_level
						}
					}
				}
				add = -20
			}
			if = {
				limit = {
					scope:impress_check.faith = {
						faith_hostility_level = {
							target = root.faith
							value >= faith_evil_level
						}
					}
				}
				add = -20
			}
		}
	}
	#Different faith, both have pluralism.
	if = {
		limit = {
			scope:impress_check = {
				NOT = {
					faith = root.faith
				}
				root.faith = { has_doctrine = doctrine_pluralism_pluralistic }
				faith = { has_doctrine = doctrine_pluralism_pluralistic }
			}
		}
		add = {
			value = -10
			if = {
				limit = {
					scope:impress_check.faith = {
						faith_hostility_level = {
							target = root.faith
							value >= faith_hostile_level
						}
					}
				}
				add = -10
			}
			if = {
				limit = {
					scope:impress_check.faith = {
						faith_hostility_level = {
							target = root.faith
							value >= faith_evil_level
						}
					}
				}
				add = -10
			}
		}
	}
	#I am a King!
	if = {
		limit = {
			scope:impress_check = { highest_held_title_tier = tier_kingdom }
		}
		add = {
			value = -50
			if = {
				limit = {
					scope:impress_check = {
						OR = {
							government_has_flag = government_is_republic
							government_has_flag = government_is_theocracy
						}
					}
				}
				add = -50
			}
			if = {
				limit = {
					scope:impress_check.sub_realm_size >= 5
				}
				add = -50
			}
			if = {
				limit = {
					scope:impress_check.sub_realm_size >= 10
				}
				add = -100
			}
		}
	}
	#We just fought against each other.
	if = {
		limit = {
			scope:impress_check = {
				any_truce_holder = {
					this = root
				}
			}
		}
		add = -50
	}
	#I fought an independence war against you.
	if = {
		limit = {
			scope:impress_check = {
				exists = var:independence_war_former_liege
				var:independence_war_former_liege = root
			}
		}
		add = -200
	}
	# I am Tribal and you are not
	if = {
		limit = {
			scope:impress_check = {
				government_has_flag = government_is_tribal
			}
			root = {
				NOT = { government_has_flag = government_is_tribal }
			}
		}
		add = -20
	}
	# You are Tribal and I am not
	if = {
		limit = {
			root = {
				government_has_flag = government_is_tribal
			}
			scope:impress_check = {
				NOT = { government_has_flag = government_is_tribal }
			}
		}
		add = -20
	}
	#Isolationist tradition
	if = {
		limit = {
			NOT = {
				root.culture = scope:impress_check.culture
			}
			scope:impress_check.culture = {
				has_cultural_tradition = tradition_isolationist
			}
		}
		add = -20
	}
	#Bankrupt
	if = {
		limit = {
			root.gold <= -1
		}
		add = -100
	}
	#Wide difference in rank
	if = {
		limit = {
			root = {
				tier_difference = {
					target = scope:impress_check
					value > 1
				}
			}
		}
		add = 10
	}
	# Allied
	if = {
		limit = {
			scope:impress_check = {
				is_allied_to = root
			}
		}
		add = 20
	}
	# Is the Rightful Liege of recipient
	if = {
		limit = {
			is_rightful_liege_of = scope:impress_check
		}
		add = 20
	}
	#Is not the Rightful Liege of recipient
	else = {
		add = -20
	}
	# Encircled
	if = {
		limit = {
			scope:impress_check = {
				NOT = {
					any_neighboring_top_liege_realm_owner = {
						NOT = {
							this = root
						}
					}
				}
				NOT = {
					any_realm_county = {
						is_coastal_county = yes
					}
				}
			}
		}
		add = 20
	}
	#Distant Realm — Overseas Connection
	if = {
		limit = {
			root = {
				character_is_realm_neighbor = scope:impress_check
				NOT = { #Ibiza should want to be a vassal of Mallorca, etc.
					character_is_land_realm_neighbor = scope:impress_check
					is_rightful_liege_of = scope:impress_check
				}
			}
		}
		add = -100
	}

	if = {
		limit = {
			root = {
				number_of_powerful_vassals >= 1
			}
		}
	  	  add = {
			value = 0
			root = {
				every_powerful_vassal = {
					limit = {
						opinion = { target = root value <= -10 }
						NOT = { opinion = { target = root value <= -20 } }
					}
					add = -10
				}
				every_powerful_vassal = {
					limit = {
						opinion = { target = root value <= -20 }
						NOT = { opinion = { target = root value <= -30 } }
					}
					add = -20
				}
				every_powerful_vassal = {
					limit = {
						opinion = { target = root value <= -30 }
						NOT = { opinion = { target = root value <= -40 } }
					}
					add = -30
				}
				every_powerful_vassal = {
					limit = {
						opinion = { target = root value <= -40 }
						NOT = { opinion = { target = root value <= -50 } }
					}
					add = -40
				}
				every_powerful_vassal = {
					limit = {
						opinion = { target = root value <= -50 }
						NOT = { opinion = { target = root value <= -60 } }
					}
					add = -50
				}
				every_powerful_vassal = {
					limit = {
						opinion = { target = root value <= -60 }
						NOT = { opinion = { target = root value <= -70 } }
					}
					add = -60
				}
				every_powerful_vassal = {
					limit = {
						opinion = { target = root value <= -70 }
						NOT = { opinion = { target = root value <= -80 } }
					}
					add = -70
				}
				every_powerful_vassal = {
					limit = {
						opinion = { target = root value <= -80 }
						NOT = { opinion = { target = root value <= -90 } }
					}
					add = -80
				}
				every_powerful_vassal = {
					limit = {
						opinion = { target = root value <= -90 }
						NOT = { opinion = { target = root value <= -100 } }
					}
					add = -90
				}
				every_powerful_vassal = {
					limit = {
						opinion = { target = root value <= -100 }
					}
					add = -100
				}
				
				every_powerful_vassal = {
					limit = {
						opinion = { target = root value < 10 }
						NOT = { opinion = { target = root value > -10 } }
					}
					add = 1
				}
				
				every_powerful_vassal = {
					limit = {
						opinion = { target = root value >= 10 }
						NOT = { opinion = { target = root value >= 20 } }
					}
					add = 10
				}
				every_powerful_vassal = {
					limit = {
						opinion = { target = root value >= 20 }
						NOT = { opinion = { target = root value >= 30 } }
					}
					add = 20
				}
				every_powerful_vassal = {
					limit = {
						opinion = { target = root value >= 30 }
						NOT = { opinion = { target = root value >= 40 } }
					}
					add = 30
				}
				every_powerful_vassal = {
					limit = {
						opinion = { target = root value >= 40 }
						NOT = { opinion = { target = root value >= 50 } }
					}
					add = 40
				}
				every_powerful_vassal = {
					limit = {
						opinion = { target = root value >= 50 }
						NOT = { opinion = { target = root value >= 60 } }
					}
					add = 50
				}
				every_powerful_vassal = {
					limit = {
						opinion = { target = root value >= 60 }
						NOT = { opinion = { target = root value >= 70 } }
					}
					add = 60
				}
				every_powerful_vassal = {
					limit = {
						opinion = { target = root value >= 70 }
						NOT = { opinion = { target = root value >= 80 } }
					}
					add = 70
				}
				every_powerful_vassal = {
					limit = {
						opinion = { target = root value >= 80 }
						NOT = { opinion = { target = root value >= 90 } }
					}
					add = 80
				}
				every_powerful_vassal = {
					limit = {
						opinion = { target = root value >= 90 }
						NOT = { opinion = { target = root value >= 100 } }
					}
					add = 90
				}
				every_powerful_vassal = {
					limit = {
						opinion = { target = root value >= 100 }
					}
					add = 100
				}
				
				if = {
					limit = {
						number_of_powerful_vassals > 0
					}
					divide = number_of_powerful_vassals
				}
				else = {
					divide = 5
				}
				divide = 5
			}
	  	}
	}
	#Friend modifier.
	if = {
		limit = {
			scope:impress_check = {
				has_relation_friend = root
				NOT = { has_relation_best_friend = root }
			}
		}
		add = 10
	}
	#Best Friend modifier.
	if = {
		limit = {
			scope:impress_check = {
				has_relation_best_friend = root
			}
		}
		add = 20
	}
	#Lover modifier.
	if = {
		limit = {
			scope:impress_check = {
				has_relation_lover = root
				NOT = { has_relation_soulmate = root }
			}
		}
		add = 10
	}
	#Soulmate modifier.
	if = {
		limit = {
			scope:impress_check = {
				has_relation_soulmate = root
			}
		}
		add = 20
	}
	#Rivalry modifier.
	if = {
		limit = {
			scope:impress_check = {
				has_relation_rival = root
				NOT = { has_relation_nemesis = root }
			}
		}
		add = -100
	}
	#Nemesis modifier.
	if = {
		limit = {
			scope:impress_check = {
				has_relation_nemesis = root
			}
		}
		add = -1000
	}
	#Same Dynasty modifier.
	if = {
		limit = {
			scope:impress_check = {
				dynasty = root.dynasty
			}
		}
		add = 5
	}
	# Same language
	if = {
		limit = {
			root = {
				knows_language_of_culture = scope:impress_check.culture
			}
		}
		add = 5
	}
	# Iberian Struggle, less likely for outsiders to vassalize inside
	if = {
		limit = {
			root = {
				NOT = {
					any_character_struggle = { is_struggle_type = iberian_struggle }
				}
			}
			scope:impress_check = {
				any_character_struggle = { is_struggle_type = iberian_struggle }
			}
		}
		add = -35
	}
	#Ageism modifier vs kids.
	if = {
		limit = {
			root = {
				age < 12
			}
			scope:impress_check = {
				age > 16
			}
		}
		add = -5
	}
	#Illegitimacy modifier.
	if = {
		limit = {
			OR = {
				AND = {
					root = {
						has_trait = bastard
					}
					scope:impress_check = {
						faith = { NOT = { has_doctrine = doctrine_bastardry_none } }
					}
				}
				has_trait = denounced
				has_trait = disinherited
			}
		}
		add = -10
	}
	#Claimant modifier.
	if = {
		limit = {
			root.primary_title = {
				scope:impress_check = {
					has_claim_on = prev
				}
			}
		}
		add = -20
	}
	# Ambitious
	if = {
		limit = {
			scope:impress_check = {
				has_trait = ambitious
			}
		}
		add = -20
	}
	# Paranoid
	if = {
		limit = {
			scope:impress_check = {
				has_trait = paranoid
			}
		}
		add = -20
	}
	# Arrogant
	if = {
		limit = {
			scope:impress_check = {
				has_trait = arrogant
			}
		}
		add = -20
	}
	# Fickle
	if = {
		limit = {
			scope:impress_check = {
				has_trait = fickle
			}
		}
		add = -10
	}
	# Stubborn
	if = {
		limit = {
			scope:impress_check = {
				has_trait = stubborn
			}
		}
		add = -10
	}
	# Trusting
	if = {
		limit = {
			scope:impress_check = {
				has_trait = trusting
			}
		}
		add = 5
	}
	# Content
	if = {
		limit = {
			scope:impress_check = {
				has_trait = content
			}
		}
		add = 5
	}
	# OPINION INFLUENCE
	if = {
		limit = {
			scope:impress_check = {
				has_dread_level_towards = {
					target = root
					level = 1
				}
			}
		}
		add = {
			value = 10
			if = {
				limit = {
					root = {
						exists = root.dynasty
						dynasty = {
							has_dynasty_perk = guile_legacy_5
						}
					}
				}
				multiply = 2
			}
		}
	}
	if = {
		limit = {
			scope:impress_check = {
				has_dread_level_towards = {
					target = root
					level = 2
				}
			}
		}
		add = {
			value = 20
			if = {
				limit = {
					root = {
						exists = root.dynasty
						dynasty = {
							has_dynasty_perk = guile_legacy_5
						}
					}
				}
				multiply = 2
			}
		}
	}
	
	if = {
		limit = {
			root = {
				has_royal_court = yes
				has_dlc_feature = royal_court
				has_court_type = court_diplomatic
				court_grandeur_current_level >= 1
			}
		}
		add = {
			value = root.court_grandeur_current
			if = {
				limit = { # Reduce the bonus if you are below your expected level
					root = {
						court_grandeur_current_level < court_grandeur_minimum_expected_level
					}
				}
				multiply = 0.15
			}
			else = {
				multiply = 0.3
			}
		}
	}
	# LEGITIMACY
	if = {
		limit = {
			root = {
				is_valid_for_legitimacy_change = yes
				legitimacy_level != 3
				is_rightful_liege_of = scope:impress_check
			}
		}
		add = {
			value = 0
			if = {
				limit = { root.legitimacy_level <= 2 }
				add = -15
			}
			if = {
				limit = { root.legitimacy_level <= 1 }
				add = -15
			}
			if = {
				limit = { root.legitimacy_level >= 4 }
				add = 10
			}
			if = {
				limit = { root.legitimacy_level >= 5 }
				add = 20
			}
			if = {
				limit = { root.legitimacy_level >= 6 }
				add = 30
			}
		}
	}

	# AI-only weights, keep the pope from vassalizing too fast
	if = {
		limit = {
			exists = faith:catholic.religious_head
			faith:catholic.religious_head = root
			root = { is_ai = yes }
		}
		add = -50
	}
}

base_wedding_cost = {
	# Base cost
	value = 25
	if = {
		limit = {
			highest_held_title_tier >= tier_duchy
		}
		add = 25
	}
	if = {
		limit = {
			highest_held_title_tier >= tier_kingdom
		}
		add = 75
	}
	if = {
		limit = {
			highest_held_title_tier >= tier_empire
		}
		add = 75
	}
}

#This is only to be used in the arrange marriage interaction window
ui_avg_wedding_cost = {
	value = 0
	# Base Cost
	add = {
		value = root.base_wedding_cost
		desc = WEDDING_BASE_COST
		# Scale by Era
		multiply = {
			value = activity_cost_scale_by_era
			desc = activity_cost_scale_by_era_desc
		}
		if = {
			limit = {
				root.dynasty ?= { has_dynasty_perk = ep2_activities_legacy_2 }
			}
			multiply = {
				value = ep2_activities_legacy_2_grand_weddings_discount_value
				desc = ep2_activities_legacy_track
			}
			# Some people get one free.
			if = {
				limit = { factor_zero_if_entitled_to_freebie_activity_trigger = yes }
				multiply = 0
			}
		}
		# OPTIONS
		add = { # Entertainment
			add = { # Calculate the average of the three option costs
				value = 0
				add = 20 # Bad Option Cost
				add = 60 # Normal Option Cost
				add = 180 # Good Option Cost
				# Divide by the total number of option levels so we get an average option cost
				divide = 3
				# Scale option costs by era
				multiply = activity_cost_scale_by_era
			}
			if = {
				limit = {
					root.dynasty ?= { has_dynasty_perk = ep2_activities_legacy_2 }
				}
				multiply = {
					value = ep2_activities_legacy_2_grand_weddings_discount_value
					desc = ep2_activities_legacy_track
				}
				# Some people get one free.
				if = {
					limit = { factor_zero_if_entitled_to_freebie_activity_trigger = yes }
					multiply = 0
				}
			}
		}
		add = { # Food
			value = { # Calculate the average of the three option costs
				value = 0
				add = 20 # Bad Option Cost
				add = 60 # Normal Option Cost
				add = 180 # Good Option Cost
				# Scale option costs by era
				multiply = activity_cost_scale_by_era
				# Divide by the total number of option levels so we get an average option cost
				divide = 3
			}
			if = {
				limit = {
					root.dynasty ?= { has_dynasty_perk = ep2_activities_legacy_2 }
				}
				multiply = {
					value = ep2_activities_legacy_2_grand_weddings_discount_value
					desc = ep2_activities_legacy_track
				}
				# Some people get one free.
				if = {
					limit = { factor_zero_if_entitled_to_freebie_activity_trigger = yes }
					multiply = 0
				}
			}
		}
		add = { # Decoration
			value = { # Calculate the average of the three option costs
				value = 0
				add = 40 # Bad Option Cost
				add = 120 # Normal Option Cost
				add = 360 # Good Option Cost
				# Scale option costs by era
				multiply = activity_cost_scale_by_era
				# Divide by the total number of option levels so we get an average option cost
				divide = 3
			}
			if = {
				limit = {
					root.dynasty ?= { has_dynasty_perk = ep2_activities_legacy_2 }
				}
				multiply = {
					value = ep2_activities_legacy_2_grand_weddings_discount_value
					desc = ep2_activities_legacy_track
				}
				# Some people get one free.
				if = {
					limit = { factor_zero_if_entitled_to_freebie_activity_trigger = yes }
					multiply = 0
				}
			}
		}
		# Make it a multiple of 5 (rounded up)
		divide = 5
		ceiling = yes
		multiply = 5
	}
}

base_bloody_wedding_cost = {
	# Base cost
	value = base_wedding_cost
	multiply = 2.5
	subtract = base_wedding_cost
}

real_wedding_cost_actor_scope = {
	value = {
		add = {
			value = scope:actor.base_wedding_cost
			desc = WEDDING_BASE_COST
		}
		multiply = {
			value = activity_cost_scale_by_era
			desc = activity_cost_scale_by_era_desc
		}
		# If there's a host already, scope into them.
		if = {
			limit = { exists = scope:actor }
			# Dynasty Legacies.
			if = {
				limit = {
					scope:actor.dynasty ?= { has_dynasty_perk = ep2_activities_legacy_2 }
				}
				multiply = ep2_activities_legacy_2_grand_weddings_discount_value
			}
			# Some people get one free.
			if = {
				limit = {
					scope:actor = {
						factor_zero_if_entitled_to_freebie_activity_trigger = yes
					}
				}
				multiply = 0
			}
		}
	}
}

ai_wedding_promise_gold_actor = {
	# Base Cost
	add = {
		value = scope:actor.real_wedding_cost_actor_scope
	}

	# OPTIONS
	add = { # Entertainment
		value = { # Calculate the average of the three option costs
			value = 0 
			add = 20 # Bad Option Cost 
			add = 60 # Normal Option Cost 
			add = 180 # Good Option Cost 
			# Scale option costs by era 
			multiply = scope:actor.activity_cost_scale_by_era
			# Divide by the total number of option levels so we get an average option cost
			divide = 3
		}
	}
	add = { # Food
		value = { # Calculate the average of the three option costs
			value = 0 
			add = 20 # Bad Option Cost 
			add = 60 # Normal Option Cost 
			add = 180 # Good Option Cost 
			# Scale option costs by era 
			multiply = scope:actor.activity_cost_scale_by_era
			# Divide by the total number of option levels so we get an average option cost
			divide = 3
		}
	}
	add = { # Decoration
		value = { # Calculate the average of the three option costs
			value = 0 
			add = 40 # Bad Option Cost 
			add = 120 # Normal Option Cost 
			add = 360 # Good Option Cost 
			# Scale option costs by era 
			multiply = scope:actor.activity_cost_scale_by_era
			# Divide by the total number of option levels so we get an average option cost
			divide = 3
		}
	}

	if = {
		limit = { exists = scope:actor }
		# Dynasty Legacies.
		if = {
			limit = {
				scope:actor.dynasty ?= { has_dynasty_perk = ep2_activities_legacy_2 }
			}
			multiply = ep2_activities_legacy_2_grand_weddings_discount_value
		}
		# Some people get one free.
		if = {
			limit = {
				scope:actor = {
					factor_zero_if_entitled_to_freebie_activity_trigger = yes
				}
			}
			multiply = 0
		}
	}
}

real_wedding_cost_root_scope = {
	value = {
		add = {
			value = base_wedding_cost
			desc = WEDDING_BASE_COST
		}
		multiply = {
			value = activity_cost_scale_by_era
			desc = activity_cost_scale_by_era_desc
		}
		# If there's a host already, scope into them.
		if = {
			limit = { exists = this }
			# Dynasty Legacies.
			if = {
				limit = {
					dynasty ?= { has_dynasty_perk = ep2_activities_legacy_2 }
				}
				multiply = ep2_activities_legacy_2_grand_weddings_discount_value
			}
			# Some people get one free.
			if = {
				limit = {
					factor_zero_if_entitled_to_freebie_activity_trigger = yes
				}
				multiply = 0
			}
		}
	}
}

real_wedding_cost_root_scope_plus_50 = {
	value = {
		add = {
			value = base_wedding_cost
			desc = WEDDING_BASE_COST
		}
		add = 50
		multiply = {
			value = activity_cost_scale_by_era
			desc = activity_cost_scale_by_era_desc
		}
		# If there's a host already, scope into them.
		if = {
			limit = { exists = this }
			# Dynasty Legacies.
			if = {
				limit = {
					dynasty ?= { has_dynasty_perk = ep2_activities_legacy_2 }
				}
				multiply = ep2_activities_legacy_2_grand_weddings_discount_value
			}
			# Some people get one free.
			if = {
				limit = {
					factor_zero_if_entitled_to_freebie_activity_trigger = yes
				}
				multiply = 0
			}
		}
	}
}

marriage_recieve_proposal_cooldown = {
	value = 0
	if = {
		limit = {
			is_ai = yes
			scope:recipient ?= { is_ai = no }
		}
		add = 0.5
	}
}

came_to_my_wedding_opinion_value_low = {
	# Keep synced with came_to_my_wedding_opinion uses
	value = 5
}

came_to_my_wedding_opinion_value_medium = {
	# Keep synced with came_to_my_wedding_opinion uses
	value = 10
}

came_to_my_wedding_opinion_value_high = {
	# Keep synced with came_to_my_wedding_opinion uses
	value = 15
}

number_of_current_and_former_spouses = {
	value = 0
	every_spouse = {
		add = 1
	}
	every_former_spouse = {
		add = 1
	}
	every_memory = {
		limit = { has_memory_type = spouse_died }
		add = 1
	}
}

wedding_ceremony_phase_duration = {
	value = 2
	if = {
		limit = { has_multiple_players = yes }
		add = 2
	}
}

dolt_stewardship_adjusted_difficulty_value = {
	value = 24
	subtract = scope:dolt.stewardship
}
