﻿# Delay after freeing the Keeper of Souls before which a heresy conspiracy
# cannot begin.
regula_heresy_free_kos_block_duration_years = 10

# Minimum number of counties in a character's realm before heresy can occur
# against them. Ignored if they are king or above.
regula_heresy_minimum_dutchy_or_below_realm_size = 20

# Minimum fraction of the magister's realm which must be a potential source
# of heresy in order for a heresy storyline to become active.
regula_heresy_minimum_heretical_county_fraction = 0.1

# Target amount of growth needed before a new member is added.
# Decreased when the conspiracy goes public.
#
# scope = the heresy story
regula_heresy_growth_needed_for_member = {
	value = 100
	if = {
		limit = {
			has_game_rule = regula_heresy_difficulty_easier
		}
		value = 200
	}
	else_if = {
		limit = {
			has_game_rule = regula_heresy_difficulty_harder
		}
		value = 75
	}

	if = {
		limit = {
			regula_heresy_story_in_public_state_trigger = yes
		}
		divide = 2
	}
}

# Target amount of discontent needed before the faction begins open opposition.
regula_heresy_discontent_needed_for_open_oppostion = {
	value = 200

	if = {
		limit = {
			has_game_rule = regula_heresy_difficulty_easier
		}
		value = 400
	}
	else_if = {
		limit = {
			has_game_rule = regula_heresy_difficulty_harder
		}
		value = 150
	}
}

# Target amount of threat needed before the conspiracy disbands.
# Increased when the conspiracy goes public.
#
# scope = the heresy story
regula_heresy_threat_needed_for_disband = {
	value = 100

	if = {
		limit = {
			regula_heresy_story_in_public_state_trigger = yes
		}
		multiply = 2
	}
}

# Amount that potentially heretical counties add to the growth rate.
regula_heresy_growth_per_direct_heresy_county = 3
regula_heresy_growth_per_indirect_heresy_county = 1

# Amount that conspiracy members add to the discontent rate.
regula_heresy_discontent_per_conspirator = 1

# Amount of threat gained per member apprehended by the Magister's inquisitor.
#
# scope = the member being apprehended, which may change the gained threat.
regula_heresy_threat_gain_per_apprehended_member = {
	value = 10

	# Unlanded = 1x, Baron = 2x, ..., King = 5x
	multiply = {
		value = 1
		add = highest_held_title_tier
	}
}

# Amount of troops relative to `county_levies_to_raise` spawned for heresy
# faction member counties.
regula_heresy_direct_heresy_troop_scale = 1.5
regula_heresy_indirect_heresy_troop_scale = 0.75

# Factor which increases the rate of secrets being discovered for a given heresy
# target. Not included in councillor values since this should not be included in
# task descriptions since it would give information about heresy status.
#
# Current implementation is a 10% increase in secret discovery chance per available to
# discover secret.
#
# scope = the heresy story target
regula_heresy_secret_discovery_adjustment_factor = {
	value = 1
	every_targeting_secret = {
		limit = {
			secret_type = regula_heresy_conspirator_secret
			NOT = { is_known_by = prev }
		}
		add = 0.1
	}
}

# Computes the rate at which a heresy conspiracy (not faction) should grow
# for a given targeted character.
#
# scope = the character to compute heresy growth rate for.
regula_heresy_growth_rate = {
	value = 0

	# Each potentially heretical county adds to the growth rate.
	every_realm_county = {
		limit = {
			regula_heresy_potential_heresy_county_including_neighbors_trigger = yes
		}

		# Counties which are directly heretical add more to growth than those
		# which simply have heretical neighbors.
		if = {
			limit = {
				regula_heresy_potential_heresy_county_directly_trigger = yes
			}
			add = regula_heresy_growth_per_direct_heresy_county
		}
		else = {
			add = regula_heresy_growth_per_indirect_heresy_county
		}
	}

	# Total growth rate is divided by 1/2 the current size of the heresy
	# conspiracy. Growth slows down as the membership gets larger.
	divide = {
		value = regula_heresy_conspiracy_num_members
		divide = 2
		min = 1
	}

	round = yes
	min = 1
}

# Computes the rate at which a heresy conspiracy (not faction) should
# increase it's discontent for a given targeted character.
#
# scope = the character to compute discontent increase rate for.
regula_heresy_discontent_rate = {
	value = 0

	every_targeting_secret = {
		limit = {
			secret_type = regula_heresy_conspirator_secret
		}

		add = regula_heresy_discontent_per_conspirator
	}
}

# Computes the current number of participants of the regula heresy secret
# conspiracy.
#
# scope = the targeted character to compute conspiracy size for.
regula_heresy_conspiracy_num_members = {
	value = 0

	# Count targeting secrets in case we are in conspiracy mode.
	every_targeting_secret = {
		limit = {
			secret_type = regula_heresy_conspirator_secret
		}

		add = 1
	}

	# Count targeting faction members in case we are in open opposition mode.
	every_targeting_faction = {
		limit = {
			regula_faction_is_heresy_faction_trigger = yes
		}

		every_faction_member = {
			add = 1
		}
	}
}

# Chance that a heresy story cycle will start on a yearly basis when eligible.
#
# scope = the character who would be targeted by the heresy story.
regula_heresy_story_start_chance = {
	value = regula_heresy_growth_rate
	divide = 3

	if = {
		limit = {
			has_game_rule = regula_heresy_difficulty_easier
		}
		divide = 2
	}
	else_if = {
		limit = {
			has_game_rule = regula_heresy_difficulty_harder
		}
		multiply = 1.25
	}

	min = 1
	max = 100
}

# Chance that a torture of a character will be successful in getting them to
# reveal other heretics.
#
# Will be in the range [0, 100].
#
# scope = the character doing the torture
# scope:recipient = the character being tortured
regula_heresy_torture_success_chance = {
	value = 50

	# Add torturer intrigue skill & other factors.
	add = {
		value = 50
		multiply = character_intrigue_skill_factor

		if = {
			limit = {
				has_trait = torturer
			}
			multiply = 2
		}

		if = {
			limit = {
				has_trait = callous
			}
			multiply = 1.25
		}

		if = {
			limit = {
				has_trait = sadistic
			}
			multiply = 1.25
		}

		if = {
			limit = {
				has_trait = compassionate
			}
			multiply = 0.75
		}

		if = {
			limit = {
				has_trait = trusting
			}
			multiply = 0.75
		}
	}

	# Subtract recipient intrigue
	subtract = {
		value = 50
		multiply = scope:recipient.character_intrigue_skill_factor

		if = {
			limit = {
				has_trait = zealous
			}
			multiply = 2
		}

		if = {
			limit = {
				has_trait = deceitful
			}
			multiply = 2
		}

		if = {
			limit = {
				has_trait = brave
			}
			multiply = 1.25
		}

		if = {
			limit = {
				has_trait = stubborn
			}
			multiply = 1.25
		}

		if = {
			limit = {
				has_trait = craven
			}
			multiply = 0.75
		}

		if = {
			limit = {
				has_trait = honest
			}
			multiply = 0.75
		}

		if = {
			limit = {
				has_trait = contrite
			}
			multiply = 0.25
		}
	}

	min = 0
	max = 100
}
