Allow units to move between subcells. Visually not quite right.
This commit is contained in:
@@ -55,8 +55,14 @@ namespace OpenRA.Traits
|
|||||||
if (!AnyUnitsAt(a))
|
if (!AnyUnitsAt(a))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return new[]{SubCell.BottomLeft, SubCell.BottomRight, SubCell.Center,
|
return new[]{SubCell.TopLeft, SubCell.TopRight, SubCell.Center,
|
||||||
SubCell.TopLeft, SubCell.TopRight}.Any(b => !AnyUnitsAt(a,b));
|
SubCell.BottomLeft, SubCell.BottomRight}.Any(b => !AnyUnitsAt(a,b));
|
||||||
|
}
|
||||||
|
|
||||||
|
public SubCell GetFreeSubcell(int2 a, SubCell preferred)
|
||||||
|
{
|
||||||
|
return new[]{preferred, SubCell.TopLeft, SubCell.TopRight, SubCell.Center,
|
||||||
|
SubCell.BottomLeft, SubCell.BottomRight}.First(b => !AnyUnitsAt(a,b));
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool AnyUnitsAt(int2 a)
|
public bool AnyUnitsAt(int2 a)
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ namespace OpenRA.Mods.RA.Move
|
|||||||
public readonly Dictionary<SubCell, int2> SubCellOffsets = new Dictionary<SubCell, int2>()
|
public readonly Dictionary<SubCell, int2> SubCellOffsets = new Dictionary<SubCell, int2>()
|
||||||
{
|
{
|
||||||
{SubCell.TopLeft, new int2(-6,-6)},
|
{SubCell.TopLeft, new int2(-6,-6)},
|
||||||
{SubCell.TopRight, new int2(6,6)},
|
{SubCell.TopRight, new int2(6,-6)},
|
||||||
{SubCell.Center, new int2(0,0)},
|
{SubCell.Center, new int2(0,0)},
|
||||||
{SubCell.BottomLeft, new int2(-6,6)},
|
{SubCell.BottomLeft, new int2(-6,6)},
|
||||||
{SubCell.BottomRight, new int2(6,6)},
|
{SubCell.BottomRight, new int2(6,6)},
|
||||||
@@ -155,12 +155,14 @@ namespace OpenRA.Mods.RA.Move
|
|||||||
[Sync]
|
[Sync]
|
||||||
public int PathHash; // written by Move.EvalPath, to temporarily debug this crap.
|
public int PathHash; // written by Move.EvalPath, to temporarily debug this crap.
|
||||||
|
|
||||||
public void SetLocation(int2 from, int2 to)
|
public void SetLocation(int2 from, SubCell fromSub, int2 to, SubCell toSub)
|
||||||
{
|
{
|
||||||
if (fromCell == from && toCell == to) return;
|
if (fromCell == from && toCell == to) return;
|
||||||
RemoveInfluence();
|
RemoveInfluence();
|
||||||
__fromCell = from;
|
__fromCell = from;
|
||||||
__toCell = to;
|
__toCell = to;
|
||||||
|
__fromSubCell = fromSub;
|
||||||
|
__toSubCell = toSub;
|
||||||
AddInfluence();
|
AddInfluence();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -194,7 +196,7 @@ namespace OpenRA.Mods.RA.Move
|
|||||||
|
|
||||||
public void SetPosition(Actor self, int2 cell)
|
public void SetPosition(Actor self, int2 cell)
|
||||||
{
|
{
|
||||||
SetLocation(cell, cell);
|
SetLocation(cell,__fromSubCell, cell,__fromSubCell);
|
||||||
PxPosition = Util.CenterOfCell(fromCell) + Info.SubCellOffsets[__fromSubCell];
|
PxPosition = Util.CenterOfCell(fromCell) + Info.SubCellOffsets[__fromSubCell];
|
||||||
FinishedMoving(self);
|
FinishedMoving(self);
|
||||||
}
|
}
|
||||||
@@ -202,7 +204,7 @@ namespace OpenRA.Mods.RA.Move
|
|||||||
public void SetPxPosition(Actor self, int2 px)
|
public void SetPxPosition(Actor self, int2 px)
|
||||||
{
|
{
|
||||||
var cell = Util.CellContaining(px);
|
var cell = Util.CellContaining(px);
|
||||||
SetLocation(cell, cell);
|
SetLocation(cell,__fromSubCell, cell,__fromSubCell);
|
||||||
PxPosition = px;
|
PxPosition = px;
|
||||||
FinishedMoving(self);
|
FinishedMoving(self);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ using System.Linq;
|
|||||||
using OpenRA.Mods.RA.Activities;
|
using OpenRA.Mods.RA.Activities;
|
||||||
using OpenRA.Traits;
|
using OpenRA.Traits;
|
||||||
using OpenRA.Traits.Activities;
|
using OpenRA.Traits.Activities;
|
||||||
|
using OpenRA.FileFormats;
|
||||||
|
|
||||||
namespace OpenRA.Mods.RA.Move
|
namespace OpenRA.Mods.RA.Move
|
||||||
{
|
{
|
||||||
@@ -132,16 +133,16 @@ namespace OpenRA.Mods.RA.Move
|
|||||||
if( nextCell == null )
|
if( nextCell == null )
|
||||||
return this;
|
return this;
|
||||||
|
|
||||||
int2 dir = nextCell.Value - mobile.fromCell;
|
int2 dir = nextCell.Value.First - mobile.fromCell;
|
||||||
var firstFacing = Util.GetFacing( dir, mobile.Facing );
|
var firstFacing = Util.GetFacing( dir, mobile.Facing );
|
||||||
if( firstFacing != mobile.Facing )
|
if( firstFacing != mobile.Facing )
|
||||||
{
|
{
|
||||||
path.Add( nextCell.Value );
|
path.Add( nextCell.Value.First );
|
||||||
return Util.SequenceActivities( new Turn( firstFacing ), this );
|
return Util.SequenceActivities( new Turn( firstFacing ), this );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
mobile.SetLocation( mobile.fromCell, nextCell.Value );
|
mobile.SetLocation( mobile.fromCell, mobile.__fromSubCell, nextCell.Value.First, nextCell.Value.Second );
|
||||||
var move = new MoveFirstHalf(
|
var move = new MoveFirstHalf(
|
||||||
this,
|
this,
|
||||||
Util.CenterOfCell( mobile.fromCell ),
|
Util.CenterOfCell( mobile.fromCell ),
|
||||||
@@ -183,7 +184,7 @@ namespace OpenRA.Mods.RA.Move
|
|||||||
nudge.OnNudge(blocker, self);
|
nudge.OnNudge(blocker, self);
|
||||||
}
|
}
|
||||||
|
|
||||||
int2? PopPath( Actor self, Mobile mobile )
|
Pair<int2, SubCell>? PopPath( Actor self, Mobile mobile )
|
||||||
{
|
{
|
||||||
if( path.Count == 0 ) return null;
|
if( path.Count == 0 ) return null;
|
||||||
var nextCell = path[ path.Count - 1 ];
|
var nextCell = path[ path.Count - 1 ];
|
||||||
@@ -229,7 +230,9 @@ namespace OpenRA.Mods.RA.Move
|
|||||||
hasNudged = false;
|
hasNudged = false;
|
||||||
hasWaited = false;
|
hasWaited = false;
|
||||||
path.RemoveAt( path.Count - 1 );
|
path.RemoveAt( path.Count - 1 );
|
||||||
return nextCell;
|
|
||||||
|
var subCell = self.World.WorldActor.Trait<UnitInfluence>().GetFreeSubcell(nextCell, mobile.__fromSubCell);
|
||||||
|
return Pair.New(nextCell, subCell);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override bool OnCancel( Actor self )
|
protected override bool OnCancel( Actor self )
|
||||||
@@ -335,22 +338,23 @@ namespace OpenRA.Mods.RA.Move
|
|||||||
var nextCell = parent.PopPath( self, mobile );
|
var nextCell = parent.PopPath( self, mobile );
|
||||||
if( nextCell != null )
|
if( nextCell != null )
|
||||||
{
|
{
|
||||||
if( ( nextCell - mobile.toCell ) != ( mobile.toCell - mobile.fromCell ) )
|
if( ( nextCell.Value.First - mobile.toCell ) != ( mobile.toCell - mobile.fromCell ) )
|
||||||
{
|
{
|
||||||
var ret = new MoveFirstHalf(
|
var ret = new MoveFirstHalf(
|
||||||
move,
|
move,
|
||||||
Util.BetweenCells( mobile.fromCell, mobile.toCell ),
|
Util.BetweenCells( mobile.fromCell, mobile.toCell ),
|
||||||
Util.BetweenCells( mobile.toCell, nextCell.Value ),
|
Util.BetweenCells( mobile.toCell, nextCell.Value.First ),
|
||||||
mobile.__fromSubCell,
|
mobile.__fromSubCell,
|
||||||
mobile.__toSubCell,
|
nextCell.Value.Second,
|
||||||
mobile.Facing,
|
mobile.Facing,
|
||||||
Util.GetNearestFacing( mobile.Facing, Util.GetFacing( nextCell.Value - mobile.toCell, mobile.Facing ) ),
|
Util.GetNearestFacing( mobile.Facing, Util.GetFacing( nextCell.Value.First - mobile.toCell, mobile.Facing ) ),
|
||||||
moveFraction - moveFractionTotal );
|
moveFraction - moveFractionTotal );
|
||||||
mobile.SetLocation( mobile.toCell, nextCell.Value );
|
|
||||||
|
mobile.SetLocation( mobile.toCell, mobile.__toSubCell, nextCell.Value.First, nextCell.Value.Second);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
parent.path.Add( nextCell.Value );
|
parent.path.Add( nextCell.Value.First );
|
||||||
}
|
}
|
||||||
var ret2 = new MoveSecondHalf(
|
var ret2 = new MoveSecondHalf(
|
||||||
move,
|
move,
|
||||||
@@ -361,7 +365,7 @@ namespace OpenRA.Mods.RA.Move
|
|||||||
mobile.Facing,
|
mobile.Facing,
|
||||||
mobile.Facing,
|
mobile.Facing,
|
||||||
moveFraction - moveFractionTotal );
|
moveFraction - moveFractionTotal );
|
||||||
mobile.SetLocation( mobile.toCell, mobile.toCell );
|
mobile.SetLocation( mobile.toCell, mobile.__toSubCell, mobile.toCell, mobile.__toSubCell );
|
||||||
return ret2;
|
return ret2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -376,7 +380,7 @@ namespace OpenRA.Mods.RA.Move
|
|||||||
protected override MovePart OnComplete( Actor self, Mobile mobile, Move parent )
|
protected override MovePart OnComplete( Actor self, Mobile mobile, Move parent )
|
||||||
{
|
{
|
||||||
mobile.PxPosition = Util.CenterOfCell( mobile.toCell );
|
mobile.PxPosition = Util.CenterOfCell( mobile.toCell );
|
||||||
mobile.SetLocation( mobile.toCell, mobile.toCell );
|
mobile.SetLocation( mobile.toCell, mobile.__toSubCell, mobile.toCell, mobile.__toSubCell );
|
||||||
mobile.FinishedMoving(self);
|
mobile.FinishedMoving(self);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user