Refactor world bootstrap and allow empty startup worlds
This commit is contained in:
@@ -75,6 +75,39 @@ public sealed class SolarSystemDefinition
|
||||
public required List<PlanetDefinition> Planets { get; set; }
|
||||
}
|
||||
|
||||
public sealed class RaceDefinition
|
||||
{
|
||||
public required string Id { get; set; }
|
||||
public required string Name { get; set; }
|
||||
public string Description { get; set; } = string.Empty;
|
||||
public string Icon { get; set; } = string.Empty;
|
||||
[JsonIgnore]
|
||||
public string Label => Name;
|
||||
}
|
||||
|
||||
public sealed class FactionDefinition
|
||||
{
|
||||
public required string Id { get; set; }
|
||||
public int Version { get; set; }
|
||||
public required string Name { get; set; }
|
||||
public string Description { get; set; } = string.Empty;
|
||||
public string Icon { get; set; } = string.Empty;
|
||||
public string? Race { get; set; }
|
||||
public List<FactionLicenseDefinition> Licenses { get; set; } = [];
|
||||
[JsonIgnore]
|
||||
public string Label => Name;
|
||||
[JsonIgnore]
|
||||
public string? RaceId => Race;
|
||||
}
|
||||
|
||||
public sealed class FactionLicenseDefinition
|
||||
{
|
||||
public required string Type { get; set; }
|
||||
public string Name { get; set; } = string.Empty;
|
||||
public string Icon { get; set; } = string.Empty;
|
||||
public float Price { get; set; }
|
||||
}
|
||||
|
||||
public sealed class AsteroidFieldDefinition
|
||||
{
|
||||
public int DecorationCount { get; set; }
|
||||
@@ -338,43 +371,174 @@ public sealed class PlanetDefinition
|
||||
public sealed class ShipDefinition
|
||||
{
|
||||
public required string Id { get; set; }
|
||||
public required string Label { get; set; }
|
||||
public required string Kind { get; set; }
|
||||
public required string Class { get; set; }
|
||||
public float Speed { get; set; }
|
||||
public float WarpSpeed { get; set; }
|
||||
public float FtlSpeed { get; set; }
|
||||
public float SpoolTime { get; set; }
|
||||
public float CargoCapacity { get; set; }
|
||||
public int Version { get; set; }
|
||||
public required string Name { get; set; }
|
||||
public string Description { get; set; } = string.Empty;
|
||||
public string Size { get; set; } = string.Empty;
|
||||
public float ExplosionDamage { get; set; }
|
||||
public float Hull { get; set; }
|
||||
public Dictionary<string, float> Storage { get; set; } = new(StringComparer.Ordinal);
|
||||
public int People { get; set; }
|
||||
public string Purpose { get; set; } = string.Empty;
|
||||
public string Thruster { get; set; } = string.Empty;
|
||||
public string Type { get; set; } = string.Empty;
|
||||
public float Mass { get; set; }
|
||||
public ShipInertiaDefinition? Inertia { get; set; }
|
||||
public ShipDragDefinition? Drag { get; set; }
|
||||
public List<ShipMountDefinition> Engines { get; set; } = [];
|
||||
public List<ShipMountDefinition> Shields { get; set; } = [];
|
||||
public List<ShipMountDefinition> Weapons { get; set; } = [];
|
||||
public List<ShipMountDefinition> Turrets { get; set; } = [];
|
||||
public List<ShipCargoDefinition> Cargo { get; set; } = [];
|
||||
public List<ModuleDockDefinition> Docks { get; set; } = [];
|
||||
public List<string> Owners { get; set; } = [];
|
||||
public ItemPriceDefinition? Price { get; set; }
|
||||
public List<ItemProductionDefinition> Production { get; set; } = [];
|
||||
[JsonIgnore]
|
||||
public StorageKind? CargoKind { get; set; }
|
||||
[JsonPropertyName("cargoKind")]
|
||||
public string? SerializedCargoKind
|
||||
public string Label => Name;
|
||||
[JsonIgnore]
|
||||
public string Kind => InferKind(Purpose);
|
||||
[JsonIgnore]
|
||||
public string Class => Type;
|
||||
[JsonIgnore]
|
||||
public float Speed => InferLocalSpeed(Size);
|
||||
[JsonIgnore]
|
||||
public float WarpSpeed => InferWarpSpeed(Size);
|
||||
[JsonIgnore]
|
||||
public float FtlSpeed => InferFtlSpeed(Size);
|
||||
[JsonIgnore]
|
||||
public float SpoolTime => InferSpoolTime(Size);
|
||||
[JsonIgnore]
|
||||
public float CargoCapacity => Cargo.Sum(entry => entry.Max);
|
||||
[JsonIgnore]
|
||||
public StorageKind? CargoKind => Cargo
|
||||
.SelectMany(entry => entry.Types)
|
||||
.Select(type => type.ToNullableStorageKind())
|
||||
.FirstOrDefault(kind => kind is not null);
|
||||
[JsonIgnore]
|
||||
public float MaxHealth => Hull;
|
||||
[JsonIgnore]
|
||||
public IReadOnlyList<string> Capabilities => InferCapabilities(Purpose, Type, Cargo, Turrets);
|
||||
|
||||
private static string InferKind(string purpose) =>
|
||||
purpose switch
|
||||
{
|
||||
"build" => "construction",
|
||||
"trade" => "transport",
|
||||
"mine" => "mining",
|
||||
"fight" => "military",
|
||||
"auxiliary" => "military",
|
||||
_ => purpose,
|
||||
};
|
||||
|
||||
private static List<string> InferCapabilities(
|
||||
string purpose,
|
||||
string type,
|
||||
IReadOnlyCollection<ShipCargoDefinition> cargo,
|
||||
IReadOnlyCollection<ShipMountDefinition> turrets)
|
||||
{
|
||||
get => CargoKind?.ToDataValue();
|
||||
set => CargoKind = value.ToNullableStorageKind();
|
||||
var capabilities = new List<string> { "warp", "ftl" };
|
||||
|
||||
if (string.Equals(purpose, "mine", StringComparison.Ordinal)
|
||||
|| type.Contains("miner", StringComparison.Ordinal)
|
||||
|| turrets.Any(turret => turret.Types.Contains("mining", StringComparer.Ordinal)))
|
||||
{
|
||||
capabilities.Add("mining");
|
||||
}
|
||||
|
||||
if (cargo.Any(entry => entry.Types.Contains("container", StringComparer.Ordinal)
|
||||
|| entry.Types.Contains("solid", StringComparer.Ordinal)
|
||||
|| entry.Types.Contains("liquid", StringComparer.Ordinal)))
|
||||
{
|
||||
capabilities.Add("cargo");
|
||||
}
|
||||
|
||||
return capabilities;
|
||||
}
|
||||
public required string Color { get; set; }
|
||||
public required string HullColor { get; set; }
|
||||
public float Size { get; set; }
|
||||
public float MaxHealth { get; set; }
|
||||
public List<string> Capabilities { get; set; } = [];
|
||||
public ConstructionDefinition? Construction { get; set; }
|
||||
|
||||
private static float InferWarpSpeed(string size) =>
|
||||
size switch
|
||||
{
|
||||
"extrasmall" => 4.8f,
|
||||
"small" => 4.2f,
|
||||
"medium" => 3.4f,
|
||||
"large" => 2.4f,
|
||||
"extralarge" => 1.8f,
|
||||
_ => 3f,
|
||||
};
|
||||
|
||||
private static float InferLocalSpeed(string size) =>
|
||||
size switch
|
||||
{
|
||||
"extrasmall" => 420f,
|
||||
"small" => 320f,
|
||||
"medium" => 230f,
|
||||
"large" => 150f,
|
||||
"extralarge" => 110f,
|
||||
_ => 200f,
|
||||
};
|
||||
|
||||
private static float InferFtlSpeed(string size) =>
|
||||
size switch
|
||||
{
|
||||
"extrasmall" => 1f,
|
||||
"small" => 0.85f,
|
||||
"medium" => 0.7f,
|
||||
"large" => 0.55f,
|
||||
"extralarge" => 0.45f,
|
||||
_ => 0.6f,
|
||||
};
|
||||
|
||||
private static float InferSpoolTime(string size) =>
|
||||
size switch
|
||||
{
|
||||
"extrasmall" => 0.8f,
|
||||
"small" => 1f,
|
||||
"medium" => 1.4f,
|
||||
"large" => 2f,
|
||||
"extralarge" => 2.6f,
|
||||
_ => 1.5f,
|
||||
};
|
||||
}
|
||||
|
||||
public sealed class GameStartOptionsDefinition
|
||||
public sealed class ShipInertiaDefinition
|
||||
{
|
||||
public int Seed { get; set; } = 1;
|
||||
public WorldGenerationOptions WorldGeneration { get; set; } = new();
|
||||
public float Pitch { get; set; }
|
||||
public float Yaw { get; set; }
|
||||
public float Roll { get; set; }
|
||||
}
|
||||
|
||||
public sealed class ShipDragDefinition
|
||||
{
|
||||
public float Forward { get; set; }
|
||||
public float Reverse { get; set; }
|
||||
public float Horizontal { get; set; }
|
||||
public float Vertical { get; set; }
|
||||
public float Pitch { get; set; }
|
||||
public float Yaw { get; set; }
|
||||
public float Roll { get; set; }
|
||||
}
|
||||
|
||||
public sealed class ShipMountDefinition
|
||||
{
|
||||
public string? Group { get; set; }
|
||||
public required string Size { get; set; }
|
||||
public bool Hittable { get; set; }
|
||||
public List<string> Types { get; set; } = [];
|
||||
}
|
||||
|
||||
public sealed class ShipCargoDefinition
|
||||
{
|
||||
public float Max { get; set; }
|
||||
public List<string> Types { get; set; } = [];
|
||||
}
|
||||
|
||||
public sealed class ScenarioDefinition
|
||||
{
|
||||
public GameStartOptionsDefinition GameStartOptions { get; set; } = new();
|
||||
public required WorldGenerationOptions WorldGeneration { get; set; }
|
||||
public required List<InitialStationDefinition> InitialStations { get; set; }
|
||||
public required List<ShipFormationDefinition> ShipFormations { get; set; }
|
||||
public required List<PatrolRouteDefinition> PatrolRoutes { get; set; }
|
||||
public required MiningDefaultsDefinition MiningDefaults { get; set; }
|
||||
}
|
||||
|
||||
public sealed class InitialStationDefinition
|
||||
@@ -405,9 +569,3 @@ public sealed class PatrolRouteDefinition
|
||||
public required string SystemId { get; set; }
|
||||
public required List<float[]> Points { get; set; }
|
||||
}
|
||||
|
||||
public sealed class MiningDefaultsDefinition
|
||||
{
|
||||
public required string NodeSystemId { get; set; }
|
||||
public required string RefinerySystemId { get; set; }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user