Skip to content

Commit

Permalink
listening post rewrite (#1369)
Browse files Browse the repository at this point in the history
* rename pirate radio map to listening post, change spawner prototype

* refactor pirate radio spawn rule into DebrisSpawner and LoadFarGrid

* remove obsolete yml

* -m make listening post rule use new stuff and antag selection

* other changes

* fixes

* more

* fixy

* fix nan

* final fix

* what

---------

Co-authored-by: deltanedas <@deltanedas:kde.org>
  • Loading branch information
deltanedas authored Jun 13, 2024
1 parent b00856c commit 5e812e0
Show file tree
Hide file tree
Showing 15 changed files with 281 additions and 204 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Delta-V - This file is licensed under AGPLv3
* Copyright (c) 2024 Delta-V Contributors
* See AGPLv3.txt for details.
*/

using Content.Server.StationEvents.Events;

namespace Content.Server.StationEvents.Components;

/// <summary>
/// Spawns random debris in space around a loaded grid.
/// Requires <see cref="LoadFarGridRuleComponent"/>.
/// </summary>
[RegisterComponent, Access(typeof(DebrisSpawnerRule))]
public sealed partial class DebrisSpawnerRuleComponent : Component
{
/// <summary>
/// How many debris grids to spawn.
/// </summary>
[DataField(required: true)]
public int Count;

/// <summary>
/// Modifier for debris distance.
/// Should be between 3 and 10 generally.
/// </summary>
[DataField(required: true)]
public float DistanceModifier;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Delta-V - This file is licensed under AGPLv3
* Copyright (c) 2024 Delta-V Contributors
* See AGPLv3.txt for details.
*/

using Content.Server.StationEvents.Events;
using Robust.Shared.Utility;

namespace Content.Server.StationEvents.Components;

/// <summary>
/// Loads a grid far away from a random station.
/// Requires <see cref="RuleGridsComponent"/>.
/// </summary>
[RegisterComponent, Access(typeof(LoadFarGridRule))]
public sealed partial class LoadFarGridRuleComponent : Component
{
/// <summary>
/// Path to the grid to spawn.
/// </summary>
[DataField(required: true)]
public ResPath Path = new();

/// <summary>
/// Roughly how many AABBs away
/// </summary>
[DataField(required: true)]
public float DistanceModifier;

/// <summary>
/// "Stations of Unusual Size Constant", derived from the AABB.Width of Shoukou.
/// This Constant is used to check the size of a station relative to the reference point
/// </summary>
[DataField]
public float Sousk = 123.44f;
}

This file was deleted.

71 changes: 71 additions & 0 deletions Content.Server/DeltaV/StationEvents/Events/DebrisSpawnerRule.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* Delta-V - This file is licensed under AGPLv3
* Copyright (c) 2024 Delta-V Contributors
* See AGPLv3.txt for details.
*/

using Content.Server.GameTicking.Rules;
using Content.Server.Station.Components;
using Content.Server.StationEvents.Components;
using Content.Shared.CCVar;
using Content.Shared.Salvage;
using Robust.Server.GameObjects;
using Robust.Server.Maps;
using Robust.Shared.Configuration;
using Robust.Shared.Map;
using Robust.Shared.Map.Components;
using Robust.Shared.Prototypes;
using Robust.Shared.Random;
using System.Linq;

namespace Content.Server.StationEvents.Events;

public sealed class DebrisSpawnerRule : StationEventSystem<DebrisSpawnerRuleComponent>
{
[Dependency] private readonly IConfigurationManager _config = default!;
[Dependency] private readonly IPrototypeManager _proto = default!;
[Dependency] private readonly MapLoaderSystem _mapLoader = default!;

public override void Initialize()
{
base.Initialize();

SubscribeLocalEvent<DebrisSpawnerRuleComponent, RuleLoadedGridsEvent>(OnLoadedGrids);
}

private void OnLoadedGrids(Entity<DebrisSpawnerRuleComponent> ent, ref RuleLoadedGridsEvent args)
{
if (_config.GetCVar<bool>(CCVars.WorldgenEnabled))
return;

// get world AABBs of every grid that was loaded, probably just 1 anyway
var boxes = new List<Box2>(args.Grids.Count);
foreach (var gridId in args.Grids)
{
var grid = Comp<MapGridComponent>(gridId);
var aabb = Transform(gridId).WorldMatrix.TransformBox(grid.LocalAABB);
boxes.Add(aabb);
}

// fetch all the salvage maps that can be picked
var salvageMaps = _proto.EnumeratePrototypes<SalvageMapPrototype>().ToList();

// spawn them!
for (var i = 0; i < ent.Comp.Count; i++)
{
var aabb = RobustRandom.Pick(boxes);
var dist = MathF.Max(aabb.Height / 2f, aabb.Width / 2f) * ent.Comp.DistanceModifier;

var offset = RobustRandom.NextVector2(dist, dist * 2.5f);
var randomer = RobustRandom.NextVector2(dist, dist * 5f); //Second random vector to ensure the outpost isn't perfectly centered in the debris field
var options = new MapLoadOptions
{
Offset = aabb.Center + offset + randomer,
LoadMap = false,
};

var salvage = RobustRandom.PickAndTake(salvageMaps);
_mapLoader.Load(args.Map, salvage.MapPath.ToString(), options);
}
}
}
78 changes: 78 additions & 0 deletions Content.Server/DeltaV/StationEvents/Events/LoadFarGridRule.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
* Delta-V - This file is licensed under AGPLv3
* Copyright (c) 2024 Delta-V Contributors
* See AGPLv3.txt for details.
*/

using Content.Server.GameTicking.Components;
using Content.Server.GameTicking.Rules;
using Content.Server.Station.Components;
using Content.Server.StationEvents.Components;
using Robust.Server.GameObjects;
using Robust.Server.Maps;
using Robust.Shared.Map;
using Robust.Shared.Map.Components;
using Robust.Shared.Random;

namespace Content.Server.StationEvents.Events;

public sealed class LoadFarGridRule : StationEventSystem<LoadFarGridRuleComponent>
{
[Dependency] private readonly MapLoaderSystem _mapLoader = default!;

protected override void Added(EntityUid uid, LoadFarGridRuleComponent comp, GameRuleComponent rule, GameRuleAddedEvent args)
{
base.Added(uid, comp, rule, args);

if (!TryGetRandomStation(out var station) || !TryComp<StationDataComponent>(station, out var data))
{
Log.Error($"{ToPrettyString(uid):rule} failed to find a station!");
ForceEndSelf(uid, rule);
return;
}

if (data.Grids.Count < 1)
{
Log.Error($"{ToPrettyString(uid):rule} picked station {station} which had no grids!");
ForceEndSelf(uid, rule);
return;
}

// get an AABB that contains all the station's grids
var aabb = new Box2();
var map = MapId.Nullspace;
foreach (var gridId in data.Grids)
{
// use the first grid's map id
if (map == MapId.Nullspace)
map = Transform(gridId).MapID;

var grid = Comp<MapGridComponent>(gridId);
var gridAabb = Transform(gridId).WorldMatrix.TransformBox(grid.LocalAABB);
aabb = aabb.Union(gridAabb);
}

var scale = comp.Sousk / aabb.Width;
var modifier = comp.DistanceModifier * scale;
var dist = MathF.Max(aabb.Height / 2f, aabb.Width / 2f) * modifier;
var offset = RobustRandom.NextVector2(dist, dist * 2.5f);
var options = new MapLoadOptions
{
Offset = aabb.Center + offset,
LoadMap = false
};

var path = comp.Path.ToString();
Log.Debug($"Loading far grid {path} at {options.Offset}");
if (!_mapLoader.TryLoad(map, path, out var grids, options))
{
Log.Error($"{ToPrettyString(uid):rule} failed to load grid {path}!");
ForceEndSelf(uid, rule);
return;
}

// let other systems do stuff
var ev = new RuleLoadedGridsEvent(map, grids);
RaiseLocalEvent(uid, ref ev);
}
}
99 changes: 0 additions & 99 deletions Content.Server/DeltaV/StationEvents/Events/PirateRadioSpawnRule.cs

This file was deleted.

9 changes: 9 additions & 0 deletions Content.Server/Roles/ListeningPostRoleComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using Content.Shared.Roles;

namespace Content.Server.Roles;

/// <summary>
/// DeltaV - listening post ops have their own role
/// </summary>
[RegisterComponent, ExclusiveAntagonist]
public sealed partial class ListeningPostRoleComponent : AntagonistRoleComponent;
1 change: 1 addition & 0 deletions Content.Server/Roles/RoleSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public override void Initialize()
SubscribeAntagEvents<TraitorRoleComponent>();
SubscribeAntagEvents<ZombieRoleComponent>();
SubscribeAntagEvents<ThiefRoleComponent>();
SubscribeAntagEvents<ListeningPostRoleComponent>(); // DeltaV - listening post role
}

public string? MindGetBriefing(EntityUid? mindId)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
listening-post-round-end-agent-name = Listening Post Operative
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ entities:
- type: MetaData
name: unknown
- type: Transform
parent: invalid
- type: MapGrid
chunks:
0,0:
Expand Down Expand Up @@ -5546,7 +5545,7 @@ entities:
- type: Transform
pos: 2.5,2.5
parent: 1
- proto: SpawnPointGhostSyndicateListener
- proto: SpawnPointNukies
entities:
- uid: 813
components:
Expand Down
Loading

0 comments on commit 5e812e0

Please sign in to comment.