Files
tbd-station-14/Content.Server/GameObjects/EntitySystems/PowerSystem.cs
Pieter-Jan Briers 147aad5064 Some work on the mess that is this power code.
Jesus.

Tons of fixes, refactors and other things.
The powernet's code is still awful though.
2018-05-27 16:44:50 +02:00

71 lines
2.2 KiB
C#

using Content.Server.GameObjects.Components.Power;
using SS14.Shared.GameObjects.System;
using SS14.Shared.Interfaces.GameObjects;
using SS14.Shared.IoC;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Content.Shared.GameObjects.EntitySystems
{
public class PowerSystem : EntitySystem
{
public List<Powernet> Powernets = new List<Powernet>();
private IComponentManager componentManager;
private int _lastUid = 0;
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 device in componentManager.GetComponents<PowerDeviceComponent>())
{
device.ProcessInternalPower(frametime);
}
}
}
}