private void SelectUnit(GridController gridController) { SelectUnit(gridController, tile.LinkedUnit, tile); }
private void Awake() { levelController = Harmony.Finder.LevelController; gridController = Harmony.Finder.GridController; }
private static List <Tile> FindPath( GridController grid, int[,] movementCosts, List <Tile> path, Vector2Int from, Vector2Int to, Unit unit ) { //Exit statement if path impossible if (CheckIfTileInaccessible(to, movementCosts)) { List <Tile> emptyPath = new List <Tile>(); emptyPath.Add(grid.TileArray[from.x, from.y]); return(emptyPath); } //Exit statement when path is found if (grid.TileArray[from.x, from.y].Equals(grid.TileArray[to.x, to.y])) { path.Remove(null); path.Reverse(); if (unit.IsEnemy && path.Count > 0) { Tile lastTileInTurn = path.Last(); for (int i = 0; i < path.Count - 1; i++) { var nexTileLogicalPosition = path[i + 1].LogicalPosition; if (movementCosts[nexTileLogicalPosition.x, nexTileLogicalPosition.y] > unit.MovesLeft) { lastTileInTurn = path[i]; i = path.Count; } } if (lastTileInTurn != null && !lastTileInTurn.IsAvailable) { TileType lastTileType = lastTileInTurn.TileType; grid.TileArray[lastTileInTurn.LogicalPosition.x, lastTileInTurn.LogicalPosition.y].MakeObstacle(); movementCosts = ComputeCost(from, unit.IsEnemy); var t = grid.TileArray[lastTileInTurn.LogicalPosition.x, lastTileInTurn.LogicalPosition.y]; grid.TileArray[lastTileInTurn.LogicalPosition.x, lastTileInTurn.LogicalPosition.y].UnMakeObstacle(lastTileType); int lastIndex = path.Count - 1; return(FindPath(grid, movementCosts, new List <Tile>(), new Vector2Int(path[0].LogicalPosition.x, path[0].LogicalPosition.y), new Vector2Int(path[lastIndex].LogicalPosition.x, path[lastIndex].LogicalPosition.y), unit)); } } return(path); } path.Add(null); Vector2Int target = new Vector2Int(-1, -1); //Check Down target = CheckDownMovement(grid, movementCosts, path, to, target, unit.IsEnemy); //Check Right target = CheckRightMovement(grid, movementCosts, path, to, target, unit.IsEnemy); //Check Up target = CheckUpMovement(grid, movementCosts, path, to, target, unit.IsEnemy); //Check Left target = CheckLeftMovement(grid, movementCosts, path, to, target, unit.IsEnemy); return(FindPath(grid, movementCosts, path, from, target, unit)); }