protected override void Update(TimeSpan gameTime) { if (pathSet && wo.player != null && wo.player.isLocalPlayer) { if (start != end) { if (wo.GetAction() == ActionEnum.Move) { updatedTiles.UnionWith(fog.updatedTiles); if (gScore[start] == float.PositiveInfinity || move.FullStop()) { //there is not a known path Reset(); } else { LayerTile tile = Map.map.GetTileByWorldPosition(wo.GetCenteredPosition()); if (recalculate) { recalculate = false; float minVal = float.PositiveInfinity; LayerTile nextTile = null; foreach (Point neighborPoint in fog.Adjacents(start, adjPoints)) { LayerTile s = map.GetTileByMapCoordinates(neighborPoint.X, neighborPoint.Y); if (minVal > rhs[s]) { minVal = rhs[s]; nextTile = s; } } start = nextTile; km += HeuristicCostEstimate(last, start); last = start; foreach (LayerTile s in updatedTiles) { foreach (Point neighborPoint in fog.Adjacents(s, adjPoints)) { LayerTile u = map.GetTileByMapCoordinates(neighborPoint.X, neighborPoint.Y); UpdateVertex(u); } UpdateVertex(s); } updatedTiles.Clear(); ComputeShortestPath(); SendPath(ReconstructPath()); } else if (last != tile) { //If we already visited this tile, we punish going back this way each time harder if (visitedTiles.ContainsKey(last)) { visitedTiles[last] = visitedTiles[last] * 3; } else { visitedTiles.Add(last, 1); } recalculate = true; recalculate = true; } } } } else { Reset(); } } }