﻿
##########
# 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 = {
			scope:councillor_liege = {
				exists = dynasty
				dynasty = { has_dynasty_perk = erudition_legacy_5 }
			}
		}
		# Base value
		add = court_chaplain_religious_relations_modifier
		# Calculation of final value
		multiply = {
			add = erudition_legacy_5_percentage
			divide = 100
		}
	}
}

# Total gain calculation (used for tooltip only)
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
}

# Opinion:

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

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

# 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 = {
			scope:councillor_liege = {
				exists = dynasty
				dynasty = { has_dynasty_perk = erudition_legacy_5 }
			}
		}
		add = court_chaplain_religious_relations_opinion_max_erudition_modifier
	}
}

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

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


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

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

# 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 = 7
court_chaplain_fabricate_claim_county_min_cost = {
	value = { 100 280 }
}

court_chaplain_fabricate_claim_duchy_base = 14
court_chaplain_fabricate_claim_duchy_min_cost = {
	value = { 280 550 }
}

court_chaplain_fabricate_claim_factor = 1

court_chaplain_fabricate_claim_county_cost = {
	add = 40
	subtract = learning
	multiply = court_chaplain_fabricate_claim_factor
	multiply = court_chaplain_fabricate_claim_county_base
	min = court_chaplain_fabricate_claim_county_min_cost
}

court_chaplain_fabricate_claim_duchy_cost = {
	add = 40
	subtract = learning
	multiply = court_chaplain_fabricate_claim_factor
	multiply = court_chaplain_fabricate_claim_duchy_base
	min = court_chaplain_fabricate_claim_duchy_min_cost
}

court_chaplain_fabricate_claim_not_adjacent_penalty = {
	value = 0.5
}

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
}

# Development penalty
convert_faith_development_penalty = {
	value = 0
	if = {
		limit = { exists = scope:county }
		add = 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.conversion_fundamentalist_faith_bonus
		add = scope:councillor.conversion_pluralistic_faith_penalty
		add = scope:councillor.conversion_false_conversion_sanction_resistance
		add = scope:councillor.conversion_reincarnation_resistance
		add = scope:councillor.conversion_adaptive_resistance
		add = scope:councillor.conversion_mendicant_preachers_bonus
		add = scope:councillor.conversion_communal_identity_bonus
		add = scope:councillor.conversion_holy_site_jerusalem
		add = scope:councillor.conversion_holy_site_kerala
		add = scope:councillor.conversion_holy_site_cordoba
		add = scope:councillor.conversion_savior_liege
		add = scope:councillor.conversion_divine_blood_liege
		add = scope:councillor.conversion_learning_theology
		multiply = {
			subtract = scope:county.development_level
			divide = 100
			min = -0.9
		}
	}
}

# Zealous Proselytizer bonus
court_chaplain_conversion_monthly_increase_perk_bonus = {
	if = {
		limit = {
			scope:councillor_liege = { has_perk = zealous_proselytizer_perk }
		}
		add = court_chaplain_conversion_base_total
		multiply = {
			add = zealous_proselytizer_percentage
			divide = 100
		}
	}
}

# Bureaucrats bonus
court_chaplain_conversion_monthly_increase_dynasty_perk_bonus = {
	if = {
		limit = {
			scope:councillor_liege = {
				exists = dynasty
				dynasty = { has_dynasty_perk = erudition_legacy_5 }
			}
		}
		add = court_chaplain_conversion_base_total
		multiply = {
			add = erudition_legacy_5_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_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 }
			NOT = { 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.
}

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

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

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

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


# Total value calculation
court_chaplain_conversion_total_value = {
	add = court_chaplain_conversion_base_total
	if = {
		limit = {
			scope:councillor_liege = { has_perk = zealous_proselytizer_perk }
		}
		add = court_chaplain_conversion_monthly_increase_perk_bonus
	}
	if = {
		limit = {
			scope:councillor_liege = {
				exists = dynasty
				dynasty = { has_dynasty_perk = erudition_legacy_5 }
			}
		}
		add = court_chaplain_conversion_monthly_increase_dynasty_perk_bonus
	}
}



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