예제 #1
0
        private WorldPath GenerateNewPath()
        {
            int num = (!moving || nextTile < 0 || !IsNextTilePassable()) ? warObject.Tile : nextTile;

            lastPathedTargetTile = destTile;
            WorldPath worldPath = Verse.Find.WorldPathFinder.FindPath(num, destTile, null); //caravan=null

            if (worldPath.Found && num != warObject.Tile)
            {
                if (worldPath.NodesLeftCount >= 2 && worldPath.Peek(1) == warObject.Tile)
                {
                    worldPath.ConsumeNextNode();
                    if (moving)
                    {
                        previousTileForDrawingIfInDoubt = nextTile;
                        nextTile         = warObject.Tile;
                        nextTileCostLeft = nextTileCostTotal - nextTileCostLeft;
                    }
                }
                else
                {
                    worldPath.AddNodeAtStart(warObject.Tile);
                }
            }
            return(worldPath);
        }
        private WorldPath GenerateNewPath()
        {
            int num = (moving && nextTile >= 0 && IsNextTilePassable()) ? nextTile : caravan.Tile;

            lastPathedTargetTile = destTile;
            WorldPath worldPath = WorldVehiclePathfinder.Instance.FindPath(num, destTile, caravan, null);

            if (worldPath.Found && num != caravan.Tile)
            {
                if (worldPath.NodesLeftCount >= 2 && worldPath.Peek(1) == caravan.Tile)
                {
                    worldPath.ConsumeNextNode();
                    if (moving)
                    {
                        previousTileForDrawingIfInDoubt = nextTile;
                        nextTile         = caravan.Tile;
                        nextTileCostLeft = nextTileCostTotal - nextTileCostLeft;
                    }
                }
                else
                {
                    worldPath.AddNodeAtStart(caravan.Tile);
                }
            }
            return(worldPath);
        }
        private void SetupMoveIntoNextTile()
        {
            if (curPath.NodesLeftCount < 2)
            {
                Log.Error(string.Concat(new object[]
                {
                    caravan,
                    " at ",
                    caravan.Tile,
                    " ran out of path nodes while pathing to ",
                    destTile,
                    "."
                }));
                PatherFailed();
                return;
            }
            nextTile = curPath.ConsumeNextNode();
            previousTileForDrawingIfInDoubt = -1;
            if (!IsPassable(nextTile))
            {
                Log.Error(string.Concat(new object[]
                {
                    caravan,
                    " entering ",
                    nextTile,
                    " which is unwalkable."
                }));
            }
            int num = CostToMove(caravan.Tile, nextTile);

            nextTileCostTotal = num;
            nextTileCostLeft  = num;
        }
예제 #4
0
        public bool testPath(WorldPath path)
        {
            WorldGrid grid     = Find.WorldGrid;
            WorldPath testpath = new WorldPath();

            testpath = path;
            List <int> nodeList = (List <int>)(typeof(WorldPath).GetField("nodes", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance).GetValue(testpath));

            typeof(WorldPath).GetField("curNodeIndex", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance).SetValue(testpath, nodeList.Count - 1, System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance, null, null);

            int  nodes    = testpath.NodesLeftCount;
            int  prevtile = testpath.FirstNode;
            int  tile;
            bool hasRoad = true;

            for (int i = 0; i < nodes - 1; i++)
            {
                if (testpath.NodesLeftCount == 1)
                {
                    tile = testpath.LastNode;
                }
                else
                {
                    tile = testpath.ConsumeNextNode();
                }

                RoadDef def = grid.GetRoadDef(prevtile, tile);
                if (def == roadDef)
                {
                    prevtile = tile;
                    continue;
                }
                if (def != null && isNewRoadBetter(def, roadDef))
                {
                    return(false); //road creatable
                }
                else if (def == null)
                {
                    return(false); //road creatable
                }
                else               //if road exists, but new road is not better
                {
                    //Make no changes
                }



                prevtile = tile;
                continue;
            }

            return(true);
        }
예제 #5
0
 private void SetupMoveIntoNextTile()
 {
     if (curPath.NodesLeftCount < 2)
     {
         Log.Error(warObject + " at " + warObject.Tile + " ran out of path nodes while pathing to " + destTile + ".");
         PatherFailed();
     }
     else
     {
         nextTile = curPath.ConsumeNextNode();
         previousTileForDrawingIfInDoubt = -1;
         if (Verse.Find.World.Impassable(nextTile))
         {
             Log.Error(warObject + " entering " + nextTile + " which is unwalkable.");
         }
         int num = CostToMove(warObject.Tile, nextTile);
         nextTileCostTotal = (float)(num);
         nextTileCostLeft  = (float)(num);
     }
 }
예제 #6
0
        public void createNextSegment(FCRoadBuilderQueue queue)
        {
            WorldGrid grid = Find.WorldGrid;
            int       num  = 1;
            //Log.Message("Loop initiated =====");
            List <int>       tilesConstructed = new List <int>();
            List <WorldPath> removeQueue      = new List <WorldPath>();

            foreach (WorldPath path in queue.ToBuild)
            {
                //Log.Message(num + " - start");
                num += 1;
                List <int> nodeList = (List <int>)(typeof(WorldPath).GetField("nodes", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance).GetValue(path));
                typeof(WorldPath).GetField("curNodeIndex", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance).SetValue(path, nodeList.Count - 1, System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance, null, null);
                //Log.Message("New Path - " + nodeList.Count());
                WorldPath newPath = new WorldPath();
                newPath = path;
                int nodes    = newPath.NodesLeftCount;
                int prevtile = newPath.FirstNode;
                int tile;

                //create segments
                //check if segment already has road
                //if not, create segment and return

                //do same but backwards
                for (int i = 0; i < nodes - 1; i++)
                {
                    if (newPath.NodesLeftCount == 1)
                    {
                        tile = newPath.LastNode;
                    }
                    else
                    {
                        tile = newPath.ConsumeNextNode();
                    }
                    if (tilesConstructed.Contains(prevtile))
                    {
                        //Log.Message(num + " tried to make a road from an already constructed tile");
                        goto Next;
                    }

                    //Log.Message(tile + "n - o" + prevtile);
                    RoadDef def = grid.GetRoadDef(prevtile, tile);
                    if (def == roadDef)
                    {
                        prevtile = tile;
                        continue;
                    }
                    if (def != null && isNewRoadBetter(def, roadDef))
                    {
                        grid.tiles[prevtile].potentialRoads.RemoveAll((Tile.RoadLink rl) => rl.neighbor == tile);
                        grid.tiles[tile].potentialRoads.RemoveAll((Tile.RoadLink rl) => rl.neighbor == prevtile);

                        grid.tiles[prevtile].potentialRoads.Add(new Tile.RoadLink {
                            neighbor = tile, road = roadDef
                        });
                        grid.tiles[tile].potentialRoads.Add(new Tile.RoadLink {
                            neighbor = prevtile, road = roadDef
                        });
                        tilesConstructed.Add(tile);
                    }
                    else if (def == null)  //if null
                    {
                        if (grid.tiles[prevtile].potentialRoads == null)
                        {
                            grid.tiles[prevtile].potentialRoads = new List <Tile.RoadLink>();
                        }
                        if (grid.tiles[tile].potentialRoads == null)
                        {
                            grid.tiles[tile].potentialRoads = new List <Tile.RoadLink>();
                        }
                        grid.tiles[prevtile].potentialRoads.Add(new Tile.RoadLink {
                            neighbor = tile, road = roadDef
                        });
                        grid.tiles[tile].potentialRoads.Add(new Tile.RoadLink {
                            neighbor = prevtile, road = roadDef
                        });
                        tilesConstructed.Add(tile);
                        if (tile == newPath.LastNode)
                        {
                            //Log.Message("Removed " + num + " from queue");
                            removeQueue.Add(path);
                        }
                    }
                    else
                    {
                        prevtile = tile;
                        continue;
                    }

                    //Regen worldmap
                    try
                    {
                        Find.World.renderer.SetDirty <WorldLayer_Roads>();
                        Find.World.renderer.SetDirty <WorldLayer_Paths>();
                        Find.WorldPathGrid.RecalculatePerceivedMovementDifficultyAt(prevtile);
                        Find.WorldPathGrid.RecalculatePerceivedMovementDifficultyAt(tile);
                    }
                    catch (Exception e)
                    {
                    }
                    //Log.Message("Created road step");
                    goto Next;
                }
Next:
                continue;
            }

            foreach (WorldPath queueRemove in removeQueue)
            {
                //Log.Message("Removing queue");
                queue.ToBuild.Remove(queueRemove);
            }
        }