Пример #1
0
        public float ApproxDistanceInTiles(int firstTile, int secondTile)
        {
            Vector3 tileCenter  = this.GetTileCenter(firstTile);
            Vector3 tileCenter2 = this.GetTileCenter(secondTile);

            return(this.ApproxDistanceInTiles(GenMath.SphericalDistance(tileCenter.normalized, tileCenter2.normalized)));
        }
Пример #2
0
        private static bool CustomTravelSpeedSRTS(int ___initialTile, int ___destinationTile, List <ActiveDropPodInfo> ___pods, ref float __result)
        {
            if (___pods.Any(x => x.innerContainer.Any(y => y.TryGetComp <CompLaunchableSRTS>() != null)))
            {
                Vector3 start = Find.WorldGrid.GetTileCenter(___initialTile);
                Vector3 end   = Find.WorldGrid.GetTileCenter(___destinationTile);

                if (start == end)
                {
                    __result = 1f;
                    return(false);
                }
                float num = GenMath.SphericalDistance(start.normalized, end.normalized);
                if (num == 0f)
                {
                    __result = 1f;
                    return(false);
                }
                Thing ship = ___pods.Find(x => x.innerContainer.First(y => y.TryGetComp <CompLaunchableSRTS>() != null) != null).innerContainer.First(z => z.TryGetComp <CompLaunchableSRTS>() != null);
                __result = ship.TryGetComp <CompLaunchableSRTS>().TravelSpeed / num;
                return(false);
            }
            return(true);
        }
Пример #3
0
        public WorldPath FindPath(int startTile, int destTile, Caravan caravan, Func <float, bool> terminator = null)
        {
            if (startTile < 0)
            {
                Log.Error("Tried to FindPath with invalid start tile " + startTile + ", caravan= " + caravan);
                return(WorldPath.NotFound);
            }
            if (destTile < 0)
            {
                Log.Error("Tried to FindPath with invalid dest tile " + destTile + ", caravan= " + caravan);
                return(WorldPath.NotFound);
            }
            if (caravan != null)
            {
                if (!caravan.CanReach(destTile))
                {
                    return(WorldPath.NotFound);
                }
            }
            else if (!Find.WorldReachability.CanReach(startTile, destTile))
            {
                return(WorldPath.NotFound);
            }
            World      world = Find.World;
            WorldGrid  grid  = world.grid;
            List <int> tileIDToNeighbors_offsets = grid.tileIDToNeighbors_offsets;
            List <int> tileIDToNeighbors_values  = grid.tileIDToNeighbors_values;
            Vector3    normalized = grid.GetTileCenter(destTile).normalized;

            float[] movementDifficulty = world.pathGrid.movementDifficulty;
            int     num  = 0;
            int     num2 = caravan?.TicksPerMove ?? 3300;
            int     num3 = CalculateHeuristicStrength(startTile, destTile);

            statusOpenValue   += 2;
            statusClosedValue += 2;
            if (statusClosedValue >= 65435)
            {
                ResetStatuses();
            }
            calcGrid[startTile].knownCost     = 0;
            calcGrid[startTile].heuristicCost = 0;
            calcGrid[startTile].costNodeCost  = 0;
            calcGrid[startTile].parentTile    = startTile;
            calcGrid[startTile].status        = statusOpenValue;
            openList.Clear();
            openList.Push(new CostNode(startTile, 0));
            while (true)
            {
                if (openList.Count <= 0)
                {
                    Log.Warning(caravan + " pathing from " + startTile + " to " + destTile + " ran out of tiles to process.");
                    return(WorldPath.NotFound);
                }
                CostNode costNode = openList.Pop();
                if (costNode.cost != calcGrid[costNode.tile].costNodeCost)
                {
                    continue;
                }
                int tile = costNode.tile;
                if (calcGrid[tile].status == statusClosedValue)
                {
                    continue;
                }
                if (tile == destTile)
                {
                    return(FinalizedPath(tile));
                }
                if (num > 500000)
                {
                    Log.Warning(caravan + " pathing from " + startTile + " to " + destTile + " hit search limit of " + 500000 + " tiles.");
                    return(WorldPath.NotFound);
                }
                int num4 = (tile + 1 < tileIDToNeighbors_offsets.Count) ? tileIDToNeighbors_offsets[tile + 1] : tileIDToNeighbors_values.Count;
                for (int i = tileIDToNeighbors_offsets[tile]; i < num4; i++)
                {
                    int num5 = tileIDToNeighbors_values[i];
                    if (calcGrid[num5].status == statusClosedValue || world.Impassable(num5))
                    {
                        continue;
                    }
                    int    num6   = (int)((float)num2 * movementDifficulty[num5] * grid.GetRoadMovementDifficultyMultiplier(tile, num5)) + calcGrid[tile].knownCost;
                    ushort status = calcGrid[num5].status;
                    if ((status != statusClosedValue && status != statusOpenValue) || calcGrid[num5].knownCost > num6)
                    {
                        Vector3 tileCenter = grid.GetTileCenter(num5);
                        if (status != statusClosedValue && status != statusOpenValue)
                        {
                            float num7 = grid.ApproxDistanceInTiles(GenMath.SphericalDistance(tileCenter.normalized, normalized));
                            calcGrid[num5].heuristicCost = Mathf.RoundToInt((float)num2 * num7 * (float)num3 * 0.5f);
                        }
                        int num8 = num6 + calcGrid[num5].heuristicCost;
                        calcGrid[num5].parentTile   = tile;
                        calcGrid[num5].knownCost    = num6;
                        calcGrid[num5].status       = statusOpenValue;
                        calcGrid[num5].costNodeCost = num8;
                        openList.Push(new CostNode(num5, num8));
                    }
                }
                num++;
                calcGrid[tile].status = statusClosedValue;
                if (terminator != null && terminator(calcGrid[tile].costNodeCost))
                {
                    break;
                }
            }
            return(WorldPath.NotFound);
        }
Пример #4
0
        public WorldPath FindPath(int startTile, int destTile, VehicleCaravan caravan, Func <float, bool> terminator = null)
        {
            if (startTile < 0)
            {
                Log.Error(string.Concat(new object[]
                {
                    "Tried to FindPath with invalid start tile ",
                    startTile,
                    ", caravan= ",
                    caravan
                }));
                return(WorldPath.NotFound);
            }
            if (destTile < 0)
            {
                Log.Error(string.Concat(new object[]
                {
                    "Tried to FindPath with invalid dest tile ",
                    destTile,
                    ", caravan= ",
                    caravan
                }));
                return(WorldPath.NotFound);
            }

            if (!WorldVehicleReachability.Instance.CanReach(caravan, destTile))
            {
                return(WorldPath.NotFound);
            }

            World      world = Find.World;
            WorldGrid  grid  = world.grid;
            List <int> tileIDToNeighbors_offsets = grid.tileIDToNeighbors_offsets;
            List <int> tileIDToNeighbors_values  = grid.tileIDToNeighbors_values;
            Vector3    normalized = grid.GetTileCenter(destTile).normalized;
            Dictionary <VehicleDef, float[]> movementDifficulty = WorldVehiclePathGrid.Instance.movementDifficulty;
            int num  = 0;
            int num2 = (caravan != null) ? caravan.TicksPerMove : 3300;
            int num3 = CalculateHeuristicStrength(startTile, destTile);

            statusOpenValue   += 2;
            statusClosedValue += 2;
            if (statusClosedValue >= 65435)
            {
                ResetStatuses();
            }
            calcGrid[startTile].knownCost     = 0;
            calcGrid[startTile].heuristicCost = 0;
            calcGrid[startTile].costNodeCost  = 0;
            calcGrid[startTile].parentTile    = startTile;
            calcGrid[startTile].status        = statusOpenValue;
            openList.Clear();
            openList.Push(new CostNode(startTile, 0));
            while (openList.Count > 0)
            {
                CostNode costNode = openList.Pop();
                if (costNode.cost == calcGrid[costNode.tile].costNodeCost)
                {
                    int tile = costNode.tile;
                    if (calcGrid[tile].status != statusClosedValue)
                    {
                        if (tile == destTile)
                        {
                            return(FinalizedPath(tile));
                        }
                        if (num > SearchLimit)
                        {
                            Log.Warning(string.Concat(new object[]
                            {
                                caravan,
                                " pathing from ",
                                startTile,
                                " to ",
                                destTile,
                                " hit search limit of ",
                                SearchLimit,
                                " tiles."
                            }));
                            return(WorldPath.NotFound);
                        }
                        int num4 = (tile + 1 < tileIDToNeighbors_offsets.Count) ? tileIDToNeighbors_offsets[tile + 1] : tileIDToNeighbors_values.Count;
                        for (int i = tileIDToNeighbors_offsets[tile]; i < num4; i++)
                        {
                            int num5 = tileIDToNeighbors_values[i];
                            if (calcGrid[num5].status != statusClosedValue && caravan.UniqueVehicleDefsInCaravan().All(v => WorldVehiclePathGrid.Instance.Passable(num5, v)) &&
                                (!caravan.HasBoat() || !(Find.World.CoastDirectionAt(num5).IsValid&& num5 != destTile)))
                            {
                                float  highestTerrainCost = caravan.UniqueVehicleDefsInCaravan().Max(v => movementDifficulty[v][num5]);
                                int    num6   = (int)(num2 * highestTerrainCost * VehicleCaravan_PathFollower.GetRoadMovementDifficultyMultiplier(caravan, tile, num5, null)) + calcGrid[tile].knownCost;
                                ushort status = calcGrid[num5].status;
                                if ((status != statusClosedValue && status != statusOpenValue) || calcGrid[num5].knownCost > num6)
                                {
                                    Vector3 tileCenter = grid.GetTileCenter(num5);
                                    if (status != statusClosedValue && status != statusOpenValue)
                                    {
                                        float num7 = grid.ApproxDistanceInTiles(GenMath.SphericalDistance(tileCenter.normalized, normalized));
                                        calcGrid[num5].heuristicCost = Mathf.RoundToInt(num2 * num7 * num3 * BestRoadDiscount);
                                    }
                                    int num8 = num6 + calcGrid[num5].heuristicCost;
                                    calcGrid[num5].parentTile   = tile;
                                    calcGrid[num5].knownCost    = num6;
                                    calcGrid[num5].status       = statusOpenValue;
                                    calcGrid[num5].costNodeCost = num8;
                                    openList.Push(new CostNode(num5, num8));
                                }
                            }
                        }
                        num++;
                        calcGrid[tile].status = statusClosedValue;
                        if (terminator != null && terminator(calcGrid[tile].costNodeCost))
                        {
                            return(WorldPath.NotFound);
                        }
                    }
                }
            }
            Log.Warning(string.Concat(new object[]
            {
                caravan,
                " pathing from ",
                startTile,
                " to ",
                destTile,
                " ran out of tiles to process."
            }));
            return(WorldPath.NotFound);
        }
Пример #5
0
        public WorldPath FindPath(int startTile, int destTile, Caravan caravan, Func <float, bool> terminator = null)
        {
            if (startTile < 0)
            {
                Log.Error("Tried to FindPath with invalid start tile " + startTile + ", caravan= " + caravan);
                return(WorldPath.NotFound);
            }
            if (destTile < 0)
            {
                Log.Error("Tried to FindPath with invalid dest tile " + destTile + ", caravan= " + caravan);
                return(WorldPath.NotFound);
            }
            if (caravan != null)
            {
                if (!caravan.CanReach(destTile))
                {
                    return(WorldPath.NotFound);
                }
            }
            else if (!Find.WorldReachability.CanReach(startTile, destTile))
            {
                return(WorldPath.NotFound);
            }
            World      world = Find.World;
            WorldGrid  grid  = world.grid;
            List <int> tileIDToNeighbors_offsets = grid.tileIDToNeighbors_offsets;
            List <int> tileIDToNeighbors_values  = grid.tileIDToNeighbors_values;
            Vector3    normalized = grid.GetTileCenter(destTile).normalized;

            int[] pathGrid = world.pathGrid.pathGrid;
            int   num      = 0;
            int   num2     = (caravan == null) ? 2500 : caravan.TicksPerMove;
            int   num3     = this.CalculateHeuristicStrength(startTile, destTile);

            this.statusOpenValue   += 2;
            this.statusClosedValue += 2;
            if (this.statusClosedValue >= 65435)
            {
                this.ResetStatuses();
            }
            this.calcGrid[startTile].knownCost     = 0;
            this.calcGrid[startTile].heuristicCost = 0;
            this.calcGrid[startTile].costNodeCost  = 0;
            this.calcGrid[startTile].parentTile    = startTile;
            this.calcGrid[startTile].status        = this.statusOpenValue;
            this.openList.Clear();
            this.openList.Push(new CostNode(startTile, 0));
            while (true)
            {
                if (this.openList.Count <= 0)
                {
                    Log.Warning(caravan + " pathing from " + startTile + " to " + destTile + " ran out of tiles to process.");
                    return(WorldPath.NotFound);
                }
                CostNode costNode = this.openList.Pop();
                if (costNode.cost == this.calcGrid[costNode.tile].costNodeCost)
                {
                    int tile = costNode.tile;
                    if (this.calcGrid[tile].status != this.statusClosedValue)
                    {
                        if (DebugViewSettings.drawPaths)
                        {
                            Find.WorldDebugDrawer.FlashTile(tile, (float)((float)this.calcGrid[tile].knownCost / 375000.0), this.calcGrid[tile].knownCost.ToString(), 50);
                        }
                        if (tile == destTile)
                        {
                            return(this.FinalizedPath(tile));
                        }
                        if (num > 500000)
                        {
                            Log.Warning(caravan + " pathing from " + startTile + " to " + destTile + " hit search limit of " + 500000 + " tiles.");
                            return(WorldPath.NotFound);
                        }
                        int num4 = (tile + 1 >= tileIDToNeighbors_offsets.Count) ? tileIDToNeighbors_values.Count : tileIDToNeighbors_offsets[tile + 1];
                        for (int i = tileIDToNeighbors_offsets[tile]; i < num4; i++)
                        {
                            int    num5 = tileIDToNeighbors_values[i];
                            int    num7;
                            ushort status;
                            if (this.calcGrid[num5].status != this.statusClosedValue && !world.Impassable(num5))
                            {
                                int num6 = num2;
                                num6  += pathGrid[num5];
                                num6   = (int)((float)num6 * grid.GetRoadMovementMultiplierFast(tile, num5));
                                num7   = num6 + this.calcGrid[tile].knownCost;
                                status = this.calcGrid[num5].status;
                                if (status != this.statusClosedValue && status != this.statusOpenValue)
                                {
                                    goto IL_041e;
                                }
                                if (this.calcGrid[num5].knownCost > num7)
                                {
                                    goto IL_041e;
                                }
                            }
                            continue;
IL_041e:
                            Vector3 tileCenter = grid.GetTileCenter(num5);
                            if (status != this.statusClosedValue && status != this.statusOpenValue)
                            {
                                float num8 = grid.ApproxDistanceInTiles(GenMath.SphericalDistance(tileCenter.normalized, normalized));
                                this.calcGrid[num5].heuristicCost = Mathf.RoundToInt((float)((float)num2 * num8 * (float)num3 * 0.5));
                            }
                            int num9 = num7 + this.calcGrid[num5].heuristicCost;
                            this.calcGrid[num5].parentTile   = tile;
                            this.calcGrid[num5].knownCost    = num7;
                            this.calcGrid[num5].status       = this.statusOpenValue;
                            this.calcGrid[num5].costNodeCost = num9;
                            this.openList.Push(new CostNode(num5, num9));
                        }
                        num++;
                        this.calcGrid[tile].status = this.statusClosedValue;
                        if (terminator != null && terminator((float)this.calcGrid[tile].costNodeCost))
                        {
                            break;
                        }
                    }
                }
            }
            return(WorldPath.NotFound);
        }
Пример #6
0
        public float ApproxDistanceInTiles(int firstTile, int secondTile)
        {
            Vector3 tileCenter = GetTileCenter(firstTile);

            return(ApproxDistanceInTiles(GenMath.SphericalDistance(normalizedB: GetTileCenter(secondTile).normalized, normalizedA: tileCenter.normalized)));
        }
Пример #7
0
        public WorldPath FindPath(int startTile, int destTile, Caravan caravan, Func <float, bool> terminator = null)
        {
            WorldPath notFound;

            if (startTile < 0)
            {
                Log.Error(string.Concat(new object[]
                {
                    "Tried to FindPath with invalid start tile ",
                    startTile,
                    ", caravan= ",
                    caravan
                }), false);
                notFound = WorldPath.NotFound;
            }
            else if (destTile < 0)
            {
                Log.Error(string.Concat(new object[]
                {
                    "Tried to FindPath with invalid dest tile ",
                    destTile,
                    ", caravan= ",
                    caravan
                }), false);
                notFound = WorldPath.NotFound;
            }
            else
            {
                if (caravan != null)
                {
                    if (!caravan.CanReach(destTile))
                    {
                        return(WorldPath.NotFound);
                    }
                }
                else if (!Find.WorldReachability.CanReach(startTile, destTile))
                {
                    return(WorldPath.NotFound);
                }
                World      world = Find.World;
                WorldGrid  grid  = world.grid;
                List <int> tileIDToNeighbors_offsets = grid.tileIDToNeighbors_offsets;
                List <int> tileIDToNeighbors_values  = grid.tileIDToNeighbors_values;
                Vector3    normalized         = grid.GetTileCenter(destTile).normalized;
                float[]    movementDifficulty = world.pathGrid.movementDifficulty;
                int        num  = 0;
                int        num2 = (caravan == null) ? 3500 : caravan.TicksPerMove;
                int        num3 = this.CalculateHeuristicStrength(startTile, destTile);
                this.statusOpenValue   += 2;
                this.statusClosedValue += 2;
                if (this.statusClosedValue >= 65435)
                {
                    this.ResetStatuses();
                }
                this.calcGrid[startTile].knownCost     = 0;
                this.calcGrid[startTile].heuristicCost = 0;
                this.calcGrid[startTile].costNodeCost  = 0;
                this.calcGrid[startTile].parentTile    = startTile;
                this.calcGrid[startTile].status        = this.statusOpenValue;
                this.openList.Clear();
                this.openList.Push(new WorldPathFinder.CostNode(startTile, 0));
                while (this.openList.Count > 0)
                {
                    WorldPathFinder.CostNode costNode = this.openList.Pop();
                    if (costNode.cost == this.calcGrid[costNode.tile].costNodeCost)
                    {
                        int tile = costNode.tile;
                        if (this.calcGrid[tile].status != this.statusClosedValue)
                        {
                            if (DebugViewSettings.drawPaths)
                            {
                                Find.WorldDebugDrawer.FlashTile(tile, (float)this.calcGrid[tile].knownCost / 375000f, this.calcGrid[tile].knownCost.ToString(), 50);
                            }
                            if (tile == destTile)
                            {
                                return(this.FinalizedPath(tile));
                            }
                            if (num > 500000)
                            {
                                Log.Warning(string.Concat(new object[]
                                {
                                    caravan,
                                    " pathing from ",
                                    startTile,
                                    " to ",
                                    destTile,
                                    " hit search limit of ",
                                    500000,
                                    " tiles."
                                }), false);
                                return(WorldPath.NotFound);
                            }
                            int num4 = (tile + 1 >= tileIDToNeighbors_offsets.Count) ? tileIDToNeighbors_values.Count : tileIDToNeighbors_offsets[tile + 1];
                            for (int i = tileIDToNeighbors_offsets[tile]; i < num4; i++)
                            {
                                int num5 = tileIDToNeighbors_values[i];
                                if (this.calcGrid[num5].status != this.statusClosedValue)
                                {
                                    if (!world.Impassable(num5))
                                    {
                                        int    num6   = (int)((float)num2 * movementDifficulty[num5] * grid.GetRoadMovementDifficultyMultiplier(tile, num5, null));
                                        int    num7   = num6 + this.calcGrid[tile].knownCost;
                                        ushort status = this.calcGrid[num5].status;
                                        if ((status != this.statusClosedValue && status != this.statusOpenValue) || this.calcGrid[num5].knownCost > num7)
                                        {
                                            Vector3 tileCenter = grid.GetTileCenter(num5);
                                            if (status != this.statusClosedValue && status != this.statusOpenValue)
                                            {
                                                float num8 = grid.ApproxDistanceInTiles(GenMath.SphericalDistance(tileCenter.normalized, normalized));
                                                this.calcGrid[num5].heuristicCost = Mathf.RoundToInt((float)num2 * num8 * (float)num3 * 0.5f);
                                            }
                                            int num9 = num7 + this.calcGrid[num5].heuristicCost;
                                            this.calcGrid[num5].parentTile   = tile;
                                            this.calcGrid[num5].knownCost    = num7;
                                            this.calcGrid[num5].status       = this.statusOpenValue;
                                            this.calcGrid[num5].costNodeCost = num9;
                                            this.openList.Push(new WorldPathFinder.CostNode(num5, num9));
                                        }
                                    }
                                }
                            }
                            num++;
                            this.calcGrid[tile].status = this.statusClosedValue;
                            if (terminator != null && terminator((float)this.calcGrid[tile].costNodeCost))
                            {
                                return(WorldPath.NotFound);
                            }
                        }
                    }
                }
                Log.Warning(string.Concat(new object[]
                {
                    caravan,
                    " pathing from ",
                    startTile,
                    " to ",
                    destTile,
                    " ran out of tiles to process."
                }), false);
                notFound = WorldPath.NotFound;
            }
            return(notFound);
        }