use new Enter activity for engy, spy, c4

This commit is contained in:
Bob
2010-10-21 20:58:07 +13:00
parent 8e4f5da791
commit 88a8d84153
10 changed files with 125 additions and 25 deletions

View File

@@ -40,7 +40,7 @@ namespace OpenRA
public List<int2> FindUnitPath(int2 from, int2 target, Actor self) public List<int2> FindUnitPath(int2 from, int2 target, Actor self)
{ {
using (new PerfSample("find_unit_path")) using (new PerfSample("Pathfinder"))
{ {
var cached = CachedPaths.FirstOrDefault(p => p.from == from && p.to == target && p.actor == self); var cached = CachedPaths.FirstOrDefault(p => p.from == from && p.to == target && p.actor == self);
if (cached != null) if (cached != null)
@@ -69,7 +69,7 @@ namespace OpenRA
public List<int2> FindUnitPathToRange( int2 src, int2 target, int range, Actor self ) public List<int2> FindUnitPathToRange( int2 src, int2 target, int range, Actor self )
{ {
using( new PerfSample( "find_unit_path_multiple_src" ) ) using( new PerfSample( "Pathfinder" ) )
{ {
var mobileInfo = self.Info.Traits.Get<MobileInfo>(); var mobileInfo = self.Info.Traits.Get<MobileInfo>();
var tilesInRange = world.FindTilesInCircle(target, range) var tilesInRange = world.FindTilesInCircle(target, range)
@@ -93,7 +93,7 @@ namespace OpenRA
public List<int2> FindPath( PathSearch search ) public List<int2> FindPath( PathSearch search )
{ {
//using (new PerfSample("find_path_inner")) using (new PerfSample("Pathfinder"))
{ {
while (!search.queue.Empty) while (!search.queue.Empty)
{ {
@@ -127,9 +127,11 @@ namespace OpenRA
List<int2> FindBidiPath( /* searches from both ends toward each other */ public List<int2> FindBidiPath( /* searches from both ends toward each other */
PathSearch fromSrc, PathSearch fromSrc,
PathSearch fromDest) PathSearch fromDest)
{
using (new PerfSample("Pathfinder"))
{ {
while (!fromSrc.queue.Empty && !fromDest.queue.Empty) while (!fromSrc.queue.Empty && !fromDest.queue.Empty)
{ {
@@ -148,6 +150,7 @@ namespace OpenRA
return new List<int2>(); return new List<int2>();
} }
}
static List<int2> MakeBidiPath(PathSearch a, PathSearch b, int2 p) static List<int2> MakeBidiPath(PathSearch a, PathSearch b, int2 p)
{ {

View File

@@ -72,7 +72,7 @@ namespace OpenRA
public PathSearch FromPoint(int2 from) public PathSearch FromPoint(int2 from)
{ {
AddInitialCell( world, from ); AddInitialCell( from );
return this; return this;
} }
@@ -155,7 +155,7 @@ namespace OpenRA
new int2( 1, 1 ), new int2( 1, 1 ),
}; };
public void AddInitialCell( World world, int2 location ) public void AddInitialCell( int2 location )
{ {
if (!world.Map.IsInMap(location.X, location.Y)) if (!world.Map.IsInMap(location.X, location.Y))
return; return;
@@ -177,7 +177,7 @@ namespace OpenRA
heuristic = DefaultEstimator( target ), heuristic = DefaultEstimator( target ),
checkForBlocked = checkForBlocked }; checkForBlocked = checkForBlocked };
search.AddInitialCell( world, from ); search.AddInitialCell( from );
return search; return search;
} }
@@ -190,7 +190,7 @@ namespace OpenRA
}; };
foreach( var sl in froms ) foreach( var sl in froms )
search.AddInitialCell(world, sl); search.AddInitialCell( sl );
return search; return search;
} }

View File

@@ -0,0 +1,37 @@
#region Copyright & License Information
/*
* Copyright 2007-2010 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information,
* see LICENSE.
*/
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using OpenRA.Traits;
using OpenRA.Traits.Activities;
namespace OpenRA.Mods.RA.Activities
{
public class Enter : CancelableActivity
{
readonly Actor target;
public Enter( Actor target ) { this.target = target; }
public override IActivity Tick( Actor self )
{
if( IsCanceled || target.Destroyed || !target.IsInWorld )
return NextActivity;
var mobile = self.Trait<Mobile>();
var nearest = target.Trait<IOccupySpace>().NearestCellTo( mobile.toCell );
if( ( nearest - mobile.toCell ).LengthSquared >= 2 )
return Util.SequenceActivities( new MoveAdjacentTo( target ), this );
return Util.SequenceActivities( new Move( nearest, target ), NextActivity );
}
}
}

View File

@@ -35,7 +35,8 @@ namespace OpenRA.Mods.RA.Activities
return new Wait(20); return new Wait(20);
return Util.SequenceActivities( return Util.SequenceActivities(
new Move(Util.CellContaining(rearmTarget.CenterLocation), rearmTarget), new Enter(rearmTarget),
//new Move(Util.CellContaining(rearmTarget.CenterLocation), rearmTarget),
new Rearm(), new Rearm(),
new Repair(rearmTarget), new Repair(rearmTarget),
this ); this );

View File

@@ -0,0 +1,54 @@
#region Copyright & License Information
/*
* Copyright 2007-2010 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information,
* see LICENSE.
*/
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using OpenRA.Traits;
using OpenRA.Traits.Activities;
namespace OpenRA.Mods.RA.Activities
{
public class MoveAdjacentTo : CancelableActivity
{
readonly Actor target;
public MoveAdjacentTo( Actor target )
{
this.target = target;
}
public override IActivity Tick( Actor self )
{
if( IsCanceled || target.Destroyed || !target.IsInWorld) return NextActivity;
var mobile = self.Trait<Mobile>();
var ps1 = new PathSearch( self.World, mobile.Info )
{
checkForBlocked = true,
heuristic = location => 0,
inReverse = true
};
foreach( var cell in target.Trait<IOccupySpace>().OccupiedCells() )
{
ps1.AddInitialCell( cell );
if( ( mobile.toCell - cell ).LengthSquared <= 2 )
return NextActivity;
}
ps1.heuristic = PathSearch.DefaultEstimator( mobile.toCell );
var ps2 = PathSearch.FromPoint( self.World, mobile.Info, mobile.toCell, target.Location, true );
var ret = self.World.PathFinder.FindBidiPath( ps1, ps2 );
if( ret.Count > 0 )
ret.RemoveAt( 0 );
return Util.SequenceActivities( new Move( () => ret ), this );
}
}
}

View File

@@ -54,7 +54,8 @@ namespace OpenRA.Mods.RA
}); });
self.CancelActivity(); self.CancelActivity();
self.QueueActivity(new Move(order.TargetActor.Location, order.TargetActor)); self.QueueActivity(new Enter(order.TargetActor));
//self.QueueActivity(new Move(order.TargetActor.Location, order.TargetActor));
self.QueueActivity(new Demolish(order.TargetActor)); self.QueueActivity(new Demolish(order.TargetActor));
self.QueueActivity(new Move(self.Location, 0)); self.QueueActivity(new Move(self.Location, 0));
} }

View File

@@ -58,7 +58,8 @@ namespace OpenRA.Mods.RA
}); });
self.CancelActivity(); self.CancelActivity();
self.QueueActivity(new Move(order.TargetActor.Location, order.TargetActor)); self.QueueActivity(new Enter(order.TargetActor));
//self.QueueActivity(new Move(order.TargetActor.Location, order.TargetActor));
self.QueueActivity(new CaptureBuilding(order.TargetActor)); self.QueueActivity(new CaptureBuilding(order.TargetActor));
} }
} }

View File

@@ -57,7 +57,8 @@ namespace OpenRA.Mods.RA
}); });
self.CancelActivity(); self.CancelActivity();
self.QueueActivity(new Move(order.TargetActor.Location, order.TargetActor)); self.QueueActivity(new Enter(order.TargetActor));
//self.QueueActivity(new Move(order.TargetActor.Location, order.TargetActor));
self.QueueActivity(new RepairBuilding(order.TargetActor)); self.QueueActivity(new RepairBuilding(order.TargetActor));
} }
} }

View File

@@ -57,6 +57,7 @@
<Compile Include="Activities\CaptureBuilding.cs" /> <Compile Include="Activities\CaptureBuilding.cs" />
<Compile Include="Activities\DeliverOre.cs" /> <Compile Include="Activities\DeliverOre.cs" />
<Compile Include="Activities\Demolish.cs" /> <Compile Include="Activities\Demolish.cs" />
<Compile Include="Activities\Enter.cs" />
<Compile Include="Activities\EnterTransport.cs" /> <Compile Include="Activities\EnterTransport.cs" />
<Compile Include="Activities\Fly.cs" /> <Compile Include="Activities\Fly.cs" />
<Compile Include="Activities\FlyAttack.cs" /> <Compile Include="Activities\FlyAttack.cs" />
@@ -70,6 +71,7 @@
<Compile Include="Activities\Land.cs" /> <Compile Include="Activities\Land.cs" />
<Compile Include="Activities\LayMines.cs" /> <Compile Include="Activities\LayMines.cs" />
<Compile Include="Activities\Leap.cs" /> <Compile Include="Activities\Leap.cs" />
<Compile Include="Activities\MoveAdjacentTo.cs" />
<Compile Include="Activities\Rearm.cs" /> <Compile Include="Activities\Rearm.cs" />
<Compile Include="Activities\Repair.cs" /> <Compile Include="Activities\Repair.cs" />
<Compile Include="Activities\ReturnToBase.cs" /> <Compile Include="Activities\ReturnToBase.cs" />

View File

@@ -39,7 +39,7 @@ namespace OpenRA.Mods.RA
if (order.OrderString == "SpyInfiltrate") if (order.OrderString == "SpyInfiltrate")
{ {
self.CancelActivity(); self.CancelActivity();
self.QueueActivity(new Move(order.TargetActor, 1)); self.QueueActivity(new MoveAdjacentTo(order.TargetActor));
if (self.Owner == self.World.LocalPlayer) if (self.Owner == self.World.LocalPlayer)
self.World.AddFrameEndTask( w => self.World.AddFrameEndTask( w =>
{ {