void UpdateCenterLocation(Actor self, MobileUnderground mobile) { // Avoid division through zero if (MoveFractionTotal != 0) { WPos pos; if (EnableArc) { var angle = WAngle.Lerp(ArcFromAngle, ArcToAngle, moveFraction, MoveFractionTotal); var length = int2.Lerp(ArcFromLength, ArcToLength, moveFraction, MoveFractionTotal); var height = int2.Lerp(From.Z, To.Z, moveFraction, MoveFractionTotal); pos = ArcCenter + new WVec(0, length, height).Rotate(WRot.FromYaw(angle)); } else { pos = WPos.Lerp(From, To, moveFraction, MoveFractionTotal); } mobile.SetVisualPosition(self, pos); } else { mobile.SetVisualPosition(self, To); } if (moveFraction >= MoveFractionTotal) { mobile.Facing = ToFacing & 0xFF; } else { mobile.Facing = int2.Lerp(FromFacing, ToFacing, moveFraction, MoveFractionTotal) & 0xFF; } }
public MoveUnderground(Actor self, CPos destination, SubCell subCell, WDist nearEnough) { mobile = self.Trait <MobileUnderground>(); getPath = () => self.World.WorldActor.Trait <IPathFinder>() .FindUnitPathToRange(mobile.FromCell, subCell, self.World.Map.CenterOfSubCell(destination, subCell), nearEnough, self); this.destination = destination; this.nearEnough = nearEnough; }
public MoveUnderground(Actor self, Func <List <CPos> > getPath) { mobile = self.Trait <MobileUnderground>(); this.getPath = getPath; destination = null; nearEnough = WDist.Zero; }
Activity InnerTick(Actor self, MobileUnderground mobile) { moveFraction += mobile.MovementSpeedForCell(self, mobile.ToCell); if (moveFraction <= MoveFractionTotal) { return(this); } return(OnComplete(self, mobile, Move)); }
void SanityCheckPath(MobileUnderground mobile) { if (path.Count == 0) { return; } var d = path[path.Count - 1] - mobile.ToCell; if (d.LengthSquared > 2) { throw new InvalidOperationException("(Move) Sanity check failed"); } }
// Scriptable move order // Ignores lane bias and nearby units public MoveUnderground(Actor self, CPos destination) { mobile = self.Trait <MobileUnderground>(); getPath = () => { List <CPos> path; using (var search = PathSearch.FromPoint(self.World, mobile.Info.LocomotorInfo, self, mobile.ToCell, destination, false) .WithoutLaneBias()) path = self.World.WorldActor.Trait <IPathFinder>().FindPath(search); return(path); }; this.destination = destination; nearEnough = WDist.Zero; }
protected override MovePart OnComplete(Actor self, MobileUnderground mobile, MoveUnderground parent) { var map = self.World.Map; var fromSubcellOffset = map.Grid.OffsetOfSubCell(mobile.FromSubCell); var toSubcellOffset = map.Grid.OffsetOfSubCell(mobile.ToSubCell); if (!IsCanceled || self.Location.Layer == CustomMovementLayerType.Tunnel) { var nextCell = parent.PopPath(self); if (nextCell != null) { if (IsTurn(mobile, nextCell.Value.First)) { var nextSubcellOffset = map.Grid.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, mobile.Facing, Util.GetNearestFacing(mobile.Facing, 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); return(ret); } parent.path.Add(nextCell.Value.First); } } var toPos = mobile.ToCell.Layer == 0 ? map.CenterOfCell(mobile.ToCell) : self.World.GetCustomMovementLayers()[mobile.ToCell.Layer].CenterOfCell(mobile.ToCell); var ret2 = new MoveSecondHalf( Move, Util.BetweenCells(self.World, mobile.FromCell, mobile.ToCell) + (fromSubcellOffset + toSubcellOffset) / 2, toPos + toSubcellOffset, mobile.Facing, mobile.Facing, moveFraction - MoveFractionTotal); mobile.EnteringCell(self); mobile.SetLocation(mobile.ToCell, mobile.ToSubCell, mobile.ToCell, mobile.ToSubCell); return(ret2); }
public MoveUnderground(Actor self, Target target, WDist range) { mobile = self.Trait <MobileUnderground>(); getPath = () => { if (!target.IsValidFor(self)) { return(NoPath); } return(self.World.WorldActor.Trait <IPathFinder>().FindUnitPathToRange( mobile.ToCell, mobile.ToSubCell, target.CenterPosition, range, self)); }; destination = null; nearEnough = range; }
public MoveUnderground(Actor self, CPos destination, WDist nearEnough, Actor ignoreActor = null, bool evaluateNearestMovableCell = false) { mobile = self.Trait <MobileUnderground>(); getPath = () => { if (!this.destination.HasValue) { return(NoPath); } return(self.World.WorldActor.Trait <IPathFinder>() .FindUnitPath(mobile.ToCell, this.destination.Value, self, ignoreActor)); }; // Note: Will be recalculated from OnFirstRun if evaluateNearestMovableCell is true this.destination = destination; this.nearEnough = nearEnough; this.ignoreActor = ignoreActor; this.evaluateNearestMovableCell = evaluateNearestMovableCell; }
protected override MovePart OnComplete(Actor self, MobileUnderground mobile, MoveUnderground parent) { mobile.SetPosition(self, mobile.ToCell); return(null); }
static bool IsTurn(MobileUnderground mobile, CPos nextCell) { return(nextCell - mobile.ToCell != mobile.ToCell - mobile.FromCell); }
protected abstract MovePart OnComplete(Actor self, MobileUnderground mobile, MoveUnderground parent);