Harvesting works better, and other related stuff.
This commit is contained in:
@@ -324,7 +324,7 @@ namespace OpenRa.Game
|
||||
unit = new Actor(name, (1 / 24f * producer.CenterLocation).ToInt2(), player);
|
||||
var mobile = unit.traits.Get<Mobile>();
|
||||
mobile.facing = 128;
|
||||
mobile.QueueActivity(new Traits.Activities.Move(unit.Location + new int2(0, 3)));
|
||||
mobile.QueueActivity(new Traits.Activities.Move(unit.Location + new int2(0, 3), 1));
|
||||
}
|
||||
|
||||
world.Add( unit );
|
||||
|
||||
@@ -54,7 +54,7 @@ namespace OpenRa.Game
|
||||
WorldRenderer.ShowUnitPaths = settings.GetValue("pathdebug", false);
|
||||
Game.Replay = settings.GetValue("replay", "");
|
||||
|
||||
Game.Initialize(settings.GetValue("map", "scg11eb.ini"), renderer, new int2(ClientSize),
|
||||
Game.Initialize(settings.GetValue("map", "scm12ea.ini"), renderer, new int2(ClientSize),
|
||||
settings.GetValue("player", 1));
|
||||
|
||||
SequenceProvider.ForcePrecache();
|
||||
|
||||
@@ -66,12 +66,12 @@ namespace OpenRa.Game
|
||||
return ret;
|
||||
}
|
||||
|
||||
List<int2> FindUnitPath( int2 unitLocation, Func<int2,double> estimator, UnitMovementType umt )
|
||||
public List<int2> FindUnitPath( int2 unitLocation, Func<int2,double> estimator, UnitMovementType umt )
|
||||
{
|
||||
return FindUnitPath( new[] { unitLocation }, estimator, umt );
|
||||
}
|
||||
|
||||
List<int2> FindUnitPath(IEnumerable<int2> startLocations, Func<int2, double> estimator, UnitMovementType umt)
|
||||
public List<int2> FindUnitPath( IEnumerable<int2> startLocations, Func<int2, double> estimator, UnitMovementType umt )
|
||||
{
|
||||
var cellInfo = InitCellInfo();
|
||||
var queue = new PriorityQueue<PathDistance>();
|
||||
@@ -109,6 +109,9 @@ namespace OpenRa.Game
|
||||
continue;
|
||||
if( checkForBlock && Game.UnitInfluence.GetUnitAt( newHere ) != null )
|
||||
continue;
|
||||
var est = estimator( newHere );
|
||||
if( est == double.PositiveInfinity )
|
||||
continue;
|
||||
|
||||
double cellCost = ( ( d.X * d.Y != 0 ) ? 1.414213563 : 1.0 ) * passableCost[(int)umt][ newHere.X, newHere.Y ];
|
||||
double newCost = cellInfo[ here.X, here.Y ].MinCost + cellCost;
|
||||
@@ -119,7 +122,7 @@ namespace OpenRa.Game
|
||||
cellInfo[ newHere.X, newHere.Y ].Path = here;
|
||||
cellInfo[ newHere.X, newHere.Y ].MinCost = newCost;
|
||||
|
||||
queue.Add( new PathDistance( newCost + estimator( newHere ), newHere ) );
|
||||
queue.Add( new PathDistance( newCost + est, newHere ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using OpenRa.Game.Traits.Activities;
|
||||
|
||||
namespace OpenRa.Game.Traits
|
||||
{
|
||||
@@ -14,7 +14,9 @@ namespace OpenRa.Game.Traits
|
||||
w =>
|
||||
{
|
||||
var harvester = new Actor("harv", self.Location + new int2(1, 2), self.Owner);
|
||||
harvester.traits.Get<Mobile>().facing = 64;
|
||||
var mobile = harvester.traits.Get<Mobile>();
|
||||
mobile.facing = 64;
|
||||
mobile.InternalSetActivity( new Harvest() );
|
||||
w.Add(harvester);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -21,8 +21,9 @@ namespace OpenRa.Game.Traits.Activities
|
||||
harv.gemsCarried = 0;
|
||||
harv.oreCarried = 0;
|
||||
|
||||
if( NextActivity == null )
|
||||
NextActivity = new Harvest();
|
||||
mobile.InternalSetActivity(NextActivity);
|
||||
/* todo: return to the ore patch */
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -12,6 +12,13 @@ namespace OpenRa.Game.Traits.Activities
|
||||
|
||||
public void Tick(Actor self, Mobile mobile)
|
||||
{
|
||||
if( NextActivity != null )
|
||||
{
|
||||
mobile.InternalSetActivity( NextActivity );
|
||||
NextActivity.Tick( self, mobile );
|
||||
return;
|
||||
}
|
||||
|
||||
var harv = self.traits.Get<Harvester>();
|
||||
var isGem = false;
|
||||
|
||||
@@ -22,7 +29,10 @@ namespace OpenRa.Game.Traits.Activities
|
||||
var harvestAnim = "harvest" + Util.QuantizeFacing(mobile.facing, 8);
|
||||
var renderUnit = self.traits.WithInterface<RenderUnit>().First(); /* better have one of these! */
|
||||
if( harvestAnim != renderUnit.anim.CurrentSequence.Name )
|
||||
{
|
||||
isHarvesting = true;
|
||||
renderUnit.PlayCustomAnimation( self, harvestAnim, () => isHarvesting = false );
|
||||
}
|
||||
harv.AcceptResource(isGem);
|
||||
return;
|
||||
}
|
||||
@@ -42,16 +52,12 @@ namespace OpenRa.Game.Traits.Activities
|
||||
{
|
||||
/* find a proc */
|
||||
var proc = ChooseReturnLocation(self);
|
||||
if (proc == null)
|
||||
if( proc != null )
|
||||
{
|
||||
Cancel(self, mobile); /* is this a sane way to cancel? */
|
||||
return;
|
||||
}
|
||||
|
||||
mobile.QueueActivity(new Move(proc.Location + new int2(1, 2)));
|
||||
mobile.QueueActivity( new Move( proc.Location + new int2( 1, 2 ), 0 ) );
|
||||
mobile.QueueActivity( new Turn( 64 ) );
|
||||
mobile.QueueActivity( new DeliverOre() );
|
||||
|
||||
}
|
||||
mobile.InternalSetActivity(NextActivity);
|
||||
}
|
||||
|
||||
@@ -72,12 +78,24 @@ namespace OpenRa.Game.Traits.Activities
|
||||
/* find a nearby patch */
|
||||
/* todo: add the queries we need to support this! */
|
||||
|
||||
var path = Game.PathFinder.FindUnitPath( self.Location, loc =>
|
||||
{
|
||||
if( Game.UnitInfluence.GetUnitAt( loc ) != null ) return double.PositiveInfinity;
|
||||
return Game.map.ContainsResource( loc ) ? 0 : 1;
|
||||
}, UnitMovementType.Wheel )
|
||||
.TakeWhile( a => a != self.Location )
|
||||
.ToList();
|
||||
if( path.Count != 0 )
|
||||
{
|
||||
mobile.QueueActivity( new Move( path ) );
|
||||
mobile.QueueActivity( new Harvest() );
|
||||
}
|
||||
|
||||
mobile.InternalSetActivity(NextActivity);
|
||||
}
|
||||
|
||||
public void Cancel(Actor self, Mobile mobile)
|
||||
{
|
||||
mobile.InternalSetActivity(null); /* bob: anything else required? */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,17 +10,19 @@ namespace OpenRa.Game.Traits.Activities
|
||||
public Activity NextActivity { get; set; }
|
||||
|
||||
int2? destination;
|
||||
int nearEnough;
|
||||
public List<int2> path;
|
||||
Func<Actor, Mobile, List<int2>> getPath;
|
||||
|
||||
MovePart move;
|
||||
|
||||
public Move( int2 destination )
|
||||
public Move( int2 destination, int nearEnough )
|
||||
{
|
||||
this.getPath = ( self, mobile ) => Game.PathFinder.FindUnitPath(
|
||||
self.Location, destination,
|
||||
mobile.GetMovementType() );
|
||||
this.destination = destination;
|
||||
this.nearEnough = nearEnough;
|
||||
}
|
||||
|
||||
public Move( Actor target, int range )
|
||||
@@ -29,6 +31,13 @@ namespace OpenRa.Game.Traits.Activities
|
||||
self.Location, target.Location,
|
||||
mobile.GetMovementType(), range );
|
||||
this.destination = null;
|
||||
this.nearEnough = range;
|
||||
}
|
||||
|
||||
public Move( List<int2> path )
|
||||
{
|
||||
this.path = path;
|
||||
this.destination = path[ 0 ];
|
||||
}
|
||||
|
||||
static bool CanEnterCell( int2 c, Actor self )
|
||||
@@ -98,7 +107,7 @@ namespace OpenRa.Game.Traits.Activities
|
||||
var nextCell = path[ path.Count - 1 ];
|
||||
if( !CanEnterCell( nextCell, self ) )
|
||||
{
|
||||
if( ( mobile.toCell - destination.Value ).LengthSquared <= 8 )
|
||||
if( ( mobile.toCell - destination.Value ).LengthSquared <= nearEnough )
|
||||
{
|
||||
path.Clear();
|
||||
return null;
|
||||
@@ -120,6 +129,11 @@ namespace OpenRa.Game.Traits.Activities
|
||||
if( path.Count == 0 )
|
||||
return null;
|
||||
nextCell = path[ path.Count - 1 ];
|
||||
if( !CanEnterCell( nextCell, self ) )
|
||||
{
|
||||
path.Clear();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
path.RemoveAt( path.Count - 1 );
|
||||
return nextCell;
|
||||
|
||||
@@ -29,7 +29,7 @@ namespace OpenRa.Game.Traits
|
||||
&& underCursor.traits.Contains<AcceptsOre>() && !IsEmpty)
|
||||
return OpenRa.Game.Order.DeliverOre(self, underCursor);
|
||||
|
||||
if (underCursor == null && Game.map.ContainsResource(xy) && !IsFull)
|
||||
if (underCursor == null && Game.map.ContainsResource(xy))
|
||||
return OpenRa.Game.Order.Harvest(self, xy);
|
||||
|
||||
return null;
|
||||
|
||||
@@ -12,8 +12,9 @@ namespace OpenRa.Game.Traits
|
||||
{
|
||||
public Actor self;
|
||||
|
||||
public int2 fromCell;
|
||||
public int2 toCell { get { return self.Location; } set { self.Location = value; } }
|
||||
int2 __fromCell;
|
||||
public int2 fromCell { get { return __fromCell; } set { Game.UnitInfluence.Remove( this ); __fromCell = value; Game.UnitInfluence.Add( this ); } }
|
||||
public int2 toCell { get { return self.Location; } set { Game.UnitInfluence.Remove( this ); self.Location = value; Game.UnitInfluence.Add( this ); } }
|
||||
public int facing;
|
||||
|
||||
public int Voice = Game.CosmeticRandom.Next(2);
|
||||
|
||||
@@ -47,6 +47,14 @@ namespace OpenRa.Game
|
||||
}
|
||||
}
|
||||
|
||||
[System.Diagnostics.Conditional( "SANITY_CHECKS" )]
|
||||
void SanityCheckAdd( Mobile a )
|
||||
{
|
||||
foreach( var c in a.OccupiedCells() )
|
||||
if( influence[c.X, c.Y] != null )
|
||||
throw new InvalidOperationException( "UIM: Sanity check failed (Add)" );
|
||||
}
|
||||
|
||||
public Actor GetUnitAt( int2 a )
|
||||
{
|
||||
return influence[ a.X, a.Y ];
|
||||
@@ -54,6 +62,7 @@ namespace OpenRa.Game
|
||||
|
||||
public void Add(Mobile a)
|
||||
{
|
||||
SanityCheckAdd(a);
|
||||
foreach (var c in a.OccupiedCells())
|
||||
influence[c.X, c.Y] = a.self;
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace OpenRa.Game
|
||||
{
|
||||
var mobile = order.Subject.traits.Get<Mobile>();
|
||||
mobile.Cancel( order.Subject );
|
||||
mobile.QueueActivity( new Traits.Activities.Move( order.TargetLocation ) );
|
||||
mobile.QueueActivity( new Traits.Activities.Move( order.TargetLocation, 8 ) );
|
||||
|
||||
var attackBase = order.Subject.traits.WithInterface<AttackBase>().FirstOrDefault();
|
||||
if( attackBase != null )
|
||||
@@ -57,7 +57,7 @@ namespace OpenRa.Game
|
||||
{
|
||||
var mobile = order.Subject.traits.Get<Mobile>();
|
||||
mobile.Cancel(order.Subject);
|
||||
mobile.QueueActivity(new Traits.Activities.Move(order.TargetActor.Location + new int2(1, 2)));
|
||||
mobile.QueueActivity(new Traits.Activities.Move(order.TargetActor.Location + new int2(1, 2), 0));
|
||||
mobile.QueueActivity(new Traits.Activities.Turn(64));
|
||||
mobile.QueueActivity(new Traits.Activities.DeliverOre());
|
||||
break;
|
||||
@@ -66,7 +66,7 @@ namespace OpenRa.Game
|
||||
{
|
||||
var mobile = order.Subject.traits.Get<Mobile>();
|
||||
mobile.Cancel(order.Subject);
|
||||
mobile.QueueActivity(new Traits.Activities.Move(order.TargetLocation));
|
||||
mobile.QueueActivity(new Traits.Activities.Move(order.TargetLocation, 0));
|
||||
mobile.QueueActivity(new Traits.Activities.Harvest() );
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user