Refactor how jobs are handed out (#5422)

* Completely refactor how job spawning works

* Remove remains of old system.

* Squash the final bug, cleanup.

* Attempt to fix tests

* Adjusts packed's round-start crew roster, re-enables a bunch of old roles.
Also adds the Central Command Official as a proper role.

* pretty up ui

* refactor StationSystem into the correct folder & namespace.

* remove a log, make sure the lobby gets updated if a new map is spontaneously added.

* re-add accidentally removed log

* We do a little logging

* we do a little resolving

* we do a little documenting

* Renamed OverflowJob to FallbackOverflowJob
Allows stations to configure their own roundstart overflow job list.

* narrator: it did not compile

* oops

* support having no overflow jobs

* filescope for consistency

* small fixes

* Bumps a few role counts for Packed, namely engis

* log moment

* E

* Update Resources/Prototypes/Entities/Objects/Misc/identification_cards.yml

Co-authored-by: Leon Friedrich <60421075+ElectroJr@users.noreply.github.com>

* Update Content.Server/Maps/GameMapPrototype.cs

Co-authored-by: Leon Friedrich <60421075+ElectroJr@users.noreply.github.com>

* factored job logic, cleanup.

* e

* Address reviews

* Remove the concept of a "default" grid.
It has no future in our new multi-station world

* why was clickable using that in the first place

* fix bad evil bug that almost slipped through
also adds chemist

* rms obsolete things from chemist

* Adds a sanity fallback

* address reviews

* adds ability to set name

* fuck

* cleanup joingame
This commit is contained in:
Moony
2021-11-26 03:02:46 -06:00
committed by GitHub
parent dfb329d5db
commit ec68226e99
53 changed files with 1148 additions and 705 deletions

View File

@@ -1,7 +1,8 @@
using Content.Server.Atmos.Components;
using System.Linq;
using Content.Server.Atmos.EntitySystems;
using Content.Server.GameTicking;
using Content.Server.Station;
using Content.Shared.Atmos;
using Content.Shared.Station;
using Robust.Shared.Audio;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
@@ -15,6 +16,9 @@ namespace Content.Server.StationEvents.Events
{
internal sealed class GasLeak : StationEvent
{
[Dependency] private IRobustRandom _robustRandom = default!;
[Dependency] private IEntityManager _entityManager = default!;
public override string Name => "GasLeak";
public override string? StartAnnouncement =>
@@ -56,6 +60,8 @@ namespace Content.Server.StationEvents.Events
// Event variables
private StationId _targetStation;
private IEntity? _targetGrid;
private Vector2i _targetTile;
@@ -84,17 +90,16 @@ namespace Content.Server.StationEvents.Events
public override void Startup()
{
base.Startup();
var robustRandom = IoCManager.Resolve<IRobustRandom>();
// Essentially we'll pick out a target amount of gas to leak, then a rate to leak it at, then work out the duration from there.
if (TryFindRandomTile(out _targetTile, robustRandom))
if (TryFindRandomTile(out _targetTile))
{
_foundTile = true;
_leakGas = robustRandom.Pick(LeakableGases);
_leakGas = _robustRandom.Pick(LeakableGases);
// Was 50-50 on using normal distribution.
var totalGas = (float) robustRandom.Next(MinimumGas, MaximumGas);
_molesPerSecond = robustRandom.Next(MinimumMolesPerSecond, MaximumMolesPerSecond);
var totalGas = (float) _robustRandom.Next(MinimumGas, MaximumGas);
_molesPerSecond = _robustRandom.Next(MinimumMolesPerSecond, MaximumMolesPerSecond);
EndAfter = totalGas / _molesPerSecond + StartAfter;
Logger.InfoS("stationevents", $"Leaking {totalGas} of {_leakGas} over {EndAfter - StartAfter} seconds at {_targetTile}");
}
@@ -147,8 +152,7 @@ namespace Content.Server.StationEvents.Events
private void Spark()
{
var atmosphereSystem = EntitySystem.Get<AtmosphereSystem>();
var robustRandom = IoCManager.Resolve<IRobustRandom>();
if (robustRandom.NextFloat() <= SparkChance)
if (_robustRandom.NextFloat() <= SparkChance)
{
if (!_foundTile ||
_targetGrid == null ||
@@ -165,27 +169,31 @@ namespace Content.Server.StationEvents.Events
}
}
private bool TryFindRandomTile(out Vector2i tile, IRobustRandom? robustRandom = null)
private bool TryFindRandomTile(out Vector2i tile)
{
tile = default;
var defaultGridId = EntitySystem.Get<GameTicker>().DefaultGridId;
if (!IoCManager.Resolve<IMapManager>().TryGetGrid(defaultGridId, out var grid) ||
!IoCManager.Resolve<IEntityManager>().TryGetEntity(grid.GridEntityId, out _targetGrid)) return false;
_targetStation = _robustRandom.Pick(_entityManager.EntityQuery<StationComponent>().ToArray()).Station;
var possibleTargets = _entityManager.EntityQuery<StationComponent>()
.Where(x => x.Station == _targetStation).ToArray();
_targetGrid = _robustRandom.Pick(possibleTargets).Owner;
if (!_entityManager.TryGetComponent<IMapGridComponent>(_targetGrid!.Uid, out var gridComp))
return false;
var grid = gridComp.Grid;
var atmosphereSystem = EntitySystem.Get<AtmosphereSystem>();
robustRandom ??= IoCManager.Resolve<IRobustRandom>();
var found = false;
var gridBounds = grid.WorldBounds;
var gridPos = grid.WorldPosition;
for (var i = 0; i < 10; i++)
{
var randomX = robustRandom.Next((int) gridBounds.Left, (int) gridBounds.Right);
var randomY = robustRandom.Next((int) gridBounds.Bottom, (int) gridBounds.Top);
var randomX = _robustRandom.Next((int) gridBounds.Left, (int) gridBounds.Right);
var randomY = _robustRandom.Next((int) gridBounds.Bottom, (int) gridBounds.Top);
tile = new Vector2i(randomX - (int) gridPos.X, randomY - (int) gridPos.Y);
if (atmosphereSystem.IsTileSpace(defaultGridId, tile) || atmosphereSystem.IsTileAirBlocked(defaultGridId, tile)) continue;
if (atmosphereSystem.IsTileSpace(grid, tile) || atmosphereSystem.IsTileAirBlocked(grid, tile)) continue;
found = true;
_targetCoords = grid.GridTileToLocal(tile);
break;

View File

@@ -1,6 +1,8 @@
using Content.Server.GameTicking;
using System.Linq;
using Content.Server.Radiation;
using Content.Server.Station;
using Content.Shared.Coordinates;
using Content.Shared.Station;
using JetBrains.Annotations;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
@@ -29,6 +31,7 @@ namespace Content.Server.StationEvents.Events
private float _timeUntilPulse;
private const float MinPulseDelay = 0.2f;
private const float MaxPulseDelay = 0.8f;
private StationId _target = StationId.Invalid;
private void ResetTimeUntilPulse()
{
@@ -44,6 +47,7 @@ namespace Content.Server.StationEvents.Events
public override void Startup()
{
ResetTimeUntilPulse();
_target = _robustRandom.Pick(_entityManager.EntityQuery<StationComponent>().ToArray()).Station;
base.Startup();
}
@@ -63,12 +67,18 @@ namespace Content.Server.StationEvents.Events
if (_timeUntilPulse <= 0.0f)
{
var pauseManager = IoCManager.Resolve<IPauseManager>();
var defaultGrid = IoCManager.Resolve<IMapManager>().GetGrid(EntitySystem.Get<GameTicker>().DefaultGridId);
// Account for split stations by just randomly picking a piece of it.
var possibleTargets = _entityManager.EntityQuery<StationComponent>()
.Where(x => x.Station == _target).ToArray();
var stationEnt = _robustRandom.Pick(possibleTargets).OwnerUid;
if (pauseManager.IsGridPaused(defaultGrid))
if (!_entityManager.TryGetComponent<IMapGridComponent>(stationEnt, out var grid))
return;
SpawnPulse(defaultGrid);
if (pauseManager.IsGridPaused(grid.GridIndex))
return;
SpawnPulse(grid.Grid);
}
}