コード例 #1
0
    public override void Execute()
    {
        parentMenu.gameObject.SetActive(false);
        Debug.Log("Move! - " + combatant);

        BattleOrder order = new BattleOrder();

        order.Action          = "move";
        order.SourceCombatant = combatant;

        MapManager map = GameObject.FindGameObjectWithTag("Map").GetComponent <MapManager>();
        //List<Tile> tiles = map.GetTilesInRange(combatant.Tile, combatant.Stats.Movement, false);
        List <Tile> tiles = map.GetTilesInRangeThreadsafe(combatant.Tile.TileData, combatant.Stats.Movement).ConvertAll(t => t.Tile);

        tiles = TileUtility.FilterOutOccupiedTiles(tiles);

        // TODO also maybe cache tilepicker results

        GameObject objToSpawn = new GameObject("Tile Picker - Move");

        objToSpawn.AddComponent <TilePicker>();
        TilePicker tilePicker = objToSpawn.GetComponent <TilePicker>();

        tilePicker.SetTileParamsMove(combatant);
        //tilePicker.SetTiles(tiles);
        tilePicker.battleStateTracker.previous = this.parentMenu.battleStateTracker;
        tilePicker.SetBattleOrder(order);

        parentMenu.CleanUp();
    }
コード例 #2
0
    static public List <TileData> Find(TileMap tileMap, TileData sourceTile, TileData destinationTile, int moveThroughMask)
    {
        List <TileData> shortestPath = new List <TileData>();
        List <TileData> unvisited    = new List <TileData>(tileMap.TileDataList);

        FindShorestPathDTO dto = new FindShorestPathDTO();

        dto.Destination     = destinationTile;
        dto.MoveThroughMask = moveThroughMask;
        if (moveThroughMask != TeamId.MOVE_THROUGH_ALL)
        {
            unvisited = TileUtility.FilterOutOccupiedTiles(unvisited, moveThroughMask);             // TODO support enemyteam
            unvisited.Add(sourceTile);
        }

        dto.TileToDistance.Add(sourceTile, 0);
        TileData currentTile = null;
        int      count       = 0;

        while (unvisited.Count > 0 && count < 100)
        {
            count++;
            currentTile = TileWithMinDistance(dto.TileToDistance, unvisited);
            unvisited.Remove(currentTile);
            CalculateDistanceAndUpdatePath(currentTile, tileMap.TopNeighbor(currentTile), dto);
            CalculateDistanceAndUpdatePath(currentTile, tileMap.BottomNeighbor(currentTile), dto);
            CalculateDistanceAndUpdatePath(currentTile, tileMap.LeftNeighbor(currentTile), dto);
            CalculateDistanceAndUpdatePath(currentTile, tileMap.RightNeighbor(currentTile), dto);
        }

        Debug.Log("starting return path - " + count);

        TileData returnTile = destinationTile;

        shortestPath.Add(returnTile);
        count = 0;
        while (returnTile != sourceTile && count < 100)
        {
            count++;
            Debug.Log("finding last hop for " + returnTile.ToString());
            try {
                returnTile = dto.TileToOptimalPrevious[returnTile];
            } catch (Exception ex) {
                Debug.LogError(ex);
                Debug.LogError("oh shit error couldn't find " + returnTile.ToString());
            }
            Debug.Log("found " + returnTile);
            shortestPath.Add(returnTile);
        }
        Debug.Log("finish return path - TILEDATA");
        shortestPath.Reverse();
        return(shortestPath);
    }
コード例 #3
0
    static public List <Tile> Find(TileMap tileMap, Tile sourceTile, Tile destinationTile, bool moveThroughOccupied)
    {
        List <Tile> shortestPath = new List <Tile>();

        Dictionary <Tile, int>  tileToDistance        = new Dictionary <Tile, int>();
        Dictionary <Tile, Tile> tileToOptimalPrevious = new Dictionary <Tile, Tile>();
        List <Tile>             unvisited             = new List <Tile>(tileMap.GetTiles());

        if (!moveThroughOccupied)
        {
            unvisited = TileUtility.FilterOutOccupiedTiles(unvisited);
            unvisited.Add(sourceTile);
        }

        tileToDistance.Add(sourceTile, 0);

        Tile currentTile = null;
        int  count       = 0;

        while (unvisited.Count > 0 && count < 100)
        {
            count++;
            currentTile = TileWithMinDistance(tileToDistance, unvisited);
            unvisited.Remove(currentTile);
            CalculateDistanceAndUpdatePath(currentTile, tileMap.TopNeighbor(currentTile), tileToDistance, tileToOptimalPrevious, moveThroughOccupied);
            CalculateDistanceAndUpdatePath(currentTile, tileMap.BottomNeighbor(currentTile), tileToDistance, tileToOptimalPrevious, moveThroughOccupied);
            CalculateDistanceAndUpdatePath(currentTile, tileMap.LeftNeighbor(currentTile), tileToDistance, tileToOptimalPrevious, moveThroughOccupied);
            CalculateDistanceAndUpdatePath(currentTile, tileMap.RightNeighbor(currentTile), tileToDistance, tileToOptimalPrevious, moveThroughOccupied);
        }

        Debug.Log("starting return path - " + count);

        Tile returnTile = destinationTile;

        shortestPath.Add(returnTile);
        count = 0;
        while (returnTile != sourceTile && count < 100)
        {
            count++;
            Debug.Log("finding last hop for " + returnTile.TileData);
            returnTile = tileToOptimalPrevious[returnTile];
            Debug.Log("found " + returnTile.LocationString());
            shortestPath.Add(returnTile);
        }
        Debug.Log("finish return path");
        shortestPath.Reverse();
        return(shortestPath);
    }
コード例 #4
0
    public void SetCombatant(Combatant combatant)
    {
        this.combatant = combatant;
        sourceTile     = combatant.Tile;
        MapManager  map   = GameObject.FindGameObjectWithTag("Map").GetComponent <MapManager>();
        List <Tile> tiles = map.GetTilesInRange(combatant.Tile, 3, false);

        tiles = TileUtility.FilterOutOccupiedTiles(tiles);


        GameObject objToSpawn;

        objToSpawn = new GameObject("Tile Picker");
        objToSpawn.AddComponent <TilePicker>();
        tilePicker = objToSpawn.GetComponent <TilePicker>();
        tilePicker.SetTiles(tiles);
    }
コード例 #5
0
 private void FindTilesInRange()
 {
     this.TileResults = map.GetTilesInRangeThreadsafe(combatant.Tile.TileData, combatant.Stats.Movement);
     this.TileResults = TileUtility.FilterOutOccupiedTiles(this.TileResults);
     this.isDone      = true;
 }