set_WE_active = { set_variable = { war_exhaustion_start_up = 3 } }
set_WE_month_2 = { set_variable = { war_exhaustion_start_up = 2 } }
set_WE_month_1 = { set_variable = { war_exhaustion_start_up = 1 } }
set_WE_month_0 = { set_variable = { war_exhaustion_start_up = 0 } }

verify_WE_to_WE_max = {
	#if = {
	#	limit = {
	#		check_variable = { war_exhaustion_value > war_exhaustion_max_value }
	#	}
	#	set_variable = { war_exhaustion_value = war_exhaustion_max_value }
	#}
	
	if = {
		limit = {
			check_variable = { war_exhaustion_value > 1 }
		}
		set_variable = { war_exhaustion_value = 1 }
	}
	if = {
		limit = {
			check_variable = { war_exhaustion_value < 0 }
		}
		set_variable = { war_exhaustion_value = 0 }
	}
}

debug_effect = {
	add_resource = {
		type = oil
		amount = 150
		state = 2
	}
}

change_WE_value_effect = {
	add_to_variable = { war_exhaustion_value = temp_war_exhaustion_value }
}

reset_WE_var = { 
	set_variable = { war_exhaustion_max_value = 1 }
	set_variable = { war_exhaustion_weekly_change = 0 }
	
	# LENGTH OF WAR — gentler linear ramp (divisor increased from 58400 to 175200)
	set_variable = {
		var = war_exhaustion_lenght_of_war_impact
		value = ROOT.days_at_war
	}
	
	divide_variable = {
		var = war_exhaustion_lenght_of_war_impact
		value = 175200
	}
	
	add_to_variable = {
		var = war_exhaustion_weekly_change
		value = war_exhaustion_lenght_of_war_impact
	}
	
	if = {
		limit = { has_war = no }
		
		subtract_from_variable = { war_exhaustion_max_value = 0.60 }
		
		# PEACETIME RECOVERY — stability-gated, not free
		if = {
			limit = { has_stability > 0.60 }
			subtract_from_variable = { war_exhaustion_weekly_change = 0.0070 }
		}
		else_if = {
			limit = { has_stability > 0.30 }
			subtract_from_variable = { war_exhaustion_weekly_change = 0.0035 }
		}
		# stability <= 0.30: no passive recovery
	}
	else = {
		
		# ECONOMY EXHAUSTION — continuous, baseline is civilian economy (CG expected = 0.35)
		# Anything below 0.35 adds exhaustion proportionally
		# Civilian economy (0.35): +0.000/week | Total mobilisation (0.15): +0.008/week
		set_variable = { war_exhaustion_cg_factor = 0.35 }
		subtract_from_variable = { war_exhaustion_cg_factor = modifier@consumer_goods_expected_value }
		if = {
			limit = { check_variable = { war_exhaustion_cg_factor < 0 } }
			set_variable = { war_exhaustion_cg_factor = 0 }
		}
		multiply_variable = { war_exhaustion_cg_factor = 0.03 }
		add_to_variable = { war_exhaustion_weekly_change = war_exhaustion_cg_factor }
		
		# CONSCRIPTION EXHAUSTION — continuous, baseline is volunteer only (conscription = 0.015)
		# Volunteer only (0.015): +0.000/week | Scraping the barrel (0.25): +0.009/week
		# Disarmed nation (0.01): tiny relief, clamped
		set_variable = { war_exhaustion_conscription_factor = modifier@conscription }
		subtract_from_variable = { war_exhaustion_conscription_factor = 0.015 }
		multiply_variable = { war_exhaustion_conscription_factor = 0.040 }
		if = {
			limit = { check_variable = { war_exhaustion_conscription_factor < -0.001 } }
			set_variable = { war_exhaustion_conscription_factor = -0.001 }
		}
		add_to_variable = { war_exhaustion_weekly_change = war_exhaustion_conscription_factor }
		
		# SURRENDER PROGRESS — dampened significantly (divisor 100 → 500)
		# At 50% SP: +0.001/week instead of old +0.005/week
		set_variable = {
			var = war_exhaustion_surrender_progress_impact
			value = ROOT.surrender_progress
		}
		divide_variable = {
			var = war_exhaustion_surrender_progress_impact
			value = 500
		}
		add_to_variable = {
			var = war_exhaustion_weekly_change
			value = war_exhaustion_surrender_progress_impact
		}
	}
	
	# CAPITULATION STOPGAP — zero out accumulation for capitulated nations
	if = {
		limit = { has_capitulated = yes }
		set_variable = { war_exhaustion_weekly_change = 0 }
	}
	
	# WAR SUPPORT DAMPENER
	# High war support = population motivated = WE grows slower
	# war_support cannot be read as a numeric variable in effect scope — use threshold bands
	# Bands approximate (1 - has_war_support* 0.5):
	#   WS > 80%: ×0.55 (~-45% accumulation)
	#   WS > 60%: ×0.65 (~-35% accumulation)
	#   WS > 40%: ×0.75 (~-25% accumulation)
	#   WS > 20%: ×0.85 (~-15% accumulation)
	#   WS <= 20%: ×1.00 (no dampening — population is done)
	# Only applies while at war — peace recovery unaffected
	if = {
		limit = {
			has_war = yes
			has_war_support > 0.80
		}
		multiply_variable = { war_exhaustion_weekly_change = 0.55 }
		set_variable = { war_exhaustion_ws_display = 45 }
	}
	else_if = {
		limit = {
			has_war = yes
			has_war_support > 0.60
		}
		multiply_variable = { war_exhaustion_weekly_change = 0.65 }
		set_variable = { war_exhaustion_ws_display = 35 }
	}
	else_if = {
		limit = {
			has_war = yes
			has_war_support > 0.40
		}
		multiply_variable = { war_exhaustion_weekly_change = 0.75 }
		set_variable = { war_exhaustion_ws_display = 25 }
	}
	else_if = {
		limit = {
			has_war = yes
			has_war_support > 0.20
		}
		multiply_variable = { war_exhaustion_weekly_change = 0.85 }
		set_variable = { war_exhaustion_ws_display = 15 }
	}
	else = {
		set_variable = { war_exhaustion_ws_display = 0 }
	}

	# PSYCHOLOGICAL SATURATION
	# Thresholds tightened: kicks in earlier (35/55/70/85 vs old 40/60/75/88)
	# Top tier tightened to 0.20x (was 0.25x)
	# Only applies to weekly accumulation — spike events bypass this naturally
	if = {
		limit = { 
			check_variable = { war_exhaustion_value > 0.35 } 
			check_variable = { war_exhaustion_weekly_change > 0 }
		}
		multiply_variable = { war_exhaustion_weekly_change = 0.80 }
	}
	if = {
		limit = { 
			check_variable = { war_exhaustion_value > 0.55 } 
			check_variable = { war_exhaustion_weekly_change > 0 }
		}
		multiply_variable = { war_exhaustion_weekly_change = 0.60 }
	}
	if = {
		limit = { 
			check_variable = { war_exhaustion_value > 0.70 } 
			check_variable = { war_exhaustion_weekly_change > 0 }
		}
		multiply_variable = { war_exhaustion_weekly_change = 0.40 }
	}
	if = {
		limit = { 
			check_variable = { war_exhaustion_value > 0.85 } 
			check_variable = { war_exhaustion_weekly_change > 0 }
		}
		multiply_variable = { war_exhaustion_weekly_change = 0.20 }
	}
	
	# END PSYCHOLOGICAL SATURATION

	add_to_variable = { war_exhaustion_value = war_exhaustion_weekly_change }
	multiply_variable = { war_exhaustion_weekly_change = 100 }
	
	verify_WE_to_WE_max = yes

	# WAR SUPPORT PENALTY — exponential curve (WE squared × -0.75)
	# Small early, accelerates hard at high WE — historically accurate
	# At 50% WE: -(0.50²) × 0.75 = -0.1875 (-18.75%)
	# At 75% WE: -(0.75²) × 0.75 = -0.4219 (-42.19%)
	# At 100% WE: -(1.00²) × 0.75 = -0.75   (-75.00%)
	set_variable = { we_war_support_factor = war_exhaustion_value }
	set_variable = { we_ws_squared = war_exhaustion_value }
	multiply_variable = { we_ws_squared = we_war_support_factor }
	multiply_variable = { we_ws_squared = -0.75 }
	set_variable = { we_war_support_factor = we_ws_squared }
	
	set_variable = { we_repair_speed_building_factor = war_exhaustion_value }
	multiply_variable = { we_repair_speed_building_factor = -0.35 }
	
	set_variable = { we_army_morale_factor = war_exhaustion_value }
	multiply_variable = { we_army_morale_factor = -0.25 }
	
	set_variable = { we_minimum_training_level = war_exhaustion_value }
	multiply_variable = { we_minimum_training_level = 0.45 }
	
	set_variable = { we_resistance_target = war_exhaustion_value }
	multiply_variable = { we_resistance_target = 0.40 }
	
	set_variable = { we_resistance_growth = war_exhaustion_value }
	multiply_variable = { we_resistance_growth = 0.40 }
	
	if = {
		limit = {
			NOT = {	has_dynamic_modifier = { modifier = war_exhaustion_modifiers } }
		}
		add_dynamic_modifier = { modifier = war_exhaustion_modifiers }
	}
	force_update_dynamic_modifier = yes
}