Files
tbd-station-14/Content.Server/GameObjects/EntitySystems/PowerSystem.cs
ZelteHonor b2e2aef78d Rider static analysis (#433)
* Non-accessed local variable

* Merge cast and type checks.

* StringComparison.Ordinal added for better culture support

* Supposed code improvement in launcher. Remove unused code.

* Update ExplosionHelper.cs

Unintentional change.

* Optimized Import

* Add Robust.Shared.Utility import where it was deleted

* Other random suggestion

* Improve my comment
2019-11-13 23:37:46 +01:00

74 lines
2.3 KiB
C#

using System.Collections.Generic;
using Content.Server.GameObjects.Components.Power;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Systems;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.IoC;
namespace Content.Shared.GameObjects.EntitySystems
{
public class PowerSystem : EntitySystem
{
public List<Powernet> Powernets = new List<Powernet>();
private IComponentManager componentManager;
private int _lastUid = 0;
public PowerSystem()
{
EntityQuery = new TypeEntityQuery(typeof(PowerDeviceComponent));
}
public override void Initialize()
{
base.Initialize();
componentManager = IoCManager.Resolve<IComponentManager>();
}
public int NewUid()
{
return ++_lastUid;
}
public override void Update(float frametime)
{
for (int i = 0; i < Powernets.Count; i++)
{
var powernet = Powernets[i];
if (powernet.Dirty)
{
//Tell all the wires of this net to be prepared to create/join new powernets
foreach (var wire in powernet.WireList)
{
wire.Regenerating = true;
}
foreach (var wire in powernet.WireList)
{
//Only a few wires should pass this if check since each will create and take all the others into its powernet
if (wire.Regenerating)
wire.SpreadPowernet();
}
//At this point all wires will have found/joined new powernet, all capable nodes will have joined them as well and removed themselves from nodelist
powernet.DirtyKill();
i--;
}
}
foreach (var powernet in Powernets)
{
powernet.Update(frametime);
}
// Draw power for devices not connected to anything.
foreach (var entity in EntityManager.GetEntities(EntityQuery))
{
var device = entity.GetComponent<PowerDeviceComponent>();
device.ProcessInternalPower(frametime);
}
}
}
}