﻿# Pilgrims and Preachers - religious camp purpose
# Additive: joins the vanilla camp_purpose law group through law_group_type.

@camp_purpose_prestige_cost = 1000

ppr_camp_purpose_pilgrims = {
	law_group_type = camp_purpose
	index = 7 # Vanilla uses 0-5, Pyrates' Merchants uses 6

	pass_phrase = camp_purpose_pass_phrase
	confirmation_title = camp_purpose_pass_phrase
	confirmation_button_text = camp_purpose_confirmation_button_text

	modifier = {
		monthly_piety_gain_mult = 0.2
		same_faith_opinion = 5
	}
	flag = uses_camp_purpose
	flag = can_change_succession_laws
	flag = laamp_contracts_weight_up_learning
	flag = laamp_contracts_weight_up_diplomacy_slight
	flag = ppr_contracts_weight_up_religious
	# Declared here so the engine knows this flag even without Pyrates (law flags are
	# validated). In Pyrates it only gives a slight learning weight on its own contracts.
	flag = pyr_laamp_contracts_weight_up_learning_slight

	# Camp unlocks (vanilla flags, so vanilla and Pyrates demolition logic keeps working).
	flag = unlocks_baggage_train_ascetics
	flag = unlocks_camp_fire_nightly_debates
	# Pilgrims-only internal buildings (common/domiciles/buildings/ppr_camp_buildings.txt).
	flag = ppr_unlocks_baggage_train_reliquary
	flag = ppr_unlocks_barber_tent_hospice
	flag = ppr_unlocks_camp_fire_vespers
	flag = ppr_unlocks_supply_tent_alms_chest
	flag = ppr_unlocks_camp_perimeter_palmers_watch

	can_keep = { realm_law_use_camp_purpose = yes }

	can_pass = {
		# Pyrates' Merchants purpose has fleet buildings that only its own purposes clean up.
		# Checked against the law in force: only Merchants carries this flag besides Pilgrims itself.
		custom_tooltip = {
			text = ppr_camp_purpose_pilgrims_not_from_merchants_tt
			NOT = { has_realm_law_flag = pyr_laamp_contracts_weight_up_learning_slight }
		}
	}

	pass_cost = {
		prestige = {
			if = {
				limit = {
					NOT = { has_realm_law_flag = can_change_purpose_for_free }
				}
				value = @camp_purpose_prestige_cost
			}
		}
	}

	on_pass = {
		# Remove modifiers.
		remove_law_related_modifiers_effect = yes
		# Remove inappropriate buildings.
		laamp_clear_inappropriate_buildings_effect = yes
		# Adjust flavourisation.
		remove_camp_purpose_flavourisation_variables_effect = yes
		set_variable = ppr_flavourise_camp_purpose_pilgrims
		add_character_modifier = ppr_missionary_carts_modifier
		local_arbitration_boon_set_purpose_effect = {
			MODIFIER = ppr_landless_local_arbitration_pilgrims_modifier
		}
	}

	# Vanilla purposes' on_pass don't know our buildings: clean them up once the new law is in place.
	on_revoke = {
		if = {
			limit = { has_character_modifier = ppr_missionary_carts_modifier }
			remove_character_modifier = ppr_missionary_carts_modifier
		}
		trigger_event = {
			id = ppr_building_events.0001
			delayed = yes
		}
	}

	# AI adventurers may take it too, like the vanilla purposes (same scale, 00_realm_laws.txt): only from the
	# default Wanderers purpose, weighed by pious or worldly traits. AI Pilgrims get the contracts, buildings and
	# camp events, but never go on preaching missions (can_start_bartering, zzz_ppr_rules.txt).
	ai_will_do = {
		if = {
			limit = {
				NOT = { has_realm_law = camp_purpose_wanderers }
			}
			value = 0
		}
		else = {
			value = 0
			# Faith
			if = {
				limit = { has_trait = zealous }
				add = 30
			}
			if = {
				limit = { has_trait = pilgrim }
				add = 30
			}
			if = {
				limit = { has_trait = devoted }
				add = 30
			}
			if = {
				limit = { has_trait = theologian }
				add = 20
			}
			if = {
				limit = { has_trait = education_learning }
				add = 20
			}
			if = {
				limit = { has_trait = cynical }
				add = -30
			}
			# Personality
			if = {
				limit = { has_trait = humble }
				add = 10
			}
			if = {
				limit = { has_trait = generous }
				add = 10
			}
			if = {
				limit = { has_trait = temperate }
				add = 10
			}
			if = {
				limit = { has_trait = greedy }
				add = -20
			}
			if = {
				limit = { has_trait = arrogant }
				add = -10
			}
		}
	}
}
