Refactor modular startup and viewer ship debugging
This commit is contained in:
@@ -8,10 +8,10 @@ public sealed class ScenarioLoader
|
||||
private const string DefaultFactionId = "sol-dominion";
|
||||
private const int TargetSystemCount = 160;
|
||||
private const int WorldSeed = 1;
|
||||
private const float MinimumFactionCredits = 240f;
|
||||
private const float MinimumRefineryOre = 60f;
|
||||
private const float MinimumRefineryStock = 40f;
|
||||
private const float MinimumShipyardStock = 180f;
|
||||
private const float MinimumFactionCredits = 0f;
|
||||
private const float MinimumRefineryOre = 0f;
|
||||
private const float MinimumRefineryStock = 0f;
|
||||
private const float MinimumShipyardStock = 0f;
|
||||
private const float MinimumSystemSeparation = 3200f;
|
||||
private static readonly string[] GeneratedSystemNames =
|
||||
[
|
||||
@@ -87,10 +87,12 @@ public sealed class ScenarioLoader
|
||||
var scenario = Read<ScenarioDefinition>("scenario.json");
|
||||
var ships = Read<List<ShipDefinition>>("ships.json");
|
||||
var constructibles = Read<List<ConstructibleDefinition>>("constructibles.json");
|
||||
var items = Read<List<ItemDefinition>>("items.json");
|
||||
var balance = Read<BalanceDefinition>("balance.json");
|
||||
|
||||
var shipDefinitions = ships.ToDictionary((definition) => definition.Id, StringComparer.Ordinal);
|
||||
var constructibleDefinitions = constructibles.ToDictionary((definition) => definition.Id, StringComparer.Ordinal);
|
||||
var itemDefinitions = items.ToDictionary((definition) => definition.Id, StringComparer.Ordinal);
|
||||
var systemRuntimes = systems
|
||||
.Select((definition) => new SystemRuntime
|
||||
{
|
||||
@@ -138,14 +140,18 @@ public sealed class ScenarioLoader
|
||||
Definition = definition,
|
||||
Position = ResolveStationPosition(system, plan, balance),
|
||||
FactionId = plan.FactionId ?? DefaultFactionId,
|
||||
OreStored = 0f,
|
||||
RefinedStock = 0f,
|
||||
});
|
||||
}
|
||||
|
||||
foreach (var station in stations)
|
||||
{
|
||||
station.Inventory["gas"] = 320f;
|
||||
}
|
||||
|
||||
var refinery = stations.FirstOrDefault((station) =>
|
||||
station.Definition.Category == "refining" && station.SystemId == scenario.MiningDefaults.RefinerySystemId)
|
||||
?? stations.FirstOrDefault((station) => station.Definition.Category == "refining");
|
||||
HasModules(station.Definition, "refinery-stack", "power-core", "liquid-tank", "gas-tank") &&
|
||||
station.SystemId == scenario.MiningDefaults.RefinerySystemId)
|
||||
?? stations.FirstOrDefault((station) => HasModules(station.Definition, "refinery-stack", "power-core", "liquid-tank", "gas-tank"));
|
||||
|
||||
var patrolRoutes = scenario.PatrolRoutes.ToDictionary(
|
||||
(route) => route.SystemId,
|
||||
@@ -177,6 +183,13 @@ public sealed class ScenarioLoader
|
||||
ControllerTask = new ControllerTaskRuntime { Kind = "idle", Threshold = balance.ArrivalThreshold },
|
||||
Health = definition.MaxHealth,
|
||||
});
|
||||
|
||||
shipsRuntime[^1].Inventory["gas"] = definition.Id switch
|
||||
{
|
||||
"constructor" => 90f,
|
||||
"miner" => 90f,
|
||||
_ => 120f,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -194,6 +207,7 @@ public sealed class ScenarioLoader
|
||||
Ships = shipsRuntime,
|
||||
Factions = factions,
|
||||
ShipDefinitions = shipDefinitions,
|
||||
ItemDefinitions = itemDefinitions,
|
||||
GeneratedAtUtc = DateTimeOffset.UtcNow,
|
||||
};
|
||||
}
|
||||
@@ -755,29 +769,32 @@ public sealed class ScenarioLoader
|
||||
.ToList();
|
||||
|
||||
var refineries = ownedStations
|
||||
.Where((station) => station.Definition.Category == "refining")
|
||||
.Where((station) => HasModules(station.Definition, "refinery-stack", "power-core", "liquid-tank", "gas-tank"))
|
||||
.ToList();
|
||||
|
||||
if (refineries.Count > 0)
|
||||
{
|
||||
foreach (var refinery in refineries)
|
||||
{
|
||||
refinery.RefinedStock = MathF.Max(refinery.RefinedStock, MinimumRefineryStock);
|
||||
refinery.Inventory["refined-metals"] = MathF.Max(GetInventoryAmount(refinery.Inventory, "refined-metals"), MinimumRefineryStock);
|
||||
}
|
||||
|
||||
if (refineries.All((station) => station.OreStored < MinimumRefineryOre))
|
||||
if (refineries.All((station) => GetInventoryAmount(station.Inventory, "ore") < MinimumRefineryOre))
|
||||
{
|
||||
refineries[0].OreStored = MinimumRefineryOre;
|
||||
refineries[0].Inventory["ore"] = MinimumRefineryOre;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var shipyard in ownedStations.Where((station) => station.Definition.Category == "shipyard"))
|
||||
{
|
||||
shipyard.RefinedStock = MathF.Max(shipyard.RefinedStock, MinimumShipyardStock);
|
||||
shipyard.Inventory["refined-metals"] = MathF.Max(GetInventoryAmount(shipyard.Inventory, "refined-metals"), MinimumShipyardStock);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static float GetInventoryAmount(IReadOnlyDictionary<string, float> inventory, string itemId) =>
|
||||
inventory.TryGetValue(itemId, out var amount) ? amount : 0f;
|
||||
|
||||
private static string ToFactionLabel(string factionId)
|
||||
{
|
||||
return string.Join(" ",
|
||||
@@ -801,7 +818,7 @@ public sealed class ScenarioLoader
|
||||
IReadOnlyDictionary<string, List<Vector3>> patrolRoutes,
|
||||
StationRuntime? refinery)
|
||||
{
|
||||
if (definition.Role == "mining" && refinery is not null)
|
||||
if (HasModules(definition, "reactor-core", "capacitor-bank", "mining-turret") && refinery is not null)
|
||||
{
|
||||
return new DefaultBehaviorRuntime
|
||||
{
|
||||
@@ -812,7 +829,7 @@ public sealed class ScenarioLoader
|
||||
};
|
||||
}
|
||||
|
||||
if (definition.Role == "military" && patrolRoutes.TryGetValue(systemId, out var route))
|
||||
if (HasModules(definition, "reactor-core", "capacitor-bank", "gun-turret") && patrolRoutes.TryGetValue(systemId, out var route))
|
||||
{
|
||||
return new DefaultBehaviorRuntime
|
||||
{
|
||||
@@ -863,5 +880,11 @@ public sealed class ScenarioLoader
|
||||
: raw;
|
||||
}
|
||||
|
||||
private static bool HasModules(ConstructibleDefinition definition, params string[] modules) =>
|
||||
modules.All((moduleId) => definition.Modules.Contains(moduleId, StringComparer.Ordinal));
|
||||
|
||||
private static bool HasModules(ShipDefinition definition, params string[] modules) =>
|
||||
modules.All((moduleId) => definition.Modules.Contains(moduleId, StringComparer.Ordinal));
|
||||
|
||||
private static Vector3 Add(Vector3 left, Vector3 right) => new(left.X + right.X, left.Y + right.Y, left.Z + right.Z);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user