public void Notify_CaravanFormed(Caravan caravan) { if (this.shouldPassStoryState) { this.shouldPassStoryState = false; this.map.StoryState.CopyTo(caravan.StoryState); } if (this.nextTile != -1 && this.nextTile != caravan.Tile && caravan.CanReach(this.nextTile)) { caravan.pather.StartPath(this.nextTile, null, true, true); caravan.pather.nextTileCostLeft = caravan.pather.nextTileCostTotal * this.nextTileCostLeftPct; caravan.pather.Paused = this.paused; caravan.tweener.ResetTweenedPosToRoot(); } if (this.HasDestinationTile && this.destinationTile != caravan.Tile) { caravan.pather.StartPath(this.destinationTile, this.arrivalAction, true, true); this.destinationTile = -1; this.arrivalAction = null; } }
public void Notify_CaravanFormed(Caravan caravan) { if (shouldPassStoryState) { shouldPassStoryState = false; map.StoryState.CopyTo(caravan.StoryState); } if (nextTile != -1 && nextTile != caravan.Tile && caravan.CanReach(nextTile)) { caravan.pather.StartPath(nextTile, null, repathImmediately: true); caravan.pather.nextTileCostLeft = caravan.pather.nextTileCostTotal * nextTileCostLeftPct; caravan.pather.Paused = paused; caravan.tweener.ResetTweenedPosToRoot(); } if (HasDestinationTile && destinationTile != caravan.Tile) { caravan.pather.StartPath(destinationTile, arrivalAction, repathImmediately: true); destinationTile = -1; arrivalAction = null; } }
public WorldPath FindOceanPath(int startTile, int destTile, Caravan 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 }), false); return(WorldPath.NotFound); } if (destTile < 0) { Log.Error(string.Concat(new object[] { "Tried to FindPath with invalid dest tile ", destTile, ", caravan= ", caravan }), false); 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 != 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 > 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_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 && !HelperMethods.ImpassableModified(world, num5, startTile, destTile, caravan)) { int num6 = (int)((float)num2 * movementDifficulty[num5] * grid.GetRoadMovementDifficultyMultiplier(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((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((float)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); return(WorldPath.NotFound); }