automate_crime_management = {
	should_ai_use_job_micro = yes

	available = {
		exists = owner
		owner = { is_gestalt = no }
	}

	emergency = yes
	category = "planet_automation_crime"

	buildings = {
		precinct = {
			building = building_precinct_house
			available = {
				planet_crime > 30
				NOT = { has_available_jobs = enforcer }
				NOT = { has_forbidden_jobs = enforcer }
				any_owned_pop_group = { can_work_specific_job = enforcer }
				NOR = {
					AND = {
						has_building = building_precinct_house
						owner = { has_technology = tech_colonial_centralization }
					}
					has_building = building_hall_judgment
					num_buildings = { type = building_precinct_house value >= 3 }
				}
			}
		}
		state_academy = {
			building = building_state_academy
			available = {
				planet_crime > 30
				NOR = {
					AND = {
						has_building = building_state_academy
						owner = { has_technology = tech_colonial_centralization }
					}
					has_building = building_center_of_guidance
					num_buildings = { type = building_state_academy value >= 3 }
				}
			}
		}
	}

	job_changes = { #No increase or decrease for educators as it's a really good job
		enforcer_reduce = {
			available = {
				planet_crime < 1
			}

			job = enforcer
			amount = -1
		}

		enforcer_increase = {
			available = {
				planet_crime > 25
			}

			job = enforcer
			amount = 10
		}
	}
}

automate_crime_management_gestalt = {
	should_ai_use_job_micro = yes

	available = {
		exists = owner
		owner = { is_gestalt = yes }
	}

	emergency = yes
	category = "planet_automation_crime"

	buildings = {
		precinct = {
			available = {
				planet_crime > 30
				NOT = { has_available_jobs = patrol_drone }
				NOT = { has_forbidden_jobs = patrol_drone }
			}

			building = building_sentinel_posts
		}
	}

	job_changes = {
		job_patrol_drone_add_reduce = {
			available = {
				planet_crime < 1
			}

			job = patrol_drone
			amount = -1
		}

		job_patrol_drone_add_increase = {
			available = {
				planet_crime > 25
			}

			job = patrol_drone
			amount = 10
		}
	}
}

automate_building_housing = {
	available = {
		free_housing < 0
	}

	emergency = yes
	category = "planet_automation_housing"

	prio_districts = {
		district_hab_housing
		district_arcology_housing
		district_rw_nexus
		district_city
		district_hive
		district_nexus
	}
}

automate_biotrophy_management_servitor_ecu = {
	available = {
		owner = {
			is_machine_empire = yes
			has_valid_civic = civic_machine_servitor
		}

		uses_district_set = city_world
		free_district_slots > 0
		any_owned_pop_group = {
			is_unemployed = yes
			has_citizenship_type = { type = citizenship_organic_trophy country = owner }
		}
	}

	emergency = yes
	category = "planet_automation_biotrophy_management"

	prio_districts = {
		district_arcology_organic_housing
	}
}

automate_biotrophy_management_servitor_hab = {
	available = {
		owner = {
			is_machine_empire = yes
			has_valid_civic = civic_machine_servitor
		}

		uses_district_set = habitat
		free_district_slots > 0
		any_owned_pop_group = {
			is_unemployed = yes
			has_citizenship_type = { type = citizenship_organic_trophy country = owner }
		}
	}

	emergency = yes
	category = "planet_automation_biotrophy_management"
}

automate_hive_spawning_pool = {
	available = {
		owner = { is_hive_empire = yes }
	}

	emergency = yes
	category = "planet_automation_pop_assembly"

	buildings = {
		assembly = {
			building = building_spawning_pool
		}
	}
}

automate_machine_assembly = {
	available = {
		owner = { is_machine_empire = yes }
	}

	emergency = yes
	category = "planet_automation_pop_assembly"

	buildings = {
		assembly = {
			building = building_machine_assembly_plant
		}
	}
}

automate_robotic_pop_assembly = {
	available = {
		owner = {
			NOT = { has_policy_flag = robots_outlawed }
		}
	}

	emergency = yes
	category = "planet_automation_pop_assembly"

	buildings = {
		assembly = {
			building = building_robot_assembly_plant
		}
	}
}

automate_bio_cloning = {
	available = {
		owner = { has_technology = tech_cloning }
	}

	emergency = yes
	category = "planet_automation_pop_assembly"

	buildings = {
		assembly = {
			building = building_clone_vats
		}
	}
}

automate_biotrophy_management_servitor = {
	available = {
		owner = {
			is_machine_empire = yes
			has_valid_civic = civic_machine_servitor
		}
		free_building_slots > 1
		any_owned_pop_group = {
			is_unemployed = yes
			has_citizenship_type = { type = citizenship_organic_trophy country = owner }
		}
	}

	emergency = yes
	category = "planet_automation_biotrophy_management"

	buildings = {
		sanctuary = {
			building = building_organic_sanctuary
		}
	}
}

automate_amenity_management = {
	available = {
		free_amenities < 0
		owner = {
			NOR = {
				is_machine_empire = yes
				is_hive_empire = yes
			}
		}
	}

	emergency = yes
	category = "planet_automation_amenities"

	buildings = {
		clinic = {
			building = building_medical_2
			available = {
				owner = { is_synthetic_empire = no }
				NOT = { has_available_jobs = entertainer }
				NOT = { has_available_jobs = healthcare }
				NOT = { has_forbidden_jobs = entertainer }
				NOT = { has_forbidden_jobs = healthcare }
				any_owned_pop_group = { can_work_specific_job = healthcare }
			}

			upgrade_trigger = {
				owner = { is_synthetic_empire = no }
				NOT = { has_available_jobs = entertainer }
				NOT = { has_available_jobs = healthcare }
				NOT = { has_forbidden_jobs = entertainer }
				NOT = { has_forbidden_jobs = healthcare }
				any_owned_pop_group = { can_work_specific_job = healthcare }
			}
		}

		holo = {
			building = building_holo_theatres
			available = {
				NOT = { has_available_jobs = entertainer }
				NOT = { has_available_jobs = healthcare }
				NOT = { has_forbidden_jobs = entertainer }
				NOT = { has_forbidden_jobs = healthcare }
				any_owned_pop_group = { can_work_specific_job = entertainer }
			}

			upgrade_trigger = {
				NOT = { has_available_jobs = entertainer }
				NOT = { has_available_jobs = healthcare }
				NOT = { has_forbidden_jobs = entertainer }
				NOT = { has_forbidden_jobs = healthcare }
				any_owned_pop_group = { can_work_specific_job = entertainer }
			}
		}
		zoo = { building = building_xeno_zoo }
	}
}

automate_hive_amenity_management = {
	available = {
		free_amenities < 0
		owner = {
			OR = {
				is_machine_empire = yes
				is_hive_empire = yes
			}
		}
		NOT = { has_available_jobs = maintenance_drone }
		NOT = { has_forbidden_jobs = maintenance_drone }
	}

	emergency = yes
	category = "planet_automation_amenities"

	prio_districts = {
		district_hab_housing
		district_arcology_housing
		district_rw_nexus
		district_city
		district_hive
		district_nexus
	}
}

automate_amenity_management_ecu = {
	available = {
		free_amenities < 0
		owner = {
			NOR = {
				is_machine_empire = yes
				is_hive_empire = yes
			}
		}
		uses_district_set = city_world
		free_district_slots > 0
		NOT = { has_available_jobs = entertainer }
		NOT = { has_forbidden_jobs = entertainer }

		owner = {
			has_resource = { type = exotic_gases amount >= 75 }
		}
	}

	emergency = yes
	category = "planet_automation_amenities"

	prio_districts = {
		district_arcology_leisure
	}
}

automate_worm_love = {
	available = {
		owner = {
			has_technology = tech_akx_worm_3
			has_event_chain = WORM_CHAIN_1
			NOT = { has_country_flag = alignment_built }
		}
		is_capital = yes
		NOT = { has_building = building_akx_worm_3 }
	}

	emergency = yes
	category = "planet_automation_worm"

	buildings = {
		worm = {
			building = building_akx_worm_3
			available = { always = yes }
		}
	}
}

automate_crystal_deficit_management = {
	available = {
		owner = { has_monthly_income = { resource = rare_crystals value < 0 } }
		free_building_slots > 0
	}

	empire_wide_emergency = yes
	category = "planet_automation_rare_resources"

	buildings = {

		crystal_plant = {
			building = building_crystal_plant
			available = { #you really want to be building science/unity buildings instead of refineries on those designations
				has_research_designation = no
				has_unity_designation = no
				has_fortress_designation = no
			}
		}
	}
}

automate_mote_deficit_management = {
	available = {
		owner = { has_monthly_income = { resource = volatile_motes value < 0 } }
		free_building_slots > 0
	}

	empire_wide_emergency = yes
	category = "planet_automation_rare_resources"

	buildings = {

		chem_plant = {
			building = building_chemical_plant
			available = { #you really want to be building science/unity buildings instead of refineries on those designations
				has_research_designation = no
				has_unity_designation = no
				has_fortress_designation = no
			}
		}
	}
}

automate_gas_deficit_management = {
	available = {
		owner = { has_monthly_income = { resource = exotic_gases value < 0 } }
		free_building_slots > 0
	}

	empire_wide_emergency = yes
	category = "planet_automation_rare_resources"

	buildings = {
		refinery = {
			building = building_refinery
			available = { #you really want to be building science/unity buildings instead of refineries on those designations
				has_research_designation = no
				has_unity_designation = no
				has_fortress_designation = no
			}
		}
	}
}

automate_permanent_employment_building = {
	available = {
		owner = { has_valid_civic = civic_permanent_employment }
		NOT = { has_building = building_posthumous_employment_center }
		free_building_slots > 1
		NOR = {
			colony_type = col_industrial
			colony_type = col_foundry
			colony_type = col_factory
			colony_type = col_research
			colony_type = col_habitat_trade
			colony_type = col_habitat_foundry
			colony_type = col_habitat_factory
			colony_type = col_habitat_research
			colony_type = col_habitat_industrial
			colony_type = col_resort
			colony_type = col_pleasure
			colony_type = col_penal
			colony_type = col_ring_research
			colony_type = col_ring_trade
			colony_type = col_ecu_industrial
			colony_type = col_ecu_factory
			colony_type = col_ecu_foundry
			colony_type = col_ecu_research
			colony_type = col_bureau
			colony_type = col_habitat_bureau
		}
	}

	emergency = yes
	category = "planet_automation_permanent_employment_center"

	buildings = {
		posthumus = {
			building = building_posthumous_employment_center
		}
	}
}

automate_psi_corps_building = {
	available = {
		owner = {
			has_psionic_ascension = yes
		}
	}

	emergency = yes
	category = "planet_automation_psi_corps_building"

	buildings = {
		psi_corps = {
			building = building_psi_corps
		}
	}
}

automate_capital_building = {
	available = {
		owner = {
			NOR = {
				is_machine_empire = yes
				is_hive_empire = yes
			}
		}
	}
	emergency = yes
	category = "planet_automation_upgrade_buildings"

	buildings = {
		colony_shelter = {
			building = building_colony_shelter
		}

		hab_capital = {
			building = building_hab_capital
		}

		slave_capital = {
			building = building_slave_capital
		}
	}
}

automate_capital_building_machine = {
	available = {
		owner = {
			is_machine_empire = yes
		}
	}
	emergency = yes
	category = "planet_automation_upgrade_buildings"

	buildings = {
		deployment_post = {
			building = building_deployment_post
		}

		hab_capital = {
			building = building_hab_capital
		}
	}
}

automate_capital_building_hive = {
	available = {
		owner = {
			is_hive_empire = yes
		}
	}
	emergency = yes
	category = "planet_automation_upgrade_buildings"

	buildings = {
		hive_capital = {
			building = building_hive_capital
		}

		hab_capital = {
			building = building_hab_capital
		}
	}
}
