Deepen faction economy and station planning
This commit is contained in:
@@ -39,8 +39,13 @@ public sealed class SimulationEngine
|
||||
_commanderPlanning.UpdateCommanders(this, world, deltaSeconds, events);
|
||||
_stationLifecycle.UpdateStations(world, deltaSeconds, events);
|
||||
|
||||
foreach (var ship in world.Ships)
|
||||
foreach (var ship in world.Ships.ToList())
|
||||
{
|
||||
if (ship.Health <= 0f)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var previousPosition = ship.Position;
|
||||
var previousState = ship.State;
|
||||
var previousBehavior = ship.DefaultBehavior.Kind;
|
||||
@@ -58,6 +63,7 @@ public sealed class SimulationEngine
|
||||
}
|
||||
|
||||
_orbitalStateUpdater.SyncSpatialState(world);
|
||||
CleanupDestroyedEntities(world, events);
|
||||
world.GeneratedAtUtc = nowUtc;
|
||||
|
||||
return _projection.BuildDelta(world, sequence, events);
|
||||
@@ -75,6 +81,60 @@ public sealed class SimulationEngine
|
||||
internal void PlanStationConstruction(ShipRuntime ship, SimulationWorld world) =>
|
||||
_shipControl.PlanStationConstruction(ship, world);
|
||||
|
||||
internal void PlanAttackTarget(ShipRuntime ship, SimulationWorld world) =>
|
||||
_shipControl.PlanAttackTarget(ship, world);
|
||||
|
||||
internal void PlanTransportHaul(ShipRuntime ship, SimulationWorld world) =>
|
||||
_shipControl.PlanTransportHaul(ship, world);
|
||||
|
||||
internal static float GetShipCargoAmount(ShipRuntime ship) =>
|
||||
SimulationRuntimeSupport.GetShipCargoAmount(ship);
|
||||
|
||||
private static void CleanupDestroyedEntities(SimulationWorld world, ICollection<SimulationEventRecord> events)
|
||||
{
|
||||
foreach (var ship in world.Ships.Where(candidate => candidate.Health <= 0f).ToList())
|
||||
{
|
||||
world.Ships.Remove(ship);
|
||||
if (ship.DockedStationId is not null && world.Stations.FirstOrDefault(station => station.Id == ship.DockedStationId) is { } dockedStation)
|
||||
{
|
||||
dockedStation.DockedShipIds.Remove(ship.Id);
|
||||
dockedStation.DockingPadAssignments.Remove(ship.AssignedDockingPadIndex ?? -1);
|
||||
}
|
||||
|
||||
if (world.Factions.FirstOrDefault(candidate => candidate.Id == ship.FactionId) is { } faction)
|
||||
{
|
||||
faction.ShipsLost += 1;
|
||||
}
|
||||
|
||||
if (ship.CommanderId is not null && world.Commanders.FirstOrDefault(candidate => candidate.Id == ship.CommanderId) is { } commander)
|
||||
{
|
||||
commander.IsAlive = false;
|
||||
}
|
||||
|
||||
events.Add(new SimulationEventRecord("ship", ship.Id, "destroyed", $"{ship.Definition.Label} was destroyed.", DateTimeOffset.UtcNow));
|
||||
}
|
||||
|
||||
foreach (var station in world.Stations.Where(candidate => candidate.Health <= 0f).ToList())
|
||||
{
|
||||
world.Stations.Remove(station);
|
||||
|
||||
if (station.CelestialId is not null && world.Celestials.FirstOrDefault(candidate => candidate.Id == station.CelestialId) is { } celestial)
|
||||
{
|
||||
celestial.OccupyingStructureId = null;
|
||||
}
|
||||
|
||||
foreach (var claim in world.Claims.Where(candidate => candidate.CelestialId == station.CelestialId))
|
||||
{
|
||||
claim.Health = 0f;
|
||||
claim.State = ClaimStateKinds.Destroyed;
|
||||
}
|
||||
|
||||
foreach (var site in world.ConstructionSites.Where(candidate => candidate.StationId == station.Id))
|
||||
{
|
||||
site.State = ConstructionSiteStateKinds.Destroyed;
|
||||
}
|
||||
|
||||
events.Add(new SimulationEventRecord("station", station.Id, "destroyed", $"{station.Label} was destroyed.", DateTimeOffset.UtcNow));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,6 +101,7 @@ internal sealed class SimulationProjectionService
|
||||
station.Id,
|
||||
station.Label,
|
||||
station.Category,
|
||||
station.Objective,
|
||||
station.SystemId,
|
||||
station.LocalPosition,
|
||||
station.CelestialId,
|
||||
@@ -544,6 +545,7 @@ internal sealed class SimulationProjectionService
|
||||
station.Id,
|
||||
station.Label,
|
||||
station.Category,
|
||||
station.Objective,
|
||||
station.SystemId,
|
||||
ToDto(station.Position),
|
||||
station.CelestialId,
|
||||
@@ -770,8 +772,16 @@ internal sealed class SimulationProjectionService
|
||||
ps.ControlledSystemCount,
|
||||
ps.TargetSystemCount,
|
||||
ps.HasShipFactory,
|
||||
ps.OreStockpile,
|
||||
ps.RefinedMetalsStockpile);
|
||||
NormalizeFiniteFloat(ps.OreStockpile),
|
||||
NormalizeFiniteFloat(ps.RefinedMetalsStockpile),
|
||||
NormalizeFiniteFloat(ps.RefinedMetalsProductionRate),
|
||||
NormalizeFiniteFloat(ps.HullpartsStockpile),
|
||||
NormalizeFiniteFloat(ps.HullpartsProductionRate),
|
||||
NormalizeFiniteFloat(ps.ClaytronicsStockpile),
|
||||
NormalizeFiniteFloat(ps.ClaytronicsProductionRate),
|
||||
NormalizeFiniteFloat(ps.WaterStockpile),
|
||||
NormalizeFiniteFloat(ps.WaterProductionRate),
|
||||
NormalizeFiniteFloat(ps.WaterShortageHorizonSeconds));
|
||||
}
|
||||
|
||||
if (commander?.LastGoalPriorities is { } prios)
|
||||
@@ -811,4 +821,7 @@ internal sealed class SimulationProjectionService
|
||||
state.Transit.Progress));
|
||||
|
||||
private static Vector3Dto ToDto(Vector3 value) => new(value.X, value.Y, value.Z);
|
||||
|
||||
private static float NormalizeFiniteFloat(float value) =>
|
||||
float.IsFinite(value) ? value : -1f;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user