# from = country
# this = species

purge_normal = {
	pop_escape_chance = 0.05
	pop_decline_rate = 100 # 100 pops per month, overrides BASE_POP_DECLINE, will only work on purge types

	pop_group_modifier = {
		pop_happiness = -10
	}

	potential = {
		exists = from
		from = { NOT = { has_valid_civic = civic_hive_devouring_swarm } }
	}

	allow = {
		hidden_trigger = { exists = from }
		if = {
			limit = {
				OR = {
					is_lonely_hive_mind_pop = yes
					AND = {
						is_disconnected_drone_pop = yes
						from = {
							has_policy_flag = disconnected_drones_purge
						}
					}
				}
			}
			always = yes
		}
		else = {
			custom_tooltip = {
				fail_text = PURGES_ALLOWED
				OR = {
					from = {
						OR = {
							has_ethic = ethic_gestalt_consciousness
							has_valid_civic = civic_fanatic_purifiers
							has_policy_flag = purge_allowed
						}
					}
					from = { is_robotic_species = yes }
				}
			}
		}
	}
	ai_will_do = {
		factor = 3
		modifier = {
			factor = 0
			from = {
				has_valid_ai_personality = yes
				NOT = {
					has_ai_personality_behaviour = purger
				}
			}
		}
	}
}

purge_neutering = {
	pop_escape_chance = 0.0
	pop_decline_rate = 10

	pop_group_modifier = {
		pop_happiness = -0.2
	}

	potential = {
		from = { NOT = { has_ethic = ethic_gestalt_consciousness } }
		is_disconnected_drone_pop = no
	}

	allow = {
		hidden_trigger = { exists = from }
		custom_tooltip = {
			fail_text = "lonely_hive_mind_pops_kill_themselves_purge_type"
			is_lonely_hive_mind_pop = no
		}
		custom_tooltip = {
			fail_text = "disconnected_machine_pops_kill_themselves_citizenship"
			is_disconnected_machine_pop = no
		}
		custom_tooltip = {
			fail_text = PURGES_ALLOWED
			from = {
				OR = {
					has_ethic = ethic_gestalt_consciousness
					has_valid_civic = civic_fanatic_purifiers
					has_policy_flag = purge_allowed
				}
			}
		}
		custom_tooltip = {
			fail_text = "CANNOT_NEUTER_NON_SENTIENT_ROBOTS"
			OR = {
				is_robotic = no
				species_has_happiness_with_owner = from
			}
		}
	}

	ai_will_do = {
		factor = 10
		modifier = {
			factor = 0
			from = {
				is_egalitarian = no
			}
		}
		modifier = {
			factor = 0
			from = {
				has_valid_ai_personality = yes
				NOT = {
					has_ai_personality_behaviour = purger
				}
			}
		}
	}
}

purge_displacement = {
	pop_escape_chance = 1.0
	pop_decline_rate = 25

	pop_group_modifier = {
		pop_happiness = -0.3
		pop_housing_usage_mult = -0.50
	}

	pop_tooltip = DISPLACING

	potential = {
		exists = from
		if = {
			limit = {
				from = { is_machine_empire = yes }
			}
			from = {
				NOR = {
					has_valid_civic = civic_hive_devouring_swarm
					has_valid_civic = civic_machine_terminator
				}
			}
			NOR = {
				has_trait = trait_machine_unit
				has_trait = trait_mechanical
				AND = {
					from = { has_civic = civic_machine_assimilator }
					has_trait = trait_cybernetic
				}
			}
		}
		is_disconnected_drone_pop = no
		from = {
			NAND = {
				has_origin = origin_nomadic_purger
				overlord? = {
					has_policy_flag = nomad_total_war_purge
				}
			}
		}
	}

	allow = {
		hidden_trigger = { exists = from }

		custom_tooltip = {
			fail_text = "lonely_hive_mind_pops_kill_themselves_purge_type"
			is_lonely_hive_mind_pop = no
		}
		custom_tooltip = {
			fail_text = "disconnected_machine_pops_kill_themselves_citizenship"
			is_disconnected_machine_pop = no
		}
		custom_tooltip = {
			fail_text = "FANATIC_PURIFIERS_MUST_PURIFY"
			OR = {
				NOT = { from = { has_valid_civic = civic_fanatic_purifiers } }
				is_same_species = from
			}
		}
		custom_tooltip = {
			fail_text = "CANNOT_DISPLACE_NON_SENTIENT_ROBOTS"
			OR = {
				is_robotic = no
				species_has_happiness_with_owner = from
			}
		}
	}
	ai_will_do = {
		factor = 1
		modifier = {
			factor = 10
			from = {
				is_hive_empire = yes
				NOT = { has_valid_civic = civic_hive_strength_of_legions }
			}
		}
		modifier = {
			factor = 10
			from = {
				is_machine_empire = yes
			}
		}
	}
}

purge_labor_camps = {
	pop_escape_chance = 0.25
	pop_decline_rate = 50

	pop_group_modifier = {
		pop_happiness = -10
	}

	potential = {
		exists = from
		from = { NOT = { has_ethic = ethic_gestalt_consciousness } }
		is_disconnected_drone_pop = no
	}

	allow = {
		hidden_trigger = { exists = from }
		custom_tooltip = {
			fail_text = "lonely_hive_mind_pops_kill_themselves_purge_type"
			is_lonely_hive_mind_pop = no
		}
		custom_tooltip = {
			fail_text = "disconnected_machine_pops_kill_themselves_citizenship"
			is_disconnected_machine_pop = no
		}
		custom_tooltip = {
			fail_text = PURGES_ALLOWED
			from = {
				OR = {
					has_ethic = ethic_gestalt_consciousness
					has_valid_civic = civic_fanatic_purifiers
					has_policy_flag = purge_allowed
				}
			}
		}
	}
	ai_will_do = {
		factor = 5
		modifier = {
			factor = 0
			from = { allows_slavery = no }
		}
		modifier = {
			factor = 0
			from = {
				has_valid_ai_personality = yes
				NOT = {
					has_ai_personality_behaviour = purger
				}
			}
		}
	}
}

purge_matrix = {
	pop_escape_chance = 0.20
	pop_decline_rate = 50

	pop_group_modifier = {
		pop_happiness = -10
	}

	potential = {
		from = { is_machine_empire = yes }
	}

	allow = {
		hidden_trigger = { exists = from }
		custom_tooltip = {
			fail_text = CANNOT_LIVESTOCK_MATRIX_MACHINES
			NOR = {
				has_trait = trait_mechanical
				has_trait = trait_machine_unit
			}
		}
	}

	ai_will_do = {
		factor = 50
		modifier = {
			factor = 0
			from = { NOT = { has_valid_civic = "civic_machine_terminator" } }
		}
		modifier = {
			factor = 0
			from = {
				has_valid_ai_personality = yes
				NOT = {
					has_ai_personality_behaviour = purger
				}
			}
		}
	}
}

purge_processing = {
	pop_escape_chance = 0.20
	pop_decline_rate = 50

	pop_group_modifier = {
		pop_happiness = -10
	}

	potential = {
		exists = from
		from = { is_machine_empire = no }
		is_disconnected_drone_pop = no
	}

	allow = {
		hidden_trigger = { exists = from }
		custom_tooltip = {
			fail_text = CAN_NOT_EAT_MACHINES
			OR = {
				NOR = {
					has_trait = trait_mechanical
					has_trait = trait_machine_unit
				}
				from = { has_valid_civic = civic_hive_devouring_swarm }
				# devouring swarms can CRONCH. in edge cases.
			}
		}
		custom_tooltip = {
			fail_text = "lonely_hive_mind_pops_kill_themselves_purge_type"
			is_lonely_hive_mind_pop = no
		}
		custom_tooltip = {
			fail_text = PURGES_ALLOWED
			from = {
				OR = {
					has_ethic = ethic_gestalt_consciousness
					has_valid_civic = civic_fanatic_purifiers
					has_policy_flag = purge_allowed
					# AND = { #species rights are disabled for presapients
					#	has_policy_flag = pre_sapients_eat
					#	prev = {
					#		is_sapient = no
					#	}
					# }
				}
			}
		}
	}
	ai_will_do = {
		factor = 50
		modifier = {
			factor = 0
			NOR = {
				has_trait = trait_delicious
				from = { has_valid_civic = civic_hive_devouring_swarm }
				AND = {
					is_sapient = no
					from = {
						has_policy_flag = pre_sapients_eat
					}
					NOT = { has_trait = trait_nascent_stage }
				}
			}
		}
		modifier = {
			factor = 0
			from = {
				has_valid_ai_personality = yes
				NOR = {
					has_ai_personality_behaviour = purger
				}
			}
		}
	}
}

purge_necrophage = {
	pop_escape_chance = 0.25
	pop_decline_rate = 20

	pop_group_modifier = {
		pop_happiness = -0.5
	}

	potential = {
		exists = from
		from = {
			OR = {
				has_origin = origin_necrophage
				AND = {
					has_origin = origin_nomadic_purger
					overlord? = {
						has_origin = origin_necrophage
					}
				}
			}
			has_trait = trait_necrophage
			OR = {
				has_valid_civic = civic_fanatic_purifiers
				has_policy_flag = purge_allowed
			}
		}
	}

	allow = {
		hidden_trigger = { exists = from }
		custom_tooltip = {
			fail_text = CANNOT_NECROPHAGE_MACHINES
			is_robotic = no
		}
		if = {
			limit = {
				OR = {
					is_lonely_hive_mind_pop = no
					is_disconnected_drone_pop = no
				}
			}
			custom_tooltip = {
				fail_text = PURGES_ALLOWED
				from = {
					OR = {
						has_valid_civic = civic_fanatic_purifiers
						has_policy_flag = purge_allowed
					}
				}
			}
		}
	}
	ai_will_do = {
		factor = 200
	}
}

purge_cosmogenesis = {
	pop_escape_chance = 0.05
	pop_decline_rate = value:num_chip_slave_purge # 0.2 per pop used as neural chip

	pop_group_modifier = {
		pop_happiness = -0.33
	}

	potential = {
		always = no
	}

	allow = {
		always = yes
	}

	hidden = {
		always = yes
	}
}

purge_cosmogenesis_lathe_resettle = {
	pop_escape_chance = 0.05
	pop_decline_rate = 100

	pop_group_modifier = {
		pop_happiness = -0.33
	}

	potential = {
		from = {
			has_ascension_perk = ap_cosmogenesis
			any_owned_planet = {
				has_designation = col_cosmogenesis_world
			}
		}
		is_sapient = yes
	}
	ai_will_do = {
		factor = 15
	}
}

purge_clips = {
	pop_escape_chance = 0.2
	pop_decline_rate = 50

	pop_group_modifier = {
		pop_happiness = -10
	}

	potential = {
		exists = from
		from = {
			OR = {
				has_valid_civic = civic_machine_obsessional_directive
				AND = {
					has_origin = origin_nomadic_purger
					overlord? = {
						has_valid_civic = civic_machine_obsessional_directive
					}
				}
			}
			OR = {
				has_ascension_perk = ap_become_the_crisis
				has_valid_civic = civic_machine_terminator
				has_country_flag = paperclip_shamed
				has_policy_flag = purge_allowed
			}
		}
	}
	allow = {
		always = yes
	}
}

purge_sacrifice = {
	pop_escape_chance = 0.2
	pop_decline_rate = 50 # 1 pop per 2 months, overrides BASE_POP_DECLINE, will only work on purge types

	pop_group_modifier = {
		pop_happiness = -10
	}

	potential = {
		has_shroud_dlc = yes
		exists = from
		from = {
			OR = {
				has_country_flag = devour_war_active
				AND = {
					has_origin = origin_nomadic_purger
					overlord? = {
						has_country_flag = devour_war_active
					}
				}
			}
		}
	}

	ai_will_do = {
		factor = 100
	}
}
