RectGrid.maskTiles

Select specific tiles from this slice based on a mask.

The upper left corner of the mask is positioned at the given offset. Each map tile that is overlaid with a 'true' value is included in the result. The mask is allowed to extend out of bounds - out of bounds coordinates are ignored

struct RectGrid(T)
maskTiles
(
T
)
if (
isValidMask!T
)

Parameters

offset RowCol

map coordinate on which to align the top-left corner of the mask.

mask T

a rectangular array of true/false values indicating which tiles to take. each true value takes the tile at that grid coordinate. the mask should be in row major order (indexed as maskrowcol).

Examples

Suppose you are making a strategy game, and an attack hits all tiles in a cross pattern. This attack is used on the tile at row 2, column 3. You want to check each tile that was affected to see if any unit was hit:

// cross pattern
ubyte[][] attackPattern = [
  [0,1,0]
  [1,1,1]
  [0,1,0]
];

// get tiles contained by a cross pattern centered at (2,3)
auto tilesHit = map.maskTilesAround((RowCol(2, 3), attackPattern));

// now do something with those tiles
auto unitsHit = tilesHit.map!(tile => tile.unitOnTile).filter!(unit => unit !is null);
foreach(unit ; unitsHit) unit.applySomeEffect;

Meta