﻿# Peace Deals Expanded — values used by the war overview negotiation panel.
# ROOT is always the character composing the proposal. The active war and the
# opposing primary war leader are stored as variables by pde_open_treaty_effect.

pde_actor_warscore_value = {
	value = 0
	if = {
		limit = { exists = var:pde_treaty_war }
		var:pde_treaty_war = {
			if = {
				limit = { primary_attacker = root }
				add = attacker_war_score
			}
			else = {
				add = defender_war_score
			}
		}
	}
}

# A payer may commit all current liquid gold plus one complete year of positive
# income. This intentionally permits debt up to that future-income allowance.
pde_max_offer_gold_value = {
	value = gold
	add = {
		value = monthly_character_income
		multiply = 12
		min = 0
	}
	min = 0
	floor = yes
}

pde_max_demand_gold_value = {
	value = 0
	if = {
		limit = { exists = var:pde_treaty_opponent }
		var:pde_treaty_opponent = {
			add = gold
			add = {
				value = monthly_character_income
				multiply = 12
				min = 0
			}
		}
	}
	min = 0
	floor = yes
}

# Herd can only be exchanged between nomadic rulers. Unlike gold, negotiated
# herd cannot create debt: the payer's current herd is the hard cap.
pde_max_offer_herd_value = {
	value = 0
	if = {
		limit = { pde_nomadic_herd_exchange_available_trigger = yes }
		add = domicile.herd
	}
	min = 0
	floor = yes
}

pde_max_demand_herd_value = {
	value = 0
	if = {
		limit = { pde_nomadic_herd_exchange_available_trigger = yes }
		var:pde_treaty_opponent = { add = domicile.herd }
	}
	min = 0
	floor = yes
}

pde_default_offer_herd_value = {
	value = pde_max_offer_herd_value
	multiply = 0.25
	min = 1
	floor = yes
}

pde_default_demand_herd_value = {
	value = pde_max_demand_herd_value
	multiply = 0.25
	min = 1
	floor = yes
}
pde_offer_county_count_value = {
	value = 0
	if = {
		limit = { has_variable_list = pde_offer_counties }
		every_in_list = {
			variable = pde_offer_counties
			add = 1
		}
	}
}

pde_demand_county_count_value = {
	value = 0
	if = {
		limit = { has_variable_list = pde_demand_counties }
		every_in_list = {
			variable = pde_demand_counties
			add = 1
		}
	}
}

# The fixed yearly payment is 20% of the payer's annual income. It is stored at
# signature time, so later income changes do not silently rewrite the treaty.
pde_actor_annual_tribute_value = {
	value = monthly_character_income
	multiply = 2.4
	min = 1
	floor = yes
}

pde_opponent_annual_tribute_value = {
	value = 0
	if = {
		limit = { has_variable = pde_treaty_opponent }
		var:pde_treaty_opponent = { add = pde_actor_annual_tribute_value }
	}
}

# Severity of concessions offered by the player. Concessions make acceptance
# easier, hence they are added back in pde_deal_acceptance_value.
pde_offer_cost_value = {
	value = 0
	if = {
		limit = { has_variable = pde_offer_gold }
		add = {
			value = var:pde_offer_gold
			divide = {
				value = pde_max_offer_gold_value
				min = 1
			}
			multiply = 45
		}
	}
	if = {
		limit = { has_variable = pde_offer_herd }
		add = {
			value = var:pde_offer_herd
			divide = {
				value = pde_max_offer_herd_value
				min = 1
			}
			multiply = 45
		}
	}
	add = {
		value = pde_offer_county_count_value
		multiply = 22
	}
	if = { limit = { has_variable = pde_offer_tribute } add = 30 }
	if = { limit = { has_variable = pde_offer_suzerainty } add = 75 }
	if = { limit = { has_variable = pde_offer_claims } add = 18 }
	if = { limit = { has_variable = pde_offer_hostage } add = 18 }
	if = { limit = { has_variable = pde_offer_break_alliances } add = 22 }
	if = { limit = { has_variable = pde_offer_humiliation } add = 18 }
	if = { limit = { has_variable = pde_offer_prisoner_release } add = 12 }
	if = { limit = { has_variable = pde_offer_conversion } add = 40 }
	if = { limit = { has_variable = pde_offer_disarmament } add = 28 }
}

# Severity of demands imposed on the opponent.
pde_demand_cost_value = {
	value = 0
	if = {
		limit = { has_variable = pde_demand_gold }
		add = {
			value = var:pde_demand_gold
			divide = {
				value = pde_max_demand_gold_value
				min = 1
			}
			multiply = 45
		}
	}
	if = {
		limit = { has_variable = pde_demand_herd }
		add = {
			value = var:pde_demand_herd
			divide = {
				value = pde_max_demand_herd_value
				min = 1
			}
			multiply = 45
		}
	}
	add = {
		value = pde_demand_county_count_value
		multiply = 22
	}
	if = { limit = { has_variable = pde_demand_tribute } add = 30 }
	if = { limit = { has_variable = pde_demand_suzerainty } add = 75 }
	if = { limit = { has_variable = pde_demand_claims } add = 18 }
	if = { limit = { has_variable = pde_demand_hostage } add = 18 }
	if = { limit = { has_variable = pde_demand_break_alliances } add = 22 }
	if = { limit = { has_variable = pde_demand_humiliation } add = 18 }
	if = { limit = { has_variable = pde_demand_prisoner_release } add = 12 }
	if = { limit = { has_variable = pde_demand_conversion } add = 40 }
	if = { limit = { has_variable = pde_demand_disarmament } add = 28 }
}

pde_common_term_value = {
	value = 0
	if = { limit = { has_variable = pde_long_truce } add = 5 }
	if = { limit = { has_variable = pde_extended_truce } add = 8 }
	if = { limit = { has_variable = pde_forced_alliance } add = 5 }
}

# Positive values favour the proposer; negative values favour the opponent.
# The three-point dead zone keeps merely symbolic payments neutral.
pde_treaty_net_value = {
	value = pde_demand_cost_value
	subtract = pde_offer_cost_value
	round = yes
}
# Positive means the opposing AI accepts. War score is real leverage, while
# offered and demanded clauses are evaluated symmetrically.
pde_deal_acceptance_value = {
	value = pde_actor_warscore_value
	add = pde_offer_cost_value
	subtract = pde_demand_cost_value
	add = pde_common_term_value
	round = yes
}
