Ejemplo n.º 1
0
        public static void GetTouchableRegions(Thing thing, Map map, List <WaterRegion> outRegions, bool allowAdjacenttEvenIfCantTouch = false)
        {
            outRegions.Clear();
            CellRect cellRect  = thing.OccupiedRect();
            CellRect cellRect2 = cellRect;

            if (WaterRegionListersUpdater.CanRegisterInAdjacentRegions(thing))
            {
                cellRect2 = cellRect2.ExpandedBy(1);
            }
            CellRect.CellRectIterator iterator = cellRect2.GetIterator();
            while (!iterator.Done())
            {
                IntVec3 intVec = iterator.Current;
                if (intVec.InBoundsShip(map))
                {
                    WaterRegion validRegionAt_NoRebuild = MapExtensionUtility.GetExtensionToMap(map).getWaterRegionGrid.GetValidRegionAt_NoRebuild(intVec);
                    if (!(validRegionAt_NoRebuild is null) && validRegionAt_NoRebuild.type.Passable() && !outRegions.Contains(validRegionAt_NoRebuild))
                    {
                        if (cellRect.Contains(intVec))
                        {
                            outRegions.Add(validRegionAt_NoRebuild);
                        }
                        else if (allowAdjacenttEvenIfCantTouch || ShipReachabilityImmediate.CanReachImmediateShip(intVec, thing, map, PathEndMode.Touch, null))
                        {
                            outRegions.Add(validRegionAt_NoRebuild);
                        }
                    }
                }
                iterator.MoveNext();
            }
        }
Ejemplo n.º 2
0
        public static void SetupMoveIntoNextCell(ref Pawn_PathFollower instance, Pawn pawn, LocalTargetInfo destination)
        {
            if (instance.curPath.NodesLeftCount <= 1)
            {
                Log.Error(string.Concat(new object[]
                {
                    pawn,
                    " at ",
                    pawn.Position,
                    " ran out of path nodes while pathing to ",
                    destination, "."
                }), false);
                PatherFailedHelper(ref instance, pawn);
                return;
            }
            instance.nextCell = instance.curPath.ConsumeNextNode();
            if (!GenGridShips.Walkable(instance.nextCell, MapExtensionUtility.GetExtensionToMap(pawn.Map)))
            {
                Log.Error(string.Concat(new object[]
                {
                    pawn,
                    " entering ",
                    instance.nextCell,
                    " which is unwalkable."
                }), false);
            }
            int num = CostToMoveIntoCellShips(pawn, instance.nextCell);

            instance.nextCellCostTotal = (float)num;
            instance.nextCellCostLeft  = (float)num;
            //Doors?
        }
Ejemplo n.º 3
0
        public void RemoveRegion(WaterRegion r)
        {
            if (!this.regions.Contains(r))
            {
                Log.Error(string.Concat(new object[]
                {
                    "Tried to remove region from Room but this region is not here. region=",
                    r,
                    ", room=",
                    this
                }), false);
                return;
            }
            this.regions.Remove(r);
            if (r.touchesMapEdge)
            {
                this.numRegionsTouchingMapEdge--;
            }
            if (this.regions.Count == 0)
            {
                //this.Group = null;

                /*this.cachedOpenRoofCount = -1;
                *  this.cachedOpenRoofState = null;
                *  this.statsAndRoleDirty = true;*/
                MapExtensionUtility.GetExtensionToMap(this.Map).getWaterRegionGrid.allRooms.Remove(this);
            }
        }
Ejemplo n.º 4
0
        public static IntVec3 RandomSpawnCellForPawnNear(IntVec3 root, Map map, int firstTryWithRadius = 4)
        {
            MapExtension mapE = MapExtensionUtility.GetExtensionToMap(map);

            if (GenGridShips.Standable(root, map, mapE) && root.GetFirstPawn(map) is null)
            {
                return(root);
            }
            IntVec3 result;
            int     num = firstTryWithRadius;

            for (int i = 0; i < 3; i++)
            {
                if (CellFinderExtended.TryFindRandomReachableCellNear(root, map, (float)num, TraverseParms.For(TraverseMode.NoPassClosedDoors, Danger.Deadly, false), (IntVec3 c)
                                                                      => GenGridShips.Standable(c, map, mapE) && (root.Fogged(map) || !c.Fogged(map)) && c.GetFirstPawn(map) is null, out result, null, 999999))
                {
                    return(result);
                }
                num *= 2;
            }
            num = firstTryWithRadius + 1;

            while (!CellFinderExtended.TryRandomClosewalkCellNear(root, map, num, out result, null))
            {
                if (num > map.Size.x / 2 && num > map.Size.z / 2)
                {
                    return(root);
                }
                num *= 2;
            }
            return(result);
        }
Ejemplo n.º 5
0
        public WaterRegion TryGenerateRegionFrom(IntVec3 root)
        {
            RegionType expectedRegionType = WaterRegionTypeUtility.GetExpectedRegionType(root, this.map);

            if (expectedRegionType == RegionType.None)
            {
                return(null);
            }
            if (this.working)
            {
                Log.Error("Trying to generate a new water region but we are currently generating one. Nested calls are not allowed.", false);
                return(null);
            }
            this.working = true;
            WaterRegion result;

            try
            {
                this.regionGrid  = MapExtensionUtility.GetExtensionToMap(this.map).getWaterRegionGrid;
                this.newReg      = WaterRegion.MakeNewUnfilled(root, this.map);
                this.newReg.type = expectedRegionType;
                //Portal type?
                this.FloodFillAndAddCells(root);
                this.CreateLinks();
                this.RegisterThingsInRegionListers();
                result = this.newReg;
            }
            finally
            {
                this.working = false;
            }
            return(result);
        }
Ejemplo n.º 6
0
        public static WaterRegion RegionAt(IntVec3 c, Map map, RegionType allowedRegionTypes = RegionType.Set_Passable)
        {
            if (!c.InBoundsShip(map))
            {
                return(null);
            }
            WaterRegion validRegionAt = MapExtensionUtility.GetExtensionToMap(map).getWaterRegionGrid.GetValidRegionAt(c);

            return(!(validRegionAt is null) && (validRegionAt.type & allowedRegionTypes) != RegionType.None ? validRegionAt : null);
        }
Ejemplo n.º 7
0
        //GetRoomGroup

        public static WaterRoom RoomAtFast(IntVec3 c, Map map, RegionType allowedRegionTypes = RegionType.Set_Passable)
        {
            WaterRegion validRegionAt = MapExtensionUtility.GetExtensionToMap(map)?.getWaterRegionGrid?.GetValidRegionAt(c);

            if (!(validRegionAt is null) && (validRegionAt.type & allowedRegionTypes) != RegionType.None)
            {
                return(validRegionAt.Room);
            }
            return(null);
        }
Ejemplo n.º 8
0
        private static IntVec3 FindCenterWaterCell(Map map, bool landing = false)
        {
            TraverseParms       tp        = TraverseParms.For(TraverseMode.NoPassClosedDoors, Danger.Deadly, false);
            MapExtension        mapE      = MapExtensionUtility.GetExtensionToMap(map);
            Predicate <IntVec3> validator = (IntVec3 x) => GenGridShips.Standable(x, map, mapE) && !x.Fogged(map) && mapE.getShipReachability.CanReachMapEdge(x, tp);
            IntVec3             result;

            if (RCellFinder.TryFindRandomCellNearTheCenterOfTheMapWith(null /*input validator here*/, map, out result))
            {
                return(result); //RECHECK
            }
            Log.Warning("Could not find any valid center cell.", false);
            return(CellFinder.RandomCell(map));
        }
Ejemplo n.º 9
0
        public WaterRegion GetValidRegionAt(IntVec3 c)
        {
            if (!c.InBoundsShip(this.map))
            {
                Log.Error("Tried to get valid water region out of bounds at " + c, false);
            }
            if (!MapExtensionUtility.GetExtensionToMap(this.map).getWaterRegionAndRoomUpdater.Enabled&& MapExtensionUtility.GetExtensionToMap(this.map).getWaterRegionAndRoomUpdater.AnythingToRebuild)
            {
                Log.Warning("Trying to get valid water region at " + c + " but RegionAndRoomUpdater is disabled. The result may be incorrect.", false);
            }
            MapExtensionUtility.GetExtensionToMap(this.map).getWaterRegionAndRoomUpdater.TryRebuildWaterRegions();
            WaterRegion region = this.regionGrid[this.map.cellIndices.CellToIndex(c)];

            return(!(region is null) && region.valid ? region : null);
        }
Ejemplo n.º 10
0
 public static RegionType GetExpectedRegionType(this IntVec3 c, Map map)
 {
     if (!c.InBoundsShip(map))
     {
         return(RegionType.None);
     }
     if (!(c.GetDoor(map) is null))
     {
         return(RegionType.Portal);
     }
     if (GenGridShips.Walkable(c, MapExtensionUtility.GetExtensionToMap(map)))
     {
         return(RegionType.Normal);
     }
     return(RegionType.ImpassableFreeAirExchange);
 }
Ejemplo n.º 11
0
        public static int CostToMoveIntoCellShips(Pawn pawn, IntVec3 c)
        {
            int num = (c.x == pawn.Position.x || c.z == pawn.Position.z) ? pawn.TicksPerMoveCardinal : pawn.TicksPerMoveDiagonal;

            num += MapExtensionUtility.GetExtensionToMap(pawn.Map)?.getShipPathGrid?.CalculatedCostAt(c) ?? 200;
            if (pawn.CurJob != null)
            {
                Pawn locomotionUrgencySameAs = pawn.jobs.curDriver.locomotionUrgencySameAs;
                if (locomotionUrgencySameAs != null && locomotionUrgencySameAs != pawn && locomotionUrgencySameAs.Spawned)
                {
                    int num2 = CostToMoveIntoCellShips(locomotionUrgencySameAs, c);
                    if (num < num2)
                    {
                        num = num2;
                    }
                }
                else
                {
                    switch (pawn.jobs.curJob.locomotionUrgency)
                    {
                    case LocomotionUrgency.Amble:
                        num *= 3;
                        if (num < 60)
                        {
                            num = 60;
                        }
                        break;

                    case LocomotionUrgency.Walk:
                        num *= 2;
                        if (num < 50)
                        {
                            num = 50;
                        }
                        break;

                    case LocomotionUrgency.Jog:
                        break;

                    case LocomotionUrgency.Sprint:
                        num = Mathf.RoundToInt((float)num * 0.75f);
                        break;
                    }
                }
            }
            return(Mathf.Max(num, 1));
        }
Ejemplo n.º 12
0
        private void RegenerateNewWaterRegions()
        {
            this.newRegions.Clear();
            List <IntVec3> cells = this.map.regionDirtyer.DirtyCells;

            foreach (IntVec3 c  in cells)
            {
                if (WaterGridsUtility.GetRegion(c, this.map, RegionType.Set_All) is null)
                {
                    WaterRegion region = MapExtensionUtility.GetExtensionToMap(map).getWaterRegionmaker.TryGenerateRegionFrom(c);
                    if (!(region is null))
                    {
                        this.newRegions.Add(region);
                    }
                }
            }
        }
Ejemplo n.º 13
0
        public static void EnterSpawn(Caravan caravan, Map map, Func <Pawn, IntVec3> spawnCellGetter, CaravanDropInventoryMode caravanDropInventoryMode = CaravanDropInventoryMode.DoNotDrop, bool draftColonists = true)
        {
            List <Pawn>  pawns    = new List <Pawn>(caravan.PawnsListForReading).Where(x => ShipHarmony.IsShip(x)).ToList();
            MapExtension mapE     = MapExtensionUtility.GetExtensionToMap(map);
            Rot4         spawnDir = GetEdgeToSpawnBoatOn(caravan, map);

            for (int i = 0; i < pawns.Count; i++)
            {
                IntVec3 loc = CellFinderExtended.MiddleEdgeCell(spawnDir, map, pawns[i], (IntVec3 c) => GenGridShips.Standable(c, map, mapE) && !c.Fogged(map)); //Change back to spawnCellGetter later

                pawns[i].GetComp <CompShips>().Angle = 0;
                Pawn ship = GenSpawn.Spawn(pawns[i], loc, map, spawnDir.Opposite, WipeMode.Vanish, false) as Pawn;
                ship.drafter.Drafted = draftColonists ? true : false;
            }
            caravan.RemoveAllPawns();
            if (caravan.Spawned)
            {
                Find.WorldObjects.Remove(caravan);
            }
        }
Ejemplo n.º 14
0
 public void AddRegion(WaterRegion r)
 {
     if (this.regions.Contains(r))
     {
         Log.Error(string.Concat(new object[]
         {
             "Tried to add the same region twice to Room. region=",
             r,
             ", room=",
             this
         }), false);
         return;
     }
     this.regions.Add(r);
     if (r.touchesMapEdge)
     {
         this.numRegionsTouchingMapEdge++;
     }
     if (this.regions.Count == 1)
     {
         MapExtensionUtility.GetExtensionToMap(this.Map).getWaterRegionGrid.allRooms.Add(this);
     }
 }
        private IntVec3 FindShoreline(Pawn p)
        {
            IntVec3 curCell = p.Position;
            int     xSize   = p.Map.Size.x - p.Position.x;
            int     zSize   = p.Map.Size.z - p.Position.z;

            IntVec3 nextCell;

            if (p.Rotation == Rot4.North)
            {
            }
            else if (p.Rotation == Rot4.East)
            {
                int alternate = 0;
                int sign      = 1;
                while (alternate < p.Map.Size.z / 2)
                {
                    sign *= -1;
                    for (int i = 0; i < xSize; i++)
                    {
                        nextCell = new IntVec3(p.Position.x + i, p.Position.y, p.Position.z + (alternate * sign));

                        TerrainDef terrain = p.Map.terrainGrid.TerrainAt(nextCell);
                        if (!terrain.IsWater && nextCell.Standable(p.Map))
                        {
                            return(curCell);
                        }
                        curCell = nextCell;
                        if (!curCell.InBoundsShip(p.Map) || !GenGridShips.Standable(curCell, p.Map, MapExtensionUtility.GetExtensionToMap(p.Map)))
                        {
                            break;
                        }
                    }
                    if (sign > 0)
                    {
                        alternate++;
                    }
                }
            }
            else if (p.Rotation == Rot4.South)
            {
            }
            else if (p.Rotation == Rot4.West)
            {
            }

            Log.Error("Unable to find location to disembark " + p.LabelShort);
            return(IntVec3.Invalid);
        }
Ejemplo n.º 16
0
        private void SweepInTwoDirectionsAndTryToCreateLink(Rot4 potentialOtherRegionDir, IntVec3 c)
        {
            if (!potentialOtherRegionDir.IsValid)
            {
                return;
            }
            HashSet <IntVec3> hashSet = this.linksProcessedAt[potentialOtherRegionDir.AsInt];

            if (hashSet.Contains(c))
            {
                return;
            }
            IntVec3 c2 = c + potentialOtherRegionDir.FacingCell;

            if (c2.InBoundsShip(this.map) && this.regionGrid.GetRegionAt_NoRebuild_InvalidAllowed(c2) == this.newReg)
            {
                return;
            }
            RegionType expectedRegionType = WaterRegionTypeUtility.GetExpectedRegionType(c2, this.map);

            if (expectedRegionType == RegionType.None)
            {
                return;
            }
            Rot4 rot = potentialOtherRegionDir;

            rot.Rotate(RotationDirection.Clockwise);
            int num  = 0;
            int num2 = 0;

            hashSet.Add(c);
            if (!WaterRegionTypeUtility.IsOneCellRegion(expectedRegionType))
            {
                for (;;)
                {
                    IntVec3 intVec = c + rot.FacingCell * (num + 1);
                    if (!intVec.InBoundsShip(this.map) || this.regionGrid.GetRegionAt_NoRebuild_InvalidAllowed(intVec) != this.newReg ||
                        WaterRegionTypeUtility.GetExpectedRegionType(intVec + potentialOtherRegionDir.FacingCell, this.map) != expectedRegionType)
                    {
                        break;
                    }
                    if (!hashSet.Add(intVec))
                    {
                        Log.Error("We've processed the same cell twice.", false);
                    }
                    num++;
                }
                for (; ;)
                {
                    IntVec3 intVec2 = c - rot.FacingCell * (num2 + 1);
                    if (!intVec2.InBoundsShip(this.map) || this.regionGrid.GetRegionAt_NoRebuild_InvalidAllowed(intVec2) != this.newReg ||
                        WaterRegionTypeUtility.GetExpectedRegionType(intVec2 + potentialOtherRegionDir.FacingCell, this.map) != expectedRegionType)
                    {
                        break;
                    }
                    if (!hashSet.Add(intVec2))
                    {
                        Log.Error("We've processed the same cell twice.", false);
                    }
                    num2++;
                }
            }
            int           length = num + num2 + 1;
            SpanDirection dir;
            IntVec3       root;

            if (potentialOtherRegionDir == Rot4.North)
            {
                dir  = SpanDirection.East;
                root = c - rot.FacingCell * num2;
                root.z++;
            }
            else if (potentialOtherRegionDir == Rot4.South)
            {
                dir  = SpanDirection.East;
                root = c + rot.FacingCell * num;
            }
            else if (potentialOtherRegionDir == Rot4.East)
            {
                dir  = SpanDirection.North;
                root = c + rot.FacingCell * num;
                root.x++;
            }
            else
            {
                dir  = SpanDirection.North;
                root = c - rot.FacingCell * num2;
            }
            EdgeSpan        span       = new EdgeSpan(root, dir, length);
            WaterRegionLink regionLink = MapExtensionUtility.GetExtensionToMap(this.map).getWaterRegionLinkDatabase.LinkFrom(span);

            regionLink.Register(this.newReg);
            this.newReg.links.Add(regionLink);
        }
Ejemplo n.º 17
0
        private static IntVec3 FindNearEdgeWaterCell(Map map)
        {
            Predicate <IntVec3> validator   = (IntVec3 x) => GenGridShips.Standable(x, map, MapExtensionUtility.GetExtensionToMap(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.", false);
            return(CellFinder.RandomCell(map));
        }
        protected override bool TryExecuteWorker(IncidentParms parms)
        {
            return(false); //Disabled for now

            Map map = (Map)parms.target;

            if (!base.TryResolveParms(parms))
            {
                return(false);
            }
            if (parms.faction.HostileTo(Faction.OfPlayer))
            {
                return(false);
            }
            List <Pawn> list = BoatStrategyWorker.GeneratePawnsForBoats(parms, PawnGroupKindDef);

            if (list.Count <= 0)
            {
                return(false);
            }
            foreach (Pawn p in list)
            {
                if (p.needs != null && p.needs.food != null)
                {
                    p.needs.food.CurLevel = p.needs.food.MaxLevel;
                }
            }
            TraderKindDef traderKind = null;

            foreach (Pawn p in list)
            {
                if (p.TraderKind != null)
                {
                    traderKind = p.TraderKind;
                    break;
                }
            }

            List <Pawn> ships = BoatStrategyWorker.GenerateBoatsForIncident(parms, PawnGroupKindDef, ref list);

            if (!ships.Any())
            {
                return(false);
            }
            List <IntVec3>      usedCells  = new List <IntVec3>();
            Predicate <IntVec3> validator  = (IntVec3 c) => GenGridShips.Standable(c, map, MapExtensionUtility.GetExtensionToMap(map)) && !c.Fogged(map);
            IntVec3             root       = CellFinderExtended.MiddleEdgeCell(Find.World.CoastDirectionAt(map.Tile), map, ships.MaxBy(x => x.def.size.z), validator);
            List <Thing>        thingShips = new List <Thing>();

            foreach (Pawn s in ships)
            {
                IntVec3 loc = !usedCells.Any() ? CellFinderExtended.MiddleEdgeCell(Find.World.CoastDirectionAt(map.Tile), map, s, validator) :
                              CellFinderExtended.RandomEdgeCell(Find.World.CoastDirectionAt(map.Tile), map, validator, usedCells, s);
                usedCells.Add(loc);
                Thing shipSpawned = GenSpawn.Spawn(s, loc, map, WipeMode.Vanish);
                shipSpawned.Rotation = Find.World.CoastDirectionAt(map.Tile).Opposite;
                thingShips.Add(shipSpawned);
            }
            List <Pawn> pawnsLeft = list;

            pawnsLeft.SortBy(x => x.health.capacities.CapableOf(PawnCapacityDefOf.Manipulation));
            foreach (Thing t in thingShips)
            {
                for (int i = 0; i < t.TryGetComp <CompShips>().PawnCountToOperate; i++)
                {
                    if (pawnsLeft.Count <= 0)
                    {
                        break;
                    }
                    t.TryGetComp <CompShips>().BoardDirectly(pawnsLeft.Pop(), t.TryGetComp <CompShips>().NextAvailableHandler.handlers);
                }
                if (pawnsLeft.Count <= 0)
                {
                    break;
                }
            }

            int iter = 0;

            for (int i = 0; i < pawnsLeft.Count; i++)
            {
                Thing ship = thingShips[iter];
                Pawn  p    = pawnsLeft.Pop();
                ship.TryGetComp <CompShips>().BoardDirectly(p, ship.TryGetComp <CompShips>().NextAvailableHandler.handlers);
                iter = iter + 1 >= thingShips.Count ? 0 : iter + 1;
            }
            foreach (Thing s in thingShips)
            {
                (s as Pawn).drafter.Drafted = true;
            }

            string label = "LetterLabelTraderCaravanArrival".Translate(parms.faction.Name, traderKind.label).CapitalizeFirst();
            string text  = "LetterTraderCaravanArrival".Translate(parms.faction.Name, traderKind.label).CapitalizeFirst();

            PawnRelationUtility.Notify_PawnsSeenByPlayer_Letter(ships, ref label, ref text, "LetterRelatedPawnsNeutralGroup".Translate(Faction.OfPlayer.def.pawnsPlural), true, true);
            Find.LetterStack.ReceiveLetter(label, text, LetterDefOf.PositiveEvent, ships[0], parms.faction, null);

            RCellFinder.TryFindRandomSpotJustOutsideColony(ships[0], out IntVec3 chillSpot);
            LordJob_TradeWithColony lordJob = new LordJob_TradeWithColony(parms.faction, chillSpot);

            foreach (Pawn s in ships)
            {
                Job job = new Job(JobDefOf_Ships.DisembarkLord, FindShoreline(s));
                s.jobs.TryTakeOrderedJob(job, JobTag.Misc);
                s.GetComp <CompShips>().lordJobToAssign = lordJob;
                s.GetComp <CompShips>().lordShipGroup.AddRange(ships);
            }
            return(true);
        }
Ejemplo n.º 19
0
 public static PawnPath GenerateNewPath(ref IntVec3 lastPathedTargetPosition, LocalTargetInfo destination, ref Pawn pawn, Map map, PathEndMode peMode)
 {
     lastPathedTargetPosition = destination.Cell;
     return(MapExtensionUtility.GetExtensionToMap(map)?.getShipPathFinder?.FindShipPath(pawn.Position, destination, pawn, peMode) ?? PawnPath.NotFound);
 }
Ejemplo n.º 20
0
        public static bool NeedNewPath(LocalTargetInfo destination, PawnPath curPath, Pawn pawn, PathEndMode peMode, IntVec3 lastPathedTargetPosition)
        {
            if (!destination.IsValid || curPath is null || !curPath.Found || curPath.NodesLeftCount == 0)
            {
                return(true);
            }
            if (destination.HasThing && destination.Thing.Map != pawn.Map)
            {
                return(true);
            }
            if ((pawn.Position.InHorDistOf(curPath.LastNode, 15f) || pawn.Position.InHorDistOf(destination.Cell, 15f)) && !ShipReachabilityImmediate.CanReachImmediateShip(
                    curPath.LastNode, destination, pawn.Map, peMode, pawn))
            {
                return(true);
            }
            if (curPath.UsedRegionHeuristics && curPath.NodesConsumedCount >= 75)
            {
                return(true);
            }
            if (lastPathedTargetPosition != destination.Cell)
            {
                float num = (float)(pawn.Position - destination.Cell).LengthHorizontalSquared;
                float num2;
                if (num > 900f)
                {
                    num2 = 10f;
                }
                else if (num > 289f)
                {
                    num2 = 5f;
                }
                else if (num > 100f)
                {
                    num2 = 3f;
                }
                else if (num > 49f)
                {
                    num2 = 2f;
                }
                else
                {
                    num2 = 0.5f;
                }

                if ((float)(lastPathedTargetPosition - destination.Cell).LengthHorizontalSquared > (num2 * num2))
                {
                    return(true);
                }
            }
            bool    flag   = curPath.NodesLeftCount < 30;
            IntVec3 other  = IntVec3.Invalid;
            IntVec3 intVec = IntVec3.Invalid;
            int     num3   = 0;

            while (num3 < 20 && num3 < curPath.NodesLeftCount)
            {
                intVec = curPath.Peek(num3);
                if (!GenGridShips.Walkable(intVec, MapExtensionUtility.GetExtensionToMap(pawn.Map)))
                {
                    return(true);
                }
                if (num3 != 0 && intVec.AdjacentToDiagonal(other) && (ShipPathFinder.BlocksDiagonalMovement(pawn.Map.cellIndices.CellToIndex(intVec.x, other.z), pawn.Map,
                                                                                                            MapExtensionUtility.GetExtensionToMap(pawn.Map)) || ShipPathFinder.BlocksDiagonalMovement(pawn.Map.cellIndices.CellToIndex(other.x, intVec.z), pawn.Map,
                                                                                                                                                                                                      MapExtensionUtility.GetExtensionToMap(pawn.Map))))
                {
                    return(true);
                }
                other = intVec;
                num3++;
            }
            return(false);
        }
Ejemplo n.º 21
0
        public static bool TryFindRandomReachableCellNear(IntVec3 root, Map map, float radius, TraverseParms traverseParms, Predicate <IntVec3> validator, out IntVec3 result,
                                                          Predicate <WaterRegion> regionValidator, int maxRegions = 999999)
        {
            if (map is null)
            {
                Log.ErrorOnce("Tried to find reachable cell using SPExtended in a null map", 61037855, false);
                result = IntVec3.Invalid;
                return(false);
            }
            WaterRegion region = WaterGridsUtility.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?.Any() ?? false?SPExtra.RiverDirection(map) : Rot4.Invalid;

            result = CellFinderExtended.RandomEdgeCell(dir, map, (IntVec3 c) => GenGridShips.Standable(c, map, MapExtensionUtility.GetExtensionToMap(map)) && !c.Fogged(map));
            return(true);
        }