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

@@ -29,7 +29,7 @@ namespace OpenRA.Traits
public void Tick(Actor self) public void Tick(Actor self)
{ {
if (!self.TraitsImplementing<IDisable>().Any(d => d.Disabled)) if (!self.IsDisabled())
self.World.WorldActor.Trait<Shroud>().HideActor(self, Info.Range); self.World.WorldActor.Trait<Shroud>().HideActor(self, Info.Range);
} }
} }

View File

@@ -11,6 +11,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Drawing; using System.Drawing;
using System.Linq;
using OpenRA.FileFormats; using OpenRA.FileFormats;
using OpenRA.GameRules; using OpenRA.GameRules;
using OpenRA.Graphics; using OpenRA.Graphics;
@@ -224,4 +225,12 @@ namespace OpenRA.Traits
public interface ILintPass { void Run(Action<string> emitError, Action<string> emitWarning); } public interface ILintPass { void Run(Action<string> emitError, Action<string> emitWarning); }
public interface IObjectivesPanel { string ObjectivesPanel { get; } } public interface IObjectivesPanel { string ObjectivesPanel { get; } }
public static class DisableExts
{
public static bool IsDisabled(this Actor a)
{
return a.TraitsImplementing<IDisable>().Any(d => d.Disabled);
}
}
} }

View File

@@ -81,7 +81,7 @@ namespace OpenRA.Mods.RA
{ {
if (!target.IsValid) return false; if (!target.IsValid) return false;
if (Weapons.All(w => w.IsReloading)) return false; if (Weapons.All(w => w.IsReloading)) return false;
if (self.TraitsImplementing<IDisable>().Any(d => d.Disabled)) return false; if (self.IsDisabled()) return false;
if (target.IsActor && target.Actor.HasTrait<ITargetable>() && if (target.IsActor && target.Actor.HasTrait<ITargetable>() &&
!target.Actor.Trait<ITargetable>().TargetableBy(target.Actor,self)) !target.Actor.Trait<ITargetable>().TargetableBy(target.Actor,self))

View File

@@ -81,8 +81,7 @@ namespace OpenRA.Mods.RA
{ {
if( IsCanceled || !target.IsValid ) return NextActivity; if( IsCanceled || !target.IsValid ) return NextActivity;
if (self.TraitsImplementing<IDisable>().Any(d => d.Disabled)) if (self.IsDisabled()) return this;
return this;
var attack = self.Trait<AttackTurreted>(); var attack = self.Trait<AttackTurreted>();
const int RangeTolerance = 1; /* how far inside our maximum range we should try to sit */ const int RangeTolerance = 1; /* how far inside our maximum range we should try to sit */

View File

@@ -55,16 +55,14 @@ namespace OpenRA.Mods.RA
&& x.Trait.Info.Produces.Contains(Info.Type)) && x.Trait.Info.Produces.Contains(Info.Type))
.OrderByDescending(x => x.Actor.IsPrimaryBuilding() ? 1 : 0 ); // prioritize the primary. .OrderByDescending(x => x.Actor.IsPrimaryBuilding() ? 1 : 0 ); // prioritize the primary.
if (producers.Count() == 0) if (!producers.Any())
{ {
CancelProduction(name,1); CancelProduction(name,1);
return true; return true;
} }
foreach (var p in producers) foreach (var p in producers.Where(p => !p.Actor.IsDisabled()))
{ {
if (IsDisabledBuilding(p.Actor)) continue;
if (p.Trait.Produce(p.Actor, Rules.Info[ name ])) if (p.Trait.Produce(p.Actor, Rules.Info[ name ]))
{ {
FinishProduction(); FinishProduction();

View File

@@ -294,11 +294,6 @@ namespace OpenRA.Mods.RA
Queue.Add(item); Queue.Add(item);
} }
protected static bool IsDisabledBuilding(Actor a)
{
return a.TraitsImplementing<IDisable>().Any(d => d.Disabled);
}
// Builds a unit from the actor that holds this queue (1 queue per building) // Builds a unit from the actor that holds this queue (1 queue per building)
// Returns false if the unit can't be built // Returns false if the unit can't be built
protected virtual bool BuildUnit( string name ) protected virtual bool BuildUnit( string name )
@@ -311,7 +306,7 @@ namespace OpenRA.Mods.RA
} }
var sp = self.TraitsImplementing<Production>().FirstOrDefault(p => p.Info.Produces.Contains(Info.Type)); var sp = self.TraitsImplementing<Production>().FirstOrDefault(p => p.Info.Produces.Contains(Info.Type));
if (sp != null && !IsDisabledBuilding(self) && sp.Produce(self, Rules.Info[ name ])) if (sp != null && !self.IsDisabled() && sp.Produce(self, Rules.Info[ name ]))
{ {
FinishProduction(); FinishProduction();
return true; return true;

View File

@@ -24,8 +24,7 @@ namespace OpenRA.Mods.RA
bool UpdateActive(Actor self) bool UpdateActive(Actor self)
{ {
// Check if powered // Check if powered
if (self.TraitsImplementing<IDisable>().Any(d => d.Disabled)) if (self.IsDisabled()) return false;
return false;
var isJammed = self.World.ActorsWithTrait<JamsRadar>().Any(a => self.Owner != a.Actor.Owner var isJammed = self.World.ActorsWithTrait<JamsRadar>().Any(a => self.Owner != a.Actor.Owner
&& (self.Location - a.Actor.Location).Length < a.Actor.Info.Traits.Get<JamsRadarInfo>().Range); && (self.Location - a.Actor.Location).Length < a.Actor.Info.Traits.Get<JamsRadarInfo>().Range);

View File

@@ -56,7 +56,7 @@ namespace OpenRA.Mods.RA.Render
public IEnumerable<Renderable> ModifyRender(Actor self, IEnumerable<Renderable> r) public IEnumerable<Renderable> ModifyRender(Actor self, IEnumerable<Renderable> r)
{ {
var disabled = self.TraitsImplementing<IDisable>().Any(d => d.Disabled); var disabled = self.IsDisabled();
foreach (var a in r) foreach (var a in r)
{ {
var ret = a.WithPos(a.Pos - Info.Origin); var ret = a.WithPos(a.Pos - Info.Origin);

View File

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