Example #1
0
    public List<Hex> HexesWithinRangeContainingEnemies(Hex location, int range, Faction faction)
    {
        List<Hex> hexes_in_range = new List<Hex>();

        foreach (Unit enemy in faction.GetAllEnemyUnits())
        {
            if (this.InRange(location, enemy.location, range))
            {
                hexes_in_range.Add(enemy.location);
            }
        }

        return hexes_in_range;
        /*
        int x = (int)location.coordinate.x;
        int xMin = Mathf.Max(0, x - range * 2);
        int xMax = Mathf.Min(x_max, x + range * 2);

        int y = (int)location.coordinate.y;
        int yMin = Mathf.Max(0, y - range * 2);
        int yMax = Mathf.Min(y_max, y + range * 2);

        for (int cur_x = xMin; cur_x <= xMax; cur_x++)
        {
            for (int cur_y = yMin; cur_y <= yMax; cur_y++)
            {
                if (HexRange(location.coordinate, new Vector2(cur_x, cur_y), range))
                {
                    Hex cur_hex;
                    hex_dictionary.TryGetValue(cur_x + "," + cur_y, out cur_hex);
                    if (cur_hex.occupying_unit != null && faction.IsEnemy(cur_hex.occupying_unit))
                    {
                        hexes_in_range.Add(cur_hex);
                    }
                }
            }
        }

        return hexes_in_range;*/
    }