#Farming Buildings

building_hydroponics_farm = {
	base_buildtime = @b1_time

	category = resource
  building_sets = {
    hydroponics
  }

	potential = {
		exists = owner
		owner = {
			OR = {
				country_uses_food = yes
				is_ai = no
			}
		}
		NOT = { is_planet_class = pc_machine }
		NOT = { has_modifier = resort_colony }
	}

	allow = { }

	destroy_trigger = {
		exists = owner
		OR = {
			owner = {
				is_ai = yes
				country_uses_food = no
			}
			planet = {
				NOT = { is_planet_class = pc_habitat }
				free_building_slots = 0
				owner = {
					is_ai = yes
					has_monthly_income = {
						resource = food
						value > 100
					}
				}
			}
		}
	}
  
  inline_script = {
    script = jobs/farmers_add
    AMOUNT = @b1_jobs
  }

	resources = {
		category = planet_buildings
		cost = {
			minerals = @b1_minerals
		}
		upkeep = {
			energy = 2
		}
	}

	prerequisites = {
		"tech_eco_simulation"
	}
	
	upgrades = {
		"eb_hydrofarm2"
	}

	ai_resource_production = {
		food = 1
		trigger = {
			always = yes
		}
	}

	# Static jobs building
	ai_weight_coefficient = 0.0
}

eb_hydrofarm2 = {
	base_buildtime = @b2_time
	can_build = no

	category = resource
  building_sets = {
    hydroponics
  }

	potential = {
		exists = owner
		owner = {
			OR = {
				country_uses_food = yes
				is_ai = no
			}
		}
		NOT = { is_planet_class = pc_machine }
		NOT = { has_modifier = resort_colony }
	}
	
	allow = {
		has_upgraded_capital = yes
	}

	destroy_trigger = {
		exists = owner
		OR = {
			owner = {
				is_ai = yes
				country_uses_food = no
			}
			planet = {
				NOT = { is_planet_class = pc_habitat }
				free_building_slots = 0
				owner = {
					is_ai = yes
					has_monthly_income = {
						resource = food
						value > 100
					}
				}
			}
		}
	}
  
  inline_script = {
    script = jobs/farmers_add
    AMOUNT = @b2_jobs
  }
  
  planet_modifier = {
    farmer_jobs_bonus_workforce_mult = 0.05
  }

	resources = {
		category = planet_buildings
		cost = {
			minerals = @b2_minerals
			volatile_motes = @b2_rare_cost
		}
		upkeep = {
			energy = @b2_upkeep
			volatile_motes = @b2_rare_upkeep
		}
	}

	prerequisites = {
		"tech_gene_crops"
	}
	
	upgrades = {
		"eb_hydrofarm3"
	}

	ai_resource_production = {
		food = 2
		trigger = {
			always = yes
		}
	}
}

eb_hydrofarm3 = {
	base_buildtime = @b3_time
	can_build = no

	category = resource
  building_sets = {
    hydroponics
  }

	potential = {
		exists = owner
		owner = {
			OR = {
				country_uses_food = yes
				is_ai = no
			}
		}
		NOT = { is_planet_class = pc_machine }
		NOT = { has_modifier = resort_colony }
	}
	
	allow = {
		has_upgraded_capital = yes
	}

	destroy_trigger = {
		exists = owner
		OR = {
			owner = {
				is_ai = yes
				country_uses_food = no
			}
			planet = {
				NOT = { is_planet_class = pc_habitat }
				free_building_slots = 0
				owner = {
					is_ai = yes
					has_monthly_income = {
						resource = food
						value > 100
					}
				}
			}
		}
	}
  
  inline_script = {
    script = jobs/farmers_add
    AMOUNT = @b3_jobs
  }
  
  planet_modifier = {
    farmer_jobs_bonus_workforce_mult = 0.1
  }

	resources = {
		category = planet_buildings
		cost = {
			minerals = @b3_minerals
			volatile_motes = @b3_rare_cost
		}
		upkeep = {
			energy = @b3_upkeep
			volatile_motes = @b3_rare_upkeep
		}
	}

	prerequisites = {
		"tech_nano_vitality_crops"
	}

	ai_resource_production = {
		food = 3
		trigger = {
			always = yes
		}
	}
}

#Mining Buildings

eb_mineral2 = {
	base_buildtime = @b2_time
	can_build = no

	category = resource
  building_sets = {
    mining
    urban
  }

	destroy_trigger = {
		has_modifier = resort_colony
	}

	potential = {
		NOT = { has_modifier = resort_colony }

		NOR = { # Ringworlds don't have mines
			is_planet_class = pc_ringworld_habitable
			is_planet_class = pc_cybrex
		}
		OR = { # Habitats only have mines if they're built on an appropriate deposit
			NOT = { is_planet_class = pc_habitat }
			has_planet_flag = mining_habitat
		}
	}
	
	allow = {
		has_upgraded_capital = yes
	}
  
  inline_script = {
    script = jobs/miners_add
    AMOUNT = @b2_jobs
  }
  
  planet_modifier = {
    miner_jobs_bonus_workforce_mult = 0.05
  }

	resources = {
		category = planet_buildings
		cost = {
			minerals = @b2_minerals
			volatile_motes = @b2_rare_cost
		}
		upkeep = {
			energy = @b2_upkeep
			volatile_motes = @b2_rare_upkeep
		}
	}

	prerequisites = {
		"tech_mining_2"
	}
	
	upgrades = {
		"eb_mineral3"
	}

	ai_resource_production = {
		minerals = 3
		trigger = {
			always = yes
		}
	}
}

eb_mineral3 = {
	base_buildtime = @b3_time
	can_build = no

	category = resource
  building_sets = {
    mining
    urban
  }

	destroy_trigger = {
		has_modifier = resort_colony
	}

	potential = {
		NOT = { has_modifier = resort_colony }

		NOR = { # Ringworlds don't have mines
			is_planet_class = pc_ringworld_habitable
			is_planet_class = pc_cybrex
		}
		OR = { # Habitats only have mines if they're built on an appropriate deposit
			NOT = { is_planet_class = pc_habitat }
			has_planet_flag = mining_habitat
		}
	}
	
	allow = {
		has_upgraded_capital = yes
	}
  
  inline_script = {
    script = jobs/miners_add
    AMOUNT = @b3_jobs
  }
  
  planet_modifier = {
    miner_jobs_bonus_workforce_mult = 0.10
  }

	resources = {
		category = planet_buildings
		cost = {
			minerals = @b3_minerals
			volatile_motes = @b3_rare_cost
		}
		upkeep = {
			energy = @b3_upkeep
			volatile_motes = @b3_rare_upkeep
		}
	}

	prerequisites = {
		"tech_mining_3"
	}

	ai_resource_production = {
		minerals = 5
		trigger = {
			always = yes
		}
	}
}

#Energy Buildings

eb_energy2 = {
	base_buildtime = @b2_time
	can_build = no

	category = resource
  building_sets = {
    generator
    urban
  }

	destroy_trigger = {
		has_modifier = resort_colony
	}

	potential = {
		NOT = { has_modifier = resort_colony }
		OR = {
			NOT = { is_planet_class = pc_habitat }
			AND = {
				exists = owner
				owner = { is_gestalt = yes }
			}
			has_planet_flag = energy_habitat
		}
	}

	allow = { }
  
  inline_script = {
    script = jobs/technicians_add
    AMOUNT = @b2_jobs
  }
  
  planet_modifier = {
    technician_jobs_bonus_workforce_mult = 0.05
  }
	
	resources = {
		category = planet_buildings
		cost = {
			minerals = @b2_minerals
			exotic_gases = @b2_rare_cost
		}
		upkeep = {
			energy = 2
			exotic_gases = @b2_rare_upkeep
		}
	}
	
	prerequisites = {
		tech_power_plant_3
	}
	
	upgrades = {
		"eb_energy3"
	}

	ai_resource_production = {
		energy = 3
		trigger = {
			always = yes
		}
	}
}

eb_energy3 = {
	base_buildtime = @b3_time
	can_build = no

	category = resource
  building_sets = {
    generator
    urban
  }

	destroy_trigger = {
		has_modifier = resort_colony
	}

	potential = {
		NOT = { has_modifier = resort_colony }
		OR = {
			NOT = { is_planet_class = pc_habitat }
			AND = {
				exists = owner
				owner = { is_gestalt = yes }
			}
			has_planet_flag = energy_habitat
		}
	}

	allow = { }
  
  inline_script = {
    script = jobs/technicians_add
    AMOUNT = @b3_jobs
  }
  
  planet_modifier = {
    technician_jobs_bonus_workforce_mult = 0.10
  }
	
	resources = {
		category = planet_buildings
		cost = {
			minerals = @b3_minerals
			exotic_gases = @b3_rare_cost
		}
		upkeep = {
			energy = 2
			exotic_gases = @b3_rare_upkeep
		}
	}
	
	prerequisites = {
		tech_power_plant_4
	}

	ai_resource_production = {
		energy = 5
		trigger = {
			always = yes
		}
	}
}