Fix power warnings & sort errors.
This commit is contained in:
@@ -98,15 +98,16 @@ namespace Content.Server.GameObjects.Components.Power
|
||||
_provider.RemoveDevice(this);
|
||||
}
|
||||
|
||||
_provider = value;
|
||||
if (value != null)
|
||||
{
|
||||
_provider = value;
|
||||
_provider.AddDevice(this);
|
||||
}
|
||||
else
|
||||
{
|
||||
Connected = DrawTypes.None;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -133,7 +134,7 @@ namespace Content.Server.GameObjects.Components.Power
|
||||
{
|
||||
if (Owner.TryGetComponent(out PowerNodeComponent node))
|
||||
{
|
||||
if (node.Parent != null)
|
||||
if (node.Parent != null && node.Parent.HasDevice(this))
|
||||
{
|
||||
node.Parent.RemoveDevice(this);
|
||||
}
|
||||
@@ -145,7 +146,7 @@ namespace Content.Server.GameObjects.Components.Power
|
||||
|
||||
if (Provider != null)
|
||||
{
|
||||
Provider.RemoveDevice(this);
|
||||
Provider = null;
|
||||
}
|
||||
|
||||
base.Shutdown();
|
||||
@@ -228,7 +229,7 @@ namespace Content.Server.GameObjects.Components.Power
|
||||
private void ConnectToBestProvider()
|
||||
{
|
||||
//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;
|
||||
|
||||
//Get the starting value for our loop
|
||||
|
||||
@@ -173,7 +173,7 @@ namespace Content.Server.GameObjects.Components.Power
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Register a continuous load from a device connected to the powernet
|
||||
/// Register a continuous load from a device connected to the powernet
|
||||
/// </summary>
|
||||
public void AddDevice(PowerDeviceComponent device)
|
||||
{
|
||||
@@ -184,7 +184,7 @@ namespace Content.Server.GameObjects.Components.Power
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update one of the loads from a deviceconnected to the powernet
|
||||
/// Update one of the loads from a deviceconnected to the powernet
|
||||
/// </summary>
|
||||
public void UpdateDevice(PowerDeviceComponent device, float oldLoad)
|
||||
{
|
||||
@@ -196,7 +196,7 @@ namespace Content.Server.GameObjects.Components.Power
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove a continuous load from a device connected to the powernet
|
||||
/// Remove a continuous load from a device connected to the powernet
|
||||
/// </summary>
|
||||
public void RemoveDevice(PowerDeviceComponent device)
|
||||
{
|
||||
@@ -209,8 +209,7 @@ namespace Content.Server.GameObjects.Components.Power
|
||||
}
|
||||
else
|
||||
{
|
||||
var name = device.Owner.Prototype.Name;
|
||||
Logger.WarningS("power", "We tried to remove a device twice from the same {0} somehow, prototype {1}", Name, name);
|
||||
Logger.WarningS("power", "We tried to remove device {0} twice from the same {1}, somehow.", device.Owner, Owner);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -289,7 +289,17 @@ namespace Content.Server.GameObjects.Components.Power
|
||||
}
|
||||
|
||||
/// <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>
|
||||
public void RemoveDevice(PowerDeviceComponent device)
|
||||
{
|
||||
@@ -302,8 +312,7 @@ namespace Content.Server.GameObjects.Components.Power
|
||||
}
|
||||
else
|
||||
{
|
||||
var name = device.Owner.Prototype.Name;
|
||||
Logger.Info("We tried to remove a device twice from the same powernet somehow, prototype {0}", name);
|
||||
Logger.WarningS("power", "We tried to remove device {0} twice from {1}, somehow.", device.Owner, this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -341,8 +350,7 @@ namespace Content.Server.GameObjects.Components.Power
|
||||
}
|
||||
else
|
||||
{
|
||||
var name = generator.Owner.Prototype.Name;
|
||||
Logger.Info(String.Format("We tried to remove a device twice from the same power somehow, prototype {1}", name));
|
||||
Logger.WarningS("power", "We tried to remove generator {0} twice from {1}, somehow.", generator.Owner, this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -389,17 +397,22 @@ namespace Content.Server.GameObjects.Components.Power
|
||||
}
|
||||
#endregion Registration
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"Powernet {Uid}";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Priority that a device will receive power if powernet cannot supply every device
|
||||
/// </summary>
|
||||
public enum Priority
|
||||
{
|
||||
Necessary,
|
||||
High,
|
||||
Medium,
|
||||
Low,
|
||||
Provider,
|
||||
Unnecessary
|
||||
Necessary = 0,
|
||||
High = 1,
|
||||
Medium = 2,
|
||||
Low = 3,
|
||||
Provider = 4,
|
||||
Unnecessary = 5
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -412,9 +425,9 @@ namespace Content.Server.GameObjects.Components.Power
|
||||
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 (compare == 0 && !x.Equals(y))
|
||||
if (compare == 0)
|
||||
{
|
||||
return 1;
|
||||
return y.Owner.Uid.CompareTo(x.Owner.Uid);
|
||||
}
|
||||
return compare;
|
||||
}
|
||||
|
||||
2
engine
2
engine
Submodule engine updated: 480a0b4a0a...1812e8743d
Reference in New Issue
Block a user