Some initial hacks towards multiple-infantry-per-cell. Make the pathfinder smart enough to do what we need, and remove a *lot* of stupid duplication. Needs more work.

This commit is contained in:
Paul Chote
2010-06-23 19:54:22 +12:00
parent 308a7b0cf6
commit b7c8e55d14
12 changed files with 93 additions and 87 deletions

View File

@@ -62,7 +62,7 @@ namespace OpenRA.Traits.Activities
{
this.getPath = (self, mobile) =>
self.World.PathFinder.FindPath(
PathSearch.FromPoint( self.World, self.Location, destination, mobile.GetMovementType(), false )
PathSearch.FromPoint( self, self.Location, destination, mobile.GetMovementType(), false )
.WithCustomBlocker( self.World.PathFinder.AvoidUnitsNear( self.Location, 4, self ))
.WithIgnoredBuilding( ignoreBuilding ));
@@ -89,17 +89,6 @@ namespace OpenRA.Traits.Activities
this.nearEnough = 0;
}
bool CanEnterCell( int2 c, Actor self )
{
if (!self.World.WorldActor.traits.Get<BuildingInfluence>().CanMoveHere(c)
&& self.World.WorldActor.traits.Get<BuildingInfluence>().GetBuildingAt(c) != ignoreBuilding)
return false;
// Cannot enter a cell if any unit inside is uncrushable
// This will need to be updated for multiple-infantry-in-a-cell
return (!self.World.WorldActor.traits.Get<UnitInfluence>().GetUnitsAt(c).Any(a => a != self && !self.World.IsActorCrushableByActor(a, self)));
}
public IActivity Tick( Actor self )
{
var unit = self.traits.Get<Unit>();
@@ -179,7 +168,7 @@ namespace OpenRA.Traits.Activities
{
if( path.Count == 0 ) return null;
var nextCell = path[ path.Count - 1 ];
if( !CanEnterCell( nextCell, self ) )
if( !mobile.CanEnterCell( nextCell ) )
{
if( ( mobile.toCell - destination.Value ).LengthSquared <= nearEnough )
{
@@ -255,6 +244,8 @@ namespace OpenRA.Traits.Activities
var frac = (float)moveFraction / moveFractionTotal;
self.CenterLocation = float2.Lerp( from, to, frac );
// + self.traits.WithInterface<IOffsetCenterLocation>().Aggregate(float2.Zero, (a, x) => a + x.CenterOffset);
if( moveFraction >= moveFractionTotal )
unit.Facing = toFacing & 0xFF;
else