StyleCop fixes
This commit is contained in:
@@ -46,7 +46,7 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
|
|
||||||
getPath = () =>
|
getPath = () =>
|
||||||
self.World.WorldActor.Trait<PathFinder>().FindPath(
|
self.World.WorldActor.Trait<PathFinder>().FindPath(
|
||||||
PathSearch.FromPoint(self.World, mobile.Info, self, mobile.toCell, destination, false)
|
PathSearch.FromPoint(self.World, mobile.Info, self, mobile.ToCell, destination, false)
|
||||||
.WithoutLaneBias());
|
.WithoutLaneBias());
|
||||||
this.destination = destination;
|
this.destination = destination;
|
||||||
this.nearEnough = WRange.Zero;
|
this.nearEnough = WRange.Zero;
|
||||||
@@ -62,7 +62,7 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
moveDisablers = self.TraitsImplementing<IDisableMove>();
|
moveDisablers = self.TraitsImplementing<IDisableMove>();
|
||||||
|
|
||||||
getPath = () => self.World.WorldActor.Trait<PathFinder>()
|
getPath = () => self.World.WorldActor.Trait<PathFinder>()
|
||||||
.FindUnitPath(mobile.toCell, destination, self);
|
.FindUnitPath(mobile.ToCell, destination, self);
|
||||||
this.destination = destination;
|
this.destination = destination;
|
||||||
this.nearEnough = nearEnough;
|
this.nearEnough = nearEnough;
|
||||||
}
|
}
|
||||||
@@ -73,7 +73,7 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
moveDisablers = self.TraitsImplementing<IDisableMove>();
|
moveDisablers = self.TraitsImplementing<IDisableMove>();
|
||||||
|
|
||||||
getPath = () => self.World.WorldActor.Trait<PathFinder>()
|
getPath = () => self.World.WorldActor.Trait<PathFinder>()
|
||||||
.FindUnitPathToRange(mobile.fromCell, subCell, self.World.Map.CenterOfSubCell(destination, subCell), nearEnough, self);
|
.FindUnitPathToRange(mobile.FromCell, subCell, self.World.Map.CenterOfSubCell(destination, subCell), nearEnough, self);
|
||||||
this.destination = destination;
|
this.destination = destination;
|
||||||
this.nearEnough = nearEnough;
|
this.nearEnough = nearEnough;
|
||||||
}
|
}
|
||||||
@@ -85,7 +85,7 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
|
|
||||||
getPath = () =>
|
getPath = () =>
|
||||||
self.World.WorldActor.Trait<PathFinder>().FindPath(
|
self.World.WorldActor.Trait<PathFinder>().FindPath(
|
||||||
PathSearch.FromPoint(self.World, mobile.Info, self, mobile.toCell, destination, false)
|
PathSearch.FromPoint(self.World, mobile.Info, self, mobile.ToCell, destination, false)
|
||||||
.WithIgnoredActor(ignoredActor));
|
.WithIgnoredActor(ignoredActor));
|
||||||
|
|
||||||
this.destination = destination;
|
this.destination = destination;
|
||||||
@@ -104,7 +104,7 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
return NoPath;
|
return NoPath;
|
||||||
|
|
||||||
return self.World.WorldActor.Trait<PathFinder>().FindUnitPathToRange(
|
return self.World.WorldActor.Trait<PathFinder>().FindUnitPathToRange(
|
||||||
mobile.toCell, mobile.toSubCell, target.CenterPosition, range, self);
|
mobile.ToCell, mobile.ToSubCell, target.CenterPosition, range, self);
|
||||||
};
|
};
|
||||||
|
|
||||||
destination = null;
|
destination = null;
|
||||||
@@ -134,7 +134,7 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
|
|
||||||
List<CPos> EvalPath(Actor self, Mobile mobile)
|
List<CPos> EvalPath(Actor self, Mobile mobile)
|
||||||
{
|
{
|
||||||
var path = getPath().TakeWhile(a => a != mobile.toCell).ToList();
|
var path = getPath().TakeWhile(a => a != mobile.ToCell).ToList();
|
||||||
mobile.PathHash = HashList(path);
|
mobile.PathHash = HashList(path);
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
@@ -144,14 +144,14 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
if (moveDisablers.Any(d => d.MoveDisabled(self)))
|
if (moveDisablers.Any(d => d.MoveDisabled(self)))
|
||||||
return this;
|
return this;
|
||||||
|
|
||||||
if (destination == mobile.toCell)
|
if (destination == mobile.ToCell)
|
||||||
return NextActivity;
|
return NextActivity;
|
||||||
|
|
||||||
if (path == null)
|
if (path == null)
|
||||||
{
|
{
|
||||||
if (mobile.ticksBeforePathing > 0)
|
if (mobile.TicksBeforePathing > 0)
|
||||||
{
|
{
|
||||||
--mobile.ticksBeforePathing;
|
--mobile.TicksBeforePathing;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -161,7 +161,7 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
|
|
||||||
if (path.Count == 0)
|
if (path.Count == 0)
|
||||||
{
|
{
|
||||||
destination = mobile.toCell;
|
destination = mobile.ToCell;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -171,7 +171,7 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
if (nextCell == null)
|
if (nextCell == null)
|
||||||
return this;
|
return this;
|
||||||
|
|
||||||
var firstFacing = self.World.Map.FacingBetween(mobile.fromCell, nextCell.Value.First, mobile.Facing);
|
var firstFacing = self.World.Map.FacingBetween(mobile.FromCell, nextCell.Value.First, mobile.Facing);
|
||||||
if (firstFacing != mobile.Facing)
|
if (firstFacing != mobile.Facing)
|
||||||
{
|
{
|
||||||
path.Add(nextCell.Value.First);
|
path.Add(nextCell.Value.First);
|
||||||
@@ -179,11 +179,11 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
}
|
}
|
||||||
else
|
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(
|
var move = new MoveFirstHalf(
|
||||||
this,
|
this,
|
||||||
self.World.Map.CenterOfSubCell(mobile.fromCell, mobile.fromSubCell),
|
self.World.Map.CenterOfSubCell(mobile.FromCell, mobile.FromSubCell),
|
||||||
Util.BetweenCells(self.World, mobile.fromCell, mobile.toCell) + (self.World.Map.OffsetOfSubCell(mobile.fromSubCell) + self.World.Map.OffsetOfSubCell(mobile.toSubCell)) / 2,
|
Util.BetweenCells(self.World, mobile.FromCell, mobile.ToCell) + (self.World.Map.OffsetOfSubCell(mobile.FromSubCell) + self.World.Map.OffsetOfSubCell(mobile.ToSubCell)) / 2,
|
||||||
mobile.Facing,
|
mobile.Facing,
|
||||||
mobile.Facing,
|
mobile.Facing,
|
||||||
0);
|
0);
|
||||||
@@ -197,7 +197,7 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
{
|
{
|
||||||
if (path.Count == 0)
|
if (path.Count == 0)
|
||||||
return;
|
return;
|
||||||
var d = path[path.Count - 1] - mobile.toCell;
|
var d = path[path.Count - 1] - mobile.ToCell;
|
||||||
if (d.LengthSquared > 2)
|
if (d.LengthSquared > 2)
|
||||||
throw new InvalidOperationException("(Move) Sanity check failed");
|
throw new InvalidOperationException("(Move) Sanity check failed");
|
||||||
}
|
}
|
||||||
@@ -224,7 +224,7 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
{
|
{
|
||||||
// Are we close enough?
|
// Are we close enough?
|
||||||
var cellRange = nearEnough.Range / 1024;
|
var cellRange = nearEnough.Range / 1024;
|
||||||
if ((mobile.toCell - destination.Value).LengthSquared <= cellRange * cellRange)
|
if ((mobile.ToCell - destination.Value).LengthSquared <= cellRange * cellRange)
|
||||||
{
|
{
|
||||||
path.Clear();
|
path.Clear();
|
||||||
return null;
|
return null;
|
||||||
@@ -248,9 +248,9 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
if (--waitTicksRemaining >= 0)
|
if (--waitTicksRemaining >= 0)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
if (mobile.ticksBeforePathing > 0)
|
if (mobile.TicksBeforePathing > 0)
|
||||||
{
|
{
|
||||||
--mobile.ticksBeforePathing;
|
--mobile.TicksBeforePathing;
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -290,42 +290,42 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
|
|
||||||
abstract class MovePart : Activity
|
abstract class MovePart : Activity
|
||||||
{
|
{
|
||||||
protected readonly Move move;
|
protected readonly Move Move;
|
||||||
protected readonly WPos from, to;
|
protected readonly WPos From, To;
|
||||||
protected readonly int fromFacing, toFacing;
|
protected readonly int FromFacing, ToFacing;
|
||||||
protected readonly int moveFractionTotal;
|
protected readonly int MoveFractionTotal;
|
||||||
protected int moveFraction;
|
protected int moveFraction;
|
||||||
|
|
||||||
public MovePart(Move move, WPos from, WPos to, int fromFacing, int toFacing, int startingFraction)
|
public MovePart(Move move, WPos from, WPos to, int fromFacing, int toFacing, int startingFraction)
|
||||||
{
|
{
|
||||||
this.move = move;
|
Move = move;
|
||||||
this.from = from;
|
From = from;
|
||||||
this.to = to;
|
To = to;
|
||||||
this.fromFacing = fromFacing;
|
FromFacing = fromFacing;
|
||||||
this.toFacing = toFacing;
|
ToFacing = toFacing;
|
||||||
this.moveFraction = startingFraction;
|
moveFraction = startingFraction;
|
||||||
this.moveFractionTotal = (to - from).Length;
|
MoveFractionTotal = (to - from).Length;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Cancel(Actor self)
|
public override void Cancel(Actor self)
|
||||||
{
|
{
|
||||||
move.Cancel(self);
|
Move.Cancel(self);
|
||||||
base.Cancel(self);
|
base.Cancel(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Queue(Activity activity)
|
public override void Queue(Activity activity)
|
||||||
{
|
{
|
||||||
move.Queue(activity);
|
Move.Queue(activity);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Activity Tick(Actor self)
|
public override Activity Tick(Actor self)
|
||||||
{
|
{
|
||||||
var mobile = self.Trait<Mobile>();
|
var mobile = self.Trait<Mobile>();
|
||||||
var ret = InnerTick(self, move.mobile);
|
var ret = InnerTick(self, Move.mobile);
|
||||||
mobile.IsMoving = ret is MovePart;
|
mobile.IsMoving = ret is MovePart;
|
||||||
|
|
||||||
if (moveFraction > moveFractionTotal)
|
if (moveFraction > MoveFractionTotal)
|
||||||
moveFraction = moveFractionTotal;
|
moveFraction = MoveFractionTotal;
|
||||||
UpdateCenterLocation(self, mobile);
|
UpdateCenterLocation(self, mobile);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
@@ -333,36 +333,36 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
|
|
||||||
Activity InnerTick(Actor self, Mobile mobile)
|
Activity InnerTick(Actor self, Mobile mobile)
|
||||||
{
|
{
|
||||||
moveFraction += mobile.MovementSpeedForCell(self, mobile.toCell);
|
moveFraction += mobile.MovementSpeedForCell(self, mobile.ToCell);
|
||||||
if (moveFraction <= moveFractionTotal)
|
if (moveFraction <= MoveFractionTotal)
|
||||||
return this;
|
return this;
|
||||||
|
|
||||||
var next = OnComplete(self, mobile, move);
|
var next = OnComplete(self, mobile, Move);
|
||||||
if (next != null)
|
if (next != null)
|
||||||
return next;
|
return next;
|
||||||
|
|
||||||
return move;
|
return Move;
|
||||||
}
|
}
|
||||||
|
|
||||||
void UpdateCenterLocation(Actor self, Mobile mobile)
|
void UpdateCenterLocation(Actor self, Mobile mobile)
|
||||||
{
|
{
|
||||||
// avoid division through zero
|
// avoid division through zero
|
||||||
if (moveFractionTotal != 0)
|
if (MoveFractionTotal != 0)
|
||||||
mobile.SetVisualPosition(self, WPos.Lerp(from, to, moveFraction, moveFractionTotal));
|
mobile.SetVisualPosition(self, WPos.Lerp(From, To, moveFraction, MoveFractionTotal));
|
||||||
else
|
else
|
||||||
mobile.SetVisualPosition(self, to);
|
mobile.SetVisualPosition(self, To);
|
||||||
|
|
||||||
if (moveFraction >= moveFractionTotal)
|
if (moveFraction >= MoveFractionTotal)
|
||||||
mobile.Facing = toFacing & 0xFF;
|
mobile.Facing = ToFacing & 0xFF;
|
||||||
else
|
else
|
||||||
mobile.Facing = int2.Lerp(fromFacing, toFacing, moveFraction, moveFractionTotal) & 0xFF;
|
mobile.Facing = int2.Lerp(FromFacing, ToFacing, moveFraction, MoveFractionTotal) & 0xFF;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract MovePart OnComplete(Actor self, Mobile mobile, Move parent);
|
protected abstract MovePart OnComplete(Actor self, Mobile mobile, Move parent);
|
||||||
|
|
||||||
public override IEnumerable<Target> GetTargets(Actor self)
|
public override IEnumerable<Target> GetTargets(Actor self)
|
||||||
{
|
{
|
||||||
return move.GetTargets(self);
|
return Move.GetTargets(self);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -373,14 +373,14 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
|
|
||||||
static bool IsTurn(Mobile mobile, CPos nextCell)
|
static bool IsTurn(Mobile mobile, CPos nextCell)
|
||||||
{
|
{
|
||||||
return nextCell - mobile.toCell !=
|
return nextCell - mobile.ToCell !=
|
||||||
mobile.toCell - mobile.fromCell;
|
mobile.ToCell - mobile.FromCell;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override MovePart OnComplete(Actor self, Mobile mobile, Move parent)
|
protected override MovePart OnComplete(Actor self, Mobile mobile, Move parent)
|
||||||
{
|
{
|
||||||
var fromSubcellOffset = self.World.Map.OffsetOfSubCell(mobile.fromSubCell);
|
var fromSubcellOffset = self.World.Map.OffsetOfSubCell(mobile.FromSubCell);
|
||||||
var toSubcellOffset = self.World.Map.OffsetOfSubCell(mobile.toSubCell);
|
var toSubcellOffset = self.World.Map.OffsetOfSubCell(mobile.ToSubCell);
|
||||||
|
|
||||||
var nextCell = parent.PopPath(self, mobile);
|
var nextCell = parent.PopPath(self, mobile);
|
||||||
if (nextCell != null)
|
if (nextCell != null)
|
||||||
@@ -389,15 +389,15 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
{
|
{
|
||||||
var nextSubcellOffset = self.World.Map.OffsetOfSubCell(nextCell.Value.Second);
|
var nextSubcellOffset = self.World.Map.OffsetOfSubCell(nextCell.Value.Second);
|
||||||
var ret = new MoveFirstHalf(
|
var ret = new MoveFirstHalf(
|
||||||
move,
|
Move,
|
||||||
Util.BetweenCells(self.World, mobile.fromCell, mobile.toCell) + (fromSubcellOffset + toSubcellOffset) / 2,
|
Util.BetweenCells(self.World, mobile.FromCell, mobile.ToCell) + (fromSubcellOffset + toSubcellOffset) / 2,
|
||||||
Util.BetweenCells(self.World, mobile.toCell, nextCell.Value.First) + (toSubcellOffset + nextSubcellOffset) / 2,
|
Util.BetweenCells(self.World, mobile.ToCell, nextCell.Value.First) + (toSubcellOffset + nextSubcellOffset) / 2,
|
||||||
mobile.Facing,
|
mobile.Facing,
|
||||||
Util.GetNearestFacing(mobile.Facing, self.World.Map.FacingBetween(mobile.toCell, nextCell.Value.First, mobile.Facing)),
|
Util.GetNearestFacing(mobile.Facing, self.World.Map.FacingBetween(mobile.ToCell, nextCell.Value.First, mobile.Facing)),
|
||||||
moveFraction - moveFractionTotal);
|
moveFraction - MoveFractionTotal);
|
||||||
|
|
||||||
mobile.FinishedMoving(self);
|
mobile.FinishedMoving(self);
|
||||||
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;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -405,15 +405,15 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
}
|
}
|
||||||
|
|
||||||
var ret2 = new MoveSecondHalf(
|
var ret2 = new MoveSecondHalf(
|
||||||
move,
|
Move,
|
||||||
Util.BetweenCells(self.World, mobile.fromCell, mobile.toCell) + (fromSubcellOffset + toSubcellOffset) / 2,
|
Util.BetweenCells(self.World, mobile.FromCell, mobile.ToCell) + (fromSubcellOffset + toSubcellOffset) / 2,
|
||||||
self.World.Map.CenterOfCell(mobile.toCell) + toSubcellOffset,
|
self.World.Map.CenterOfCell(mobile.ToCell) + toSubcellOffset,
|
||||||
mobile.Facing,
|
mobile.Facing,
|
||||||
mobile.Facing,
|
mobile.Facing,
|
||||||
moveFraction - moveFractionTotal);
|
moveFraction - MoveFractionTotal);
|
||||||
|
|
||||||
mobile.EnteringCell(self);
|
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;
|
return ret2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -425,7 +425,7 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
|
|
||||||
protected override MovePart OnComplete(Actor self, Mobile mobile, Move parent)
|
protected override MovePart OnComplete(Actor self, Mobile mobile, Move parent)
|
||||||
{
|
{
|
||||||
mobile.SetPosition(self, mobile.toCell);
|
mobile.SetPosition(self, mobile.ToCell);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,14 +26,14 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
readonly DomainIndex domainIndex;
|
readonly DomainIndex domainIndex;
|
||||||
readonly uint movementClass;
|
readonly uint movementClass;
|
||||||
|
|
||||||
protected Target target { get; private set; }
|
protected Target Target { get; private set; }
|
||||||
protected CPos targetPosition;
|
protected CPos targetPosition;
|
||||||
Activity inner;
|
Activity inner;
|
||||||
bool repath;
|
bool repath;
|
||||||
|
|
||||||
public MoveAdjacentTo(Actor self, Target target)
|
public MoveAdjacentTo(Actor self, Target target)
|
||||||
{
|
{
|
||||||
this.target = target;
|
Target = target;
|
||||||
|
|
||||||
mobile = self.Trait<Mobile>();
|
mobile = self.Trait<Mobile>();
|
||||||
pathFinder = self.World.WorldActor.Trait<PathFinder>();
|
pathFinder = self.World.WorldActor.Trait<PathFinder>();
|
||||||
@@ -58,12 +58,12 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
|
|
||||||
protected virtual IEnumerable<CPos> CandidateMovementCells(Actor self)
|
protected virtual IEnumerable<CPos> CandidateMovementCells(Actor self)
|
||||||
{
|
{
|
||||||
return Util.AdjacentCells(self.World, target);
|
return Util.AdjacentCells(self.World, Target);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Activity Tick(Actor self)
|
public override Activity Tick(Actor self)
|
||||||
{
|
{
|
||||||
var targetIsValid = target.IsValidFor(self);
|
var targetIsValid = Target.IsValidFor(self);
|
||||||
|
|
||||||
// Inner move order has completed.
|
// Inner move order has completed.
|
||||||
if (inner == null)
|
if (inner == null)
|
||||||
@@ -82,7 +82,7 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
{
|
{
|
||||||
// Check if the target has moved
|
// Check if the target has moved
|
||||||
var oldTargetPosition = targetPosition;
|
var oldTargetPosition = targetPosition;
|
||||||
targetPosition = self.World.Map.CellContaining(target.CenterPosition);
|
targetPosition = self.World.Map.CellContaining(Target.CenterPosition);
|
||||||
|
|
||||||
var shouldStop = ShouldStop(self, oldTargetPosition);
|
var shouldStop = ShouldStop(self, oldTargetPosition);
|
||||||
if (shouldStop || (!repath && ShouldRepath(self, oldTargetPosition)))
|
if (shouldStop || (!repath && ShouldRepath(self, oldTargetPosition)))
|
||||||
@@ -97,7 +97,7 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Target became invalid. Move to its last known position.
|
// Target became invalid. Move to its last known position.
|
||||||
target = Target.FromCell(self.World, targetPosition);
|
Target = Target.FromCell(self.World, targetPosition);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ticks the inner move activity to actually move the actor.
|
// Ticks the inner move activity to actually move the actor.
|
||||||
|
|||||||
@@ -33,13 +33,13 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
// We are now in range. Don't move any further!
|
// We are now in range. Don't move any further!
|
||||||
// HACK: This works around the pathfinder not returning the shortest path
|
// HACK: This works around the pathfinder not returning the shortest path
|
||||||
var cp = self.CenterPosition;
|
var cp = self.CenterPosition;
|
||||||
return target.IsInRange(cp, maxRange) && !target.IsInRange(cp, minRange);
|
return Target.IsInRange(cp, maxRange) && !Target.IsInRange(cp, minRange);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override bool ShouldRepath(Actor self, CPos oldTargetPosition)
|
protected override bool ShouldRepath(Actor self, CPos oldTargetPosition)
|
||||||
{
|
{
|
||||||
var cp = self.CenterPosition;
|
var cp = self.CenterPosition;
|
||||||
return targetPosition != oldTargetPosition && (!target.IsInRange(cp, maxRange) || target.IsInRange(cp, minRange));
|
return targetPosition != oldTargetPosition && (!Target.IsInRange(cp, maxRange) || Target.IsInRange(cp, minRange));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override IEnumerable<CPos> CandidateMovementCells(Actor self)
|
protected override IEnumerable<CPos> CandidateMovementCells(Actor self)
|
||||||
@@ -50,7 +50,7 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
|
|
||||||
var outerSq = maxRange.Range * maxRange.Range;
|
var outerSq = maxRange.Range * maxRange.Range;
|
||||||
var innerSq = minRange.Range * minRange.Range;
|
var innerSq = minRange.Range * minRange.Range;
|
||||||
var center = target.CenterPosition;
|
var center = Target.CenterPosition;
|
||||||
|
|
||||||
return map.FindTilesInAnnulus(targetPosition, minCells + 1, maxCells).Where(c =>
|
return map.FindTilesInAnnulus(targetPosition, minCells + 1, maxCells).Where(c =>
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -61,9 +61,9 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
public readonly WeaponInfo Weapon;
|
public readonly WeaponInfo Weapon;
|
||||||
public readonly Barrel[] Barrels;
|
public readonly Barrel[] Barrels;
|
||||||
|
|
||||||
public readonly Actor self;
|
readonly Actor self;
|
||||||
Lazy<Turreted> Turret;
|
Lazy<Turreted> turret;
|
||||||
Lazy<IBodyOrientation> Coords;
|
Lazy<IBodyOrientation> coords;
|
||||||
Lazy<LimitedAmmo> limitedAmmo;
|
Lazy<LimitedAmmo> limitedAmmo;
|
||||||
List<Pair<int, Action>> delayedActions = new List<Pair<int, Action>>();
|
List<Pair<int, Action>> delayedActions = new List<Pair<int, Action>>();
|
||||||
|
|
||||||
@@ -77,8 +77,8 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
this.self = self;
|
this.self = self;
|
||||||
|
|
||||||
// We can't resolve these until runtime
|
// We can't resolve these until runtime
|
||||||
Turret = Exts.Lazy(() => self.TraitsImplementing<Turreted>().FirstOrDefault(t => t.Name == info.Turret));
|
turret = Exts.Lazy(() => self.TraitsImplementing<Turreted>().FirstOrDefault(t => t.Name == info.Turret));
|
||||||
Coords = Exts.Lazy(() => self.Trait<IBodyOrientation>());
|
coords = Exts.Lazy(() => self.Trait<IBodyOrientation>());
|
||||||
limitedAmmo = Exts.Lazy(() => self.TraitOrDefault<LimitedAmmo>());
|
limitedAmmo = Exts.Lazy(() => self.TraitOrDefault<LimitedAmmo>());
|
||||||
|
|
||||||
Weapon = self.World.Map.Rules.Weapons[info.Weapon.ToLowerInvariant()];
|
Weapon = self.World.Map.Rules.Weapons[info.Weapon.ToLowerInvariant()];
|
||||||
@@ -205,23 +205,23 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
public WVec MuzzleOffset(Actor self, Barrel b)
|
public WVec MuzzleOffset(Actor self, Barrel b)
|
||||||
{
|
{
|
||||||
var bodyOrientation = Coords.Value.QuantizeOrientation(self, self.Orientation);
|
var bodyOrientation = coords.Value.QuantizeOrientation(self, self.Orientation);
|
||||||
var localOffset = b.Offset + new WVec(-Recoil, WRange.Zero, WRange.Zero);
|
var localOffset = b.Offset + new WVec(-Recoil, WRange.Zero, WRange.Zero);
|
||||||
if (Turret.Value != null)
|
if (turret.Value != null)
|
||||||
{
|
{
|
||||||
var turretOrientation = Coords.Value.QuantizeOrientation(self, Turret.Value.LocalOrientation(self));
|
var turretOrientation = coords.Value.QuantizeOrientation(self, turret.Value.LocalOrientation(self));
|
||||||
localOffset = localOffset.Rotate(turretOrientation);
|
localOffset = localOffset.Rotate(turretOrientation);
|
||||||
localOffset += Turret.Value.Offset;
|
localOffset += turret.Value.Offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Coords.Value.LocalToWorld(localOffset.Rotate(bodyOrientation));
|
return coords.Value.LocalToWorld(localOffset.Rotate(bodyOrientation));
|
||||||
}
|
}
|
||||||
|
|
||||||
public WRot MuzzleOrientation(Actor self, Barrel b)
|
public WRot MuzzleOrientation(Actor self, Barrel b)
|
||||||
{
|
{
|
||||||
var orientation = self.Orientation + WRot.FromYaw(b.Yaw);
|
var orientation = self.Orientation + WRot.FromYaw(b.Yaw);
|
||||||
if (Turret.Value != null)
|
if (turret.Value != null)
|
||||||
orientation += Turret.Value.LocalOrientation(self);
|
orientation += turret.Value.LocalOrientation(self);
|
||||||
return orientation;
|
return orientation;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -34,19 +34,19 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
public class LimitedAmmo : INotifyAttack, IPips, ISync
|
public class LimitedAmmo : INotifyAttack, IPips, ISync
|
||||||
{
|
{
|
||||||
[Sync] int ammo;
|
[Sync] int ammo;
|
||||||
LimitedAmmoInfo Info;
|
LimitedAmmoInfo info;
|
||||||
|
|
||||||
public LimitedAmmo(LimitedAmmoInfo info)
|
public LimitedAmmo(LimitedAmmoInfo info)
|
||||||
{
|
{
|
||||||
ammo = info.Ammo;
|
ammo = info.Ammo;
|
||||||
Info = info;
|
this.info = info;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool FullAmmo() { return ammo == Info.Ammo; }
|
public bool FullAmmo() { return ammo == info.Ammo; }
|
||||||
public bool HasAmmo() { return ammo > 0; }
|
public bool HasAmmo() { return ammo > 0; }
|
||||||
public bool GiveAmmo()
|
public bool GiveAmmo()
|
||||||
{
|
{
|
||||||
if (ammo >= Info.Ammo) return false;
|
if (ammo >= info.Ammo) return false;
|
||||||
++ammo;
|
++ammo;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -58,7 +58,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int ReloadTimePerAmmo() { return Info.ReloadTicks; }
|
public int ReloadTimePerAmmo() { return info.ReloadTicks; }
|
||||||
|
|
||||||
public void Attacking(Actor self, Target target, Armament a, Barrel barrel) { TakeAmmo(); }
|
public void Attacking(Actor self, Target target, Armament a, Barrel barrel) { TakeAmmo(); }
|
||||||
|
|
||||||
@@ -66,10 +66,10 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
public IEnumerable<PipType> GetPips(Actor self)
|
public IEnumerable<PipType> GetPips(Actor self)
|
||||||
{
|
{
|
||||||
var pips = Info.PipCount != 0 ? Info.PipCount : Info.Ammo;
|
var pips = info.PipCount != 0 ? info.PipCount : info.Ammo;
|
||||||
return Enumerable.Range(0, pips).Select(i =>
|
return Enumerable.Range(0, pips).Select(i =>
|
||||||
(ammo * pips) / Info.Ammo > i ?
|
(ammo * pips) / info.Ammo > i ?
|
||||||
Info.PipType : Info.PipTypeEmpty);
|
info.PipType : info.PipTypeEmpty);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -159,7 +159,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
if (otherMobile == null) return false;
|
if (otherMobile == null) return false;
|
||||||
|
|
||||||
// Sign of dot-product indicates (roughly) if vectors are facing in same or opposite directions:
|
// Sign of dot-product indicates (roughly) if vectors are facing in same or opposite directions:
|
||||||
var dp = CVec.Dot(selfMobile.toCell - self.Location, otherMobile.toCell - other.Location);
|
var dp = CVec.Dot(selfMobile.ToCell - self.Location, otherMobile.ToCell - other.Location);
|
||||||
if (dp <= 0) return false;
|
if (dp <= 0) return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -249,60 +249,60 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
public class Mobile : IIssueOrder, IResolveOrder, IOrderVoice, IPositionable, IMove, IFacing, ISync, INotifyAddedToWorld, INotifyRemovedFromWorld, INotifyBlockingMove
|
public class Mobile : IIssueOrder, IResolveOrder, IOrderVoice, IPositionable, IMove, IFacing, ISync, INotifyAddedToWorld, INotifyRemovedFromWorld, INotifyBlockingMove
|
||||||
{
|
{
|
||||||
public readonly Actor self;
|
const int AverageTicksBeforePathing = 5;
|
||||||
|
const int SpreadTicksBeforePathing = 5;
|
||||||
|
internal int TicksBeforePathing = 0;
|
||||||
|
|
||||||
|
readonly Actor self;
|
||||||
public readonly MobileInfo Info;
|
public readonly MobileInfo Info;
|
||||||
public bool IsMoving { get; set; }
|
public bool IsMoving { get; set; }
|
||||||
|
|
||||||
int __facing;
|
int facing;
|
||||||
CPos __fromCell, __toCell;
|
CPos fromCell, toCell;
|
||||||
public SubCell fromSubCell, toSubCell;
|
public SubCell FromSubCell, ToSubCell;
|
||||||
|
|
||||||
[Sync] public int Facing
|
[Sync] public int Facing
|
||||||
{
|
{
|
||||||
get { return __facing; }
|
get { return facing; }
|
||||||
set { __facing = value; }
|
set { facing = value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public int ROT { get { return Info.ROT; } }
|
public int ROT { get { return Info.ROT; } }
|
||||||
|
|
||||||
[Sync] public WPos CenterPosition { get; private set; }
|
[Sync] public WPos CenterPosition { get; private set; }
|
||||||
[Sync] public CPos fromCell { get { return __fromCell; } }
|
[Sync] public CPos FromCell { get { return fromCell; } }
|
||||||
[Sync] public CPos toCell { get { return __toCell; } }
|
[Sync] public CPos ToCell { get { return toCell; } }
|
||||||
|
|
||||||
[Sync] public int PathHash; // written by Move.EvalPath, to temporarily debug this crap.
|
[Sync] public int PathHash; // written by Move.EvalPath, to temporarily debug this crap.
|
||||||
|
|
||||||
public void SetLocation(CPos from, SubCell fromSub, CPos to, SubCell toSub)
|
public void SetLocation(CPos from, SubCell fromSub, CPos to, SubCell toSub)
|
||||||
{
|
{
|
||||||
if (fromCell == from && toCell == to && fromSubCell == fromSub && toSubCell == toSub)
|
if (FromCell == from && ToCell == to && FromSubCell == fromSub && ToSubCell == toSub)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
RemoveInfluence();
|
RemoveInfluence();
|
||||||
__fromCell = from;
|
fromCell = from;
|
||||||
__toCell = to;
|
toCell = to;
|
||||||
fromSubCell = fromSub;
|
FromSubCell = fromSub;
|
||||||
toSubCell = toSub;
|
ToSubCell = toSub;
|
||||||
AddInfluence();
|
AddInfluence();
|
||||||
}
|
}
|
||||||
|
|
||||||
const int avgTicksBeforePathing = 5;
|
|
||||||
const int spreadTicksBeforePathing = 5;
|
|
||||||
internal int ticksBeforePathing = 0;
|
|
||||||
|
|
||||||
public Mobile(ActorInitializer init, MobileInfo info)
|
public Mobile(ActorInitializer init, MobileInfo info)
|
||||||
{
|
{
|
||||||
this.self = init.self;
|
self = init.self;
|
||||||
this.Info = info;
|
Info = info;
|
||||||
|
|
||||||
toSubCell = fromSubCell = info.SharesCell ? init.world.Map.DefaultSubCell : SubCell.FullCell;
|
ToSubCell = FromSubCell = info.SharesCell ? init.world.Map.DefaultSubCell : SubCell.FullCell;
|
||||||
if (init.Contains<SubCellInit>())
|
if (init.Contains<SubCellInit>())
|
||||||
{
|
{
|
||||||
this.fromSubCell = this.toSubCell = init.Get<SubCellInit, SubCell>();
|
this.FromSubCell = this.ToSubCell = init.Get<SubCellInit, SubCell>();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (init.Contains<LocationInit>())
|
if (init.Contains<LocationInit>())
|
||||||
{
|
{
|
||||||
this.__fromCell = this.__toCell = init.Get<LocationInit, CPos>();
|
this.fromCell = this.toCell = init.Get<LocationInit, CPos>();
|
||||||
SetVisualPosition(self, init.world.Map.CenterOfSubCell(fromCell, fromSubCell));
|
SetVisualPosition(self, init.world.Map.CenterOfSubCell(FromCell, FromSubCell));
|
||||||
}
|
}
|
||||||
|
|
||||||
this.Facing = init.Contains<FacingInit>() ? init.Get<FacingInit, int>() : info.InitialFacing;
|
this.Facing = init.Contains<FacingInit>() ? init.Get<FacingInit, int>() : info.InitialFacing;
|
||||||
@@ -318,7 +318,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
{
|
{
|
||||||
// Try same sub-cell
|
// Try same sub-cell
|
||||||
if (preferred == SubCell.Any)
|
if (preferred == SubCell.Any)
|
||||||
preferred = fromSubCell;
|
preferred = FromSubCell;
|
||||||
|
|
||||||
// Fix sub-cell assignment
|
// Fix sub-cell assignment
|
||||||
if (Info.SharesCell)
|
if (Info.SharesCell)
|
||||||
@@ -346,7 +346,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
public void SetPosition(Actor self, WPos pos)
|
public void SetPosition(Actor self, WPos pos)
|
||||||
{
|
{
|
||||||
var cell = self.World.Map.CellContaining(pos);
|
var cell = self.World.Map.CellContaining(pos);
|
||||||
SetLocation(cell, fromSubCell, cell, fromSubCell);
|
SetLocation(cell, FromSubCell, cell, FromSubCell);
|
||||||
SetVisualPosition(self, pos);
|
SetVisualPosition(self, pos);
|
||||||
FinishedMoving(self);
|
FinishedMoving(self);
|
||||||
}
|
}
|
||||||
@@ -435,7 +435,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
if (!queued) self.CancelActivity();
|
if (!queued) self.CancelActivity();
|
||||||
|
|
||||||
ticksBeforePathing = avgTicksBeforePathing + self.World.SharedRandom.Next(-spreadTicksBeforePathing, spreadTicksBeforePathing);
|
TicksBeforePathing = AverageTicksBeforePathing + self.World.SharedRandom.Next(-SpreadTicksBeforePathing, SpreadTicksBeforePathing);
|
||||||
|
|
||||||
self.QueueActivity(new Move(self, currentLocation, 8));
|
self.QueueActivity(new Move(self, currentLocation, 8));
|
||||||
|
|
||||||
@@ -481,21 +481,21 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public CPos TopLeft { get { return toCell; } }
|
public CPos TopLeft { get { return ToCell; } }
|
||||||
|
|
||||||
public IEnumerable<Pair<CPos, SubCell>> OccupiedCells()
|
public IEnumerable<Pair<CPos, SubCell>> OccupiedCells()
|
||||||
{
|
{
|
||||||
if (fromCell == toCell)
|
if (FromCell == ToCell)
|
||||||
return new[] { Pair.New(fromCell, fromSubCell) };
|
return new[] { Pair.New(FromCell, FromSubCell) };
|
||||||
if (CanEnterCell(toCell))
|
if (CanEnterCell(ToCell))
|
||||||
return new[] { Pair.New(toCell, toSubCell) };
|
return new[] { Pair.New(ToCell, ToSubCell) };
|
||||||
return new[] { Pair.New(fromCell, fromSubCell), Pair.New(toCell, toSubCell) };
|
return new[] { Pair.New(FromCell, FromSubCell), Pair.New(ToCell, ToSubCell) };
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool IsLeavingCell(CPos location, SubCell subCell = SubCell.Any)
|
public bool IsLeavingCell(CPos location, SubCell subCell = SubCell.Any)
|
||||||
{
|
{
|
||||||
return toCell != location && __fromCell == location
|
return ToCell != location && fromCell == location
|
||||||
&& (subCell == SubCell.Any || fromSubCell == subCell || subCell == SubCell.FullCell || fromSubCell == SubCell.FullCell);
|
&& (subCell == SubCell.Any || FromSubCell == subCell || subCell == SubCell.FullCell || FromSubCell == SubCell.FullCell);
|
||||||
}
|
}
|
||||||
|
|
||||||
public SubCell GetAvailableSubCell(CPos a, SubCell preferredSubCell = SubCell.Any, Actor ignoreActor = null, bool checkTransientActors = true)
|
public SubCell GetAvailableSubCell(CPos a, SubCell preferredSubCell = SubCell.Any, Actor ignoreActor = null, bool checkTransientActors = true)
|
||||||
@@ -510,7 +510,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
public void EnteringCell(Actor self)
|
public void EnteringCell(Actor self)
|
||||||
{
|
{
|
||||||
var crushables = self.World.ActorMap.GetUnitsAt(toCell).Where(a => a != self)
|
var crushables = self.World.ActorMap.GetUnitsAt(ToCell).Where(a => a != self)
|
||||||
.SelectMany(a => a.TraitsImplementing<ICrushable>().Where(b => b.CrushableBy(Info.Crushes, self.Owner)));
|
.SelectMany(a => a.TraitsImplementing<ICrushable>().Where(b => b.CrushableBy(Info.Crushes, self.Owner)));
|
||||||
foreach (var crushable in crushables)
|
foreach (var crushable in crushables)
|
||||||
crushable.WarnCrush(self);
|
crushable.WarnCrush(self);
|
||||||
@@ -518,7 +518,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
public void FinishedMoving(Actor self)
|
public void FinishedMoving(Actor self)
|
||||||
{
|
{
|
||||||
var crushables = self.World.ActorMap.GetUnitsAt(toCell).Where(a => a != self)
|
var crushables = self.World.ActorMap.GetUnitsAt(ToCell).Where(a => a != self)
|
||||||
.SelectMany(a => a.TraitsImplementing<ICrushable>().Where(c => c.CrushableBy(Info.Crushes, self.Owner)));
|
.SelectMany(a => a.TraitsImplementing<ICrushable>().Where(c => c.CrushableBy(Info.Crushes, self.Owner)));
|
||||||
foreach (var crushable in crushables)
|
foreach (var crushable in crushables)
|
||||||
crushable.OnCrush(self);
|
crushable.OnCrush(self);
|
||||||
@@ -571,11 +571,11 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
for (var i = -1; i < 2; i++)
|
for (var i = -1; i < 2; i++)
|
||||||
for (var j = -1; j < 2; j++)
|
for (var j = -1; j < 2; j++)
|
||||||
{
|
{
|
||||||
var p = toCell + new CVec(i, j);
|
var p = ToCell + new CVec(i, j);
|
||||||
if (CanEnterCell(p))
|
if (CanEnterCell(p))
|
||||||
availCells.Add(p);
|
availCells.Add(p);
|
||||||
else
|
else
|
||||||
if (p != nudger.Location && p != toCell)
|
if (p != nudger.Location && p != ToCell)
|
||||||
notStupidCells.Add(p);
|
notStupidCells.Add(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -28,13 +28,13 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
public class Reloads : ITick
|
public class Reloads : ITick
|
||||||
{
|
{
|
||||||
[Sync] int remainingTicks;
|
[Sync] int remainingTicks;
|
||||||
ReloadsInfo Info;
|
ReloadsInfo info;
|
||||||
LimitedAmmo la;
|
LimitedAmmo la;
|
||||||
int previousAmmo;
|
int previousAmmo;
|
||||||
|
|
||||||
public Reloads(Actor self, ReloadsInfo info)
|
public Reloads(Actor self, ReloadsInfo info)
|
||||||
{
|
{
|
||||||
Info = info;
|
this.info = info;
|
||||||
remainingTicks = info.Period;
|
remainingTicks = info.Period;
|
||||||
la = self.Trait<LimitedAmmo>();
|
la = self.Trait<LimitedAmmo>();
|
||||||
previousAmmo = la.GetAmmoCount();
|
previousAmmo = la.GetAmmoCount();
|
||||||
@@ -44,18 +44,18 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
{
|
{
|
||||||
if (!la.FullAmmo() && --remainingTicks == 0)
|
if (!la.FullAmmo() && --remainingTicks == 0)
|
||||||
{
|
{
|
||||||
remainingTicks = Info.Period;
|
remainingTicks = info.Period;
|
||||||
|
|
||||||
for (var i = 0; i < Info.Count; i++)
|
for (var i = 0; i < info.Count; i++)
|
||||||
la.GiveAmmo();
|
la.GiveAmmo();
|
||||||
|
|
||||||
previousAmmo = la.GetAmmoCount();
|
previousAmmo = la.GetAmmoCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Resets the tick counter if ammo was fired.
|
// Resets the tick counter if ammo was fired.
|
||||||
if (Info.ResetOnFire && la.GetAmmoCount() < previousAmmo)
|
if (info.ResetOnFire && la.GetAmmoCount() < previousAmmo)
|
||||||
{
|
{
|
||||||
remainingTicks = Info.Period;
|
remainingTicks = info.Period;
|
||||||
previousAmmo = la.GetAmmoCount();
|
previousAmmo = la.GetAmmoCount();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,33 +28,33 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
public class PathFinder
|
public class PathFinder
|
||||||
{
|
{
|
||||||
const int MaxPathAge = 50; /* x 40ms ticks */
|
const int MaxPathAge = 50; /* x 40ms ticks */
|
||||||
static readonly List<CPos> emptyPath = new List<CPos>(0);
|
static readonly List<CPos> EmptyPath = new List<CPos>(0);
|
||||||
|
|
||||||
readonly World world;
|
readonly World world;
|
||||||
public PathFinder(World world) { this.world = world; }
|
public PathFinder(World world) { this.world = world; }
|
||||||
|
|
||||||
class CachedPath
|
class CachedPath
|
||||||
{
|
{
|
||||||
public CPos from;
|
public CPos From;
|
||||||
public CPos to;
|
public CPos To;
|
||||||
public List<CPos> result;
|
public List<CPos> Result;
|
||||||
public int tick;
|
public int Tick;
|
||||||
public Actor actor;
|
public Actor Actor;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<CachedPath> CachedPaths = new List<CachedPath>();
|
List<CachedPath> cachedPaths = new List<CachedPath>();
|
||||||
|
|
||||||
public List<CPos> FindUnitPath(CPos from, CPos target, Actor self)
|
public List<CPos> FindUnitPath(CPos from, CPos target, Actor self)
|
||||||
{
|
{
|
||||||
using (new PerfSample("Pathfinder"))
|
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)
|
||||||
{
|
{
|
||||||
Log.Write("debug", "Actor {0} asked for a path from {1} tick(s) ago", self.ActorID, world.WorldTick - cached.tick);
|
Log.Write("debug", "Actor {0} asked for a path from {1} tick(s) ago", self.ActorID, world.WorldTick - cached.Tick);
|
||||||
if (world.WorldTick - cached.tick > MaxPathAge)
|
if (world.WorldTick - cached.Tick > MaxPathAge)
|
||||||
CachedPaths.Remove(cached);
|
cachedPaths.Remove(cached);
|
||||||
return new List<CPos>(cached.result);
|
return new List<CPos>(cached.Result);
|
||||||
}
|
}
|
||||||
|
|
||||||
var mi = self.Info.Traits.Get<MobileInfo>();
|
var mi = self.Info.Traits.Get<MobileInfo>();
|
||||||
@@ -65,7 +65,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
{
|
{
|
||||||
var passable = mi.GetMovementClass(world.TileSet);
|
var passable = mi.GetMovementClass(world.TileSet);
|
||||||
if (!domainIndex.IsPassable(from, target, (uint)passable))
|
if (!domainIndex.IsPassable(from, target, (uint)passable))
|
||||||
return emptyPath;
|
return EmptyPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
var fromPoint = PathSearch.FromPoint(world, mi, self, target, from, true)
|
var fromPoint = PathSearch.FromPoint(world, mi, self, target, from, true)
|
||||||
@@ -79,8 +79,8 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
CheckSanePath2(pb, from, target);
|
CheckSanePath2(pb, from, target);
|
||||||
|
|
||||||
CachedPaths.RemoveAll(p => world.WorldTick - p.tick > MaxPathAge);
|
cachedPaths.RemoveAll(p => world.WorldTick - p.Tick > MaxPathAge);
|
||||||
CachedPaths.Add(new CachedPath { from = from, to = target, actor = self, result = pb, tick = world.WorldTick });
|
cachedPaths.Add(new CachedPath { From = from, To = target, Actor = self, Result = pb, Tick = world.WorldTick });
|
||||||
return new List<CPos>(pb);
|
return new List<CPos>(pb);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -110,7 +110,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
var passable = mi.GetMovementClass(world.TileSet);
|
var passable = mi.GetMovementClass(world.TileSet);
|
||||||
tilesInRange = new List<CPos>(tilesInRange.Where(t => domainIndex.IsPassable(src, t, (uint)passable)));
|
tilesInRange = new List<CPos>(tilesInRange.Where(t => domainIndex.IsPassable(src, t, (uint)passable)));
|
||||||
if (!tilesInRange.Any())
|
if (!tilesInRange.Any())
|
||||||
return emptyPath;
|
return EmptyPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
var path = FindBidiPath(
|
var path = FindBidiPath(
|
||||||
@@ -148,7 +148,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
}
|
}
|
||||||
|
|
||||||
// no path exists
|
// no path exists
|
||||||
return emptyPath;
|
return EmptyPath;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -212,7 +212,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
return emptyPath;
|
return EmptyPath;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -143,7 +143,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
// For horizontal/vertical directions, the set is the three cells 'ahead'. For diagonal directions, the set
|
// For horizontal/vertical directions, the set is the three cells 'ahead'. For diagonal directions, the set
|
||||||
// is the three cells ahead, plus the two cells to the side, which we cannot exclude without knowing if
|
// is the three cells ahead, plus the two cells to the side, which we cannot exclude without knowing if
|
||||||
// the cell directly between them and our parent is passable.
|
// the cell directly between them and our parent is passable.
|
||||||
static CVec[][] DirectedNeighbors = {
|
static CVec[][] directedNeighbors = {
|
||||||
new CVec[] { new CVec(-1, -1), new CVec(0, -1), new CVec(1, -1), new CVec(-1, 0), new CVec(-1, 1) },
|
new CVec[] { new CVec(-1, -1), new CVec(0, -1), new CVec(1, -1), new CVec(-1, 0), new CVec(-1, 1) },
|
||||||
new CVec[] { new CVec(-1, -1), new CVec(0, -1), new CVec(1, -1) },
|
new CVec[] { new CVec(-1, -1), new CVec(0, -1), new CVec(1, -1) },
|
||||||
new CVec[] { new CVec(-1, -1), new CVec(0, -1), new CVec(1, -1), new CVec(1, 0), new CVec(1, 1) },
|
new CVec[] { new CVec(-1, -1), new CVec(0, -1), new CVec(1, -1), new CVec(1, 0), new CVec(1, 1) },
|
||||||
@@ -161,7 +161,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
var dy = p.Y - prev.Y;
|
var dy = p.Y - prev.Y;
|
||||||
var index = dy * 3 + dx + 4;
|
var index = dy * 3 + dx + 4;
|
||||||
|
|
||||||
return DirectedNeighbors[index];
|
return directedNeighbors[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
public CPos Expand(World world)
|
public CPos Expand(World world)
|
||||||
@@ -285,7 +285,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
}
|
}
|
||||||
|
|
||||||
static readonly Queue<CellLayer<CellInfo>> CellInfoPool = new Queue<CellLayer<CellInfo>>();
|
static readonly Queue<CellLayer<CellInfo>> CellInfoPool = new Queue<CellLayer<CellInfo>>();
|
||||||
static readonly object defaultCellInfoLayerSync = new object();
|
static readonly object DefaultCellInfoLayerSync = new object();
|
||||||
static CellLayer<CellInfo> defaultCellInfoLayer;
|
static CellLayer<CellInfo> defaultCellInfoLayer;
|
||||||
|
|
||||||
static CellLayer<CellInfo> GetFromPool()
|
static CellLayer<CellInfo> GetFromPool()
|
||||||
@@ -325,7 +325,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
if (result == null)
|
if (result == null)
|
||||||
result = new CellLayer<CellInfo>(map);
|
result = new CellLayer<CellInfo>(map);
|
||||||
|
|
||||||
lock (defaultCellInfoLayerSync)
|
lock (DefaultCellInfoLayerSync)
|
||||||
{
|
{
|
||||||
if (defaultCellInfoLayer == null ||
|
if (defaultCellInfoLayer == null ||
|
||||||
defaultCellInfoLayer.Size != mapSize ||
|
defaultCellInfoLayer.Size != mapSize ||
|
||||||
|
|||||||
@@ -8,8 +8,8 @@
|
|||||||
*/
|
*/
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
using OpenRA.Mods.D2k.Activities;
|
|
||||||
using OpenRA.Mods.Common.Traits;
|
using OpenRA.Mods.Common.Traits;
|
||||||
|
using OpenRA.Mods.D2k.Activities;
|
||||||
using OpenRA.Traits;
|
using OpenRA.Traits;
|
||||||
|
|
||||||
namespace OpenRA.Mods.D2k.Traits
|
namespace OpenRA.Mods.D2k.Traits
|
||||||
|
|||||||
@@ -39,9 +39,9 @@ namespace OpenRA.Mods.RA.Activities
|
|||||||
}
|
}
|
||||||
|
|
||||||
var mobile = self.Trait<Mobile>();
|
var mobile = self.Trait<Mobile>();
|
||||||
var nearest = target.Actor.OccupiesSpace.NearestCellTo(mobile.toCell);
|
var nearest = target.Actor.OccupiesSpace.NearestCellTo(mobile.ToCell);
|
||||||
|
|
||||||
if ((nearest - mobile.toCell).LengthSquared > 2)
|
if ((nearest - mobile.ToCell).LengthSquared > 2)
|
||||||
return Util.SequenceActivities(new MoveAdjacentTo(self, target), this);
|
return Util.SequenceActivities(new MoveAdjacentTo(self, target), this);
|
||||||
|
|
||||||
if (!capturable.CaptureInProgress)
|
if (!capturable.CaptureInProgress)
|
||||||
|
|||||||
@@ -38,11 +38,11 @@ namespace OpenRA.Mods.RA.Activities
|
|||||||
this.weapon = weapon;
|
this.weapon = weapon;
|
||||||
this.angle = angle;
|
this.angle = angle;
|
||||||
mobile = self.Trait<Mobile>();
|
mobile = self.Trait<Mobile>();
|
||||||
mobile.SetLocation(mobile.fromCell, mobile.fromSubCell, targetMobile.fromCell, targetMobile.fromSubCell);
|
mobile.SetLocation(mobile.FromCell, mobile.FromSubCell, targetMobile.FromCell, targetMobile.FromSubCell);
|
||||||
mobile.IsMoving = true;
|
mobile.IsMoving = true;
|
||||||
|
|
||||||
from = self.CenterPosition;
|
from = self.CenterPosition;
|
||||||
to = self.World.Map.CenterOfSubCell(targetMobile.fromCell, targetMobile.fromSubCell);
|
to = self.World.Map.CenterOfSubCell(targetMobile.FromCell, targetMobile.FromSubCell);
|
||||||
length = Math.Max((to - from).Length / speed.Range, 1);
|
length = Math.Max((to - from).Length / speed.Range, 1);
|
||||||
|
|
||||||
self.Trait<RenderInfantry>().Attacking(self, Target.FromActor(target));
|
self.Trait<RenderInfantry>().Attacking(self, Target.FromActor(target));
|
||||||
@@ -59,11 +59,11 @@ namespace OpenRA.Mods.RA.Activities
|
|||||||
mobile.SetVisualPosition(self, WPos.LerpQuadratic(from, to, angle, ++ticks, length));
|
mobile.SetVisualPosition(self, WPos.LerpQuadratic(from, to, angle, ++ticks, length));
|
||||||
if (ticks >= length)
|
if (ticks >= length)
|
||||||
{
|
{
|
||||||
mobile.SetLocation(mobile.toCell, mobile.toSubCell, mobile.toCell, mobile.toSubCell);
|
mobile.SetLocation(mobile.ToCell, mobile.ToSubCell, mobile.ToCell, mobile.ToSubCell);
|
||||||
mobile.FinishedMoving(self);
|
mobile.FinishedMoving(self);
|
||||||
mobile.IsMoving = false;
|
mobile.IsMoving = false;
|
||||||
|
|
||||||
self.World.ActorMap.GetUnitsAt(mobile.toCell, mobile.toSubCell)
|
self.World.ActorMap.GetUnitsAt(mobile.ToCell, mobile.ToSubCell)
|
||||||
.Except(new[] { self }).Where(t => weapon.IsValidAgainst(t, self))
|
.Except(new[] { self }).Where(t => weapon.IsValidAgainst(t, self))
|
||||||
.Do(t => t.Kill(self));
|
.Do(t => t.Kill(self));
|
||||||
|
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ namespace OpenRA.Mods.RA.Scripting
|
|||||||
[Desc("Moves from outside the world into the cell grid")]
|
[Desc("Moves from outside the world into the cell grid")]
|
||||||
public void MoveIntoWorld(CPos cell)
|
public void MoveIntoWorld(CPos cell)
|
||||||
{
|
{
|
||||||
self.QueueActivity(mobile.MoveIntoWorld(self, cell, mobile.toSubCell));
|
self.QueueActivity(mobile.MoveIntoWorld(self, cell, mobile.ToSubCell));
|
||||||
}
|
}
|
||||||
|
|
||||||
[ScriptActorPropertyActivity]
|
[ScriptActorPropertyActivity]
|
||||||
|
|||||||
Reference in New Issue
Block a user