﻿# Pilgrims and Preachers - preaching expeditions
# A Pilgrims missionary army is an engine barter army. Its "barter goods" are the camp PROVISIONS
# it carries: taken out of the camp when it sets out, handed out sermon after sermon (vanilla barter
# rate: 2 provisions per point of loot; see ppr_preaching_gold_per_loot_value below for what that point earns),
# and the leftovers go back to the camp when it returns.
# The alms it collects are carried home and paid as gold at the camp; piety is gained at each sermon.

# Provisions a missionary army can carry: 50 + half a ration per soldier, and never less than 51.
# (Army automation does not work for a landless adventurer: missions are sent by hand.) Root = owner, scope:army.
ppr_mission_rations_capacity_value = {
	value = scope:army.army_size
	multiply = 0.5
	add = 50
	floor = yes
	min = 51
}

# Domicile scope. The camp never lends its provisions below this: the vanilla privation threshold
# (provisions_privation_threshold_start = define NCharacter PROVISIONS_LOW_WARNING), the very point where the
# camp window shows its stores in yellow (Domicile.IsProvisionsLow) and privation events begin.
ppr_camp_provisions_floor_value = {
	value = provisions_privation_threshold_start
}

# Provisions the camp can spare for the missionaries: what it holds above that floor. Root = owner.
ppr_mission_rations_spare_value = {
	value = 0
	domicile ?= {
		add = provisions
		subtract = ppr_camp_provisions_floor_value
	}
	floor = yes
	min = 0
}

# Provisions set aside for the missionaries while none are raised (Pilgrims players), so that they
# can be raised (the raise buttons need barter goods): a token 1 provision, within what the
# camp can spare above its low threshold, counting what is already set aside. When the camp's stores
# are low (yellow) or critical (red), nothing is set aside: the reserve goes back, and with no barter
# goods left the missionaries cannot be raised. Root = owner.
ppr_mission_rations_reserve_value = {
	value = barter_goods
	add = ppr_mission_rations_spare_value
	if = {
		limit = { ppr_mission_rations_spare_value <= 0 }
		value = 0
	}
	floor = yes
	max = 1
	min = 0
}

# Provisions to load now: what the army can still carry, within what the camp can spare.
# Root = owner, scope:army.
ppr_mission_rations_to_load_value = {
	value = ppr_mission_rations_capacity_value
	subtract = barter_goods
	max = ppr_mission_rations_spare_value
	min = 0
}

# --- What a sermon earns, per point of the engine's barter loot (scope:value) ---
# Balanced on vanilla values: contracts pay about 250 provisions for 50 gold or 100 piety (~5 provisions per
# gold, 1 gold ~ 2 piety). The engine hands out 2 provisions per point of loot, so:
#   alms:  0.5 gold per point  -> 4 provisions per gold (close to what vanilla deems provisions worth)
#   piety: 1 piety per point   -> the same value as the alms, by vanilla's own exchange rate
# The GUI shows the alms with the same 0.5 (Multiply_CFixedPoint in ppr_ui_l_*.yml and gui/window_barter.gui).
ppr_preaching_gold_per_loot_value = 0.5
ppr_preaching_piety_per_loot_value = 1

# Alms in a land of hostile faith: the faithful there still give, but only half as much.
ppr_preaching_hostile_alms_mult_value = 0.5

# Piety in a land of hostile faith: few listen, so half as much too.
ppr_preaching_hostile_piety_mult_value = 0.5

# --- Wandering Preacher (commander trait, common/traits/ppr_traits.txt) ---
# Extra share of what a sermon earns when scope:preach_holy_commander (the army's commander,
# who has the trait) leads the missionaries: +10%, then +10% more at 33, 66 and 100 experience.
ppr_wandering_preacher_bonus_value = {
	value = 0
	if = {
		limit = { exists = scope:preach_holy_commander }
		add = 0.1
		if = {
			limit = {
				scope:preach_holy_commander = {
					has_trait_xp = {
						trait = ppr_wandering_preacher
						value >= 33
					}
				}
			}
			add = 0.1
		}
		if = {
			limit = {
				scope:preach_holy_commander = {
					has_trait_xp = {
						trait = ppr_wandering_preacher
						value >= 66
					}
				}
			}
			add = 0.1
		}
		if = {
			limit = {
				scope:preach_holy_commander = {
					has_trait_xp = {
						trait = ppr_wandering_preacher
						value >= 100
					}
				}
			}
			add = 0.1
		}
	}
}

# Commander scope. Experience per sermon, exactly like the Pillager's per completed raid (vanilla
# on_raid_action_completion: 0.5 + martial / 10), with learning instead of martial.
ppr_wandering_preacher_xp_value = {
	value = 0.5
	add = {
		value = learning
		divide = 10
	}
}

# Commander scope. Chance (%) per sermon to become a Wandering Preacher, from the 3rd sermon led.
ppr_wandering_preacher_gain_chance_value = {
	value = 15
	add = learning
	if = {
		limit = {
			OR = {
				has_trait = zealous
				has_trait = pilgrim
				has_trait = devoted
			}
		}
		add = 10
	}
	max = 50
}

# --- The missionaries' purse ---
# The engine's barter purse is never handed over for a landless adventurer (no "own territory") and
# cannot be emptied by script, so each missionary army keeps its own purse in army variables
# (ppr_gold_carried, ppr_piety_carried), paid at the camp by ppr_missionaries_home_effect.
# No purse limit: the provisions the missionaries carry already limit what a mission earns.
# This value needs scope:ppr_purse_army (the army) and is evaluated in its owner's scope.

# What the army carries now (gold + piety; piety lost to jeering crowds counts as nothing).
ppr_alms_carried_value = {
	value = 0
	if = {
		limit = { scope:ppr_purse_army = { has_variable = ppr_gold_carried } }
		add = scope:ppr_purse_army.var:ppr_gold_carried
	}
	if = {
		limit = {
			scope:ppr_purse_army = {
				has_variable = ppr_piety_carried
				var:ppr_piety_carried > 0
			}
		}
		add = scope:ppr_purse_army.var:ppr_piety_carried
	}
}

# For message texts ([SCOPE.ScriptValue('...')]): amounts saved by the on_actions.
ppr_sermon_gain_display_value = {
	value = 0
	if = {
		limit = { exists = scope:ppr_sermon_gain }
		add = scope:ppr_sermon_gain
	}
}

ppr_alms_lost_display_value = {
	value = 0
	if = {
		limit = { exists = scope:ppr_alms_lost }
		add = scope:ppr_alms_lost
	}
}

# --- Fervor (vanilla faith fervor) when a preaching mission wins souls ---
# Kept tiny: vanilla fervor only grows by 0.5 a year on its own (define YEARLY_FERVOR_GROWTH) and its scripted
# gains are rare, realm-wide feats (smallest step: miniscule_fervor_value = 10). One county = one year of growth.
ppr_preaching_fervor_county_value = 0.5	# a county takes up the faith (ppr_preaching.0010)
ppr_preaching_fervor_lord_value = 1	# a lord converts (ppr_preaching.0001 / 0002)
