councillor_everpreg_archess_of_plenty_scale = {
	add = diplomacy
	if = {
		limit = { has_trait = gregarious 
			  has_trait = beauty_good_3 
			}
		add = 5
	}
	if = {
		limit = { has_trait = everpreg_1
			  has_trait = everpreg_2
			  has_trait = everpreg_3
		}
		add = 3
	}	
	if = {
		limit = { has_trait = reveler_1
			  has_trait = reveler_2
			  has_trait = reveler_3
		}
		add = 3
	}
	if = {
		limit = {
			has_trait = beauty_bad_3
		}
		add = -5
	}
	if = {
		limit = { has_trait = stuttering
			  has_trait = lisping
			  has_trait = wheezing
			  has_trait = depressed_1
		}
		divide = 2
	}
	min = 5
}

councillor_everpreg_archess_of_plenty_religious_relations_modifier = {
	add = diplomacy
	divide = 20
}

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

# Bonus from Bureaucrats
councillor_everpreg_archess_of_plenty_religious_relations_glory_legacy_5_bonus_modifier = {
	if = {
		limit = {
			scope:councillor_liege = {
				exists = dynasty
				dynasty = { has_dynasty_perk = glory_legacy_5 }
			}
		}
		# Base value
		add = councillor_everpreg_archess_of_plenty_religious_relations_modifier
		# Calculation of final value
		multiply = {
			add = glory_legacy_5_percentage
			divide = 100
		}
	}
}

# Total gain calculation (used for tooltip only)
councillor_everpreg_archess_of_plenty_religious_relations_total_piety_gain = {
	add = councillor_everpreg_archess_of_plenty_religious_relations_modifier
	add = councillor_everpreg_archess_of_plenty_religious_relations_perk_bonus_modifier
	add = councillor_everpreg_archess_of_plenty_religious_relations_glory_legacy_5_bonus_modifier
}

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

# Base modifier value
councillor_everpreg_archess_of_plenty_religious_relations_opinion_base = {
	add = diplomacy
	divide = 2
}

councillor_everpreg_archess_of_plenty_religious_relations_no_hof_opinion_base = {
	add = councillor_everpreg_archess_of_plenty_religious_relations_opinion_base
	divide = councillor_everpreg_archess_of_plenty_religious_relations_no_hof_balance
}

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

glory_legacy_5_percentage = 10

# Bonus to opinion from Bureaucrats
councillor_everpreg_archess_of_plenty_religious_relations_opinion_max_glory_modifier = {
	add = councillor_everpreg_archess_of_plenty_religious_relations_opinion_base
	multiply = {
		add = glory_legacy_5_percentage
		divide = 100
	}
}

# Calculate the full max value of the opinion gain
councillor_everpreg_archess_of_plenty_religious_relations_opinion_max = {
	add = councillor_everpreg_archess_of_plenty_religious_relations_opinion_base
	# Add bonus from Clerical Justification:
	if = {
		limit = {
			scope:councillor_liege = { has_perk = clerical_justifications_perk }
		}
		add = councillor_everpreg_archess_of_plenty_religious_relations_opinion_max_perk_modifier
	}
	# Add bonus from Bureaucrats
	if = {
		limit = {
			scope:councillor_liege = {
				exists = dynasty
				dynasty = { has_dynasty_perk = glory_legacy_5 }
			}
		}
		add = councillor_everpreg_archess_of_plenty_religious_relations_opinion_max_glory_modifier
	}
}

councillor_everpreg_archess_of_plenty_religious_relations_no_hof_opinion_max = {
	add = councillor_everpreg_archess_of_plenty_religious_relations_opinion_max
	divide = councillor_everpreg_archess_of_plenty_religious_relations_no_hof_balance
}

# 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)
councillor_everpreg_archess_of_plenty_religious_relations_opinion_modifier = {
	add = 0
	if = {
		limit = {
			scope:councillor_liege = {
				is_ai = no
				has_variable = councillor_everpreg_archess_of_plenty_religious_relations_opinion_value
			}
		}
		add = liege.var:councillor_everpreg_archess_of_plenty_religious_relations_opinion_value
	}
	else = {
		add = councillor_everpreg_archess_of_plenty_religious_relations_opinion_max
	}
}

councillor_everpreg_archess_of_plenty_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 = councillor_everpreg_archess_of_plenty_religious_relations_opinion_modifier
		divide = councillor_everpreg_archess_of_plenty_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)
councillor_everpreg_archess_of_plenty_religious_relations_monthly_increase = {
	add = councillor_everpreg_archess_of_plenty_religious_relations_opinion_max
	divide = 24 # 2 years to max out
}

councillor_everpreg_archess_of_plenty_religious_relations_no_hof_monthly_increase = {
	add = councillor_everpreg_archess_of_plenty_religious_relations_monthly_increase
	divide = councillor_everpreg_archess_of_plenty_religious_relations_no_hof_balance
}


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

# Base value
councillor_everpreg_archess_of_plenty_fabricate_claim_base = {
	add = 3
}

councillor_everpreg_archess_of_plenty_fabricate_claim_monthly_increase_base = {
	add = diplomacy
	divide = 5
}

councillor_everpreg_archess_of_plenty_fabricate_claim_base_total = {
	add = councillor_everpreg_archess_of_plenty_fabricate_claim_base
	add = councillor_everpreg_archess_of_plenty_fabricate_claim_monthly_increase_base
}

# Bonus from Accomplished Forger Perk
councillor_everpreg_archess_of_plenty_fabricate_claim_perk_bonus_monthly_increase = {
	add = councillor_everpreg_archess_of_plenty_fabricate_claim_base_total
	multiply = {
		add = accomplished_forger_percentage
		divide = 100
	}
}

# Bonus from Bureaucrats
councillor_everpreg_archess_of_plenty_fabricate_claim_dynasty_perk_bonus = {
	add = councillor_everpreg_archess_of_plenty_fabricate_claim_base_total
	multiply = {
		add = glory_legacy_5_percentage
		divide = 100
	}
}

# Bonus from Land Grants innovation
councillor_everpreg_archess_of_plenty_fabricate_claim_innovation_bonus_land_grants = {
	value = 0
	add = councillor_everpreg_archess_of_plenty_fabricate_claim_base_total
	multiply = 0.50
}

# Relation impact
councillor_everpreg_archess_of_plenty_fabricate_claim_monthly_increase_friend_bonus = {
	value = councillor_everpreg_archess_of_plenty_fabricate_claim_base_total
	multiply = {
		add = council_friend_impact_percentage
		divide = 100
	}
}
councillor_everpreg_archess_of_plenty_fabricate_claim_monthly_increase_best_friend_bonus = {
	value = councillor_everpreg_archess_of_plenty_fabricate_claim_base_total
	multiply = {
		add = council_best_friend_impact_percentage
		divide = 100
	}
}
councillor_everpreg_archess_of_plenty_fabricate_claim_monthly_increase_rival_bonus = {
	value = councillor_everpreg_archess_of_plenty_fabricate_claim_base_total
	multiply = {
		add = council_rival_impact_percentage
		divide = 100
	}
}
councillor_everpreg_archess_of_plenty_fabricate_claim_monthly_increase_nemesis_bonus = {
	value = councillor_everpreg_archess_of_plenty_fabricate_claim_base_total
	multiply = {
		add = council_nemesis_impact_percentage
		divide = 100
	}
}

councillor_everpreg_archess_of_plenty_fabricate_claim_county_base = 3
councillor_everpreg_archess_of_plenty_fabricate_claim_county_min_cost = {
	value = { 40 60 }
}

councillor_everpreg_archess_of_plenty_fabricate_claim_duchy_base = 7
councillor_everpreg_archess_of_plenty_fabricate_claim_duchy_min_cost = {
	value = { 80 100 }
}

councillor_everpreg_archess_of_plenty_fabricate_claim_factor = 1

councillor_everpreg_archess_of_plenty_fabricate_claim_county_cost = {
	add = 40
	subtract = diplomacy
	multiply = councillor_everpreg_archess_of_plenty_fabricate_claim_factor
	multiply = councillor_everpreg_archess_of_plenty_fabricate_claim_county_base
	min = councillor_everpreg_archess_of_plenty_fabricate_claim_county_min_cost
}

councillor_everpreg_archess_of_plenty_fabricate_claim_duchy_cost = {
	add = 40
	subtract = diplomacy
	multiply = councillor_everpreg_archess_of_plenty_fabricate_claim_factor
	multiply = councillor_everpreg_archess_of_plenty_fabricate_claim_duchy_base
	min = councillor_everpreg_archess_of_plenty_fabricate_claim_duchy_min_cost
}

councillor_everpreg_archess_of_plenty_fabricate_claim_not_adjacent_penalty = {
	value = 0.5
}

councillor_everpreg_archess_of_plenty_fabricate_claim_vassal_penalty = {
	value = 0.3
}

councillor_everpreg_archess_of_plenty_heretic_bonus = {
	value = 1.3
}

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

# Base progress value
councillor_everpreg_archess_of_plenty_conversion_base = {
	add = 0.5
}

councillor_everpreg_archess_of_plenty_conversion_monthly_increase = {
	add = diplomacy
	divide = 10
}

councillor_everpreg_archess_of_plenty_conversion_base_total = {
	add = councillor_everpreg_archess_of_plenty_conversion_base
	add = councillor_everpreg_archess_of_plenty_conversion_monthly_increase
}

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 = councillor_everpreg_archess_of_plenty_conversion_base
		add = scope:councillor.councillor_everpreg_archess_of_plenty_conversion_monthly_increase
		add = scope:councillor.councillor_everpreg_archess_of_plenty_conversion_monthly_increase_perk_bonus
		add = {
			add = {
				add = scope:councillor.councillor_everpreg_archess_of_plenty_progress_percentage
				multiply = scope:councillor.faith.fervor
			}
			subtract = {
				add = scope:councillor.councillor_everpreg_archess_of_plenty_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_diplomacy_theology
		multiply = {
			subtract = scope:county.development_level
			divide = 100
			min = -0.9
		}
	}
}

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

# Bureaucrats bonus
councillor_everpreg_archess_of_plenty_conversion_monthly_increase_dynasty_perk_bonus = {
	if = {
		limit = {
			scope:councillor_liege = {
				exists = dynasty
				dynasty = { has_dynasty_perk = glory_legacy_5 }
			}
		}
		add = councillor_everpreg_archess_of_plenty_conversion_base_total
		multiply = {
			add = glory_legacy_5_percentage
			divide = 100
		}
	}
}

# Friend Bonus
councillor_everpreg_archess_of_plenty_conversion_monthly_increase_friend_bonus = {
	add = councillor_everpreg_archess_of_plenty_conversion_base_total
	multiply = {
		add = council_friend_impact_percentage
		divide = 100
	}
}

# Best Friend Bonus
councillor_everpreg_archess_of_plenty_conversion_monthly_increase_best_friend_bonus = {
	add = councillor_everpreg_archess_of_plenty_conversion_base_total
	multiply = {
		add = council_best_friend_impact_percentage
		divide = 100
	}
}

# Rival Penalty
councillor_everpreg_archess_of_plenty_conversion_monthly_increase_rival_bonus = {
	add = councillor_everpreg_archess_of_plenty_conversion_base_total
	multiply = {
		add = council_rival_impact_percentage
		divide = 100
	}
}

# Nemesis Penalty
councillor_everpreg_archess_of_plenty_conversion_monthly_increase_nemesis_bonus = {
	add = councillor_everpreg_archess_of_plenty_conversion_base_total
	multiply = {
		add = council_nemesis_impact_percentage
		divide = 100
	}
}

# Convert "full" percentage value to 0-1 scale
councillor_everpreg_archess_of_plenty_progress_percentage = {
	add = councillor_everpreg_archess_of_plenty_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 = councillor_everpreg_archess_of_plenty_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 = councillor_everpreg_archess_of_plenty_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 = councillor_everpreg_archess_of_plenty_conversion_base_total
		multiply = 0.3
	}
}

conversion_reincarnation_resistance = {
	value = 0
	if = {
		limit = {
			exists = scope:county
			scope:county.faith = {
				has_doctrine = tenet_reincarnation
			}
		}
		subtract = councillor_everpreg_archess_of_plenty_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 = councillor_everpreg_archess_of_plenty_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 = councillor_everpreg_archess_of_plenty_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 = councillor_everpreg_archess_of_plenty_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 = councillor_everpreg_archess_of_plenty_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 = councillor_everpreg_archess_of_plenty_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 = councillor_everpreg_archess_of_plenty_conversion_base_total
		multiply = 0.50
	}
}

conversion_communal_identity_penalty = {
	value = 0
	subtract = councillor_everpreg_archess_of_plenty_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 = councillor_everpreg_archess_of_plenty_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 = councillor_everpreg_archess_of_plenty_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 = councillor_everpreg_archess_of_plenty_conversion_base_total
	multiply = 0.15
}

### Various Modifier Bonuses
population_fled_persecution_modifier_value = {
	value = 0
	add = councillor_everpreg_archess_of_plenty_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 = councillor_everpreg_archess_of_plenty_conversion_base_total
		multiply = 0.20
	}
}

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

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

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

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

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

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

conversion_diplomacy_theology = {
	if = {
		limit = {
			exists = scope:county
			scope:county = {
				has_variable = diplomacy_encouraged_conversion
			}
		}
		value = councillor_everpreg_archess_of_plenty_conversion_base_total
		multiply = 0.25
	}
}


# Total value calculation
councillor_everpreg_archess_of_plenty_conversion_total_value = {
	add = councillor_everpreg_archess_of_plenty_conversion_base_total
	if = {
		limit = {
			scope:councillor_liege = { has_perk = zealous_proselytizer_perk }
		}
		add = councillor_everpreg_archess_of_plenty_conversion_monthly_increase_perk_bonus
	}
	if = {
		limit = {
			scope:councillor_liege = {
				exists = dynasty
				dynasty = { has_dynasty_perk = glory_legacy_5 }
			}
		}
		add = councillor_everpreg_archess_of_plenty_conversion_monthly_increase_dynasty_perk_bonus
	}
}



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