Ejemplo n.º 1
0
        private static IntVec3 FindCenterWaterCell(Map map, bool landing = false)
        {
            TraverseParms       tp        = TraverseParms.For(TraverseMode.NoPassClosedDoors, Danger.Deadly, false);
            Predicate <IntVec3> validator = (IntVec3 x) => GenGridVehicles.Standable(x, map) && !x.Fogged(map) && map.GetCachedMapComponent <VehicleMapping>().VehicleReachability.CanReachMapEdge(x, tp);
            IntVec3             result;

            if (RCellFinder.TryFindRandomCellNearTheCenterOfTheMapWith(null /*input validator here*/, map, out result))
            {
                return(result);                //REDO
            }
            Log.Warning("Could not find any valid center cell.");
            return(CellFinder.RandomCell(map));
        }
Ejemplo n.º 2
0
        private static IntVec3 FindNearEdgeWaterCell(Map map)
        {
            Predicate <IntVec3> validator   = (IntVec3 x) => GenGridVehicles.Standable(x, map) && !x.Fogged(map);
            Faction             hostFaction = map.ParentFaction;
            IntVec3             root;

            if (CellFinder.TryFindRandomEdgeCellWith(validator, map, CellFinder.EdgeRoadChance_Ignore, out root))
            {
                return(CellFinderExtended.RandomClosewalkCellNear(root, map, 5, null));
            }
            if (CellFinder.TryFindRandomEdgeCellWith(validator, map, CellFinder.EdgeRoadChance_Ignore, out root))
            {
                return(CellFinderExtended.RandomClosewalkCellNear(root, map, 5, null));
            }
            Log.Warning("Could not find any valid edge cell.");
            return(CellFinder.RandomCell(map));
        }
Ejemplo n.º 3
0
        public static bool TryFindRandomReachableCellNear(IntVec3 root, Map map, float radius, TraverseParms traverseParms, Predicate <IntVec3> validator, Predicate <VehicleRegion> regionValidator, out IntVec3 result,
                                                          int maxRegions = 999999)
        {
            if (map is null)
            {
                Log.ErrorOnce("Tried to find reachable cell using SPExtended in a null map", 61037855);
                result = IntVec3.Invalid;
                return(false);
            }
            VehicleRegion region = VehicleGridsUtility.GetRegion(root, map, RegionType.Set_Passable);

            if (region is null)
            {
                result = IntVec3.Invalid;
                return(false);
            }
            Rot4 dir = Find.World.CoastDirectionAt(map.Tile).IsValid ? Find.World.CoastDirectionAt(map.Tile) : !Find.WorldGrid[map.Tile].Rivers.NullOrEmpty() ? Ext_Map.RiverDirection(map) : Rot4.Invalid;

            result = RandomEdgeCell(dir, map, (IntVec3 c) => GenGridVehicles.Standable(c, map) && !c.Fogged(map), 0);
            return(true);
        }
Ejemplo n.º 4
0
        public static void EnterAndSpawn(Caravan caravan, Map map, CaravanEnterMode enterMode, CaravanDropInventoryMode dropInventoryMode = CaravanDropInventoryMode.DoNotDrop,
                                         bool draftColonists = false, Predicate <IntVec3> extraValidator = null)
        {
            bool coastalSpawn = caravan.HasBoat();

            if (enterMode == CaravanEnterMode.None)
            {
                Log.Error(string.Concat(new object[]
                {
                    "Caravan ", caravan, " tried to enter map ", map, " with no enter mode. Defaulting to edge."
                }));
                enterMode = CaravanEnterMode.Edge;
            }
            List <Pawn> pawns = new List <Pawn>(caravan.PawnsListForReading).ToList();

            IntVec3             enterCell = pawns.NotNullAndAny(v => v.IsBoat()) ? GetWaterCell(caravan, map, CaravanEnterMode.Edge) : GetEnterCellVehicle(caravan, map, enterMode, extraValidator);
            Rot4                edge      = enterMode == CaravanEnterMode.Edge ? CellRect.WholeMap(map).GetClosestEdge(enterCell) : Rot4.North;
            Predicate <IntVec3> validator = (IntVec3 c) => coastalSpawn?GenGridVehicles.Standable(c, map) : GenGrid.Standable(c, map);

            Func <Pawn, IntVec3> spawnCellGetter = (Pawn p) => CellFinderExtended.RandomSpawnCellForPawnNear(enterCell, map, p, validator);

            SpawnVehicles(caravan, pawns, map, spawnCellGetter, edge, draftColonists);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Ensures the cellrect inhabited by <paramref name="vehicleDef"/> contains no Things that will block pathing and movement at <paramref name="cell"/>.
        /// </summary>
        /// <param name="pawn"></param>
        /// <param name="c"></param>
        public static bool CellRectStandable(this VehicleDef vehicleDef, Map map, IntVec3 cell, Rot4?rot = null)
        {
            IntVec2 dimensions = vehicleDef.Size;

            if (rot?.IsHorizontal ?? false)
            {
                int x = dimensions.x;
                dimensions.x = dimensions.z;
                dimensions.z = x;
            }
            foreach (IntVec3 cell2 in CellRect.CenteredOn(cell, dimensions.x, dimensions.z))
            {
                if (vehicleDef.IsBoat() && !GenGridVehicles.Standable(cell2, map))
                {
                    return(false);
                }
                else if (!GenGrid.Standable(cell2, map))
                {
                    return(false);
                }
            }
            return(true);
        }
Ejemplo n.º 6
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);
        }