migrating most things to use the Target struct rather than Actor directly.

This commit is contained in:
Chris Forbes
2010-07-05 18:25:10 +12:00
parent 88b705c8ef
commit 5c61c9d3a9
14 changed files with 57 additions and 49 deletions

View File

@@ -17,10 +17,10 @@ namespace OpenRA.Mods.RA.Activities
/* non-turreted attack */
public class Attack : IActivity
{
Actor Target;
Target Target;
int Range;
public Attack(Actor target, int range)
public Attack(Target target, int range)
{
Target = target;
Range = range;
@@ -32,13 +32,15 @@ namespace OpenRA.Mods.RA.Activities
{
var unit = self.traits.Get<Unit>();
if (Target == null || Target.IsDead)
if (!Target.IsValid)
return NextActivity;
if ((Target.Location - self.Location).LengthSquared >= Range * Range)
return new Move( Target, Range ) { NextActivity = this };
var targetCell = Util.CellContaining(Target.CenterLocation);
var desiredFacing = Util.GetFacing((Target.Location - self.Location).ToFloat2(), 0);
if ((targetCell - self.Location).LengthSquared >= Range * Range)
return new Move( targetCell, Range ) { NextActivity = this };
var desiredFacing = Util.GetFacing((targetCell - self.Location).ToFloat2(), 0);
var renderUnit = self.traits.GetOrDefault<RenderUnit>();
var numDirs = (renderUnit != null)
? renderUnit.anim.CurrentSequence.Facings : 8;
@@ -57,7 +59,7 @@ namespace OpenRA.Mods.RA.Activities
public void Cancel(Actor self)
{
Target = null;
Target = new Target();
}
}
}

View File

@@ -16,13 +16,13 @@ namespace OpenRA.Mods.RA.Activities
{
class Leap : IActivity
{
Actor target;
Target target;
float2 initialLocation;
float t;
const int delay = 6;
public Leap(Actor self, Actor target)
public Leap(Actor self, Target target)
{
this.target = target;
initialLocation = self.CenterLocation;
@@ -35,7 +35,7 @@ namespace OpenRA.Mods.RA.Activities
public IActivity Tick(Actor self)
{
if (target == null || !target.IsInWorld)
if (!target.IsValid)
return NextActivity;
t += (1f / delay);
@@ -44,14 +44,17 @@ namespace OpenRA.Mods.RA.Activities
if (t >= 1f)
{
self.traits.WithInterface<IMove>().FirstOrDefault().SetPosition(self, target.Location);
target.InflictDamage(self, target.Health, null); // kill it
self.traits.WithInterface<IMove>().FirstOrDefault()
.SetPosition(self, Util.CellContaining(target.CenterLocation));
if (target.IsActor)
target.Actor.InflictDamage(self, target.Actor.Health, null); // kill it
return NextActivity;
}
return this;
}
public void Cancel(Actor self) { target = null; NextActivity = null; }
public void Cancel(Actor self) { target = new Target(); NextActivity = null; }
}
}