﻿# Modifiers for the base discontent growth of a scoped servitude faction.
#
# scope = the faction in question
regula_faction_servitude_discontent_modifier = {
	# Peasant members generally gain discontent, even if they are weaker than
	# target.
	modifier = {
		add = 4
		any_faction_county_member = {
			exists = this
		}
	}
}

# Modifiers for the base discontent growth of a scoped servitude faction.
#
# scope = the faction in question
regula_faction_servitude_power_threshold_modifier = {
	# Hard rule makes factions weaker.
	modifier = {
		add = 20
		faction_target = {
			has_perk = hard_rule_perk
		}
		desc = FACTION_POWER_HARD_RULE
	}

	# Peasant counties are willing to enforce demands even at lower power.
	modifier = {
		add = -15
		any_faction_county_member = {
			exists = this
		}
	}
}

# Evaluates the likelyhood of a given county creating or joining a servitude
# faction.
#
# scope = the character being evaluated
# TARGET = the faction target to evaluate
# FACTION_POWER = current faction power level
# FACTION_POWER_THRESHOLD = the power threshold
regula_faction_servitude_character_faction_score = {
	############
	# BLOCKERS #
	############
	# Can't create or join faction if it is invalid.
	modifier = {
		add = -2000
		NOT = {
			regula_faction_servitude_common_valid_trigger = {
				TARGET = $TARGET$
			}
		}
	}

	# Do not join a new faction if I am already at war.
	modifier = {
		add = -2000
		is_at_war = yes
		trigger_if = {
			limit = {
				exists = joined_faction
				exists = scope:faction
			}
			NOT = { joined_faction = scope:faction }
		}
	}

	# Can't create or join if title is higher than Magister's
	modifier = {
		highest_held_title_tier >= global_var:magister_character.highest_held_title_tier
		add = -2000
	}

	#######################
	# Standard AI Weights #
	#######################
	common_faction_modifiers = {
		FACTION_TARGET = $TARGET$
		OPINION_MULTIPLIER = -0.4
		MAX_OPINION = 100
		POWER = $FACTION_POWER$
		THRESHOLD = $FACTION_POWER_THRESHOLD$
	}

	#######################
	## Regula AI Weights ##
	#######################
	# Very high base create chance.
	modifier = {
		add = 1500
		has_trait = devoted_trait_group
	}
}

# Evaluates the likelyhood of a given county creating or joining a servitude
# faction.
#
# scope = the county being evaluated
# TARGET = the faction target to evaluate
regula_faction_servitude_county_faction_score = {
	############
	# BLOCKERS #
	############
	# Can't create or join faction if we are non-Magister faith.
	modifier = {
		add = -2000
		NOT = {
			faith = global_var:magister_character.faith
		}
	}

	# Can't create or join faction if it is invalid.
	modifier = {
		add = -2000
		NOT = {
			regula_faction_servitude_common_valid_trigger = {
				TARGET = $TARGET$
			}
		}
	}

	#######################
	# Standard AI Weights #
	#######################
	# Greatly reduced chance for a character's capital county to form a faction against them (extra -25 opinion needed).
	modifier = {
		add = -200
		title_province = $TARGET$.capital_province
	}

	legalism_virtue_and_sin_modifier = {
		TARGET = $TARGET$
		SCORE_PER_TRAIT = 50 # Worth ~12 opinion per trait.
	}

	liege_debt_modifier = {
		TARGET = $TARGET$
		SCORE_PER_DEBT_LEVEL = 20 # Worth ~5 opinon per debt level, up to a max of 140 (-35 opinion)
	}

	# Ruling Caste
	modifier = {
		add = -25
		NOT = {
			culture = $TARGET$.culture
		}
		$TARGET$.culture = {
			has_cultural_parameter = peasant_and_populist_factions_less_common
		}
	}

	# Realm Stability Settings
	modifier = {
		add = 50
		has_game_rule = lesser_realm_stability
	}
	modifier = {
		add = -100
		has_game_rule = higher_realm_stability
	}
	modifier = {
		add = -200
		has_game_rule = extreme_realm_stability
	}

	#######################
	## Regula AI Weights ##
	#######################
	# Recently converted has higher desire to join the magister.
	modifier = {
		add = 500
		has_county_modifier = regula_dispatch_missionaries_liege_religion_disapproval_modifier
	}

	# If there is a nearby magister faith county (basically always), increase our join likelyhood.
	modifier = {
		add = 1000
		any_title_to_title_neighboring_and_across_water_county = {
			faith = global_var:magister_character.faith
		}
	}

	# If there are multiple nearby magister faith counties, increase our join likelyhood even more.
	modifier = {
		add = 1000
		any_title_to_title_neighboring_and_across_water_county = {
			count >= 2
			faith = global_var:magister_character.faith
		}
	}
}

# Likelyhood of enforcing demands for a servitude faction.
#
# scope = the faction in question.
regula_faction_servitude_demand_score = {
	# 40% base chance at minimum power (70%), increasing linearly
	compare_modifier = {
		value = faction_power
		multiplier = 0.5
	}

	# Once the faction has a good chance to win (10% stronger than liege) demand chance increases much more rapidly.
	compare_modifier = {
		trigger = {	faction_power > 110 }
		value = faction_power
		multiplier = 1
	}

	# Servitude factions are opportunistic!
	modifier = {
		add = 100
		faction_target = {
			is_at_war = yes
		}
	}

	# County members are more likely to enforce demands.
	modifier = {
		add = 50
		any_faction_county_member = {
			exists = this
		}
	}
}
