tidy up disabled handling

This commit is contained in:
Chris Forbes
2012-04-06 19:34:43 +12:00
parent aa21ddaa4d
commit 10c1b996ed
9 changed files with 36 additions and 41 deletions

View File

@@ -131,36 +131,31 @@ namespace OpenRA.Mods.RA
Key = key;
}
static bool InstanceDisabled(SupportPower sp)
{
return sp.self.TraitsImplementing<IDisable>().Any(d => d.Disabled);
}
bool notifiedCharging;
bool notifiedReady;
public void Tick()
{
Active = !Disabled && Instances.Any(i => !InstanceDisabled(i));
if (Disabled || Instances.All(i => i.self.IsDisabled()))
return;
if (Active)
if (Manager.devMode.FastCharge && RemainingTime > 25)
RemainingTime = 25;
if (RemainingTime > 0) --RemainingTime;
var power = Instances.First();
if (!notifiedCharging)
{
var power = Instances.First();
if (Manager.devMode.FastCharge && RemainingTime > 25)
RemainingTime = 25;
power.Charging(power.self, Key);
notifiedCharging = true;
}
if (RemainingTime > 0) --RemainingTime;
if (!notifiedCharging)
{
power.Charging(power.self, Key);
notifiedCharging = true;
}
if (RemainingTime == 0
&& !notifiedReady)
{
power.Charged(power.self, Key);
notifiedReady = true;
}
if (RemainingTime == 0 && !notifiedReady)
{
power.Charged(power.self, Key);
notifiedReady = true;
}
}
@@ -177,7 +172,7 @@ namespace OpenRA.Mods.RA
if (!Ready)
return;
var power = Instances.First(i => !InstanceDisabled(i));
var power = Instances.First(i => !i.self.IsDisabled());
// Note: order.Subject is the *player* actor
power.Activate(power.self, order);