Esempio n. 1
0
 /// <summary>
 /// Determine if next cell is walkable with final determination if vehicle is in cell or not
 /// </summary>
 /// <param name="__result"></param>
 /// <param name="___pawn"></param>
 /// <param name="nextCell"></param>
 public static void IsVehicleInNextCell(ref bool __result, Pawn ___pawn, Pawn_PathFollower __instance)
 {
     if (!__result)
     {
         //Peek 2 nodes ahead to avoid collision last second
         __result = (__instance.curPath.NodesLeftCount > 1 && PathingHelper.VehicleInCell(___pawn.Map, __instance.curPath.Peek(1))) ||
                    (__instance.curPath.NodesLeftCount > 2 && PathingHelper.VehicleInCell(___pawn.Map, __instance.curPath.Peek(2)));
     }
 }
Esempio n. 2
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);
        }