Route the power check for support powers via the tech tree

This commit is contained in:
Paul Chote
2010-09-18 20:42:32 +12:00
parent 2a10af2007
commit 652f06f604
10 changed files with 42 additions and 45 deletions

View File

@@ -47,7 +47,6 @@ namespace OpenRA.Traits
protected readonly Actor Self;
protected readonly Player Owner;
string[] effectivePrereq = {};
bool notifiedCharging;
bool notifiedReady;
@@ -60,9 +59,6 @@ namespace OpenRA.Traits
Self = self;
Owner = self.Owner;
PlayerPower = self.Trait<PowerManager>();
effectivePrereq = Info.Prerequisites
.Select(a => a.ToLowerInvariant()).ToArray();
self.Trait<TechTree>().Add( Info.OrderName, Info.Prerequisites.Select( a => a.ToLowerInvariant() ).ToList(), this );
}
@@ -74,8 +70,8 @@ namespace OpenRA.Traits
if (Info.GivenAuto)
IsAvailable = hasPrerequisites;
if (IsAvailable && (!Info.RequiresPower || IsPowered()))
if (IsAvailable && (!Info.RequiresPower || PlayerPower.PowerState == PowerState.Normal))
{
if (Game.LobbyInfo.GlobalSettings.AllowCheats && self.Trait<DeveloperMode>().FastCharge) RemainingTime = 0;
@@ -97,16 +93,6 @@ namespace OpenRA.Traits
}
}
bool IsPowered()
{
if (effectivePrereq.Count() == 0)
return PlayerPower.GetPowerState() == PowerState.Normal;
// Takes 0.3ms on pchote's machine -- calling it every tick for every active special power is retarded
var buildings = TechTree.GatherBuildings(Owner);
return effectivePrereq.All(a => buildings[a].Any(b => !b.TraitsImplementing<IDisable>().All(d => d.Disabled)));
}
public void FinishActivate()
{
if (Info.OneShot)
@@ -135,7 +121,7 @@ namespace OpenRA.Traits
if (!IsAvailable || !IsReady)
return;
if (Info.RequiresPower && !IsPowered())
if (Info.RequiresPower && PlayerPower.PowerState != PowerState.Normal)
{
var eva = Owner.World.WorldActor.Info.Traits.Get<EvaAlertsInfo>();
Sound.Play(eva.AbilityInsufficientPower);