Refactor runtime bootstrap and ship control flows
This commit is contained in:
@@ -3,8 +3,56 @@ namespace SpaceGame.Api.Shared.Runtime;
|
||||
|
||||
internal static class SimulationRuntimeSupport
|
||||
{
|
||||
internal static bool HasShipCapabilities(ShipDefinition definition, params string[] capabilities) =>
|
||||
capabilities.All(cap => definition.Capabilities.Contains(cap, StringComparer.Ordinal));
|
||||
internal static bool CanWarp(ShipDefinition definition) =>
|
||||
definition.Engines.Count > 0;
|
||||
|
||||
internal static bool CanFtl(ShipDefinition definition) =>
|
||||
definition.Engines.Count > 0;
|
||||
|
||||
internal static bool IsMiningShip(ShipDefinition definition) =>
|
||||
definition.Type is ShipType.Miner or ShipType.LargeMiner;
|
||||
|
||||
internal static bool IsTransportShip(ShipDefinition definition) =>
|
||||
definition.Type is ShipType.Freighter or ShipType.Transporter or ShipType.Courier or ShipType.Resupplier;
|
||||
|
||||
internal static bool IsConstructionShip(ShipDefinition definition) =>
|
||||
definition.Type == ShipType.Builder;
|
||||
|
||||
internal static bool IsMilitaryShip(ShipDefinition definition) =>
|
||||
definition.Type is ShipType.Fighter
|
||||
or ShipType.HeavyFighter
|
||||
or ShipType.Destroyer
|
||||
or ShipType.Bomber
|
||||
or ShipType.Frigate
|
||||
or ShipType.Interceptor
|
||||
or ShipType.Corvette
|
||||
or ShipType.Battleship
|
||||
or ShipType.Gunboat;
|
||||
|
||||
internal static string? GetShipCategory(ShipDefinition definition)
|
||||
{
|
||||
if (IsMilitaryShip(definition))
|
||||
{
|
||||
return "military";
|
||||
}
|
||||
|
||||
if (IsConstructionShip(definition))
|
||||
{
|
||||
return "construction";
|
||||
}
|
||||
|
||||
if (IsTransportShip(definition))
|
||||
{
|
||||
return "transport";
|
||||
}
|
||||
|
||||
if (IsMiningShip(definition))
|
||||
{
|
||||
return "mining";
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
internal static int CountStationModules(StationRuntime station, ModuleType moduleType) =>
|
||||
station.Modules.Count(module => module.ModuleType == moduleType);
|
||||
@@ -131,13 +179,13 @@ internal static class SimulationRuntimeSupport
|
||||
modules.All(moduleId => station.Modules.Any(candidate => string.Equals(candidate.ModuleId, moduleId, StringComparison.Ordinal)));
|
||||
|
||||
internal static bool CanExtractNode(ShipRuntime ship, ResourceNodeRuntime node, SimulationWorld world) =>
|
||||
HasShipCapabilities(ship.Definition, "mining")
|
||||
IsMiningShip(ship.Definition)
|
||||
&& world.ItemDefinitions.TryGetValue(node.ItemId, out var item)
|
||||
&& item.CargoKind is not null
|
||||
&& item.CargoKind == ship.Definition.CargoKind;
|
||||
&& ship.Definition.SupportsCargoKind(item.CargoKind.Value);
|
||||
|
||||
internal static bool CanBuildClaimBeacon(ShipRuntime ship) =>
|
||||
string.Equals(ship.Definition.Kind, "military", StringComparison.Ordinal);
|
||||
IsMilitaryShip(ship.Definition);
|
||||
|
||||
internal static float ComputeWorkforceRatio(float population, float workforceRequired)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user