Exemple #1
0
    private bool CheckWalkable(int x, int y)
    {
        MapNode      node  = MapLogic.Instance.Nodes[x, y];
        uint         tile  = node.Tile;
        MapNodeFlags flags = node.Flags;

        if ((!flags.HasFlag(MapNodeFlags.Unblocked) && (tile >= 0x1C0 && tile <= 0x2FF)) ||      // blocked by ground terrain
            flags.HasFlag(MapNodeFlags.BlockedGround)) // or blocked explicitly
        {
            return(false);                             // not walkable
        }
        return(true);                                  // walkable
    }
Exemple #2
0
    // returns true if cell is walkable for this unit
    public bool CheckWalkableForUnit(int x, int y, bool staticOnly)
    {
        if (x < 8 || x > MapLogic.Instance.Width - 8 ||
            y < 8 || y > MapLogic.Instance.Height - 8)
        {
            return(false);
        }
        for (int ly = y; ly < y + Unit.Height; ly++)
        {
            for (int lx = x; lx < x + Unit.Width; lx++)
            {
                MapNode node = MapLogic.Instance.Nodes[lx, ly];
                // skip cells currently taken
                if (node.Objects.Contains(Unit))
                {
                    continue; // if we are already on this cell, skip it as passible
                }
                uint         tile  = node.Tile;
                MapNodeFlags flags = node.Flags;
                if (Unit.IsWalking && !flags.HasFlag(MapNodeFlags.Unblocked) && flags.HasFlag(MapNodeFlags.BlockedTerrain))
                {
                    return(false);
                }
                MapNodeFlags bAir    = staticOnly ? MapNodeFlags.BlockedAir : MapNodeFlags.BlockedAir | MapNodeFlags.DynamicAir;
                MapNodeFlags bGround = staticOnly ? MapNodeFlags.BlockedGround : MapNodeFlags.BlockedGround | MapNodeFlags.DynamicGround;
                if (Unit.IsFlying && (flags & bAir) != 0)
                {
                    return(false);
                }
                else if (!Unit.IsFlying && (flags & bGround) != 0)
                {
                    return(false);
                }
            }
        }

        return(true);
    }