* Calculates the amount of power that is blocked going from one tile to another on the same level. * @param startTile The tile where the power starts. * @param endTile The adjacent tile where the power ends. * @param type The type of power/damage. * @return Amount of blockage. */
| 1508 | * @return Amount of blockage. |
| 1509 | */ |
| 1510 | int TileEngine::horizontalBlockage(Tile *startTile, Tile *endTile, ItemDamageType type) |
| 1511 | { |
| 1512 | static const Position oneTileNorth = Position(0, -1, 0); |
| 1513 | static const Position oneTileEast = Position(1, 0, 0); |
| 1514 | static const Position oneTileSouth = Position(0, 1, 0); |
| 1515 | static const Position oneTileWest = Position(-1, 0, 0); |
| 1516 | |
| 1517 | // safety check |
| 1518 | if (startTile == 0 || endTile == 0) return 0; |
| 1519 | if (startTile->getPosition().z != endTile->getPosition().z) return 0; |
| 1520 | |
| 1521 | int direction; |
| 1522 | Pathfinding::vectorToDirection(endTile->getPosition() - startTile->getPosition(), direction); |
| 1523 | if (direction == -1) return 0; |
| 1524 | int block = 0; |
| 1525 | |
| 1526 | switch(direction) |
| 1527 | { |
| 1528 | case 0: // north |
| 1529 | block = blockage(startTile, MapData::O_NORTHWALL, type); |
| 1530 | break; |
| 1531 | case 1: // north east |
| 1532 | if (type == DT_NONE) //this is two-way diagonal visiblity check, used in original game |
| 1533 | { |
| 1534 | block = blockage(startTile, MapData::O_NORTHWALL, type) + blockage(endTile, MapData::O_WESTWALL, type); //up+right |
| 1535 | block += blockage(_save->getTile(startTile->getPosition() + oneTileNorth), MapData::O_OBJECT, type, 3); |
| 1536 | if (block == 0) break; //this way is opened |
| 1537 | block = blockage(_save->getTile(startTile->getPosition() + oneTileEast), MapData::O_NORTHWALL, type) |
| 1538 | + blockage(_save->getTile(startTile->getPosition() + oneTileEast), MapData::O_WESTWALL, type); //right+up |
| 1539 | block += blockage(_save->getTile(startTile->getPosition() + oneTileEast), MapData::O_OBJECT, type, 7); |
| 1540 | } |
| 1541 | else |
| 1542 | { |
| 1543 | block = (blockage(startTile,MapData::O_NORTHWALL, type) + blockage(endTile,MapData::O_WESTWALL, type))/2 |
| 1544 | + (blockage(_save->getTile(startTile->getPosition() + oneTileEast),MapData::O_WESTWALL, type) |
| 1545 | + blockage(_save->getTile(startTile->getPosition() + oneTileEast),MapData::O_NORTHWALL, type))/2; |
| 1546 | |
| 1547 | if (!endTile->getMapData(MapData::O_OBJECT)) |
| 1548 | { |
| 1549 | block += (blockage(_save->getTile(startTile->getPosition() + oneTileEast),MapData::O_OBJECT, type, direction) |
| 1550 | + blockage(_save->getTile(startTile->getPosition() + oneTileNorth),MapData::O_OBJECT, type, 4) |
| 1551 | + blockage(_save->getTile(startTile->getPosition() + oneTileNorth),MapData::O_OBJECT, type, 2))/2; |
| 1552 | } |
| 1553 | } |
| 1554 | break; |
| 1555 | case 2: // east |
| 1556 | block = blockage(endTile,MapData::O_WESTWALL, type); |
| 1557 | break; |
| 1558 | case 3: // south east |
| 1559 | if (type == DT_NONE) |
| 1560 | { |
| 1561 | block = blockage(_save->getTile(startTile->getPosition() + oneTileSouth), MapData::O_NORTHWALL, type) |
| 1562 | + blockage(endTile, MapData::O_WESTWALL, type); //down+right |
| 1563 | block += blockage(_save->getTile(startTile->getPosition() + oneTileSouth), MapData::O_OBJECT, type, 1); |
| 1564 | if (block == 0) break; //this way is opened |
| 1565 | block = blockage(_save->getTile(startTile->getPosition() + oneTileEast), MapData::O_WESTWALL, type) |
| 1566 | + blockage(endTile, MapData::O_NORTHWALL, type); //right+down |
| 1567 | block += blockage(_save->getTile(startTile->getPosition() + oneTileEast), MapData::O_OBJECT, type, 5); |
no test coverage detected