public static void CheckArrived(Lord lord, List <Pawn> pawnsToCheck, IntVec3 meetingPoint, string memo, Predicate <Pawn> shouldCheckIfArrived, bool waterPathing,
                                        Predicate <Pawn> extraValidator = null)
        {
            bool flag = true;

            foreach (Pawn p in pawnsToCheck)
            {
                if (shouldCheckIfArrived(p) && !waterPathing)
                {
                    if (!p.Spawned || !p.Position.InHorDistOf(meetingPoint, 15f) || !ReachabilityUtility.CanReach(p, meetingPoint, PathEndMode.ClosestTouch, Danger.Deadly, false, TraverseMode.ByPawn) ||
                        (extraValidator != null && !extraValidator(p)))
                    {
                        flag = false;
                        break;
                    }
                }
                else if (waterPathing)
                {
                    Pawn leadShip = ((LordJob_FormAndSendCaravanShip)lord.LordJob).LeadShip;
                    if (!p.Spawned || !p.Position.InHorDistOf(((LordJob_FormAndSendCaravanShip)lord.LordJob).LeadShip.Position, 5f) || !leadShip.Position.InHorDistOf(meetingPoint, leadShip.def.size.z > 5 ? (float)leadShip.def.size.z / 2 : 3f) ||
                        !ShipReachabilityUtility.CanReachShip(p, meetingPoint, PathEndMode.ClosestTouch, Danger.Deadly, false, TraverseMode.ByPawn) || (extraValidator != null && !extraValidator(p)))
                    {
                        flag = false;
                        break;
                    }
                }
            }
            if (flag)
            {
                lord.ReceiveMemo(memo);
            }
        }
Exemplo n.º 2
0
        protected override Job TryGiveJob(Pawn pawn)
        {
            pawn.drafter.Drafted = true;

            IntVec3 cell = pawn.mindState.duty.focus.Cell;

            if (pawn.IsBoat() && !ShipReachabilityUtility.CanReachShip(pawn, cell, PathEndMode.OnCell, PawnUtility.ResolveMaxDanger(pawn, maxDanger), false, TraverseMode.ByPawn))
            {
                return(null);
            }
            else if (!pawn.IsBoat() && pawn is VehiclePawn vehicle && !ReachabilityUtility.CanReach(vehicle, cell, PathEndMode.OnCell, PawnUtility.ResolveMaxDanger(vehicle, maxDanger), false))
            {
                return(null);
            }
            if (exactCell && pawn.Position == cell)
            {
                return(null);
            }

            return(new Job(JobDefOf.Goto, cell)
            {
                locomotionUrgency = PawnUtility.ResolveLocomotion(pawn, locomotionUrgency),
                expiryInterval = jobMaxDuration
            });
        }
        protected override Job TryGiveJob(Pawn pawn)
        {
            pawn.mindState.nextMoveOrderIsWait = !pawn.mindState.nextMoveOrderIsWait;
            if (pawn.mindState.nextMoveOrderIsWait && !this.exactCell)
            {
                return(new Job(JobDefOf_Ships.IdleShip)
                {
                    expiryInterval = this.WaitTicks.RandomInRange
                });
            }
            IntVec3 cell = pawn.mindState.duty.focus.Cell;

            if (!ShipReachabilityUtility.CanReachShip(pawn, cell, PathEndMode.OnCell, PawnUtility.ResolveMaxDanger(pawn, this.maxDanger), false, TraverseMode.ByPawn))
            {
                return(null);
            }
            if (this.exactCell && pawn.Position == cell)
            {
                return(null);
            }
            IntVec3 c = cell;

            return(new Job(JobDefOf.Goto, c)
            {
                locomotionUrgency = PawnUtility.ResolveLocomotion(pawn, this.locomotionUrgency),
                expiryInterval = this.jobMaxDuration
            });
        }
Exemplo n.º 4
0
        /// <summary>
        /// Intercepts FloatMenuMakerMap call to restrict by size and call through to custom water based pathing requirements
        /// </summary>
        /// <param name="clickCell"></param>
        /// <param name="pawn"></param>
        /// <param name="__result"></param>
        /// <returns></returns>
        public static bool GotoLocationShips(IntVec3 clickCell, Pawn pawn, ref FloatMenuOption __result)
        {
            if (pawn is VehiclePawn vehicle)
            {
                if (vehicle.Faction != Faction.OfPlayer || !vehicle.CanMoveFinal)
                {
                    return(false);
                }
                if (VehicleMod.settings.main.fullVehiclePathing && vehicle.LocationRestrictedBySize(clickCell))
                {
                    Messages.Message("VehicleCannotFit".Translate(), MessageTypeDefOf.RejectInput);
                    return(false);
                }

                if (vehicle.CompFueledTravel != null && vehicle.CompFueledTravel.EmptyTank)
                {
                    Messages.Message("VehicleOutOfFuel".Translate(), MessageTypeDefOf.RejectInput);
                    return(false);
                }

                Debug.Message("-> " + clickCell + " | " + vehicle.Map.terrainGrid.TerrainAt(clickCell).LabelCap + " | " + vehicle.Map.GetCachedMapComponent <VehicleMapping>().VehiclePathGrid.CalculatedCostAt(clickCell) +
                              " - " + vehicle.Map.GetCachedMapComponent <VehicleMapping>().VehiclePathGrid.pathGrid[vehicle.Map.cellIndices.CellToIndex(clickCell)]);

                if (vehicle.IsBoat() && !VehicleMod.settings.debug.debugDisableWaterPathing)
                {
                    int     num = GenRadial.NumCellsInRadius(2.9f);
                    int     i   = 0;
                    IntVec3 curLoc;
                    while (i < num)
                    {
                        curLoc = GenRadial.RadialPattern[i] + clickCell;
                        if (GenGridVehicles.Standable(curLoc, vehicle.Map))
                        {
                            if (curLoc == vehicle.Position || vehicle.beached)
                            {
                                __result = null;
                                return(false);
                            }
                            if (!ShipReachabilityUtility.CanReachShip(vehicle, curLoc, PathEndMode.OnCell, Danger.Deadly, false, TraverseMode.ByPawn))
                            {
                                Debug.Message($"Cant Reach {curLoc} with {vehicle.Label}");
                                __result = new FloatMenuOption("CannotSailToCell".Translate(), null, MenuOptionPriority.Default, null, null, 0f, null, null);
                                return(false);
                            }
                            Action action = delegate()
                            {
                                Job job = new Job(JobDefOf.Goto, curLoc);
                                if (vehicle.Map.exitMapGrid.IsExitCell(Verse.UI.MouseCell()))
                                {
                                    job.exitMapOnArrival = true;
                                }
                                else if (!vehicle.Map.IsPlayerHome && !vehicle.Map.exitMapGrid.MapUsesExitGrid && CellRect.WholeMap(vehicle.Map).IsOnEdge(Verse.UI.MouseCell(), 3) &&
                                         vehicle.Map.Parent.GetComponent <FormCaravanComp>() != null && MessagesRepeatAvoider.MessageShowAllowed("MessagePlayerTriedToLeaveMapViaExitGrid-" +
                                                                                                                                                 vehicle.Map.uniqueID, 60f))
                                {
                                    FormCaravanComp component = vehicle.Map.Parent.GetComponent <FormCaravanComp>();
                                    if (component.CanFormOrReformCaravanNow)
                                    {
                                        Messages.Message("MessagePlayerTriedToLeaveMapViaExitGrid_CanReform".Translate(), vehicle.Map.Parent, MessageTypeDefOf.RejectInput, false);
                                    }
                                    else
                                    {
                                        Messages.Message("MessagePlayerTriedToLeaveMapViaExitGrid_CantReform".Translate(), vehicle.Map.Parent, MessageTypeDefOf.RejectInput, false);
                                    }
                                }
                                if (vehicle.jobs.TryTakeOrderedJob(job, JobTag.Misc))
                                {
                                    MoteMaker.MakeStaticMote(curLoc, vehicle.Map, ThingDefOf.Mote_FeedbackGoto, 1f);
                                }
                            };
                            __result = new FloatMenuOption("GoHere".Translate(), action, MenuOptionPriority.GoHere, null, null, 0f, null, null)
                            {
                                autoTakeable         = true,
                                autoTakeablePriority = 10f
                            };
                            return(false);
                        }
                        else
                        {
                            i++;
                        }
                    }
                }
                else
                {
                    int     num = GenRadial.NumCellsInRadius(2.9f);
                    int     i   = 0;
                    IntVec3 curLoc;

                    while (i < num)
                    {
                        curLoc = GenRadial.RadialPattern[i] + clickCell;
                        if (GenGrid.Standable(curLoc, pawn.Map))
                        {
                            if (curLoc == pawn.Position)
                            {
                                __result = null;
                                return(false);
                            }
                            if (!ReachabilityUtility.CanReach(pawn, curLoc, PathEndMode.OnCell, Danger.Deadly, false))
                            {
                                Debug.Message($"Cant Reach {curLoc} with {vehicle.Label}");
                                __result = new FloatMenuOption("CannotSailToCell".Translate(), null, MenuOptionPriority.Default, null, null, 0f, null, null);
                                return(false);
                            }
                            Action action = delegate()
                            {
                                Job job = new Job(JobDefOf.Goto, curLoc);
                                if (pawn.Map.exitMapGrid.IsExitCell(Verse.UI.MouseCell()))
                                {
                                    job.exitMapOnArrival = true;
                                }
                                else if (!pawn.Map.IsPlayerHome && !pawn.Map.exitMapGrid.MapUsesExitGrid && CellRect.WholeMap(pawn.Map).IsOnEdge(Verse.UI.MouseCell(), 3) &&
                                         pawn.Map.Parent.GetComponent <FormCaravanComp>() != null && MessagesRepeatAvoider.MessageShowAllowed("MessagePlayerTriedToLeaveMapViaExitGrid-" +
                                                                                                                                              pawn.Map.uniqueID, 60f))
                                {
                                    FormCaravanComp component = pawn.Map.Parent.GetComponent <FormCaravanComp>();
                                    if (component.CanFormOrReformCaravanNow)
                                    {
                                        Messages.Message("MessagePlayerTriedToLeaveMapViaExitGrid_CanReform".Translate(), pawn.Map.Parent, MessageTypeDefOf.RejectInput, false);
                                    }
                                    else
                                    {
                                        Messages.Message("MessagePlayerTriedToLeaveMapViaExitGrid_CantReform".Translate(), pawn.Map.Parent, MessageTypeDefOf.RejectInput, false);
                                    }
                                }
                                if (pawn.jobs.TryTakeOrderedJob(job, JobTag.Misc))
                                {
                                    MoteMaker.MakeStaticMote(curLoc, pawn.Map, ThingDefOf.Mote_FeedbackGoto, 1f);
                                }
                            };
                            __result = new FloatMenuOption("GoHere".Translate(), action, MenuOptionPriority.GoHere, null, null, 0f, null, null)
                            {
                                autoTakeable         = true,
                                autoTakeablePriority = 10f
                            };
                            return(false);
                        }
                        else
                        {
                            i++;
                        }
                    }
                }
                __result = null;
                return(false);
            }
            else
            {
                if (PathingHelper.VehicleInCell(pawn.Map, clickCell))
                {
                    __result = new FloatMenuOption("CannotGoNoPath".Translate(), null, MenuOptionPriority.Default, null, null, 0f, null, null);
                    return(false);
                }
            }
            return(true);
        }