mirror of
https://github.com/DeltaV-Station/Delta-v.git
synced 2026-09-29 23:57:29 +00:00
Unify BatteryComponent and PredictedBatteryComponent (#41867)
* unify * cleanup and merge conflicts * floating points --------- Co-authored-by: Princess Cheeseballs <66055347+Pronana@users.noreply.github.com>
This commit is contained in:
committed by
BarryNorfolk
co-authored by
Princess Cheeseballs
parent
d039f6fdfd
commit
17ff77b61f
@@ -54,6 +54,7 @@ namespace Content.IntegrationTests.Tests.Power
|
||||
nodeGroupID: HVPower
|
||||
- type: PowerNetworkBattery
|
||||
- type: Battery
|
||||
netsync: false
|
||||
- type: BatteryCharger
|
||||
|
||||
- type: entity
|
||||
@@ -68,6 +69,7 @@ namespace Content.IntegrationTests.Tests.Power
|
||||
nodeGroupID: HVPower
|
||||
- type: PowerNetworkBattery
|
||||
- type: Battery
|
||||
netsync: false
|
||||
- type: BatteryDischarger
|
||||
|
||||
- type: entity
|
||||
@@ -85,6 +87,7 @@ namespace Content.IntegrationTests.Tests.Power
|
||||
nodeGroupID: HVPower
|
||||
- type: PowerNetworkBattery
|
||||
- type: Battery
|
||||
netsync: false
|
||||
- type: BatteryDischarger
|
||||
node: output
|
||||
- type: BatteryCharger
|
||||
@@ -110,6 +113,7 @@ namespace Content.IntegrationTests.Tests.Power
|
||||
maxSupply: 1000
|
||||
supplyRampTolerance: 1000
|
||||
- type: Battery
|
||||
netsync: false
|
||||
maxCharge: 1000
|
||||
startingCharge: 1000
|
||||
- type: Transform
|
||||
@@ -119,6 +123,7 @@ namespace Content.IntegrationTests.Tests.Power
|
||||
id: ApcDummy
|
||||
components:
|
||||
- type: Battery
|
||||
netsync: false
|
||||
maxCharge: 10000
|
||||
startingCharge: 10000
|
||||
- type: PowerNetworkBattery
|
||||
@@ -380,6 +385,8 @@ namespace Content.IntegrationTests.Tests.Power
|
||||
const float startingCharge = 100_000;
|
||||
|
||||
PowerNetworkBatteryComponent netBattery = default!;
|
||||
EntityUid generatorEnt = default!;
|
||||
EntityUid consumerEnt = default!;
|
||||
BatteryComponent battery = default!;
|
||||
PowerConsumerComponent consumer = default!;
|
||||
|
||||
@@ -395,8 +402,8 @@ namespace Content.IntegrationTests.Tests.Power
|
||||
entityManager.SpawnEntity("CableHV", grid.Owner.ToCoordinates(0, i));
|
||||
}
|
||||
|
||||
var generatorEnt = entityManager.SpawnEntity("DischargingBatteryDummy", grid.Owner.ToCoordinates());
|
||||
var consumerEnt = entityManager.SpawnEntity("ConsumerDummy", grid.Owner.ToCoordinates(0, 2));
|
||||
generatorEnt = entityManager.SpawnEntity("DischargingBatteryDummy", grid.Owner.ToCoordinates());
|
||||
consumerEnt = entityManager.SpawnEntity("ConsumerDummy", grid.Owner.ToCoordinates(0, 2));
|
||||
|
||||
netBattery = entityManager.GetComponent<PowerNetworkBatteryComponent>(generatorEnt);
|
||||
battery = entityManager.GetComponent<BatteryComponent>(generatorEnt);
|
||||
@@ -441,7 +448,8 @@ namespace Content.IntegrationTests.Tests.Power
|
||||
|
||||
// Trivial integral to calculate expected power spent.
|
||||
const double spentExpected = (200 + 100) / 2.0 * 0.25;
|
||||
Assert.That(battery.CurrentCharge, Is.EqualTo(startingCharge - spentExpected).Within(tickDev));
|
||||
var currentCharge = batterySys.GetCharge((generatorEnt, battery));
|
||||
Assert.That(currentCharge, Is.EqualTo(startingCharge - spentExpected).Within(tickDev));
|
||||
});
|
||||
});
|
||||
|
||||
@@ -460,7 +468,8 @@ namespace Content.IntegrationTests.Tests.Power
|
||||
|
||||
// Trivial integral to calculate expected power spent.
|
||||
const double spentExpected = (400 + 100) / 2.0 * 0.75 + 400 * 0.25;
|
||||
Assert.That(battery.CurrentCharge, Is.EqualTo(startingCharge - spentExpected).Within(tickDev));
|
||||
var currentCharge = batterySys.GetCharge((generatorEnt, battery));
|
||||
Assert.That(currentCharge, Is.EqualTo(startingCharge - spentExpected).Within(tickDev));
|
||||
});
|
||||
});
|
||||
|
||||
@@ -576,6 +585,8 @@ namespace Content.IntegrationTests.Tests.Power
|
||||
var entityManager = server.ResolveDependency<IEntityManager>();
|
||||
var batterySys = entityManager.System<BatterySystem>();
|
||||
var mapSys = entityManager.System<SharedMapSystem>();
|
||||
EntityUid generatorEnt = default!;
|
||||
EntityUid batteryEnt = default!;
|
||||
PowerSupplierComponent supplier = default!;
|
||||
BatteryComponent battery = default!;
|
||||
|
||||
@@ -591,8 +602,8 @@ namespace Content.IntegrationTests.Tests.Power
|
||||
entityManager.SpawnEntity("CableHV", grid.Owner.ToCoordinates(0, i));
|
||||
}
|
||||
|
||||
var generatorEnt = entityManager.SpawnEntity("GeneratorDummy", grid.Owner.ToCoordinates());
|
||||
var batteryEnt = entityManager.SpawnEntity("ChargingBatteryDummy", grid.Owner.ToCoordinates(0, 2));
|
||||
generatorEnt = entityManager.SpawnEntity("GeneratorDummy", grid.Owner.ToCoordinates());
|
||||
batteryEnt = entityManager.SpawnEntity("ChargingBatteryDummy", grid.Owner.ToCoordinates(0, 2));
|
||||
|
||||
supplier = entityManager.GetComponent<PowerSupplierComponent>(generatorEnt);
|
||||
var netBattery = entityManager.GetComponent<PowerNetworkBatteryComponent>(batteryEnt);
|
||||
@@ -615,7 +626,8 @@ namespace Content.IntegrationTests.Tests.Power
|
||||
{
|
||||
// half a second @ 500 W = 250
|
||||
// 50% efficiency, so 125 J stored total.
|
||||
Assert.That(battery.CurrentCharge, Is.EqualTo(125).Within(0.1));
|
||||
var currentCharge = batterySys.GetCharge((batteryEnt, battery));
|
||||
Assert.That(currentCharge, Is.EqualTo(125).Within(0.1));
|
||||
Assert.That(supplier.CurrentSupply, Is.EqualTo(500).Within(0.1));
|
||||
});
|
||||
});
|
||||
@@ -633,6 +645,9 @@ namespace Content.IntegrationTests.Tests.Power
|
||||
var gameTiming = server.ResolveDependency<IGameTiming>();
|
||||
var batterySys = entityManager.System<BatterySystem>();
|
||||
var mapSys = entityManager.System<SharedMapSystem>();
|
||||
EntityUid batteryEnt = default!;
|
||||
EntityUid supplyEnt = default!;
|
||||
EntityUid consumerEnt = default!;
|
||||
PowerConsumerComponent consumer = default!;
|
||||
PowerSupplierComponent supplier = default!;
|
||||
PowerNetworkBatteryComponent netBattery = default!;
|
||||
@@ -653,9 +668,9 @@ namespace Content.IntegrationTests.Tests.Power
|
||||
var terminal = entityManager.SpawnEntity("CableTerminal", grid.Owner.ToCoordinates(0, 1));
|
||||
entityManager.GetComponent<TransformComponent>(terminal).LocalRotation = Angle.FromDegrees(180);
|
||||
|
||||
var batteryEnt = entityManager.SpawnEntity("FullBatteryDummy", grid.Owner.ToCoordinates(0, 2));
|
||||
var supplyEnt = entityManager.SpawnEntity("GeneratorDummy", grid.Owner.ToCoordinates(0, 0));
|
||||
var consumerEnt = entityManager.SpawnEntity("ConsumerDummy", grid.Owner.ToCoordinates(0, 3));
|
||||
batteryEnt = entityManager.SpawnEntity("FullBatteryDummy", grid.Owner.ToCoordinates(0, 2));
|
||||
supplyEnt = entityManager.SpawnEntity("GeneratorDummy", grid.Owner.ToCoordinates(0, 0));
|
||||
consumerEnt = entityManager.SpawnEntity("ConsumerDummy", grid.Owner.ToCoordinates(0, 3));
|
||||
|
||||
consumer = entityManager.GetComponent<PowerConsumerComponent>(consumerEnt);
|
||||
supplier = entityManager.GetComponent<PowerSupplierComponent>(supplyEnt);
|
||||
@@ -694,7 +709,8 @@ namespace Content.IntegrationTests.Tests.Power
|
||||
Assert.That(netBattery.SupplyRampPosition, Is.EqualTo(200).Within(0.1));
|
||||
|
||||
const int expectedSpent = 200;
|
||||
Assert.That(battery.CurrentCharge, Is.EqualTo(battery.MaxCharge - expectedSpent).Within(tickDev));
|
||||
var currentCharge = batterySys.GetCharge((batteryEnt, battery));
|
||||
Assert.That(currentCharge, Is.EqualTo(battery.MaxCharge - expectedSpent).Within(tickDev));
|
||||
});
|
||||
});
|
||||
|
||||
@@ -711,6 +727,9 @@ namespace Content.IntegrationTests.Tests.Power
|
||||
var gameTiming = server.ResolveDependency<IGameTiming>();
|
||||
var batterySys = entityManager.System<BatterySystem>();
|
||||
var mapSys = entityManager.System<SharedMapSystem>();
|
||||
EntityUid batteryEnt = default!;
|
||||
EntityUid supplyEnt = default!;
|
||||
EntityUid consumerEnt = default!;
|
||||
PowerConsumerComponent consumer = default!;
|
||||
PowerSupplierComponent supplier = default!;
|
||||
PowerNetworkBatteryComponent netBattery = default!;
|
||||
@@ -731,9 +750,9 @@ namespace Content.IntegrationTests.Tests.Power
|
||||
var terminal = entityManager.SpawnEntity("CableTerminal", grid.Owner.ToCoordinates(0, 1));
|
||||
entityManager.GetComponent<TransformComponent>(terminal).LocalRotation = Angle.FromDegrees(180);
|
||||
|
||||
var batteryEnt = entityManager.SpawnEntity("FullBatteryDummy", grid.Owner.ToCoordinates(0, 2));
|
||||
var supplyEnt = entityManager.SpawnEntity("GeneratorDummy", grid.Owner.ToCoordinates(0, 0));
|
||||
var consumerEnt = entityManager.SpawnEntity("ConsumerDummy", grid.Owner.ToCoordinates(0, 3));
|
||||
batteryEnt = entityManager.SpawnEntity("FullBatteryDummy", grid.Owner.ToCoordinates(0, 2));
|
||||
supplyEnt = entityManager.SpawnEntity("GeneratorDummy", grid.Owner.ToCoordinates(0, 0));
|
||||
consumerEnt = entityManager.SpawnEntity("ConsumerDummy", grid.Owner.ToCoordinates(0, 3));
|
||||
|
||||
consumer = entityManager.GetComponent<PowerConsumerComponent>(consumerEnt);
|
||||
supplier = entityManager.GetComponent<PowerSupplierComponent>(supplyEnt);
|
||||
@@ -772,7 +791,8 @@ namespace Content.IntegrationTests.Tests.Power
|
||||
Assert.That(netBattery.SupplyRampPosition, Is.EqualTo(400).Within(0.1));
|
||||
|
||||
const int expectedSpent = 400;
|
||||
Assert.That(battery.CurrentCharge, Is.EqualTo(battery.MaxCharge - expectedSpent).Within(tickDev));
|
||||
var currentCharge = batterySys.GetCharge((batteryEnt, battery));
|
||||
Assert.That(currentCharge, Is.EqualTo(battery.MaxCharge - expectedSpent).Within(tickDev));
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1223,6 +1243,9 @@ namespace Content.IntegrationTests.Tests.Power
|
||||
var entityManager = server.ResolveDependency<IEntityManager>();
|
||||
var batterySys = entityManager.System<BatterySystem>();
|
||||
var mapSys = entityManager.System<SharedMapSystem>();
|
||||
EntityUid generatorEnt = default!;
|
||||
EntityUid substationEnt = default!;
|
||||
EntityUid apcEnt = default!;
|
||||
PowerNetworkBatteryComponent substationNetBattery = default!;
|
||||
BatteryComponent apcBattery = default!;
|
||||
|
||||
@@ -1242,9 +1265,9 @@ namespace Content.IntegrationTests.Tests.Power
|
||||
entityManager.SpawnEntity("CableMV", grid.Owner.ToCoordinates(0, 1));
|
||||
entityManager.SpawnEntity("CableMV", grid.Owner.ToCoordinates(0, 2));
|
||||
|
||||
var generatorEnt = entityManager.SpawnEntity("GeneratorDummy", grid.Owner.ToCoordinates(0, 0));
|
||||
var substationEnt = entityManager.SpawnEntity("SubstationDummy", grid.Owner.ToCoordinates(0, 1));
|
||||
var apcEnt = entityManager.SpawnEntity("ApcDummy", grid.Owner.ToCoordinates(0, 2));
|
||||
generatorEnt = entityManager.SpawnEntity("GeneratorDummy", grid.Owner.ToCoordinates(0, 0));
|
||||
substationEnt = entityManager.SpawnEntity("SubstationDummy", grid.Owner.ToCoordinates(0, 1));
|
||||
apcEnt = entityManager.SpawnEntity("ApcDummy", grid.Owner.ToCoordinates(0, 2));
|
||||
|
||||
var generatorSupplier = entityManager.GetComponent<PowerSupplierComponent>(generatorEnt);
|
||||
substationNetBattery = entityManager.GetComponent<PowerNetworkBatteryComponent>(substationEnt);
|
||||
@@ -1262,8 +1285,9 @@ namespace Content.IntegrationTests.Tests.Power
|
||||
{
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
var currentCharge = batterySys.GetCharge((apcEnt, apcBattery));
|
||||
Assert.That(substationNetBattery.CurrentSupply, Is.GreaterThan(0)); //substation should be providing power
|
||||
Assert.That(apcBattery.CurrentCharge, Is.GreaterThan(0)); //apc battery should have gained charge
|
||||
Assert.That(currentCharge, Is.GreaterThan(0)); //apc battery should have gained charge
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.Linq;
|
||||
using Content.Server.GameTicking;
|
||||
using Content.Server.Maps;
|
||||
using Content.Server.Power.Components;
|
||||
using Content.Server.Power.EntitySystems;
|
||||
using Content.Server.Power.NodeGroups;
|
||||
using Content.Server.Power.Pow3r;
|
||||
using Content.Shared.Power.Components;
|
||||
@@ -47,6 +48,7 @@ public sealed class StationPowerTests
|
||||
var entMan = server.EntMan;
|
||||
var protoMan = server.ProtoMan;
|
||||
var ticker = entMan.System<GameTicker>();
|
||||
var batterySys = entMan.System<BatterySystem>();
|
||||
|
||||
// Load the map
|
||||
await server.WaitAssertion(() =>
|
||||
@@ -70,7 +72,8 @@ public sealed class StationPowerTests
|
||||
if (node.NodeGroup is not IBasePowerNet group)
|
||||
continue;
|
||||
networks.TryGetValue(group.NetworkNode, out var charge);
|
||||
networks[group.NetworkNode] = charge + battery.CurrentCharge;
|
||||
var currentCharge = batterySys.GetCharge((uid, battery));
|
||||
networks[group.NetworkNode] = charge + currentCharge;
|
||||
}
|
||||
var totalStartingCharge = networks.MaxBy(n => n.Value).Value;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user