#root = starbase
#from = player

# Weights in the ai_design part are multiplied with the base weight of 00_starbase_buildings.txt and 00_starbase_modules.txt
# Then, a random number between that value and and extra 50% of that it is ADDED to it
# F.e. 100 base weight multiplies with 2.00 = 200. Then we take a random number between 0 and 100 (50% of 200) and ADD it to 200. 235 then, for example
# This is done for ALL starbase modules and buildings in the list every time an evaluation is made
# And the building or module with the highest value will be chosen to being built
# The implication of that is that you can not balance the weights TOO FAR from each other - otherwise some modules will never be chosen, unless they are the only thing on the evaluation
# Due to the progression of the game and the unlocking of tech, though, it is often the case that there will only be 1 item on the list at any given time anyway

# How the AI/game selects which type to use:
# First of all, it will try to find one which fulfils both the potential trigger and has a positive weight_modifier
# If this succeeds, the starbase already has a type.
# If it fails, it will go through each starbase type that fulfils the potential trigger. Then it will check the ratio it has built (total of this type / total upgraded starbases) compared to the desired ratio. If it is set to desire a minimum value and owns less than that, it multiplies its ratio desire by * 100. Then it build according to that type's template.

# Shipyard
sshipyard = {
	potential = {
		has_starbase_size > starbase_outpost

		NOT = {
			has_starbase_module = beastport
		}

		owner = {
			OR = {
				is_ai = no
				is_beastmasters_empire = no
			}
		}
	}

	weight_modifier = {
		base = 0
		complex_trigger_modifier = { #+100 for each shipyard
			trigger = count_starbase_modules
			parameters = {
				type = shipyard
			}
			mode = add
			mult = 100
		}
		modifier = {
			add = 1000
			owner = {
				is_ai = yes
				NOT = {
					any_owned_starbase = {
						controller = { is_same_value = root.owner }
						has_starbase_module = shipyard
					}
				}
			}
		}
		modifier = {
			factor = 0
			exists = owner
			owner = {
				is_beastmasters_empire = yes
			}
		}
	}

	ai_design = {
		min = {
			base = 0
			modifier = {
				add = 1
				exists = owner
				owner = {
					uses_standard_ship_sizes = yes
				}
			}
			modifier = {
				add = 1
				exists = owner
				owner = {
					country_uses_bio_ships = yes
				}
			}
		}

		ratio = {
			base = 0.20
			modifier = {
				add = 0.10
				exists = owner
				owner = {
					has_ethic = ethic_militarist
				}
			}
			modifier = {
				add = 0.15
				exists = owner
				owner = {
					has_ethic = ethic_fanatic_militarist
				}
			}
			modifier = {
				factor = 0
				exists = owner
				owner = {
					uses_standard_ship_sizes = no
					country_uses_bio_ships = no
				}
			}
		}

		# token followed by priority
		buildings = {
			crew_quarters = {
				base = 1.00
			}

			fleet_academy = {
				base = 1.00
			}

			capital_yards = {
				base = 1.00
			}

			ice_mining_station = {
				base = 1.00
			}

			dragon_hatchery = {
				base = 1.00
			}

			hydroponics_bay = {
				base = 1.00
			}

			dimensional_shrine = {
				base = 1.00
			}

			irassian_naval_yards = {
				base = 3.00
			}
			cordyceptic_reanimation_facility = {
				base = 3.00
			}

			growth_chamber = {
				base = 2.00
			}
		}

		modules = {
			shipyard = {
				base = 1.00
			}

			anchorage = {
				base = 0.50
			}

			starbase_hangar_bay = {
				base = 0.45
			}

			starbase_archaeo_hangar_bay = {
				base = 0.45
			}

			starbase_psionic_hangar_bay = {
				base = 0.45
			}

			starbase_amoeba_hangar_bay = {
				base = 0.45
			}

			starbase_swarm_hangar_bay = {
				base = 0.45
			}
		}
	}
}


# Beastport
sbeastport = {
	potential = {
		OR = {
			AND = {
				is_orbital_ring = yes
				owner = { is_ai = no }
				NOT = { has_starbase_module = orbital_ring_shipyard }
			}

			AND = {
				has_starbase_size > starbase_outpost

				owner = {
					is_beastmasters_empire = yes
				}
				NOT = { has_starbase_module = shipyard }
			}
		}
	}
	inline_script = {
		script = grand_archive/ship_building_starbase_type
		TYPE = beastport
	}
}

# Anchorage
sanchorage = {
	potential = {
		has_starbase_size > starbase_outpost

		NAND = {
			solar_system = {
				is_same_value = sector.sector_capital.solar_system
			}
		}
	}

	weight_modifier = {
		base = 0
		complex_trigger_modifier = { #+100 for each anchorage
			trigger = count_starbase_modules
			parameters = {
				type = anchorage
			}
			mode = add
			mult = 100
		}
	}

	ai_design = {
		min = {
			base = 0
		}

		ratio = {
			base = 0.65
			modifier = {
				add = 0.05
				exists = owner
				owner = {
					has_ethic = ethic_militarist
				}
			}
			modifier = {
				add = 0.05
				exists = owner
				owner = {
					has_ethic = ethic_fanatic_militarist
				}
			}
		}

		# token followed by priority
		buildings = {

			naval_logistics_office = {
				base = 1.00
			}

			curator_think_tank = {
				base = 2.00
			}

			art_college = {
				base = 2.00
			}

			nebula_refinery = {
				base = 2.00
			}

			ice_mining_station = {
				base = 2.00
			}

			dragon_hatchery = {
				base = 2.00
			}

			hydroponics_bay = {
				base = 2.00
			}

			dimensional_shrine = {
				base = 2.00
			}

			cordyceptic_reanimation_facility = {
				base = 3.00
			}

			recruitment_office = {
				base = 0.50
			}

			black_hole_observatory = {
				base = 2.00
			}

			deep_space_black_site = {
				base = 2.00
			}

			shroud_beacon = {
				base = 0.50
			}

			nanite_harvester = {
				base = 3.00
			}

			trader_proxy_office = {
				base = 2.00
			}
		}

		modules = {
			anchorage = {
				base = 1.00
			}
		}
	}
}

# Trading Hub
strading_hub = {
	potential = {
		has_starbase_size > starbase_outpost
		exists = owner
		owner = { NOT = { has_ethic = ethic_gestalt_consciousness } }
	}

	weight_modifier = {
		base = 0
		complex_trigger_modifier = { #+100 for each trading_hub
			trigger = count_starbase_modules
			parameters = {
				type = trading_hub
			}
			mode = add
			mult = 100
		}
	}

	ai_design = {
		min = {
			base = 0
		}

		ratio = {
			base = 0.05
			modifier = {
				add = 0.05
				exists = owner
				owner = {
					OR = {
						has_ethic = ethic_xenophile
						is_megacorp = yes
					}
				}
			}
			modifier = {
				add = 0.10
				exists = owner
				owner = {
					OR = {
						has_ethic = ethic_fanatic_xenophile
						is_megacorp = yes
					}
				}
			}
		}

		# token followed by priority
		buildings = {
			offworld_trading_company = {
				base = 1.00
			}

			nebula_refinery = {
				base = 1.00
			}

			resource_silo = {
				base = 0.25
			}

			art_college = {
				base = 1.00
			}

			curator_think_tank = {
				base = 1.00
			}

			ice_mining_station = {
				base = 1.00
			}

			dragon_hatchery = {
				base = 1.00
			}

			hydroponics_bay = {
				base = 1.00
			}

			dimensional_shrine = {
				base = 1.00
			}

			yuht_detection_array = {
				base = 1.25
				modifier = {
					factor = 0
					exists = owner
					owner = {
						OR = {
							has_megastructure = spy_orb_1
							has_megastructure = spy_orb_2
							has_megastructure = spy_orb_3
							has_megastructure = spy_orb_4
						}
					}
				}
				modifier = {
					factor = 0.10
					exists = owner
					owner = {
						any_owned_starbase = {
							count_starbase_buildings = {
								type = yuht_detection_array
								count > 0
							}
						}
					}
				}
			}

			hyperlane_detailer = {
				base = 1.00
			}

			recruitment_office = {
				base = 0.50
			}

			black_hole_observatory = {
				base = 2.00
			}

			deep_space_black_site = {
				base = 2.00
			}

			shroud_beacon = {
				base = 0.50
			}

			nanite_harvester = {
				base = 3.00
			}

			trader_proxy_office = {
				base = 2.00
			}
		}

		modules = {
			trading_hub = {
				base = 1.0
			}
		}
	}
}

# Fortress System
sfortress = {
	potential = {
		has_starbase_size > starbase_outpost
		exists = owner

		OR = {
			owner = { is_ai = no }
			AND = {
				solar_system = { is_bottleneck_system = yes }
				closest_system = {
					min_steps = 0
					max_steps = 2
					limit = {
						exists = owner
						owner = {
							is_country_type = default
							NOR = {
								is_same_value = root.owner
								is_in_federation_with = root.owner
								has_association_status = root.owner
								has_defensive_pact = root.owner
								has_non_aggression_pact = root.owner
								has_overlord = root.owner
								AND = {
									has_subject = root.owner
									has_loyalty > 0
								}
							}
						}
					}
					exists = this
				}
			}
			AND = { # closest_system (above) doesn't check bypass connections
				solar_system = {
					OR = {
						has_star_flag = starlit_nexus_system
						AND = {
							has_natural_wormhole = yes
							exists = prev.owner
							prev.owner = {
								has_technology = tech_wormhole_stabilization
							}
						}
						has_star_flag = shroud_tunnel_nexus
						has_star_flag = spawned_shroud_tunnel
						AND = {
							has_megastructure = lgate_base
							has_global_flag = lgates_activated_globally
						}
					}
					any_country_neighbor_to_system = {
						OR = {
							is_country_type = default
							is_country_type = awakened_fallen_empire
						}
						NOR = {
							is_same_value = root.owner
							is_in_federation_with = root.owner
							has_association_status = root.owner
							has_defensive_pact = root.owner
							has_non_aggression_pact = root.owner
							has_overlord = root.owner
							AND = {
								has_subject = root.owner
								has_loyalty > 0
							}
						}
					}
				}
			}
		}
	}

	ai_use_defense_platforms = yes #AI will not build defense platforms otherwise, except in the capital system

	weight_modifier = {
		base = 0
		complex_trigger_modifier = {
			trigger = count_starbase_modules
			parameters = {
				type = starbase_laser_battery
			}
			mode = add
			mult = 75
		}
		complex_trigger_modifier = {
			trigger = count_starbase_modules
			parameters = {
				type = starbase_archaeo_laser_battery
			}
			mode = add
			mult = 75
		}
		complex_trigger_modifier = {
			trigger = count_starbase_modules
			parameters = {
				type = starbase_mass_driver_battery
			}
			mode = add
			mult = 75
		}
		complex_trigger_modifier = {
			trigger = count_starbase_modules
			parameters = {
				type = starbase_archaeo_mass_driver_battery
			}
			mode = add
			mult = 75
		}
		complex_trigger_modifier = {
			trigger = count_starbase_modules
			parameters = {
				type = starbase_swarmer_missile_battery
			}
			mode = add
			mult = 75
		}
		complex_trigger_modifier = {
			trigger = count_starbase_modules
			parameters = {
				type = starbase_particle_launcher
			}
			mode = add
			mult = 75
		}
		complex_trigger_modifier = {
			trigger = count_starbase_modules
			parameters = {
				type = starbase_psionic_torpedo
			}
			mode = add
			mult = 75
		}
		complex_trigger_modifier = {
			trigger = count_starbase_modules
			parameters = {
				type = starbase_scourge_missile_battery
			}
			mode = add
			mult = 75
		}
		complex_trigger_modifier = {
			trigger = count_starbase_modules
			parameters = {
				type = starbase_hangar_bay
			}
			mode = add
			mult = 75
		}
		complex_trigger_modifier = {
			trigger = count_starbase_modules
			parameters = {
				type = starbase_archaeo_hangar_bay
			}
			mode = add
			mult = 75
		}
		complex_trigger_modifier = {
			trigger = count_starbase_modules
			parameters = {
				type = starbase_psionic_hangar_bay
			}
			mode = add
			mult = 75
		}
		complex_trigger_modifier = {
			trigger = count_starbase_modules
			parameters = {
				type = starbase_amoeba_hangar_bay
			}
			mode = add
			mult = 75
		}
		complex_trigger_modifier = {
			trigger = count_starbase_modules
			parameters = {
				type = starbase_swarm_hangar_bay
			}
			mode = add
			mult = 75
		}
		modifier = {
			add = 150
			solar_system = { is_bottleneck_system = yes }
			closest_system = {
				max_steps = 2
				limit = {
					exists = owner
					owner = {
						OR = {
							is_rival = root
							is_hostile_to = root
							is_hostile = root
						}
					}
				}
				exists = this
			}
		}
	}

	ai_design = {
		min = {
			base = 0
		}

		ratio = {
			base = 0.10
			modifier = {
				add = 0.10
				exists = owner
				owner = {
					has_ethic = ethic_pacifist
				}
			}
			modifier = {
				add = 0.10
				exists = owner
				owner = {
					has_ethic = ethic_fanatic_pacifist
				}
			}
		}

		# token followed by priority
		buildings = {

			target_uplink_computer = {
				base = 1.00
			}

			command_center = {
				base = 1.00
			}

			defense_grid = {
				base = 1.00
			}

			communications_jammer = {
				base = 0.90
			}

			disruption_field = {
				base = 0.90
			}

			ice_mining_station = {
				base = 3.00
			}

			dragon_hatchery = {
				base = 3.00
			}

			hydroponics_bay = {
				base = 0.25
			}

			reloading_bay = {
				base = 2.00
			}

			zroni_storm_caster = {
				base = 1.5
				modifier = {
					factor = 0
					exists = owner
					owner = {
						has_monthly_income = {
							resource = sr_zro
							value < 2
						}
					}
				}
			}
			offspring_outlook = {
				base = 10
			}

			recruitment_office = {
				base = 0.50
			}

			black_hole_observatory = {
				base = 2.00
			}

			deep_space_black_site = {
				base = 2.00
			}

			shroud_beacon = {
				base = 0.50
			}

			nanite_harvester = {
				base = 3.00
			}

			trader_proxy_office = {
				base = 2.00
			}
		}

		modules = {
			starbase_hangar_bay = {
				base = 0.80
				modifier = {
					factor = 2
					owner? = { is_flight_schools_empire = yes }
				}
			}

			starbase_archaeo_hangar_bay = {
				base = 0.80
			}

			starbase_psionic_hangar_bay = {
				base = 0.80
			}

			starbase_amoeba_hangar_bay = {
				base = 0.80
			}

			starbase_swarm_hangar_bay = {
				base = 0.80
			}

			starbase_particle_launcher = {
				base = 1.00
			}

			starbase_psionic_torpedo = {
				base = 1.00
			}

			starbase_scourge_missile_battery = {
				base = 1.00
			}

			starbase_laser_battery = {
				base = 1.00
			}

			starbase_archaeo_laser_battery = {
				base = 1.00
			}

			starbase_mass_driver_battery = {
				base = 1.00
			}

			starbase_archaeo_mass_driver_battery = {
				base = 1.00
			}

			starbase_swarmer_missile_battery = {
				base = 1.00
			}

			archaeo_rampart = {
				base = 1.25
			}
		}
	}
}

# Trading Hub - Gestalts
strading_hub_gestalt = {
	potential = {
		has_starbase_size > starbase_outpost
		exists = owner
		owner = {
			has_ethic = ethic_gestalt_consciousness
			NOT = { has_valid_civic = civic_machine_astromining_drones }
		}
	}

	weight_modifier = {
		base = 0
		complex_trigger_modifier = { #+100 for each trading_hub
			trigger = count_starbase_modules
			parameters = {
				type = solar_panel_network
			}
			mode = add
			mult = 100
		}
		modifier = {
			factor = 0
			exists = owner
			owner = {
				any_owned_starbase = {
					NOR = {
						is_starbase_type = sshipyard
						is_starbase_type = sbeastport
					}
				}
			}
		}
	}

	ai_design = {
		min = {
			base = 0
		}

		# token followed by priority
		modules = {
			solar_panel_network = {
				base = 1.00
			}
		}

		buildings = {

			nebula_refinery = {
				base = 1.00
			}

			resource_silo = {
				base = 0.25
			}

			art_college = {
				base = 1.00
			}

			curator_think_tank = {
				base = 1.00
			}

			ice_mining_station = {
				base = 1.00
			}

			dragon_hatchery = {
				base = 1.00
			}

			hydroponics_bay = {
				base = 1.00
			}

			dimensional_shrine = {
				base = 1.00
			}

			defense_grid = {
				base = 0.05
			}

			communications_jammer = {
				base = 0.05
			}

			cordyceptic_reanimation_facility = {
				base = 3.00
			}

			feeder = {
				base = 3.00
			}

			black_hole_observatory = {
				base = 2.00
			}

			shroud_beacon = {
				base = 0.50
			}

			nanite_harvester = {
				base = 3.00
			}
		}
	}
}

# Mining Hub for Astrominer machine civic
smining_hub = {
	potential = {
		has_starbase_size > starbase_outpost
		exists = owner
		owner = {
			has_ethic = ethic_gestalt_consciousness
			has_valid_civic = civic_machine_astromining_drones
		}
		solar_system = {
			count_ship_in_system= {
				count > 3
				limit = {
					is_ship_size = mining_station
				}
			}
		}
	}

	weight_modifier = {
		base = 0
		complex_trigger_modifier = { #+100 for each mining_bay
			trigger = count_starbase_modules
			parameters = {
				type = astromining_bay
			}
			mode = add
			mult = 100
		}
		modifier = {
			add = 1000
			solar_system = {
				is_capital_system = no
			}
			owner = {
				is_ai = yes
				NOT = {
					any_owned_starbase = {
						has_starbase_module = astromining_bay
					}
				}
			}
		}
		modifier = {
			add = 1000
			solar_system = {
				owner ={
					is_ai = yes
				}
				is_capital_system = no
				count_ship_in_system= {
					count > 3
					limit = {
						is_ship_size = mining_station
					}
				}
			}
		}
	}

	ai_design = {
		min = {
			base = 0
		}

		# token followed by priority
		modules = {
			astromining_bay = {
				base = 5.00
			}
		}

		buildings = {

			astromining_hub = {
				base = 3.00
			}

			nebula_refinery = {
				base = 1.00
			}

			resource_silo = {
				base = 0.25
			}

			art_college = {
				base = 1.00
			}

			curator_think_tank = {
				base = 1.00
			}

			ice_mining_station = {
				base = 1.00
			}

			dragon_hatchery = {
				base = 1.00
			}

			hydroponics_bay = {
				base = 1.00
			}

			dimensional_shrine = {
				base = 1.00
			}

			defense_grid = {
				base = 0.05
			}

			communications_jammer = {
				base = 0.05
			}

			cordyceptic_reanimation_facility = {
				base = 3.00
			}

			feeder = {
				base = 3.00
			}

			black_hole_observatory = {
				base = 2.00
			}

			shroud_beacon = {
				base = 0.50
			}

			nanite_harvester = {
				base = 3.00
			}
		}
	}
}

sdetection_array = {
	potential = {
		has_first_contact_dlc = yes
		has_starbase_size > starbase_outpost
		exists = owner
		owner = {
			has_technology = tech_detection_array
		}
		OR = {
			owner = { is_ai = no } # These rules shouldn't apply to players
			AND = {
				exists = sector
				sector = {
					any_system_within_border = {
						starbase = {
							NOT = {
								is_starbase_type = sdetection_array
							}
						}
					}
				}
				solar_system = {
					is_capital_system = no
					is_inside_nebula = no
				}
			}
		}
		OR = {
			AND = {
				owner = { is_ai = no }
				has_starbase_module = detection_array
			}
			# Either this is near the capital system
			AND = {
				owner = { is_ai = yes }
				sector = {
					any_system_within_border = {
						is_capital_system = yes
					}
				}
			}
			# Or is a border system
			AND = {
				owner = { is_ai = yes }
				closest_system = {
					min_steps = 0
					max_steps = 4
					limit = {
						exists = owner
						owner = {
							is_country_type = default
							NOR = {
								is_same_value = root.owner
								is_in_federation_with = root.owner
								has_association_status = root.owner
								has_defensive_pact = root.owner
								has_non_aggression_pact = root.owner
								has_overlord = root.owner
								AND = {
									has_subject = root.owner
									has_loyalty > 0
								}
							}
						}
					}
					exists = this
				}
			}
		}
	}

	ai_use_defense_platforms = yes #AI will not build defense platforms otherwise, except in the capital system

	weight_modifier = {
		base = 0
		complex_trigger_modifier = { #+100 for each detection array
			trigger = count_starbase_modules
			parameters = {
				type = detection_array
			}
			mode = add
			mult = 100
		}
		modifier = {
			add = 1000
			owner = {
				NOT = {
					any_owned_starbase = {
						has_starbase_module = detection_array
					}
				}
			}
		}
	}

	ai_design = {
		min = {
			base = 1
		}

		ratio = {
			base = 0.10
			modifier = {
				add = 0.10
				exists = owner
				owner = {
					has_ethic = ethic_pacifist
				}
			}
			modifier = {
				add = 0.20
				exists = owner
				owner = {
					has_ethic = ethic_fanatic_pacifist
				}
			}
			modifier = {
				add = 0.10
				exists = owner
				owner = {
					has_ethic = ethic_xenophobe
				}
			}
			modifier = {
				add = 0.20
				exists = owner
				owner = {
					has_ethic = ethic_fanatic_xenophobe
				}
			}
		}

		# token followed by priority
		buildings = {
			listening_post = {
				base = 1.00
				modifier = {
					factor = 6
					exists = owner
					owner = {
						has_technology = tech_unusual_senses
					}
				}
				modifier = {
					factor = 2
					exists = owner
					owner = {
						has_civic = civic_hive_subspace_ephapse
					}
				}
			}

			dark_matter_detector = {
				base = 10.00
			}

			yuht_detection_array = {
				base = 5.00
			}

			target_uplink_computer = {
				base = 1.00
			}

			defense_grid = {
				base = 1.00
			}


			cybrex_mining_hub = {
				base = 1.00
			}

			recruitment_office = {
				base = 0.50
			}

			black_hole_observatory = {
				base = 2.00
			}

			deep_space_black_site = {
				base = 2.00
			}

			shroud_beacon = {
				base = 0.50
			}

			nanite_harvester = {
				base = 3.00
			}

			trader_proxy_office = {
				base = 2.00
			}
		}

		modules = {
			detection_array = {
				base = 1.00
			}
		}
	}
}

sseeder = {
	potential = {
		has_starbase_size > starbase_outpost
		exists = owner
		owner = { has_origin = origin_fruitful }
		NOT = { has_global_flag = tiyanki_extinct }
	}

	weight_modifier = {
		base = 0
		modifier = {
			add = 500
			has_starbase_building = feeder
		}
	}

	ai_design = {
		min = {
			base = 1
		}

		ratio = {
			base = 0
		}

		# token followed by priority
		buildings = {
			feeder = {
				base = 5.00
				modifier = {
					add = 5.00
					solar_system = {
						closest_system = {
							limit = {
								has_star_flag = space_critter_system
							}
							min_steps = 0
							max_steps = 5
						}
					}
				}
			}
			naval_logistics_office = {
				base = 1.00
			}

			defense_grid = {
				base = 0.05
			}

			communications_jammer = {
				base = 0.05
			}

			curator_think_tank = {
				base = 2.00
			}

			art_college = {
				base = 2.00
			}

			nebula_refinery = {
				base = 2.00
			}

			ice_mining_station = {
				base = 2.00
			}

			dragon_hatchery = {
				base = 2.00
			}

			hydroponics_bay = {
				base = 2.00
			}
		}

		modules = {
			shipyard = {
				base = 1.00
			}

			anchorage = {
				base = 0.50
			}

			starbase_hangar_bay = {
				base = 0.45
			}

			starbase_archaeo_hangar_bay = {
				base = 0.45
			}

			starbase_psionic_hangar_bay = {
				base = 0.45
			}

			starbase_amoeba_hangar_bay = {
				base = 0.45
			}

			starbase_swarm_hangar_bay = {
				base = 0.45
			}
		}
	}
}

### ORBITAL RINGS

sorbital_ring = { # generic
	potential = { is_orbital_ring = yes }
	weight_modifier = { base = 10 }
	ai_design = {
		min = {
			base = 0
		}
		modules = {
			orbital_ring_habitation = {
				base = 20.00
				modifier = {
					factor = 2
					planet = {
						num_free_districts = { type = any value <= 2 }
					}
				}
			}

			orbital_ring_shipyard = {
				base = 0.0 # Generally better to use normal starbases for this
			}

			orbital_ring_beastport = {
				base = 0.0 # Generally better to use normal starbases for this
			}

			orbital_ring_anchorage = {
				base = 0.0 # Generally better to use normal starbases for this
			}

			orbital_ring_laser_battery = {
				base = 0.0
			}

			orbital_ring_archaeo_laser_battery = {
				base = 0.0
			}

			orbital_ring_mass_driver_battery = {
				base = 0.0
			}

			orbital_ring_archaeo_mass_driver_battery = {
				base = 0.0
			}

			orbital_ring_swarmer_missile_battery = {
				base = 0.0
			}

			orbital_ring_particle_launcher = {
				base = 0.0
			}

			orbital_ring_psionic_torpedo = {
				base = 0.0
			}

			orbital_ring_scourge_missile_battery = {
				base = 0.0
			}

			orbital_ring_hangar_bay = {
				base = 0.0
			}

			orbital_ring_archaeo_hangar_bay = {
				base = 0.0
			}

			orbital_ring_psionic_hangar_bay = {
				base = 0.0
			}

			orbital_ring_amoeba_hangar_bay = {
				base = 0.0
			}

			orbital_ring_swarm_hangar_bay = {
				base = 0.0
			}
		}

		# token followed by priority
		buildings = {
			ring_synapse_hub = {
				base = 1.00
			}

			ring_maintenance_hub = {
				base = 1.00
			}

			ring_bureaucracy_hub = {
				base = 1
				modifier = {
					add = 2
					planet = {
						OR = {
							has_unity_designation = yes
							has_building = building_sensorium_1
							has_building = building_autochthon_monument
							has_building = building_corporate_monument
							has_building = building_galactic_memorial_1
							has_building = building_simulation_1
						}
					}
				}
			}

			ring_minerals_hub = {
				base = 1
				modifier = {
					add = 2
					planet = {
						OR = {
							has_mining_designation = yes
							has_building = building_mineral_purification_plant
							has_building = building_mineral_purification_hub
							has_building = building_churning_tunnels_3
							has_building = building_churning_tunnels_4
						}
					}
				}
			}

			ring_energy_hub = {
				base = 1
				modifier = {
					add = 2
					planet = {
						OR = {
							has_generator_designation = yes
							has_building = building_energy_grid
							has_building = building_energy_nexus
							has_building = building_bioelectric_stimulator_3
							has_building = building_bioelectric_stimulator_4
						}
					}
				}
			}

			ring_food_hub = {
				base = 1
				modifier = {
					add = 2
					planet = {
						OR = {
							has_farming_designation = yes
							has_building = building_food_processing_facility
							has_building = building_food_processing_center
							has_building = building_massive_growth_4
						}
					}
				}
			}

			ring_consumer_goods_hub = {
				base = 1
				modifier = {
					add = 2
					planet = {
						OR = {
							has_factory_designation = yes
							has_industrial_designation = yes
							has_building = building_factory_1
							has_building = building_factory_2
							has_building = building_factory_3
						}
					}
				}
			}

			ring_alloys_hub = {
				base = 1
				modifier = {
					add = 2
					planet = {
						OR = {
							has_foundry_designation = yes
							has_industrial_designation = yes
							has_building = building_foundry_1
							has_building = building_natural_furnace_1
							has_building = building_foundry_2
							has_building = building_natural_furnace_2
							has_building = building_foundry_3
							has_building = building_natural_furnace_3
						}
					}
				}
			}

			ring_trade_hub = {
				base = 1
				modifier = {
					add = 2
					planet = {
						OR = {
							has_trade_designation = yes
							has_building = building_galactic_stock_exchange
						}
					}
				}
			}
		}
	}
}

# Shipyard
sorbital_shipyard = {
	potential = {
		is_orbital_ring = yes
		has_starbase_module = orbital_ring_shipyard
	}

	weight_modifier = {
		base = 0

		complex_trigger_modifier = { # +100 for each shipyard
			trigger = count_starbase_modules
			parameters = {
				type = orbital_ring_shipyard
			}
			mode = add
			mult = 100
		}

		modifier = {
			add = 1000
			owner = {
				NOR = {
					any_owned_megastructure = {
						OR = {
							is_megastructure_type = mega_shipyard_1
							is_megastructure_type = mega_shipyard_2
							is_megastructure_type = mega_shipyard_3
							is_megastructure_type = mega_shipyard_restored
						}
					}
					any_owned_starbase = {
						has_starbase_module = shipyard
						has_starbase_module = orbital_ring_shipyard
					}
				}
			}
		}
	}

	ai_design = {
		min = {
			base = 0
		}

		# token followed by priority
		buildings = {
			crew_quarters = {
				base = 1.00
			}

			hydroponics_bay = {
				base = 0.25
			}

			ring_growth_chamber = {
				base = 1.00
			}
		}

		modules = {
			orbital_ring_shipyard = {
				base = 1.00
			}
		}
	}
}


# Orbital Beastport
sorbital_ring_beastport = {
	potential = {
		OR = {
			AND = {
				is_orbital_ring = yes
				owner = { is_ai = no }
				NOT = { has_starbase_module = orbital_ring_shipyard }
			}

			AND = {
				has_starbase_size > starbase_outpost

				owner = {
					is_beastmasters_empire = yes
				}
				NOT = { has_starbase_module = shipyard }
			}
		}
	}
	inline_script = {
		script = grand_archive/ship_building_starbase_type
		TYPE = orbital_ring_beastport
	}
}

# Anchorage
sorbital_anchorage = {
	potential = {
		is_orbital_ring = yes
		has_starbase_module = orbital_ring_anchorage
	}

	weight_modifier = {
		base = 0
		complex_trigger_modifier = { # +100 for each anchorage
			trigger = count_starbase_modules
			parameters = {
				type = orbital_ring_anchorage
			}
			mode = add
			mult = 100
		}
	}

	ai_design = {
		min = {
			base = 0
		}

		ratio = {
			base = 0
		}

		# token followed by priority
		buildings = {
			naval_logistics_office = {
				base = 10.00
			}

			defense_grid = {
				base = 0.25
			}

			communications_jammer = {
				base = 0.25
			}

			nebula_refinery = {
				base = 2.00
			}

			hydroponics_bay = {
				base = 1.00
			}
		}

		modules = {
			orbital_ring_anchorage = {
				base = 1.00
			}

			orbital_ring_habitation = {
				base = 0
				modifier = {
					add = 1
					planet = {
						num_free_districts = { type = any value <= 2 }
					}
				}
			}
		}
	}
}

# Fortress System
sorbital_fortress = {
	potential = {
		is_orbital_ring = yes
		OR = {
			count_starbase_modules = { type = orbital_ring_laser_battery count > 0 }
			count_starbase_modules = { type = orbital_ring_archaeo_laser_battery count > 0 }
			count_starbase_modules = { type = orbital_ring_mass_driver_battery count > 0 }
			count_starbase_modules = { type = orbital_ring_archaeo_mass_driver_battery count > 0 }
			count_starbase_modules = { type = orbital_ring_swarmer_missile_battery count > 0 }
			count_starbase_modules = { type = orbital_ring_particle_launcher count > 0 }
			count_starbase_modules = { type = orbital_ring_psionic_torpedo count > 0 }
			count_starbase_modules = { type = orbital_ring_scourge_missile_battery count > 0 }
			count_starbase_modules = { type = orbital_ring_hangar_bay count > 0 }
			count_starbase_modules = { type = orbital_ring_archaeo_hangar_bay count > 0 }
			count_starbase_modules = { type = orbital_ring_psionic_hangar_bay count > 0 }
			count_starbase_modules = { type = orbital_ring_amoeba_hangar_bay count > 0 }
			count_starbase_modules = { type = orbital_ring_swarm_hangar_bay count > 0 }
		}
	}

	ai_use_defense_platforms = yes #AI will not build defense platforms otherwise, except in the capital system

	weight_modifier = {
		base = 0
		complex_trigger_modifier = {
			trigger = count_starbase_modules
			parameters = {
				type = orbital_ring_laser_battery
			}
			mode = add
			mult = 75
		}
		complex_trigger_modifier = {
			trigger = count_starbase_modules
			parameters = {
				type = orbital_ring_archaeo_laser_battery
			}
			mode = add
			mult = 75
		}
		complex_trigger_modifier = {
			trigger = count_starbase_modules
			parameters = {
				type = orbital_ring_mass_driver_battery
			}
			mode = add
			mult = 75
		}
		complex_trigger_modifier = {
			trigger = count_starbase_modules
			parameters = {
				type = orbital_ring_archaeo_mass_driver_battery
			}
			mode = add
			mult = 75
		}
		complex_trigger_modifier = {
			trigger = count_starbase_modules
			parameters = {
				type = orbital_ring_swarmer_missile_battery
			}
			mode = add
			mult = 75
		}
		complex_trigger_modifier = {
			trigger = count_starbase_modules
			parameters = {
				type = orbital_ring_particle_launcher
			}
			mode = add
			mult = 75
		}
		complex_trigger_modifier = {
			trigger = count_starbase_modules
			parameters = {
				type = orbital_ring_psionic_torpedo
			}
			mode = add
			mult = 75
		}
		complex_trigger_modifier = {
			trigger = count_starbase_modules
			parameters = {
				type = orbital_ring_scourge_missile_battery
			}
			mode = add
			mult = 75
		}
		complex_trigger_modifier = {
			trigger = count_starbase_modules
			parameters = {
				type = orbital_ring_hangar_bay
			}
			mode = add
			mult = 75
		}
		complex_trigger_modifier = {
			trigger = count_starbase_modules
			parameters = {
				type = orbital_ring_archaeo_hangar_bay
			}
			mode = add
			mult = 75
		}
		complex_trigger_modifier = {
			trigger = count_starbase_modules
			parameters = {
				type = orbital_ring_psionic_hangar_bay
			}
			mode = add
			mult = 75
		}
		complex_trigger_modifier = {
			trigger = count_starbase_modules
			parameters = {
				type = orbital_ring_amoeba_hangar_bay
			}
			mode = add
			mult = 75
		}
		complex_trigger_modifier = {
			trigger = count_starbase_modules
			parameters = {
				type = orbital_ring_swarm_hangar_bay
			}
			mode = add
			mult = 75
		}
	}

	ai_design = {
		min = {
			base = 0
		}

		ratio = {
			base = 0
		}

		# token followed by priority
		buildings = {
			target_uplink_computer = {
				base = 2.00
			}

			command_center = {
				base = 2.00
			}

			reloading_bay = {
				base = 2.00
			}

			defense_grid = {
				base = 1.00
			}

			communications_jammer = {
				base = 0.90
			}

			disruption_field = {
				base = 0.90
			}
		}

		modules = {
			orbital_ring_laser_battery = {
				base = 1.00
				modifier = {
					factor = 3
					owner? = { is_preferred_starbase_weapons = weapon_type_energy }
				}
			}

			orbital_ring_archaeo_laser_battery = {
				base = 1.00
				modifier = {
					factor = 3
					owner? = { is_preferred_starbase_weapons = weapon_type_energy }
				}
			}

			orbital_ring_mass_driver_battery = {
				base = 1.00
				modifier = {
					factor = 3
					owner? = { is_preferred_starbase_weapons = weapon_type_kinetic }
				}
			}

			orbital_ring_archaeo_mass_driver_battery = {
				base = 1.00
				modifier = {
					factor = 3
					owner? = { is_preferred_starbase_weapons = weapon_type_kinetic }
				}
			}

			orbital_ring_swarmer_missile_battery = {
				base = 1.00
				modifier = {
					factor = 3
					owner? = { is_preferred_starbase_weapons = weapon_type_explosive }
				}
			}

			orbital_ring_particle_launcher = {
				base = 1.00
				modifier = {
					factor = 3
					owner? = { is_preferred_starbase_weapons = weapon_type_energy }
				}
			}

			orbital_ring_psionic_torpedo = {
				base = 1.00
				modifier = {
					factor = 3
					owner? = { is_preferred_starbase_weapons = weapon_type_energy }
				}
			}

			orbital_ring_scourge_missile_battery = {
				base = 1.00
				modifier = {
					factor = 3
					owner? = { is_preferred_starbase_weapons = weapon_type_explosive }
				}
			}

			orbital_ring_hangar_bay = {
				base = 1.00
				modifier = {
					factor = 3
					owner? = { is_preferred_starbase_weapons = weapon_type_strike_craft }
				}
			}

			orbital_ring_archaeo_hangar_bay = {
				base = 1.00
				modifier = {
					factor = 3
					owner? = { is_preferred_starbase_weapons = weapon_type_strike_craft }
				}
			}

			orbital_ring_psionic_hangar_bay = {
				base = 1.00
				modifier = {
					factor = 3
					owner? = { is_preferred_starbase_weapons = weapon_type_strike_craft }
				}
			}

			orbital_ring_amoeba_hangar_bay = {
				base = 1.00
				modifier = {
					factor = 3
					owner? = { is_preferred_starbase_weapons = weapon_type_strike_craft }
				}
			}

			orbital_ring_swarm_hangar_bay = {
				base = 1.00
				modifier = {
					factor = 3
					owner? = { is_preferred_starbase_weapons = weapon_type_strike_craft }
				}
			}
		}
	}
}

sorbital_habitation = {
	potential = {
		is_orbital_ring = yes
		has_starbase_module = orbital_ring_habitation
	}

	weight_modifier = {
		base = 0
		complex_trigger_modifier = { # +75 for each habitation module
			trigger = count_starbase_modules
			parameters = {
				type = orbital_ring_habitation
			}
			mode = add
			mult = 75
		}
	}

	ai_design = {
		min = {
			base = 1
		}

		ratio = {
			base = 0.50
			modifier = {
				add = 0.25
				exists = owner
				owner = {
					is_pacifist = yes
				}
			}
		}

		# token followed by priority
		buildings = {
			ring_synapse_hub = {
				base = 1.00
			}

			ring_maintenance_hub = {
				base = 1.00
			}

			ring_bureaucracy_hub = {
				base = 0
				modifier = {
					add = 3
					planet = {
						OR = {
							has_designation = col_bureau
							has_designation = col_bureau_spiritualist
							has_building = building_sensorium_1
							has_building = building_autochthon_monument
							has_building = building_corporate_monument
							has_building = building_galactic_memorial_1
							has_building = building_simulation_1
						}
					}
				}
			}

			ring_minerals_hub = {
				base = 0
				modifier = {
					add = 3
					planet = {
						OR = {
							has_designation = col_mining
							has_building = building_mineral_purification_plant
							has_building = building_mineral_purification_hub
							has_building = building_churning_tunnels_3
							has_building = building_churning_tunnels_4
						}
					}
				}
			}

			ring_energy_hub = {
				base = 0
				modifier = {
					add = 3
					planet = {
						OR = {
							has_designation = col_generator
							has_building = building_energy_grid
							has_building = building_energy_nexus
							has_building = building_bioelectric_stimulator_3
							has_building = building_bioelectric_stimulator_4
						}
					}
				}
			}

			ring_food_hub = {
				base = 0
				modifier = {
					add = 3
					planet = {
						OR = {
							has_designation = col_farming
							has_building = building_food_processing_facility
							has_building = building_food_processing_center
							has_building = building_massive_growth_4
						}
					}
				}
			}

			ring_consumer_goods_hub = {
				base = 0
				modifier = {
					add = 3
					planet = {
						OR = {
							has_designation = col_industrial
							has_designation = col_factory
							has_building = building_factory_1
							has_building = building_factory_2
							has_building = building_factory_3
						}
					}
				}
			}

			ring_alloys_hub = {
				base = 0
				modifier = {
					add = 3
					planet = {
						OR = {
							has_designation = col_industrial
							has_designation = col_foundry
							has_building = building_foundry_1
							has_building = building_natural_furnace_1
							has_building = building_foundry_2
							has_building = building_natural_furnace_2
							has_building = building_foundry_3
							has_building = building_natural_furnace_3
						}
					}
				}
			}

			ring_trade_hub = {
				base = 1
				modifier = {
					add = 2
					planet = {
						OR = {
							has_designation = col_city
							has_building = building_galactic_stock_exchange
						}
					}
				}
			}
		}

		modules = {
			orbital_ring_habitation = {
				base = 20.00
			}
		}
	}
}

sorbital_seeder = {
	potential = {
		is_orbital_ring = yes
		exists = owner
		owner = { has_origin = origin_fruitful }
		NOT = { has_global_flag = tiyanki_extinct }
	}

	weight_modifier = {
		base = 0
		modifier = {
			add = 500
			has_starbase_building = ring_feeder
		}
	}

	ai_design = { # Similar to the generic sorbital_ring
		min = {
			base = 0
		}

		modules = {
			orbital_ring_habitation = {
				base = 5.00
				modifier = {
					factor = 2
					planet = {
						num_free_districts = { type = any value <= 2 }
					}
				}
			}

			orbital_ring_shipyard = {
				base = 0.0 # Generally better to use normal starbases for this
			}

			orbital_ring_beastport = {
				base = 0.0 # Generally better to use normal starbases for this
			}

			orbital_ring_anchorage = {
				base = 0.0 # Generally better to use normal starbases for this
			}

			orbital_ring_laser_battery = {
				base = 0.0
			}

			orbital_ring_archaeo_laser_battery = {
				base = 0.0
			}

			orbital_ring_mass_driver_battery = {
				base = 0.0
			}

			orbital_ring_archaeo_mass_driver_battery = {
				base = 0.0
			}

			orbital_ring_swarmer_missile_battery = {
				base = 0.0
			}

			orbital_ring_particle_launcher = {
				base = 0.0
			}

			orbital_ring_psionic_torpedo = {
				base = 0.0
			}

			orbital_ring_scourge_missile_battery = {
				base = 0.0
			}

			orbital_ring_hangar_bay = {
				base = 1.00
			}

			orbital_ring_archaeo_hangar_bay = {
				base = 1.00
			}

			orbital_ring_psionic_hangar_bay = {
				base = 1.00
			}

			orbital_ring_amoeba_hangar_bay = {
				base = 1.00
			}

			orbital_ring_swarm_hangar_bay = {
				base = 1.00
			}
		}

		# token followed by priority
		buildings = {
			ring_feeder = {
				base = 5.00
				modifier = {
					add = 5.00
					solar_system = {
						closest_system = {
							limit = {
								has_star_flag = space_critter_system
							}
							min_steps = 0
							max_steps = 5
						}
					}
				}
			}

			ring_synapse_hub = {
				base = 1.00
			}

			ring_maintenance_hub = {
				base = 1.00
			}

			ring_bureaucracy_hub = {
				base = 1
				modifier = {
					add = 2
					planet = {
						OR = {
							has_unity_designation = yes
							has_building = building_sensorium_1
							has_building = building_autochthon_monument
							has_building = building_corporate_monument
							has_building = building_galactic_memorial_1
							has_building = building_simulation_1
						}
					}
				}
			}

			ring_energy_hub = {
				base = 1
				modifier = {
					add = 2
					planet = {
						OR = {
							has_generator_designation = yes
							has_building = building_energy_grid
							has_building = building_energy_nexus
							has_building = building_bioelectric_stimulator_3
							has_building = building_bioelectric_stimulator_4
						}
					}
				}
			}

			ring_food_hub = {
				base = 5
				modifier = {
					add = 2
					planet = {
						OR = {
							has_farming_designation = yes
							has_building = building_food_processing_facility
							has_building = building_food_processing_center
							has_building = building_massive_growth_4
						}
					}
				}
			}

			ring_consumer_goods_hub = {
				base = 1
				modifier = {
					add = 2
					planet = {
						OR = {
							has_factory_designation = yes
							has_industrial_designation = yes
							has_building = building_factory_1
							has_building = building_factory_2
							has_building = building_factory_3
						}
					}
				}
			}

			ring_trade_hub = {
				base = 1
				modifier = {
					add = 2
					planet = {
						OR = {
							has_trade_designation = yes
							has_building = building_galactic_stock_exchange
						}
					}
				}
			}
		}
	}
}
# Space Citadel
sdeepspacecitadel = {
	ai_use_defense_platforms = yes #AI will not build defense platforms otherwise, except in the capital system
	potential = {
		is_space_citadel = yes
	}
}
