﻿holy_sites_to_create_temporal_head_of_faith = {
	if = {
		limit = { has_game_rule = head_holy_site_0 }
		value = 0
	}
	else_if = {
		limit = { has_game_rule = head_holy_site_1 }
		value = 1
	}
	else_if = {
		limit = { has_game_rule = head_holy_site_2 }
		value = 2
	}
	else_if = {
		limit = { has_game_rule = head_holy_site_3 }
		value = 3
	}
	else_if = {
		limit = { has_game_rule = head_holy_site_4 }
		value = 4
	}
	else_if = {
		limit = { has_game_rule = head_holy_site_5 }
		value = 5
	}
	else = { value = 2 }
}
holy_sites_to_create_spiritual_head_of_faith = {
	if = {
		limit = { has_game_rule = head_holy_site_0 }
		value = 0
	}
	else_if = {
		limit = { has_game_rule = head_holy_site_1 }
		value = 1
	}
	else_if = {
		limit = { has_game_rule = head_holy_site_2 }
		value = 2
	}
	else_if = {
		limit = { has_game_rule = head_holy_site_3 }
		value = 3
	}
	else_if = {
		limit = { has_game_rule = head_holy_site_4 }
		value = 4
	}
	else_if = {
		limit = { has_game_rule = head_holy_site_5 }
		value = 5
	}
	else = { value = 1 }
}

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 = no_faith_conversion
		}
		multiply = {
			value = 0
			desc = GAME_RULE_SLOWER_REASON
		}
	}
	if = {
		limit = {
			has_game_rule = extremely_slow_faith_conversion_speed
		}
		multiply = {
			value = 0.10 #significantly_slower_game_rule_value
			desc = GAME_RULE_EXTREMELY_SLOW_REASON
		}
	}		
	if = {
		limit = {
			has_game_rule = slower_faith_conversion_speed
		}
		multiply = {
			value = slower_game_rule_value
			desc = GAME_RULE_SLOWER_REASON
		}
	}
	if = {
		limit = {
			has_game_rule = significantly_slower_faith_conversion_speed
		}
		multiply = {
			value = significantly_slower_game_rule_value
			desc = GAME_RULE_SIGNIFICANTLY_SLOWER_REASON
		}
	}
	if = {
		limit = {
			OR = {
				has_game_rule = faster_faith_conversion_speed
				AND = {
					has_game_rule = faster_faith_conversion_speed_pl
					scope:councillor.liege = { is_ai = no }
				}
			}
		}
		multiply = {
			value = faster_game_rule_value
			desc = GAME_RULE_FASTER_REASON
		}
	}
	if = {
		limit = {
			OR = {
				has_game_rule = significantly_faster_faith_conversion_speed
				AND = {
					has_game_rule = significantly_faster_faith_conversion_speed_pl
					scope:councillor.liege = { is_ai = no }
				}
			}

		}
		multiply = {
			value = significantly_faster_game_rule_value
			desc = GAME_RULE_SIGNIFICANTLY_FASTER_REASON
		}
	}
}

rite_growth_min_cooldown_years = {
	if = {
		limit = { has_game_rule = much_less_branched_rite_frequency }
		value = 8
	}
	else_if = {
		limit = { has_game_rule = less_branched_rite_frequency }
		value = 5
	}
	else_if = {
		limit = { has_game_rule = more_branched_rite_frequency }
		value = 2
	}
	else_if = {
		limit = { has_game_rule = much_more_branched_rite_frequency }
		value = 1
	}
	else_if = {
		limit = { has_game_rule = rare_branched_rite_frequency }
		value = 20
	}
	else_if = {
		limit = { has_game_rule = very_rare_branched_rite_frequency }
		value = 100
	}
	else = {
		value = @rite_growth_min_cooldown_years
	}
}

rite_growth_max_cooldown_years = {
	if = {
		limit = { has_game_rule = much_less_branched_rite_frequency }
		value = 45
	}
	else_if = {
		limit = { has_game_rule = less_branched_rite_frequency }
		value = 27
	}
	else_if = {
		limit = { has_game_rule = more_branched_rite_frequency }
		value = 12
	}
	else_if = {
		limit = { has_game_rule = much_more_branched_rite_frequency }
		value = 8
	}
	else_if = {
		limit = { has_game_rule = rare_branched_rite_frequency }
		value = 20
	}
	else_if = {
		limit = { has_game_rule = very_rare_branched_rite_frequency }
		value = 100
	}
	else = {
		value = @rite_growth_max_cooldown_years
	}
}

# Shorter cooldown for faith_rite_additional_growth_chance_pulse so at-target faiths can still trickle
rite_growth_fallback_cooldown_days = {
	if = {
		limit = { has_game_rule = much_less_branched_rite_frequency }
		value = 12
	}
	else_if = {
		limit = { has_game_rule = less_branched_rite_frequency }
		value = 8
	}
	else_if = {
		limit = { has_game_rule = more_branched_rite_frequency }
		value = 3
	}
	else_if = {
		limit = { has_game_rule = much_more_branched_rite_frequency }
		value = 2
	}
	else_if = {
		limit = { has_game_rule = rare_branched_rite_frequency }
		value = 50
	}
	else_if = {
		limit = { has_game_rule = very_rare_branched_rite_frequency }
		value = 100
	}
	else = {
		value = @rite_growth_fallback_cooldown_years
	}
	multiply = 365
}

# After a heresy splits off we wait, otherwise the pulse just fills the gap again within a year
rite_growth_heresy_cooldown_days = {
	if = {
		limit = { has_game_rule = much_less_branched_rite_frequency }
		value = 8
	}
	else_if = {
		limit = { has_game_rule = less_branched_rite_frequency }
		value = 5
	}
	else_if = {
		limit = { has_game_rule = more_branched_rite_frequency }
		value = 2
	}
	else_if = {
		limit = { has_game_rule = much_more_branched_rite_frequency }
		value = 1
	}
	else = {
		value = @rite_growth_heresy_cooldown_years
	}
	multiply = 365
}
