
##########
# 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 = {
			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
	}
}

# 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
}

# 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
	}
}

# 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
	}
}

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 }
				}
				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
}

# 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
}

#######################
# 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.faith = {
				has_doctrine_parameter = pluralism_fundamentalist_proselytization_bonus
			}
		}
		add = {
			value = scope:councillor.conversion_fundamentalist_faith_bonus
			desc = COURT_CHAPLAIN_CONVERSION_FUNDAMENTALIST_FAITH_BONUS
		}
	}
	if = {
		limit = {
			scope:councillor.faith = {
				has_doctrine_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
	if = {
		limit = {
			exists = scope:county
			scope:county.faith = {
				has_doctrine = tenet_false_conversion_sanction
			}
		}
		add = {
			value = scope:councillor.conversion_false_conversion_sanction_resistance
			desc = COURT_CHAPLAIN_CONVERSION_FALSE_CONVERSION_MODIFIER
		}
	}
	if = {
		limit = {
			exists = scope:county
			scope:county.faith = {
				has_doctrine = tenet_reincarnation
			}
		}
		add = {
			value = scope:councillor.conversion_reincarnation_resistance
			desc = COURT_CHAPLAIN_CONVERSION_REINCARNATION_MODIFIER
		}
	}
	if = {
		limit = {
			exists = scope:county
			scope:county.faith = {
				has_doctrine = tenet_dharmic_pacifism
			}
		}
		add = {
			value = scope:councillor.conversion_dharmic_pacifism_resistance
			desc = COURT_CHAPLAIN_CONVERSION_DHARMIC_PACIFISM_MODIFIER
		}
	}
	if = {
		limit = {
			exists = scope:county
			scope:county.faith = {
				has_doctrine_parameter = tenet_adaptive_conversion_resistance
			}
		}
		add = {
			value = scope:councillor.conversion_adaptive_resistance
			desc = COURT_CHAPLAIN_CONVERSION_ADAPTIVE_MODIFIER
		}
	}
	if = {
		limit = {
			exists = scope:county
			scope:county.faith = {
				has_doctrine = tenet_pastoral_isolation
			}
		}
		add = {
			value = scope:councillor.conversion_pastoral_isolation_resistance
			desc = COURT_CHAPLAIN_CONVERSION_PASTORAL_ISOLATION_MODIFIER
		}
	}
	if = {
		limit = {
			scope:councillor.liege.faith = { has_doctrine = tenet_communal_identity }
			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.faith = {
				has_doctrine_parameter = mendicant_preachers_conversion_active
			}
		}
		add = {
			value = scope:councillor.conversion_mendicant_preachers_bonus
			desc = COURT_CHAPLAIN_CONVERSION_MENDICANT_PREACHERS_MODIFIER
		}
	}
	### Communal Identity
	if = {
		limit = {
			exists = scope:county
			scope:councillor.faith = {
				has_doctrine_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.faith = { has_doctrine_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 = {
				faith = { has_doctrine_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
			scope:councillor.faith = { has_doctrine_parameter = unreformed_syncretic_actor_opinion_active }
			scope:county.faith = { has_doctrine_parameter = unreformed}
		}
		add = {
			value = scope:councillor.conversion_syncretic_with_religion_malus
			desc = COURT_CHAPLAIN_CONVERSION_SYNCRETIC_WITH_RELIGION_MODIFIER
		}
	}
	if = {
		limit = {
			exists = scope:county
			scope:councillor.faith = { has_doctrine_parameter = christian_syncretic_actor_opinion_active }
			scope:county.faith = { religion_tag = christianity_religion }
		}
		add = {
			value = scope:councillor.conversion_syncretic_with_religion_malus
			desc = COURT_CHAPLAIN_CONVERSION_SYNCRETIC_WITH_RELIGION_MODIFIER
		}
	}
	if = {
		limit = {
			exists = scope:county
			scope:councillor.faith = { has_doctrine_parameter = islamic_syncretic_actor_opinion_active }
			scope:county.faith = { religion_tag = islam_religion }
		}
		add = {
			value = scope:councillor.conversion_syncretic_with_religion_malus
			desc = COURT_CHAPLAIN_CONVERSION_SYNCRETIC_WITH_RELIGION_MODIFIER
		}
	}
	if = {
		limit = {
			exists = scope:county
			scope:councillor.faith = { has_doctrine_parameter = jewish_syncretic_actor_opinion_active }
			scope:county.faith = { religion_tag = judaism_religion }
		}
		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
		}
	}

	#Conversion bonuses from certain Holy Sites.
	if = {
		limit = {
			scope:councillor.faith = {
				controls_holy_site = jerusalem
			}
			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 = kerala
			}
			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 = iona
			}
			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 = wadi_el_milk
			}
			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 = cordoba
			}
			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 = geneva
			}
			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 = visoki
			}
			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.faith = {
				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.faith = {
				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 = {
			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
		}
	}
}

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

# 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.faith = {
				has_doctrine_parameter = pluralism_fundamentalist_proselytization_bonus
			}
		}
		value = court_chaplain_conversion_base_total
		multiply = 0.2
	}
}

conversion_pluralistic_faith_penalty = {
	value = 0
	if = {
		limit = {
			scope:councillor.faith = {
				has_doctrine_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.faith = {
				has_doctrine = tenet_false_conversion_sanction
			}
		}
		subtract = court_chaplain_conversion_base_total
		multiply = 0.3
	}
}

conversion_reincarnation_resistance = {
	value = 0
	if = {
		limit = {
			exists = scope:county
			scope:county.faith = {
				has_doctrine = tenet_reincarnation
			}
		}
		subtract = court_chaplain_conversion_base_total
		multiply = 0.2
	}
}

conversion_dharmic_pacifism_resistance = {
	value = 0
	if = {
		limit = {
			exists = scope:county
			scope:county.faith = {
				has_doctrine = tenet_dharmic_pacifism
			}
		}
		subtract = court_chaplain_conversion_base_total
		multiply = 0.2
	}
}

conversion_adaptive_resistance = {
	value = 0
	if = {
		limit = {
			exists = scope:county
			scope:county.faith = {
				has_doctrine_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
	}
}

conversion_pastoral_isolation_resistance = {
	value = 0
	if = {
		limit = {
			exists = scope:county
			scope:county.faith = {
				has_doctrine = tenet_pastoral_isolation
			}
		}
		subtract = court_chaplain_conversion_base_total
		multiply = 0.3
	}
}

conversion_communal_identity_resistance = {
	value = 0
	if = {
		limit = {
			scope:councillor.faith = { has_doctrine = tenet_communal_identity }
			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.faith = {
				has_doctrine_parameter = mendicant_preachers_conversion_active
			}
		}
		add = court_chaplain_conversion_base_total
		multiply = 0.33
	}
}

conversion_communal_identity_bonus = {
	value = 0
	if = {
		limit = {
			exists = scope:county
			scope:councillor.faith = {
				has_doctrine_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 = jerusalem
			}
		}
		add = court_chaplain_conversion_base_total
		multiply = 0.20
	}
}

conversion_holy_site_kerala = {
	value = 0
	if = {
		limit = {
			scope:councillor.faith = {
				controls_holy_site = kerala
			}
		}
		add = court_chaplain_conversion_base_total
		multiply = 0.50
	}
}

conversion_holy_site_iona = {
	value = 0
	if = {
		limit = {
			scope:councillor.faith = {
				controls_holy_site = iona
			}
		}
		add = court_chaplain_conversion_base_total
		multiply = 0.30
	}
}

conversion_holy_site_visoki = {
	value = 0
	if = {
		limit = {
			scope:councillor.faith = {
				controls_holy_site = visoki
			}
		}
		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 = wadi_el_milk
			}
		}
		add = court_chaplain_conversion_base_total
		multiply = -0.50
	}
}

conversion_holy_site_cordoba = {
	value = 0
	if = {
		limit = {
			scope:councillor.faith = {
				controls_holy_site = cordoba
			}
		}
		add = court_chaplain_conversion_base_total
		multiply = 0.20
	}
}

conversion_holy_site_geneva = {
	value = 0
	if = {
		limit = {
			scope:councillor.faith = {
				controls_holy_site = geneva
			}
		}
		add = court_chaplain_conversion_base_total
		multiply = 0.20
	}
}

### 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_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
			faith = {
				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
			faith = {
				has_doctrine = muhammad_succession_shia_doctrine
			}
		}
		value = court_chaplain_conversion_base_total
		multiply = 0.5
		floor = yes
		min = 1
	}
}
