StyleCop fixes
This commit is contained in:
@@ -46,7 +46,7 @@ namespace OpenRA.Mods.Common.Activities
|
||||
|
||||
getPath = () =>
|
||||
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());
|
||||
this.destination = destination;
|
||||
this.nearEnough = WRange.Zero;
|
||||
@@ -62,7 +62,7 @@ namespace OpenRA.Mods.Common.Activities
|
||||
moveDisablers = self.TraitsImplementing<IDisableMove>();
|
||||
|
||||
getPath = () => self.World.WorldActor.Trait<PathFinder>()
|
||||
.FindUnitPath(mobile.toCell, destination, self);
|
||||
.FindUnitPath(mobile.ToCell, destination, self);
|
||||
this.destination = destination;
|
||||
this.nearEnough = nearEnough;
|
||||
}
|
||||
@@ -73,7 +73,7 @@ namespace OpenRA.Mods.Common.Activities
|
||||
moveDisablers = self.TraitsImplementing<IDisableMove>();
|
||||
|
||||
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.nearEnough = nearEnough;
|
||||
}
|
||||
@@ -85,7 +85,7 @@ namespace OpenRA.Mods.Common.Activities
|
||||
|
||||
getPath = () =>
|
||||
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));
|
||||
|
||||
this.destination = destination;
|
||||
@@ -104,7 +104,7 @@ namespace OpenRA.Mods.Common.Activities
|
||||
return NoPath;
|
||||
|
||||
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;
|
||||
@@ -134,7 +134,7 @@ namespace OpenRA.Mods.Common.Activities
|
||||
|
||||
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);
|
||||
return path;
|
||||
}
|
||||
@@ -144,14 +144,14 @@ namespace OpenRA.Mods.Common.Activities
|
||||
if (moveDisablers.Any(d => d.MoveDisabled(self)))
|
||||
return this;
|
||||
|
||||
if (destination == mobile.toCell)
|
||||
if (destination == mobile.ToCell)
|
||||
return NextActivity;
|
||||
|
||||
if (path == null)
|
||||
{
|
||||
if (mobile.ticksBeforePathing > 0)
|
||||
if (mobile.TicksBeforePathing > 0)
|
||||
{
|
||||
--mobile.ticksBeforePathing;
|
||||
--mobile.TicksBeforePathing;
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -161,7 +161,7 @@ namespace OpenRA.Mods.Common.Activities
|
||||
|
||||
if (path.Count == 0)
|
||||
{
|
||||
destination = mobile.toCell;
|
||||
destination = mobile.ToCell;
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -171,7 +171,7 @@ namespace OpenRA.Mods.Common.Activities
|
||||
if (nextCell == null)
|
||||
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)
|
||||
{
|
||||
path.Add(nextCell.Value.First);
|
||||
@@ -179,11 +179,11 @@ namespace OpenRA.Mods.Common.Activities
|
||||
}
|
||||
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,
|
||||
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,
|
||||
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,
|
||||
mobile.Facing,
|
||||
mobile.Facing,
|
||||
0);
|
||||
@@ -197,7 +197,7 @@ namespace OpenRA.Mods.Common.Activities
|
||||
{
|
||||
if (path.Count == 0)
|
||||
return;
|
||||
var d = path[path.Count - 1] - mobile.toCell;
|
||||
var d = path[path.Count - 1] - mobile.ToCell;
|
||||
if (d.LengthSquared > 2)
|
||||
throw new InvalidOperationException("(Move) Sanity check failed");
|
||||
}
|
||||
@@ -224,7 +224,7 @@ namespace OpenRA.Mods.Common.Activities
|
||||
{
|
||||
// Are we close enough?
|
||||
var cellRange = nearEnough.Range / 1024;
|
||||
if ((mobile.toCell - destination.Value).LengthSquared <= cellRange * cellRange)
|
||||
if ((mobile.ToCell - destination.Value).LengthSquared <= cellRange * cellRange)
|
||||
{
|
||||
path.Clear();
|
||||
return null;
|
||||
@@ -248,9 +248,9 @@ namespace OpenRA.Mods.Common.Activities
|
||||
if (--waitTicksRemaining >= 0)
|
||||
return null;
|
||||
|
||||
if (mobile.ticksBeforePathing > 0)
|
||||
if (mobile.TicksBeforePathing > 0)
|
||||
{
|
||||
--mobile.ticksBeforePathing;
|
||||
--mobile.TicksBeforePathing;
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -290,42 +290,42 @@ namespace OpenRA.Mods.Common.Activities
|
||||
|
||||
abstract class MovePart : Activity
|
||||
{
|
||||
protected readonly Move move;
|
||||
protected readonly WPos from, to;
|
||||
protected readonly int fromFacing, toFacing;
|
||||
protected readonly int moveFractionTotal;
|
||||
protected readonly Move Move;
|
||||
protected readonly WPos From, To;
|
||||
protected readonly int FromFacing, ToFacing;
|
||||
protected readonly int MoveFractionTotal;
|
||||
protected int moveFraction;
|
||||
|
||||
public MovePart(Move move, WPos from, WPos to, int fromFacing, int toFacing, int startingFraction)
|
||||
{
|
||||
this.move = move;
|
||||
this.from = from;
|
||||
this.to = to;
|
||||
this.fromFacing = fromFacing;
|
||||
this.toFacing = toFacing;
|
||||
this.moveFraction = startingFraction;
|
||||
this.moveFractionTotal = (to - from).Length;
|
||||
Move = move;
|
||||
From = from;
|
||||
To = to;
|
||||
FromFacing = fromFacing;
|
||||
ToFacing = toFacing;
|
||||
moveFraction = startingFraction;
|
||||
MoveFractionTotal = (to - from).Length;
|
||||
}
|
||||
|
||||
public override void Cancel(Actor self)
|
||||
{
|
||||
move.Cancel(self);
|
||||
Move.Cancel(self);
|
||||
base.Cancel(self);
|
||||
}
|
||||
|
||||
public override void Queue(Activity activity)
|
||||
{
|
||||
move.Queue(activity);
|
||||
Move.Queue(activity);
|
||||
}
|
||||
|
||||
public override Activity Tick(Actor self)
|
||||
{
|
||||
var mobile = self.Trait<Mobile>();
|
||||
var ret = InnerTick(self, move.mobile);
|
||||
var ret = InnerTick(self, Move.mobile);
|
||||
mobile.IsMoving = ret is MovePart;
|
||||
|
||||
if (moveFraction > moveFractionTotal)
|
||||
moveFraction = moveFractionTotal;
|
||||
if (moveFraction > MoveFractionTotal)
|
||||
moveFraction = MoveFractionTotal;
|
||||
UpdateCenterLocation(self, mobile);
|
||||
|
||||
return ret;
|
||||
@@ -333,36 +333,36 @@ namespace OpenRA.Mods.Common.Activities
|
||||
|
||||
Activity InnerTick(Actor self, Mobile mobile)
|
||||
{
|
||||
moveFraction += mobile.MovementSpeedForCell(self, mobile.toCell);
|
||||
if (moveFraction <= moveFractionTotal)
|
||||
moveFraction += mobile.MovementSpeedForCell(self, mobile.ToCell);
|
||||
if (moveFraction <= MoveFractionTotal)
|
||||
return this;
|
||||
|
||||
var next = OnComplete(self, mobile, move);
|
||||
var next = OnComplete(self, mobile, Move);
|
||||
if (next != null)
|
||||
return next;
|
||||
|
||||
return move;
|
||||
return Move;
|
||||
}
|
||||
|
||||
void UpdateCenterLocation(Actor self, Mobile mobile)
|
||||
{
|
||||
// avoid division through zero
|
||||
if (moveFractionTotal != 0)
|
||||
mobile.SetVisualPosition(self, WPos.Lerp(from, to, moveFraction, moveFractionTotal));
|
||||
if (MoveFractionTotal != 0)
|
||||
mobile.SetVisualPosition(self, WPos.Lerp(From, To, moveFraction, MoveFractionTotal));
|
||||
else
|
||||
mobile.SetVisualPosition(self, to);
|
||||
mobile.SetVisualPosition(self, To);
|
||||
|
||||
if (moveFraction >= moveFractionTotal)
|
||||
mobile.Facing = toFacing & 0xFF;
|
||||
if (moveFraction >= MoveFractionTotal)
|
||||
mobile.Facing = ToFacing & 0xFF;
|
||||
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);
|
||||
|
||||
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)
|
||||
{
|
||||
return nextCell - mobile.toCell !=
|
||||
mobile.toCell - mobile.fromCell;
|
||||
return nextCell - mobile.ToCell !=
|
||||
mobile.ToCell - mobile.FromCell;
|
||||
}
|
||||
|
||||
protected override MovePart OnComplete(Actor self, Mobile mobile, Move parent)
|
||||
{
|
||||
var fromSubcellOffset = self.World.Map.OffsetOfSubCell(mobile.fromSubCell);
|
||||
var toSubcellOffset = self.World.Map.OffsetOfSubCell(mobile.toSubCell);
|
||||
var fromSubcellOffset = self.World.Map.OffsetOfSubCell(mobile.FromSubCell);
|
||||
var toSubcellOffset = self.World.Map.OffsetOfSubCell(mobile.ToSubCell);
|
||||
|
||||
var nextCell = parent.PopPath(self, mobile);
|
||||
if (nextCell != null)
|
||||
@@ -389,15 +389,15 @@ namespace OpenRA.Mods.Common.Activities
|
||||
{
|
||||
var nextSubcellOffset = self.World.Map.OffsetOfSubCell(nextCell.Value.Second);
|
||||
var ret = new MoveFirstHalf(
|
||||
move,
|
||||
Util.BetweenCells(self.World, mobile.fromCell, mobile.toCell) + (fromSubcellOffset + toSubcellOffset) / 2,
|
||||
Util.BetweenCells(self.World, mobile.toCell, nextCell.Value.First) + (toSubcellOffset + nextSubcellOffset) / 2,
|
||||
Move,
|
||||
Util.BetweenCells(self.World, mobile.FromCell, mobile.ToCell) + (fromSubcellOffset + toSubcellOffset) / 2,
|
||||
Util.BetweenCells(self.World, mobile.ToCell, nextCell.Value.First) + (toSubcellOffset + nextSubcellOffset) / 2,
|
||||
mobile.Facing,
|
||||
Util.GetNearestFacing(mobile.Facing, self.World.Map.FacingBetween(mobile.toCell, nextCell.Value.First, mobile.Facing)),
|
||||
moveFraction - moveFractionTotal);
|
||||
Util.GetNearestFacing(mobile.Facing, self.World.Map.FacingBetween(mobile.ToCell, nextCell.Value.First, mobile.Facing)),
|
||||
moveFraction - MoveFractionTotal);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -405,15 +405,15 @@ namespace OpenRA.Mods.Common.Activities
|
||||
}
|
||||
|
||||
var ret2 = new MoveSecondHalf(
|
||||
move,
|
||||
Util.BetweenCells(self.World, mobile.fromCell, mobile.toCell) + (fromSubcellOffset + toSubcellOffset) / 2,
|
||||
self.World.Map.CenterOfCell(mobile.toCell) + toSubcellOffset,
|
||||
Move,
|
||||
Util.BetweenCells(self.World, mobile.FromCell, mobile.ToCell) + (fromSubcellOffset + toSubcellOffset) / 2,
|
||||
self.World.Map.CenterOfCell(mobile.ToCell) + toSubcellOffset,
|
||||
mobile.Facing,
|
||||
mobile.Facing,
|
||||
moveFraction - moveFractionTotal);
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -425,7 +425,7 @@ namespace OpenRA.Mods.Common.Activities
|
||||
|
||||
protected override MovePart OnComplete(Actor self, Mobile mobile, Move parent)
|
||||
{
|
||||
mobile.SetPosition(self, mobile.toCell);
|
||||
mobile.SetPosition(self, mobile.ToCell);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,14 +26,14 @@ namespace OpenRA.Mods.Common.Activities
|
||||
readonly DomainIndex domainIndex;
|
||||
readonly uint movementClass;
|
||||
|
||||
protected Target target { get; private set; }
|
||||
protected Target Target { get; private set; }
|
||||
protected CPos targetPosition;
|
||||
Activity inner;
|
||||
bool repath;
|
||||
|
||||
public MoveAdjacentTo(Actor self, Target target)
|
||||
{
|
||||
this.target = target;
|
||||
Target = target;
|
||||
|
||||
mobile = self.Trait<Mobile>();
|
||||
pathFinder = self.World.WorldActor.Trait<PathFinder>();
|
||||
@@ -58,12 +58,12 @@ namespace OpenRA.Mods.Common.Activities
|
||||
|
||||
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)
|
||||
{
|
||||
var targetIsValid = target.IsValidFor(self);
|
||||
var targetIsValid = Target.IsValidFor(self);
|
||||
|
||||
// Inner move order has completed.
|
||||
if (inner == null)
|
||||
@@ -82,7 +82,7 @@ namespace OpenRA.Mods.Common.Activities
|
||||
{
|
||||
// Check if the target has moved
|
||||
var oldTargetPosition = targetPosition;
|
||||
targetPosition = self.World.Map.CellContaining(target.CenterPosition);
|
||||
targetPosition = self.World.Map.CellContaining(Target.CenterPosition);
|
||||
|
||||
var shouldStop = ShouldStop(self, oldTargetPosition);
|
||||
if (shouldStop || (!repath && ShouldRepath(self, oldTargetPosition)))
|
||||
@@ -97,7 +97,7 @@ namespace OpenRA.Mods.Common.Activities
|
||||
else
|
||||
{
|
||||
// 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.
|
||||
|
||||
@@ -33,13 +33,13 @@ namespace OpenRA.Mods.Common.Activities
|
||||
// We are now in range. Don't move any further!
|
||||
// HACK: This works around the pathfinder not returning the shortest path
|
||||
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)
|
||||
{
|
||||
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)
|
||||
@@ -50,7 +50,7 @@ namespace OpenRA.Mods.Common.Activities
|
||||
|
||||
var outerSq = maxRange.Range * maxRange.Range;
|
||||
var innerSq = minRange.Range * minRange.Range;
|
||||
var center = target.CenterPosition;
|
||||
var center = Target.CenterPosition;
|
||||
|
||||
return map.FindTilesInAnnulus(targetPosition, minCells + 1, maxCells).Where(c =>
|
||||
{
|
||||
|
||||
@@ -61,9 +61,9 @@ namespace OpenRA.Mods.Common.Traits
|
||||
public readonly WeaponInfo Weapon;
|
||||
public readonly Barrel[] Barrels;
|
||||
|
||||
public readonly Actor self;
|
||||
Lazy<Turreted> Turret;
|
||||
Lazy<IBodyOrientation> Coords;
|
||||
readonly Actor self;
|
||||
Lazy<Turreted> turret;
|
||||
Lazy<IBodyOrientation> coords;
|
||||
Lazy<LimitedAmmo> limitedAmmo;
|
||||
List<Pair<int, Action>> delayedActions = new List<Pair<int, Action>>();
|
||||
|
||||
@@ -77,8 +77,8 @@ namespace OpenRA.Mods.Common.Traits
|
||||
this.self = self;
|
||||
|
||||
// We can't resolve these until runtime
|
||||
Turret = Exts.Lazy(() => self.TraitsImplementing<Turreted>().FirstOrDefault(t => t.Name == info.Turret));
|
||||
Coords = Exts.Lazy(() => self.Trait<IBodyOrientation>());
|
||||
turret = Exts.Lazy(() => self.TraitsImplementing<Turreted>().FirstOrDefault(t => t.Name == info.Turret));
|
||||
coords = Exts.Lazy(() => self.Trait<IBodyOrientation>());
|
||||
limitedAmmo = Exts.Lazy(() => self.TraitOrDefault<LimitedAmmo>());
|
||||
|
||||
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)
|
||||
{
|
||||
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);
|
||||
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 += 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)
|
||||
{
|
||||
var orientation = self.Orientation + WRot.FromYaw(b.Yaw);
|
||||
if (Turret.Value != null)
|
||||
orientation += Turret.Value.LocalOrientation(self);
|
||||
if (turret.Value != null)
|
||||
orientation += turret.Value.LocalOrientation(self);
|
||||
return orientation;
|
||||
}
|
||||
|
||||
|
||||
@@ -34,19 +34,19 @@ namespace OpenRA.Mods.Common.Traits
|
||||
public class LimitedAmmo : INotifyAttack, IPips, ISync
|
||||
{
|
||||
[Sync] int ammo;
|
||||
LimitedAmmoInfo Info;
|
||||
LimitedAmmoInfo info;
|
||||
|
||||
public LimitedAmmo(LimitedAmmoInfo info)
|
||||
{
|
||||
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 GiveAmmo()
|
||||
{
|
||||
if (ammo >= Info.Ammo) return false;
|
||||
if (ammo >= info.Ammo) return false;
|
||||
++ammo;
|
||||
return true;
|
||||
}
|
||||
@@ -58,7 +58,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
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(); }
|
||||
|
||||
@@ -66,10 +66,10 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
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 =>
|
||||
(ammo * pips) / Info.Ammo > i ?
|
||||
Info.PipType : Info.PipTypeEmpty);
|
||||
(ammo * pips) / info.Ammo > i ?
|
||||
info.PipType : info.PipTypeEmpty);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -159,7 +159,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (otherMobile == null) return false;
|
||||
|
||||
// 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;
|
||||
|
||||
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 readonly Actor self;
|
||||
const int AverageTicksBeforePathing = 5;
|
||||
const int SpreadTicksBeforePathing = 5;
|
||||
internal int TicksBeforePathing = 0;
|
||||
|
||||
readonly Actor self;
|
||||
public readonly MobileInfo Info;
|
||||
public bool IsMoving { get; set; }
|
||||
|
||||
int __facing;
|
||||
CPos __fromCell, __toCell;
|
||||
public SubCell fromSubCell, toSubCell;
|
||||
int facing;
|
||||
CPos fromCell, toCell;
|
||||
public SubCell FromSubCell, ToSubCell;
|
||||
|
||||
[Sync] public int Facing
|
||||
{
|
||||
get { return __facing; }
|
||||
set { __facing = value; }
|
||||
get { return facing; }
|
||||
set { facing = value; }
|
||||
}
|
||||
|
||||
public int ROT { get { return Info.ROT; } }
|
||||
|
||||
[Sync] public WPos CenterPosition { get; private set; }
|
||||
[Sync] public CPos fromCell { get { return __fromCell; } }
|
||||
[Sync] public CPos toCell { get { return __toCell; } }
|
||||
[Sync] public CPos FromCell { get { return fromCell; } }
|
||||
[Sync] public CPos ToCell { get { return toCell; } }
|
||||
|
||||
[Sync] public int PathHash; // written by Move.EvalPath, to temporarily debug this crap.
|
||||
|
||||
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;
|
||||
|
||||
RemoveInfluence();
|
||||
__fromCell = from;
|
||||
__toCell = to;
|
||||
fromSubCell = fromSub;
|
||||
toSubCell = toSub;
|
||||
fromCell = from;
|
||||
toCell = to;
|
||||
FromSubCell = fromSub;
|
||||
ToSubCell = toSub;
|
||||
AddInfluence();
|
||||
}
|
||||
|
||||
const int avgTicksBeforePathing = 5;
|
||||
const int spreadTicksBeforePathing = 5;
|
||||
internal int ticksBeforePathing = 0;
|
||||
|
||||
public Mobile(ActorInitializer init, MobileInfo info)
|
||||
{
|
||||
this.self = init.self;
|
||||
this.Info = info;
|
||||
self = init.self;
|
||||
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>())
|
||||
{
|
||||
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, CPos>();
|
||||
SetVisualPosition(self, init.world.Map.CenterOfSubCell(fromCell, fromSubCell));
|
||||
this.fromCell = this.toCell = init.Get<LocationInit, CPos>();
|
||||
SetVisualPosition(self, init.world.Map.CenterOfSubCell(FromCell, FromSubCell));
|
||||
}
|
||||
|
||||
this.Facing = init.Contains<FacingInit>() ? init.Get<FacingInit, int>() : info.InitialFacing;
|
||||
@@ -318,7 +318,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
// Try same sub-cell
|
||||
if (preferred == SubCell.Any)
|
||||
preferred = fromSubCell;
|
||||
preferred = FromSubCell;
|
||||
|
||||
// Fix sub-cell assignment
|
||||
if (Info.SharesCell)
|
||||
@@ -346,7 +346,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
public void SetPosition(Actor self, WPos pos)
|
||||
{
|
||||
var cell = self.World.Map.CellContaining(pos);
|
||||
SetLocation(cell, fromSubCell, cell, fromSubCell);
|
||||
SetLocation(cell, FromSubCell, cell, FromSubCell);
|
||||
SetVisualPosition(self, pos);
|
||||
FinishedMoving(self);
|
||||
}
|
||||
@@ -435,7 +435,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
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));
|
||||
|
||||
@@ -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()
|
||||
{
|
||||
if (fromCell == toCell)
|
||||
return new[] { Pair.New(fromCell, fromSubCell) };
|
||||
if (CanEnterCell(toCell))
|
||||
return new[] { Pair.New(toCell, toSubCell) };
|
||||
return new[] { Pair.New(fromCell, fromSubCell), Pair.New(toCell, toSubCell) };
|
||||
if (FromCell == ToCell)
|
||||
return new[] { Pair.New(FromCell, FromSubCell) };
|
||||
if (CanEnterCell(ToCell))
|
||||
return new[] { Pair.New(ToCell, ToSubCell) };
|
||||
return new[] { Pair.New(FromCell, FromSubCell), Pair.New(ToCell, ToSubCell) };
|
||||
}
|
||||
|
||||
public bool IsLeavingCell(CPos location, SubCell subCell = SubCell.Any)
|
||||
{
|
||||
return toCell != location && __fromCell == location
|
||||
&& (subCell == SubCell.Any || fromSubCell == subCell || subCell == SubCell.FullCell || fromSubCell == SubCell.FullCell);
|
||||
return ToCell != location && fromCell == location
|
||||
&& (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)
|
||||
@@ -510,7 +510,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
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)));
|
||||
foreach (var crushable in crushables)
|
||||
crushable.WarnCrush(self);
|
||||
@@ -518,7 +518,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
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)));
|
||||
foreach (var crushable in crushables)
|
||||
crushable.OnCrush(self);
|
||||
@@ -571,11 +571,11 @@ namespace OpenRA.Mods.Common.Traits
|
||||
for (var i = -1; i < 2; i++)
|
||||
for (var j = -1; j < 2; j++)
|
||||
{
|
||||
var p = toCell + new CVec(i, j);
|
||||
var p = ToCell + new CVec(i, j);
|
||||
if (CanEnterCell(p))
|
||||
availCells.Add(p);
|
||||
else
|
||||
if (p != nudger.Location && p != toCell)
|
||||
if (p != nudger.Location && p != ToCell)
|
||||
notStupidCells.Add(p);
|
||||
}
|
||||
|
||||
|
||||
@@ -28,13 +28,13 @@ namespace OpenRA.Mods.Common.Traits
|
||||
public class Reloads : ITick
|
||||
{
|
||||
[Sync] int remainingTicks;
|
||||
ReloadsInfo Info;
|
||||
ReloadsInfo info;
|
||||
LimitedAmmo la;
|
||||
int previousAmmo;
|
||||
|
||||
public Reloads(Actor self, ReloadsInfo info)
|
||||
{
|
||||
Info = info;
|
||||
this.info = info;
|
||||
remainingTicks = info.Period;
|
||||
la = self.Trait<LimitedAmmo>();
|
||||
previousAmmo = la.GetAmmoCount();
|
||||
@@ -44,18 +44,18 @@ namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
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();
|
||||
|
||||
previousAmmo = la.GetAmmoCount();
|
||||
}
|
||||
|
||||
// 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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,33 +28,33 @@ namespace OpenRA.Mods.Common.Traits
|
||||
public class PathFinder
|
||||
{
|
||||
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;
|
||||
public PathFinder(World world) { this.world = world; }
|
||||
|
||||
class CachedPath
|
||||
{
|
||||
public CPos from;
|
||||
public CPos to;
|
||||
public List<CPos> result;
|
||||
public int tick;
|
||||
public Actor actor;
|
||||
public CPos From;
|
||||
public CPos To;
|
||||
public List<CPos> Result;
|
||||
public int Tick;
|
||||
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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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)
|
||||
CachedPaths.Remove(cached);
|
||||
return new List<CPos>(cached.result);
|
||||
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)
|
||||
cachedPaths.Remove(cached);
|
||||
return new List<CPos>(cached.Result);
|
||||
}
|
||||
|
||||
var mi = self.Info.Traits.Get<MobileInfo>();
|
||||
@@ -65,7 +65,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
var passable = mi.GetMovementClass(world.TileSet);
|
||||
if (!domainIndex.IsPassable(from, target, (uint)passable))
|
||||
return emptyPath;
|
||||
return EmptyPath;
|
||||
}
|
||||
|
||||
var fromPoint = PathSearch.FromPoint(world, mi, self, target, from, true)
|
||||
@@ -79,8 +79,8 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
CheckSanePath2(pb, from, target);
|
||||
|
||||
CachedPaths.RemoveAll(p => world.WorldTick - p.tick > MaxPathAge);
|
||||
CachedPaths.Add(new CachedPath { from = from, to = target, actor = self, result = pb, tick = world.WorldTick });
|
||||
cachedPaths.RemoveAll(p => world.WorldTick - p.Tick > MaxPathAge);
|
||||
cachedPaths.Add(new CachedPath { From = from, To = target, Actor = self, Result = pb, Tick = world.WorldTick });
|
||||
return new List<CPos>(pb);
|
||||
}
|
||||
}
|
||||
@@ -110,7 +110,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
var passable = mi.GetMovementClass(world.TileSet);
|
||||
tilesInRange = new List<CPos>(tilesInRange.Where(t => domainIndex.IsPassable(src, t, (uint)passable)));
|
||||
if (!tilesInRange.Any())
|
||||
return emptyPath;
|
||||
return EmptyPath;
|
||||
}
|
||||
|
||||
var path = FindBidiPath(
|
||||
@@ -148,7 +148,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
}
|
||||
|
||||
// no path exists
|
||||
return emptyPath;
|
||||
return EmptyPath;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -212,7 +212,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
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
|
||||
// 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.
|
||||
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[] { 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 index = dy * 3 + dx + 4;
|
||||
|
||||
return DirectedNeighbors[index];
|
||||
return directedNeighbors[index];
|
||||
}
|
||||
|
||||
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 object defaultCellInfoLayerSync = new object();
|
||||
static readonly object DefaultCellInfoLayerSync = new object();
|
||||
static CellLayer<CellInfo> defaultCellInfoLayer;
|
||||
|
||||
static CellLayer<CellInfo> GetFromPool()
|
||||
@@ -325,7 +325,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (result == null)
|
||||
result = new CellLayer<CellInfo>(map);
|
||||
|
||||
lock (defaultCellInfoLayerSync)
|
||||
lock (DefaultCellInfoLayerSync)
|
||||
{
|
||||
if (defaultCellInfoLayer == null ||
|
||||
defaultCellInfoLayer.Size != mapSize ||
|
||||
|
||||
Reference in New Issue
Block a user