follow activity for turreted attacks

This commit is contained in:
Chris Forbes
2009-11-09 22:29:07 +13:00
parent 14e2e3c2eb
commit b13f399ec0
12 changed files with 64 additions and 30 deletions

View File

@@ -83,7 +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\Activity.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" />
<Compile Include="Actor.cs" /> <Compile Include="Actor.cs" />
@@ -137,6 +137,7 @@
<Compile Include="Graphics\TreeCache.cs" /> <Compile Include="Graphics\TreeCache.cs" />
<Compile Include="Traits\Activities\Harvest.cs" /> <Compile Include="Traits\Activities\Harvest.cs" />
<Compile Include="Traits\Activities\Move.cs" /> <Compile Include="Traits\Activities\Move.cs" />
<Compile Include="Traits\Activities\Follow.cs" />
<Compile Include="Traits\Activities\Turn.cs" /> <Compile Include="Traits\Activities\Turn.cs" />
<Compile Include="Traits\AttackTurreted.cs" /> <Compile Include="Traits\AttackTurreted.cs" />
<Compile Include="Traits\Building.cs" /> <Compile Include="Traits\Building.cs" />

View File

@@ -9,7 +9,7 @@ namespace OpenRa.Game.Traits
{ {
public AcceptsOre(Actor self) public AcceptsOre(Actor self)
{ {
if (!Game.skipMakeAnims) // if (!Game.skipMakeAnims)
Game.world.AddFrameEndTask( Game.world.AddFrameEndTask(
w => w =>
{ /* create the free harvester! */ { /* create the free harvester! */

View File

@@ -5,9 +5,9 @@ using System.Text;
namespace OpenRa.Game.Traits.Activities namespace OpenRa.Game.Traits.Activities
{ {
class DeliverOre : Activity class DeliverOre : IActivity
{ {
public Activity NextActivity { get; set; } public IActivity NextActivity { get; set; }
bool isDone; bool isDone;
Actor refinery; Actor refinery;

View File

@@ -5,9 +5,9 @@ using System.Text;
namespace OpenRa.Game.Traits.Activities namespace OpenRa.Game.Traits.Activities
{ {
class DeployMcv : Activity class DeployMcv : IActivity
{ {
public Activity NextActivity { get; set; } public IActivity NextActivity { get; set; }
public void Tick( Actor self, Mobile mobile ) public void Tick( Actor self, Mobile mobile )
{ {

View File

@@ -0,0 +1,38 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace OpenRa.Game.Traits.Activities
{
class Follow : IActivity
{
Actor Target;
int Range;
public Follow(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);
}
}
public void Cancel(Actor self, Mobile mobile) { }
}
}

View File

@@ -5,9 +5,9 @@ using System.Text;
namespace OpenRa.Game.Traits.Activities namespace OpenRa.Game.Traits.Activities
{ {
class Harvest : Activity class Harvest : IActivity
{ {
public Activity NextActivity { get; set; } public IActivity NextActivity { get; set; }
bool isHarvesting = false; bool isHarvesting = false;
public void Tick(Actor self, Mobile mobile) public void Tick(Actor self, Mobile mobile)
@@ -85,12 +85,9 @@ namespace OpenRa.Game.Traits.Activities
return Game.PathFinder.FindPath(search); return Game.PathFinder.FindPath(search);
})); }));
mobile.QueueActivity(new Harvest()); mobile.QueueActivity(new Harvest());
mobile.InternalSetActivity( NextActivity ); mobile.InternalSetActivity( NextActivity );
} }
public void Cancel(Actor self, Mobile mobile) public void Cancel(Actor self, Mobile mobile) { }
{
}
} }
} }

View File

@@ -5,9 +5,9 @@ using System.Text;
namespace OpenRa.Game.Traits.Activities namespace OpenRa.Game.Traits.Activities
{ {
interface Activity interface IActivity
{ {
Activity NextActivity { get; set; } IActivity NextActivity { get; set; }
void Tick( Actor self, Mobile mobile ); void Tick( Actor self, Mobile mobile );
void Cancel( Actor self, Mobile mobile ); void Cancel( Actor self, Mobile mobile );
} }

View File

@@ -5,9 +5,9 @@ using OpenRa.Game.GameRules;
namespace OpenRa.Game.Traits.Activities namespace OpenRa.Game.Traits.Activities
{ {
class Move : Activity class Move : IActivity
{ {
public Activity NextActivity { get; set; } public IActivity NextActivity { get; set; }
int2? destination; int2? destination;
int nearEnough; int nearEnough;

View File

@@ -5,9 +5,9 @@ using System.Text;
namespace OpenRa.Game.Traits.Activities namespace OpenRa.Game.Traits.Activities
{ {
class Turn : Activity class Turn : IActivity
{ {
public Activity NextActivity { get; set; } public IActivity NextActivity { get; set; }
public int desiredFacing; public int desiredFacing;

View File

@@ -8,9 +8,7 @@ namespace OpenRa.Game.Traits
{ {
class McvDeploy : IOrder class McvDeploy : IOrder
{ {
public McvDeploy(Actor self) public McvDeploy(Actor self) { }
{
}
public Order Order(Actor self, int2 xy, bool lmb, Actor underCursor) public Order Order(Actor self, int2 xy, bool lmb, Actor underCursor)
{ {

View File

@@ -18,7 +18,7 @@ namespace OpenRa.Game.Traits
public int facing; public int facing;
public int Voice = Game.CosmeticRandom.Next(2); public int Voice = Game.CosmeticRandom.Next(2);
Activity currentActivity; IActivity currentActivity;
public Mobile(Actor self) public Mobile(Actor self)
{ {
@@ -27,7 +27,7 @@ namespace OpenRa.Game.Traits
Game.UnitInfluence.Update( this ); Game.UnitInfluence.Update( this );
} }
public void QueueActivity( Activity nextActivity ) public void QueueActivity( IActivity nextActivity )
{ {
if( currentActivity == null ) if( currentActivity == null )
{ {
@@ -42,7 +42,7 @@ namespace OpenRa.Game.Traits
act.NextActivity = nextActivity; act.NextActivity = nextActivity;
} }
public void InternalSetActivity( Activity activity ) public void InternalSetActivity( IActivity activity )
{ {
currentActivity = activity; currentActivity = activity;
} }

View File

@@ -36,8 +36,7 @@ namespace OpenRa.Game
var range = Rules.WeaponInfo[weapon].Range; var range = Rules.WeaponInfo[weapon].Range;
mobile.QueueActivity( mobile.QueueActivity(
new Traits.Activities.Move( order.TargetActor, new Traits.Activities.Follow(order.TargetActor, Math.Max(0, (int)range - RangeTolerance)));
Math.Max( 0, (int)range - RangeTolerance ) ) );
} }
order.Subject.traits.Get<AttackTurreted>().target = order.TargetActor; order.Subject.traits.Get<AttackTurreted>().target = order.TargetActor;
@@ -49,6 +48,7 @@ namespace OpenRa.Game
break; /* throw the order on the floor */ break; /* throw the order on the floor */
var mobile = order.Subject.traits.Get<Mobile>(); var mobile = order.Subject.traits.Get<Mobile>();
mobile.Cancel(order.Subject);
mobile.QueueActivity( new Traits.Activities.Turn( 96 ) ); mobile.QueueActivity( new Traits.Activities.Turn( 96 ) );
mobile.QueueActivity( new Traits.Activities.DeployMcv() ); mobile.QueueActivity( new Traits.Activities.DeployMcv() );
break; break;