﻿
##########
# Religious Relations
##########

# Piety:

# The base modifier
court_chaplain_religious_relations_modifier = {
	add = learning
	divide = 20
}

# Bonus from Clerical Justifications Perk
court_chaplain_religious_relations_perk_bonus_modifier = {
	if = {
		limit = {
			scope:councillor_liege = { has_perk = clerical_justifications_perk }
		}
		# Set up the base value
		add = court_chaplain_religious_relations_modifier
		# Calculate the final value
		multiply = {
			add = clerical_justifications_percentage
			divide = 100
		}
	}
}

# Bonus from Bureaucrats
court_chaplain_religious_relations_erudition_legacy_5_bonus_modifier = {
	if = {
		limit = {
			councillor_liege_has_erudition_legacy_5_perk = yes
		}
		# Base value
		add = court_chaplain_religious_relations_modifier
		# Calculation of final value
		multiply = {
			add = erudition_legacy_5_percentage
			divide = 100
		}
	}
}

court_chaplain_religious_relations_family_business_bonus_modifier = {
	if = {
		limit = {
			councillor_liege_has_family_business_bonus = yes
		}
		# Base value
		add = court_chaplain_religious_relations_modifier
		# Calculation of final value
		multiply = {
			add = family_business_councillors_percentage
			divide = 100
		}
	}
}

court_chaplain_religious_relations_consulted_house_bonus_modifier = {
	if = {
		limit = {
			councillor_liege_has_consulted_house_bonus = yes
		}
		# Base value
		add = court_chaplain_religious_relations_modifier
		# Calculation of final value
		multiply = {
			add = consulted_house_councillors_percentage
			divide = 100
		}
	}
}

court_chaplain_religious_relations_cultural_tradition_bonus_modifier = {
	if = {
		limit = {
			exists = scope:councillor_liege.culture
			trigger_if = {
				limit = { exists = scope:councillor_liege.culture }
				scope:councillor_liege.culture ?= { has_cultural_parameter = religious_relations_is_empowered }
			}
		}
		add = court_chaplain_religious_relations_modifier
		multiply = 0.2 #When changing, adjust culture_parameter_religious_relations_is_empowered
	}
}

court_chaplain_religious_relations_celestial_hierarchy_bonus_modifier = {
	if = {
		limit = {
			scope:councillor_liege.rite ?= { rite_has_parameter = tenet_celestial_hierarchy_religious_relations_bonus }
		}
		add = court_chaplain_religious_relations_modifier
		multiply = celestial_hierarchy_religious_relations_percentage_value
	}
}

# Total gain calculation
court_chaplain_religious_relations_total_piety_gain = {
	add = court_chaplain_religious_relations_modifier
	add = court_chaplain_religious_relations_perk_bonus_modifier
	add = court_chaplain_religious_relations_erudition_legacy_5_bonus_modifier
	add = court_chaplain_religious_relations_family_business_bonus_modifier
	add = court_chaplain_religious_relations_consulted_house_bonus_modifier
	add = court_chaplain_religious_relations_cultural_tradition_bonus_modifier
	add = court_chaplain_religious_relations_celestial_hierarchy_bonus_modifier
}

# Opinion:
# Religious Relations balancing value for no HoF -- this value will be used to divide the final values 
court_chaplain_religious_relations_no_hof_balance = {
	add = 2
}

# Base modifier value
court_chaplain_religious_relations_opinion_base = {
	add = learning
	divide = 2
}

court_chaplain_religious_relations_no_hof_opinion_base = {
	add = court_chaplain_religious_relations_opinion_base
	divide = court_chaplain_religious_relations_no_hof_balance
}

# Bonus to opinion from Clerical Justifications Perk
court_chaplain_religious_relations_opinion_max_perk_modifier = {
	add = court_chaplain_religious_relations_opinion_base
	multiply = {
		add = clerical_justifications_percentage
		divide = 100
	}
}

# Bonus to opinion from Bureaucrats
court_chaplain_religious_relations_opinion_max_erudition_modifier = {
	add = court_chaplain_religious_relations_opinion_base
	multiply = {
		add = erudition_legacy_5_percentage
		divide = 100
	}
}

court_chaplain_religious_relations_opinion_max_family_business_modifier = {
	add = court_chaplain_religious_relations_opinion_base
	multiply = {
		add = family_business_councillors_percentage
		divide = 100
	}
}

court_chaplain_religious_relations_opinion_max_consulted_house_modifier = {
	add = court_chaplain_religious_relations_opinion_base
	multiply = {
		add = consulted_house_councillors_percentage
		divide = 100
	}
}

court_chaplain_religious_relations_opinion_max_celestial_hierarchy_modifier = {
	add = court_chaplain_religious_relations_opinion_base
	multiply = celestial_hierarchy_religious_relations_percentage_value
}

# Calculate the full max value of the opinion gain
court_chaplain_religious_relations_opinion_max = {
	add = court_chaplain_religious_relations_opinion_base
	# Add bonus from Clerical Justification:
	if = {
		limit = {
			scope:councillor_liege = { has_perk = clerical_justifications_perk }
		}
		add = court_chaplain_religious_relations_opinion_max_perk_modifier
	}
	# Add bonus from Bureaucrats
	if = {
		limit = {
			councillor_liege_has_erudition_legacy_5_perk = yes
		}
		add = court_chaplain_religious_relations_opinion_max_erudition_modifier
	}
	if = {
		limit = {
			councillor_liege_has_family_business_bonus = yes
		}
		add = court_chaplain_religious_relations_opinion_max_family_business_modifier
	}
	if = {
		limit = {
			councillor_liege_has_consulted_house_bonus = yes
		}
		add = court_chaplain_religious_relations_opinion_max_consulted_house_modifier
	}
	# PAM Celestial Hierarchy
	if = {
		limit = {
			scope:councillor_liege.rite ?= { rite_has_parameter = tenet_celestial_hierarchy_religious_relations_bonus }
		}
		add = court_chaplain_religious_relations_opinion_max_celestial_hierarchy_modifier
	}
}

court_chaplain_religious_relations_no_hof_opinion_max = {
	add = court_chaplain_religious_relations_opinion_max
	divide = court_chaplain_religious_relations_no_hof_balance
}

# What % of total religious relations opinion gain have we achieved?
court_chaplain_religious_relations_opinion_scale = {
	value = 0
	if = {
		limit = {
			scope:councillor_liege = {
				is_ai = yes
				top_liege = this
			}
		}
		add = court_chaplain_religious_relations_opinion_max
	}
	else_if = {
		limit = {
			scope:councillor_liege = { has_variable = court_chaplain_religious_relations_opinion_value }
		}
		add = scope:councillor_liege.var:court_chaplain_religious_relations_opinion_value
	}
}

# Value used to fetch the correct "current Opinion bonus" value for player or AI
# Bypasses monthly calculation for AI (it's not worth calculating it for them)
court_chaplain_religious_relations_opinion_modifier = {
	add = 0
	if = {
		limit = {
			scope:councillor_liege = {
				is_ai = no
				has_variable = court_chaplain_religious_relations_opinion_value
			}
		}
		add = liege.var:court_chaplain_religious_relations_opinion_value
	}
	else = {
		add = court_chaplain_religious_relations_opinion_max
	}
}

court_chaplain_religious_relations_no_hof_opinion_modifier = {
	add = 0
	if = {
		limit = { 
			scope:councillor.faith ?= {
				OR = {
					has_doctrine_parameter = no_head_of_faith
					NOT = { exists = religious_head }
				}
			}
			scope:councillor.rite ?= { rite_has_doctrine = doctrine_theocracy_lay_clergy }
		}
		add = court_chaplain_religious_relations_opinion_modifier
		divide = court_chaplain_religious_relations_no_hof_balance
	}
}

# How much religious relations increases by montly. Simply derived from the Max value (which in turn considers Councillor Skill and bonuses)
court_chaplain_religious_relations_monthly_increase = {
	add = court_chaplain_religious_relations_opinion_max
	divide = 24 # 2 years to max out
}

court_chaplain_religious_relations_no_hof_monthly_increase = {
	add = court_chaplain_religious_relations_monthly_increase
	divide = court_chaplain_religious_relations_no_hof_balance
}


#####################
# Fabricate Claim
#####################

# Base value
court_chaplain_fabricate_claim_base = {
	add = 3
}

court_chaplain_fabricate_claim_monthly_increase_base = {
	add = learning
	divide = 5
}

court_chaplain_fabricate_claim_base_total = {
	add = court_chaplain_fabricate_claim_base
	add = court_chaplain_fabricate_claim_monthly_increase_base
}

# Bonus from Accomplished Forger Perk
court_chaplain_fabricate_claim_perk_bonus_monthly_increase = {
	add = court_chaplain_fabricate_claim_base_total
	multiply = {
		add = accomplished_forger_percentage
		divide = 100
	}
}

# Bonus from Bureaucrats
court_chaplain_fabricate_claim_dynasty_perk_bonus = {
	add = court_chaplain_fabricate_claim_base_total
	multiply = {
		add = erudition_legacy_5_percentage
		divide = 100
	}
}

# From Family Business
court_chaplain_fabricate_claim_family_business_bonus = {
	add = court_chaplain_fabricate_claim_base_total
	multiply = {
		add = family_business_councillors_percentage
		divide = 100
	}
}

# FP3 Consulted House
court_chaplain_fabricate_claim_consulted_house_bonus = {
	add = court_chaplain_fabricate_claim_base_total
	multiply = {
		add = consulted_house_councillors_percentage
		divide = 100
	}
}

# Bonus from Land Grants innovation
court_chaplain_fabricate_claim_innovation_bonus_land_grants = {
	value = 0
	add = court_chaplain_fabricate_claim_base_total
	multiply = 0.50
}

# Bonus from tradition_language_scholars
court_chaplain_fabricate_claim_tradition_language_scholars_bonus = {
	value = 0
	add = court_chaplain_fabricate_claim_base_total
	multiply = {
		add = {
			value = scope:councillor.liege.num_of_known_languages
			multiply = 10
		}
		divide = 100
	}
}

court_chaplain_fabricate_claim_inspection_reward_bonus = {
	value = 0
	add = court_chaplain_fabricate_claim_base_total
	multiply = 0.25
}

# tenet_transubstantiation

court_chaplain_fabricate_claim_transubstantiation_bonus = {
	value = 0
	add = court_chaplain_fabricate_claim_base_total
	multiply = 0.20
}

# Relation impact
court_chaplain_fabricate_claim_monthly_increase_friend_bonus = {
	value = court_chaplain_fabricate_claim_base_total
	multiply = {
		add = council_friend_impact_percentage
		divide = 100
	}
}
court_chaplain_fabricate_claim_monthly_increase_best_friend_bonus = {
	value = court_chaplain_fabricate_claim_base_total
	multiply = {
		add = council_best_friend_impact_percentage
		divide = 100
	}
}
court_chaplain_fabricate_claim_monthly_increase_rival_bonus = {
	value = court_chaplain_fabricate_claim_base_total
	multiply = {
		add = council_rival_impact_percentage
		divide = 100
	}
}
court_chaplain_fabricate_claim_monthly_increase_nemesis_bonus = {
	value = court_chaplain_fabricate_claim_base_total
	multiply = {
		add = council_nemesis_impact_percentage
		divide = 100
	}
}

court_chaplain_fabricate_claim_county_base = 3
court_chaplain_fabricate_claim_county_min_cost = {
	value = { 40 60 }
}

court_chaplain_fabricate_claim_duchy_base = 7
court_chaplain_fabricate_claim_duchy_min_cost = {
	value = { 80 100 }
}

court_chaplain_fabricate_claim_factor = 1

court_chaplain_fabricate_claim_struggle_penalty_multiplier_value = {
	if = {
		limit = {
			exists = scope:county
			scope:county = {
				any_county_struggle = {
					is_struggle_parameter_active_secondary_character_involvement_neither_trigger = {
						PARAMETER = claims_in_region_more_expensive_to_press_for_uninvolved
						CHAR = root
					}
				}
			}
		}
		value = 2
	}
	else = { value = 1 }
}

court_chaplain_fabricate_claim_county_cost = {
	# Base cost
	add = 40
	subtract = learning
	# Standard Factors
	multiply = court_chaplain_fabricate_claim_factor
	multiply = court_chaplain_fabricate_claim_county_base
	# Struggle Factors
	multiply = court_chaplain_fabricate_claim_struggle_penalty_multiplier_value

	min = court_chaplain_fabricate_claim_county_min_cost
}

court_chaplain_fabricate_claim_duchy_cost = {
	# Base cost
	add = 40
	subtract = learning
	# Standard Factors
	multiply = court_chaplain_fabricate_claim_factor
	multiply = court_chaplain_fabricate_claim_duchy_base
	# Struggle Factors
	multiply = court_chaplain_fabricate_claim_struggle_penalty_multiplier_value

	min = court_chaplain_fabricate_claim_duchy_min_cost
}

court_chaplain_fabricate_claim_not_adjacent_penalty = {
	value = 0.5
}

court_chaplain_fabricate_claim_vassal_penalty = {
	value = 0.3
}

court_chaplain_heretic_bonus = {
	value = 1.3
}

#Domicile Bonus 
estate_increase_fabricate_speed = { #Chancery bonus
	if = {
		limit = {
			OR = {
				#Does the archbishopric they reside in have a Chancery? 
				liege.capital_county.clerical_region_title.holder ?= { 
					domicile ?= {
						has_domicile_parameter = estate_increase_fabricate_speed_3
					}
					rite = root.rite
				}
				#Does their liege have a Chancery? 
				liege.domicile ?= { has_domicile_parameter = estate_increase_fabricate_speed_3 }
				domicile ?= { has_domicile_parameter = estate_increase_fabricate_speed_3 }
			}
		}
		value = court_chaplain_fabricate_claim_base_total
		multiply = ecclesiastical_domicile_increase_fabricate_speed_value_3
		desc = estate_increase_fabricate_speed_desc
	}
	else_if = {
		limit = {
			OR = {
				#Does the archbishopric they reside in have a Chancery? 
				liege.capital_county.clerical_region_title.holder ?= { 
					domicile ?= {
						has_domicile_parameter = estate_increase_fabricate_speed_2
					}
					rite = root.rite
				}
				#Does their liege have a Chancery? 
				liege.domicile ?= { has_domicile_parameter = estate_increase_fabricate_speed_2 }
				domicile ?= { has_domicile_parameter = estate_increase_fabricate_speed_2 }
			}
		}
		value = court_chaplain_fabricate_claim_base_total
		multiply = ecclesiastical_domicile_increase_fabricate_speed_value_2
		desc = estate_increase_fabricate_speed_desc
	}
	else_if = {
		limit = {
			OR = {
				#Does the archbishopric they reside in have a Chancery? 
				liege.capital_county.clerical_region_title.holder ?= { 
					domicile ?= {
						has_domicile_parameter = estate_increase_fabricate_speed_1
					}
					rite = root.rite
				}
				#Does their liege have a Chancery? 
				liege.domicile ?= { has_domicile_parameter = estate_increase_fabricate_speed_1 }
				domicile ?= { has_domicile_parameter = estate_increase_fabricate_speed_1 }
			}
		}
		value = court_chaplain_fabricate_claim_base_total
		multiply = ecclesiastical_domicile_increase_fabricate_speed_value_1
		desc = estate_increase_fabricate_speed_desc
	}
}

#######################
# Conversion
#######################

# Base progress value
court_chaplain_conversion_base = {
	add = 0.5
}

court_chaplain_conversion_monthly_increase = {
	add = learning
	divide = 10
}

court_chaplain_conversion_base_total = {
	add = court_chaplain_conversion_base
	add = court_chaplain_conversion_monthly_increase
}

court_chaplain_conversion_contextual_bonuses = {
	#Perk Bonus
	if = {
		limit = {
			scope:councillor_liege = { has_perk = zealous_proselytizer_perk }
		}
		add = {
			value = scope:councillor.court_chaplain_conversion_monthly_increase_perk_bonus
			desc = CONVERSION_PERK_BONUS_VALUE
		}
	}
	if = {
		limit = {
			councillor_liege_has_erudition_legacy_5_perk = yes
		}
		add = {
			value = scope:councillor.court_chaplain_conversion_monthly_increase_dynasty_perk_bonus
			desc = CONVERSION_DYNASTY_PERK_BONUS_VALUE
		}
	}
	if = {
		limit = {
			councillor_liege_has_family_business_bonus = yes
		}
		add = {
			value = scope:councillor.court_chaplain_conversion_monthly_increase_family_business_bonus
			desc = FAMILY_BUSINESS_BONUS_VALUE
		}
	}
	if = {
		limit = {
			councillor_liege_has_consulted_house_bonus = yes
		}
		add = {
			value = scope:councillor.court_chaplain_conversion_monthly_increase_consulted_house_bonus
			desc = CONSULTED_HOUSE_BONUS_VALUE
		}
	}
	# Relation Bonuses/Penalties
	if = { # Friend
		limit = {
			scope:councillor_liege = {
				has_relation_friend = scope:councillor
				NOT = { has_relation_best_friend = scope:councillor }
			}
		}
		add = {
			value = scope:councillor.court_chaplain_conversion_monthly_increase_friend_bonus
			desc = COUNCILLOR_IS_YOUR_FRIEND
		}
	}
	if = { # Best Friend
		limit = {
			scope:councillor_liege = {
				has_relation_best_friend = scope:councillor
			}
		}
		add = {
			value = scope:councillor.court_chaplain_conversion_monthly_increase_best_friend_bonus
			desc = COUNCILLOR_IS_YOUR_BEST_FRIEND
		}
	}
	if = { # Rival
		limit = {
			scope:councillor_liege = {
				has_relation_rival = scope:councillor
				NOT = { has_relation_nemesis = scope:councillor }
			}
		}
		add = {
			value = scope:councillor.court_chaplain_conversion_monthly_increase_rival_bonus
			desc = COUNCILLOR_IS_YOUR_RIVAL
		}
	}
	if = { # Nemesis
		limit = {
			scope:councillor_liege = {
				has_relation_nemesis = scope:councillor
			}
		}
		add = {
			value = scope:councillor.court_chaplain_conversion_monthly_increase_nemesis_bonus
			desc = COUNCILLOR_IS_YOUR_NEMESIS
		}
	}
	#Conversion modifiers from where the Faith is on the Pluralism spectrum.
	if = {
		limit = {
			scope:councillor.rite ?= {
				rite_has_parameter = pluralism_fundamentalist_proselytization_bonus
			}
		}
		add = {
			value = scope:councillor.conversion_fundamentalist_faith_bonus
			desc = COURT_CHAPLAIN_CONVERSION_FUNDAMENTALIST_FAITH_BONUS
		}
	}
	if = {
		limit = {
			scope:councillor.rite ?= {
				rite_has_parameter = pluralism_pluralistic_proselytization_penalty
			}
		}
		add = {
			value = scope:councillor.conversion_pluralistic_faith_penalty
			desc = COURT_CHAPLAIN_CONVERSION_PLURALISTIC_FAITH_PENALTY
		}
	}
	
	#Conversion penalties for County Faith Tenets
	# Shared parameter; breakdown credits the tenet that grants it
	if = {
		limit = {
			exists = scope:county
			scope:county.rite ?= {
				rite_has_parameter = sanctioned_false_conversion_county_resistance
			}
		}
		if = {
			limit = {
				scope:county.rite ?= { rite_has_tenet = tenet_false_conversion_sanction }
			}
			add = {
				value = scope:councillor.conversion_false_conversion_sanction_resistance
				desc = COURT_CHAPLAIN_CONVERSION_FALSE_CONVERSION_MODIFIER
			}
		}
		else_if = {
			limit = {
				scope:county.rite ?= { rite_has_tenet = tenet_pastoral_isolation }
			}
			add = {
				value = scope:councillor.conversion_pastoral_isolation_resistance
				desc = COURT_CHAPLAIN_CONVERSION_PASTORAL_ISOLATION_MODIFIER
			}
		}
		else = {
			add = {
				value = scope:councillor.conversion_pure_land_resistance
				desc = COURT_CHAPLAIN_CONVERSION_PURE_LAND_MODIFIER
			}
		}
	}
	# Two tenets grant this, so we check once and a faith with both still resists only once
	if = {
		limit = {
			exists = scope:county
			scope:county.rite ?= {
				rite_has_parameter = reincarnation_resistance_to_conversion
			}
		}
		if = {
			limit = {
				scope:county.rite ?= { rite_has_tenet = tenet_reincarnation }
			}
			add = {
				value = scope:councillor.conversion_reincarnation_resistance
				desc = COURT_CHAPLAIN_CONVERSION_REINCARNATION_MODIFIER
			}
		}
		else = {
			# Dharmic Pacifism is the only other tenet granting the parameter; add a branch if that changes.
			add = {
				value = scope:councillor.conversion_dharmic_pacifism_resistance
				desc = COURT_CHAPLAIN_CONVERSION_DHARMIC_PACIFISM_MODIFIER
			}
		}
	}
	if = {
		limit = {
			exists = scope:county
			scope:county.rite ?= {
				rite_has_parameter = tenet_adaptive_conversion_resistance
			}
		}
		add = {
			value = scope:councillor.conversion_adaptive_resistance
			desc = COURT_CHAPLAIN_CONVERSION_ADAPTIVE_MODIFIER
		}
	}
	if = {
		limit = {
			scope:councillor.liege.rite ?= { rite_has_parameter = other_culture_conversion_penalty_active }
			exists = scope:county
			scope:county.culture != scope:councillor.liege.culture
		}
		add = {
			value = scope:councillor.conversion_communal_identity_resistance
			desc = COURT_CHAPLAIN_CONVERSION_COMMUNAL_IDENTITY_PENALTY_MODIFIER
		}
	}

	# Tenet Modifiers
	## Bonuses
	### Mendicant Preachers
	if = {
		limit = {
			scope:councillor.rite ?= {
				rite_has_parameter = mendicant_preachers_conversion_active
			}
		}
		add = {
			value = scope:councillor.conversion_mendicant_preachers_bonus
			desc = COURT_CHAPLAIN_CONVERSION_MENDICANT_PREACHERS_MODIFIER
		}
	}
	### Alexandrian Catechism
	if = {
		limit = {
			scope:councillor_liege ?= {
				has_personal_tenet_flag = tenet_alexandrian_catechism_catechesis_conversion
			}
		}
		add = {
			value = scope:councillor.conversion_alexandrian_catechism_bonus
			desc = COURT_CHAPLAIN_CONVERSION_ALEXANDRIAN_CATECHISM_MODIFIER
		}
	}
	### Communal Identity
	if = {
		limit = {
			exists = scope:county
			scope:councillor.rite ?= {
				rite_has_parameter = same_culture_conversion_bonus_active
			}
			scope:county.culture = scope:councillor.liege.culture
		}
		add = {
			value = scope:councillor.conversion_communal_identity_bonus
			desc = COURT_CHAPLAIN_CONVERSION_COMMUNAL_IDENTITY_BONUS_MODIFIER
		}
	}
	### GHW sans HoF buffs
	if = {
		limit = {
			exists = scope:county
			scope:councillor.faith ?= {
				has_doctrine_parameter = ghw_no_hof_conversion_buffs_active
				OR = {
					has_doctrine_parameter = no_head_of_faith
					NOT = { exists = religious_head }
				}
				holy_sites_controlled >= 1
			}
		}
		add = {
			value = scope:councillor.conversion_ghw_tenet_no_hof_bonus
			desc = COURT_CHAPLAIN_CONVERSION_GHW_TENET_NO_HOF_MODIFIER
		}
	}
	### Chthonic Redoubts
	if = {
		limit = {
			exists = scope:county
			scope:councillor.rite ?= { rite_has_parameter = easier_to_convert_faith_in_mountains }
			scope:county = {
				# We check any province and not just title province, to be generous.
				county_has_province_with_terrain = {
					terrain = mountains
					terrain = desert_mountains
				}
			}
		}
		add = {
			value = scope:councillor.easier_to_convert_faith_in_mountains_bonus
			desc = COURT_CHAPLAIN_CONVERSION_EASIER_TO_CONVERT_FAITH_IN_MOUNTAINS_BONUS_MODIFIER
		}
	}
	## Maluses
	### Chthonic Redoubts
	if = {
		limit = {
			exists = scope:county
			scope:county = {
				rite ?= { rite_has_parameter = harder_to_convert_faith_away_in_mountains }
				# We check any province and not just title province, to be generous.
				county_has_province_with_terrain = {
					terrain = mountains
					terrain = desert_mountains
				}
			}
		}
		add = {
			value = scope:councillor.harder_to_convert_faith_away_in_mountains_malus
			desc = COURT_CHAPLAIN_CONVERSION_HARDER_TO_CONVERT_FAITH_AWAY_IN_MOUNTAINS_MALUS_MODIFIER
		}
	}
	### Syncretics
	#### Syncretic tenets aim to allow a faith and a separate religion/family to coexist without one eating the other. Accordingly, we make it harder for you to syncretise with a faith *then* wipe it out.
	if = {
		limit = {
			exists = scope:county.faith
			scope:county.faith != scope:councillor.faith
			scope:councillor.faith ?= { faith_is_syncretic_with = { FAITH = scope:county.faith } }
		}
		add = {
			value = scope:councillor.conversion_syncretic_with_religion_malus
			desc = COURT_CHAPLAIN_CONVERSION_SYNCRETIC_WITH_RELIGION_MODIFIER
		}
	}

	#Various Modifier Penalties
	if = {
		limit = {
			exists = scope:county
			scope:county = { has_county_modifier = tougher_to_convert }
		}
		add = {
			value = -0.25
			desc = COURT_CHAPLAIN_CONVERSION_LOCAL_COUNTY_MODIFIERS
		}
	}
	if = {
		limit = {
			exists = scope:county
			scope:county = { has_county_modifier = easier_to_convert }
		}
		add = {
			value = 0.25
			desc = COURT_CHAPLAIN_CONVERSION_LOCAL_COUNTY_MODIFIERS
		}
	}
	if = {
		limit = {
			exists = scope:county
			scope:county = { has_county_modifier = governance_1074_local_faith_respected_modifier }
		}
		add = {
			value = scope:councillor.local_faith_respected_modifier_value
			desc = COURT_CHAPLAIN_CONVERSION_LOCAL_COUNTY_MODIFIERS
		}
	}
	if = {
		limit = {
			exists = scope:county
			scope:county = { has_county_modifier = governance_1074_population_fled_persecution_modifier }
		}
		add = {
			value = scope:councillor.population_fled_persecution_modifier_value
			desc = COURT_CHAPLAIN_CONVERSION_LOCAL_COUNTY_MODIFIERS
		}
	}
	if = {
		limit = {
			scope:councillor.liege = {
				OR = {
					has_character_modifier = defiant_high_king_conversion_boost_modifier
					has_character_modifier = defiant_high_queen_conversion_boost_modifier
				}
				religion = religion:germanic_religion
			}
			scope:county.faith ?= {
				NOT = { has_doctrine_parameter = unreformed }
			}
		}
		add = {
			value = scope:councillor.defiant_high_monarch_conversion_boost_value
			desc = COURT_CHAPLAIN_CONVERSION_LIEGE_IS_DEFIANT_HIGH_MONARCH
		}
	}
	if = {
		limit = {
			exists = scope:county
			scope:county = { has_county_modifier = court_6090_almoners_county_modifier }
		}
		add = {
			value = scope:councillor.court_6090_almoners_modifier_value
			desc = COURT_CHAPLAIN_CONVERSION_LOCAL_COUNTY_MODIFIERS
		}
	}
	if = {
		limit = {
			exists = scope:county
			scope:county = { has_county_modifier = hold_court_8200_vassal_modifier }
		}
		add = {
			value = scope:councillor.court_8200_vassal_modifier_value
			desc = COURT_CHAPLAIN_CONVERSION_LOCAL_COUNTY_MODIFIERS
		}
	}	
	if = {
		limit = {
			scope:county ?= { has_county_modifier = petition_liege_county_convert_modifier }
		}
		add = {
			value = scope:councillor.petition_liege_county_convert_modifier_value
			desc = COURT_CHAPLAIN_CONVERSION_LOCAL_COUNTY_MODIFIERS
		}
	}
	if = {
		limit = {
			scope:county ?= { has_county_modifier = pam_cardinal_order_convert_faith_modifier }
		}
		add = {
			value = cardinal_order_convert_faith
			desc = pam_cardinal_order_convert_faith_modifier
		}
	}
	#Baptistery domicile buildings, evaluated from the councillor doing the task
	add = {
		value = scope:councillor.estate_increase_conversion_speed
		desc = estate_increase_conversion_speed_desc
	}

	#Conversion bonuses from certain Holy Sites.
	if = {
		limit = {
			scope:councillor.faith ?= {
				controls_holy_site_with_parameter = jerusalem_conversion_bonus
			}
			title:b_jerusalem = {
				is_holy_site_of = scope:councillor.faith
			}
		}
		add = {
			value = scope:councillor.conversion_holy_site_jerusalem
			desc = COURT_CHAPLAIN_CONVERSION_HOLY_SITE_JERUSALEM
		}
	}
	if = {
		limit = {
			scope:councillor.faith ?= {
				controls_holy_site_with_parameter = kerala_conversion_bonus
			}
			title:b_mahoyadapuram = {
				is_holy_site_of = scope:councillor.faith
			}
		}
		add = {
			value = scope:councillor.conversion_holy_site_kerala
			desc = COURT_CHAPLAIN_CONVERSION_HOLY_SITE_KERALA
		}
	}
	if = {
		limit = {
			exists = scope:county
			scope:councillor.faith ?= {
				controls_holy_site_with_parameter = iona_conversion_bonus
			}
			title:b_islay = {
				is_holy_site_of = scope:councillor.faith
			}
			scope:county.title_province = {
				geographical_region = world_europe_west_britannia
			}
		}
		add = {
			value = scope:councillor.conversion_holy_site_iona
			desc = COURT_CHAPLAIN_CONVERSION_HOLY_SITE_IONA
		}
	}
	if = {
		limit = {
			exists = scope:county
			scope:county.faith ?= {
				controls_holy_site_with_parameter = wadi_el_milk_conversion_resistance_bonus
			}
			title:b_wadi_el-milk = {
				is_holy_site_of = scope:councillor.faith
			}
		}
		add = {
			value = scope:councillor.conversion_holy_site_wadi_el_milk
			desc = COURT_CHAPLAIN_CONVERSION_HOLY_SITE_WADI_EL_MILK
		}
	}
	if = {
		limit = {
			scope:councillor.faith ?= {
				controls_holy_site_with_parameter = cordoba_conversion_bonus
			}
			title:b_cordoba = {
				is_holy_site_of = scope:councillor.faith
			}
		}
		add = {
			value = scope:councillor.conversion_holy_site_cordoba
			desc = COURT_CHAPLAIN_CONVERSION_HOLY_SITE_CORDOBA
		}
	}
	if = {
		limit = {
			scope:councillor.faith ?= {
				controls_holy_site_with_parameter = geneva_conversion_bonus
			}
			title:b_geneva = {
				is_holy_site_of = scope:councillor.faith
			}
		}
		add = {
			value = scope:councillor.conversion_holy_site_geneva
			desc = COURT_CHAPLAIN_CONVERSION_HOLY_SITE_GENEVA
		}
	}
	if = {
		limit = {
			exists = scope:county
			scope:county.faith ?= {
				controls_holy_site_with_parameter = visoki_conversion_resistance_bonus
			}
			title:b_visoki = {
				is_holy_site_of = scope:councillor.faith
			}
		}
		add = {
			value = scope:councillor.conversion_holy_site_visoki
			desc = COURT_CHAPLAIN_CONVERSION_HOLY_SITE_VISOKI
		}
	}

	#Tradition modifiers
	if = {
		limit = {
			exists = scope:county
			scope:county.culture ?= {
				has_cultural_parameter = more_easily_converted
			}
		}
		add = {
			value = conversion_culture_more_easily_converted
			desc = TRADITION_RELIGION_BLENDING_CONVERSION_MODIFIER
		}
	}
	if = {
		limit = {
			exists = scope:county
			scope:county.culture ?= {
				has_cultural_parameter = harder_to_convert_county_faith
			}
		}
		add = {
			value = conversion_culture_harder_to_convert
			desc = TRADITION_HARDER_TO_CONVERT_CONVERSION_MODIFIER
		}
	}

	# Struggle Bonuses/Penalties
	## Boost conversion in some phases.
#	if = {
#		limit = {
#			exists = scope:county
#			scope:county = {
#				any_county_struggle = { has_struggle_phase_parameter = county_faith_conversion_in_region_proceeds_faster }
#			}
#		}
#		add = {
#			value = scope:councillor.boost_county_conversion_phase_bonus_value
#			desc = CHAPLAIN_CONVERT_COUNTY_STRUGGLE_BONUS
#		}
#	}
#	## Reduce it in others.
#	if = {
#		limit = {
#			exists = scope:county
#			scope:county = {
#				any_county_struggle = {
#					has_struggle_phase_parameter = county_faith_conversion_in_region_proceeds_slower
#				}
#			}
#		}
#		add = {
#			value = scope:councillor.boost_county_conversion_phase_malus_value
#			desc = CHAPLAIN_CONVERT_COUNTY_STRUGGLE_PENALTY
#		}
#	}

	# FP3 ending
	if = {
		limit = {
			exists = global_var:fp3_struggle_ending
			global_var:fp3_struggle_ending = flag:fp3_struggle_shia_caliphate_ending
			scope:councillor.rite ?= {
				rite_has_doctrine = muhammad_succession_shia_doctrine
			}
		}
		add = {
			value = scope:councillor.court_chaplain_shia_promotion
			desc = CONVERSION_FP3_STRUGGLE_ENDING_BONUS
		}
	}
	else_if = {
		limit = {
			exists = global_var:fp3_struggle_ending
			global_var:fp3_struggle_ending = flag:fp3_struggle_strengthen_caliphate_ending
			scope:councillor.rite ?= {
				rite_has_doctrine = muhammad_succession_sunni_doctrine
			}
		}
		add = {
			value = scope:councillor.court_chaplain_sunni_promotion
			desc = CONVERSION_FP3_STRUGGLE_ENDING_BONUS
		}
	}

	#Other
	if = {
		limit = {
			scope:councillor.liege = {
				has_trait = savior
			}
		}
		add = {
			value = scope:councillor.conversion_savior_liege
			desc = COURT_CHAPLAIN_CONVERSION_LIEGE_IS_SAVIOR
		}
	}
	if = {
		limit = {
			scope:councillor.liege = {
				has_trait = divine_blood
			}
		}
		add = {
			value = scope:councillor.conversion_divine_blood_liege
			desc = COURT_CHAPLAIN_CONVERSION_LIEGE_IS_DIVINE_BLOOD
		}
	}
	if = {
		limit = {
			scope:councillor.liege = {
				has_personal_tenet_flag = tenet_literalism_scholar_conversion
				has_trait = lifestyle_scholar
			}
		}
		add = {
			value = scope:councillor.conversion_literalism_scholar_liege
			desc = COURT_CHAPLAIN_CONVERSION_LIEGE_IS_LITERALIST_SCHOLAR
		}
	}
	if = {
		limit = {
			scope:councillor.liege = {
				has_personal_tenet_flag = tenet_monophysitism_conversion_conviction
			}
			exists = scope:county.faith
			NOT = { scope:county.faith = scope:councillor.liege.faith }
			scope:county.faith.religion = scope:councillor.liege.faith.religion
		}
		add = {
			value = scope:councillor.conversion_monophysite_conviction_liege
			desc = COURT_CHAPLAIN_CONVERSION_LIEGE_IS_MONOPHYSITE_CONVICTION
		}
	}
	if = {
		limit = {
			exists = scope:county
			scope:county = {
				has_variable = learning_encouraged_conversion
			}
		}
		add = {
			value = scope:councillor.conversion_learning_theology
			desc = COURT_CHAPLAIN_CONVERSION_LEARNING_THEOLOGY
		}
	}
	#Foreign-raised reformer is enforcing uniform faith
	if = {
		limit = {
			scope:councillor.liege = {
				has_character_flag = reformer_conversion
			}
		}
		add = {
			value = scope:councillor.court_chaplain_conversion_monthly_increase_perk_bonus
			desc = CONVERSION_REFORMER_BONUS_VALUE
		}
	}
	if = {
		limit = {
			exists = scope:county
			scope:county = {
				has_county_modifier = internal_affairs_county_religious_tensions_modifier
			}
		}
		add = {
			value = -0.2
			desc = RELIGIOUS_TENSIONS_DESC
		}
	}
	if = {
		limit = {
			exists = scope:county
			scope:county = {
				has_county_modifier = internal_affairs_county_religious_tolerance_modifier
			}
		}
		add = {
			value = -0.1
			desc = RELIGIOUS_TOLERANCE_DESC
		}
	}

	# Faster conversion for certain special doctrines
	if = {
		limit = {
			scope:councillor_liege.faith ?= { has_doctrine_parameter = adoptionists_attractively_intuitive_theology }
			exists = scope:county
			scope:county.faith.religion = religion:christianity_religion
		}
		add = {
			value = fp2_lyonese_monk_conversion_bonus_actual_value
			desc = fp2_lyonese_monk_faith_conversion_task_desc
		}
	}
}

court_chaplain_conversion_factors = {
	value = 1
	if = {
		limit = {
			scope:councillor.faith ?= {
				has_doctrine_parameter = unreformed
			}
		}
		multiply = {
			value = conversion_unreformed_faith_penalty
			desc = COURT_CHAPLAIN_CONVERSION_UNREFORMED_FAITH_PENALTY
		}
	}

	# Off-rite Chaplain: applies on every path (faith and rite) when the Chaplain's rite differs from the Liege's.
	if = {
		limit = {
			scope:councillor.rite != scope:councillor_liege.rite
		}
		multiply = {
			value = chaplain_off_rite_conversion_penalty
			desc = COURT_CHAPLAIN_CONVERSION_OFF_RITE_CHAPLAIN_PENALTY
		}
	}

	# Additive fervor is 0 on same faith
	if = {
		limit = {
			exists = scope:county
			exists = scope:councillor.faith
			exists = scope:councillor_liege.faith
			exists = scope:county.faith
			OR = {
				scope:county.faith = scope:councillor_liege.faith
				scope:county.faith = scope:councillor.faith
			}
		}
		multiply = {
			value = rite_conversion_fervor_mult
			desc = COURT_CHAPLAIN_CONVERSION_RITE_FERVOR_IMPACT
		}
	}
	
	# Faster conversion for FP2 Hostility ending, if county is in Iberia and faith was involved
	if = {
		limit = {
			exists = scope:councillor.liege.house
			scope:councillor.liege.house = {
				OR = {
					has_house_modifier = fp2_struggle_hostility_house_faith_modifier
					has_house_modifier = fp2_struggle_hostility_house_combined_modifier
				}
			}
			any_in_global_list = {
				variable = fp2_struggle_ending_faith_list
				this = scope:county.faith
			}
			scope:county.title_province = { geographical_region = world_europe_west_iberia }
		}
		multiply = {
			value = fp2_struggle_hostility_conversion_value
			desc = fp2_struggle_hostility_faith_conversion_task_desc
		}
	}
	# Faster conversion of infidels for FP2 Council Toledo Conversion
	if = {
		limit = {
			scope:councillor.liege = { has_character_modifier = fp2_council_conversion_modifier }
			scope:county.religion != scope:councillor.liege.religion
		}
		multiply = {
			value = council_toledo_conversion_modifier_value
			desc = council_toledo_conversion_task_desc
		}
	}
	# Faster conversion of heretics for FP2 Council Toledo Heresies
	if = {
		limit = {
			scope:councillor.liege = { has_character_modifier = fp2_council_conversion_modifier }
			scope:county.rite != rite:mozarabic_church
			scope:county.faith ?= {
				religion = scope:councillor.liege.religion
				NOT = { exists = religious_head }
			}
		}
		multiply = {
			value = council_toledo_conversion_modifier_value
			desc = council_toledo_heresies_task_desc
		}
	}

	# Faster conversion of Persian counties with the FP3 Promote Persian Scripture decision
	if = {
		limit = {
			scope:councillor.liege = { 
				has_character_modifier = fp3_promoted_persian_scripture_modifier 
				is_ai = no #this is so that we don't get AI converting and homogenizing Persia too quickly
			}
			scope:county.culture ?= { has_cultural_pillar = heritage_iranian }
		}
		multiply = {
			value = promote_persian_scripture_conversion_modifier_value
			desc = fp3_promote_persian_scripture_task_desc
		}
	}

	# FP3 faster conversion struggle ending rewards
	if = {
		limit = {
			exists = global_var:fp3_struggle_ending_assertion_school
			switch = {
				trigger = global_var:fp3_struggle_ending_assertion_school
				flag:sunni = {
					scope:councillor.liege.rite ?= { rite_has_doctrine = muhammad_succession_sunni_doctrine }
				}
				flag:shia = {
					scope:councillor.liege.rite ?= { rite_has_doctrine = muhammad_succession_shia_doctrine }
				}
				flag:muhakkima = {
					scope:councillor.liege.rite ?= { rite_has_doctrine = muhammad_succession_muhakkima_doctrine }
				}
				flag:zandaqa = {
					scope:councillor.liege.rite ?= { rite_has_doctrine = muhammad_succession_zandaqa_doctrine }
				}
			}
		}
		multiply = {
			value = fp3_struggle_ending_conversion_modifier_value
			desc = fp3_struggle_ending_conversion_modifier_desc
		}
	}
	# Court events
	if = {	#court.6010
		limit = {
			scope:councillor.liege = {
				var:6010_harsh_conversion ?= scope:county.faith
			}
		}
		multiply = {
			value = 1.2
			desc = court_6010_harsh_conversions
		}
	}
	if = {	#court.6010
		limit = {
			scope:councillor.liege = {
				var:6010_tolerant_conversion ?= scope:county.faith
			}
		}
		multiply = {
			value = 0.8
			desc = court_6010_tolerant_conversions
		}
	}
	#If someone has done some buddhist teaching in this province
	if = {
		limit = {
			scope:county ?= {
				has_county_modifier = buddhist_teachings_conversion_modifier
			}
			scope:councillor.liege.religion = religion:buddhism_religion 
		}
		multiply = {
			value = 2
			desc = buddhist_teachings_conversion_modifier
		}
	}
	# State Rite Boost
	if = {
		limit = {
			scope:councillor.top_liege.primary_title.state_rite ?= {
				this != scope:county.rite
				this = scope:councillor.top_liege.rite
			}
		}
		multiply = {
			value = ep3_state_faith_conversion_mult_value
			desc = ep3_convert_county_to_state_faith
		}
	}

	# The Christian Church situation bonus
	if = {
		limit = {
			scope:councillor_liege = {
				top_participant_group:the_christian_church ?= {
					has_participant_group_parameter = the_christian_church_county_conversion_bonus
				}
			}
		}
		multiply = {
			value = pam_the_christian_church_county_conversion_bonus_value
			desc = pam_the_christian_church_county_conversion_bonus_desc
		}
	}
	
	# The Christian Church situation malus
	if = {
		limit = {
			scope:councillor_liege = {
				top_participant_group:the_christian_church ?= {
					has_participant_group_parameter = the_christian_church_county_conversion_malus
				}
			}
		}
		multiply = {
			value = pam_the_christian_church_county_conversion_malus_value
			desc = pam_the_christian_church_county_conversion_bonus_desc # Intentional, it just states the phase name
		}
	}

	# Conversion speed game rules
	if = {
		limit = {
			has_game_rule = slower_faith_conversion_speed
		}
		multiply = {
			value = slower_game_rule_value
			desc = GAME_RULE_SLOWER_REASON
		}
	}
	else_if = {
		limit = {
			has_game_rule = significantly_slower_faith_conversion_speed
		}
		multiply = {
			value = significantly_slower_game_rule_value
			desc = GAME_RULE_SIGNIFICANTLY_SLOWER_REASON
		}
	}
	else_if = {
		limit = {
			has_game_rule = faster_faith_conversion_speed
		}
		multiply = {
			value = faster_game_rule_value
			desc = GAME_RULE_FASTER_REASON
		}
	}
	else_if = {
		limit = {
			has_game_rule = significantly_faster_faith_conversion_speed
		}
		multiply = {
			value = significantly_faster_game_rule_value
			desc = GAME_RULE_SIGNIFICANTLY_FASTER_REASON
		}
	}
}

convert_faith_fervor_modifier_scale = 0.5 # Fervor causes the conversion speed to scale from 150% to 50% of base.

chaplain_off_rite_conversion_penalty = 0.5 # task_conversion slowdown when the Chaplain's rite differs from the Liege's; applies on every path.

# We only use this when the faiths already match
# Young rites without clerical regions never convert slower than normal
rite_conversion_fervor_mult = {
	value = 1
	if = {
		limit = {
			OR = {
				scope:councillor_liege = {
					highest_held_title_tier >= tier_hegemony
					government_has_flag = government_has_merit
				}
				scope:county.faith = scope:councillor_liege.faith
			}
		}
		if = {
			limit = {
				scope:councillor_liege = { rite = faith.main_rite }
			}
			add = {
				value = scope:councillor_liege.faith.fervor
				subtract = 50
				divide = 100
			}
		}
		else = {
			subtract = {
				value = scope:councillor_liege.faith.fervor
				subtract = 50
				divide = 100
			}
			if = {
				limit = {
					scope:councillor_liege.rite ?= { has_variable = pam_rite_grace_period }
				}
				min = 1
			}
		}
	}
	else = {
		if = {
			limit = {
				scope:councillor = { rite = faith.main_rite }
			}
			add = {
				value = scope:councillor.faith.fervor
				subtract = 50
				divide = 100
			}
		}
		else = {
			subtract = {
				value = scope:councillor.faith.fervor
				subtract = 50
				divide = 100
			}
			if = {
				limit = {
					scope:councillor.rite ?= { has_variable = pam_rite_grace_period }
				}
				min = 1
			}
		}
	}
}

# Development penalty
convert_faith_development_penalty = {
	value = 0
	if = {
		limit = { exists = scope:county }
		add = scope:councillor.court_chaplain_conversion_base
		add = scope:councillor.court_chaplain_conversion_monthly_increase
		add = scope:councillor.court_chaplain_conversion_monthly_increase_perk_bonus
		add = {
			add = {
				add = scope:councillor.court_chaplain_progress_percentage
				multiply = scope:councillor.faith.fervor
			}
			subtract = {
				add = scope:councillor.court_chaplain_progress_percentage
				multiply = scope:county.faith.fervor
			}
			if = {
				limit = {
					scope:councillor_liege = { has_perk = religious_icon_perk }
				}
				min = 0
			}
		}
		add = scope:councillor.court_chaplain_conversion_contextual_bonuses
		multiply = {
			subtract = scope:county.development_level
			divide = 100
			min = -0.9
		}
	}
}

# Zealous Proselytizer bonus
court_chaplain_conversion_monthly_increase_perk_bonus = {
	if = {
		limit = {
			OR = {
				scope:councillor_liege = { has_perk = zealous_proselytizer_perk }
				#Foreign-raised reformer uses same value
				scope:councillor_liege = { has_character_flag = reformer_conversion }
			}
		}
		add = court_chaplain_conversion_base_total
		multiply = {
			add = zealous_proselytizer_percentage
			divide = 100
		}
	}
}

# Bureaucrats bonus
court_chaplain_conversion_monthly_increase_dynasty_perk_bonus = {
	add = court_chaplain_conversion_base_total
	multiply = {
		add = erudition_legacy_5_percentage
		divide = 100
	}
}

court_chaplain_conversion_monthly_increase_family_business_bonus = {
	add = court_chaplain_conversion_base_total
	multiply = {
		add = family_business_councillors_percentage
		divide = 100
	}
}

court_chaplain_conversion_monthly_increase_consulted_house_bonus = {
	add = court_chaplain_conversion_base_total
	multiply = {
		add = consulted_house_councillors_percentage
		divide = 100
	}
}

# Friend Bonus
court_chaplain_conversion_monthly_increase_friend_bonus = {
	add = court_chaplain_conversion_base_total
	multiply = {
		add = council_friend_impact_percentage
		divide = 100
	}
}

# Best Friend Bonus
court_chaplain_conversion_monthly_increase_best_friend_bonus = {
	add = court_chaplain_conversion_base_total
	multiply = {
		add = council_best_friend_impact_percentage
		divide = 100
	}
}

# Rival Penalty
court_chaplain_conversion_monthly_increase_rival_bonus = {
	add = court_chaplain_conversion_base_total
	multiply = {
		add = council_rival_impact_percentage
		divide = 100
	}
}

# Nemesis Penalty
court_chaplain_conversion_monthly_increase_nemesis_bonus = {
	add = court_chaplain_conversion_base_total
	multiply = {
		add = council_nemesis_impact_percentage
		divide = 100
	}
}

# Convert "full" percentage value to 0-1 scale
court_chaplain_progress_percentage = {
	add = court_chaplain_conversion_base_total
	divide = 100
}

#### Various Doctrine bonuses and penalties
conversion_fundamentalist_faith_bonus = {
	if = {
		limit = {
			scope:councillor.rite ?= {
				rite_has_parameter = pluralism_fundamentalist_proselytization_bonus
			}
		}
		value = court_chaplain_conversion_base_total
		multiply = 0.2
	}
}

conversion_pluralistic_faith_penalty = {
	value = 0
	if = {
		limit = {
			scope:councillor.rite ?= {
				rite_has_parameter = pluralism_pluralistic_proselytization_penalty
			}
		}
		subtract = court_chaplain_conversion_base_total
		multiply = 0.2
	}
}

conversion_unreformed_faith_penalty = 0.3

conversion_false_conversion_sanction_resistance = {
	value = 0
	if = {
		limit = {
			exists = scope:county
			scope:county.rite ?= {
				rite_has_parameter = sanctioned_false_conversion_county_resistance
			}
		}
		subtract = court_chaplain_conversion_base_total
		multiply = 0.3
	}
}

conversion_reincarnation_resistance = {
	value = 0
	if = {
		limit = {
			exists = scope:county
			scope:county.rite ?= {
				rite_has_parameter = reincarnation_resistance_to_conversion
			}
		}
		subtract = court_chaplain_conversion_base_total
		multiply = 0.2
	}
}

# Same shared parameter as above, kept separate so the conversion breakdown can credit Dharmic Pacifism.
conversion_dharmic_pacifism_resistance = {
	value = conversion_reincarnation_resistance
}

conversion_adaptive_resistance = {
	value = 0
	if = {
		limit = {
			exists = scope:county
			scope:county.rite ?= {
				rite_has_parameter = tenet_adaptive_conversion_resistance
			}
		}
		subtract = court_chaplain_conversion_base_total
		multiply = 0.3
	}
}

conversion_culture_harder_to_convert = {
	value = 0
	if = {
		limit = {
			exists = scope:county
			scope:county.culture ?= {
				has_cultural_parameter = harder_to_convert_county_faith
			}
		}
		subtract = court_chaplain_conversion_base_total
		multiply = 0.3
	}
}

conversion_culture_more_easily_converted = {
	value = 0
	if = {
		limit = {
			exists = scope:county
			scope:county.culture ?= {
				has_cultural_parameter = more_easily_converted
			}
		}
		add = court_chaplain_conversion_base_total
		multiply = 0.3
	}
}

# Twin of conversion_false_conversion_sanction_resistance for breakdown credit
conversion_pastoral_isolation_resistance = {
	value = conversion_false_conversion_sanction_resistance
}

conversion_pure_land_resistance = {
	value = conversion_false_conversion_sanction_resistance
}

conversion_communal_identity_resistance = {
	value = 0
	if = {
		limit = {
			scope:councillor.rite ?= { rite_has_parameter = other_culture_conversion_penalty_active }
			scope:county.culture != scope:councillor.liege.culture
		}
		subtract = court_chaplain_conversion_base_total
		multiply = 0.5
	}
}

conversion_mendicant_preachers_bonus = {
	value = 0
	if = {
		limit = {
			scope:councillor.rite ?= {
				rite_has_parameter = mendicant_preachers_conversion_active
			}
		}
		add = court_chaplain_conversion_base_total
		multiply = 0.33
	}
}

conversion_alexandrian_catechism_bonus = {
	value = 0
	if = {
		limit = {
			scope:councillor_liege ?= {
				has_personal_tenet_flag = tenet_alexandrian_catechism_catechesis_conversion
			}
		}
		add = court_chaplain_conversion_base_total
		multiply = 0.25
	}
}

conversion_communal_identity_bonus = {
	value = 0
	if = {
		limit = {
			exists = scope:county
			scope:councillor.rite ?= {
				rite_has_parameter = same_culture_conversion_bonus_active
			}
			scope:county.culture = scope:councillor.liege.culture
		}
		add = court_chaplain_conversion_base_total
		multiply = 0.50
	}
}

conversion_communal_identity_penalty = {
	value = 0
	subtract = court_chaplain_conversion_base_total
	multiply = 0.50
}

conversion_ghw_tenet_multiplier_control = {
	#Tweak this to control how much of a speed bonus per controlled holy site is given.
	value = 0.25
}

conversion_ghw_tenet_no_hof_bonus = {
	value = 1
	#add = court_chaplain_conversion_base_total
	if = {
		limit = {
			faith ?= { holy_sites_controlled = 1 }
		}
		multiply = conversion_ghw_tenet_multiplier_control
	}
	else_if = {
		limit = {
			faith ?= { holy_sites_controlled = 2 }
		}
		multiply = {
			value = conversion_ghw_tenet_multiplier_control
			multiply = 2
		}
	}
	else_if = {
		limit = {
			faith ?= { holy_sites_controlled = 3 }
		}
		multiply = {
			value = conversion_ghw_tenet_multiplier_control
			multiply = 3
		}
	}
	else_if = {
		limit = {
			faith ?= { holy_sites_controlled = 4 }
		}
		multiply = {
			value = conversion_ghw_tenet_multiplier_control
			multiply = 4
		}
	}
	else_if = {
		limit = {
			faith ?= { holy_sites_controlled = 5 }
		}
		multiply = {
			value = conversion_ghw_tenet_multiplier_control
			multiply = 5
		}
	}
	else_if = {
		limit = {
			faith ?= { holy_sites_controlled = 6 }
		}
		multiply = {
			value = conversion_ghw_tenet_multiplier_control
			multiply = 6
		}
	}
	else_if = {
		limit = {
			faith ?= { holy_sites_controlled = 7 }
		}
		multiply = {
			value = conversion_ghw_tenet_multiplier_control
			multiply = 7
		}
	}
	else_if = {
		limit = {
			faith ?= { holy_sites_controlled = 8 }
		}
		multiply = {
			value = conversion_ghw_tenet_multiplier_control
			multiply = 8
		}
	}
	else_if = {
		limit = {
			faith ?= { holy_sites_controlled = 9 }
		}
		multiply = {
			value = conversion_ghw_tenet_multiplier_control
			multiply = 9
		}
	}
	else_if = {
		limit = {
			faith ?= { holy_sites_controlled >= 10 }
		}
		multiply = {
			value = conversion_ghw_tenet_multiplier_control
			multiply = 10
		}
	}
	#Not that you should ever really have ten holy sites, but just in case.
}

easier_to_convert_faith_in_mountains_bonus_root_value = 0.5

easier_to_convert_faith_in_mountains_bonus_loc_control = {
	value = easier_to_convert_faith_in_mountains_bonus_root_value
	multiply = 100
}

easier_to_convert_faith_in_mountains_bonus = {
	value = court_chaplain_conversion_base_total
	multiply = easier_to_convert_faith_in_mountains_bonus_root_value
}

harder_to_convert_faith_away_in_mountains_malus_root_value = -0.75

harder_to_convert_faith_away_in_mountains_malus_loc_control = {
	value = harder_to_convert_faith_away_in_mountains_malus_root_value
	multiply = 100
}

harder_to_convert_faith_away_in_mountains_malus = {
	value = court_chaplain_conversion_base_total
	multiply = harder_to_convert_faith_away_in_mountains_malus_root_value
}

### Syncretism Penalties
conversion_syncretic_with_religion_malus = {
	value = 0
	subtract = court_chaplain_conversion_base_total
	multiply = conversion_syncretic_with_religion_malus_efficancy_procentage 
}

conversion_syncretic_with_religion_malus_efficancy_procentage = {
	value = 1
	subtract = 0.25
}

### Various Modifier Penalties
local_faith_respected_modifier_value = {
	value = 0
	subtract = court_chaplain_conversion_base_total
	multiply = 0.15
}

### Various Modifier Bonuses
population_fled_persecution_modifier_value = {
	value = 0
	add = court_chaplain_conversion_base_total
	multiply = 0.15
}

court_6090_almoners_modifier_value = {
	value = 0
	add = court_chaplain_conversion_base_total
	multiply = 0.10
}

### Various Holy Site bonuses
conversion_holy_site_jerusalem = {
	value = 0
	if = {
		limit = {
			scope:councillor.faith ?= {
				controls_holy_site_with_parameter = jerusalem_conversion_bonus
			}
		}
		add = court_chaplain_conversion_base_total
		multiply = 0.20
	}
}

conversion_holy_site_kerala = {
	value = 0
	if = {
		limit = {
			scope:councillor.faith ?= {
				controls_holy_site_with_parameter = kerala_conversion_bonus
			}
		}
		add = court_chaplain_conversion_base_total
		multiply = 0.50
	}
}

conversion_holy_site_iona = {
	value = 0
	if = {
		limit = {
			scope:councillor.faith ?= {
				controls_holy_site_with_parameter = iona_conversion_bonus
			}
		}
		add = court_chaplain_conversion_base_total
		multiply = 0.30
	}
}

conversion_holy_site_visoki = {
	value = 0
	if = {
		limit = {
			scope:councillor.faith ?= {
				controls_holy_site_with_parameter = visoki_conversion_resistance_bonus
			}
		}
		add = court_chaplain_conversion_base_total
		multiply = -0.50
	}
}

conversion_holy_site_wadi_el_milk = {
	value = 0
	if = {
		limit = {
			scope:councillor.faith ?= {
				controls_holy_site_with_parameter = wadi_el_milk_conversion_resistance_bonus
			}
		}
		add = court_chaplain_conversion_base_total
		multiply = -0.50
	}
}

conversion_holy_site_cordoba = {
	value = 0
	if = {
		limit = {
			scope:councillor.faith ?= {
				controls_holy_site_with_parameter = cordoba_conversion_bonus
			}
		}
		add = court_chaplain_conversion_base_total
		multiply = 0.20
	}
}

conversion_holy_site_geneva = {
	value = 0
	if = {
		limit = {
			scope:councillor.faith ?= {
				controls_holy_site_with_parameter = geneva_conversion_bonus
			}
		}
		add = court_chaplain_conversion_base_total
		multiply = -0.30
	}
}

### Various trait bonuses
conversion_savior_liege = {
	if = {
		limit = {
			scope:councillor.liege = {
				has_trait = savior
			}
		}
		value = court_chaplain_conversion_base_total
		multiply = 0.75
	}
}

conversion_divine_blood_liege = {
	if = {
		limit = {
			scope:councillor.liege = {
				has_trait = divine_blood
			}
		}
		value = court_chaplain_conversion_base_total
		multiply = 0.25
	}
}

conversion_monophysite_conviction_liege = {
	if = {
		limit = {
			scope:councillor.liege = {
				has_personal_tenet_flag = tenet_monophysitism_conversion_conviction
			}
			exists = scope:county.faith
			NOT = { scope:county.faith = scope:councillor.liege.faith }
			scope:county.faith.religion = scope:councillor.liege.faith.religion
		}
		value = court_chaplain_conversion_base_total
		multiply = 0.25
	}
}

conversion_literalism_scholar_liege = {
	if = {
		limit = {
			scope:councillor.liege = {
				has_personal_tenet_flag = tenet_literalism_scholar_conversion
				has_trait = lifestyle_scholar
			}
		}
		value = court_chaplain_conversion_base_total
		multiply = 0.25
	}
}

conversion_learning_theology = {
	if = {
		limit = {
			exists = scope:county
			scope:county = {
				has_variable = learning_encouraged_conversion
			}
		}
		value = court_chaplain_conversion_base_total
		multiply = 0.25
	}
}

##### Learn on the Job Skill bonus for Liege
court_chaplain_learn_on_the_job_scale = {
	value = 0
	if = {
		limit = {
			liege ?= { has_perk = learn_on_the_job_perk }
		}
		add = learning
		multiply = {
			add = learn_on_the_job_percentage
			divide = 100
		}
		floor = yes
		min = 1
	}
}

##### Kurultai Learn on the Job Skill bonus for Liege
kurultai_court_chaplain_learn_on_the_job_scale = {
	value = 0
	if = {
		limit = {
			liege ?= { has_perk = learn_on_the_job_perk }
			highest_skill = learning
		}
		add = learning
		multiply = {
			add = learn_on_the_job_percentage
			divide = 100
		}
		floor = yes
		min = 1
	}
}

### Reliable House modifier
court_chaplain_reliable_house_scale = {
	value = 0
	if = {
		limit = {
			exists = liege.dynasty
			liege.dynasty = { has_dynasty_perk = fp2_coterie_legacy_2 }
			house = liege.house
		}
		add = learning
		multiply = {
			add = council_reliable_house_percentage
			divide = 100
		}
		floor = yes
		min = 1
	}
}


### FP3 Struggle Ending
court_chaplain_sunni_promotion = {
	if = {
		limit = {
			exists = global_var:fp3_struggle_ending
			global_var:fp3_struggle_ending = flag:fp3_struggle_strengthen_caliphate_ending
			rite ?= {
				rite_has_doctrine = muhammad_succession_sunni_doctrine
			}
		}
		value = court_chaplain_conversion_base_total
		multiply = 0.5
		floor = yes
		min = 1
	}
}

court_chaplain_shia_promotion = {
	if = {
		limit = {
			exists = global_var:fp3_struggle_ending
			global_var:fp3_struggle_ending = flag:fp3_struggle_shia_caliphate_ending
			rite ?= {
				rite_has_doctrine = muhammad_succession_shia_doctrine
			}
		}
		value = court_chaplain_conversion_base_total
		multiply = 0.5
		floor = yes
		min = 1
	}
}

#Cardinal Order bonus 
cardinal_order_convert_faith ?= {
	if = {
		limit = {
			scope:county ?= {
				has_county_modifier = pam_cardinal_order_convert_faith_modifier
			}
		}
		value = court_chaplain_conversion_base_total
		multiply = 0.25
	}
}


#Read as scope:councillor.estate_increase_conversion_speed, so relatives resolve from the councillor
estate_increase_conversion_speed = {
	value = 0
	if = {
		limit = {
			OR = {
				#Does the archbishopric they reside in have a baptistery?
				liege.capital_county.clerical_region_title.holder ?= {
					domicile ?= {
						has_domicile_parameter = estate_increase_conversion_speed_3
					}
					rite = scope:councillor.rite
				}
				#Does their liege have a baptistery?
				liege.domicile ?= { has_domicile_parameter = estate_increase_conversion_speed_3 }
			}
		}
		add = {
			value = court_chaplain_conversion_base_total
			multiply = ecclesiastical_domicile_increase_conversion_speed_value_3
		}
	}
	else_if = {
		limit = {
			OR = {
				#Does the archbishopric they reside in have a baptistery?
				liege.capital_county.clerical_region_title.holder ?= {
					domicile ?= {
						has_domicile_parameter = estate_increase_conversion_speed_2
					}
					rite = scope:councillor.rite
				}
				#Does their liege have a baptistery?
				liege.domicile ?= { has_domicile_parameter = estate_increase_conversion_speed_2 }
			}
		}
		add = {
			value = court_chaplain_conversion_base_total
			multiply = ecclesiastical_domicile_increase_conversion_speed_value_2
		}
	}
	else_if = {
		limit = {
			OR = {
				#Does the archbishopric they reside in have a baptistery?
				liege.capital_county.clerical_region_title.holder ?= {
					domicile ?= {
						has_domicile_parameter = estate_increase_conversion_speed_1
					}
					rite = scope:councillor.rite
				}
				#Does their liege have a baptistery?
				liege.domicile ?= { has_domicile_parameter = estate_increase_conversion_speed_1 }
			}
		}
		add = {
			value = court_chaplain_conversion_base_total
			multiply = ecclesiastical_domicile_increase_conversion_speed_value_1
		}
	}
	if = {
		limit = {
			OR = {
				#Does the archbishopric they reside in have a belltower?
				liege.capital_county.clerical_region_title.holder ?= {
					domicile ?= {
						has_domicile_parameter = estate_belltower_conversion_speed_3
					}
					rite = scope:councillor.rite
				}
				#Does their liege have a belltower?
				liege.domicile ?= { has_domicile_parameter = estate_belltower_conversion_speed_3 }
			}
		}
		add = {
			value = court_chaplain_conversion_base_total
			multiply = ecclesiastical_domicile_belltower_conversion_speed_value_3
		}
	}
	else_if = {
		limit = {
			OR = {
				#Does the archbishopric they reside in have a belltower?
				liege.capital_county.clerical_region_title.holder ?= {
					domicile ?= {
						has_domicile_parameter = estate_belltower_conversion_speed_2
					}
					rite = scope:councillor.rite
				}
				#Does their liege have a belltower?
				liege.domicile ?= { has_domicile_parameter = estate_belltower_conversion_speed_2 }
			}
		}
		add = {
			value = court_chaplain_conversion_base_total
			multiply = ecclesiastical_domicile_belltower_conversion_speed_value_2
		}
	}
	else_if = {
		limit = {
			OR = {
				#Does the archbishopric they reside in have a belltower?
				liege.capital_county.clerical_region_title.holder ?= {
					domicile ?= {
						has_domicile_parameter = estate_belltower_conversion_speed_1
					}
					rite = scope:councillor.rite
				}
				#Does their liege have a belltower?
				liege.domicile ?= { has_domicile_parameter = estate_belltower_conversion_speed_1 }
			}
		}
		add = {
			value = court_chaplain_conversion_base_total
			multiply = ecclesiastical_domicile_belltower_conversion_speed_value_1
		}
	}
}
