Fix power warnings & sort errors.

This commit is contained in:
Pieter-Jan Briers
2018-05-30 16:10:36 +02:00
parent 097c876578
commit ff0b1bfd05
4 changed files with 36 additions and 23 deletions

View File

@@ -98,15 +98,16 @@ namespace Content.Server.GameObjects.Components.Power
_provider.RemoveDevice(this); _provider.RemoveDevice(this);
} }
_provider = value;
if (value != null) if (value != null)
{ {
_provider = value;
_provider.AddDevice(this); _provider.AddDevice(this);
} }
else else
{ {
Connected = DrawTypes.None; Connected = DrawTypes.None;
} }
} }
} }
@@ -133,7 +134,7 @@ namespace Content.Server.GameObjects.Components.Power
{ {
if (Owner.TryGetComponent(out PowerNodeComponent node)) if (Owner.TryGetComponent(out PowerNodeComponent node))
{ {
if (node.Parent != null) if (node.Parent != null && node.Parent.HasDevice(this))
{ {
node.Parent.RemoveDevice(this); node.Parent.RemoveDevice(this);
} }
@@ -145,7 +146,7 @@ namespace Content.Server.GameObjects.Components.Power
if (Provider != null) if (Provider != null)
{ {
Provider.RemoveDevice(this); Provider = null;
} }
base.Shutdown(); base.Shutdown();
@@ -228,7 +229,7 @@ namespace Content.Server.GameObjects.Components.Power
private void ConnectToBestProvider() private void ConnectToBestProvider()
{ {
//Any values we can connect to or are we already connected to a node, cancel! //Any values we can connect to or are we already connected to a node, cancel!
if (!AvailableProviders.Any() || Connected == DrawTypes.Node) if (!AvailableProviders.Any() || Connected == DrawTypes.Node || Deleted)
return; return;
//Get the starting value for our loop //Get the starting value for our loop

View File

@@ -173,7 +173,7 @@ namespace Content.Server.GameObjects.Components.Power
} }
/// <summary> /// <summary>
/// Register a continuous load from a device connected to the powernet /// Register a continuous load from a device connected to the powernet
/// </summary> /// </summary>
public void AddDevice(PowerDeviceComponent device) public void AddDevice(PowerDeviceComponent device)
{ {
@@ -184,7 +184,7 @@ namespace Content.Server.GameObjects.Components.Power
} }
/// <summary> /// <summary>
/// Update one of the loads from a deviceconnected to the powernet /// Update one of the loads from a deviceconnected to the powernet
/// </summary> /// </summary>
public void UpdateDevice(PowerDeviceComponent device, float oldLoad) public void UpdateDevice(PowerDeviceComponent device, float oldLoad)
{ {
@@ -196,7 +196,7 @@ namespace Content.Server.GameObjects.Components.Power
} }
/// <summary> /// <summary>
/// Remove a continuous load from a device connected to the powernet /// Remove a continuous load from a device connected to the powernet
/// </summary> /// </summary>
public void RemoveDevice(PowerDeviceComponent device) public void RemoveDevice(PowerDeviceComponent device)
{ {
@@ -209,8 +209,7 @@ namespace Content.Server.GameObjects.Components.Power
} }
else else
{ {
var name = device.Owner.Prototype.Name; Logger.WarningS("power", "We tried to remove device {0} twice from the same {1}, somehow.", device.Owner, Owner);
Logger.WarningS("power", "We tried to remove a device twice from the same {0} somehow, prototype {1}", Name, name);
} }
} }
} }

View File

@@ -289,7 +289,17 @@ namespace Content.Server.GameObjects.Components.Power
} }
/// <summary> /// <summary>
/// Remove a continuous load from a device connected to the powernet /// Returns whether or not a power device is in this powernet's load list.
/// </summary>
/// <param name="device">The device to check for.</param>
/// <returns>True if the device is in the load list, false otherwise.</returns>
public bool HasDevice(PowerDeviceComponent device)
{
return DeviceLoadList.Contains(device);
}
/// <summary>
/// Remove a continuous load from a device connected to the powernet
/// </summary> /// </summary>
public void RemoveDevice(PowerDeviceComponent device) public void RemoveDevice(PowerDeviceComponent device)
{ {
@@ -302,8 +312,7 @@ namespace Content.Server.GameObjects.Components.Power
} }
else else
{ {
var name = device.Owner.Prototype.Name; Logger.WarningS("power", "We tried to remove device {0} twice from {1}, somehow.", device.Owner, this);
Logger.Info("We tried to remove a device twice from the same powernet somehow, prototype {0}", name);
} }
} }
@@ -341,8 +350,7 @@ namespace Content.Server.GameObjects.Components.Power
} }
else else
{ {
var name = generator.Owner.Prototype.Name; Logger.WarningS("power", "We tried to remove generator {0} twice from {1}, somehow.", generator.Owner, this);
Logger.Info(String.Format("We tried to remove a device twice from the same power somehow, prototype {1}", name));
} }
} }
@@ -389,17 +397,22 @@ namespace Content.Server.GameObjects.Components.Power
} }
#endregion Registration #endregion Registration
public override string ToString()
{
return $"Powernet {Uid}";
}
/// <summary> /// <summary>
/// Priority that a device will receive power if powernet cannot supply every device /// Priority that a device will receive power if powernet cannot supply every device
/// </summary> /// </summary>
public enum Priority public enum Priority
{ {
Necessary, Necessary = 0,
High, High = 1,
Medium, Medium = 2,
Low, Low = 3,
Provider, Provider = 4,
Unnecessary Unnecessary = 5
} }
/// <summary> /// <summary>
@@ -412,9 +425,9 @@ namespace Content.Server.GameObjects.Components.Power
int compare = y.Priority.CompareTo(x.Priority); int compare = y.Priority.CompareTo(x.Priority);
//If the comparer returns 0 sortedset will believe it is a duplicate and return 0, so return 1 instead //If the comparer returns 0 sortedset will believe it is a duplicate and return 0, so return 1 instead
if (compare == 0 && !x.Equals(y)) if (compare == 0)
{ {
return 1; return y.Owner.Uid.CompareTo(x.Owner.Uid);
} }
return compare; return compare;
} }

2
engine

Submodule engine updated: 480a0b4a0a...1812e8743d