﻿#############
# FP3 Scripted Values
#############

##################################################
# Unity

critical_house_unity = 20
terrible_house_unity = 40
low_house_unity = 60
mediocre_house_unity = 80
average_house_unity = 100
decent_house_unity = 120
good_house_unity = 140
high_house_unity = 160
very_high_house_unity = 180

opinion_thresholds_for_antagonistic_independence = -50

number_of_futuwaa_members = {
	value = 0
	every_courtier = {
		limit = { fp3_is_valid_futuwaa_member = { SPONSOR = root } }
		add = 1
	}
	house ?= {
		every_house_member = {
			limit = {
				fp3_is_valid_futuwaa_member = { SPONSOR = root }
				NOT = { is_courtier_of = root }
			}
			add = 1
		}
	}
}

number_of_madrasa_pupils = {
	value = 0
	every_courtier = {
		limit = { fp3_is_valid_madrasa_pupil = { SPONSOR = root } }
		add = 1
	}
	house ?= {
		every_house_member = {
			limit = {
				fp3_is_valid_madrasa_pupil = { SPONSOR = root }
				NOT = { is_courtier_of = root }
			}
			add = 1
		}
	}
}

##################################################
# Struggle

fp3_house_modifier_concession_ending_duration = 100
fp3_house_modifier_sunder_caliphate_duration = 100

fp3_concession_death_countdown = {
	value = current_year
	subtract = 866
	multiply = 1
}

fp3_persia_ownage_percentage_for_foundation = 0.20

fp3_persia_supporter_rulers_decimal_value = {
	value = 50
	divide = 100
	max = 1
}

fp3_persia_supporter_rulers_max_value = {
	value = 0
	struggle:persian_struggle ?= {
		every_involved_ruler = {
			limit = {
				is_landed = yes
				highest_held_title_tier >= tier_county
				OR = {
					NOT = { has_title = title:d_sunni }
					OR = {
						is_independent_ruler = yes
						is_vassal_of = title:d_sunni.holder
					}
				}
			}
			add = 1
		}
	}
}

fp3_persia_supporter_rulers_half_value = {
	value = fp3_persia_supporter_rulers_max_value
	divide = 2
	ceiling = yes
}

fp3_persia_supporter_rulers_count_value = {
	value = 0
	struggle:persian_struggle ?= {
		every_involved_ruler = {
			limit = {
				is_landed = yes
				highest_held_title_tier >= tier_county
				OR = {
					NOT = { has_title = title:d_sunni }
					OR = {
						is_independent_ruler = yes
						is_vassal_of = title:d_sunni.holder
					}
				}
				# Trigger
				has_trait = fp3_struggle_supporter
			}
			add = 1
		}
	}
	floor = yes
}

fp3_persia_iranian_rulers_count_value = {
	value = 0
	struggle:persian_struggle ?= {
		every_involved_ruler = {
			limit = {
				is_landed = yes
				highest_held_title_tier >= tier_county
				culture = { has_cultural_pillar = heritage_iranian }
			}
			add = 1
		}
		every_interloper_ruler = {
			limit = {
				is_landed = yes
				highest_held_title_tier >= tier_county
				culture = { has_cultural_pillar = heritage_iranian }
			}
			add = 1
		}
	}
	floor = yes
}

fp3_persia_all_rulers_count_value = {
	value = 0
	struggle:persian_struggle ?= {
		every_involved_ruler = {
			limit = {
				is_landed = yes
				highest_held_title_tier >= tier_county
			}
			add = 1
		}
		every_interloper_ruler = {
			limit = {
				is_landed = yes
				highest_held_title_tier >= tier_county
			}
			add = 1
		}
	}
	floor = yes
}

fp3_persia_all_rulers_requirement_value = {
	value = fp3_persia_all_rulers_count_value
	multiply = 0.6
}

fp3_persia_all_rulers_percentage_value = {
	value = fp3_persia_iranian_rulers_count_value
	divide = {
		value = fp3_persia_all_rulers_count_value
		min = 1
	}
}

fp3_persia_independent_detractor_rulers_count_value = {
	value = 0
	struggle:persian_struggle ?= {
		every_involved_ruler = {
			limit = {
				is_independent_ruler = yes
				is_landed = yes
				highest_held_title_tier >= tier_duchy
				has_trait = fp3_struggle_detractor
			}
			add = 1
		}
		every_interloper_ruler = {
			limit = {
				is_independent_ruler = yes
				is_landed = yes
				highest_held_title_tier >= tier_duchy
				has_trait = fp3_struggle_detractor
			}
			add = 1
		}
	}
	floor = yes
}

fp3_persia_independent_non_sunni_rulers_count_value = {
	value = 0
	struggle:persian_struggle ?= {
		every_involved_ruler = {
			limit = {
				is_independent_ruler = yes
				is_landed = yes
				highest_held_title_tier >= tier_duchy
				faith = {
					NOT = {
						has_doctrine = muhammad_succession_sunni_doctrine
					}
				}
			}
			add = 1
		}
		every_interloper_ruler = {
			limit = {
				is_independent_ruler = yes
				is_landed = yes
				highest_held_title_tier >= tier_duchy
				faith = {
					NOT = {
						has_doctrine = muhammad_succession_sunni_doctrine
					}
				}
			}
			add = 1
		}
	}
	floor = yes
}

fp3_iranian_sub_realm_counties_value = {
	value = 0
	every_sub_realm_county = {
		limit = {
			culture = { has_cultural_pillar = heritage_iranian }
		}
		add = 1
	}
	floor = yes
}

fp3_persia_flame_of_iran_independent_value = {
	value = 0
	struggle:persian_struggle ?= {
		every_involved_ruler = {
			limit = {
				is_independent_ruler = no
				culture = { has_cultural_pillar = heritage_iranian }
				exists = liege
				NOT = {
					liege.culture = { has_cultural_pillar = heritage_iranian }
				}
			}
			add = 1
		}
	}
}

# Paramameter for percentage of Persia you must control
fp3_persia_owned_for_rekindle_persia_percent_value = 30

# Uses above to plug in to script as a decimal
fp3_persia_owned_for_rekindle_persia_decimal_value = {
	value = fp3_persia_owned_for_rekindle_persia_percent_value
	divide = 100
	max = 1
}

fp3_iranian_current_owned_persia_value = {
	value = 0
	every_county_in_region = {
		region = world_persian_empire
		limit = {
			holder.top_liege = root
		}
		add = 1
	}
	divide = {
		value = 0
		every_county_in_region = {
			region = world_persian_empire
			add = 1
		}
	}
	multiply = 100
}

# Paramameter for percentage of Persia that must be iranian
fp3_iranian_culture_for_rekindle_persia_percent_value = 75

fp3_iranian_culture_for_rekindle_persia_decimal_value = {
	value = fp3_iranian_culture_for_rekindle_persia_percent_value
	divide = 100
	max = 1
}

fp3_iranian_culture_current_persian_culture_value = {
	value = 0
	every_county_in_region = {
		region = world_persian_empire
		limit = {
			culture = { has_cultural_pillar = heritage_iranian }
		}
		add = 1
	}
	divide = {
		value = 0
		every_county_in_region = {
			region = world_persian_empire
			add = 1
		}
	}
	multiply = 100
}

fp3_shia_caliphate_ending_conversion_chance_percent_value = 75

fp3_shia_caliphate_ending_conversion_chance_decimal_value = {
	value = fp3_iranian_culture_for_rekindle_persia_percent_value
	divide = 100
	max = 1
}

fp3_strengthen_caliphate_ending_conversion_chance_percent_value = 50

fp3_strengthen_caliphate_ending_conversion_chance_decimal_value = {
	value = fp3_iranian_culture_for_rekindle_persia_percent_value
	divide = 100
	max = 1
}

fp3_struggle_ending_conversion_modifier_value = 1.5

fp3_iranian_faith_for_rekindle_persia_conversion_chance_percent_value = 50

fp3_iranian_faith_for_rekindle_persia_conversion_chance_decimal_value = {
	value = fp3_iranian_culture_for_rekindle_persia_percent_value
	divide = 100
	max = 1
}

fp3_current_nb_ally_shia_caliphate = {
	value = 0
	every_ally = {
		limit = { highest_held_title_tier >= tier_kingdom }
		add = 1
	}
}

##################################################
# Tax Collector 
tax_collector_aptitude_miniscule_increase = { value = 5 }

tax_collector_aptitude_minor_increase = { value = 10 }

tax_collector_aptitude_medium_increase = { value = 15 }

tax_collector_aptitude_major_increase = { value = 20 }

tax_collector_aptitude_massive_increase = { value = 25 }


tax_collector_aptitude_score = {
	value = 1
	add = {
		value = diplomacy
		max = 50
		desc = court_position_skill_diplomacy
	}
	add = {
		value = martial
		max = 50
		desc = court_position_skill_martial
	}
	add = {
		value = stewardship
		max = 50
		desc = court_position_skill_stewardship
	}
	add = {
		value = intrigue
		max = 50
		desc = court_position_skill_intrigue
	}
	add = {
		value = learning
		multiply = 2
		max = 50
		desc = court_position_skill_learning
	}

	if = {
		limit = {
			has_trait = just
		}
		add = {
			value = 10
			desc = court_position_just_trait
		}
	}
	if = {
		limit = {
			has_trait = diplomat
		}
		add = {
			value = 10
			desc = court_position_diplomat_trait
		}
	}
	if = {
		limit = {
			has_trait = administrator
		}
		add = {
			value = 10
			desc = court_position_administrator_trait
		}
	}
	if = {
		limit = {
			has_trait = avaricious
		}
		add = {
			value = 10
			desc = court_position_avaricious_trait
		}
	}
	if = {
		limit = {
			has_character_modifier = fp3_capable_magistrates_modifier
		}
		add = {
			value = tax_collector_aptitude_major_increase
			desc = capable_magistrates_modifier
		}
	}
	if = {
		limit = {
			has_character_flag = fp3_inspired_tax_collector
		}
		add = {
			value = 20
			desc = fp3_inspired_tax_collector
		}
	}
	# Opinion of liege
	add = {
		desc = opinion_of_liege
		value = {
			if = {
				limit = {
					save_temporary_opinion_value_as = { name = target_opinion target = liege}
					scope:target_opinion >= very_high_positive_opinion
				}
				add = 20
			}
			else_if = {
				limit = {
					save_temporary_opinion_value_as = { name = target_opinion target = liege }
					scope:target_opinion >= high_positive_opinion
				}
				add = 15
			}
			else_if = {
				limit = {
					save_temporary_opinion_value_as = { name = target_opinion target = liege }
					scope:target_opinion >= medium_positive_opinion
				}
				add = 10
			}
			else_if = {
				limit = {
					save_temporary_opinion_value_as = { name = target_opinion target = liege }
					scope:target_opinion >= low_positive_opinion
				}
				add = 5
			}
			else = {
				add = 0
			}
		}
	}

	# Cultural Tradition
	if = {
		limit = {
			culture = { has_cultural_parameter = characters_are_better_tax_collector }
		}
		add = {
			value = tax_collector_aptitude_medium_increase
			desc = traditions_cheaper_value
		}
	}

	# Flag Check (for debug/event usage) - Use debug.9610
	if = {
		limit = { has_character_flag = is_guaranteed_excellent_tax_collector }
		add = 110
	}

	add = court_position_aptitude_family_business_value
	add = court_position_aptitude_eunuch_tradition_value

	# Viziers
	if = {
		limit = {
			liege ?= {
				exists = diarch
				has_diarchy_active_parameter = diarch_aptitude_helps_tax_collectors_toggle
			}
		}
		# Are we the vizier? If yes, we get a flat boost tied to our Scales of Power swing.
		if = {
			limit = { this = liege.diarch }
			add = {
				value = diarch_aptitude_helps_tax_collectors_buffed_by_swing_value
				desc = diarchy_tax_collector_boost.scales_of_power
			}
		}
		# Else we're someone different, so we get a fraction of the vizier's aptitude added to our own.
		else = {
			## Plenty of vizier's aptitude.
			if = {
				limit = {
					liege = { has_diarchy_active_parameter = diarch_aptitude_helps_tax_collectors_t4 }
				}
				add = {
					value = {
						value = liege.diarch.tax_collector_aptitude_score
						# But remove the buff the vizier got from the SoP swing or things'll get ridiculous.
						subtract = diarch_aptitude_helps_tax_collectors_buffed_by_swing_value
						# Now, reduce according to the correct percentage.
						multiply = diarch_aptitude_helps_tax_collectors_t4_value
						# Just in case, let's min things.
						min = 1
					}
					desc = diarchy_tax_collector_boost.diarch_aptitude.t4
				}
			}
			## Most of vizier's aptitude.
			else_if = {
				limit = {
					liege = { has_diarchy_active_parameter = diarch_aptitude_helps_tax_collectors_t3 }
				}
				add = {
					value = {
						value = liege.diarch.tax_collector_aptitude_score
						# But remove the buff the vizier got from the SoP swing or things'll get ridiculous.
						subtract = diarch_aptitude_helps_tax_collectors_buffed_by_swing_value
						# Now, reduce according to the correct percentage.
						multiply = diarch_aptitude_helps_tax_collectors_t3_value
						# Just in case, let's min things.
						min = 1
					}
					desc = diarchy_tax_collector_boost.diarch_aptitude.t3
				}
			}
			## Some of vizier's aptitude.
			else_if = {
				limit = {
					liege = { has_diarchy_active_parameter = diarch_aptitude_helps_tax_collectors_t2 }
				}
				add = {
					value = {
						value = liege.diarch.tax_collector_aptitude_score
						# But remove the buff the vizier got from the SoP swing or things'll get ridiculous.
						subtract = diarch_aptitude_helps_tax_collectors_buffed_by_swing_value
						# Now, reduce according to the correct percentage.
						multiply = diarch_aptitude_helps_tax_collectors_t2_value
						# Just in case, let's min things.
						min = 1
					}
					desc = diarchy_tax_collector_boost.diarch_aptitude.t2
				}
			}
			## A little of vizier's aptitude.
			else_if = {
				limit = {
					liege = { has_diarchy_active_parameter = diarch_aptitude_helps_tax_collectors_t1 }
				}
				add = {
					value = {
						value = liege.diarch.tax_collector_aptitude_score
						# But remove the buff the vizier got from the SoP swing or things'll get ridiculous.
						subtract = diarch_aptitude_helps_tax_collectors_buffed_by_swing_value
						# Now, reduce according to the correct percentage.
						multiply = diarch_aptitude_helps_tax_collectors_t1_value
						# Just in case, let's min things.
						min = 1
					}
					desc = diarchy_tax_collector_boost.diarch_aptitude.t1
				}
			}
		}
	}
}

diarch_aptitude_helps_tax_collectors_buffed_by_swing_multiplier_value = 0.5
diarch_aptitude_helps_tax_collectors_buffed_by_swing_value = {
	value = liege.diarchy_swing
	multiply = diarch_aptitude_helps_tax_collectors_buffed_by_swing_multiplier_value
}
diarch_aptitude_helps_tax_collectors_t1_value = 0.1
diarch_aptitude_helps_tax_collectors_t2_value = 0.2
diarch_aptitude_helps_tax_collectors_t3_value = 0.4
diarch_aptitude_helps_tax_collectors_t4_value = 0.6


preferred_tax_collector_modifier = {
	value = 0 
	if = { # Let's prioritize any close family members (cause that's more interesting)
		add = 25
		limit = {
			is_close_family_of = root
		}
	}
}
##################################################

##################################################
# Decisions
embellish_capital_gold_cost = { value = major_gold_value }

claim_the_imamate_decision_same_faith_county_count = 5

claim_the_imamate_decision_same_faith_greater_county_count = 15

claim_the_imamate_decision_own_max_sins = 1

promote_persian_scripture_piety_cost = { value = major_piety_value }

promote_persian_scripture_conversion_modifier_value = 1.5

promote_persian_scripture_fundamentalist_stress_value = { value = major_stress_gain }

consulted_house_councillors_percentage = 10

favour_skilled_outsiders_decision_prestige_cost_value = {
	# Scales to tier.
	## Counts pay basically nothing.
	if = {
		limit = { highest_held_title_tier = tier_county }
		add = minor_prestige_value
	}
	## Dukes pay a bit.
	else_if = {
		limit = { highest_held_title_tier = tier_duchy }
		add = medium_prestige_value
	}
	## Kings pay a moderate amount.
	else_if = {
		limit = { highest_held_title_tier = tier_kingdom }
		add = 225
	}
	## Emperors pay a substantial amount.
	else_if = {
		limit = { highest_held_title_tier = tier_empire }
		add = 300
	}
}


favour_skilled_outsiders_decision_skill_threshold_value = high_skill_rating

favour_skilled_outsiders_decision_tally_offended_courtlies_value = {
	value = 0
	every_vassal = {
		limit = { favour_skilled_outsiders_decision_grab_courtlies_trigger = yes }
	}
	add = 1
}

favour_skilled_outsiders_decision_tally_offended_landless_councillors_value = {
	value = 0
	every_councillor = {
		limit = { favour_skilled_outsiders_decision_grab_landless_councillors_trigger = yes }
	}
	add = 1
}

favour_skilled_outsiders_decision_tally_offended_non_courtlies_value = {
	value = 0
	every_vassal = {
		limit = { favour_skilled_outsiders_decision_non_courtlies_trigger = yes }
	}
	add = 1
}

fp3_skilled_outsider_template_diplomacy_min_value = {
	# Is this a primary skill for this outsider?
	if = {
		limit = { scope:outsider_diplomacy_martial = yes }
		# Guarantee a nice minimum rather than using the usual variance rules.
		add = high_skill_rating
	}
	# Is this a secondary skill for this outsider?
	else_if = {
		limit = { scope:outsider_stewardship_diplomacy = yes }
		# And again, guarantee a nice minimum without variance.
		add = decent_skill_rating
	}
	# Otherwise, this is an irrelevant skill for this outsider.
	else = { add = min_template_low_skill }
}

fp3_skilled_outsider_template_diplomacy_max_value = {
	# Is this a primary skill for this outsider?
	if = {
		limit = { scope:outsider_diplomacy_martial = yes }
		add = max_template_high_skill
	}
	# Is this a secondary skill for this outsider?
	else_if = {
		limit = { scope:outsider_stewardship_diplomacy = yes }
		add = max_template_decent_skill
	}
	# Otherwise, this is an irrelevant skill for this outsider.
	else = { add = max_template_low_skill }
}

fp3_skilled_outsider_template_martial_min_value = {
	# Is this a primary skill for this outsider?
	if = {
		limit = { scope:outsider_martial_prowess = yes }
		# Guarantee a nice minimum rather than using the usual variance rules.
		add = high_skill_rating
	}
	# Is this a secondary skill for this outsider?
	else_if = {
		limit = { scope:outsider_diplomacy_martial = yes }
		# And again, guarantee a nice minimum without variance.
		add = decent_skill_rating
	}
	# Otherwise, this is an irrelevant skill for this outsider.
	else = { add = min_template_low_skill }
}

fp3_skilled_outsider_template_martial_max_value = {
	# Is this a primary skill for this outsider?
	if = {
		limit = { scope:outsider_martial_prowess = yes }
		add = max_template_high_skill
	}
	# Is this a secondary skill for this outsider?
	else_if = {
		limit = { scope:outsider_diplomacy_martial = yes }
		add = max_template_decent_skill
	}
	# Otherwise, this is an irrelevant skill for this outsider.
	else = { add = max_template_low_skill }
}

fp3_skilled_outsider_template_stewardship_min_value = {
	# Is this a primary skill for this outsider?
	if = {
		limit = { scope:outsider_stewardship_diplomacy = yes }
		# Guarantee a nice minimum rather than using the usual variance rules.
		add = high_skill_rating
	}
	# Is this a secondary skill for this outsider?
	else_if = {
		limit = { scope:outsider_intrigue_stewardship = yes }
		# And again, guarantee a nice minimum without variance.
		add = decent_skill_rating
	}
	# Otherwise, this is an irrelevant skill for this outsider.
	else = { add = min_template_low_skill }
}

fp3_skilled_outsider_template_stewardship_max_value = {
	# Is this a primary skill for this outsider?
	if = {
		limit = { scope:outsider_stewardship_diplomacy = yes }
		add = max_template_high_skill
	}
	# Is this a secondary skill for this outsider?
	else_if = {
		limit = { scope:outsider_intrigue_stewardship = yes }
		add = max_template_decent_skill
	}
	# Otherwise, this is an irrelevant skill for this outsider.
	else = { add = max_template_low_skill }
}

fp3_skilled_outsider_template_intrigue_min_value = {
	# Is this a primary skill for this outsider?
	if = {
		limit = { scope:outsider_intrigue_stewardship = yes }
		# Guarantee a nice minimum rather than using the usual variance rules.
		add = high_skill_rating
	}
	# Is this a secondary skill for this outsider?
	else_if = {
		limit = { scope:outsider_learning_intrigue = yes }
		# And again, guarantee a nice minimum without variance.
		add = decent_skill_rating
	}
	# Otherwise, this is an irrelevant skill for this outsider.
	else = { add = min_template_low_skill }
}

fp3_skilled_outsider_template_intrigue_max_value = {
	# Is this a primary skill for this outsider?
	if = {
		limit = { scope:outsider_intrigue_stewardship = yes }
		add = max_template_high_skill
	}
	# Is this a secondary skill for this outsider?
	else_if = {
		limit = { scope:outsider_learning_intrigue = yes }
		add = max_template_decent_skill
	}
	# Otherwise, this is an irrelevant skill for this outsider.
	else = { add = max_template_low_skill }
}

fp3_skilled_outsider_template_learning_min_value = {
	# Is this a primary skill for this outsider?
	if = {
		limit = { scope:outsider_learning_intrigue = yes }
		# Guarantee a nice minimum rather than using the usual variance rules.
		add = high_skill_rating
	}
	# Is this a secondary skill for this outsider?
	else_if = {
		limit = { scope:outsider_prowess_learning = yes }
		# And again, guarantee a nice minimum without variance.
		add = decent_skill_rating
	}
	# Otherwise, this is an irrelevant skill for this outsider.
	else = { add = min_template_low_skill }
}

fp3_skilled_outsider_template_learning_max_value = {
	# Is this a primary skill for this outsider?
	if = {
		limit = { scope:outsider_learning_intrigue = yes }
		add = max_template_high_skill
	}
	# Is this a secondary skill for this outsider?
	else_if = {
		limit = { scope:outsider_prowess_learning = yes }
		add = max_template_decent_skill
	}
	# Otherwise, this is an irrelevant skill for this outsider.
	else = { add = max_template_low_skill }
}

fp3_skilled_outsider_template_prowess_min_value = {
	# Is this a primary skill for this outsider?
	if = {
		limit = { scope:outsider_prowess_learning = yes }
		# Guarantee a nice minimum rather than using the usual variance rules.
		add = high_skill_rating
	}
	# Is this a secondary skill for this outsider?
	else_if = {
		limit = { scope:outsider_martial_prowess = yes }
		# And again, guarantee a nice minimum without variance.
		add = decent_skill_rating
	}
	# Otherwise, this is an irrelevant skill for this outsider.
	else = { add = min_template_low_skill }
}

fp3_skilled_outsider_template_prowess_max_value = {
	# Is this a primary skill for this outsider?
	if = {
		limit = { scope:outsider_prowess_learning = yes }
		add = max_template_high_skill
	}
	# Is this a secondary skill for this outsider?
	else_if = {
		limit = { scope:outsider_martial_prowess = yes }
		add = max_template_decent_skill
	}
	# Otherwise, this is an irrelevant skill for this outsider.
	else = { add = max_template_low_skill }
}

fp3_skilled_outsider_minimum_main_skill_batch_b_char1_value = {
	# Three points above...
	value = 3
	if = {
		limit = { scope:outsider_diplomacy_martial = yes }
		add = diplomacy
	}
	if = {
		limit = { scope:outsider_martial_prowess = yes }
		add = martial
	}
	if = {
		limit = { scope:outsider_prowess_learning = yes }
		add = prowess
	}
	if = {
		limit = { scope:outsider_learning_intrigue = yes }
		add = learning
	}
	if = {
		limit = { scope:outsider_intrigue_stewardship = yes }
		add = intrigue
	}
	if = {
		limit = { scope:outsider_stewardship_diplomacy = yes }
		add = stewardship
	}
}

fp3_skilled_outsider_minimum_main_skill_batch_b_char2_value = {
	# Two points below...
	value = -2
	if = {
		limit = { scope:outsider_diplomacy_martial = yes }
		add = diplomacy
	}
	if = {
		limit = { scope:outsider_martial_prowess = yes }
		add = martial
	}
	if = {
		limit = { scope:outsider_prowess_learning = yes }
		add = prowess
	}
	if = {
		limit = { scope:outsider_learning_intrigue = yes }
		add = learning
	}
	if = {
		limit = { scope:outsider_intrigue_stewardship = yes }
		add = intrigue
	}
	if = {
		limit = { scope:outsider_stewardship_diplomacy = yes }
		add = stewardship
	}
}

##################################################
# Military
fp3_realm_based_mercenary_cost = {
	# Sample formula
	# X * (Y + (Z/10) # Real example: 1162 * (0.6 + (4 / 10)) = 1162, meaning that if you have 4 counties, you get no discount, but no increase either.
	# X is the initial cost. It is not in the operation above because it is applied post-facto as a modifier.
	# Y is our base value, since we want to make the initial cost cheaper with a multiplication, it is a decimal. I chose 0.6, but it can be tweaked.
	# Z is realm size. We turn it into a decimal so that it can then be added to our base value (Y), increasing the cost to either a lesser discount or an upsell based on size.
	value = 0.6
	add = {
		value = sub_realm_size
		divide = 10
	}
}

fp3_request_invasion_troop_value_estimate = {
	value = scope:recipient.max_military_strength
	subtract = scope:secondary_recipient.max_military_strength
	divide = 20
	round = yes
}

fp3_request_invasion_troop_value_bonus_troops = {
	value = scope:recipient.max_military_strength
	subtract = scope:secondary_recipient.max_military_strength
	divide = 500
	round = yes
	min = 1
	max = 10
}

fp3_request_invasion_troop_value_bonus_levy_troops = {
	value = fp3_request_invasion_troop_value_bonus_troops
	multiply = 100
}



# The cost in gold of sponsoring a new research project
fp3_research_base_cost = {
	value = medium_gold_value
}


##################################################
# Seljuk invaion

fp3_seljuk_chance_of_appearance = 10
fp3_chance_female_leader = {
	value = 0
	if = {
		limit = {  has_game_rule = inversed_gender_equality  }
		add = 100
	}
	else_if = {
		limit = {  has_game_rule = full_gender_equality  }
		add = 50
	}
	else = {
		add = 0
	}
}

fp3_seljuk_invasion_troop_gain_minor = 1
fp3_seljuk_invasion_troop_gain_small = 2
fp3_seljuk_invasion_troop_gain_medium = 3
fp3_seljuk_invasion_troop_gain_major = 4
fp3_seljuk_invasion_troop_gain_massive = 5

fp3_seljuk_stack_miniscule_value = 0.6
fp3_seljuk_stack_minor_value = 0.8
fp3_seljuk_stack_medium_value = 1
fp3_seljuk_stack_major_value = 1.25
fp3_seljuk_stack_massive_value = 1.5
fp3_seljuk_stack_monumental_value = 2

seljuk_invasion_nomad_strength_score_levy = {
	value = 0
	if = {
		limit = { has_variable = seljuk_invasion_nomad_strength_score }
		add = var:seljuk_invasion_nomad_strength_score
	}
	multiply = 100
}

seljuk_invasion_nomad_strength_score_siege_weapon = {
	value = 0
	if = {
		limit = { has_variable = seljuk_invasion_nomad_strength_score }
		add = var:seljuk_invasion_nomad_strength_score
	}
	multiply = 0.5
}

# Zanj Rebellion

zanj_rebellion_strength_score_levy = {
		value = 0
		if = {
			limit = { has_variable = zanj_rebellion_strength_score }
			add = var:zanj_rebellion_strength_score
		}
		multiply = 200
}

zanj_rebellion_strength_score_skirmishers = {
		value = 0
		if = {
			limit = { has_variable = zanj_rebellion_strength_score }
			add = var:zanj_rebellion_strength_score
		}
}

zanj_rebellion_strength_score_bowmen = {
		value = 0
		if = {
			limit = { has_variable = zanj_rebellion_strength_score }
			add = var:zanj_rebellion_strength_score
		}
		multiply = 0.5
}

zanj_rebellion_strength_score_pikemen = {
		value = 0
		if = {
			limit = { has_variable = zanj_rebellion_strength_score }
			add = var:zanj_rebellion_strength_score
		}
		multiply = 0.5
}

rescue_house_members_cb_house_unity_gain = {
	scope:defender = {
		every_prisoner = {
			limit = { house ?= scope:attacker.house }
			add = medium_unity_gain
		}
	}

	max = 20
}

fp3_struggle_switch_sides_value = {
	value = 0
	if = {
		limit = {
			has_trait = fp3_struggle_supporter
			NAND = {
				faith = { has_doctrine = muhammad_succession_sunni_doctrine }
				has_trait = zealous
			}
			exists = title:d_sunni.holder
			NOR = {
				this = title:d_sunni.holder
				has_relation_friend = title:d_sunni.holder
				has_relation_lover = title:d_sunni.holder
				opinion = {
					target = title:d_sunni.holder
					value >= 50
				}
			}
		}
		if = {
			limit = {
				has_trait = ambitious
			}
			add = 10
		}
		if = {
			limit = {
				has_trait = cynical
			}
			add = 20
		}
		if = {
			limit = {
				has_trait = vengeful
			}
			add = 5
		}
		if = {
			limit = {
				has_trait = arrogant
			}
			add = 10
		}
		if = {
			limit = {
				has_trait = arbitrary
			}
			add = 5
		}
		if = {
			limit = {
				has_trait = disloyal
			}
			add = 30
		}
		if = {
			limit = {
				has_trait = fickle
			}
			add = 5
		}
		if = {
			limit = {
				culture = { has_cultural_pillar = heritage_turkic }
			}
			add = 50
		}
		if = {
			limit = {
				NOT = {
					faith = { has_doctrine = muhammad_succession_sunni_doctrine }
				}
			}
			add = 200
		}
		if = {
			limit = {
				ai_zeal < 0
			}
			add = {
				value = ai_zeal
				multiply = -1
				divide = 4
			}
		}
		if = {
			limit = {
				exists = title:d_sunni.holder
				has_relation_rival = title:d_sunni.holder
			}
			add = 200
		}
		if = {
			limit = {
				exists = title:d_sunni.holder
				opinion = {
					target = title:d_sunni.holder
					value <= -75
				}
			}
			add = 50
		}
		else_if = {
			limit = {
				exists = title:d_sunni.holder
				opinion = {
					target = title:d_sunni.holder
					value <= -50
				}
			}
			add = 40
		}
		else_if = {
			limit = {
				exists = title:d_sunni.holder
				opinion = {
					target = title:d_sunni.holder
					value <= -30
				}
			}
			add = 30
		}
		else_if = {
			limit = {
				exists = title:d_sunni.holder
				opinion = {
					target = title:d_sunni.holder
					value <= -10
				}
			}
			add = 20
		}
		else_if = {
			limit = {
				exists = title:d_sunni.holder
				opinion = {
					target = title:d_sunni.holder
					value <= 0
				}
			}
			add = 10
		}
		else_if = {
			limit = {
				exists = title:d_sunni.holder
				opinion = {
					target = title:d_sunni.holder
					value >= 40
				}
			}
			add = -30
		}
		else_if = {
			limit = {
				exists = title:d_sunni.holder
				opinion = {
					target = title:d_sunni.holder
					value >= 30
				}
			}
			add = -20
		}
		else_if = {
			limit = {
				exists = title:d_sunni.holder
				opinion = {
					target = title:d_sunni.holder
					value >= 20
				}
			}
			add = -10
		}
		else_if = {
			limit = {
				exists = title:d_sunni.holder
				opinion = {
					target = title:d_sunni.holder
					value >= 10
				}
			}
			add = -5
		}
	}
	else_if = {
		limit = {
			has_trait = fp3_struggle_detractor
			exists = title:d_sunni.holder
			NOR = {
				has_relation_rival = title:d_sunni.holder
				opinion = {
					target = title:d_sunni.holder
					value <= -50
				}
			}
		}
		if = {
			limit = {
				has_trait = content
			}
			add = 20
		}
		if = {
			limit = {
				has_trait = zealous
			}
			add = 30
		}
		if = {
			limit = {
				has_trait = trusting
			}
			add = 10
		}
		if = {
			limit = {
				has_trait = just
			}
			add = 10
		}
		if = {
			limit = {
				has_trait = humble
			}
			add = 20
		}
		if = {
			limit = {
				has_trait = loyal
			}
			add = 30
		}
		if = {
			limit = {
				culture = { has_cultural_pillar = heritage_turkic }
			}
			add = -50
		}
		if = {
			limit = {
				NOT = {
					faith = { has_doctrine = muhammad_succession_sunni_doctrine }
				}
			}
			add = -200
		}
		if = {
			limit = {
				ai_zeal > 0
				faith = { has_doctrine = muhammad_succession_sunni_doctrine }
			}
			add = {
				value = ai_zeal
				multiply = -1
				divide = 4
			}
		}
		if = {
			limit = {
				exists = title:d_sunni.holder
				OR = {
					has_relation_friend = title:d_sunni.holder
					has_relation_lover = title:d_sunni.holder
				}
			}
			add = 200
		}
		if = {
			limit = {
				exists = title:d_sunni.holder
				opinion = {
					target = title:d_sunni.holder
					value >= 75
				}
			}
			add = 50
		}
		else_if = {
			limit = {
				exists = title:d_sunni.holder
				opinion = {
					target = title:d_sunni.holder
					value >= 50
				}
			}
			add = 40
		}
		else_if = {
			limit = {
				exists = title:d_sunni.holder
				opinion = {
					target = title:d_sunni.holder
					value >= 30
				}
			}
			add = 20
		}
		else_if = {
			limit = {
				exists = title:d_sunni.holder
				opinion = {
					target = title:d_sunni.holder
					value >= 10
				}
			}
			add = 5
		}
		else_if = {
			limit = {
				exists = title:d_sunni.holder
				opinion = {
					target = title:d_sunni.holder
					value <= -40
				}
			}
			add = -50
		}
		else_if = {
			limit = {
				exists = title:d_sunni.holder
				opinion = {
					target = title:d_sunni.holder
					value <= -30
				}
			}
			add = -40
		}
		else_if = {
			limit = {
				exists = title:d_sunni.holder
				opinion = {
					target = title:d_sunni.holder
					value <= -20
				}
			}
			add = -30
		}
		else_if = {
			limit = {
				exists = title:d_sunni.holder
				opinion = {
					target = title:d_sunni.holder
					value <= 0
				}
			}
			add = -20
		}
	}
} 
