﻿###################
# SCHEME VALUES	#
###################
# Determines the scheme progress loss when declining to execute it at full progress
decline_execution_setback = -3
major_decline_execution_setback = -5

# Failed scheme setback values
scheme_failed_outcome_setback_value = -7

#Scheme progress changes, 10% of current phase duration max in days
scheme_progress_gain = {
	value = scope:scheme.scheme_phase_duration
	subtract = scope:scheme.scheme_progress
	multiply = 0.1
}
scheme_progress_loss = {
	value = scope:scheme.scheme_phase_duration
	subtract = scope:scheme.scheme_progress
	multiply = -0.1
}
# Secrecy changes
minor_secrecy_loss = -0.05
medium_secrecy_loss = -0.1
major_secrecy_loss  = -0.15
minor_secrecy_gain = 0.05
medium_secrecy_gain = 0.1
major_secrecy_gain = 0.15

#Watchful Modifier
watchful_modifier_duration = 730


# EVENT COOLDOWN FOR VARIOUS SCHEMES
default_scheme_event_cooldown_duration_value = 730
spy_scheme_event_cooldown_time = 365

# BRIBES
bribe_value = {
	value = 50
	if = {
		limit = {
			scope:recipient.ai_greed > 0
		}
		add = {
			value = scope:recipient.ai_greed
			divide = 4
		}
	}

	if = {
		limit = {
			scope:recipient = { is_playable_character = yes }
			scope:recipient.primary_title.tier < tier_duchy
		}
		multiply = 2
	}
	else_if = {
		limit = {
			scope:recipient.primary_title.tier >= tier_duchy
		}
		multiply = 3
	}

	if = {
		limit = {
			scope:recipient = {
				liege = scope:actor
				is_theocratic_lessee = yes
			}
			scope:actor.primary_title.tier < tier_duchy
		}
		multiply = 2
	}
	else_if = {
		limit = {
			scope:recipient = {
				liege = scope:actor
				is_theocratic_lessee = yes
			}
			scope:actor.primary_title.tier >= tier_duchy
		}
		multiply = 3
	}

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

	if = {
		limit = {
			scope:recipient = {
				OR = {
					AND = {
						is_playable_character = yes
						government_has_flag = government_is_tribal
					}
					AND = {
						is_playable_character = no
						exists = liege
						liege = {
							government_has_flag = government_is_tribal
						}
					}
					AND = {
						is_playable_character = no
						exists = host
						host = {
							government_has_flag = government_is_tribal
						}
					}
				}
			}
		}
		multiply = 0.25
		min = 5
	}

	# Discount from BP2 imaginary friend story cycle ending
	if = {
		limit = {
			scope:actor = { has_character_modifier = imaginary_friend_mad_modifier }
		}
		multiply = 0.5
		min = 5
	}
}

greater_bribe_value = {
	value = { add = bribe_value }
	multiply = 2
}

prestige_bribe_value = {
	# Base.
	value = medium_prestige_value
	# Your tier.
	add = {
		value = 25
		multiply = scope:actor.highest_held_title_tier
	}
	# Their tier.
	add = {
		value = 25
		multiply = scope:recipient.highest_held_title_tier
	}
}

influence_bribe_value = {
	# Base.
	value = major_influence_value
	# Your tier.
	add = {
		value = 25
		multiply = scope:actor.highest_held_title_tier
	}
	# Their tier.
	add = {
		value = 25
		multiply = scope:recipient.highest_held_title_tier
	}
}

piety_bribe_value = {
	# Base.
	value = medium_piety_value
	# Your tier.
	add = {
		value = 25
		multiply = scope:actor.highest_held_title_tier
	}
	# Their tier.
	add = {
		value = 25
		multiply = scope:recipient.highest_held_title_tier
	}
}

#GIFTS
gift_value = {
	value = 50
	if = {
		limit = {
			scope:recipient.ai_greed > 0
		}
		add = {
			value = scope:recipient.ai_greed
			divide = 4
		}
	}

	if = {
		limit = {
			scope:recipient = { is_playable_character = yes }
			scope:recipient.primary_title.tier < tier_duchy
		}
		multiply = 2
	}
	else_if = {
		limit = {
			scope:recipient.primary_title.tier >= tier_duchy
		}
		multiply = 3
	}

	if = {
		limit = {
			scope:recipient = {
				liege = scope:actor
				is_theocratic_lessee = yes
			}
			scope:actor.primary_title.tier < tier_duchy
		}
		multiply = 2
	}
	else_if = {
		limit = {
			scope:recipient = {
				liege = scope:actor
				is_theocratic_lessee = yes
			}
			scope:actor.primary_title.tier >= tier_duchy
		}
		multiply = 3
	}

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

	if = {
		limit = {
			scope:recipient = {
				OR = {
					AND = {
						is_playable_character = yes
						government_has_flag = government_is_tribal
					}
					AND = {
						is_playable_character = no
						exists = liege
						liege = {
							government_has_flag = government_is_tribal
						}
					}
					AND = {
						is_playable_character = no
						exists = host
						host = {
							government_has_flag = government_is_tribal
						}
					}
				}
			}
		}
		multiply = 0.25
		min = 5
	}
}

bribe_acceptance_value = {
	value = 10
	if = {
		limit = {
			root.ai_greed > 0
		}
		add = root.ai_greed
	}
	divide = 5
	ceiling = yes
	multiply = 5
}

sway_opinion_increase_per_success = 25
sway_max_value = 100

# Claim Throne values
claim_throne_discovered_prestige_loss = {
	value = major_prestige_loss
}
claim_throne_discovered_failure_prestige_loss = {
	value = medium_prestige_loss
}

# Vengeful Trait Scheme Success Chance Modifier
vengeful_scheme_success_chance_modifier = 15

court_scheme_max_compatability_value = {
	value = 30
	if = {
		limit = {
			culture = {
				has_cultural_parameter = ai_romance_scheme_increase
			}
		}
		add = 70
	}
}

##################################################
# Schemes 2.5

##################################################
# Misc Values

# Script copy of a define for easier, more legible referencing.
opportunity_cap_value = { value = define:NScheme|SCHEME_MAX_OPPORTUNITIES }

##################################################
# Parameter Values

# Control values for scheme parameters
## There's gonna be a lot of dumb letter abbreviations here, just go with it: the script will _not_ be readable by mortal eyes if we write the whole thing out.
## t1 is slow.
## t2 is average.
## t3 is fast.
### Base Progress Goal
#### Each one is the _base_ length for a phase to take for schemes of that tempo, before speed modifiers are applied.
t3_base_phase_length_value = 70
t2_base_phase_length_value = 120
t1_base_phase_length_value = 170
### Base Maximum Success
#### Max success before agents.
t1_base_max_success_value = 20
t2_base_max_success_value = 30
t3_base_max_success_value = 40
### Speed per Skill Point
#### How many days we knock off phase duration per relevant skill point of the scheme owner.
t3_spsp_owner_value = -0.5
t2_spsp_owner_value = -0.25
t1_spsp_owner_value = -0.1
### Speed per Target Skill Point
#### How many days we add on to phase duration per relevant skill point of the scheme target.
t3_spsp_target_value = 0.3
t2_spsp_target_value = 0.1
t1_spsp_target_value = 0.05
### Spymaster Speed per Skill Point
#### How many days we knock off phase duration per relevant skill point of the scheme owner's spymaster.
t3_spsp_owner_spy_value = -0.3
t2_spsp_owner_spy_value = -0.15
t1_spsp_owner_spy_value = -0.05
### Target Spymaster Speed per Skill Point
#### How many days we add on to phase duration per relevant skill point of the scheme target's spymaster.
t3_spsp_target_spy_value = 0.3
t2_spsp_target_spy_value = 0.1
t1_spsp_target_spy_value = 0.05
### Success Chance Growth per Skill Point
#### How much success chance per phase per relevant skill point of the scheme owner.
laamp_contract_scgpsp_value = 0.7
t3_scgpsp_value = 0.6
t2_scgpsp_value = 0.45
t1_scgpsp_value = 0.3

# Scheme speed standardisation modifiers.
## Speeding up a scheme.
microscopic_scheme_phase_duration_bonus_value = -2
miniscule_scheme_phase_duration_bonus_value = -5
minor_scheme_phase_duration_bonus_value = -10
medium_scheme_phase_duration_bonus_value = -20
major_scheme_phase_duration_bonus_value = -40
massive_scheme_phase_duration_bonus_value = -60
monumental_scheme_phase_duration_bonus_value = -100
## Slowing down a scheme.
microscopic_scheme_phase_duration_malus_value = 2
miniscule_scheme_phase_duration_malus_value = 5
minor_scheme_phase_duration_malus_value = 10
medium_scheme_phase_duration_malus_value = 20
major_scheme_phase_duration_malus_value = 40
massive_scheme_phase_duration_malus_value = 60
monumental_scheme_phase_duration_malus_value = 100

##################################################
# Success Chance Values

scheme_phases_till_max_success_value = {
	value = max_scheme_success_chance
	subtract = scheme_success_chance
	#TODO_CD_EP3; get the actual scheme growth value from Code, this is just keyed to murder.
	divide = {
		value = scheme_owner.intrigue
		multiply = 0.3
	}
	ceiling = yes
}

# What % intercept chance does this thing grant against murder schemes?
## We don't use these for court positions, generally, because we want more fine-tuning per court position & between their breakpoints.
add_intercept_repeatable_minor_value = 2
add_intercept_repeatable_medium_value = 5
add_intercept_repeatable_major_value = 10
add_intercept_repeatable_massive_value = 20

scheme_intercept_repeatable_chance_total_value = {
	# Court positions.
	## Remember with all of these: it's an aggregate, so if you give one court position (_especially_ one that you can have multiple of) too much, then you may render a character unmurderable.
	## Bodyguard.
	### Has subsumed the shieldmaiden/varangian variants: means we don't have to iterate over courtiers.
	if = {
		limit = { employs_court_position = bodyguard_court_position }
		every_court_position_holder = {
			type = bodyguard_court_position
			limit = { bodyguard_will_actually_do_job_trigger = yes }
			# Now we add aptitude per breakpoint, starting highest to lowest.
			## Excellent
			if = {
				limit = { aptitude:bodyguard_court_position >= 4 }
				add = 10
			}
			## Good
			else_if = {
				limit = { aptitude:bodyguard_court_position = 3 }
				add = 8
			}
			## Average
			else_if = {
				limit = { aptitude:bodyguard_court_position = 2 }
				add = 6
			}
			## Poor
			else_if = {
				limit = { aptitude:bodyguard_court_position = 1 }
				add = 4
			}
			## Terrible
			else = { add = 2 }
		}
	}
	## Food taster.
	if = {
		limit = { employs_court_position = food_taster_court_position }
		every_court_position_holder = {
			type = food_taster_court_position
			limit = { foodtaster_will_actually_do_job_trigger = yes }
			# Now we add aptitude per breakpoint, starting highest to lowest.
			## Excellent
			if = {
				limit = { aptitude:food_taster_court_position >= 4 }
				add = 8
			}
			## Good
			else_if = {
				limit = { aptitude:food_taster_court_position = 3 }
				add = 6
			}
			## Average
			else_if = {
				limit = { aptitude:food_taster_court_position = 2 }
				add = 4
			}
			## Poor
			else_if = {
				limit = { aptitude:food_taster_court_position = 1 }
				add = 2
			}
			## Terrible
			else = { add = 1 }
		}
	}
	## Cupbearer.
	if = {
		limit = { employs_court_position = cupbearer_court_position }
		every_court_position_holder = {
			type = cupbearer_court_position
			limit = { cupbearer_will_actually_do_job_trigger = yes }
			# Now we add aptitude per breakpoint, starting highest to lowest.
			## Excellent
			if = {
				limit = { aptitude:cupbearer_court_position >= 4 }
				add = 3
			}
			## Good
			else_if = {
				limit = { aptitude:cupbearer_court_position = 3 }
				add = 2
			}
			## Average
			else_if = {
				limit = { aptitude:cupbearer_court_position = 2 }
				add = 1
			}
			## Poor
			else_if = {
				limit = { aptitude:cupbearer_court_position = 1 }
				add = 0
			}
			## Terrible
			else = { add = 0 }
		}
	}
	# Traits.
	## Gluttonous.
	if = {
		limit = { has_trait = gluttonous }
		add = add_intercept_repeatable_minor_value
	}
	# Character modifiers.
	## Personal guard.
	if = {
		limit = { has_character_modifier = spouse_martial_personal_guard_modifier }
		add = add_intercept_repeatable_major_value
	}

	# You can never have more than a certain amount of intercept value.
	max = 75
}

##################################################
# Secrecy Values

# Cap secrecy for the scheme_owner to a sensible maximum value so that you can't single-handedly cover up for every gossip in the world.
secrecy_skill_contribution_max_value = 40

secrecy_base_value = {
	add = {
		value = 20
		desc = BASE
	}
	# Reduce by the target's scheme discovery chance, if appropriate.
	if = {
		limit = {
			# Scheme has to exist already.
			exists = this
			# We gotta be facing a character.
			is_scheme_target_type = character
			# Do they have a spymaster...
			scheme_target_character.cp:councillor_spymaster ?= {
				# ... who is performing the appropriate task...
				is_performing_council_task = task_disrupt_schemes
				NOR = {
					# ... who _isn't_ the scheme owner...
					this = scope:owner
					# ... or an agent in the scheme.
					save_temporary_scope_as = char_temp
					root = {
						any_scheme_agent_character = { this = scope:char_temp }
					}
				}
			}
		}
		add = {
			value = scope:target.cp:councillor_spymaster.spymaster_disrupt_schemes_total_modifier
			multiply = -1
			desc = secrecy.scheme_owner.spymaster.disrupt_schemes
		}
	}
}
secrecy_agent_count_reduction_value = {
	add = {
		value = {
			every_scheme_agent_slot = {
				limit = {
					is_filled = yes
					NOT = { agent_slot_has_contribution_type = secrecy }
				}
				add = -10
			}
		}
		desc = secrecy.num_agents
	}
}

# How many months, by default, before a scheme can be discovered in the monthly check?
## Schemes can always be discovered when they attempt conclusion.
## Only referenced in one spot in script, but we use a script value regardless so that we can refer to it in loc.
secrecy_grace_period_value = 6

# How many extra months of grace you get from the Court of Shadows lifestyle perk.
court_of_shadows_extra_secrecy_grace_value = 4

# The actual value checked for starting grace on a scheme — any extra bonuses can be fed in here (though you can also adjust it on the fly by modifying the variable set on the scheme itself).
secrecy_grace_character_total_starting_value = {
	value = secrecy_grace_period_value
	scope:scheme_launcher ?= {
		if = {
			limit = { has_perk = court_of_shadows_perk }
			add = court_of_shadows_extra_secrecy_grace_value
		}
	}
}

# Calc if the next scheme breach we get would destroy the scoped scheme.
scheme_breaches_about_to_hit_limit_value = {
	value = maximum_scheme_breaches
	add = -1
}

##################################################
# Interaction Values

# Standardised scheme starter package values, so that we can fake it for the widget.
scheme_starter_bonus_success_chance_value = 20
scheme_starter_bonus_secrecy_value = 25
scheme_starter_bonus_speed_value = -20

scheme_starter_duration_value = 8
scheme_starter_success_chance_cost_value = { value = major_gold_value }
scheme_starter_speed_cost_value = { value = medium_gold_value }
scheme_starter_secrecy_cost_value = { value = minor_gold_value }

##################################################
# Agent Values

# How many agents can a character have in a scheme before they're forced to make a final try?
character_max_scheme_agents_value = 5

# How many agent slots are filled in the scheme atm?
current_scheme_filled_agent_slots_value = {
	every_scheme_agent_slot = {
		limit = { is_filled = yes }
		add = 1
	}
}

# How much do we reduce the weight on agent types that we already have in a scheme?
weight_down_existing_agent_slots_value = 0.5

# What're the upper and lower constraints for how much contribution an agent can give?
## Because we don't want any agent to insta-boost you too high.
agent_scheme_contributor_max = 50
## Aaaaaand it's just way less of a headache of edge cases if they're never literally zero.
agent_scheme_contributor_min = 1


# Standard base value for agent contribution.
## Atm, we only really use this for calculating degree of closeness bonuses for agents in hostile schemes.
## Nothing stopping it from being updated for something like the inverse, though: best friends better at the plan_surprise_party scheme or whatever.
### Control values.
scheme_agent_general_bonuses_contribution_score_bonus_max_value = agent_max_skill_value
scheme_agent_general_bonuses_contribution_score_bonus_massive_value = 30
scheme_agent_general_bonuses_contribution_score_bonus_major_value = 20
scheme_agent_general_bonuses_contribution_score_bonus_medium_value = 10
scheme_agent_general_bonuses_contribution_score_bonus_minor_value = 5
scheme_agent_general_bonuses_contribution_score_bonus_miniscule_value = 2
### Actual value.
scheme_agent_general_bonuses_contribution_score_value = {
	# First off, are we dealing with a hostile scheme against a character or a title?
	if = {
		limit = {
			exists = scope:target
			trigger_if = {
				limit = {
					scope:scheme ?= {
						is_scheme_target_type = character
						is_scheme_category = hostile
					}
				}
				scope:scheme ?= {
					scheme_target_character = { save_temporary_scope_as = target_character }
				}
			}
			trigger_else_if = {
				limit = {
					scope:scheme ?= {
						is_scheme_target_type = title
						is_scheme_category = hostile
					}
				}
				scope:scheme ?= {
					scheme_target_title.holder ?= { save_temporary_scope_as = target_character }
				}
			}
			trigger_else = { always = no }
		}
		# Do we have a scope:target_character to play with now?
		if = {
			limit = { exists = scope:target_character }
			# Degree of closeness to target.
			if = {
				limit = {
					scope:target_character = {
						is_ruler = yes
						cp:councillor_spymaster ?= prev
					}
				}
				add = {
					add = scheme_agent_general_bonuses_contribution_score_bonus_max_value
					desc = "SCHEME_AGENT_IS_SPYMASTER_IN_MY_COURT"
				}
			}
			else_if = {
				limit = {
					scope:target_character = { is_ruler = no }
					has_council_position = councillor_spymaster
					scope:target_character.liege.cp:councillor_spymaster ?= this
				}
				add = {
					add = scheme_agent_general_bonuses_contribution_score_bonus_max_value
					desc = "SCHEME_AGENT_IS_SPYMASTER"
				}
			}
			else_if = {
				limit = { is_spouse_of = scope:target_character }
				add = {
					add = scheme_agent_general_bonuses_contribution_score_bonus_massive_value
					desc = "SCHEME_AGENT_IS_SPOUSE"
				}
			}
			else_if = {
				limit = { has_relation_best_friend = scope:target_character }
				add = {
					add = scheme_agent_general_bonuses_contribution_score_bonus_massive_value
					desc = "SCHEME_AGENT_IS_BEST_FRIEND"
				}
			}
			else_if = {
				limit = { has_relation_ward = scope:target_character }
				add = {
					add = scheme_agent_general_bonuses_contribution_score_bonus_massive_value
					desc = "SCHEME_AGENT_IS_GUARDIAN"
				}
			}
			else_if = {
				limit = { is_diarch_of_target = scope:target_character }
				add = {
					add = scheme_agent_general_bonuses_contribution_score_bonus_massive_value
					desc = "SCHEME_AGENT_IS_DIARCH"
				}
			}
			else_if = {
				limit = { has_relation_friend = scope:target_character }
				add = {
					add = scheme_agent_general_bonuses_contribution_score_bonus_major_value
					desc = "SCHEME_AGENT_IS_FRIEND"
				}
			}
			else_if = {
				limit = { is_concubine_of = scope:target_character }
				add = {
					add = scheme_agent_general_bonuses_contribution_score_bonus_major_value
					desc = "SCHEME_AGENT_IS_CONCUBINE"
				}
			}
			else_if = {
				limit = { has_relation_lover = scope:target_character }
				add = {
					add = scheme_agent_general_bonuses_contribution_score_bonus_major_value
					desc = "SCHEME_AGENT_IS_LOVER"
				}
			}
			else_if = {
				limit = {
					has_court_position = court_physician_court_position
					is_court_position_employer = {
						court_position = court_physician_court_position
						who = scope:target_character
					}
				}
				add = {
					add = scheme_agent_general_bonuses_contribution_score_bonus_major_value
					desc = "SCHEME_AGENT_IS_COURT_PHYSICIAN"
				}
			}
			else_if = {
				limit = {
					has_court_position = food_taster_court_position
					is_court_position_employer = {
						court_position = food_taster_court_position
						who = scope:target_character
					}
				}
				add = {
					add = scheme_agent_general_bonuses_contribution_score_bonus_major_value
					desc = "SCHEME_AGENT_IS_FOOD_TASTER"
				}
			}
			else_if = {
				limit = {
					has_court_position = cupbearer_court_position
					is_court_position_employer = {
						court_position = cupbearer_court_position
						who = scope:target_character
					}
				}
				add = {
					add = scheme_agent_general_bonuses_contribution_score_bonus_major_value
					desc = "SCHEME_AGENT_IS_CUP_BEARER"
				}
			}
			else_if = {
				limit = {
					has_court_position = chief_eunuch_court_position
					is_court_position_employer = {
						court_position = chief_eunuch_court_position
						who = scope:target_character
					}
				}
				add = {
					add = scheme_agent_general_bonuses_contribution_score_bonus_major_value
					desc = "SCHEME_AGENT_IS_CHIEF_EUNUCH"
				}
			}
			else_if = {
				limit = {
					has_court_position = bodyguard_court_position
					is_court_position_employer = {
						court_position = bodyguard_court_position
						who = scope:target_character
					}
				}
				add = {
					add = scheme_agent_general_bonuses_contribution_score_bonus_major_value
					desc = "SCHEME_AGENT_IS_BODYGUARD"
				}
			}
			else_if = {
				limit = {
					has_court_position = lady_in_waiting_court_position
					is_court_position_employer = {
						court_position = lady_in_waiting_court_position
						who = scope:target_character
					}
				}
				add = {
					add = scheme_agent_general_bonuses_contribution_score_bonus_minor_value
					desc = "SCHEME_AGENT_IS_LADY_IN_WAITING"
				}
			}
			else_if = {
				limit = {
					is_councillor_of = scope:target_character
					NOT = { has_council_position = councillor_spymaster }
				}
				add = {
					add = scheme_agent_general_bonuses_contribution_score_bonus_medium_value
					desc = "SCHEME_AGENT_IS_COUNCILLOR"
				}
			}
			else_if = {
				limit = { is_close_family_of = scope:target_character }
				add = {
					add = scheme_agent_general_bonuses_contribution_score_bonus_medium_value
					desc = "SCHEME_AGENT_IS_CLOSE_KIN"
				}
			}
			else_if = {
				limit = { is_powerful_vassal_of = scope:target_character }
				add = {
					add = scheme_agent_general_bonuses_contribution_score_bonus_minor_value
					desc = "SCHEME_AGENT_IS_POWERFUL_VASSAL"
				}
			}
			else_if = {
				limit = { is_extended_family_of = scope:target_character }
				add = {
					add = scheme_agent_general_bonuses_contribution_score_bonus_minor_value
					desc = "SCHEME_AGENT_IS_EXTENDED_FAMILY"
				}
			}
			else_if = {
				limit = {
					scope:target_character = { is_ruler = yes }
					is_ruler = yes
				}
				add = {
					add = scheme_agent_general_bonuses_contribution_score_bonus_miniscule_value
					desc = "SCHEME_AGENT_IS_VASSAL"
				}
			}
			else_if = {
				limit = {
					scope:target_character = { is_ruler = no }
					is_ruler = yes
				}
				add = {
					add = scheme_agent_general_bonuses_contribution_score_bonus_miniscule_value
					desc = "SCHEME_AGENT_IS_VASSAL_OF_LIEGE"
				}
			}
			# Rivalry boosts an agent's industriousness.
			if = {
				limit = { has_relation_nemesis = scope:target_character }
				add = {
					add = scheme_agent_general_bonuses_contribution_score_bonus_medium_value
					desc = "SCHEME_AGENT_IS_NEMESIS"
				}
			}
			else_if = {
				limit = { has_relation_rival = scope:target_character }
				add = {
					add = scheme_agent_general_bonuses_contribution_score_bonus_minor_value
					desc = "SCHEME_AGENT_IS_RIVAL"
				}
			}
		}
	}
	# Otherwise nada.
	else = { value = 0 }
}

# Agent contribution setup values.
# How much can any one of an agent's skills contribute to their score?
agent_max_skill_value = 25

# Ratio of 75% major skill to 25% minor skill.
agent_3to1_3_skill_mult_value = 0.75
agent_3to1_1_skill_mult_value = 0.25

# Ratio of 50% between two skills.
agent_1to1_1_skill_mult_value = 0.5

# Ratio of 50% major skill to 25% for two minor skills.
agent_2to1to1_2_skill_mult_value = 0.5
agent_2to1to1_1_skill_mult_value = 0.25

# Trait bonus'n'malus tiers.
agent_trait_bonus_t3_value = 9
agent_trait_bonus_t2_value = 6
agent_trait_bonus_t1_value = 3
agent_trait_malus_t1_value = -3
agent_trait_malus_t2_value = -6
agent_trait_malus_t3_value = -9

# Political Schemem agent values
political_agent_max_skill_value = 15
agent_house_power_score_mult = 0.1
agent_max_house_power_value = 30

agent_house_power_score_value = {
	value = 0 
	if = {
		limit = { exists = house }
		add = house.house_power_score
	}
	multiply = agent_house_power_score_mult
	ceiling = yes 
	max = agent_max_house_power_value
	desc = scheme_agent_aptitude.scaled_house_power_score
}

# Sync values for agents that have multiple contribution types.
## Justiciar.
agent_justiciar_contribution_value = {
	# Base value.
	value = scheme_agent_general_bonuses_contribution_score_value
	# Skills
	## Learning
	add = {
		value = learning
		multiply = agent_3to1_3_skill_mult_value
		ceiling = yes
		max = agent_max_skill_value
		desc = scheme_agent_aptitude.skill.learning
	}
	## Diplomacy
	add = {
		value = diplomacy
		multiply = agent_3to1_1_skill_mult_value
		ceiling = yes
		max = agent_max_skill_value
		desc = scheme_agent_aptitude.skill.diplomacy
	}
	# Traits
	## Bonuses
	### +++ Just
	if = {
		limit = { has_trait = just }
		add = {
			value = agent_trait_bonus_t3_value
			desc = scheme_agent_aptitude.trait.just
		}
	}
	### +++ Diligent
	if = {
		limit = { has_trait = diligent }
		add = {
			value = agent_trait_bonus_t3_value
			desc = scheme_agent_aptitude.trait.diligent
		}
	}
	### +++ Honest
	if = {
		limit = { has_trait = honest }
		add = {
			value = agent_trait_bonus_t3_value
			desc = scheme_agent_aptitude.trait.honest
		}
	}
	### ++ Patient
	if = {
		limit = { has_trait = patient }
		add = {
			value = agent_trait_bonus_t2_value
			desc = scheme_agent_aptitude.trait.patient
		}
	}
	### + Paranoid
	if = {
		limit = { has_trait = paranoid }
		add = {
			value = agent_trait_bonus_t1_value
			desc = scheme_agent_aptitude.trait.paranoid
		}
	}
	## Maluses
	### - Trusting
	if = {
		limit = { has_trait = trusting }
		add = {
			value = agent_trait_malus_t1_value
			desc = scheme_agent_aptitude.trait.trusting
		}
	}
	### -- Impatient
	if = {
		limit = { has_trait = impatient }
		add = {
			value = agent_trait_malus_t2_value
			desc = scheme_agent_aptitude.trait.impatient
		}
	}
	### --- Deceitful
	if = {
		limit = { has_trait = deceitful }
		add = {
			value = agent_trait_malus_t3_value
			desc = scheme_agent_aptitude.trait.deceitful
		}
	}
	### --- Diligent
	if = {
		limit = { has_trait = diligent }
		add = {
			value = agent_trait_malus_t3_value
			desc = scheme_agent_aptitude.trait.diligent
		}
	}
	### --- Arbitrary
	if = {
		limit = { has_trait = arbitrary }
		add = {
			value = agent_trait_malus_t3_value
			desc = scheme_agent_aptitude.trait.arbitrary
		}
	}

	# Cap this off.
	max = agent_scheme_contributor_max
	min = agent_scheme_contributor_min
}
## Wrangler
agent_wrangler_contribution_value = {
	value = scheme_agent_general_bonuses_contribution_score_value
	# Skills
	## Diplomacy
	add = {
		value = diplomacy
		multiply = agent_3to1_3_skill_mult_value
		ceiling = yes
		max = agent_max_skill_value
		desc = scheme_agent_aptitude.skill.diplomacy
	}
	## Intrigue
	add = {
		value = intrigue
		multiply = agent_3to1_1_skill_mult_value
		ceiling = yes
		max = agent_max_skill_value
		desc = scheme_agent_aptitude.skill.intrigue
	}
	# Traits
	## Bonuses
	### +++ Gregarious
	if = {
		limit = { has_trait = gregarious }
		add = {
			value = agent_trait_bonus_t3_value
			desc = scheme_agent_aptitude.trait.gregarious
		}
	}
	### +++ Diplomat
	if = {
		limit = { has_trait = diplomat }
		add = {
			value = agent_trait_bonus_t3_value
			desc = scheme_agent_aptitude.trait.diplomat
		}
	}
	### ++ Arrogant
	if = {
		limit = { has_trait = arrogant }
		add = {
			value = agent_trait_bonus_t2_value
			desc = scheme_agent_aptitude.trait.arrogant
		}
	}
	### ++ Ambitious
	if = {
		limit = { has_trait = ambitious }
		add = {
			value = agent_trait_bonus_t2_value
			desc = scheme_agent_aptitude.trait.ambitious
		}
	}
	### + Eccentric
	if = {
		limit = { has_trait = eccentric }
		add = {
			value = agent_trait_bonus_t1_value
			desc = scheme_agent_aptitude.trait.eccentric
		}
	}
	## Maluses
	### - Temperate
	if = {
		limit = { has_trait = temperate }
		add = {
			value = agent_trait_malus_t1_value
			desc = scheme_agent_aptitude.trait.temperate
		}
	}
	### -- Humble
	if = {
		limit = { has_trait = humble }
		add = {
			value = agent_trait_malus_t2_value
			desc = scheme_agent_aptitude.trait.humble
		}
	}
	### -- Trusting
	if = {
		limit = { has_trait = trusting }
		add = {
			value = agent_trait_malus_t2_value
			desc = scheme_agent_aptitude.trait.trusting
		}
	}
	### --- Content
	if = {
		limit = { has_trait = content }
		add = {
			value = agent_trait_malus_t3_value
			desc = scheme_agent_aptitude.trait.content
		}
	}
	### --- Forgiving
	if = {
		limit = { has_trait = forgiving }
		add = {
			value = agent_trait_malus_t3_value
			desc = scheme_agent_aptitude.trait.forgiving
		}
	}
	### --- Shy
	if = {
		limit = { has_trait = shy }
		add = {
			value = agent_trait_malus_t3_value
			desc = scheme_agent_aptitude.trait.shy
		}
	}
	# Cap this off.
	max = agent_scheme_contributor_max
	min = agent_scheme_contributor_min
}
## Cleric
agent_cleric_contribution_value = {
	# Base value.
	value = scheme_agent_general_bonuses_contribution_score_value
	# Skills
	## Diplomacy
	add = {
		value = diplomacy
		multiply = agent_3to1_3_skill_mult_value
		ceiling = yes
		max = agent_max_skill_value
		desc = scheme_agent_aptitude.skill.diplomacy
	}
	## Learning
	add = {
		value = learning
		multiply = agent_3to1_1_skill_mult_value
		ceiling = yes
		max = agent_max_skill_value
		desc = scheme_agent_aptitude.skill.learning
	}
	# Traits
	## Bonuses
	### +++ Zealous
	if = {
		limit = { has_trait = zealous }
		add = {
			value = agent_trait_bonus_t3_value
			desc = scheme_agent_aptitude.trait.zealous
		}
	}
	### ++ Humble
	if = {
		limit = { has_trait = humble }
		add = {
			value = agent_trait_bonus_t2_value
			desc = scheme_agent_aptitude.trait.humble
		}
	}
	### ++ Diligent
	if = {
		limit = { has_trait = diligent }
		add = {
			value = agent_trait_bonus_t2_value
			desc = scheme_agent_aptitude.trait.diligent
		}
	}
	### + Honest
	if = {
		limit = { has_trait = honest }
		add = {
			value = agent_trait_bonus_t1_value
			desc = scheme_agent_aptitude.trait.honest
		}
	}
	## Maluses
	### - Deceitful
	if = {
		limit = { has_trait = deceitful }
		add = {
			value = agent_trait_malus_t1_value
			desc = scheme_agent_aptitude.trait.deceitful
		}
	}
	### -- Lazy
	if = {
		limit = { has_trait = lazy }
		add = {
			value = agent_trait_malus_t2_value
			desc = scheme_agent_aptitude.trait.lazy
		}
	}
	### -- Arrogant
	if = {
		limit = { has_trait = arrogant }
		add = {
			value = agent_trait_malus_t2_value
			desc = scheme_agent_aptitude.trait.arrogant
		}
	}
	### --- Cynical
	if = {
		limit = { has_trait = cynical }
		add = {
			value = agent_trait_malus_t3_value
			desc = scheme_agent_aptitude.trait.cynical
		}
	}

	# Cap this off.
	max = agent_scheme_contributor_max
	min = agent_scheme_contributor_min
}
## Theologian
agent_theologian_contribution_value = {
	# Base value.
	value = scheme_agent_general_bonuses_contribution_score_value
	# Skills
	## Learning
	add = {
		value = learning
		multiply = agent_3to1_3_skill_mult_value
		ceiling = yes
		max = agent_max_skill_value
		desc = scheme_agent_aptitude.skill.learning
	}
	## Diplomacy
	add = {
		value = diplomacy
		multiply = agent_3to1_1_skill_mult_value
		ceiling = yes
		max = agent_max_skill_value
		desc = scheme_agent_aptitude.skill.diplomacy
	}
	# Traits
	## Bonuses
	### +++ Just
	if = {
		limit = { has_trait = just }
		add = {
			value = agent_trait_bonus_t3_value
			desc = scheme_agent_aptitude.trait.just
		}
	}
	### +++ Zealous
	if = {
		limit = { has_trait = zealous }
		add = {
			value = agent_trait_bonus_t3_value
			desc = scheme_agent_aptitude.trait.zealous
		}
	}
	### +++ Stubborn
	if = {
		limit = { has_trait = stubborn }
		add = {
			value = agent_trait_bonus_t3_value
			desc = scheme_agent_aptitude.trait.stubborn
		}
	}
	### ++ Calm (we like both measured responses...)
	if = {
		limit = { has_trait = calm }
		add = {
			value = agent_trait_bonus_t2_value
			desc = scheme_agent_aptitude.trait.calm
		}
	}
	### ++ Wrathful (... and less measured ones)
	if = {
		limit = { has_trait = wrathful }
		add = {
			value = agent_trait_bonus_t2_value
			desc = scheme_agent_aptitude.trait.wrathful
		}
	}
	### ++ Diligent
	if = {
		limit = { has_trait = diligent }
		add = {
			value = agent_trait_bonus_t2_value
			desc = scheme_agent_aptitude.trait.diligent
		}
	}
	### + Eccentric
	if = {
		limit = { has_trait = eccentric }
		add = {
			value = agent_trait_bonus_t1_value
			desc = scheme_agent_aptitude.trait.eccentric
		}
	}
	## Maluses
	### -- Lazy
	if = {
		limit = { has_trait = lazy }
		add = {
			value = agent_trait_malus_t2_value
			desc = scheme_agent_aptitude.trait.lazy
		}
	}
	### --- Fickle
	if = {
		limit = { has_trait = fickle }
		add = {
			value = agent_trait_malus_t3_value
			desc = scheme_agent_aptitude.trait.fickle
		}
	}
	### --- Cynical
	if = {
		limit = { has_trait = cynical }
		add = {
			value = agent_trait_malus_t3_value
			desc = scheme_agent_aptitude.trait.cynical
		}
	}
	### --- Arbitrary
	if = {
		limit = { has_trait = arbitrary }
		add = {
			value = agent_trait_malus_t3_value
			desc = scheme_agent_aptitude.trait.arbitrary
		}
	}

	# Cap this off.
	max = agent_scheme_contributor_max
	min = agent_scheme_contributor_min
}
## Lookout
agent_lookout_contribution_value = {
	# Base value.
	value = scheme_agent_general_bonuses_contribution_score_value
	# Skills
	## Intrigue
	add = {
		value = intrigue
		multiply = agent_3to1_3_skill_mult_value
		ceiling = yes
		max = agent_max_skill_value
		desc = scheme_agent_aptitude.skill.intrigue
	}
	## Martial
	add = {
		value = martial
		multiply = agent_3to1_1_skill_mult_value
		ceiling = yes
		max = agent_max_skill_value
		desc = scheme_agent_aptitude.skill.martial
	}
	# Traits
	## Bonuses
	### +++ Patient
	if = {
		limit = { has_trait = patient }
		add = {
			value = agent_trait_bonus_t3_value
			desc = scheme_agent_aptitude.trait.patient
		}
	}
	### +++ Diligent
	if = {
		limit = { has_trait = diligent }
		add = {
			value = agent_trait_bonus_t3_value
			desc = scheme_agent_aptitude.trait.diligent
		}
	}
	### +++ Paranoid
	if = {
		limit = { has_trait = paranoid }
		add = {
			value = agent_trait_bonus_t3_value
			desc = scheme_agent_aptitude.trait.paranoid
		}
	}
	### + Brave
	if = {
		limit = { has_trait = brave }
		add = {
			value = agent_trait_bonus_t1_value
			desc = scheme_agent_aptitude.trait.brave
		}
	}
	## Maluses
	### - Craven
	if = {
		limit = { has_trait = craven }
		add = {
			value = agent_trait_malus_t1_value
			desc = scheme_agent_aptitude.trait.craven
		}
	}
	### -- Trusting
	if = {
		limit = { has_trait = trusting }
		add = {
			value = agent_trait_malus_t2_value
			desc = scheme_agent_aptitude.trait.trusting
		}
	}
	### --- Lazy
	if = {
		limit = { has_trait = lazy }
		add = {
			value = agent_trait_malus_t3_value
			desc = scheme_agent_aptitude.trait.lazy
		}
	}
	### --- Impatient
	if = {
		limit = { has_trait = impatient }
		add = {
			value = agent_trait_malus_t3_value
			desc = scheme_agent_aptitude.trait.impatient
		}
	}

	# Cap this off.
	max = agent_scheme_contributor_max
	min = agent_scheme_contributor_min
}
## Gabbler
agent_gabbler_contribution_value = {
	# Base value.
	value = scheme_agent_general_bonuses_contribution_score_value
	# Skills
	## Diplomacy
	add = {
		value = diplomacy
		multiply = agent_1to1_1_skill_mult_value
		ceiling = yes
		max = agent_max_skill_value
		desc = scheme_agent_aptitude.skill.diplomacy
	}
	## Intrigue
	add = {
		value = intrigue
		multiply = agent_1to1_1_skill_mult_value
		ceiling = yes
		max = agent_max_skill_value
		desc = scheme_agent_aptitude.skill.intrigue
	}
	# Traits
	## Bonuses
	### +++ Gregarious
	if = {
		limit = { has_trait = gregarious }
		add = {
			value = agent_trait_bonus_t3_value
			desc = scheme_agent_aptitude.trait.gregarious
		}
	}
	### +++ Eccentric
	if = {
		limit = { has_trait = eccentric }
		add = {
			value = agent_trait_bonus_t3_value
			desc = scheme_agent_aptitude.trait.eccentric
		}
	}
	### +++ Fickle
	if = {
		limit = { has_trait = fickle }
		add = {
			value = agent_trait_bonus_t3_value
			desc = scheme_agent_aptitude.trait.fickle
		}
	}
	### ++ Arrogant
	if = {
		limit = { has_trait = arrogant }
		add = {
			value = agent_trait_bonus_t2_value
			desc = scheme_agent_aptitude.trait.arrogant
		}
	}
	### ++ Lazy
	if = {
		limit = { has_trait = lazy }
		add = {
			value = agent_trait_bonus_t2_value
			desc = scheme_agent_aptitude.trait.lazy
		}
	}
	### + Brave
	if = {
		limit = { has_trait = brave }
		add = {
			value = agent_trait_bonus_t1_value
			desc = scheme_agent_aptitude.trait.brave
		}
	}
	## Maluses
	### - Craven
	if = {
		limit = { has_trait = craven }
		add = {
			value = agent_trait_malus_t1_value
			desc = scheme_agent_aptitude.trait.craven
		}
	}
	### -- Diligent
	if = {
		limit = { has_trait = diligent }
		add = {
			value = agent_trait_malus_t2_value
			desc = scheme_agent_aptitude.trait.diligent
		}
	}
	### -- Humble
	if = {
		limit = { has_trait = humble }
		add = {
			value = agent_trait_malus_t2_value
			desc = scheme_agent_aptitude.trait.humble
		}
	}
	### --- Stubborn
	if = {
		limit = { has_trait = stubborn }
		add = {
			value = agent_trait_malus_t3_value
			desc = scheme_agent_aptitude.trait.stubborn
		}
	}
	### --- Shy
	if = {
		limit = { has_trait = shy }
		add = {
			value = agent_trait_malus_t3_value
			desc = scheme_agent_aptitude.trait.shy
		}
	}

	# Cap this off.
	max = agent_scheme_contributor_max
	min = agent_scheme_contributor_min
}

# How many opportunities it takes to spend them inviting an agent to a scheme.
invite_agent_opportunities_t1_value = 3
invite_agent_opportunities_t2_value = 5

# Contribution threshold values — how helpful they're being with a certain scheme.
agent_contribution_poor = 5
agent_contribution_good = 15
agent_contribution_excellent = 30

##################################################
# Preparation Event Values

# Weights for how likely scheme agents are to be rolled in critical moments.
critical_moment_agent_weight_very_high_value = 50
critical_moment_agent_weight_high_value = 25
critical_moment_agent_weight_medium_value = 15
critical_moment_agent_weight_low_value = 10
critical_moment_agent_weight_very_low_value = 5
# Don't use microscopic. This is largely here as a joke for wolf hunters in romance schemes.
critical_moment_agent_weight_microscopic_value = 1

# The standard charge cost for completing a scheme: we need this so we can calculate if bonus options should be cheaper.
scheme_charge_to_advance_threshold_base_value = 2

# How many charges does this scheme need before it can attempt completion?
## Default for schemes with only one ending option.
scheme_charge_to_advance_threshold_value = {
	# If a scheme has a custom threshold set, use that.
	if = {
		limit = { has_variable = custom_charge_threshold }
		add = var:custom_charge_threshold
	}
	# Otherwise, use the base.
	else = { add = scheme_charge_to_advance_threshold_base_value }
}
## Schemes with multiple ending options cost varying amounts to end, depending on your selected final bonus.
multi_ending_scheme_charge_to_advance_threshold_t1_value = {
	# If a scheme has a custom threshold set, use that.
	if = {
		limit = {
			exists = this
			has_variable = custom_charge_threshold
			var:custom_charge_threshold < scheme_charge_to_advance_threshold_base_value
		}
		subtract = var:custom_charge_threshold
	}
	# Now, add the base.
	add = 5
	# Make sure this never goes completely nuts.
	min = scheme_charge_to_advance_threshold_base_value
}
multi_ending_scheme_charge_to_advance_threshold_t2_value = {
	# If a scheme has a custom threshold set, use that.
	if = {
		limit = {
			exists = this
			has_variable = custom_charge_threshold
			var:custom_charge_threshold < scheme_charge_to_advance_threshold_base_value
		}
		subtract = var:custom_charge_threshold
	}
	# Now, add the base.
	add = 10
	# Make sure this never goes completely nuts.
	min = scheme_charge_to_advance_threshold_base_value
}
multi_ending_scheme_charge_to_advance_threshold_t3_value = {
	# If a scheme has a custom threshold set, use that.
	if = {
		limit = {
			exists = this
			has_variable = custom_charge_threshold
			var:custom_charge_threshold < scheme_charge_to_advance_threshold_base_value
		}
		subtract = var:custom_charge_threshold
	}
	# Now, add the base.
	add = 15
	# Make sure this never goes completely nuts.
	min = scheme_charge_to_advance_threshold_base_value
}
multi_ending_scheme_charge_to_advance_threshold_t4_value = {
	# If a scheme has a custom threshold set, use that.
	if = {
		limit = {
			exists = this
			has_variable = custom_charge_threshold
			var:custom_charge_threshold < scheme_charge_to_advance_threshold_base_value
		}
		subtract = var:custom_charge_threshold
	}
	# Now, add the base.
	add = 20
	# Make sure this never goes completely nuts.
	min = scheme_charge_to_advance_threshold_base_value
}

# Schemes with multiple ending options come with boosts at the end that we want to reference in loc for brevity.
multi_ending_scheme_buff_t2_value = 5
multi_ending_scheme_buff_t3_value = 10
multi_ending_scheme_buff_t4_value = 20
multi_ending_scheme_buff_t2_total_success_value = {
	value = scheme_success_chance 
	add = multi_ending_scheme_buff_t2_value
	max = 95
}
multi_ending_scheme_buff_t3_total_success_value = {
	value = scheme_success_chance 
	add = multi_ending_scheme_buff_t3_value
	max = 95
}
multi_ending_scheme_buff_t4_total_success_value = {
	value = scheme_success_chance 
	add = multi_ending_scheme_buff_t4_value
	max = 95
}

# Get the actual max value of our current scheme.
scheme_max_theoretical_success_chance_value = {
	if = {
		limit = { is_scheme_category = hostile }
		value = define:NScheme|HOSTILE_SCHEME_MAX_SUCCESS_CHANCE
	}
	else_if = {
		limit = { is_scheme_category = contract }
		value = define:NScheme|CONTRACT_SCHEME_MAX_SUCCESS_CHANCE
	}
	else_if = {
		limit = { is_scheme_category = political }
		value = define:NScheme|POLITICAL_SCHEME_MAX_SUCCESS_CHANCE
	}
	else = { value = define:NScheme|PERSONAL_SCHEME_MAX_SUCCESS_CHANCE }
}

##################################################
# Pulse Action Values

# How likely are you to get positive or negative APAs in a scheme, largely dependent on personal skill?
scheme_owner_aptitude_weight_up_positive_value = {
	value = 1
	# Diplomacy.
	if = {
		limit = { scheme_skill = diplomacy }
		scope:owner = {
			# Excellent skill.
			if = {
				limit = { diplomacy >= extremely_high_skill_rating }
				add = 1
			}
			# High skill.
			if = {
				limit = { diplomacy >= high_skill_rating }
				add = 1
			}
			# Low skill.
			if = {
				limit = { diplomacy <= mediocre_skill_rating }
				add = -1
			}
			# Atrocious skill.
			if = {
				limit = { diplomacy <= low_skill_rating }
				add = -1
			}
		}
	}
	# Martial.
	else_if = {
		limit = { scheme_skill = martial }
		scope:owner = {
			# Excellent skill.
			if = {
				limit = { martial >= extremely_high_skill_rating }
				add = 1
			}
			# High skill.
			if = {
				limit = { martial >= high_skill_rating }
				add = 1
			}
			# Low skill.
			if = {
				limit = { martial <= mediocre_skill_rating }
				add = -1
			}
			# Atrocious skill.
			if = {
				limit = { martial <= low_skill_rating }
				add = -1
			}
		}
	}
	# Stewardship.
	else_if = {
		limit = { scheme_skill = stewardship }
		scope:owner = {
			# Excellent skill.
			if = {
				limit = { stewardship >= extremely_high_skill_rating }
				add = 1
			}
			# High skill.
			if = {
				limit = { stewardship >= high_skill_rating }
				add = 1
			}
			# Low skill.
			if = {
				limit = { stewardship <= mediocre_skill_rating }
				add = -1
			}
			# Atrocious skill.
			if = {
				limit = { stewardship <= low_skill_rating }
				add = -1
			}
		}
	}
	# Intrigue.
	else_if = {
		limit = { scheme_skill = intrigue }
		scope:owner = {
			# Excellent skill.
			if = {
				limit = { intrigue >= extremely_high_skill_rating }
				add = 1
			}
			# High skill.
			if = {
				limit = { intrigue >= high_skill_rating }
				add = 1
			}
			# Low skill.
			if = {
				limit = { intrigue <= mediocre_skill_rating }
				add = -1
			}
			# Atrocious skill.
			if = {
				limit = { intrigue <= low_skill_rating }
				add = -1
			}
		}
	}
	# Learning.
	else_if = {
		limit = { scheme_skill = learning }
		scope:owner = {
			# Excellent skill.
			if = {
				limit = { learning >= extremely_high_skill_rating }
				add = 1
			}
			# High skill.
			if = {
				limit = { learning >= high_skill_rating }
				add = 1
			}
			# Low skill.
			if = {
				limit = { learning <= mediocre_skill_rating }
				add = -1
			}
			# Atrocious skill.
			if = {
				limit = { learning <= low_skill_rating }
				add = -1
			}
		}
	}
	# Prowess.
	else_if = {
		limit = { scheme_skill = prowess }
		scope:owner = {
			# Excellent skill.
			if = {
				limit = { prowess >= extremely_high_skill_rating }
				add = 1
			}
			# High skill.
			if = {
				limit = { prowess >= high_skill_rating }
				add = 1
			}
			# Low skill.
			if = {
				limit = { prowess <= mediocre_skill_rating }
				add = -1
			}
			# Atrocious skill.
			if = {
				limit = { prowess <= low_skill_rating }
				add = -1
			}
		}
	}
}
scheme_owner_aptitude_weight_up_negative_value = {
	value = 1
	# Diplomacy.
	if = {
		limit = { scheme_skill = diplomacy }
		scope:owner = {
			# Atrocious skill.
			if = {
				limit = { diplomacy <= low_skill_rating }
				add = 1
			}
			# Low skill.
			if = {
				limit = { diplomacy <= mediocre_skill_rating }
				add = 1
			}
			# High skill.
			if = {
				limit = { diplomacy >= high_skill_rating }
				add = -1
			}
			# Excellent skill.
			if = {
				limit = { diplomacy >= extremely_high_skill_rating }
				add = -1
			}
		}
	}
	# Martial.
	else_if = {
		limit = { scheme_skill = martial }
		scope:owner = {
			# Atrocious skill.
			if = {
				limit = { martial <= low_skill_rating }
				add = 1
			}
			# Low skill.
			if = {
				limit = { martial <= mediocre_skill_rating }
				add = 1
			}
			# High skill.
			if = {
				limit = { martial >= high_skill_rating }
				add = -1
			}
			# Excellent skill.
			if = {
				limit = { martial >= extremely_high_skill_rating }
				add = -1
			}
		}
	}
	# Stewardship.
	else_if = {
		limit = { scheme_skill = stewardship }
		scope:owner = {
			# Atrocious skill.
			if = {
				limit = { stewardship <= low_skill_rating }
				add = 1
			}
			# Low skill.
			if = {
				limit = { stewardship <= mediocre_skill_rating }
				add = 1
			}
			# High skill.
			if = {
				limit = { stewardship >= high_skill_rating }
				add = -1
			}
			# Excellent skill.
			if = {
				limit = { stewardship >= extremely_high_skill_rating }
				add = -1
			}
		}
	}
	# Intrigue.
	else_if = {
		limit = { scheme_skill = intrigue }
		scope:owner = {
			# Atrocious skill.
			if = {
				limit = { intrigue <= low_skill_rating }
				add = 1
			}
			# Low skill.
			if = {
				limit = { intrigue <= mediocre_skill_rating }
				add = 1
			}
			# High skill.
			if = {
				limit = { intrigue >= high_skill_rating }
				add = -1
			}
			# Excellent skill.
			if = {
				limit = { intrigue >= extremely_high_skill_rating }
				add = -1
			}
		}
	}
	# Learning.
	else_if = {
		limit = { scheme_skill = learning }
		scope:owner = {
			# Atrocious skill.
			if = {
				limit = { learning <= low_skill_rating }
				add = 1
			}
			# Low skill.
			if = {
				limit = { learning <= mediocre_skill_rating }
				add = 1
			}
			# High skill.
			if = {
				limit = { learning >= high_skill_rating }
				add = -1
			}
			# Excellent skill.
			if = {
				limit = { learning >= extremely_high_skill_rating }
				add = -1
			}
		}
	}
	# Prowess.
	else_if = {
		limit = { scheme_skill = prowess }
		scope:owner = {
			# Atrocious skill.
			if = {
				limit = { prowess <= low_skill_rating }
				add = 1
			}
			# Low skill.
			if = {
				limit = { prowess <= mediocre_skill_rating }
				add = 1
			}
			# High skill.
			if = {
				limit = { prowess >= high_skill_rating }
				add = -1
			}
			# Excellent skill.
			if = {
				limit = { prowess >= extremely_high_skill_rating }
				add = -1
			}
		}
	}
}

# What's the chance of no APA firing each month of a scheme?
scheme_apa_chance_of_no_event_value = 90

# Control values for scheme APAs.
## Positive.
scheme_apa_modifier_positive_success_chance_value = 5
scheme_apa_modifier_positive_secrecy_value = 5
scheme_apa_modifier_positive_speed_value = -5
## Negative.
scheme_apa_modifier_negative_success_chance_value = -5
scheme_apa_modifier_negative_secrecy_value = -5
scheme_apa_modifier_negative_speed_value = 5

##################################################
# Countermeasure Values

countermeasure_disliked_by_trait_agenthood_acceptance_value = 25

countermeasure_scheme_category_success_chance_bonus_against_minor_value = -50
countermeasure_scheme_category_success_chance_bonus_against_medium_value = -100
countermeasure_scheme_category_success_chance_bonus_against_major_value = -150

countermeasure_scheme_category_success_chance_malus_against_minor_value = 10
countermeasure_scheme_category_success_chance_malus_against_medium_value = 15
countermeasure_scheme_category_success_chance_malus_against_major_value = 25

countermeasure_apply_secrecy_maluses_value = {
	# Minor bonus to detection.
	if = {
		limit = {
			countermeasure_parametre_applies_againt_char_trigger = {
				SCHEME_TARGET = scope:target
				SCHEME_OWNER = scope:owner
				PARAMETER = secrecy_vs_all_schemes_bonus_minor
			}
		}
		add = {
			value = countermeasure_apply_secrecy_maluse_minor_value
			desc = countermeasures_in_target_court.tt.secrecy
		}
	}
	# Medium bonus to detection.
	if = {
		limit = {
			countermeasure_parametre_applies_againt_char_trigger = {
				SCHEME_TARGET = scope:target
				SCHEME_OWNER = scope:owner
				PARAMETER = secrecy_vs_all_schemes_bonus_medium
			}
		}
		add = {
			value = countermeasure_apply_secrecy_maluse_medium_value
			desc = countermeasures_in_target_court.tt.secrecy
		}
	}
	# Major bonus to detection.
	if = {
		limit = {
			countermeasure_parametre_applies_againt_char_trigger = {
				SCHEME_TARGET = scope:target
				SCHEME_OWNER = scope:owner
				PARAMETER = secrecy_vs_all_schemes_bonus_major
			}
		}
		add = {
			value = countermeasure_apply_secrecy_maluse_major_value
			desc = countermeasures_in_target_court.tt.secrecy
		}
	}
}

# Lifestyle Perk
realm_charts_perk_value = 35
secrecy_charting_realm_increase_value = {
	if = {
		limit = {
			scope:owner = {
				has_perk = realm_charts_perk
			}
			scope:target ?= {
				top_liege = scope:owner.top_liege
			}
		}
		add = {
			value = realm_charts_perk_value
			desc = realm_chart_perk_same_realm_secrecy
		}
	}
}

# We use separate values so we can display them in loc too.
countermeasure_apply_secrecy_maluse_minor_value = -15
countermeasure_apply_secrecy_maluse_medium_value = -25
countermeasure_apply_secrecy_maluse_major_value = -35

# We use a script value instead of inline maths for this because for some reason _specifically_ the courtly and parochial vassal stances don't like in-line vassals.
dislikes_countermeasure_opinion_value = -30
dislikes_countermeasure_opinion_lowered_value = -20
dislikes_countermeasure_opinion_lowered_further_value = -10
dislikes_countermeasure_county_opinion_value = -40
dislikes_countermeasure_county_opinion_lowered_value = -30
dislikes_countermeasure_county_opinion_lowered_further_value = -20

# Controls when the AI will and won't use certain countermeasures.
## Prioritise what values are active.
### These don't all need to be script values, I've only done it so that they're all grouped next to each other for easy visualisation.
countermeasure_ai_will_do_prio4 = 80
countermeasure_ai_will_do_prio3 = 60
countermeasure_ai_will_do_prio2 = 40
countermeasure_ai_will_do_prio1 = 20
### We originally had this lower but it causes maddening stretching in debug mode.
countermeasure_ai_will_do_prio0 = -20
## Then we distribute these values out nicely between the different countermeasures.
ai_will_do_bounties_for_whispers_value = {
	if = {
		limit = {
			should_ai_take_preemptive_countermeasures_trigger = yes
			OR = {
				has_trait = deceitful
				has_trait = craven
			}
			NOR = {
				has_trait = honest
				has_trait = brave
				has_trait = trusting
			}
		}
		add = countermeasure_ai_will_do_prio1
	}
	else = { add = countermeasure_ai_will_do_prio0 }
}
ai_will_do_arbitrary_arrests_value = {
	if = {
		limit = {
			should_ai_take_preemptive_countermeasures_trigger = yes
			OR = {
				has_trait = arbitrary
				has_trait = paranoid
			}
			NOR = {
				has_trait = just
				has_trait = trusting
			}
		}
		add = countermeasure_ai_will_do_prio1
	}
	else = { add = countermeasure_ai_will_do_prio0 }
}
ai_will_do_strengthen_sentries_value = {
	if = {
		limit = {
			# Don't do this if we've already deployed countermeasures.
			NOT = { has_scheme_countermeasure_parameter = has_aggressive_countermeasure_active }
			# Then actually check to see if the scheme'd be appropriate for this.
			any_targeting_scheme = {
				is_scheme_exposed = yes
				var:apply_countermeasures ?= flag:opportunistic
			}
		}
		add = countermeasure_ai_will_do_prio3
	}
	else = { add = countermeasure_ai_will_do_prio0 }
}
ai_will_do_strengthen_sentries_for_courtier_value = {
	if = {
		limit = {
			any_in_list = {
				variable = host_should_prevent_seduce_schemes_list
				host ?= prev
			}
		}
		add = countermeasure_ai_will_do_prio2
	}
}
ai_will_do_redouble_guards_value = {
	if = {
		limit = {
			# We don't care about dpeloyed countermeasures here: guard against murders even if there's a seduction already happening.
			any_targeting_scheme = {
				is_scheme_exposed = yes
				var:apply_countermeasures ?= flag:calculating
			}
		}
		add = countermeasure_ai_will_do_prio4
	}
	else = { add = countermeasure_ai_will_do_prio0 }
}
ai_will_do_redouble_guards_for_courtier_value = {
	if = {
		limit = {
			any_in_list = {
				variable = host_should_prevent_murder_schemes_list
				host ?= prev
			}
		}
		add = countermeasure_ai_will_do_prio2
	}
}
ai_will_do_withdraw_from_view_value = {
	if = {
		limit = {
			any_targeting_scheme = {
				is_scheme_exposed = yes
				OR = {
					var:apply_countermeasures ?= flag:calculating
					var:apply_countermeasures ?= flag:opportunistic
				}
			}
			OR = {
				has_trait = humble
				has_trait = shy
				has_trait = eccentric
			}
			NOR = {
				has_trait = arrogant
				has_trait = gregarious
				has_trait = stubborn
				has_trait = trusting
			}
		}
		add = countermeasure_ai_will_do_prio1
	}
	else = { add = countermeasure_ai_will_do_prio0 }
}

##################################################
# Murder Values

# How much automatic stress loss do we give a character, before traits, upon successfully murdering someone?
murder_base_stress_value = {
	# If our imaginary friend told us to do it, then we lose a lot.
	if = {
		limit = { scope:owner.var:imaginary_friend_murder_target ?= scope:target }
		add = major_stress_impact_loss
	}
	# Or a moderate gain if we've been caught and this is our first time.
	else_if = {
		limit = {
			exists = scope:scheme_discovered
			NOT = { has_trait = murderer }
		}
		add = medium_stress_impact_gain
	}
	# Else we're a repeat offender, so we care less.
	else_if = {
		limit = { exists = scope:scheme_discovered }
		add = minor_stress_impact_gain
	}
	# Otherwise, a moderate loss.
	else = { add = medium_stress_impact_loss }
}

# Which bodyguard is best poised to come to their liege's defence?
murder_weight_best_bodyguard_value = {
	add = prowess
	add = {
		value = ai_boldness
		# To bring us in line with skill scaling.
		multiply = 0.25
	}
	add = {
		value = "opinion(scope:target)"
		# To bring us roughly in line with skill scaling.
		multiply = 0.25
	}
	if = {
		limit = { has_trait = loyal }
		add = 25
	}
}

# How much prestige do you get for successfully murdering a rival? 
rival_outlived_prestige_value = medium_prestige_gain

##################################################
# Odds Values

base_odds_prediction_target_is_title_value = {
	if = {
		limit = { # Target is a landed title
			exists = scope:target.holder
		}
		scope:target ?= {
			holder = { save_temporary_scope_as = temp_target }
		}
	}
	else_if = { # Title is a province
		limit = {
			exists = scope:target.province_owner
		}
		scope:target ?= {
			province_owner = { save_temporary_scope_as = temp_target }
		}
	}
	else_if = { # 
		limit = {
			scope:target = {
				any_de_jure_top_liege = {
					exists = this
					save_temporary_scope_as = de_jure_liege
				}
			}
		}
		scope:de_jure_liege = {
			save_temporary_scope_as = temp_target
		}
	}
	add = base_odds_prediction_guts_value
}

base_odds_prediction_target_is_char_value = {
	scope:target ?= { save_temporary_scope_as = temp_target }
	add = base_odds_prediction_guts_value
}

# For non-hostile, non-secret schemes (generally non-intrigue too).
base_odds_prediction_guts_value = {
	add = {
		value = {
			scope:temp_target = { value = "opinion(scope:owner)" }
			multiply = 0.2
			floor = yes
		}
		desc = scheme_odds.target.opinion_of_owner
	}
	add = {
		value = {
			value = scope:temp_target.highest_held_title_tier
			# Barons aren't imposing at all.
			add = -1
			# Don't give a bonus just for someone being a courtier and call it a tier thing.
			min = 0
		}
		desc = scheme_odds.target.tier
		multiply = -5
	}
	if = {
		limit = {
			scope:owner = {
				exists = scope:temp_target.cp:councillor_spymaster
				scope:temp_target.cp:councillor_spymaster = this
			}
		}
		add = {
			value = 12
			desc = scheme_odds.owner.is_target_spymaster
		}
	}
	if = {
		limit = {
			scope:temp_target = {
				is_landed_or_landless_administrative = no
			}
			scope:owner = {
				exists = scope:temp_target.liege.cp:councillor_spymaster
				scope:temp_target.liege.cp:councillor_spymaster = this
			}
		}
		add = {
			value = 8
			desc = scheme_odds.owner.is_target_liege_spymaster
		}
	}
	if = {
		limit = {
			scope:temp_target = {
				is_landed_or_landless_administrative = no
			}
			scope:owner = {
				exists = scope:temp_target.host.cp:councillor_spymaster
				scope:temp_target.host.cp:councillor_spymaster = this
			}
		}
		add = {
			value = 8
			desc = scheme_odds.owner.is_target_host_spymaster
		}
	}
	if = {
		limit = {
			scope:owner = {
				has_relation_guardian = scope:temp_target
			}
		}
		add = {
			value = 8
			desc = scheme_odds.owner.relation.owner_is_guardian_of_target
		}
	}
	if = {
		limit = {
			scope:owner = { is_diarch_of_target = scope:temp_target }
		}
		add = {
			value = 5
			desc = scheme_odds.owner.relation.owner_is_diarch_of_target
		}
	}
	if = {
		limit = {
			scope:temp_target = {
				is_ruler = no
			}
			exists = scope:temp_target.liege
			scope:temp_target.liege = scope:owner
		}
		add = {
			value = 10
			desc = scheme_odds.owner.relation.owner_is_liege_of_target
		}
	}
	if = {
		limit = {
			scope:owner = {
				is_councillor_of = scope:temp_target
			}
		}
		add = {
			value = 10
			desc = scheme_odds.owner.relation.owner_is_councillor_of_target
		}
	}
	if = {
		limit = {
			scope:owner = {
				has_relation_lover = scope:temp_target
			}
		}
		add = {
			value = 10
			desc = scheme_odds.owner.relation.owner_is_lover_of_target
		}
	}
	if = {
		limit = {
			scope:owner = {
				is_spouse_of = scope:temp_target
			}
		}
		add = {
			value = 10
			desc = scheme_odds.owner.relation.owner_is_spouse_of_target
		}
	}
	if = {
		limit = {
			scope:owner = {
				is_consort_of = scope:temp_target
				NOT = { is_spouse_of = scope:temp_target }
			}
		}
		add = {
			value = 5
			desc = scheme_odds.owner.relation.owner_is_consort_of_target
		}
	}
	if = {
		limit = {
			scope:owner = {
				is_close_family_of = scope:temp_target
			}
		}
		add = {
			value = 5
			desc = scheme_odds.owner.relation.owner_is_close_family_of_target
		}
	}
}

agent_groups_owner_perspective_value = {
	scope:owner = {
		# We need to check the any's here to avoid +0s if there's no valid chars.
		if = {
			limit = {
				OR = {
					any_courtier_or_guest = { is_valid_agent_standard_trigger = yes }
					any_relation = {
						type = friend
						is_valid_agent_standard_trigger = yes
					}
					any_relation = {
						type = lover
						is_valid_agent_standard_trigger = yes
					}
				}
				
			}
			add = {
				value = 1
				multiply = {
					value = 0
					if = {
						limit = {
							any_courtier_or_guest = { is_valid_agent_standard_trigger = yes }
						}
						every_courtier_or_guest = {
							limit = { is_valid_agent_standard_trigger = yes }
							add = 1
						}
					} 	
					if = {
						limit = {
							any_relation = {
								type = friend
								is_valid_agent_standard_trigger = yes
							}
						}
						every_relation = {
							type = friend
							limit = { is_valid_agent_standard_trigger = yes }
							add = 1
						}		
					}
					if = {
						limit = {
							any_relation = {
								type = lover
								is_valid_agent_standard_trigger = yes
							}
						}
						every_relation = {
							type = lover
							limit = { is_valid_agent_standard_trigger = yes }
							add = 1
						}
					}
					max = 5
				}
				desc = scheme_odds.agents.owner.number_of_valid_courtiers_agents
			}
		}
	}
}

agent_groups_target_character_perspective_value = {
	if = {
		limit = {
			scope:scheme ?= {
				is_scheme_target_type = title
			}
		}
		scope:scheme ?= {
			scheme_target_title.holder ?= { save_temporary_scope_as = target }
		}
	}
	scope:target = {
		# We need to check the any's here to avoid +0s if there's no valid chars.
		if = {
			limit = {
				any_courtier = { is_valid_agent_standard_trigger = yes }
			}
			add = {
				value = 3
				multiply = {
					value = 0
					every_courtier = {
						limit = { is_valid_agent_standard_trigger = yes }
						add = 1
					}
					max = 5
				}
				desc = scheme_odds.agents.target.number_of_valid_courtiers_agents
			}
		}
		if = {
			limit = {
				any_vassal = { is_valid_agent_standard_trigger = yes }
			}
			add = {
				value = 2
				multiply = {
					value = 0
					every_vassal = {
						limit = { is_valid_agent_standard_trigger = yes }
						add = 1
					}
					max = 5
				}
				desc = scheme_odds.agents.target.number_of_valid_vassal_agents
			}
		}
	}
}

hostile_scheme_base_odds_prediction_target_is_title_value = {
	if = {
		limit = { # Target is a landed title
			exists = scope:target.holder
		}
		scope:target ?= {
			holder = { save_temporary_scope_as = temp_target }
		}
	}
	else_if = { # Title is a province
		limit = {
			exists = scope:target.province_owner
		}
		scope:target ?= {
			province_owner = { save_temporary_scope_as = temp_target }
		}
	}
	else_if = { # 
		limit = {
			scope:target = {
				any_de_jure_top_liege = {
					exists = this
					save_temporary_scope_as = de_jure_liege
				}
			}
		}
		scope:de_jure_liege = {
			save_temporary_scope_as = temp_target
		}
	}
	add = hostile_scheme_base_odds_prediction_guts_value
}

hostile_scheme_base_odds_prediction_target_is_char_value = {
	scope:target ?= { save_temporary_scope_as = temp_target }
	add = hostile_scheme_base_odds_prediction_guts_value
}

hostile_scheme_base_odds_prediction_guts_value = {
	if = {
		limit = {
			exists = scope:temp_target.primary_title
			scope:temp_target.primary_title.tier = tier_empire
		}
		add = {
			value = -40
			desc = scheme_odds.target.tier
		}
	}
	else_if = {
		limit = {
			exists = scope:temp_target.primary_title
			scope:temp_target.primary_title.tier = tier_kingdom
		}
		add = {
			value = -30
			desc = scheme_odds.target.tier
		}
	}
	else_if = {
		limit = {
			exists = scope:temp_target.primary_title
			scope:temp_target.primary_title.tier = tier_duchy
		}
		add = {
			value = -20
			desc = scheme_odds.target.tier
		}
	}

	if = { # Minor Lifestyle Perk protection for Courtiers
		limit = {
			scope:temp_target = {
				is_alive = yes
				is_ruler = no
				exists = court_owner
				court_owner = {
					has_perk = prepared_for_anything_perk
				}
				NOT = { court_owner = scope:owner }
				NOT = { has_perk = prepared_for_anything_perk }
			}
		}
		add = {
			value = 0
			desc = scheme_odds.target.court_owner_has_prepared_for_anything_perk
			subtract = prepared_for_anything_perk_secondary_percentage
		}
	}
	if = {
		limit = { # Bonus for murdering Pool characters, as you can't have agents against them
			scope:temp_target = {
				is_pool_character = yes
				NOT = { intrigue >= very_high_skill_rating }
			}
		}
		add = {
			value = 25
			desc = scheme_odds.target.is_pool_char
		}
	}

	if = { # FP3 legacy track bonus for murdering dynasty members
		limit = {
			scope:temp_target = {
				exists = dynasty
				exists = scope:owner.dynasty
				dynasty = scope:owner.dynasty
				dynasty = { has_dynasty_perk = fp3_khvarenah_legacy_2 }
			}
		}
		add = {
			value = 10
			desc = scheme_odds.owner.dynasty_legacy_kinslaying_bonus_from_fp3_khvarenah_legacy_2
		}
	}
	
	if = { # Essentially the Base
		limit = {
			scope:owner = {
				exists = scope:temp_target.cp:councillor_spymaster
				scope:temp_target.cp:councillor_spymaster = this
			}
		}
		add = {
			value = 75
			desc = scheme_odds.owner.is_target_spymaster
		}
	}
	if = {
		limit = {
			scope:temp_target = {
				is_landed_or_landless_administrative = no
			}
			scope:owner = {
				exists = scope:temp_target.liege.cp:councillor_spymaster
				scope:temp_target.liege.cp:councillor_spymaster = this
			}
		}
		add = {
			value = 75
			desc = scheme_odds.owner.is_target_liege_spymaster
		}
	}
	if = {
		limit = {
			scope:temp_target = {
				is_landed_or_landless_administrative = no
			}
			scope:owner = {
				exists = scope:temp_target.host.cp:councillor_spymaster
				scope:temp_target.host.cp:councillor_spymaster = this
			}
		}
		add = {
			value = 75
			desc = scheme_odds.owner.is_target_host_spymaster
		}
	}
	if = {
		limit = {
			scope:owner = {
				has_relation_guardian = scope:temp_target
			}
		}
		add = {
			value = 75
			desc = scheme_odds.owner.relation.owner_is_guardian_of_target
		}
	}
	if = {
		limit = {
			scope:owner = { is_diarch_of_target = scope:temp_target }
		}
		add = {
			value = 50
			desc = scheme_odds.owner.relation.owner_is_diarch_of_target
		}
	}
	if = {
		limit = {
			scope:temp_target = {
				is_ruler = no
			}
			exists = scope:temp_target.liege
			scope:temp_target.liege = scope:owner
		}
		add = {
			value = 25
			desc = scheme_odds.owner.relation.owner_is_liege_of_target
		}
	}
	if = {
		limit = {
			scope:owner = {
				is_councillor_of = scope:temp_target
			}
		}
		add = {
			value = 15
			desc = scheme_odds.owner.relation.owner_is_councillor_of_target
		}
	}
	if = {
		limit = {
			scope:owner = {
				has_relation_lover = scope:temp_target
			}
		}
		add = {
			value = 15
			desc = scheme_odds.owner.relation.owner_is_lover_of_target
		}
	}
	if = {
		limit = {
			scope:owner = {
				is_spouse_of = scope:temp_target
			}
		}
		add = {
			value = 10
			desc = scheme_odds.owner.relation.owner_is_spouse_of_target
		}
	}
	if = {
		limit = {
			scope:owner = {
				is_consort_of = scope:temp_target
			}
		}
		add = {
			value = 5
			desc = scheme_odds.owner.relation.owner_is_consort_of_target
		}
	}
	if = {
		limit = {
			scope:owner = {
				is_close_family_of = scope:temp_target
			}
		}
		add = {
			value = 5
			desc = scheme_odds.owner.relation.owner_is_close_family_of_target
		}
	}

	# Vengeful Bonus
	if = {
		limit = {
			scope:owner = {
				has_trait = vengeful
				OR = {
					has_relation_rival = scope:temp_target	
					has_relation_nemesis = scope:temp_target
				}
			}
		}
		add = {
			value = vengeful_scheme_success_chance_modifier
			desc = scheme_odds.trait.owner.vengeful
		}
	}
	# Paranoid Malus
	if = {
		limit = {
			scope:temp_target ?= {
				has_trait = paranoid
				OR = {
					has_relation_rival = scope:temp_target	
					has_relation_nemesis = scope:temp_target
				}
			}
		}
		add = {
			value = -20
			desc = scheme_odds.trait.target.paranoid
		}
	}

	if = {
		limit = {
			scope:owner = {
				culture = {
					has_cultural_parameter = hostile_action_vs_rival_bonuses
				}
				OR = {
					has_relation_rival = scope:temp_target	
					has_relation_nemesis = scope:temp_target
				}
			}
		}
		add = {
			value = 15
			desc = scheme_odds.culture.owner.hostile_scheme_bonuses_vs_rivals
		}
	}

	if = {
		limit = {# Culture Bonus
			scope:owner = {
				culture = {
					has_cultural_parameter = hostile_scheme_success_chance_vs_spouse_penalty
				}
				is_spouse_of = scope:temp_target	
			}
		}
		add = {
			value = -50
			desc = scheme_odds.culture.owner.hostile_scheme_maluses_vs_spouse
		}
	}
	
	# Difficulty
	if = {
		limit = {
			has_game_rule = easy_difficulty
			scope:owner = {
				is_ai = yes
			}
			scope:temp_target = {
				is_ai = no
			}
		}
		add = {
			value = -25
			desc = scheme_odds.game_difficulty.easy
		}
	}

	if = {
		limit = {
			has_game_rule = very_easy_difficulty
			scope:owner = {
				is_ai = yes
			}
			scope:temp_target = {
				is_ai = no
			}
		}
		add = {
			value = -75
			desc = scheme_odds.game_difficult.very_easy
		}
	}

	# Struggle
	if = {
		limit = {
			scope:owner = {
				any_character_struggle = {
					involvement = involved
					has_struggle_phase_parameter = struggle_agents_less_likely_to_join_schemes
					is_secondary_character_involvement_involved_trigger = {
						CHAR = scope:temp_target
					}
				}
			}
		}
		add = {
			value = -25
			desc = scheme_odds.struggle.owner.agents_less_likely_to_join_due_to_struggle_phase
		}
	}
	## court_events.3060
	if = {
		limit = {
			scope:owner = { has_character_modifier = spies_behind_every_corner_modifier }
		}
		add = {
			value = 25
			desc = scheme_odds.owner.spies_behind_every_corner_modifier
		}
	}
	if = {
		limit = {
			scope:temp_target = { has_character_modifier = spies_behind_every_corner_modifier }
		}
		add = {
			value = 25
			desc = scheme_odds.target.spies_behind_every_corner_modifier
		}
	}
}

odds_skill_contribution_diplomacy_value = {
	add = {
		value = scope:owner.diplomacy
		desc = scheme_odds.diplomacy.owner
	}
	scope:target ?= {
		add = {
			value = scope:target.diplomacy
			desc = scheme_odds.diplomacy.target
			multiply = -0.5
		}
	}
}
odds_skill_contribution_martial_value = {
	add = {
		value = scope:owner.martial
		desc = scheme_odds.martial.owner
	}
	scope:target ?= {
		add = {
			value = scope:target.martial
			desc = scheme_odds.martial.target
			multiply = -0.5
		}
	}
}
odds_skill_contribution_stewardship_value = {
	add = {
		value = scope:owner.stewardship
		desc = scheme_odds.stewardship.owner
	}
	scope:target ?= {
		add = {
			value = scope:target.stewardship
			desc = scheme_odds.stewardship.target
			multiply = -0.5
		}
	}
}
odds_skill_contribution_intrigue_value = {
	add = {
		value = scope:owner.intrigue
		desc = scheme_odds.intrigue.owner
	}
	scope:target ?= {
		add = {
			value = scope:target.intrigue
			desc = scheme_odds.intrigue.target
			multiply = -0.5
		}
	}
}
odds_skill_contribution_learning_value = {
	add = {
		value = scope:owner.learning
		desc = scheme_odds.learning.owner
	}
	
	scope:target ?= {
		add = {
			value = scope:target.learning
			desc = scheme_odds.learning.target
			multiply = -0.5
		}
	}
}
odds_skill_contribution_prowess_value = {
	add = {
		value = scope:owner.prowess
		desc = scheme_odds.prowess.owner
	}
	scope:target ?= {
		add = {
			value = scope:target.prowess
			desc = scheme_odds.prowess.target
			multiply = -0.5
		}
	}
}

odds_skill_contribution_learning_target_is_title_value = {
	add = {
		value = scope:owner.learning
		desc = scheme_odds.learning.owner
	}
	
	scope:target ?= {
		add = {
			value = scope:target.holder.learning
			desc = scheme_odds.learning.target
			multiply = -0.5
		}
	}
}

odds_sway_scheme_misc_value = {
	add = {
		value = 30
		desc = scheme_odds.misc_modifiers
		if = {
			limit = {
				scope:owner = { knows_language_of_culture = scope:target.culture }
			}
			add = 4
		}
		if = {
			limit = {
				scope:owner = { has_trait = diplomat }
			}
			add = 2
		}
		if = {
			limit = {
				scope:owner = { is_adult = no }
			}
			add = -6
		}
		if = {
			limit = {
				scope:target = {
					has_opinion_modifier = {
						target = scope:owner
						modifier = scheme_sway_opinion
						value >= 25
					}
				}
			}
			add = -12
		}
		if = {
			limit = {
				NOT = { scope:target.top_liege = scope:owner.top_liege }
			}
			add = -16
		}
		if = {
			limit = {
				scope:target = {
					personal_scheme_success_compare_target_liege_tier_trigger = no
				}
				scope:owner = {
					tier_difference = {
						target = scope:target
						value >= 1
					}
				}
			}
			add = 6
		}
		if = {
			limit = {
				scope:target = {
					personal_scheme_success_compare_target_liege_tier_trigger = no
				}
				scope:owner = {
					tier_difference = {
						target = scope:target
						value <= -1
					}
				}
			}
			add = -14
		}
		if = {
			limit = {
				scope:target = {
					is_theocratic_lessee = yes
				}
				scope:owner.piety_level < 0
			}
			add = -50
		}
		if = {
			limit = {
				scope:target = {
					is_theocratic_lessee = yes
				}
				scope:owner.piety_level > 1
			}
			add = 12
		}
		if = {
			limit = {
				scope:target = {
					faith = scope:owner.faith
					faith = {
						exists = religious_head
						religious_head = {
				 			this = scope:target
				 		}
					}
				}
			}
			add = -50
		}
	}	
}

odds_steal_back_artifact_scheme_misc_value = {
	add = {
		value = 0
		desc = scheme_odds.misc_modifiers
		if = {
			limit = {
				scope:owner = {
					any_character_task_contract = {
						has_task_contract_type = laamp_steal_artifact_contract
						var:task_contract_target ?= scope:target
					}
				}
			}
			add = 14
		}
		if = {
			limit = {
				scope:owner = { has_character_modifier = hostile_schemes_distracted_modifier }
			}
			add = -6
		}	
	}
}

odds_slander_scheme_misc_value = {
	add = {
		value = 0
		desc = scheme_odds.misc_modifiers
		if = {
			limit = {
				scope:target = {
					faith = scope:owner.faith
					faith = {
						has_doctrine = doctrine_spiritual_head
					}
					faith = {
						exists = religious_head
						religious_head = {
				 			this = scope:target
				 		}
					}
				}
			}
			add = -26
		}
		if = {
			limit = {
				scope:target = {
					exists = inspiration
					inspiration = { exists = inspiration_sponsor}
				}
			}
			add = -17
		}
		if = {
			limit = {
				scope:owner = { has_character_modifier = poet_for_diplo_schemes_modifier } 
			}
			add = 11
		}
		if = {
			limit = {
				scope:owner = {
					has_character_modifier = united_political_agents_modifier
					is_vassal_of = scope:target
				}
			}
			add = 13
		}
	}
}

odds_seize_realm_scheme_misc_value = {
	add = {
		value = 0
		desc = scheme_odds.misc_modifiers
		if = {
			limit = {
				scope:target = {				
					has_opinion_modifier = {
						target = scope:owner
						modifier = attempted_to_seize_my_realm_crime
					}
				}
			}
			add = -50
		}
		if = {
			limit = {
				scope:target.inspiration ?= { exists = inspiration_sponsor }
			}
			add = -22
		}
		if = {
			limit = {
				scope:target.faith = {
					this = scope:owner.faith
					has_doctrine = doctrine_spiritual_head
					religious_head ?= scope:target
				}
			}
			add = -50
		}
		if = {
			limit = {
				OR = {
					scope:target = { is_at_war_with = scope:owner }
					scope:target = {
						is_playable_character = no
						liege ?= { is_at_war_with = scope:owner }
					}
					scope:target = {
						is_playable_character = yes
						liege ?= { is_at_war_with = scope:owner }
					}
				}
			}
			add = -22
		}
		if = {
			limit = {
				scope:owner = {
					has_character_modifier = tournament_tailor_mixup_scheme_modifier
					exists = var:tailor_mixup_house
					exists = scope:target.holder.house
					var:tailor_mixup_house = scope:target.holder.house
				}
			}
			add = 8
		}
		if = {
			limit = {
				scope:owner = {
					any_scheme = {
						scheme_type = murder
						scheme_target_character = scope:target
						has_scheme_modifier = feast_learnt_habits_modifier
					}
				}
			}
			add = 8
		}
		if = {
			limit = {
				scope:target = { has_character_modifier = fp3_struggle_caliph_super_suspicious_modifier }
			}
			add = -200
		}
	}
}

odds_seduce_scheme_misc_value = {
	add = {
		value = 0
		desc = scheme_odds.misc_modifiers
		if = {
			limit = {
				scope:owner = {
					exists = var:wnight_seduce_memento_var
					var:wnight_seduce_memento_var = scope:target
				}
			}
			add = 14
		}
		if = {
			limit = {
				scope:owner = { knows_language_of_culture = scope:target.culture }
			}
			add = 4
		}
		if = {
			limit = {
				scope:owner = { has_perk = home_advantage_perk }
				scope:target = {
					OR = {
						is_courtier_of = scope:owner
						is_pool_guest_of = scope:owner
						is_foreign_court_guest_of = scope:owner
					}
				}
			}
			add = home_advantage_perk_bonus
		}
		if = {
			limit = {
				scope:owner = { has_perk = smooth_operator_perk }
			}
			add = smooth_operator_perk_bonus
		}
		if = {
			limit = {
				scope:owner = {
					exists = dynasty
					dynasty = {
						has_dynasty_perk = fp1_adventure_legacy_2
					}
				}
			}
			add = fp1_adventure_legacy_2_success_chance_seduction
		}
		if = {
			limit = {
				scope:owner = { has_trait = seducer }
			}
			add = 16
		}
		if = {
			limit = {
				OR = {
					scope:owner = { has_trait = beauty_good_1 }
					scope:owner = { has_trait = beauty_good_2 }
					scope:owner = { has_trait = beauty_good_3 }
				}
			}
			add = 12
		}
		if = {
			limit = {
				OR = {
					scope:owner = { has_trait = physique_good_1 }
					scope:owner = { has_trait = physique_good_2 }
					scope:owner = { has_trait = physique_good_3 }
				}
			}
			add = 11
		}
		if = {
			limit = {
				OR = {
					scope:owner = { has_trait = beauty_bad_1 }
					scope:owner = { has_trait = beauty_bad_2 }
					scope:owner = { has_trait = beauty_bad_3 }
				}
			}
			add = -21
		}
		if = {
			limit = {
				OR = {
					scope:owner = { has_trait = great_pox }
					scope:owner = { has_trait = lovers_pox }
					scope:owner = { has_trait = early_great_pox }
				}
			}
			add = -17
		}
		if = {
			limit = {
				scope:owner = {
					NOR = {
						is_attracted_to_gender_of = scope:target
						has_perk = unshackled_lust_perk
					}
				}
			}
			add = -15
		}
		if = {
			limit = {
				scope:target = { has_trait = lifestyle_reveler }
			}
			add = 3
		}
		if = {
			limit = {
				scope:target = { has_trait = lustful }
			}
			add = 7
		}
		if = {
			limit = {
				scope:target = { has_trait = chaste }
			}
			add = -18
		}
		if = {
			limit = {
				scope:target = { has_trait = shy }
			}
			add = -7
		}
		if = {
			limit = {
				scope:owner = { is_consort_of = scope:target }
			}
			add = 14
		}
		if = {
			limit = {
				scope:target = {			
					is_married = yes
					NOT = { is_consort_of = scope:owner }
					ai_honor >= high_positive_ai_value
					trait_is_shunned_or_criminal_in_faith_trigger = { TRAIT = adulterer FAITH = scope:target.faith GENDER_CHARACTER = scope:target }
				}
			}
			add = -50
		}
		if = {
			limit = {
				scope:target = {
					is_married = yes
					NOT = { is_consort_of = scope:owner }
					exists = primary_spouse
					primary_spouse = { save_temporary_scope_as = target_spouse }
					NOT = { might_cheat_on_partner_trigger = { PARTNER = scope:target_spouse }}
				}
			}
			add = -100
		}
		if = {
			limit = {
				scope:owner = { NOT = { is_consort_of = scope:target } }
				scope:target = {
					is_married = yes
					exists = primary_spouse
					primary_spouse = { save_temporary_scope_as = target_spouse }
					opinion = {
						target = scope:target_spouse
						value < low_negative_opinion
					}
				}
			}
			add = 18
		}
		if = {
			limit = {
				scope:target = {
					faith = scope:owner.faith
					faith = {
						exists = religious_head
						religious_head = {
							this = scope:target
						}
					}
				}
			}
			add = -50
		}
		if = {
			limit = {
				scope:target = {
					relation_with_character_is_incestuous_in_my_or_lieges_faith_trigger = { CHARACTER = scope:owner }
				}
				scope:owner = { # The Subtle Desire Perk nullifies 	this
					NOT = { has_perk = subtle_desire_perk }
				}
			}
			add = -22
		}
		if = {
			limit = {
				scope:target = {
					NOT = { is_consort_of = scope:owner }
					is_close_or_extended_family_of = scope:owner
					NOR = {
						accepts_incest_with_trigger = { CHARACTER = scope:owner } #100% fine with incest with 	owner
						scope:owner = { has_perk = subtle_desire_perk }  # The Subtle Desire 	Perk nullifies this
						guaranteed_under_20_incest_rejection_trigger	 = { # handled by hard block modifier
							TARGET = scope:target
							SEDUCER = scope:owner
						}
					}
				}
			}
			add = -16
		}
		if = {
			limit = {
				scope:target = {
					personal_scheme_success_compare_target_liege_tier_trigger = no
				}
				scope:owner = {
					tier_difference = {
						target = scope:target
						value >= 1
					}
				}
			}
			add = 12
		}
		if = {
			limit = {
				scope:target = {
					personal_scheme_success_compare_target_liege_tier_trigger = no
				}
				scope:owner = {
					tier_difference = {
						target = scope:target
						value <= -1
					}
				}
			}
			add = -40
		}
		if = {
			limit = {
				scope:target = {
					trait_compatibility = {
						target = scope:owner
						value >= medium_positive_trait_compatibility
					}
				}
			}
			add = 18
		}
		if = {
			limit = {
				scope:target = {
					trait_compatibility = {
						target = scope:owner
						value <= medium_negative_trait_compatibility
					}
				}
			}
			add = -36
		}	
	}
}

odds_promote_scheme_misc_value = {
	add = {
		value = 0
		desc = scheme_odds.misc_modifiers
		if = {
			limit = {
				exists = scope:owner.dynasty
				scope:owner.dynasty = {
					has_dynasty_perk = kin_legacy_4
				}
				scope:target.dynasty = scope:owner.dynasty
				}	
			add = kin_legacy_4_success_chance
		}
		if = {
			limit = {
				exists = scope:owner.house
				exists = scope:target.house
				scope:owner.culture = {
					has_cultural_parameter = cultural_house_personal_scheme_success_chance
				}
				scope:target.house = scope:owner.house
			}
			add = cultural_house_personal_scheme_success_chance
		}
		if = {
			limit = {
				scope:owner = { has_character_modifier = poet_for_diplo_schemes_modifier }
			}
			add = 8
		}
		if = {
			limit = {
				scope:owner = {
					has_variable_list = supporting_political_schemes
				}
			}
			add = 7
		}
	}
}

odds_murder_scheme_misc_value = {
	add = {
		value = -17
		desc = scheme_odds.misc_modifiers
		if = {
			limit = {
				OR = {
					scope:target = {
						is_at_war_with = scope:owner
					}
					scope:target = {
						is_playable_character = no
						exists = liege
						liege = {
							is_at_war_with = scope:owner
						}
					}
					scope:target = {
						is_playable_character = yes
						exists = liege
						liege = {
							is_at_war_with = scope:owner
						}
					}
				}
			}
			add = -30
		}
		if = {
			limit = {
				scope:target = {
					faith = scope:owner.faith
					faith = {
						has_doctrine = doctrine_spiritual_head
					}
					faith = {
						exists = religious_head
						religious_head = {
			 				this = scope:target
			 			}
					}
				}
			}
			add = -50
		}
		if = {
			limit = {
				scope:target = {				
					has_opinion_modifier = {
						target = scope:owner
						modifier = attempted_murder_me_crime
					}
				}
			}
			add = -50
		}
		if = {
			limit = {
				scope:target = {
					has_perk = prepared_for_anything_perk
				}
			}
			add = -26
		}
		if = {
			limit = {
				scope:target = {
					has_character_modifier = fp3_struggle_caliph_super_suspicious_modifier
				}
			}
			add = -18
		}
		if = {
			limit = {
				scope:target = {
					has_trait = trusting
				}
			}
			add = 18
		}
	}
	
}

odds_learn_language_scheme_misc_value = {
	add = {
		value = 0
		desc = scheme_odds.misc_modifiers
		if = {
			limit = {
				scope:owner.piety_level > 0
				scope:owner.culture = {
					has_cultural_parameter = language_success_chance_per_piety_level
				}
			}
			add = 4
		}
		if = {
			limit = {
				exists = scope:owner.cp:councillor_court_chaplain
				scope:owner.cp:councillor_court_chaplain.learning > 10
			}
			add = 3
		}
		if = {
			limit = {
				scope:owner.age < 30
			}
			add = 8
		}
		if = {
			limit = {
				scope:target.culture = {
					has_same_culture_heritage = scope:owner.culture
				}
			}
			add = 3
		}
		if = {
			limit = {
				scope:owner = {
					has_perk = pedagogy_perk
				}
			}
			add = 4
		}
		if = {
			limit = {
				scope:owner = {
					has_trait = intellect_good_1
					has_trait = intellect_good_2
					has_trait = intellect_good_3
					has_trait = stubborn
					has_trait = ambitious
				}
			}
			add = 4
		}
	}
	
}

odds_generate_claim_scheme_misc_value = {
	add = {
		value = 0
		desc = scheme_odds.misc_modifiers
		if = {
			limit = {
				exists = scope:target.holder
				scope:owner = {
					faith = {
						exists = religious_head
						has_doctrine = doctrine_spiritual_head
						religious_head = {
					 		this = scope:target.holder
					 	}
					}
				}
			}
			add = -50
		}
		if = {
			limit = {
				scope:owner = {
					has_trait = deceitful
				}
			}
			add = -18
		}
		if = {
			limit = {
				scope:owner = {
					has_trait = honest
				}
			}
			add = -16
		}
		if = {
			limit = {
				scope:target.holder ?= {
					has_trait = trusting
				}
			}
			add = 8
		}
	}
	
}

odds_foster_legitimacy_scheme_misc_value = {
	add = {
		value = 0
		desc = scheme_odds.misc_modifiers
		if = {
			limit = {
				scope:owner = {
					has_trait = overseer
				}
			}
			add = 8
		}
		if = {
			limit = {
				scope:owner = { has_character_modifier = poet_for_diplo_schemes_modifier }
			}
			add = 8
		}
	}
	
}

odds_fabricate_hook_scheme_misc_value = {
	add = {
		value = 0
		desc = scheme_odds.misc_modifiers
		if = {
			limit = {
				scope:owner = {
					has_trait = deceitful
				}
			}
			add = 8
		}
		if = {
			limit = {
				scope:target = {
					OR = {
						has_trait = trusting
						has_trait = intellect_bad_1
						has_trait = intellect_bad_2
						has_trait = intellect_bad_3
						has_trait = arrogant
						has_trait = greedy
						has_trait = craven
					}
				}
			}
			add = 8
		}
		if = {
			limit = {
				scope:target = {
					OR = {
						has_trait = fickle
						has_trait = paranoid
						has_trait = schemer
						has_trait = intellect_good_3
						has_trait = intellect_good_2
						has_trait = intellect_good_1
					}
				}
			}
			add = -22
		}
		if = {
			limit = {
				scope:target = {
					faith = scope:owner.faith
					faith = {
						has_doctrine = doctrine_spiritual_head
					}
					faith = {
						exists = religious_head
						religious_head = {
				 			this = scope:target
				 		}
					}
				}
			}
			add = -50
		}
	}
	
}

odds_ep3_teach_governor_scheme_misc_value = {
	add = {
		value = 0
		desc = scheme_odds.misc_modifiers
		add = {
			value = scope:owner.age
			add = {
				value = scope:target.age
				multiply = -1
			}
		}
		if = {
			limit = {
				scope:owner = {
					NOR = {
						has_trait = governor
						has_trait = lazy
						has_trait = diligent
					}
				}
			}
			add = -11
		}
		if = {
			limit = {
				scope:target = {
					trait_compatibility = {
						target = scope:owner
						value >= medium_positive_trait_compatibility
					}
				}
			}
			add = 9
		}
		if = {
			limit = {
				scope:target = {
					trait_compatibility = {
						target = scope:owner
						value <= medium_negative_trait_compatibility
					}
				}
			}
			add = -18
		}
	}
	
}

odds_subsume_province_scheme_misc_value = {
	add = {
		value = 0
		desc = scheme_odds.misc_modifiers
		if = {
			limit = {
				scope:owner = {
					any_sub_realm_county = {
						NOT = { target_is_de_facto_liege_or_above = scope:owner.primary_title }
					}

				}
			}
			add = -9
		}
		if = {
			limit = {
				scope:owner.house = {
					is_powerful_family = yes
					is_dominant_family = no
				}
			}
			add = 8
		}
		if = {
			limit = {
				scope:target.holder.house = {
					is_powerful_family = yes
					is_dominant_family = no
				}
			}
			add = -16
		}
		add = {
			value = scope:owner.influence_level
			multiply = 2
		}
		add = {
			value = scope:target.holder.influence_level
			multiply = -4
		}
		if = {
			limit = {
				scope:target.holder.house = scope:owner.top_liege.house
			}
			add = -12
		}
	}
	
}

odds_raid_estate_scheme_misc_value = {
	add = {
		value = 0
		desc = scheme_odds.misc_modifiers
		add = {
			value = scope:owner.influence_level
			multiply = 2
		}
		add = {
			value = scope:target.holder.influence_level
			multiply = -4
		}
		if = {
			limit = {
				scope:target.holder.house = scope:owner.top_liege.house
			}
			add = -12
		}
		if = {
			limit = {
				scope:owner.house = {
					is_powerful_family = yes
					is_dominant_family = no
				}
			}
			add = 8
		}
		if = {
			limit = {
				scope:target.holder.house = {
					is_powerful_family = yes
					is_dominant_family = no
				}
			}
			add = -16
		}
		if = {
			limit = {
				scope:target.domicile = {
					OR = {
						has_domicile_building_or_higher = barracks_01
						has_domicile_building_or_higher = guardhouse_01
						has_domicile_building_or_higher = watchtower_01
						has_domicile_building_or_higher = estate_main_02
					}
				}
			}
			add = -4
		}
		if = {
			limit = {
				scope:target.domicile = {
					OR = {
						has_domicile_building_or_higher = barracks_03
						has_domicile_building_or_higher = guardhouse_03
						has_domicile_building_or_higher = watchtower_03
						has_domicile_building_or_higher = estate_main_04
					}
				}
			}
			add = -12
		}
	}
}

odds_prepare_fire_dromons_scheme_misc_value = {
	add = {
		value = 0
		desc = scheme_odds.misc_modifiers
		add = {
			value = scope:owner.influence_level
			multiply = 2
		}
	}	
}

odds_ingratiate_family_scheme_misc_value = {
	add = {
		value = 0
		desc = scheme_odds.misc_modifiers
		if = {
			limit = {
				scope:target = {
					trait_compatibility = {
						target = scope:owner
						value >= medium_positive_trait_compatibility
					}
				}
			}
			add = 6
		}
		if = {
			limit = {
				scope:target = {
					trait_compatibility = {
						target = scope:owner
						value <= medium_negative_trait_compatibility
					}
				}
			}
			add = -12
		}
		if = {
			limit = {
				scope:target = {
					personal_scheme_success_compare_target_liege_tier_trigger = no
				}
				scope:owner = {
					tier_difference = {
						target = scope:target
						value >= 1
					}
				}
			}
			add = 8
		}
		if = {
			limit = {
				scope:target = {
					personal_scheme_success_compare_target_liege_tier_trigger = no
				}
				scope:owner = {
					tier_difference = {
						target = scope:target
						value <= -1
					}
				}
			}
			add = -14
		}
		if = {
			limit = {
				scope:owner.house = { is_dominant_family = yes }
			}
			add = 6
		}
		if = {
			limit = {
				scope:owner.dynasty = scope:target.dynasty
			}
			add = 8
		}
	}
}

odds_found_despotate_scheme_misc_value = {
	add = {
		value = -6
		desc = scheme_odds.misc_modifiers
		if = {
			limit = {
				scope:owner.house = {
					is_powerful_family = yes
					is_dominant_family = no
				}
			}
			add = 6
		}
		if = {
			limit = {
				scope:owner.house = { is_dominant_family = yes }
			}
			add = 8
		}
		if = {
			limit = {
				scope:owner.top_liege.capital_county.kingdom ?= scope:target
			}
			add = -12
		}
	}
}

odds_diarch_scheme_misc_value = {
	add = {
		value = 0
		desc = scheme_odds.misc_modifiers
		add = {
			value = scope:target.strife_opinion
			multiply = 0.25
			min = 5
			max = 40
		}
	}
	
}

odds_depose_scheme_misc_value = {
	add = {
		value = 0
		desc = scheme_odds.misc_modifiers
		if = {
			limit = {
				scope:target = {
					faith = scope:owner.faith
					faith = {
						has_doctrine = doctrine_spiritual_head
					}
					faith = {
						exists = religious_head
						religious_head = {
				 			this = scope:target
				 		}
					}
				}
			}
			add = -28
		}
		if = {
			limit = {
				scope:owner.house = { is_dominant_family = yes }
			}
			add = 8
		}
	}
	
}

odds_befriend_scheme_misc_value = {
	add = {
		value = 0
		desc = scheme_odds.misc_modifiers
		if = {
			limit = {
				scope:owner = {
					knows_language_of_culture = scope:target.culture
				}
			}
			add = 6
		}
		if = {
			limit = {
				scope:owner = {
					OR = {
						has_trait = education_diplomacy_1
						has_trait = education_diplomacy_2
						has_trait = education_diplomacy_3
						has_trait = education_diplomacy_4
						has_trait = education_diplomacy_5
					}
				}
			}
			add = 6
		}
		if = {
			limit = {
				scope:owner = {
					OR = {
						has_trait = diplomat
						has_trait = august
						has_trait = lifestyle_reveler
					}
				}
			}
			add = 12
		}
		if = {
			limit = {
				scope:owner = {
					has_trait = shy
					has_trait = callous
				}
			}
			add = -8
		}
		if = {
			limit = {
				scope:target = {
					has_trait = shy
					has_trait = callous
					has_trait = paranoid
				}
			}
			add = -12
		}
		if = {
			limit = {
				scope:target = {
					trait_compatibility = {
						target = scope:owner
						value >= medium_positive_trait_compatibility
					}
				}
			}
			add = 14
		}
		if = {
			limit = {
				scope:target = {
					trait_compatibility = {
						target = scope:owner
						value <= medium_negative_trait_compatibility
					}
				}
			}
			add = -26
		}
		if = {
			limit = {
				scope:target = {
					personal_scheme_success_compare_target_liege_tier_trigger = no
				}
				scope:owner = {
					tier_difference = {
						target = scope:target
						value >= 1
					}
				}
			}
			add = 14
		}
		if = {
			limit = {
				scope:target = {
					personal_scheme_success_compare_target_liege_tier_trigger = no
				}
				scope:owner = {
					tier_difference = {
						target = scope:target
						value <= -1
					}
				}
			}
			add = -16
		}
		if = {
			limit = {
				scope:owner = { has_relation_rival = scope:target }
			}
			add = -24
		}
	}
}

odds_abduct_scheme_misc_value = {
	add = {
		value = 0
		desc = scheme_odds.misc_modifiers
		if = {
			limit = {
				scope:target = {
					personal_scheme_success_compare_target_liege_tier_trigger = no
				}
				scope:owner = {
					tier_difference = {
						target = scope:target
						value >= 1
					}
				}
			}
			add = 14
		}
		if = {
			limit = {
				scope:target = {
					personal_scheme_success_compare_target_liege_tier_trigger = no
				}
				scope:owner = {
					tier_difference = {
						target = scope:target
						value <= -1
					}
				}
			}
			add = -16
		}
		if = { # Foreign Rulers are very hard to kidnap
			limit = {
				scope:target = {
					OR = {
						is_ruler = yes
						is_foreign_court_or_pool_guest = no
					}
					NOT = {
						scope:target.top_liege = scope:owner.top_liege
					}
				}
			}
			add = -25
		}
		if = { # Rulers are harder to kidnap
			limit = {
				scope:target = {
					is_ruler = yes
					scope:target.top_liege = scope:owner.top_liege
				}
			}
			add = -10
		}
	}
}

odds_romance_scheme_misc_value = {
	add = {
		value = 0
		desc = scheme_odds.misc_modifiers
		# Thicker Than Water Perk
		if = {
			limit = {
				scope:owner = {
					has_perk = thicker_than_water_perk
				}
				scope:target = {
					is_close_or_extended_family_of = scope:owner
				}
			}
			add = 5
		}
		if = { # Tradition
			limit = {
				scope:owner = {
					has_trait = poet
					culture = {
						has_cultural_parameter = poet_trait_romance_bonuses
					}
				}
			}
			add = 8
		}
		# You are a Courteous Knight
		if = {
			limit = {
				scope:owner = {
					has_character_modifier = ep3_courteous_knight_modifier
				}
			}
			add = 5
		}
		if = {
			limit = {
				scope:owner = { has_perk = home_advantage_perk }
				scope:target = {
					OR = {
						is_courtier_of = scope:owner
						is_pool_guest_of = scope:owner
						is_foreign_court_guest_of = scope:owner
					}
				}
			}
			add = 10
		}
		if = {
			limit = {
				scope:owner = { has_perk = courtship_perk }
			}
			add = 5
		}
		if = {
			limit = {
				scope:owner = {
					is_spouse_of = scope:target
				}
				scope:owner.culture = {
					has_cultural_parameter = romance_scheme_bonus_vs_spouse
				}
			}
			add = 5
		}
		if = {
			limit = {
				scope:owner = { knows_language_of_culture = scope:target.culture }
			}
			add = 4
		}
		if = {
			limit = {
				scope:owner.dynasty ?= {
					has_dynasty_perk = kin_legacy_4
				}
				scope:target.dynasty ?= scope:owner.dynasty
			}
			add = 5
		}

		if = {
			limit = {
				exists = scope:owner.house
				exists = scope:target.house
				scope:owner.culture = {
					has_cultural_parameter = cultural_house_personal_scheme_success_chance
				}
				scope:target.house = scope:owner.house
			}
			add = 5
		}
		if = {
			limit = {
				scope:owner = { has_trait = gallant }
			}
			add = 16
		}
		if = {
			limit = {
				OR = {
					scope:owner = { has_trait = beauty_good_1 }
					scope:owner = { has_trait = beauty_good_2 }
					scope:owner = { has_trait = beauty_good_3 }
				}
			}
			add = 12
		}
		if = {
			limit = {
				OR = {
					scope:owner = { has_trait = physique_good_1 }
					scope:owner = { has_trait = physique_good_2 }
					scope:owner = { has_trait = physique_good_3 }
				}
			}
			add = 11
		}
		if = {
			limit = {
				OR = {
					scope:owner = { has_trait = beauty_bad_1 }
					scope:owner = { has_trait = beauty_bad_2 }
					scope:owner = { has_trait = beauty_bad_3 }
				}
			}
			add = -21
		}
		if = {
			limit = {
				OR = {
					scope:owner = { has_trait = great_pox }
					scope:owner = { has_trait = lovers_pox }
					scope:owner = { has_trait = early_great_pox }
				}
			}
			add = -17
		}
		if = {
			limit = {
				scope:owner = {
					NOR = {
						is_attracted_to_gender_of = scope:target
						has_perk = unshackled_lust_perk
					}
				}
			}
			add = -15
		}
		if = {
			limit = {
				scope:target = {
					relation_with_character_is_incestuous_in_my_or_lieges_faith_trigger = { CHARACTER = scope:owner }
				}
				scope:owner = { # The Subtle Desire Perk nullifies 	this
					NOT = { has_perk = subtle_desire_perk }
				}
			}
			add = -22
		}
		if = {
			limit = {
				scope:target = {
					NOT = { is_consort_of = scope:owner }
					is_close_or_extended_family_of = scope:owner
					NOR = {
						accepts_incest_with_trigger = { CHARACTER = scope:owner } #100% fine with incest with 	owner
						scope:owner = { has_perk = subtle_desire_perk }  # The Subtle Desire 	Perk nullifies this
						guaranteed_under_20_incest_rejection_trigger	 = { # handled by hard block modifier
							TARGET = scope:target
							SEDUCER = scope:owner
						}
					}
				}
			}
			add = -16
		}
		if = {
			limit = {
				scope:target = {
					personal_scheme_success_compare_target_liege_tier_trigger = no
				}
				scope:owner = {
					tier_difference = {
						target = scope:target
						value >= 1
					}
				}
			}
			add = 12
		}
		if = {
			limit = {
				scope:target = {
					personal_scheme_success_compare_target_liege_tier_trigger = no
				}
				scope:owner = {
					tier_difference = {
						target = scope:target
						value <= -1
					}
				}
			}
			add = -40
		}
		if = {
			limit = {
				scope:target = {
					trait_compatibility = {
						target = scope:owner
						value >= medium_positive_trait_compatibility
					}
				}
			}
			add = 18
		}
		if = {
			limit = {
				scope:target = {
					trait_compatibility = {
						target = scope:owner
						value <= medium_negative_trait_compatibility
					}
				}
			}
			add = -36
		}
	}
}

odds_convert_to_witchcraft_misc_value = {
	add = {
		value = 0
		desc = scheme_odds.misc_modifiers
		add = {
			value = {
				scope:target = { value = "opinion(scope:owner)" }
				multiply = 0.2
				floor = yes
			}
		}
		if = {
			limit = {
				scope:owner = {
					exists = house
					house = { has_house_modifier = witch_coven }
				}
			}
			add = 4
		}
		add = {
			value = scope:target.ai_zeal
			multiply = -1
			max = 50
			min = -50
		}

		#Attraction
		if = {
			limit = {
				scope:target = { is_attracted_to_gender_of = scope:owner }
			}
			add = 5
		}

		#Target traits
		if = {
			limit = {
				scope:target = {
					has_trait = zealous
					NOR = {
						faith = {
							trait_is_virtue = witch
							has_doctrine_parameter = witchcraft_accepted
						}
					}
				}
			}
			add = -10
		}

		if = {
			limit = {
				scope:target = {
					has_trait = devoted
					NOR = {
						faith = {
							trait_is_virtue = witch
							has_doctrine_parameter = witchcraft_accepted
						}
					}
				}
			}
			add = -6
		}

		if = {
			limit = {
				scope:target = {
					has_trait = order_member
					NOR = {
						faith = {
							trait_is_virtue = witch
							has_doctrine_parameter = witchcraft_accepted
						}
					}
				}
			}
			add = -6
		}

		if = {
			limit = {
				scope:target = {
					OR = {
						has_trait = craven
						has_trait = paranoid
					}
				}
			}
			add = -8
		}

		if = {
			limit = {
				scope:target = {
					OR = {
						has_trait = lifestyle_reveler
						has_trait = seducer
						has_trait = lifestyle_mystic
						has_trait = lifestyle_herbalist
						has_trait = lustful
						has_trait = deceitful
						has_trait = ambitious
						has_trait = trusting
						has_trait = excommunicated
					}
				}
			}
			add = 8
		}

		if = {
			limit = {
				scope:target = { has_intrigue_lifestyle_trait_trigger = yes }
			}
			add = 4
		}

		if = {
			limit = {
				scope:target = {
					has_trait = cynical
					NOT = {
						faith = { trait_is_virtue = witch }
					}
				}
			}
			add = 2
		}

		# House Personal Scheme Success Chance on Cultural Parameter
		if = {
			limit = {
				exists = scope:owner.house
				exists = scope:target.house
				scope:owner.culture = {
					has_cultural_parameter = cultural_house_personal_scheme_success_chance
				}
				scope:target.house = scope:owner.house
			}
			add = 5
		}

		# Modifiers
		# house_head_request_interaction
		if = {
			limit = {
				scope:owner = {
					has_variable_list = supporting_personal_schemes
				}
			}
			add = 2
		}
		if = {
			limit = {
				scope:owner = { has_character_modifier = personal_schemes_distracted_modifier }
			}
			add = -2
		}
		# Estate
		if = {
			limit = {
				scope:owner.domicile ?= {
					has_domicile_parameter = increased_success_personal_schemes_1
				}
			}
			add = 2
		}
		if = {
			limit = {
				scope:owner.domicile ?= {
					has_domicile_parameter = increased_success_personal_schemes_2
				}
			}
			add = 4
		}
		if = {
			limit = {
				scope:owner.domicile ?= {
					has_domicile_parameter = increased_success_personal_schemes_3
				}
			}
			add = 6
		}
	}	
}
