Esempio n. 1
0
    private bool IsWithinBounds(Position3D position)
    {
        int x = position.GetX();
        int y = position.GetY();
        int z = position.GetZ();

        if (x >= _sizeX || y >= _sizeY || z >= _sizeZ)
        {
            return(false);
        }
        return(true);
    }
Esempio n. 2
0
    //TODO maybe replace this with an arbitrary query instead of searching just by position
    //for example we might search for a list of all sources of danger within some distance
    public List <IPlaceable> GetContent(Position position)
    {
        Position3D position3D = GetPosition3D(position);

        if (position3D == null)
        {
            Debug.Log("not a position3d");
            return(null);
        }
        VoxelMap2DLayer layer = _layers[position3D.GetZ()];

        return(layer == null ? new List <IPlaceable> () : layer.GetContent(position));
    }
Esempio n. 3
0
    public bool Place(IPlaceable placeable, Position position)
    {
        Position3D position3D = position.AsPosition3D();

        if (!CanPlace(placeable, position, position3D))
        {
            return(false);
        }
        bool            addedSuccessfully = true;
        VoxelMap2DLayer layer             = _layers [position3D.GetZ()];

        if (layer == null)
        {
            layer = new VoxelMap2DLayer(_sizeX, _sizeY);
        }
        addedSuccessfully = addedSuccessfully && layer.Place(placeable, (Position)position3D);     //TODO this is sligthly inefficient because the check happens at both the 3D map and the 2D slice...
        System.Diagnostics.Debug.Assert(addedSuccessfully, "3D map and 2D slice should match in terms of whether or not this can be added");
        return(addedSuccessfully);
    }
Esempio n. 4
0
    /// <summary>
    /// Returns null if the position is not valid
    /// </summary>
    private Position3D GetPosition3D(Position position)
    {
        Position3D position3D = position.AsPosition3D();

        if (position3D == null)
        {
            Debug.Log("The position must be a position3D " + position);
            return(null);
        }
        int x = position3D.GetX();
        int y = position3D.GetY();
        int z = position3D.GetZ();

        if (x >= _sizeX || y >= _sizeY || z >= _sizeZ)
        {
            Debug.Log("The specified position is out of bounds (" + x + "," + y + "," + z + ") is outside bounds (" + _sizeX + "," + _sizeY + "," + _sizeZ + ")");
            return(null);
        }
        return(position3D);
    }