Beispiel #1
0
    private HashSet <MapCoordinate> FindMoveRange(IMBUnit mbUnit, MapCoordinate origin)
    {
        int unitMove = mbUnit.Unit.c_Mv;
        Dictionary <MapCoordinate, int> range = new Dictionary <MapCoordinate, int>();

        FindMoveRange(mbUnit, range, unitMove, origin);
        return(new HashSet <MapCoordinate>(range.Keys));
    }
Beispiel #2
0
    private void FindMoveRange(IMBUnit mbUnit, Dictionary <MapCoordinate, int> rangeOutput, int mvLeft, MapCoordinate currentNode)
    {
        if (!tiles.ContainsKey(currentNode))
        {
            return;
        }

        // If the node has been added/checked already and had more mvLeft
        if (rangeOutput.ContainsKey(currentNode) && mvLeft <= rangeOutput[currentNode])
        {
            return;
        }

        ITile currentTile = tiles.Get(currentNode).Tile;

        if (!currentTile.Traversable)
        {
            return;
        }

        // Remove mvLeft when it is not the unit's current tile
        if (rangeOutput.Count > 0)
        {
            mvLeft -= currentTile.MoveCost(mbUnit.Unit);
        }

        if (mvLeft < 0)
        {
            return;
        }

        rangeOutput[currentNode] = mvLeft;

        foreach (MapCoordinate direction in new MapCoordinate[] { MapCoordinate.UP, MapCoordinate.DOWN, MapCoordinate.LEFT, MapCoordinate.RIGHT })
        {
            MapCoordinate adjacentNode = currentNode + direction;
            FindMoveRange(mbUnit, rangeOutput, mvLeft, adjacentNode);
        }
    }
Beispiel #3
0
    private HashSet <MapCoordinate> FindAttackRange(IMBUnit mbUnit, MapCoordinate origin)
    {
        int maxAttackRange            = mbUnit.Unit.Profile.Weapon.RangeMax;
        int minAttackRange            = mbUnit.Unit.Profile.Weapon.RangeMin;
        HashSet <MapCoordinate> range = new HashSet <MapCoordinate>();

        for (int xOffset = -maxAttackRange; xOffset <= maxAttackRange; xOffset++)
        {
            int yAbsRange = maxAttackRange - Math.Abs(xOffset);
            for (int yOffset = -yAbsRange; yOffset <= yAbsRange; yOffset++)
            {
                MapCoordinate offset = new MapCoordinate(xOffset, yOffset);
                MapCoordinate tile   = origin + offset;
                if (tiles.ContainsKey(tile) &&
                    offset != new MapCoordinate(0, 0) &&
                    (Math.Abs(xOffset) + Math.Abs(yOffset) >= minAttackRange))
                {
                    range.Add(tile);
                }
            }
        }
        return(range);
    }