clean up some of the noise in Move
This commit is contained in:
@@ -109,7 +109,7 @@ namespace OpenRA.Mods.RA.Move
|
||||
|
||||
int __facing;
|
||||
int2 __fromCell, __toCell;
|
||||
public SubCell __fromSubCell, __toSubCell;
|
||||
public SubCell fromSubCell, toSubCell;
|
||||
|
||||
int __altitude;
|
||||
|
||||
@@ -146,8 +146,8 @@ namespace OpenRA.Mods.RA.Move
|
||||
RemoveInfluence();
|
||||
__fromCell = from;
|
||||
__toCell = to;
|
||||
__fromSubCell = fromSub;
|
||||
__toSubCell = toSub;
|
||||
fromSubCell = fromSub;
|
||||
toSubCell = toSub;
|
||||
AddInfluence();
|
||||
}
|
||||
|
||||
@@ -160,16 +160,16 @@ namespace OpenRA.Mods.RA.Move
|
||||
this.self = init.self;
|
||||
this.Info = info;
|
||||
|
||||
__toSubCell = __fromSubCell = info.SharesCell ? SubCell.Center : SubCell.FullCell;
|
||||
toSubCell = fromSubCell = info.SharesCell ? SubCell.Center : SubCell.FullCell;
|
||||
if (init.Contains<SubCellInit>())
|
||||
{
|
||||
this.__fromSubCell = this.__toSubCell = init.Get<SubCellInit, SubCell>();
|
||||
this.fromSubCell = this.toSubCell = init.Get<SubCellInit, SubCell>();
|
||||
}
|
||||
|
||||
if (init.Contains<LocationInit>())
|
||||
{
|
||||
this.__fromCell = this.__toCell = init.Get<LocationInit, int2>();
|
||||
this.PxPosition = Util.CenterOfCell(fromCell) + info.SubCellOffsets[__fromSubCell];
|
||||
this.PxPosition = Util.CenterOfCell(fromCell) + info.SubCellOffsets[fromSubCell];
|
||||
}
|
||||
|
||||
this.Facing = init.Contains<FacingInit>() ? init.Get<FacingInit, int>() : info.InitialFacing;
|
||||
@@ -178,15 +178,15 @@ namespace OpenRA.Mods.RA.Move
|
||||
|
||||
public void SetPosition(Actor self, int2 cell)
|
||||
{
|
||||
SetLocation(cell,__fromSubCell, cell,__fromSubCell);
|
||||
PxPosition = Util.CenterOfCell(fromCell) + Info.SubCellOffsets[__fromSubCell];
|
||||
SetLocation(cell,fromSubCell, cell,fromSubCell);
|
||||
PxPosition = Util.CenterOfCell(fromCell) + Info.SubCellOffsets[fromSubCell];
|
||||
FinishedMoving(self);
|
||||
}
|
||||
|
||||
public void SetPxPosition(Actor self, int2 px)
|
||||
{
|
||||
var cell = Util.CellContaining(px);
|
||||
SetLocation(cell,__fromSubCell, cell,__fromSubCell);
|
||||
SetLocation(cell,fromSubCell, cell,fromSubCell);
|
||||
PxPosition = px;
|
||||
FinishedMoving(self);
|
||||
}
|
||||
@@ -287,13 +287,13 @@ namespace OpenRA.Mods.RA.Move
|
||||
public IEnumerable<Pair<int2, SubCell>> OccupiedCells()
|
||||
{
|
||||
if (fromCell == toCell)
|
||||
yield return Pair.New(fromCell, __fromSubCell);
|
||||
yield return Pair.New(fromCell, fromSubCell);
|
||||
else if (CanEnterCell(toCell))
|
||||
yield return Pair.New(toCell, __toSubCell);
|
||||
yield return Pair.New(toCell, toSubCell);
|
||||
else
|
||||
{
|
||||
yield return Pair.New(fromCell, __fromSubCell);
|
||||
yield return Pair.New(toCell, __toSubCell);
|
||||
yield return Pair.New(fromCell, fromSubCell);
|
||||
yield return Pair.New(toCell, toSubCell);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -303,7 +303,7 @@ namespace OpenRA.Mods.RA.Move
|
||||
return SubCell.FullCell;
|
||||
|
||||
// Prioritise the current subcell
|
||||
return new[]{ __fromSubCell, SubCell.TopLeft, SubCell.TopRight, SubCell.Center,
|
||||
return new[]{ fromSubCell, SubCell.TopLeft, SubCell.TopRight, SubCell.Center,
|
||||
SubCell.BottomLeft, SubCell.BottomRight}.First(b =>
|
||||
{
|
||||
var blockingActors = self.World.ActorMap.GetUnitsAt(a,b).Where(c => c != ignoreActor);
|
||||
|
||||
@@ -133,11 +133,11 @@ namespace OpenRA.Mods.RA.Move
|
||||
}
|
||||
else
|
||||
{
|
||||
mobile.SetLocation( mobile.fromCell, mobile.__fromSubCell, nextCell.Value.First, nextCell.Value.Second );
|
||||
mobile.SetLocation( mobile.fromCell, mobile.fromSubCell, nextCell.Value.First, nextCell.Value.Second );
|
||||
var move = new MoveFirstHalf(
|
||||
this,
|
||||
Util.CenterOfCell( mobile.fromCell ) + mobile.Info.SubCellOffsets[mobile.__fromSubCell],
|
||||
Util.BetweenCells( mobile.fromCell, mobile.toCell ) + (mobile.Info.SubCellOffsets[mobile.__fromSubCell] + mobile.Info.SubCellOffsets[mobile.__toSubCell] ) / 2,
|
||||
Util.CenterOfCell( mobile.fromCell ) + mobile.Info.SubCellOffsets[mobile.fromSubCell],
|
||||
Util.BetweenCells( mobile.fromCell, mobile.toCell ) + (mobile.Info.SubCellOffsets[mobile.fromSubCell] + mobile.Info.SubCellOffsets[mobile.toSubCell] ) / 2,
|
||||
mobile.Facing,
|
||||
mobile.Facing,
|
||||
0 );
|
||||
@@ -316,41 +316,50 @@ namespace OpenRA.Mods.RA.Move
|
||||
class MoveFirstHalf : MovePart
|
||||
{
|
||||
public MoveFirstHalf( Move move, int2 from, int2 to, int fromFacing, int toFacing, int startingFraction )
|
||||
: base( move, from, to, fromFacing, toFacing, startingFraction )
|
||||
: base( move, from, to, fromFacing, toFacing, startingFraction ) { }
|
||||
|
||||
static bool IsTurn( Mobile mobile, int2 nextCell )
|
||||
{
|
||||
return nextCell - mobile.toCell !=
|
||||
mobile.toCell - mobile.fromCell;
|
||||
}
|
||||
|
||||
protected override MovePart OnComplete( Actor self, Mobile mobile, Move parent )
|
||||
{
|
||||
var fromSubcellOffset = mobile.Info.SubCellOffsets[mobile.fromSubCell];
|
||||
var toSubcellOffset = mobile.Info.SubCellOffsets[mobile.toSubCell];
|
||||
|
||||
var nextCell = parent.PopPath( self, mobile );
|
||||
if( nextCell != null )
|
||||
{
|
||||
if( ( nextCell.Value.First - mobile.toCell ) != ( mobile.toCell - mobile.fromCell ) )
|
||||
if(IsTurn(mobile, nextCell.Value.First))
|
||||
{
|
||||
var nextSubcellOffset = mobile.Info.SubCellOffsets[nextCell.Value.Second];
|
||||
var ret = new MoveFirstHalf(
|
||||
move,
|
||||
Util.BetweenCells( mobile.fromCell, mobile.toCell ) + (mobile.Info.SubCellOffsets[mobile.__fromSubCell] + mobile.Info.SubCellOffsets[mobile.__toSubCell]) / 2,
|
||||
Util.BetweenCells( mobile.toCell, nextCell.Value.First ) + (mobile.Info.SubCellOffsets[mobile.__toSubCell] + mobile.Info.SubCellOffsets[nextCell.Value.Second]) / 2,
|
||||
Util.BetweenCells( mobile.fromCell, mobile.toCell ) + (fromSubcellOffset + toSubcellOffset) / 2,
|
||||
Util.BetweenCells( mobile.toCell, nextCell.Value.First ) + (toSubcellOffset + nextSubcellOffset) / 2,
|
||||
mobile.Facing,
|
||||
Util.GetNearestFacing( mobile.Facing, Util.GetFacing( nextCell.Value.First - mobile.toCell, mobile.Facing ) ),
|
||||
moveFraction - moveFractionTotal );
|
||||
|
||||
mobile.SetLocation( mobile.toCell, mobile.__toSubCell, nextCell.Value.First, nextCell.Value.Second);
|
||||
mobile.SetLocation( mobile.toCell, mobile.toSubCell, nextCell.Value.First, nextCell.Value.Second);
|
||||
return ret;
|
||||
}
|
||||
else
|
||||
parent.path.Add( nextCell.Value.First );
|
||||
|
||||
parent.path.Add( nextCell.Value.First );
|
||||
}
|
||||
|
||||
var ret2 = new MoveSecondHalf(
|
||||
move,
|
||||
Util.BetweenCells( mobile.fromCell, mobile.toCell ) + (mobile.Info.SubCellOffsets[mobile.__fromSubCell] + mobile.Info.SubCellOffsets[mobile.__toSubCell]) / 2,
|
||||
Util.CenterOfCell( mobile.toCell ) + mobile.Info.SubCellOffsets[mobile.__toSubCell],
|
||||
Util.BetweenCells( mobile.fromCell, mobile.toCell ) + (fromSubcellOffset + toSubcellOffset) / 2,
|
||||
Util.CenterOfCell( mobile.toCell ) + toSubcellOffset,
|
||||
mobile.Facing,
|
||||
mobile.Facing,
|
||||
moveFraction - moveFractionTotal );
|
||||
|
||||
mobile.EnteringCell(self);
|
||||
mobile.SetLocation( mobile.toCell, mobile.__toSubCell, mobile.toCell, mobile.__toSubCell );
|
||||
mobile.SetLocation( mobile.toCell, mobile.toSubCell, mobile.toCell, mobile.toSubCell );
|
||||
return ret2;
|
||||
}
|
||||
}
|
||||
@@ -365,7 +374,7 @@ namespace OpenRA.Mods.RA.Move
|
||||
protected override MovePart OnComplete( Actor self, Mobile mobile, Move parent )
|
||||
{
|
||||
mobile.PxPosition = Util.CenterOfCell( mobile.toCell );
|
||||
mobile.SetLocation( mobile.toCell, mobile.__toSubCell, mobile.toCell, mobile.__toSubCell );
|
||||
mobile.SetLocation( mobile.toCell, mobile.toSubCell, mobile.toCell, mobile.toSubCell );
|
||||
mobile.FinishedMoving(self);
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user