planes attacking works; post-attack glitches though
This commit is contained in:
@@ -113,6 +113,7 @@
|
||||
<Compile Include="Traits\Activities\Circle.cs" />
|
||||
<Compile Include="Traits\Activities\Demolish.cs" />
|
||||
<Compile Include="Traits\Activities\Fly.cs" />
|
||||
<Compile Include="Traits\Activities\FlyAttack.cs" />
|
||||
<Compile Include="Traits\Activities\FlyTimed.cs" />
|
||||
<Compile Include="Traits\Activities\IActivity.cs" />
|
||||
<Compile Include="Traits\Activities\DeliverOre.cs" />
|
||||
@@ -174,6 +175,7 @@
|
||||
<Compile Include="Traits\ATMine.cs" />
|
||||
<Compile Include="Traits\AttackBase.cs" />
|
||||
<Compile Include="Traits\AttackInfo.cs" />
|
||||
<Compile Include="Traits\AttackPlane.cs" />
|
||||
<Compile Include="Traits\AttackTurreted.cs" />
|
||||
<Compile Include="Traits\AutoHeal.cs" />
|
||||
<Compile Include="Traits\AutoTarget.cs" />
|
||||
|
||||
@@ -16,15 +16,10 @@ namespace OpenRa.Game.Traits.Activities
|
||||
public IActivity Tick(Actor self)
|
||||
{
|
||||
if (isCanceled) return NextActivity;
|
||||
var unit = self.traits.Get<Unit>();
|
||||
return new Fly(Util.CenterOfCell(Cell))
|
||||
{
|
||||
NextActivity =
|
||||
new FlyTimed(50, 20)
|
||||
{
|
||||
NextActivity = this
|
||||
}
|
||||
};
|
||||
return Util.SequenceActivities(
|
||||
new Fly(Util.CenterOfCell(Cell)),
|
||||
new FlyTimed(50, 20),
|
||||
this);
|
||||
}
|
||||
|
||||
public void Cancel(Actor self) { isCanceled = true; NextActivity = null; }
|
||||
|
||||
31
OpenRa.Game/Traits/Activities/FlyAttack.cs
Normal file
31
OpenRa.Game/Traits/Activities/FlyAttack.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace OpenRa.Game.Traits.Activities
|
||||
{
|
||||
class FlyAttack : IActivity
|
||||
{
|
||||
public IActivity NextActivity { get; set; }
|
||||
Actor Target;
|
||||
|
||||
public FlyAttack(Actor target) { Target = target; }
|
||||
|
||||
public IActivity Tick(Actor self)
|
||||
{
|
||||
if (Target == null || Target.IsDead) return NextActivity;
|
||||
|
||||
var limitedAmmo = self.traits.GetOrDefault<LimitedAmmo>();
|
||||
if (limitedAmmo != null && !limitedAmmo.HasAmmo())
|
||||
return NextActivity;
|
||||
|
||||
return Util.SequenceActivities(
|
||||
new Fly(Target.CenterLocation),
|
||||
new FlyTimed(50, 20),
|
||||
this);
|
||||
}
|
||||
|
||||
public void Cancel(Actor self) { Target = null; NextActivity = null; }
|
||||
}
|
||||
}
|
||||
38
OpenRa.Game/Traits/AttackPlane.cs
Normal file
38
OpenRa.Game/Traits/AttackPlane.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using OpenRa.Game.Traits.Activities;
|
||||
|
||||
namespace OpenRa.Game.Traits
|
||||
{
|
||||
// yet another ugly trait that does two things:
|
||||
// - plane-specific attack order dispatch
|
||||
// - forward-facing attack with a tolerance
|
||||
|
||||
class AttackPlane : AttackBase
|
||||
{
|
||||
const int facingTolerance = 20;
|
||||
|
||||
public AttackPlane(Actor self) : base(self) { }
|
||||
|
||||
public override void Tick(Actor self)
|
||||
{
|
||||
base.Tick(self);
|
||||
|
||||
if (target == null) return;
|
||||
|
||||
var unit = self.traits.Get<Unit>();
|
||||
var facingToTarget = Util.GetFacing(target.CenterLocation - self.CenterLocation, unit.Facing);
|
||||
|
||||
if (Math.Abs(facingToTarget - unit.Facing) % 256 < facingTolerance)
|
||||
DoAttack(self);
|
||||
}
|
||||
|
||||
protected override void QueueAttack(Actor self, Order order)
|
||||
{
|
||||
self.QueueActivity(new FlyAttack(order.TargetActor));
|
||||
target = order.TargetActor;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -41,7 +41,7 @@ namespace OpenRa.Game.Traits
|
||||
self.QueueActivity( new Traits.Activities.Follow( order.TargetActor,
|
||||
Math.Max( 0, (int)Rules.WeaponInfo[ weapon ].Range - RangeTolerance ) ) );
|
||||
|
||||
self.traits.Get<AttackTurreted>().target = order.TargetActor;
|
||||
target = order.TargetActor;
|
||||
}
|
||||
|
||||
bool buildComplete = false;
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using System.Linq;
|
||||
using OpenRa.Game.GameRules;
|
||||
using OpenRa.Game.Graphics;
|
||||
using OpenRa.Game.Traits.Activities;
|
||||
|
||||
namespace OpenRa.Game.Traits
|
||||
{
|
||||
@@ -135,5 +136,11 @@ namespace OpenRa.Game.Traits
|
||||
.Product();
|
||||
return mi.Speed * modifier;
|
||||
}
|
||||
|
||||
public static IActivity SequenceActivities(params IActivity[] acts)
|
||||
{
|
||||
return acts.Reverse().Aggregate((IActivity)null,
|
||||
(next, a) => { a.NextActivity = next; return a; });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -165,13 +165,13 @@ HIND
|
||||
[MIG]
|
||||
Description=Mig Attack Plane
|
||||
BuiltAt=afld
|
||||
Traits=Unit, Plane, RenderUnit, WithShadow, LimitedAmmo
|
||||
Traits=Unit, AttackPlane, Plane, RenderUnit, WithShadow, LimitedAmmo
|
||||
InitialFacing=192
|
||||
LongDesc=Fast Ground-Attack Plane.\n Strong vs Buildings\n Weak vs Infantry, Light Vehicles
|
||||
[YAK]
|
||||
Description=Yak Attack Plane
|
||||
BuiltAt=afld
|
||||
Traits=Unit, Plane, RenderUnit, WithShadow, LimitedAmmo
|
||||
Traits=Unit, AttackPlane, Plane, RenderUnit, WithShadow, LimitedAmmo
|
||||
InitialFacing=192
|
||||
LongDesc=Anti-Tanks & Anti-Infantry Plane.\n Strong vs Infantry, Tanks\n Weak vs Buildings
|
||||
[TRAN]
|
||||
|
||||
Reference in New Issue
Block a user