on_actions = {
	on_startup = {
		effect = {
			every_country = {
				limit = {
					tag = THIS
				}
				set_variable = { war_exhaustion_max_value = 1 }
				set_WE_active = yes
			}
		}
	}
	
	on_daily = {
		effect = {
			if = {

			limit = {

				has_war = yes

			}

			add_to_variable = {
				var = ROOT.days_at_war
				value = 1
			}

		}

		if = {

			limit = {

				has_war = no

			}

			set_variable = { var = ROOT.days_at_war value = 0 }

		}
		}
	}
	
	on_weekly = {
		effect = {
			reset_WE_var = yes
			
			subtract_from_variable = { WE_consecutive_wars = 1 }
			if = {
				limit = {
					check_variable = { WE_consecutive_wars < 0 }
				}
				set_variable = { WE_consecutive_wars = 0 }
			}
			if = {
				limit = {
					check_variable = { WE_consecutive_wars > 10 }
				}
				set_variable = { WE_consecutive_wars = 0 }
			}
		}
	}
	
	on_nuke_drop = {
		effect = {
			# Increment nuke counter on the target nation
			FROM.owner = {
				add_to_variable = { war_exhaustion_nukes_received = 1 }
			}

			if = {
				limit = { has_dynamic_modifier = { modifier = fallout_thermonuclear } }

				# THERMONUCLEAR — Ivy Mike tier, region-killing yield
				# 1st strike: +35% | 2nd: +25% | 3rd+: +17%
				FROM.owner = {
					if = {
						limit = { check_variable = { war_exhaustion_nukes_received < 2 } }
						add_to_variable = { war_exhaustion_value = 0.35 }
					}
					else_if = {
						limit = { check_variable = { war_exhaustion_nukes_received < 3 } }
						add_to_variable = { war_exhaustion_value = 0.25 }
					}
					else = {
						add_to_variable = { war_exhaustion_value = 0.17 }
					}
					verify_WE_to_WE_max = yes
				}
			}
			else = {
				# FISSION — Hiroshima/Nagasaki tier
				# 1st strike: +15% | 2nd: +10% | 3rd+: +7%
				FROM.owner = {
					if = {
						limit = { check_variable = { war_exhaustion_nukes_received < 2 } }
						add_to_variable = { war_exhaustion_value = 0.15 }
					}
					else_if = {
						limit = { check_variable = { war_exhaustion_nukes_received < 3 } }
						add_to_variable = { war_exhaustion_value = 0.10 }
					}
					else = {
						add_to_variable = { war_exhaustion_value = 0.07 }
					}
					verify_WE_to_WE_max = yes
				}
			}
		}
	}
	
	on_state_control_changed = {
		effect = {
			# CAPITAL — one-time spike, loser takes the hit, taker gets relief
			if = {
				limit = {
					FROM.FROM = { is_capital = yes }
					has_war = yes
					NOT = { has_country_flag = original_capital_taken }
				}
				FROM = {
					add_to_variable = { war_exhaustion_value = 0.10 }
					verify_WE_to_WE_max = yes
				}
				ROOT = {
					add_to_variable = { war_exhaustion_value = -0.10 }
					verify_WE_to_WE_max = yes
					set_country_flag = original_capital_taken
				}
			}

			# STATE SIZE — loser takes WE hit, taker gets smaller relief
			# ROOT = taker, FROM = loser
			if = {
				limit = {
					FROM.FROM = { is_megalopolis_state = yes }
					has_war = yes
				}
				FROM = {
					add_to_variable = { war_exhaustion_value = 0.05 }
					verify_WE_to_WE_max = yes
				}
				ROOT = {
					add_to_variable = { war_exhaustion_value = -0.04 }
					verify_WE_to_WE_max = yes
				}
			}
			else_if = {
				limit = {
					FROM.FROM = { is_metropolis_state = yes }
					has_war = yes
				}
				FROM = {
					add_to_variable = { war_exhaustion_value = 0.04 }
					verify_WE_to_WE_max = yes
				}
				ROOT = {
					add_to_variable = { war_exhaustion_value = -0.03 }
					verify_WE_to_WE_max = yes
				}
			}
			else_if = {
				limit = {
					FROM.FROM = { is_large_city_state = yes }
					has_war = yes
				}
				FROM = {
					add_to_variable = { war_exhaustion_value = 0.03 }
					verify_WE_to_WE_max = yes
				}
				ROOT = {
					add_to_variable = { war_exhaustion_value = -0.02 }
					verify_WE_to_WE_max = yes
				}
			}
			else_if = {
				limit = {
					FROM.FROM = { is_city_state = yes }
					has_war = yes
				}
				FROM = {
					add_to_variable = { war_exhaustion_value = 0.02 }
					verify_WE_to_WE_max = yes
				}
				ROOT = {
					add_to_variable = { war_exhaustion_value = -0.01 }
					verify_WE_to_WE_max = yes
				}
			}
			else_if = {
				limit = {
					FROM.FROM = { is_large_town_state = yes }
					has_war = yes
				}
				FROM = {
					add_to_variable = { war_exhaustion_value = 0.01 }
					verify_WE_to_WE_max = yes
				}
				# taker gets nothing — taking a large town isn't a morale event
			}
			# Town and Rural — no WE change for either side
		}
	}
	
	on_war = {
		effect = {
			THIS = {
				add_to_variable = { WE_consecutive_wars = 1 }
				if = {
					limit = {
						check_variable = { WE_consecutive_wars > 1 }
					}
					add_to_variable = { war_exhaustion_value = 0.05 }
				}
			}
		}
	}
}