Skip to content

Commit

Permalink
Merge pull request #370 from sleepyyapril/fix-heisentest
Browse files Browse the repository at this point in the history
Fix PirateRadio Heisentest
  • Loading branch information
FoxxoTrystan authored Nov 22, 2024
2 parents fe28c98 + ac22152 commit 5a556be
Showing 1 changed file with 36 additions and 5 deletions.
41 changes: 36 additions & 5 deletions Content.Server/StationEvents/Events/PirateRadioSpawnRule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
using System.Linq;
using Content.Server.GameTicking.Components;
using Content.Shared.CCVar;
using Robust.Shared.Serialization.Manager;
using Content.Shared.Parallax.Biomes;
using Robust.Shared.Map;

namespace Content.Server.StationEvents.Events;

Expand All @@ -21,25 +24,43 @@ public sealed class PirateRadioSpawnRule : StationEventSystem<PirateRadioSpawnRu
[Dependency] private readonly IConfigurationManager _confMan = default!;
[Dependency] private readonly GameTicker _gameTicker = default!;
[Dependency] private readonly TransformSystem _xform = default!;
[Dependency] private readonly ISerializationManager _serializationManager = default!;
[Dependency] private readonly MapSystem _mapSystem = default!;

protected override void Started(EntityUid uid, PirateRadioSpawnRuleComponent component, GameRuleComponent gameRule, GameRuleStartedEvent args)
{
base.Started(uid, component, gameRule, args);

var stations = _gameTicker.GetSpawnableStations();
if (stations is null || stations.Count <= 0)
if (stations is null)
return;

// Remove any station from the list that is on a Planet's surface.
// We have to do this because if we spawn the listening post 1.5 kilometers from the station on a planet
// The server will then attempt to generate 7 billion entities, immediately exceeding the 32bit signed integer limit for EntityUids.
var stationsCopy = _serializationManager.CreateCopy(stations, notNullableOverride: true);
foreach (var station in stationsCopy)
if (HasComp<BiomeComponent>(Transform(station).MapUid))
stations.Remove(station);

// _random forces Test Fails if given an empty list. which is guaranteed to happen during Tests.
if (stations.Count <= 0)
return;

var targetStation = _random.Pick(stations);
var randomOffset = _random.NextVector2(component.MinimumDistance, component.MaximumDistance);
var targetMapId = Transform(targetStation).MapID;

if (!_mapSystem.MapExists(targetMapId))
return;

var randomOffset = _random.NextVector2(component.MinimumDistance, component.MaximumDistance);
var outpostOptions = new MapLoadOptions
{
Offset = _xform.GetWorldPosition(targetStation) + randomOffset,
LoadMap = false,
};

if (!_map.TryLoad(GameTicker.DefaultMap, _random.Pick(component.PirateRadioShuttlePath), out var outpostids, outpostOptions))
if (!_map.TryLoad(Transform(targetStation).MapID, _random.Pick(component.PirateRadioShuttlePath), out var outpostids, outpostOptions))
return;

SpawnDebris(component, outpostids);
Expand All @@ -55,6 +76,7 @@ private void SpawnDebris(PirateRadioSpawnRuleComponent component, IReadOnlyList<
{
var outpostaabb = _xform.GetWorldPosition(id);
var k = 0;

while (k < component.DebrisCount)
{
var debrisRandomOffset = _random.NextVector2(component.MinimumDebrisDistance, component.MaximumDebrisDistance);
Expand All @@ -65,7 +87,16 @@ private void SpawnDebris(PirateRadioSpawnRuleComponent component, IReadOnlyList<
LoadMap = false,
};

var salvageProto = _random.Pick(_prototypeManager.EnumeratePrototypes<SalvageMapPrototype>().ToList());
var salvPrototypes = _prototypeManager.EnumeratePrototypes<SalvageMapPrototype>().ToList();
var salvageProto = _random.Pick(salvPrototypes);

if (!_mapSystem.MapExists(GameTicker.DefaultMap))
return;

// Round didn't start before running this, leading to a null-space test fail.
if (GameTicker.DefaultMap == MapId.Nullspace)
return;

if (!_map.TryLoad(GameTicker.DefaultMap, salvageProto.MapPath.ToString(), out _, debrisOptions))
return;

Expand All @@ -81,4 +112,4 @@ protected override void Ended(EntityUid uid, PirateRadioSpawnRuleComponent compo
if (component.AdditionalRule != null)
GameTicker.EndGameRule(component.AdditionalRule.Value);
}
}
}

0 comments on commit 5a556be

Please sign in to comment.