private void FindSelectableTiles(TileSearchType searchType, int attackCost = Constants.ATTACK_AP_COST) { ClearVisitedTiles(); AssignCurrentTile(); if (actionPoints == 0) { return; } if (actionPoints < attackCost && searchType == TileSearchType.ATTACK_ONLY) { return; } if (actionPoints < attackCost && searchType == TileSearchType.CHARGE_ATTACK) { return; } if (actionPoints < attackCost && searchType == TileSearchType.RANGED_ATTACK_ONLY) { return; } if (actionPoints < attackCost && searchType == TileSearchType.REACH_ATTACK_ONLY) { return; } if (actionPoints < attackCost && searchType == TileSearchType.ALLY_BUFF) { return; } // TODO: Replace with PriorityQueue for performance optimization List <Tile> queue = new List <Tile>(); queue.Add(currentTile); visitedTiles.Add(currentTile); currentTile.wasVisited = true; // Can buff self or ally with ally buff. if (searchType == TileSearchType.ALLY_BUFF) { selectableTiles.Add(currentTile); currentTile.isSelectable = true; } while (queue.Count > 0) { queue.Sort((item1, item2) => item1.distance.CompareTo(item2.distance)); Tile tile = queue[0]; queue.RemoveAt(0); // Only default can select tiles that end in movement. if (tile != currentTile && (searchType == TileSearchType.DEFAULT || searchType == TileSearchType.DEFAULT_RANGED || searchType == TileSearchType.DEFAULT_REACH)) { selectableTiles.Add(tile); tile.isSelectable = true; } // Potential ranged attacks if (searchType == TileSearchType.DEFAULT_RANGED || searchType == TileSearchType.RANGED_ATTACK_ONLY) { AssignRangedAttackTargets(tile, attackCost, true); } // Potential reach attacks if (searchType == TileSearchType.DEFAULT_REACH || searchType == TileSearchType.REACH_ATTACK_ONLY) { AssignReachAttackTargets(tile, attackCost); } // Potential ally buffs if (searchType == TileSearchType.ALLY_BUFF) { AssignRangedAttackTargets(tile, attackCost, false); } foreach (Tile adjacentTile in tile.adjacentTileList) { if (adjacentTile.isBlocked) { // Potential melee attacks. if (!adjacentTile.wasVisited && IsMeleeType(searchType)) { if (searchType == TileSearchType.CHARGE_ATTACK && tile.distance <= actionPoints && ContainsEnemy(adjacentTile)) { AttachTile(attackCost > tile.distance ? attackCost : tile.distance, adjacentTile, tile); selectableTiles.Add(adjacentTile); adjacentTile.isSelectable = true; } else if (tile.distance + attackCost <= actionPoints && ContainsEnemy(adjacentTile)) { AttachTile(attackCost, adjacentTile, tile); selectableTiles.Add(adjacentTile); adjacentTile.isSelectable = true; } visitedTiles.Add(adjacentTile); adjacentTile.wasVisited = true; } continue; } // Potential children in search tree. if (!adjacentTile.wasVisited || adjacentTile.IsFasterParent(tile)) { if (adjacentTile.GetTotalDistanceWithParent(tile) <= actionPoints) { // You cannot step up a stair of more than .25 meters, though you can jump down any height. if (adjacentTile.transform.position.y > tile.transform.position.y + .25f) { continue; } adjacentTile.wasVisited = true; visitedTiles.Add(adjacentTile); AttachTile(-1, adjacentTile, tile); queue.Add(adjacentTile); } } } } }
public void SetTileSearchType(TileSearchType t) { DEFAULT_ATTACK_TYPE = t; }
// Returns true for basic melee types (not reach or ranged). private bool IsMeleeType(TileSearchType searchType) { return(searchType == TileSearchType.DEFAULT || searchType == TileSearchType.ATTACK_ONLY || searchType == TileSearchType.CHARGE_ATTACK); }