Update the PowerState only when power is added or removed

This commit is contained in:
abcdefg30
2020-06-19 18:23:11 +02:00
committed by Oliver Brakmann
parent ab8790e8f1
commit 2e06d5790b

View File

@@ -92,6 +92,8 @@ namespace OpenRA.Mods.Common.Traits
totalProvided += amount;
else if (amount < 0)
totalDrained -= amount;
UpdatePowerState();
}
public void RemoveActor(Actor a)
@@ -108,6 +110,21 @@ namespace OpenRA.Mods.Common.Traits
totalProvided -= amount;
else if (amount < 0)
totalDrained += amount;
UpdatePowerState();
}
void UpdatePowerState()
{
isLowPower = ExcessPower < 0;
if (isLowPower != wasLowPower)
UpdatePowerRequiringActors();
if (isLowPower && !wasLowPower)
nextPowerAdviceTime = 0;
wasLowPower = isLowPower;
}
void ITick.Tick(Actor self)
@@ -129,18 +146,9 @@ namespace OpenRA.Mods.Common.Traits
}
wasHackEnabled = devMode.UnlimitedPower;
UpdatePowerState();
}
isLowPower = ExcessPower < 0;
if (isLowPower != wasLowPower)
UpdatePowerRequiringActors();
if (isLowPower && !wasLowPower)
nextPowerAdviceTime = 0;
wasLowPower = isLowPower;
if (--nextPowerAdviceTime <= 0)
{
if (isLowPower)