StationSystem/jobs/partial spawning refactor (#7580)

* Partial work on StationSystem refactor.

* WIP station jobs API.

* forgor to fire off grid events.

* Partial implementation of StationSpawningSystem

* whoops infinite loop.

* Spawners should work now.

* it compiles.

* tfw

* Vestigial code cleanup.

* fix station deletion.

* attempt to make tests go brr

* add latejoin spawnpoints to test maps.

* make sure the station still exists while destructing spawners.

* forgot an exists check.

* destruction order check.

* hopefully fix final test.

* fail-safe radstorm.

* Deep-clean job code further. This is bugged!!!!!

* Fix job bug. (init order moment)

* whooo cleanup

* New job selection algorithm that tries to distribute fairly across stations.

* small nitpicks

* Give the heads their weights to replace the head field.

* make overflow assign take a station list.

* moment

* Fixes and test #1 of many.

* please fix nullspace

* AssignJobs should no longer even consider showing up on a trace.

* add comment.

* Introduce station configs, praying i didn't miss something.

* in one small change stations are now fully serializable.

* Further doc comments.

* whoops.

* Solve bug where assignjobs didn't account for roundstart.

* Fix spawning, improve the API.
Caught an oversight in stationsystem that should've broke everything but didn't, whoops.

* Goodbye JobController.

* minor fix..

* fix test fail, remove debug logs.

* quick serialization fixes.

* fixes..

* sus

* partialing

* Update Content.Server/Station/Systems/StationJobsSystem.Roundstart.cs

Co-authored-by: Kara <lunarautomaton6@gmail.com>

* Use dirtying to avoid rebuilding the list 2,100 times.

* add a bajillion more lines of docs (mostly in AssignJobs so i don't ever forget how it works)

* Update Content.IntegrationTests/Tests/Station/StationJobsTest.cs

Co-authored-by: Kara <lunarautomaton6@gmail.com>

* Add the Mysteriously Missing Captain Check.

* Put maprender back the way it belongs.

* I love addressing reviews.

* Update Content.Server/Station/Systems/StationJobsSystem.cs

Co-authored-by: Kara <lunarautomaton6@gmail.com>

* doc cleanup.

* Fix bureaucratic error, add job slot tests.

* zero cost abstractions when

* cri

* saner error.

* Fix spawning failing certain tests due to gameticker not handling falliability correctly.
Can't fix this until I refactor the rest of spawning code.

* submodule gaming

* Packedenger.

* Documentation consistency.

Co-authored-by: Kara <lunarautomaton6@gmail.com>
This commit is contained in:
Moony
2022-05-10 13:43:30 -05:00
committed by GitHub
parent d234a79d28
commit 36181334b5
65 changed files with 2564 additions and 1368 deletions

View File

@@ -1,10 +1,6 @@
using Content.Server.GameTicking;
using Robust.Shared.Analyzers;
using Robust.Shared.GameObjects;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.ViewVariables;
namespace Content.Server.Station;
namespace Content.Server.Station.Components;
/// <summary>
/// Added to grids saved in maps to designate that they are the 'main station' grid.

View File

@@ -1,20 +1,15 @@
using Content.Server.GameTicking;
using Robust.Shared.Analyzers;
using Robust.Shared.GameObjects;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.ViewVariables;
namespace Content.Server.Station;
namespace Content.Server.Station.Components;
/// <summary>
/// Added to grids saved in maps to designate them as 'part of a station' and not main grids. I.e. ancillary
/// shuttles for multi-grid stations.
/// </summary>
[RegisterComponent]
[Friend(typeof(GameTicker))]
[RegisterComponent, Friend(typeof(GameTicker)), Obsolete("Performs the exact same function as BecomesStationComponent.")]
public sealed class PartOfStationComponent : Component
{
[DataField("id", required: true)] // does yamllinter even lint maps for required fields?
[DataField("id", required: true)]
[ViewVariables(VVAccess.ReadWrite)]
public string Id = default!;
}

View File

@@ -1,13 +0,0 @@
using Content.Shared.Station;
using Robust.Shared.Analyzers;
using Robust.Shared.GameObjects;
using Robust.Shared.ViewVariables;
namespace Content.Server.Station;
[RegisterComponent, Friend(typeof(StationSystem))]
public sealed class StationComponent : Component
{
[ViewVariables]
public StationId Station = StationId.Invalid;
}

View File

@@ -0,0 +1,28 @@
using Content.Server.Maps;
using Content.Server.Station.Systems;
using Robust.Shared.Map;
namespace Content.Server.Station.Components;
/// <summary>
/// Stores core information about a station, namely it's config and associated grids.
/// All station entities will have this component.
/// </summary>
[RegisterComponent, Friend(typeof(StationSystem))]
public sealed class StationDataComponent : Component
{
/// <summary>
/// The game map prototype, if any, associated with this station.
/// </summary>
[DataField("stationConfig")]
public StationConfig? StationConfig = null;
/// <summary>
/// List of all grids this station is part of.
/// </summary>
/// <remarks>
/// You should not mutate this yourself, go through StationSystem so the appropriate events get fired.
/// </remarks>
[DataField("grids")]
public readonly HashSet<EntityUid> Grids = new();
}

View File

@@ -0,0 +1,61 @@
using Content.Server.Station.Systems;
using Content.Shared.Roles;
using JetBrains.Annotations;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Dictionary;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Set;
namespace Content.Server.Station.Components;
/// <summary>
/// Stores information about a station's job selection.
/// </summary>
[RegisterComponent, Friend(typeof(StationJobsSystem)), PublicAPI]
public sealed class StationJobsComponent : Component
{
/// <summary>
/// Total *round-start* jobs at station start.
/// </summary>
[DataField("roundStartTotalJobs")] public int RoundStartTotalJobs;
/// <summary>
/// Total *mid-round* jobs at station start.
/// </summary>
[DataField("midRoundTotalJobs")] public int MidRoundTotalJobs;
/// <summary>
/// Current total jobs.
/// </summary>
[DataField("totalJobs")] public int TotalJobs;
/// <summary>
/// The percentage of jobs remaining.
/// </summary>
/// <remarks>
/// Null if MidRoundTotalJobs is zero. This is a NaN free API.
/// </remarks>
[ViewVariables]
public float? PercentJobsRemaining => MidRoundTotalJobs > 0 ? TotalJobs / (float) MidRoundTotalJobs : null;
/// <summary>
/// The current list of jobs.
/// </summary>
/// <remarks>
/// This should not be mutated or used directly unless you really know what you're doing, go through StationJobsSystem.
/// </remarks>
[DataField("jobList", customTypeSerializer: typeof(PrototypeIdDictionarySerializer<uint?, JobPrototype>))]
public Dictionary<string, uint?> JobList = new();
/// <summary>
/// The round-start list of jobs.
/// </summary>
/// <remarks>
/// This should not be mutated, ever.
/// </remarks>
[DataField("roundStartJobList", customTypeSerializer: typeof(PrototypeIdDictionarySerializer<uint?, JobPrototype>))]
public Dictionary<string, uint?> RoundStartJobList = new();
/// <summary>
/// Overflow jobs that round-start can spawn infinitely many of.
/// </summary>
[DataField("overflowJobs", customTypeSerializer: typeof(PrototypeIdHashSetSerializer<JobPrototype>))] public HashSet<string> OverflowJobs = new();
}

View File

@@ -0,0 +1,16 @@
using Content.Server.Station.Systems;
namespace Content.Server.Station.Components;
/// <summary>
/// Indicates that a grid is a member of the given station.
/// </summary>
[RegisterComponent, Friend(typeof(StationSystem))]
public sealed class StationMemberComponent : Component
{
/// <summary>
/// Station that this grid is a part of.
/// </summary>
[ViewVariables]
public EntityUid Station = EntityUid.Invalid;
}

View File

@@ -0,0 +1,12 @@
using Content.Server.Station.Systems;
using Robust.Shared.Map;
namespace Content.Server.Station.Components;
/// <summary>
/// Controls spawning on the given station, tracking spawners present on it.
/// </summary>
[RegisterComponent, Friend(typeof(StationSpawningSystem))]
public sealed class StationSpawningComponent : Component
{
}