Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Listening Post Code Refactor #398

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,4 @@ public sealed partial class PirateRadioSpawnRuleComponent : Component

[DataField("debrisCount")]
public int DebrisCount { get; set; }

[DataField("distanceModifier")]
public float DistanceModifier { get; set; }

[DataField("debrisDistanceModifier")]
public float DebrisDistanceModifier { get; set; }

/// <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("sousk")]
public float SOUSK = 123.44f;

}
30 changes: 10 additions & 20 deletions Content.Server/DeltaV/StationEvents/Events/PirateRadioSpawnRule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
using Content.Shared.Random.Helpers;
using System.Linq;
using Content.Shared.CCVar;
using System.Numerics;

namespace Content.Server.StationEvents.Events;

Expand All @@ -41,50 +42,39 @@ protected override void Started(EntityUid uid, PirateRadioSpawnRuleComponent com
x.Grids.Select(x =>
xformQuery.GetComponent(x).WorldMatrix.TransformBox(_mapManager.GetGridComp(x).LocalAABB)))
.ToArray();
if (aabbs.Length < 1) return;
var aabb = aabbs[0];

for (var i = 1; i < aabbs.Length; i++)
{
aabb.Union(aabbs[i]);
}
var distanceFactorCoefficient = component.SOUSK / aabb.Width;
var distanceModifier = Math.Clamp(component.DistanceModifier, 1, 25);
var distanceModifierNormalized = distanceModifier * distanceFactorCoefficient;
var a = MathF.Max(aabb.Height / 2f, aabb.Width / 2f) * distanceModifierNormalized;
var randomoffset = _random.NextVector2(a, a * 2.5f);
var theta = _random.NextFloat(0, 2 * MathF.PI);
var randomoffset = _random.NextFloat(800f, 1500f) * new Vector2(MathF.Cos(theta), MathF.Sin(theta));

var outpostOptions = new MapLoadOptions
{
Offset = aabb.Center + randomoffset,
Offset = aabbs[0].Center + randomoffset,
LoadMap = false,
};
if (!_map.TryLoad(GameTicker.DefaultMap, component.PirateRadioShuttlePath, out var outpostids, outpostOptions)) return;
//End of Syndicate Listening Outpost spawning system

//Start of Debris Field Generation
var debrisSpawner = _confMan.GetCVar<bool>(CCVars.WorldgenEnabled);
if (debrisSpawner == true) return;
var debrisSpawner = _confMan.GetCVar(CCVars.WorldgenEnabled);
if (debrisSpawner == true || component.DebrisCount == 0) return;
var debrisCount = Math.Clamp(component.DebrisCount, 0, 6);
if (debrisCount == 0) return;
var debrisDistanceModifier = Math.Clamp(component.DebrisDistanceModifier, 3, 10);

foreach (var id in outpostids)
{
if (!TryComp<MapGridComponent>(id, out var grid)) return;
var outpostaabb = _entities.GetComponent<TransformComponent>(id).WorldMatrix.TransformBox(grid.LocalAABB);
var b = MathF.Max(outpostaabb.Height / 2f, aabb.Width / 2f) * debrisDistanceModifier;
var k = 1;
while (k < debrisCount + 1)
{
var debrisRandomOffset = _random.NextVector2(b, b * 2.5f);
var randomer = _random.NextVector2(b, b * 5f); //Second random vector to ensure the outpost isn't perfectly centered in the debris field
var debrisOptions = new MapLoadOptions
{
Offset = outpostaabb.Center + debrisRandomOffset + randomer,
Offset = outpostaabb.Center + _random.NextFloat(250f, 500f) * new Vector2(MathF.Cos(theta), MathF.Sin(theta)),
LoadMap = false,
};

var salvageProto = _random.Pick(_prototypeManager.EnumeratePrototypes<SalvageMapPrototype>().ToList());
_map.TryLoad(GameTicker.DefaultMap, salvageProto.MapPath.ToString(), out _, debrisOptions);
theta += _random.NextFloat(MathF.PI / 18, MathF.PI / 3);
k++;
}
}
Expand Down
2 changes: 0 additions & 2 deletions Resources/Prototypes/DeltaV/GameRules/events.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,3 @@
duration: 1
- type: PirateRadioSpawnRule
debrisCount: 6
distanceModifier: 13
debrisDistanceModifier: 3
Loading