Actor properties consistency improved

This commit is contained in:
huwpascoe
2014-11-10 14:20:19 +00:00
parent 6a425b8636
commit a660bb95b5
58 changed files with 109 additions and 120 deletions

View File

@@ -475,7 +475,7 @@ namespace OpenRA.Mods.RA.AI
List<Actor> FindEnemyConstructionYards()
{
return world.Actors.Where(a => p.Stances[a.Owner] == Stance.Enemy && !a.IsDead()
return world.Actors.Where(a => p.Stances[a.Owner] == Stance.Enemy && !a.IsDead
&& a.HasTrait<BaseBuilding>() && !a.HasTrait<Mobile>()).ToList();
}
@@ -483,7 +483,7 @@ namespace OpenRA.Mods.RA.AI
{
squads.RemoveAll(s => !s.IsValid);
foreach (var s in squads)
s.units.RemoveAll(a => a.IsDead() || a.Owner != p);
s.units.RemoveAll(a => a.IsDead || a.Owner != p);
}
// Use of this function requires that one squad of this type. Hence it is a piece of shit
@@ -506,8 +506,8 @@ namespace OpenRA.Mods.RA.AI
void AssignRolesToIdleUnits(Actor self)
{
CleanSquads();
activeUnits.RemoveAll(a => a.IsDead() || a.Owner != p);
unitsHangingAroundTheBase.RemoveAll(a => a.IsDead() || a.Owner != p);
activeUnits.RemoveAll(a => a.IsDead || a.Owner != p);
unitsHangingAroundTheBase.RemoveAll(a => a.IsDead || a.Owner != p);
if (--rushTicks <= 0)
{

View File

@@ -94,7 +94,7 @@ namespace OpenRA.Mods.RA.AI
else
{
var enemies = owner.world.FindActorsInCircle(leader.CenterPosition, WRange.FromCells(12))
.Where(a1 => !a1.Destroyed && !a1.IsDead()).ToList();
.Where(a1 => !a1.Destroyed && !a1.IsDead).ToList();
var enemynearby = enemies.Where(a1 => a1.HasTrait<ITargetable>() && leader.Owner.Stances[a1.Owner] == Stance.Enemy).ToList();
if (enemynearby.Any())
{

View File

@@ -98,7 +98,7 @@ namespace OpenRA.Mods.RA.Activities
public override Activity Tick(Actor self)
{
if (IsCanceled || self.IsDead())
if (IsCanceled || self.IsDead)
return NextActivity;
if (!isCalculated)

View File

@@ -34,7 +34,7 @@ namespace OpenRA.Mods.RA.Activities
protected override void OnInside(Actor self)
{
if (actor.IsDead() || capturable.BeingCaptured)
if (actor.IsDead || capturable.BeingCaptured)
return;
var b = actor.TraitOrDefault<Building>();
@@ -46,7 +46,7 @@ namespace OpenRA.Mods.RA.Activities
if (b != null && b.Locked)
b.Unlock();
if (actor.IsDead() || capturable.BeingCaptured)
if (actor.IsDead || capturable.BeingCaptured)
return;
var health = actor.Trait<Health>();

View File

@@ -46,7 +46,7 @@ namespace OpenRA.Mods.RA.Activities
{
self.World.AddFrameEndTask(w =>
{
if (target.IsDead())
if (target.IsDead)
return;
for (var f = 0; f < flashes; f++)
@@ -55,7 +55,7 @@ namespace OpenRA.Mods.RA.Activities
w.Add(new DelayedAction(delay, () =>
{
if (target.IsDead())
if (target.IsDead)
return;
var modifiers = target.TraitsImplementing<IDamageModifier>()

View File

@@ -27,7 +27,7 @@ namespace OpenRA.Mods.RA.Activities
protected override void OnInside(Actor self)
{
if (target.IsDead())
if (target.IsDead)
return;
target.Owner.PlayerActor.Trait<PlayerResources>().GiveCash(payload);

View File

@@ -46,7 +46,7 @@ namespace OpenRA.Mods.RA.Activities
{
self.World.AddFrameEndTask(w =>
{
if (self.IsDead() || transport.IsDead() || !cargo.CanLoad(transport, self))
if (self.IsDead || transport.IsDead || !cargo.CanLoad(transport, self))
return;
cargo.Load(transport, self);

View File

@@ -27,7 +27,7 @@ namespace OpenRA.Mods.RA.Activities
var capturable = target.Actor.Trait<ExternalCapturable>();
if (IsCanceled || !self.IsInWorld || self.IsDead() || !target.IsValidFor(self))
if (IsCanceled || !self.IsInWorld || self.IsDead || !target.IsValidFor(self))
{
if (capturable.CaptureInProgress)
capturable.EndCapture();
@@ -59,7 +59,7 @@ namespace OpenRA.Mods.RA.Activities
self.World.AddFrameEndTask(w =>
{
if (target.Actor.IsDead())
if (target.Actor.IsDead)
return;
var oldOwner = target.Actor.Owner;

View File

@@ -21,7 +21,7 @@ namespace OpenRA.Mods.RA.Activities
public Hunt(Actor self)
{
var attack = self.Trait<AttackBase>();
targets = self.World.Actors.Where(a => self != a && !a.IsDead() && a.IsInWorld && a.AppearsHostileTo(self)
targets = self.World.Actors.Where(a => self != a && !a.IsDead && a.IsInWorld && a.AppearsHostileTo(self)
&& a.HasTrait<Huntable>() && attack.HasAnyValidWeapons(Target.FromActor(a)));
}

View File

@@ -24,7 +24,7 @@ namespace OpenRA.Mods.RA.Activities
protected override void OnInside(Actor self)
{
if (target.IsDead() || target.Owner == self.Owner)
if (target.IsDead || target.Owner == self.Owner)
return;
foreach (var t in target.TraitsImplementing<INotifyInfiltrated>())

View File

@@ -47,7 +47,7 @@ namespace OpenRA.Mods.RA
case State.Dock:
ru.PlayCustomAnimation(self, "dock", () => {
ru.PlayCustomAnimRepeating(self, "dock-loop");
if (proc.IsInWorld && !proc.IsDead())
if (proc.IsInWorld && !proc.IsDead)
foreach (var nd in proc.TraitsImplementing<INotifyDocking>())
nd.Docked(proc, self);
state = State.Loop;
@@ -55,7 +55,7 @@ namespace OpenRA.Mods.RA
state = State.Wait;
return this;
case State.Loop:
if (!proc.IsInWorld || proc.IsDead() || harv.TickUnload(self, proc))
if (!proc.IsInWorld || proc.IsDead || harv.TickUnload(self, proc))
state = State.Undock;
return this;
case State.Undock:
@@ -65,7 +65,7 @@ namespace OpenRA.Mods.RA
case State.Complete:
harv.LastLinkedProc = harv.LinkedProc;
harv.LinkProc(self, null);
if (proc.IsInWorld && !proc.IsDead())
if (proc.IsInWorld && !proc.IsDead)
foreach (var nd in proc.TraitsImplementing<INotifyDocking>())
nd.Undocked(proc, self);
return NextActivity;

View File

@@ -37,7 +37,7 @@ namespace OpenRA.Mods.RA.Activities
self.World.AddFrameEndTask(w =>
{
if (self.IsDead())
if (self.IsDead)
return;
foreach (var nt in self.TraitsImplementing<INotifyTransform>())

View File

@@ -21,7 +21,7 @@ namespace OpenRA.Mods.RA
if (stance == Stance.Ally)
return true;
if (self.IsDisguised() && !toActor.HasTrait<IgnoresDisguise>())
if (self.EffectiveOwner != null && self.EffectiveOwner.Disguised && !toActor.HasTrait<IgnoresDisguise>())
return toActor.Owner.Stances[self.EffectiveOwner.Owner] == Stance.Ally;
return stance == Stance.Ally;
@@ -33,7 +33,7 @@ namespace OpenRA.Mods.RA
if (stance == Stance.Ally)
return false; /* otherwise, we'll hate friendly disguised spies */
if (self.IsDisguised() && !toActor.HasTrait<IgnoresDisguise>())
if (self.EffectiveOwner != null && self.EffectiveOwner.Disguised && !toActor.HasTrait<IgnoresDisguise>())
return toActor.Owner.Stances[self.EffectiveOwner.Owner] == Stance.Enemy;
return stance == Stance.Enemy;

View File

@@ -25,7 +25,7 @@ namespace OpenRA.Mods.RA
var target = inRange
.Where(a => a != self && a.AppearsFriendlyTo(self))
.Where(a => a.IsInWorld && !a.IsDead())
.Where(a => a.IsInWorld && !a.IsDead)
.Where(a => a.GetDamageState() > DamageState.Undamaged)
.Where(a => attack.HasAnyValidWeapons(Target.FromActor(a)))
.ClosestTo(self);

View File

@@ -59,7 +59,7 @@ namespace OpenRA.Mods.RA.Buildings
self.World.AddFrameEndTask(w =>
{
if (!self.IsDead())
if (!self.IsDead)
w.Add(new RepairIndicator(self, Info.IndicatorPalettePrefix));
});
}

View File

@@ -66,7 +66,7 @@ namespace OpenRA.Mods.RA.Crates
{
foreach (var a in actorsInRange.Append(collector))
{
if (!a.IsInWorld || a.IsDead())
if (!a.IsInWorld || a.IsDead)
continue;
var um = a.TraitOrDefault<UpgradeManager>();

View File

@@ -89,7 +89,7 @@ namespace OpenRA.Mods.RA.Effects
world.AddFrameEndTask(w => w.Remove(this));
show = false;
if (!self.IsInWorld || self.IsDead() || self.World.RenderPlayer == null)
if (!self.IsInWorld || self.IsDead || self.World.RenderPlayer == null)
return;
var gps = watcher[self.World.RenderPlayer];

View File

@@ -33,7 +33,7 @@ namespace OpenRA.Mods.RA.Effects
public void Tick(World world)
{
if (self.IsDead())
if (self.IsDead)
world.AddFrameEndTask(w => w.Remove(this));
else
anim.Tick();
@@ -44,7 +44,7 @@ namespace OpenRA.Mods.RA.Effects
if (!self.IsInWorld)
yield break;
if (self.IsDead())
if (self.IsDead)
yield break;
if (!self.Owner.IsAlliedWith(self.World.RenderPlayer))
@@ -54,7 +54,7 @@ namespace OpenRA.Mods.RA.Effects
yield break;
var pos = wr.ScreenPxPosition(self.CenterPosition);
var bounds = self.Bounds.Value;
var bounds = self.Bounds;
bounds.Offset(pos.X, pos.Y);
var palette = wr.Palette(paletteName);

View File

@@ -38,7 +38,7 @@ namespace OpenRA.Mods.RA.Effects
public void Tick(World world)
{
if (!building.IsInWorld || building.IsDead() ||
if (!building.IsInWorld || building.IsDead ||
rb == null || !rb.Repairers.Any())
world.AddFrameEndTask(w => w.Remove(this));

View File

@@ -84,7 +84,7 @@ namespace OpenRA.Mods.RA
public void Tick(Actor self)
{
if (Captor != null && (!Captor.IsInWorld || Captor.IsDead()))
if (Captor != null && (!Captor.IsInWorld || Captor.IsDead))
EndCapture();
if (!CaptureInProgress)

View File

@@ -115,7 +115,7 @@ namespace OpenRA.Mods.RA
{
self.World.AddFrameEndTask(w =>
{
if (!self.IsDead())
if (!self.IsDead)
w.Add(new Rank(self, info.ChevronPalette));
});
}

View File

@@ -64,7 +64,7 @@ namespace OpenRA.Mods.RA
var target = FriendlyGuardableUnits(world, mi).FirstOrDefault();
if (target == null || subjects.All(s => s.IsDead()))
if (target == null || subjects.All(s => s.IsDead))
yield break;
foreach (var subject in subjects)
@@ -74,7 +74,7 @@ namespace OpenRA.Mods.RA
public void Tick(World world)
{
if (subjects.All(s => s.IsDead() || !s.HasTrait<Guard>()))
if (subjects.All(s => s.IsDead || !s.HasTrait<Guard>()))
world.CancelInputMode();
}
@@ -96,7 +96,7 @@ namespace OpenRA.Mods.RA
static IEnumerable<Actor> FriendlyGuardableUnits(World world, MouseInput mi)
{
return world.ScreenMap.ActorsAt(mi)
.Where(a => !world.FogObscures(a) && !a.IsDead() &&
.Where(a => !world.FogObscures(a) && !a.IsDead &&
a.AppearsFriendlyTo(world.LocalPlayer.PlayerActor) &&
a.HasTrait<Guardable>());
}

View File

@@ -59,7 +59,7 @@ namespace OpenRA.Mods.RA
void Kill()
{
if (self.IsDead())
if (self.IsDead)
return;
if (info.RemoveInstead || !self.HasTrait<Health>())

View File

@@ -166,7 +166,7 @@ namespace OpenRA.Mods.RA
public void Tick(World world)
{
if (!minelayer.IsInWorld || minelayer.IsDead())
if (!minelayer.IsInWorld || minelayer.IsDead)
world.CancelInputMode();
}

View File

@@ -76,14 +76,14 @@ namespace OpenRA.Mods.RA
preventDock = true;
// Cancel the dock sequence
if (dockedHarv != null && !dockedHarv.IsDead())
if (dockedHarv != null && !dockedHarv.IsDead)
dockedHarv.CancelActivity();
}
public void Tick(Actor self)
{
// Harvester was killed while unloading
if (dockedHarv != null && dockedHarv.IsDead())
if (dockedHarv != null && dockedHarv.IsDead)
{
self.Trait<RenderBuilding>().CancelCustomAnim(self);
dockedHarv = null;

View File

@@ -29,7 +29,7 @@ namespace OpenRA.Mods.RA
{
var prevItems = GetNumBuildables(self.Owner);
if (order.TargetActor.IsDead())
if (order.TargetActor.IsDead)
return;
var unit = self.World.Map.Rules.Actors[order.TargetString];

View File

@@ -59,7 +59,7 @@ namespace OpenRA.Mods.RA
{
var total = (double)world.Map.Bounds.Width * world.Map.Bounds.Height;
MapControl = world.Actors
.Where(a => !a.IsDead() && a.IsInWorld && a.Owner == player && a.HasTrait<RevealsShroud>())
.Where(a => !a.IsDead && a.IsInWorld && a.Owner == player && a.HasTrait<RevealsShroud>())
.SelectMany(a => world.Map.FindTilesInCircle(
a.Location,
a.Trait<RevealsShroud>().Range.Clamp(WRange.Zero, WRange.FromCells(Map.MaxTilesInCircleRange)).Range / 1024))

View File

@@ -372,7 +372,7 @@ namespace OpenRA.Mods.RA
protected virtual bool BuildUnit(string name)
{
// Cannot produce if i'm dead
if (!self.IsInWorld || self.IsDead())
if (!self.IsInWorld || self.IsDead)
{
CancelProduction(name, 1);
return true;

View File

@@ -77,7 +77,7 @@ namespace OpenRA.Mods.RA
// Add all actors that provide prerequisites
var prerequisites = player.World.ActorsWithTrait<ITechTreePrerequisite>()
.Where(a => a.Actor.Owner == player && a.Actor.IsInWorld && !a.Actor.IsDead());
.Where(a => a.Actor.Owner == player && a.Actor.IsInWorld && !a.Actor.IsDead);
foreach (var b in prerequisites)
{
@@ -96,7 +96,7 @@ namespace OpenRA.Mods.RA
.Where(a =>
a.Actor.Owner == player &&
a.Actor.IsInWorld &&
!a.Actor.IsDead() &&
!a.Actor.IsDead &&
!ret.ContainsKey(a.Actor.Info.Name) &&
a.Actor.Info.Traits.Get<BuildableInfo>().BuildLimit > 0)
.Do(b => ret[b.Actor.Info.Name].Add(b.Actor));

View File

@@ -164,7 +164,7 @@ namespace OpenRA.Mods.RA
public void Tick(World world)
{
if (!self.IsInWorld || self.IsDead())
if (!self.IsInWorld || self.IsDead)
world.CancelInputMode();
}

View File

@@ -51,7 +51,7 @@ namespace OpenRA.Mods.RA
public Production(ProductionInfo info, Actor self)
{
Info = info;
rp = Exts.Lazy(() => self.IsDead() ? null : self.TraitOrDefault<RallyPoint>());
rp = Exts.Lazy(() => self.IsDead ? null : self.TraitOrDefault<RallyPoint>());
}
public void DoProduction(Actor self, ActorInfo producee, ExitInfo exitinfo, string raceVariant)
@@ -94,7 +94,7 @@ namespace OpenRA.Mods.RA
newUnit.SetTargetLine(target, rp.Value != null ? Color.Red : Color.Green, false);
if (!self.IsDead())
if (!self.IsDead)
foreach (var t in self.TraitsImplementing<INotifyProduction>())
t.UnitProduced(self, newUnit, exit);

View File

@@ -46,7 +46,7 @@ namespace OpenRA.Mods.RA.Render
public IEnumerable<IRenderable> Render(Actor self, WorldRenderer wr)
{
var pos = wr.ScreenPxPosition(self.CenterPosition);
var bounds = self.Bounds.Value;
var bounds = self.Bounds;
bounds.Offset(pos.X, pos.Y);
var spaceBuffer = (int)(10 / wr.Viewport.Zoom);
var effectPos = wr.Position(new int2(pos.X, bounds.Y - spaceBuffer));

View File

@@ -69,7 +69,7 @@ namespace OpenRA.Mods.RA.Render
public void Tick(Actor self)
{
var isFlying = movement.IsMoving && !self.IsDead();
var isFlying = movement.IsMoving && !self.IsDead;
if (isFlying ^ (rotorAnim.CurrentSequence.Name != info.Sequence))
return;

View File

@@ -42,7 +42,7 @@ namespace OpenRA.Mods.RA.Scripting
}
[Desc("Specifies whether the actor is alive or dead.")]
public bool IsDead { get { return self.IsDead(); } }
public bool IsDead { get { return self.IsDead; } }
[Desc("Specifies whether the actor is idle (not performing any activities).")]
public bool IsIdle { get { return self.IsIdle; } }

View File

@@ -29,7 +29,7 @@ namespace OpenRA.Mods.RA.Scripting
public Actor[] GetGroundAttackers()
{
return player.World.ActorsWithTrait<AttackBase>().Select(a => a.Actor)
.Where(a => a.Owner == player && !a.IsDead() && a.IsInWorld && a.HasTrait<Mobile>())
.Where(a => a.Owner == player && !a.IsDead && a.IsInWorld && a.HasTrait<Mobile>())
.ToArray();
}
}

View File

@@ -129,7 +129,7 @@ namespace OpenRA.Mods.RA.Scripting
if (squad.Count >= squadSize)
{
using (func)
using (var luaSquad = squad.Where(u => !u.IsDead()).ToArray().ToLuaValue(context))
using (var luaSquad = squad.Where(u => !u.IsDead).ToArray().ToLuaValue(context))
func.Call(luaSquad).Dispose();
triggers.OnProducedInternal -= productionHandler;
@@ -230,7 +230,7 @@ namespace OpenRA.Mods.RA.Scripting
if (squad.Count >= squadSize)
{
using (func)
using (var luaSquad = squad.Where(u => !u.IsDead()).ToArray().ToLuaValue(context))
using (var luaSquad = squad.Where(u => !u.IsDead).ToArray().ToLuaValue(context))
func.Call(luaSquad).Dispose();
foreach (var q in queueTypes)

View File

@@ -60,7 +60,7 @@ namespace OpenRA.Mods.RA
public void Tick(Actor self)
{
if (self.IsDead() || disabled)
if (self.IsDead || disabled)
return;
if (health.HP >= info.HealIfBelow * health.MaxHP)

View File

@@ -95,7 +95,7 @@ namespace OpenRA.Mods.RA.Traits
return WVec.Zero;
return self.World.FindActorsInCircle(self.CenterPosition, info.IdealSeparation)
.Where(a => !a.IsDead() && a.HasTrait<Aircraft>())
.Where(a => !a.IsDead && a.HasTrait<Aircraft>())
.Select(GetRepulsionForce)
.Aggregate(WVec.Zero, (a, b) => a + b);
}

View File

@@ -244,11 +244,11 @@ namespace OpenRA.Mods.RA.Widgets.Logic
var assets = template.Get<LabelWidget>("ASSETS");
assets.GetText = () => "$" + world.Actors
.Where(a => a.Owner == player && !a.IsDead() && a.Info.Traits.WithInterface<ValuedInfo>().Any())
.Where(a => a.Owner == player && !a.IsDead && a.Info.Traits.WithInterface<ValuedInfo>().Any())
.Sum(a => a.Info.Traits.WithInterface<ValuedInfo>().First().Cost);
var harvesters = template.Get<LabelWidget>("HARVESTERS");
harvesters.GetText = () => world.Actors.Count(a => a.Owner == player && !a.IsDead() && a.HasTrait<Harvester>()).ToString();
harvesters.GetText = () => world.Actors.Count(a => a.Owner == player && !a.IsDead && a.HasTrait<Harvester>()).ToString();
return template;
}
@@ -282,7 +282,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
{
return ScrollItemWidget.Setup(template, () => false, () =>
{
var playerBase = world.Actors.FirstOrDefault(a => !a.IsDead() && a.HasTrait<BaseBuilding>() && a.Owner == player);
var playerBase = world.Actors.FirstOrDefault(a => !a.IsDead && a.HasTrait<BaseBuilding>() && a.Owner == player);
if (playerBase != null)
worldRenderer.Viewport.Center(playerBase.CenterPosition);
});

View File

@@ -29,7 +29,7 @@ namespace OpenRA.Mods.RA.Widgets
public SupportPowerTimerWidget(World world)
{
powers = world.ActorsWithTrait<SupportPowerManager>()
.Where(p => !p.Actor.IsDead() && !p.Actor.Owner.NonCombatant)
.Where(p => !p.Actor.IsDead && !p.Actor.Owner.NonCombatant)
.SelectMany(s => s.Trait.Powers.Values)
.Where(p => p.Instances.Any() && p.Info.DisplayTimer && !p.Disabled);
}