## Categories used in this file must have use_for_ai_budget = yes defined in economic_categories ##
## It is possible to have multiple entries with the same category and resource ##

#################
## Expenditure ##
#################
energy_expenditure_buffer = { # Buffer, will not be spent
	resource = energy
	type = expenditure
	category = buffer

	potential = {
		always = yes
	}

	weight = {
		weight = 0.1
	}
}

energy_expenditure_planets_gaia_seeder = {
	resource = energy
	type = expenditure
	category = planets

	potential = {
		is_idyllic_bloom_empire = yes
		resource_stockpile_compare = { resource = energy value > 2000 }

		any_owned_planet = {
			NOR = {
				is_planet_class = pc_gaia
				is_planet_class = pc_city
				is_planet_class = pc_hive
				is_planet_class = pc_machine
			}
			is_artificial = no
		}
	}

	weight = {
		weight = 0.2
	}
}

energy_expenditure_colonies_infernal_hive = {
	resource = energy
	type = expenditure
	category = colonies

	potential = {
		is_nomadic = no
		is_infernal_empire = yes
		is_hive_empire = yes
		ai_colonize_plans > 0
		has_resource = { type = alloys amount > 100 }
		has_monthly_income = {
			resource = alloys
			value > 0
		}
	}

	weight = {
		weight = 0.8
	}

	desired_min = {
		base = @colony_cost_mid # Infernal hive colony ship costs 400 energy
	}

	desired_max = {
		base = @colony_cost_mid_max
	}
}

energy_expenditure_colonies_machine = {
	resource = energy
	type = expenditure
	category = colonies

	potential = {
		is_nomadic = no
		OR = {
			is_robot_empire = yes
			has_origin = origin_synthetic_fertility
		}
		ai_colonize_plans > 0
		has_resource = { type = energy amount > 400 }
		has_monthly_income = {
			resource = energy
			value > 0
		}
	}

	weight = {
		weight = 0.5
	}

	desired_min = {
		base = 0
		modifier = {
			add = @colony_cost_base
			is_gestalt = no
			is_virtual_empire = no
		}
		modifier = {
			add = @colony_cost_mid
			is_gestalt = no
			is_virtual_empire = yes
		}
		modifier = {
			add = @colony_cost_high
			is_gestalt = yes
			is_virtual_empire = no
		}
		modifier = {
			add = @colony_cost_very_high
			is_gestalt = yes
			is_virtual_empire = yes
		}
	}

	desired_max = {
		base = 0
		modifier = {
			add = @colony_cost_base_max
			is_gestalt = no
			is_virtual_empire = no
		}
		modifier = {
			add = @colony_cost_mid_max
			is_gestalt = no
			is_virtual_empire = yes
		}
		modifier = {
			add = @colony_cost_high_max
			is_gestalt = yes
			is_virtual_empire = no
		}
		modifier = {
			add = @colony_cost_very_high_max
			is_gestalt = yes
			is_virtual_empire = yes
		}
	}
}

energy_expenditure_deposit_blockers = {
	resource = energy
	type = expenditure
	category = deposit_blockers

	potential = {
		any_owned_planet = {
			num_uncleared_blockers > 0
		}
	}

	weight = {
		weight = 0.3

		modifier = {
			factor = 5

			# if we have any planet that is currently completely blocked
			any_owned_planet = {
				num_uncleared_blockers > 0
				num_free_districts = { type = any value < 1 }
			}
		}
	}

	# base remove blocker cost
	desired_min = {
		base = 500
	}

	desired_max = {
		base = 1000
	}
}

energy_expenditure_megastructures = {
	resource = energy
	type = expenditure
	category = megastructures

	potential = {
		is_country_type = default
		has_technology = tech_gateway_activation
		is_at_war = no
		any_owned_megastructure = {
			OR = {
				is_megastructure_type = gateway_0
				is_megastructure_type = gateway_ruined
			}
		}
		has_resource = {
			type = energy
			amount > 6000
		}
	}

	weight = {
		weight = 0.5
	}

	desired_max = {
		base = 6000 # currently only used by gateways
	}
}

energy_expenditure_decisions = {
	resource = energy
	type = expenditure
	category = decisions

	potential = {
		# only consider these kinds of decisions when "wealthy"
		has_resource = {
			type = energy
			amount > 5000
		}
	}

	weight = {
		weight = 0.20
	}

	# based on mastery of nature decision
	desired_max = {
		base = 2000
	}
}

energy_expenditure_terraforming = {
	resource = energy
	type = expenditure
	category = terraforming

	potential = {
		is_nomadic = no
		has_technology = tech_terrestrial_sculpting
	}

	weight = {
		weight = 0.3
		modifier = {
			factor = 0.5
			end_game_years_passed > 0 #Probably not relevant anymore
		}
		modifier = {
			factor = 1.5
			OR = {
				has_ascension_perk = ap_machine_worlds
				has_ascension_perk = ap_hive_worlds
				AND = {
					has_technology = tech_climate_restoration
					any_system_within_border = {
						any_system_planet = {
							OR = {
								has_modifier = terraforming_candidate
								AND = {
									is_planet_class = pc_nuked
									root = {
										NOT = { ideal_planet_class = pc_nuked }
									}
								}
							}
						}
					}
				}
				AND = {
					has_ascension_perk = ap_detox
					any_system_within_border = {
						any_system_planet = {
							has_modifier = toxic_terraforming_candidate
						}
					}
				}
			}
		}
	}

	desired_max = { #never any need for more than that for a single planet
		base = 20000
	}
}

energy_expenditure_exhibit_unlock = {
	resource = energy
	type = expenditure
	category = specimens

	potential = {
		has_technology = tech_galactic_archivism
		has_grand_archive = yes
		any_exhibit = {
			is_exhibit_active = no
		}
	}

	weight = {
		weight = 0.10
	}
}

energy_expenditure_armies = {
	resource = energy
	type = expenditure
	category = armies

	potential = {
		has_valid_civic = civic_reanimated_armies
	}

	weight = {
		weight = 0.1
	}
}

############
## Upkeep ##
############
energy_upkeep_buffer = {	# Buffer, will not be spent
	resource = energy
	type = upkeep
	category = buffer

	potential = {
		always = yes
	}

	weight = {
		weight = 0.01
	}
}

energy_upkeep_country = { # Covers most other things. Note: each category opts into using this pool via ai_use_parent_for_resources_upkeep in the category
	resource = energy
	type = upkeep
	category = country

	potential = {
		always = yes
	}

	weight = {
		weight = 1
		modifier = {
			factor = 1.25
			resource_income_compare = {
				resource = energy
				value > 1000
			}
		}
		modifier = {
			factor = 1.5
			resource_income_compare = {
				resource = energy
				value > 2000
			}
		}
	}
}

energy_upkeep_armies = {
	resource = energy
	type = upkeep
	category = armies

	potential = {
		always = yes
	}

	weight = {
		weight = 0.05
	}
}
