#THIS is state
decrease_population_on_nuke = {
	log = "[GetDateText]: Nuke dropped on [This.GetName], owner [This.owner.GetName], dropped by [Root.GetName]"
	set_temp_variable = { temp_var = random } #0 to 1
	owner = { set_temp_variable = { PREV.prenuke_country_manpower = manpower_k } }
	if = {
		limit = { state_population > 999999 }
		set_temp_variable = { pop_to_kill = state_population_k }
		set_state_flag = state_population_thousands
	}
	else = {
		set_temp_variable = { pop_to_kill = state_population }
	}
	if = {
		limit = { has_state_category = megalopolis } #20 kt bomb in a very dense urban region - 250,000 - 300,000 casualties
		multiply_temp_variable = { temp_var = 50000 } # 300,000 - 250,000
		add_to_temp_variable = { temp_var = 250000 }
		set_temp_variable = { pop_to_kill = temp_var }
		clr_state_flag = state_population_thousands
		if = {
			limit = {
				OR  = {
					state_population < 800000
					has_state_flag = recently_nuked
				}
			}
			set_temp_variable = { temp_var = random } #0 to 1
			multiply_temp_variable = { temp_var = 0.05 } # 0.1 - 0.05
			add_to_temp_variable = { temp_var = 0.05 }
			multiply_temp_variable = { pop_to_kill = temp_var }
		}
	}
	else_if = {
		limit = { has_state_category = metropolis } #20 kt bomb in a dense urban region - 175,000 - 250,000 casualties
		multiply_temp_variable = { temp_var = 75000 } # 250,000 - 175,000
		add_to_temp_variable = { temp_var = 175000 }
		set_temp_variable = { pop_to_kill = temp_var }
		clr_state_flag = state_population_thousands
		if = {
			limit = {
				OR  = {
					state_population < 600000
					has_state_flag = recently_nuked
				}
			}
			set_temp_variable = { temp_var = random } #0 to 1
			multiply_temp_variable = { temp_var = 0.05 } # 0.1 - 0.05
			add_to_temp_variable = { temp_var = 0.05 }
			multiply_temp_variable = { pop_to_kill = temp_var }
		}
	}
	else_if = {
		limit = { has_state_category = large_city } #20 kt bomb in an urban region - 100,000 - 150,000 casualties
		multiply_temp_variable = { temp_var = 75000 } # 250,000 - 175,000
		add_to_temp_variable = { temp_var = 175000 }
		set_temp_variable = { pop_to_kill = temp_var }
		clr_state_flag = state_population_thousands
		if = {
			limit = {
				OR  = {
					state_population < 500000
					has_state_flag = recently_nuked
				}
			}
			set_temp_variable = { temp_var = random } #0 to 1
			multiply_temp_variable = { temp_var = 0.05 } # 0.1 - 0.05
			add_to_temp_variable = { temp_var = 0.05 }
			multiply_temp_variable = { pop_to_kill = temp_var }
		}
	}
	else_if = {
		limit = { has_state_category = city } #20 kt bomb in a sparse urban region - 50,000 - 100,000 casualties
		multiply_temp_variable = { temp_var = 50000 } # 100,000 - 50,000
		add_to_temp_variable = { temp_var = 50000 }
		set_temp_variable = { pop_to_kill = temp_var }
		clr_state_flag = state_population_thousands
		if = {
			limit = {
				OR  = {
					state_population < 500000
					has_state_flag = recently_nuked
				}
			}
			set_temp_variable = { temp_var = random } #0 to 1
			multiply_temp_variable = { temp_var = 0.05 } # 0.1 - 0.05
			add_to_temp_variable = { temp_var = 0.05 }
			multiply_temp_variable = { pop_to_kill = temp_var }
		}
	}
	else_if = {
		limit = { has_state_category = large_town } #20 kt bomb in a very sparse urban region - 20,000 - 80,000 casualties
		multiply_temp_variable = { temp_var = 60000 } # 80,000 - 20,000
		add_to_temp_variable = { temp_var = 20000 }
		set_temp_variable = { pop_to_kill = temp_var }
		clr_state_flag = state_population_thousands
		if = {
			limit = {
				OR  = {
					state_population < 400000
					has_state_flag = recently_nuked
				}
			}
			set_temp_variable = { temp_var = random } #0 to 1
			multiply_temp_variable = { temp_var = 0.05 } # 0.1 - 0.05
			add_to_temp_variable = { temp_var = 0.05 }
			multiply_temp_variable = { pop_to_kill = temp_var }
		}
	}
	else_if = {
		limit = { has_state_category = town } #20 kt bomb in a developed rural region - 20,000 - 50,000 casualties
		multiply_temp_variable = { temp_var = 30000 } # 50,000 - 20,000
		add_to_temp_variable = { temp_var = 20000 }
		set_temp_variable = { pop_to_kill = temp_var }
		clr_state_flag = state_population_thousands
		if = {
			limit = {
				OR  = {
					state_population < 300000
					has_state_flag = recently_nuked
				}
			}
			set_temp_variable = { temp_var = random } #0 to 1
			multiply_temp_variable = { temp_var = 0.05 } # 0.1 - 0.05
			add_to_temp_variable = { temp_var = 0.05 }
			multiply_temp_variable = { pop_to_kill = temp_var }
		}
	}
	else_if = {
		limit = { has_state_category = rural } #20 kt bomb in a rural region - 5,000 - 25,000 casualties
		multiply_temp_variable = { temp_var = 20000 } # 25,000 - 5,000
		add_to_temp_variable = { temp_var = 5000 }
		set_temp_variable = { pop_to_kill = temp_var }
		clr_state_flag = state_population_thousands
		if = {
			limit = {
				OR  = {
					state_population < 200000
					has_state_flag = recently_nuked
				}
			}
			set_temp_variable = { temp_var = random } #0 to 1
			multiply_temp_variable = { temp_var = 0.05 } # 0.1 - 0.05
			add_to_temp_variable = { temp_var = 0.05 }
			multiply_temp_variable = { pop_to_kill = temp_var }
		}
	}
	else_if = {
		limit = { has_state_category = pastoral } #20 kt bomb in a sparse rural region - 500 - 2,500 casualties
		multiply_temp_variable = { temp_var = 1000 } # 2500 - 500
		add_to_temp_variable = { temp_var = 500 }
		set_temp_variable = { pop_to_kill = temp_var }
		clr_state_flag = state_population_thousands
		if = {
			limit = {
				OR  = {
					state_population < 200000
					has_state_flag = recently_nuked
				}
			}
			set_temp_variable = { temp_var = random } #0 to 1
			multiply_temp_variable = { temp_var = 0.05 } # 0.1 - 0.05
			add_to_temp_variable = { temp_var = 0.05 }
			multiply_temp_variable = { pop_to_kill = temp_var }
		}
	}
	else_if = {
		limit = { has_state_category = small_island } #20 kt bomb on a small island - 20% - 50%
		multiply_temp_variable = { temp_var = 0.3 } # 0.5 - 0.2
		add_to_temp_variable = { temp_var = 0.2 }
		multiply_temp_variable = { pop_to_kill = temp_var }
		if = {
			limit = {
				has_state_flag = recently_nuked
			}
			multiply_temp_variable = { pop_to_kill = 0.2 }
		}
	}
	else_if = {
		limit = { has_state_category = tiny_island } #20 kt bomb on a tiny island - 30% - 75%
		multiply_temp_variable = { temp_var = 0.45 } # 0.75 - 0.3
		add_to_temp_variable = { temp_var = 0.3 }
		multiply_temp_variable = { pop_to_kill = temp_var }
		if = {
			limit = {
				has_state_flag = recently_nuked
			}
			multiply_temp_variable = { pop_to_kill = 0.2 }
		}
	}
	else_if = {
		limit = { has_state_category = wasteland } #20 kt bomb on a literally nothing - 0 - 1%
		multiply_temp_variable = { pop_to_kill = temp_var }
		if = {
			limit = {
				has_state_flag = recently_nuked
			}
			multiply_temp_variable = { pop_to_kill = 0.2 }
		}
	}
	else_if = {
		limit = { has_state_category = enclave } #20 kt bomb on a an enclave - 40% - 75%
		multiply_temp_variable = { temp_var = 0.35 } # 0.75 - 0.4
		add_to_temp_variable = { temp_var = 0.4 }
		multiply_temp_variable = { pop_to_kill = temp_var }
		if = {
			limit = {
				has_state_flag = recently_nuked
			}
			multiply_temp_variable = { pop_to_kill = 0.2 }
		}
	}
	if = {
		limit = { PREV = { has_tech = nukes_2 } } #25kt - 30kt
		multiply_temp_variable = { pop_to_kill = 1.1 }
	}
	if = {
		limit = { PREV = { has_tech = nukes_3 } } #30kt - 35kt
		multiply_temp_variable = { pop_to_kill = 1.1 }
	}
	if = {
		limit = { THIS = { has_tech = future_radar_4 } } # early warning allows for some level of protection
		multiply_temp_variable = { pop_to_kill = 0.8 }
	}
	owner = {
		set_temp_variable = {
			civil_defence_factor = modifier@industry_air_damage_factor
		}
		divide_temp_variable = {
			civil_defence_factor = 3
		}
		add_to_temp_variable = {
			civil_defence_factor = 1
		}
		clamp_temp_variable = {
			var = civil_defence_factor
			min = 0.5
			max = 1.25
		}
		multiply_temp_variable = { pop_to_kill = civil_defence_factor }
	}
	if = {
		limit = {
			has_state_flag = state_population_thousands
		}
		log = "Nuke dropped on [This.GetName], state_population_thousands, expected [?pop_to_kill]*1000 casualties"
		while_loop_effect = {
			limit = { check_variable = { pop_to_kill > 999 } }
			log = "Nuke dropped on [This.GetName], 1000000 dead"
			subtract_from_temp_variable = { pop_to_kill = 1000 }
			add_manpower = -1000000
		}
		multiply_temp_variable = { pop_to_kill = 1000 }
	}
	round_temp_variable = pop_to_kill
	log = "Nuke dropped on [This.GetName], [?pop_to_kill] dead"
	multiply_temp_variable = { pop_to_kill = -1 }
	add_manpower = pop_to_kill

	#take care of country manpower change
	owner = { set_temp_variable = { PREV.afternuke_country_manpower = manpower_k } }
	log = "Nuke dropped on [This.GetName], prenuke_country_manpower [?prenuke_country_manpower], afternuke_country_manpower [?afternuke_country_manpower]"
	subtract_from_temp_variable = { afternuke_country_manpower = prenuke_country_manpower }
	while_loop_effect = {
		limit = { check_variable = { afternuke_country_manpower > 9 } }
		log = "Nuke dropped on [This.GetName], afternuke_country_manpower adjustment, 10000 removed"
		subtract_from_temp_variable = { afternuke_country_manpower = 10 }
		owner = { add_manpower = -10000 }
	}
	multiply_temp_variable = { afternuke_country_manpower = 1000 }
	round_temp_variable = afternuke_country_manpower
	log = "Nuke dropped on [This.GetName], afternuke_country_manpower adjustment, [?afternuke_country_manpower] removed"
	multiply_temp_variable = { afternuke_country_manpower = -1 }
	owner = { add_manpower = afternuke_country_manpower }

	# if = {
	# 	limit = {
	# 		NOT = { has_state_flag = recently_nuked }
	# 	}
	# 	log = "Nuke dropped on [This.GetName], not recently nuked"
	# 	add_province_modifier = {
	# 		static_modifiers = { nuked }
	# 		province = {
	# 			all_provinces = yes
	# 		}
	# 	}
	# 	add_state_modifier = {
	# 		modifier = {
	# 			local_supplies = -0.35
	# 			local_factories = -0.15
	# 		}
	# 	}
	# 	set_state_flag = nuke_modifier
	# }
	set_state_flag = { flag = recently_nuked value = 1 days = 360 }
	clr_state_flag = state_population_thousands
	owner = { country_event = { id = utility.3 days = 361 } }
}
import_sand = {
	hidden_effect = {
		country_event = { id = katerin.152 days = 28 }
	}
}
summon_goat_council = {
	hidden_effect = {
		if = {
			limit = {
				AND = {
					has_country_flag = indeed_i_visited_katerin
					has_country_flag = yes_i_visited_jakistan_too
					has_country_flag = and_zwadai_also
				}
			}
			set_country_flag = ready_for_next_stage_now
		}
		else = {
			country_event = { id = temple.12 days = 1 }
		}
	}
}