##########################################################################
# Decisions
##########################################################################
# Enable Population Controls
decision_enact_population_control = {
	owned_planets_only = yes
	sound = event_administrative_work
	icon = decision_politics

	resources = {
		category = decisions
		cost = {
			unity = 250
		}
	}

	potential = {
		owner = {
			NOT = { has_policy_flag = population_controls_not_allowed }
			is_regular_empire = yes
			is_individual_machine = no
		}
		NOT = { has_modifier = planet_population_control }
	}

	effect = {
		add_modifier = { modifier = "planet_population_control" days = -1 }
		IF = {
			limit = {
				has_modifier = planet_food_boost
			}
			remove_modifier = planet_food_boost
		}
	}

	ai_weight = {
		weight = 5
		modifier = { # don't enable if you have free housing and no city districts left to build
			factor = 0
			OR = {
				free_housing > 0
				num_free_districts = {
					type = any
					value > 0
				}
				has_building_construction = yes #Added since they're probably building housing
			}
		}
	}
}

decision_end_population_control = {
	owned_planets_only = yes
	sound = event_administrative_work
	icon = decision_politics

	resources = {
		category = decisions
	}

	potential = {
		has_modifier = planet_population_control
	}

	effect = {
		remove_modifier = "planet_population_control"
	}

	ai_weight = {
		weight = 20

		modifier = { # don't end if less than 100 housing
			factor = 0
			free_housing < 100
		}
	}
}

# Enable Population Controls Machine
decision_enact_population_control_gestalt = {
	owned_planets_only = yes
	sound = event_administrative_work
	icon = decision_politics

	resources = {
		category = decisions
		cost = {
			unity = 250
		}
	}

	potential = {
		owner = {
			is_gestalt = yes
			is_wilderness_empire = no
		}
		NOT = { has_modifier = planet_population_control_gestalt }
	}

	effect = {
		add_modifier = { modifier = "planet_population_control_gestalt" days = -1 } # if name changes, change in jobs too
	}

	ai_weight = {
		weight = 5
		modifier = { # don't enable if you have free housing and no city districts left to build
			factor = 0
			OR = {
				free_housing > 0
				num_free_districts = {
					type = any
					value > 0
				}
				has_building_construction = yes #Added since they're probably building housing
			}
		}
	}
}

decision_end_population_control_gestalt = {
	owned_planets_only = yes
	sound = event_administrative_work
	icon = decision_politics

	resources = {
		category = decisions
	}

	potential = {
		has_modifier = planet_population_control_gestalt
	}

	effect = {
		remove_modifier = "planet_population_control_gestalt"
	}

	ai_weight = {
		weight = 20
		modifier = { # don't end if less than 100 housing
			factor = 0
			free_housing < 100
		}
	}
}

# Stop Robot/Droid Assembly
decision_enact_robot_assembly_control = {
	owned_planets_only = yes
	sound = event_administrative_work
	icon = decision_politics

	resources = {
		category = decisions
		cost = {
			unity = 250
		}
	}

	potential = {
		owner = {
			OR = {
				AND = {
					is_regular_empire = yes
					NOT = { has_policy_flag = robots_outlawed }
					has_technology = tech_robotic_workers
					OR = {
						AND = {
							has_policy_flag = ai_full_rights
							has_policy_flag = population_controls_allowed
						}
						NOT = {
							has_policy_flag = ai_full_rights
						}
					}
				}
				is_individual_machine = yes
			}
		}
		NOT = { has_modifier = planet_robot_assembly_control }
	}

	effect = {
		add_modifier = { modifier = "planet_robot_assembly_control" days = -1 }
	}

	ai_weight = {
		weight = 5
		modifier = { # don't enable if you have free housing and no city districts left to build
			factor = 0
			OR = {
				free_housing > 0
				num_free_districts = {
					type = any
					value > 0
				}
				has_building_construction = yes #Added since they're probably building housing
			}
		}
	}
}

decision_end_robot_assembly_control = {
	owned_planets_only = yes
	sound = event_administrative_work
	icon = decision_politics

	resources = {
		category = decisions
	}

	potential = {
		has_modifier = planet_robot_assembly_control
	}

	effect = {
		remove_modifier = "planet_robot_assembly_control"
	}

	ai_weight = {
		weight = 20

		modifier = { # don't end if less than 100 housing
			factor = 0
			free_housing < 100
		}
	}
}


# Expel Excess Population
decision_expel_population = {
	owned_planets_only = yes
	sound = event_administrative_work
	icon = decision_expel_population

	resources = {
		category = decisions
		cost = {
			unity = 250
		}
	}

	potential = {
		owner = {
			is_regular_empire = yes
			NOT = { has_policy_flag = population_controls_not_allowed }
		}
	}


	allow = {
		free_housing < 0
		NOT = { has_modifier = planet_population_expelled }
		custom_tooltip = {
			fail_text = "decision_expel_population_fail_tooltip"
			any_owned_pop_group = {
				can_think = yes
				NOR = {
					has_trait = trait_hive_mind
					is_non_sapient_robot = yes
					is_pop_category = ruler
				}
			}
		}
	}


	effect = {
		custom_tooltip = decision_expel_population_effects
		add_modifier = { modifier = "planet_population_expelled" days = 1800 }
		hidden_effect = {
			reroll_random = yes
			switch = {
				trigger = free_housing
				-900 < { set_variable = { which = expel_pop_var value = 10 } } # 10
				-800 < { set_variable = { which = expel_pop_var value = 9 } } # 9
				-700 < { set_variable = { which = expel_pop_var value = 8 } } # 8
				-600 < { set_variable = { which = expel_pop_var value = 7 } } # 7
				-500 < { set_variable = { which = expel_pop_var value = 6 } } # 6
				-400 < { set_variable = { which = expel_pop_var value = 5 } } # 5
				-300 < { set_variable = { which = expel_pop_var value = 4 } } # 4
				-200 < { set_variable = { which = expel_pop_var value = 3 } } # 3
				-100 < { set_variable = { which = expel_pop_var value = 2 } } # 2
				0 < { set_variable = { which = expel_pop_var value = 1 } } # 1
			}
			while = {
				count = expel_pop_var

				weighted_random_owned_pop_group = {
					limit = {
						can_think = yes
						NOR = {
							has_trait = trait_hive_mind
							is_non_sapient_robot = yes
							is_pop_category = ruler
						}
					}
					weights = {
						# can use add or mult
						base = 1
						modifier = {
							add = 100
							is_pop_category = purge
						}
						modifier = {
							factor = 5
							is_unemployed = yes
						}
						modifier = {
							factor = 10
							has_citizenship_rights = no
						}
						modifier = {
							add = 10
							OR = {
								is_pop_category = worker
								is_enslaved = yes
							}
						}
					}
					if = {
						limit = { is_valid_refugee_pop = yes }
						save_event_target_as = refugee_pop #Must be saved for refugee_pop_effect to work
						refugee_pop_effect = yes
					}
					else = {
						kill_single_pop = yes
					}
				}
			}
			clear_variable = expel_pop_var
		}
	}

	ai_weight = {
		weight = 0
	}
}

# Discourage Growth
decision_discourage_growth = {
	owned_planets_only = yes
	sound = event_administrative_work
	icon = decision_politics

	resources = {
		category = decisions
		cost = {
			unity = 250
		}
	}

	potential = {
		owner = {
			has_policy_flag = population_controls_not_allowed
			is_individual_machine = no
		}
		NOT = { has_modifier = planet_growth_discouraged }
	}
	effect = {
		add_modifier = { modifier = "planet_growth_discouraged" days = -1 }
		remove_modifier = planet_food_boost
	}

	ai_weight = {
		weight = 5
		modifier = { # don't enable if you have free housing and no city districts left to build
			factor = 0
			OR = {
				free_housing > 0
				num_free_districts = {
					type = any
					value > 0
				}
				has_building_construction = yes #Added since they're probably building housing
			}
		}
	}
}

decision_end_discourage_growth = {
	owned_planets_only = yes
	sound = event_administrative_work
	icon = decision_politics

	resources = {
		category = decisions
	}

	potential = {
		has_modifier = planet_growth_discouraged
	}

	effect = {
		remove_modifier = "planet_growth_discouraged"
	}

	ai_weight = {
		weight = 20

		modifier = { # don't end if less than 100 housing
			factor = 0
			free_housing < 100
		}
	}
}
