follow activity for turreted attacks
This commit is contained in:
@@ -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" />
|
||||||
|
|||||||
@@ -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! */
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
@@ -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 )
|
||||||
{
|
{
|
||||||
|
|||||||
38
OpenRa.Game/Traits/Activities/Follow.cs
Normal file
38
OpenRa.Game/Traits/Activities/Follow.cs
Normal 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) { }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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)
|
||||||
@@ -84,13 +84,10 @@ namespace OpenRa.Game.Traits.Activities
|
|||||||
search.AddInitialCell(self.Location);
|
search.AddInitialCell(self.Location);
|
||||||
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) { }
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
4
OpenRa.Game/Traits/Activities/Activity.cs → OpenRa.Game/Traits/Activities/IActivity.cs
Executable file → Normal file
4
OpenRa.Game/Traits/Activities/Activity.cs → OpenRa.Game/Traits/Activities/IActivity.cs
Executable file → Normal 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 );
|
||||||
}
|
}
|
||||||
@@ -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;
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|
||||||
|
|||||||
@@ -7,10 +7,8 @@ using OpenRa.Game.GameRules;
|
|||||||
namespace OpenRa.Game.Traits
|
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)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -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;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,15 +29,14 @@ namespace OpenRa.Game
|
|||||||
var mobile = order.Subject.traits.GetOrDefault<Mobile>();
|
var mobile = order.Subject.traits.GetOrDefault<Mobile>();
|
||||||
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);
|
||||||
// TODO: this block should be a separate activity; "MoveNear", maybe?
|
// TODO: this block should be a separate activity; "MoveNear", maybe?
|
||||||
{
|
{
|
||||||
/* todo: choose the appropriate weapon, when only one works against this target */
|
/* todo: choose the appropriate weapon, when only one works against this target */
|
||||||
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;
|
||||||
|
|||||||
Reference in New Issue
Block a user