#25 fixed
This commit is contained in:
@@ -83,6 +83,7 @@
|
|||||||
<Compile Include="Stopwatch.cs" />
|
<Compile Include="Stopwatch.cs" />
|
||||||
<Compile Include="Support\PerfHistory.cs" />
|
<Compile Include="Support\PerfHistory.cs" />
|
||||||
<Compile Include="Traits\AcceptsOre.cs" />
|
<Compile Include="Traits\AcceptsOre.cs" />
|
||||||
|
<Compile Include="Traits\Activities\Attack.cs" />
|
||||||
<Compile Include="Traits\Activities\IActivity.cs" />
|
<Compile Include="Traits\Activities\IActivity.cs" />
|
||||||
<Compile Include="Traits\Activities\DeliverOre.cs" />
|
<Compile Include="Traits\Activities\DeliverOre.cs" />
|
||||||
<Compile Include="Traits\Activities\DeployMcv.cs" />
|
<Compile Include="Traits\Activities\DeployMcv.cs" />
|
||||||
|
|||||||
58
OpenRa.Game/Traits/Activities/Attack.cs
Normal file
58
OpenRa.Game/Traits/Activities/Attack.cs
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace OpenRa.Game.Traits.Activities
|
||||||
|
{
|
||||||
|
/* non-turreted attack */
|
||||||
|
class Attack : IActivity
|
||||||
|
{
|
||||||
|
Actor Target;
|
||||||
|
int Range;
|
||||||
|
|
||||||
|
public Attack(Actor target, int range)
|
||||||
|
{
|
||||||
|
Target = target;
|
||||||
|
Range = range;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IActivity NextActivity { get; set; }
|
||||||
|
|
||||||
|
public void Tick(Actor self, Mobile mobile)
|
||||||
|
{
|
||||||
|
if (Target.IsDead)
|
||||||
|
{
|
||||||
|
mobile.InternalSetActivity(NextActivity);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((Target.Location - self.Location).LengthSquared >= Range * Range)
|
||||||
|
{
|
||||||
|
mobile.InternalSetActivity(new Move(Target, Range));
|
||||||
|
mobile.QueueActivity(this);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var desiredFacing = Util.GetFacing((Target.Location - self.Location).ToFloat2(), 0);
|
||||||
|
var renderUnit = self.traits.WithInterface<RenderUnit>().First();
|
||||||
|
|
||||||
|
if (Util.QuantizeFacing(mobile.facing, renderUnit.anim.CurrentSequence.Length)
|
||||||
|
!= Util.QuantizeFacing(desiredFacing, renderUnit.anim.CurrentSequence.Length))
|
||||||
|
{
|
||||||
|
mobile.InternalSetActivity(new Turn(desiredFacing));
|
||||||
|
mobile.QueueActivity(this);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var attack = self.traits.WithInterface<AttackBase>().First();
|
||||||
|
attack.target = Target;
|
||||||
|
attack.DoAttack(self);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Cancel(Actor self, Mobile mobile)
|
||||||
|
{
|
||||||
|
mobile.InternalSetActivity(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,7 +5,7 @@ using System.Text;
|
|||||||
|
|
||||||
namespace OpenRa.Game.Traits
|
namespace OpenRa.Game.Traits
|
||||||
{
|
{
|
||||||
abstract class AttackBase : IOrder, ITick
|
class AttackBase : IOrder, ITick
|
||||||
{
|
{
|
||||||
public Actor target;
|
public Actor target;
|
||||||
|
|
||||||
@@ -13,6 +13,8 @@ namespace OpenRa.Game.Traits
|
|||||||
protected int primaryFireDelay = 0;
|
protected int primaryFireDelay = 0;
|
||||||
protected int secondaryFireDelay = 0;
|
protected int secondaryFireDelay = 0;
|
||||||
|
|
||||||
|
public AttackBase(Actor self) { }
|
||||||
|
|
||||||
protected bool CanAttack( Actor self )
|
protected bool CanAttack( Actor self )
|
||||||
{
|
{
|
||||||
return target != null;
|
return target != null;
|
||||||
@@ -26,7 +28,7 @@ namespace OpenRa.Game.Traits
|
|||||||
if (target != null && target.IsDead) target = null; /* he's dead, jim. */
|
if (target != null && target.IsDead) target = null; /* he's dead, jim. */
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void DoAttack( Actor self )
|
public void DoAttack( Actor self )
|
||||||
{
|
{
|
||||||
var rut = self.traits.GetOrDefault<RenderUnitTurreted>();
|
var rut = self.traits.GetOrDefault<RenderUnitTurreted>();
|
||||||
|
|
||||||
@@ -79,7 +81,7 @@ namespace OpenRa.Game.Traits
|
|||||||
|
|
||||||
class AttackTurreted : AttackBase
|
class AttackTurreted : AttackBase
|
||||||
{
|
{
|
||||||
public AttackTurreted( Actor self ) { self.traits.Get<Turreted>(); }
|
public AttackTurreted( Actor self ) : base(self) { self.traits.Get<Turreted>(); }
|
||||||
|
|
||||||
public override void Tick(Actor self)
|
public override void Tick(Actor self)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -31,11 +31,20 @@ namespace OpenRa.Game
|
|||||||
var weapon = order.Subject.unitInfo.Primary ?? order.Subject.unitInfo.Secondary;
|
var weapon = order.Subject.unitInfo.Primary ?? order.Subject.unitInfo.Secondary;
|
||||||
|
|
||||||
mobile.Cancel(order.Subject);
|
mobile.Cancel(order.Subject);
|
||||||
|
if (order.Subject.traits.Contains<AttackTurreted>())
|
||||||
|
{
|
||||||
mobile.QueueActivity(
|
mobile.QueueActivity(
|
||||||
new Traits.Activities.Follow(order.TargetActor,
|
new Traits.Activities.Follow(order.TargetActor,
|
||||||
Math.Max(0, (int)Rules.WeaponInfo[weapon].Range - RangeTolerance)));
|
Math.Max(0, (int)Rules.WeaponInfo[weapon].Range - RangeTolerance)));
|
||||||
|
|
||||||
order.Subject.traits.Get<AttackTurreted>().target = order.TargetActor;
|
order.Subject.traits.Get<AttackTurreted>().target = order.TargetActor;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mobile.QueueActivity(
|
||||||
|
new Traits.Activities.Attack(order.TargetActor,
|
||||||
|
Math.Max(0, (int)Rules.WeaponInfo[weapon].Range - RangeTolerance)));
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "DeployMcv":
|
case "DeployMcv":
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ Traits=Mobile, RenderUnitTurreted
|
|||||||
PrimaryOffset=0,6,0,-3
|
PrimaryOffset=0,6,0,-3
|
||||||
[ARTY]
|
[ARTY]
|
||||||
Description=Artillery
|
Description=Artillery
|
||||||
Traits=Mobile, RenderUnit
|
Traits=Mobile, RenderUnit, AttackBase
|
||||||
[HARV]
|
[HARV]
|
||||||
Description=Ore Truck
|
Description=Ore Truck
|
||||||
Traits=Harvester, Mobile, RenderUnit
|
Traits=Harvester, Mobile, RenderUnit
|
||||||
@@ -55,7 +55,7 @@ PrimaryOffset=0,0,0,-2
|
|||||||
MuzzleFlash=yes
|
MuzzleFlash=yes
|
||||||
[APC]
|
[APC]
|
||||||
Description=Armored Personnel Carrier
|
Description=Armored Personnel Carrier
|
||||||
Traits=Mobile, RenderUnit
|
Traits=Mobile, RenderUnit, AttackBase
|
||||||
[MNLY]
|
[MNLY]
|
||||||
Description=Minelayer
|
Description=Minelayer
|
||||||
Traits=Mobile, RenderUnit
|
Traits=Mobile, RenderUnit
|
||||||
|
|||||||
Reference in New Issue
Block a user