* Get neighbouring tile from the map. * @param pos Current position. * @param dir Direction of neighbouring tile, only horizontal and * vertical directions are supported. * @param defaultTile Tile to return if off-map. * @return The tile in the indicated direction. If tile is off-world or an * incorrect direction is given, \c DIRT is returned. */
| 393 | * incorrect direction is given, \c DIRT is returned. |
| 394 | */ |
| 395 | MapTile Micropolis::getTileFromMap(const Position &pos, |
| 396 | Direction2 dir, MapTile defaultTile) |
| 397 | { |
| 398 | switch (dir) { |
| 399 | |
| 400 | case DIR2_NORTH: |
| 401 | if (pos.posY > 0) { |
| 402 | return map[pos.posX][pos.posY - 1] & LOMASK; |
| 403 | } |
| 404 | |
| 405 | return defaultTile; |
| 406 | |
| 407 | case DIR2_EAST: |
| 408 | if (pos.posX < WORLD_W - 1) { |
| 409 | return map[pos.posX + 1][pos.posY] & LOMASK; |
| 410 | } |
| 411 | |
| 412 | return defaultTile; |
| 413 | |
| 414 | case DIR2_SOUTH: |
| 415 | if (pos.posY < WORLD_H - 1) { |
| 416 | return map[pos.posX][pos.posY + 1] & LOMASK; |
| 417 | } |
| 418 | |
| 419 | return defaultTile; |
| 420 | |
| 421 | case DIR2_WEST: |
| 422 | if (pos.posX > 0) { |
| 423 | return map[pos.posX - 1][pos.posY] & LOMASK; |
| 424 | } |
| 425 | |
| 426 | return defaultTile; |
| 427 | |
| 428 | default: |
| 429 | return defaultTile; |
| 430 | |
| 431 | } |
| 432 | } |
| 433 | |
| 434 | |
| 435 | /** |
nothing calls this directly
no outgoing calls
no test coverage detected