Use Target range checks in attack activities.
This commit is contained in:
@@ -22,6 +22,7 @@ namespace OpenRA
|
||||
|
||||
public WRange(int r) { Range = r; }
|
||||
public static readonly WRange Zero = new WRange(0);
|
||||
public static WRange FromCells(int cells) { return new WRange(1024*cells); }
|
||||
|
||||
public static WRange operator +(WRange a, WRange b) { return new WRange(a.Range + b.Range); }
|
||||
public static WRange operator -(WRange a, WRange b) { return new WRange(a.Range - b.Range); }
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace OpenRA.Mods.RA.Activities
|
||||
{
|
||||
protected Target Target;
|
||||
ITargetable targetable;
|
||||
int Range;
|
||||
WRange Range;
|
||||
bool AllowMovement;
|
||||
|
||||
int nextPathTime;
|
||||
@@ -27,7 +27,10 @@ namespace OpenRA.Mods.RA.Activities
|
||||
const int delayBetweenPathingAttempts = 20;
|
||||
const int delaySpread = 5;
|
||||
|
||||
public Attack(Target target, int range, bool allowMovement)
|
||||
public Attack(Target target, WRange range)
|
||||
: this(target, range, true) {}
|
||||
|
||||
public Attack(Target target, WRange range, bool allowMovement)
|
||||
{
|
||||
Target = target;
|
||||
if (target.IsActor)
|
||||
@@ -37,12 +40,9 @@ namespace OpenRA.Mods.RA.Activities
|
||||
AllowMovement = allowMovement;
|
||||
}
|
||||
|
||||
public Attack(Target target, int range) : this(target, range, true) {}
|
||||
|
||||
public override Activity Tick(Actor self)
|
||||
{
|
||||
var attack = self.Trait<AttackBase>();
|
||||
|
||||
var ret = InnerTick(self, attack);
|
||||
attack.IsAttacking = (ret == this);
|
||||
return ret;
|
||||
@@ -50,7 +50,8 @@ namespace OpenRA.Mods.RA.Activities
|
||||
|
||||
protected virtual Activity InnerTick(Actor self, AttackBase attack)
|
||||
{
|
||||
if (IsCanceled) return NextActivity;
|
||||
if (IsCanceled)
|
||||
return NextActivity;
|
||||
|
||||
if (!Target.IsValid)
|
||||
return NextActivity;
|
||||
@@ -61,7 +62,7 @@ namespace OpenRA.Mods.RA.Activities
|
||||
if (targetable != null && !targetable.TargetableBy(Target.Actor, self))
|
||||
return NextActivity;
|
||||
|
||||
if (!Combat.IsInRange(self.CenterLocation, Range, Target))
|
||||
if (!Target.IsInRange(self.CenterPosition, Range))
|
||||
{
|
||||
if (--nextPathTime > 0)
|
||||
return this;
|
||||
@@ -69,7 +70,7 @@ namespace OpenRA.Mods.RA.Activities
|
||||
nextPathTime = self.World.SharedRandom.Next(delayBetweenPathingAttempts - delaySpread,
|
||||
delayBetweenPathingAttempts + delaySpread);
|
||||
|
||||
return (AllowMovement) ? Util.SequenceActivities(self.Trait<Mobile>().MoveWithinRange(Target, Range), this) : NextActivity;
|
||||
return (AllowMovement) ? Util.SequenceActivities(self.Trait<Mobile>().MoveWithinRange(Target, Range.Range / 1024), this) : NextActivity;
|
||||
}
|
||||
|
||||
var desiredFacing = Util.GetFacing(Target.CenterLocation - self.CenterLocation, 0);
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace OpenRA.Mods.RA.Activities
|
||||
/* non-turreted attack */
|
||||
public class Heal : Attack
|
||||
{
|
||||
public Heal(Target target, int range, bool allowMovement)
|
||||
public Heal(Target target, WRange range, bool allowMovement)
|
||||
: base(target, range, allowMovement) {}
|
||||
|
||||
protected override Activity InnerTick(Actor self, AttackBase attack)
|
||||
|
||||
@@ -44,10 +44,13 @@ namespace OpenRA.Mods.RA
|
||||
|
||||
public override Activity GetAttackActivity(Actor self, Target newTarget, bool allowMove)
|
||||
{
|
||||
var weapon = ChooseArmamentForTarget(newTarget);
|
||||
if (weapon == null)
|
||||
var a = ChooseArmamentForTarget(newTarget);
|
||||
if (a == null)
|
||||
return null;
|
||||
return new Activities.Attack(newTarget, Math.Max(0, (int)weapon.Weapon.Range), allowMove);
|
||||
|
||||
// TODO: Define weapon ranges as WRange
|
||||
var range = new WRange(Math.Max(0,(int)(1024*a.Weapon.Range)));
|
||||
return new Activities.Attack(newTarget, range, allowMove);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,13 +42,5 @@ namespace OpenRA.Mods.RA
|
||||
self.CancelActivity();
|
||||
self.QueueActivity(new Leap(self, target));
|
||||
}
|
||||
|
||||
public override Activity GetAttackActivity(Actor self, Target newTarget, bool allowMove)
|
||||
{
|
||||
var a = ChooseArmamentForTarget(newTarget);
|
||||
if (a == null)
|
||||
return null;
|
||||
return new Activities.Attack(newTarget, Math.Max(0, (int)a.Weapon.Range), allowMove);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,10 +29,13 @@ namespace OpenRA.Mods.RA
|
||||
|
||||
public override Activity GetAttackActivity(Actor self, Target newTarget, bool allowMove)
|
||||
{
|
||||
var weapon = ChooseArmamentForTarget(newTarget);
|
||||
if (weapon == null)
|
||||
var a = ChooseArmamentForTarget(newTarget);
|
||||
if (a == null)
|
||||
return null;
|
||||
return new Activities.Heal(newTarget, Math.Max(0, (int)weapon.Weapon.Range), allowMove);
|
||||
|
||||
// TODO: Define weapon ranges as WRange
|
||||
var range = new WRange(Math.Max(0,(int)(1024*a.Weapon.Range)));
|
||||
return new Activities.Heal(newTarget, range, allowMove);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -297,7 +297,7 @@ namespace OpenRA.Mods.RA.Missions
|
||||
|
||||
var enemy = FirstUnshroudedOrDefault(enemies.OrderBy(u => (self.CenterLocation - u.CenterLocation).LengthSquared), world, 10);
|
||||
if (enemy != null)
|
||||
self.QueueActivity(new AttackMove.AttackMoveActivity(self, new Attack(Target.FromActor(enemy), 3)));
|
||||
self.QueueActivity(new AttackMove.AttackMoveActivity(self, new Attack(Target.FromActor(enemy), WRange.FromCells(3))));
|
||||
}
|
||||
|
||||
void ManageSovietUnits()
|
||||
|
||||
@@ -125,7 +125,7 @@ namespace OpenRA.Mods.RA.Missions
|
||||
|
||||
if (world.FrameNumber == frameInfiltrated + 1500 * 12 && !bridgeTank.IsDead() && bridgeTank.IsInWorld && !bridge.IsDead())
|
||||
{
|
||||
bridgeTank.QueueActivity(new Attack(Target.FromPos(bridge.CenterLocation), 4));
|
||||
bridgeTank.QueueActivity(new Attack(Target.FromPos(bridge.CenterLocation), WRange.FromCells(4)));
|
||||
attackingBridge = true;
|
||||
}
|
||||
if (attackingBridge && bridge.IsDead())
|
||||
@@ -152,7 +152,7 @@ namespace OpenRA.Mods.RA.Missions
|
||||
|
||||
var enemy = enemies.OrderBy(u => (attacker.CenterLocation - u.CenterLocation).LengthSquared).FirstOrDefault();
|
||||
if (enemy != null)
|
||||
attacker.QueueActivity(new AttackMove.AttackMoveActivity(attacker, new Attack(Target.FromActor(enemy), 3)));
|
||||
attacker.QueueActivity(new AttackMove.AttackMoveActivity(attacker, new Attack(Target.FromActor(enemy), WRange.FromCells(3))));
|
||||
else
|
||||
{
|
||||
attackingTown = false;
|
||||
|
||||
@@ -82,7 +82,7 @@ namespace OpenRA.Mods.RA.Missions
|
||||
var targetEnemy = enemies.OrderBy(u => (self.CenterLocation - u.CenterLocation).LengthSquared).FirstOrDefault();
|
||||
if (targetEnemy != null)
|
||||
{
|
||||
self.QueueActivity(new AttackMove.AttackMoveActivity(self, new Attack(Target.FromActor(targetEnemy), 6)));
|
||||
self.QueueActivity(new AttackMove.AttackMoveActivity(self, new Attack(Target.FromActor(targetEnemy), WRange.FromCells(6))));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -213,7 +213,7 @@ namespace OpenRA.Mods.RA.Missions
|
||||
|
||||
var enemy = enemies.OrderBy(u => (self.CenterLocation - u.CenterLocation).LengthSquared).FirstOrDefault();
|
||||
if (enemy != null)
|
||||
self.QueueActivity(queued, new AttackMove.AttackMoveActivity(self, new Attack(Target.FromActor(enemy), 3)));
|
||||
self.QueueActivity(queued, new AttackMove.AttackMoveActivity(self, new Attack(Target.FromActor(enemy), WRange.FromCells(3))));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -214,7 +214,7 @@ namespace OpenRA.Mods.RA.Missions
|
||||
var targetEnemy = enemies.OrderBy(u => (self.CenterLocation - u.CenterLocation).LengthSquared).FirstOrDefault();
|
||||
if (targetEnemy != null)
|
||||
{
|
||||
self.QueueActivity(new AttackMove.AttackMoveActivity(self, new Attack(Target.FromActor(targetEnemy), 3)));
|
||||
self.QueueActivity(new AttackMove.AttackMoveActivity(self, new Attack(Target.FromActor(targetEnemy), WRange.FromCells(3))));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -139,7 +139,7 @@ namespace OpenRA.Mods.RA.Missions
|
||||
|
||||
var enemy = FirstUnshroudedOrDefault(enemies.OrderBy(u => (self.CenterLocation - u.CenterLocation).LengthSquared), world, 20);
|
||||
if (enemy != null)
|
||||
self.QueueActivity(new AttackMove.AttackMoveActivity(self, new Attack(Target.FromActor(enemy), 3)));
|
||||
self.QueueActivity(new AttackMove.AttackMoveActivity(self, new Attack(Target.FromActor(enemy), WRange.FromCells(3))));
|
||||
}
|
||||
|
||||
void SpawnAndAttack(string[] squad, Player owner, CPos location)
|
||||
|
||||
Reference in New Issue
Block a user