mirror of
https://github.com/DeltaV-Station/Delta-v.git
synced 2026-10-03 01:27:26 +00:00
* Pass 1. * i'm FREE * Prevent hangups. * okay fine here's an attribute for settings, will polish later and prolly remove the overridable thing. * sigh. * fix singular trigger bug so LatheTest doesn't flake. * Remove SystemAttribute usage. * Poke * I used the shotgun. You know why? Cause the shot gun doesn’t miss, and unlike the shitty hybrid taser it stops a criminal in their tracks in two hits. Bang, bang, and they’re fucking done. I use four shots just to make damn sure. Because, once again, I’m not there to coddle a buncha criminal scum sucking f------, I’m there to 1) Survive the fucking round. 2) Guard the armory. So you can absolutely get fucked. If I get unbanned, which I won’t, you can guarantee I will continue to use the shotgun to apprehend criminals. Because it’s quick, clean and effective as fuck. Why in the seven hells would I fuck around with the disabler shots, which take half a clip just to bring someone down, or with the tazer bolts which are slow as balls, impossible to aim and do about next to jack shit, fuck all. The shotgun is the superior law enforcement weapon. Because it stops crime. And it stops crime by reducing the number of criminals roaming the fucking halls. * Change the faulty store test into two tests, one of which is ignored for failing.
157 lines
5.9 KiB
C#
157 lines
5.9 KiB
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using Content.IntegrationTests.Fixtures;
|
|
using Content.Server.GameTicking;
|
|
using Content.Server.Power.Components;
|
|
using Content.Server.Power.EntitySystems;
|
|
using Content.Server.Power.NodeGroups;
|
|
using Content.Server.Power.Pow3r;
|
|
using Content.Shared.Maps;
|
|
using Content.Shared.Power.Components;
|
|
using Content.Shared.NodeContainer;
|
|
using Robust.Server.GameObjects;
|
|
using Robust.Shared.EntitySerialization;
|
|
|
|
namespace Content.IntegrationTests.Tests.Power;
|
|
|
|
public sealed class StationPowerTests : GameTest
|
|
{
|
|
/// <summary>
|
|
/// How long the station should be able to survive on stored power if nothing is changed from round start.
|
|
/// </summary>
|
|
private const float MinimumPowerDurationSeconds = 10 * 60;
|
|
|
|
// Begin DeltaV Additions - DeltaV maps for testing
|
|
private static readonly string[] GameMaps =
|
|
[
|
|
"Academy",
|
|
"Arena",
|
|
"Asterisk",
|
|
"Byoin",
|
|
"Chibi",
|
|
"Division",
|
|
"Edge",
|
|
"Elegance",
|
|
"Glacier",
|
|
"Hammurabi",
|
|
"TheHive",
|
|
"Lighthouse",
|
|
"Micro",
|
|
"Ovni",
|
|
"Pebble",
|
|
"Shoukou",
|
|
"Submarine",
|
|
"Terra",
|
|
"Tortuga",
|
|
];
|
|
// Begin DeltaV Additions - DeltaV maps for testing
|
|
|
|
public override PoolSettings PoolSettings => new ()
|
|
{
|
|
Dirty = true,
|
|
};
|
|
|
|
[Explicit]
|
|
[Test, TestCaseSource(nameof(GameMaps))]
|
|
public async Task TestStationStartingPowerWindow(string mapProtoId)
|
|
{
|
|
var pair = Pair;
|
|
var server = pair.Server;
|
|
|
|
var entMan = server.EntMan;
|
|
var protoMan = server.ProtoMan;
|
|
var ticker = entMan.System<GameTicker>();
|
|
var batterySys = entMan.System<BatterySystem>();
|
|
|
|
// Load the map
|
|
await server.WaitAssertion(() =>
|
|
{
|
|
Assert.That(protoMan.TryIndex<GameMapPrototype>(mapProtoId, out var mapProto));
|
|
var opts = DeserializationOptions.Default with { InitializeMaps = true };
|
|
ticker.LoadGameMap(mapProto, out var mapId, opts);
|
|
});
|
|
|
|
// Let powernet set up
|
|
await server.WaitRunTicks(1);
|
|
|
|
// Find the power network with the greatest stored charge in its batteries.
|
|
// This keeps backup SMESes out of the calculation.
|
|
var networks = new Dictionary<PowerState.Network, float>();
|
|
var batteryQuery = entMan.EntityQueryEnumerator<PowerNetworkBatteryComponent, BatteryComponent, NodeContainerComponent>();
|
|
while (batteryQuery.MoveNext(out var uid, out _, out var battery, out var nodeContainer))
|
|
{
|
|
if (!nodeContainer.Nodes.TryGetValue("output", out var node))
|
|
continue;
|
|
if (node.NodeGroup is not IBasePowerNet group)
|
|
continue;
|
|
networks.TryGetValue(group.NetworkNode, out var charge);
|
|
var currentCharge = batterySys.GetCharge((uid, battery));
|
|
networks[group.NetworkNode] = charge + currentCharge;
|
|
}
|
|
var totalStartingCharge = networks.MaxBy(n => n.Value).Value;
|
|
|
|
// Find how much charge all the APC-connected devices would like to use per second.
|
|
var totalAPCLoad = 0f;
|
|
var receiverQuery = entMan.EntityQueryEnumerator<ApcPowerReceiverComponent>();
|
|
while (receiverQuery.MoveNext(out _, out var receiver))
|
|
{
|
|
totalAPCLoad += receiver.Load;
|
|
}
|
|
|
|
var estimatedDuration = totalStartingCharge / totalAPCLoad;
|
|
var requiredStoredPower = totalAPCLoad * MinimumPowerDurationSeconds;
|
|
Assert.Multiple(() =>
|
|
{
|
|
Assert.That(estimatedDuration, Is.GreaterThanOrEqualTo(MinimumPowerDurationSeconds),
|
|
$"Initial power for {mapProtoId} does not last long enough! Needs at least {MinimumPowerDurationSeconds}s " +
|
|
$"but estimated to last only {estimatedDuration}s!");
|
|
Assert.That(totalStartingCharge, Is.GreaterThanOrEqualTo(requiredStoredPower),
|
|
$"Needs at least {requiredStoredPower - totalStartingCharge} more stored power!");
|
|
});
|
|
}
|
|
|
|
[Test, TestCaseSource(nameof(GameMaps))]
|
|
public async Task TestApcLoad(string mapProtoId)
|
|
{
|
|
var pair = Pair;
|
|
var server = pair.Server;
|
|
|
|
var entMan = server.EntMan;
|
|
var protoMan = server.ProtoMan;
|
|
var ticker = entMan.System<GameTicker>();
|
|
var xform = entMan.System<TransformSystem>();
|
|
|
|
// Load the map
|
|
await server.WaitAssertion(() =>
|
|
{
|
|
Assert.That(protoMan.TryIndex<GameMapPrototype>(mapProtoId, out var mapProto));
|
|
var opts = DeserializationOptions.Default with { InitializeMaps = true };
|
|
ticker.LoadGameMap(mapProto, out var mapId, opts);
|
|
});
|
|
|
|
// Wait long enough for power to ramp up, but before anything can trip
|
|
await pair.RunSeconds(2);
|
|
|
|
// Check that no APCs start overloaded
|
|
var apcQuery = entMan.EntityQueryEnumerator<ApcComponent, PowerNetworkBatteryComponent>();
|
|
Assert.Multiple(() =>
|
|
{
|
|
while (apcQuery.MoveNext(out var uid, out var apc, out var battery))
|
|
{
|
|
// Uncomment the following line to log starting APC load to the console
|
|
//Console.WriteLine($"ApcLoad:{mapProtoId}:{uid}:{battery.CurrentSupply}");
|
|
if (xform.TryGetMapOrGridCoordinates(uid, out var coord))
|
|
{
|
|
Assert.That(apc.MaxLoad, Is.GreaterThanOrEqualTo(battery.CurrentSupply),
|
|
$"APC {uid} on {mapProtoId} ({coord.Value.X}, {coord.Value.Y}) is overloaded {battery.CurrentSupply} / {apc.MaxLoad}");
|
|
}
|
|
else
|
|
{
|
|
Assert.That(apc.MaxLoad, Is.GreaterThanOrEqualTo(battery.CurrentSupply),
|
|
$"APC {uid} on {mapProtoId} is overloaded {battery.CurrentSupply} / {apc.MaxLoad}");
|
|
}
|
|
}
|
|
});
|
|
}
|
|
}
|