Esempio n. 1
0
        private static bool ShouldNotEnterCell(Pawn pawn, VehicleMapping mapE, IntVec3 dest)
        {
            if (mapE.VehiclePathGrid.PerceivedPathCostAt(dest) > 30)
            {
                return(true);
            }
            if (!GenGridVehicles.Walkable(dest, mapE))
            {
                return(true);
            }
            if (pawn is VehiclePawn)
            {
                if (dest.IsForbidden(pawn))
                {
                    return(true);
                }
                //Add utility for doors later?
            }

            return(false);
        }
Esempio n. 2
0
        public void StartPath(LocalTargetInfo dest, PathEndMode peMode)
        {
            if (!pawn.Drafted)
            {
                PatherFailed();
                return;
            }

            if (pawn.IsBoat())
            {
                dest = (LocalTargetInfo)GenPathVehicles.ResolvePathMode(pawn, dest.ToTargetInfo(pawn.Map), ref peMode);
                if (dest.HasThing && dest.ThingDestroyed)
                {
                    Log.Error(pawn + " pathing to destroyed thing " + dest.Thing);
                    PatherFailed();
                    return;
                }
                //Add Building and Position Recoverable extras
                if (!GenGridVehicles.Walkable(pawn.Position, pawn.Map.GetCachedMapComponent <VehicleMapping>()))
                {
                    return;
                }
                if (Moving && curPath != null && destination == dest && this.peMode == peMode)
                {
                    return;
                }
                if (!pawn.Map.GetCachedMapComponent <VehicleMapping>().VehicleReachability?.CanReachShip(pawn.Position, dest, peMode, TraverseParms.For(TraverseMode.PassDoors, Danger.Deadly, false)) ?? false)
                {
                    PatherFailed();
                    return;
                }
                this.peMode = peMode;
                destination = dest;
                if ((GenGridVehicles.Walkable(nextCell, pawn.Map.GetCachedMapComponent <VehicleMapping>()) || WillCollideWithPawnOnNextPathCell()) || nextCellCostLeft == nextCellCostTotal)
                {
                    ResetToCurrentPosition();
                }
                PawnDestinationReservationManager.PawnDestinationReservation pawnDestinationReservation = pawn.Map.pawnDestinationReservationManager.
                                                                                                          MostRecentReservationFor(pawn);
                if (!(pawnDestinationReservation is null) && ((Destination.HasThing && pawnDestinationReservation.target != Destination.Cell) ||
                                                              (pawnDestinationReservation.job != pawn.CurJob && pawnDestinationReservation.target != Destination.Cell)))
                {
                    pawn.Map.pawnDestinationReservationManager.ObsoleteAllClaimedBy(pawn);
                }
                if (VehicleReachabilityImmediate.CanReachImmediateShip(pawn, dest, peMode))
                {
                    PatherArrived();
                    return;
                }
                if (curPath != null)
                {
                    curPath.ReleaseToPool();
                }
                curPath           = null;
                moving            = true;
                pawn.jobs.posture = PawnPosture.Standing;

                return;
            }
            else
            {
                dest = (LocalTargetInfo)GenPath.ResolvePathMode(pawn, dest.ToTargetInfo(pawn.Map), ref peMode);
                if (dest.HasThing && dest.ThingDestroyed)
                {
                    Log.Error(pawn + " pathing to destroyed thing " + dest.Thing);
                    PatherFailed();
                    return;
                }
                if (!PawnCanOccupy(pawn.Position) && !TryRecoverFromUnwalkablePosition(true))
                {
                    return;
                }
                if (moving && curPath != null && destination == dest && this.peMode == peMode)
                {
                    return;
                }
                if (!pawn.Map.reachability.CanReach(pawn.Position, dest, peMode, TraverseParms.For(TraverseMode.PassDoors, Danger.Deadly, false)))
                {
                    PatherFailed();
                    return;
                }
                this.peMode = peMode;
                destination = dest;
                if (!IsNextCellWalkable() || NextCellDoorToWaitForOrManuallyOpen() != null || nextCellCostLeft == nextCellCostTotal)
                {
                    ResetToCurrentPosition();
                }
                PawnDestinationReservationManager.PawnDestinationReservation pawnDestinationReservation = pawn.Map.pawnDestinationReservationManager.MostRecentReservationFor(pawn);
                if (pawnDestinationReservation != null && ((destination.HasThing && pawnDestinationReservation.target != destination.Cell) || (pawnDestinationReservation.job != pawn.CurJob && pawnDestinationReservation.target != destination.Cell)))
                {
                    pawn.Map.pawnDestinationReservationManager.ObsoleteAllClaimedBy(pawn);
                }
                if (AtDestinationPosition())
                {
                    PatherArrived();
                    return;
                }
                if (pawn.Downed)
                {
                    Log.Error(pawn.LabelCap + " tried to path while downed. This should never happen. curJob=" + pawn.CurJob.ToStringSafe());
                    PatherFailed();
                    return;
                }
                if (curPath != null)
                {
                    curPath.ReleaseToPool();
                }
                curPath           = null;
                moving            = true;
                pawn.jobs.posture = PawnPosture.Standing;
            }
        }