Skip to content

Commit

Permalink
make midround antag spawn code better (#919)
Browse files Browse the repository at this point in the history
* kill shitcode

* give each midround antag its own spawn rule

* using

* break test real

* typographical error

---------

Co-authored-by: deltanedas <@deltanedas:kde.org>
  • Loading branch information
deltanedas authored Mar 2, 2024
1 parent 8183085 commit 1d24249
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,9 @@ namespace Content.Server.StationEvents.Components;
[RegisterComponent, Access(typeof(MidRoundAntagRule))]
public sealed partial class MidRoundAntagRuleComponent : Component
{
[DataField("antags")]
public List<EntProtoId> MidRoundAntags = new()
{
"SpawnPointGhostRatKing",
//"SpawnPointGhostVampSpider",
//"SpawnPointGhostFugitive",
"SpawnPointGhostParadoxAnomaly"
};
/// <summary>
/// Spawner to create at a random mid round antag marker.
/// </summary>
[DataField(required: true)]
public EntProtoId Spawner = string.Empty;
}
Original file line number Diff line number Diff line change
@@ -1,38 +1,55 @@
using Content.Server.GameTicking.Rules.Components;
using Content.Server.StationEvents.Components;
using Robust.Shared.Random;
using System.Linq;

namespace Content.Server.StationEvents.Events;

public sealed class MidRoundAntagRule : StationEventSystem<MidRoundAntagRuleComponent>
{
[Dependency] private readonly IRobustRandom _random = default!;

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

var spawnLocations = EntityQuery<MidRoundAntagSpawnLocationComponent, TransformComponent>().ToList();
var backupSpawnLocations = EntityQuery<VentCritterSpawnLocationComponent, TransformComponent>().ToList();

TransformComponent? spawn = new();
if (!TryGetRandomStation(out var station))
return;

if (spawnLocations.Count > 0)
{
var spawnLoc = _random.Pick(spawnLocations);
spawn = spawnLoc.Item2;
} else if (backupSpawnLocations.Count > 0)
var spawnLocations = FindSpawns(station.Value);
if (spawnLocations.Count == 0)
{
var spawnLoc = _random.Pick(backupSpawnLocations);
spawn = spawnLoc.Item2;
Log.Warning("Couldn't find any midround antag spawners or vent critter spawners, not spawning an antag.");
return;
}

if (spawn?.GridUid == null)
return;
var spawn = RobustRandom.Pick(spawnLocations);

var proto = _random.Pick(component.MidRoundAntags);
var proto = component.Spawner;
Log.Info($"Spawning midround antag {proto} at {spawn.Coordinates}");
Spawn(proto, spawn.Coordinates);
}

private List<TransformComponent> FindSpawns(EntityUid station)
{
var spawns = new List<TransformComponent>();
var query = EntityQueryEnumerator<MidRoundAntagSpawnLocationComponent, TransformComponent>();
while (query.MoveNext(out var uid, out _, out var xform))
{
if (StationSystem.GetOwningStation(uid, xform) == station && xform.GridUid != null)
spawns.Add(xform);
}

// if there are any midround antag spawns mapped, use them
if (spawns.Count > 0)
return spawns;

// otherwise, fall back to vent critter spawns
Log.Info($"Station {ToPrettyString(station):station} has no midround antag spawnpoints mapped, falling back. Please map them!");
var fallbackQuery = EntityQueryEnumerator<VentCritterSpawnLocationComponent, TransformComponent>();
while (fallbackQuery.MoveNext(out var uid, out _, out var xform))
{
if (StationSystem.GetOwningStation(uid, xform) == station && xform.GridUid != null)
spawns.Add(xform);
}

return spawns;
}
}
32 changes: 24 additions & 8 deletions Resources/Prototypes/Nyanotrasen/GameRules/events.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,34 @@
earliestStart: 15
- type: NoosphericStormRule

# Rat king and paradox anomaly.
# Mid round antag spawns
- type: entity
id: MidRoundAntag
abstract: true
parent: BaseGameRule
id: BaseMidRoundAntag
components:
- type: StationEvent
weight: 7
reoccurrenceDelay: 5
minimumPlayers: 15
earliestStart: 25
- type: MidRoundAntagRule

- type: entity
noSpawn: true
parent: BaseMidRoundAntag
id: RatKingSpawn
components:
- type: StationEvent
weight: 7
reoccurrenceDelay: 5
minimumPlayers: 15
earliestStart: 25
- type: MidRoundAntagRule
- type: MidRoundAntagRule
spawner: SpawnPointGhostRatKing

- type: entity
noSpawn: true
parent: BaseMidRoundAntag
id: ParadoxAnomalySpawn
components:
- type: MidRoundAntagRule
spawner: SpawnPointGhostParadoxAnomaly

# Base glimmer event
- type: entity
Expand Down

0 comments on commit 1d24249

Please sign in to comment.