Пример #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();
            }
        }
Пример #2
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);
        }