* Places units on the map. Handles large units that are placed on multiple tiles. * @param bu The unit to be placed. * @param position The position to place the unit. * @param testOnly If true then just checks if the unit can be placed at the position. * @return True if the unit could be successfully placed. */
| 1420 | * @return True if the unit could be successfully placed. |
| 1421 | */ |
| 1422 | bool SavedBattleGame::setUnitPosition(BattleUnit *bu, const Position &position, bool testOnly) |
| 1423 | { |
| 1424 | int size = bu->getArmor()->getSize() - 1; |
| 1425 | |
| 1426 | // first check if the tiles are occupied |
| 1427 | for (int x = size; x >= 0; x--) |
| 1428 | { |
| 1429 | for (int y = size; y >= 0; y--) |
| 1430 | { |
| 1431 | Tile *t = getTile(position + Position(x,y,0)); |
| 1432 | Tile *tb = getTile(position + Position(x,y,-1)); |
| 1433 | if (t == 0 || (t->getUnit() != 0 && t->getUnit() != bu) || t->getTUCost(MapData::O_OBJECT, bu->getArmor()->getMovementType()) == 255 || (t->hasNoFloor(tb) && bu->getArmor()->getMovementType() != MT_FLY)) |
| 1434 | { |
| 1435 | return false; |
| 1436 | } |
| 1437 | } |
| 1438 | } |
| 1439 | |
| 1440 | if (size > 0) |
| 1441 | { |
| 1442 | getPathfinding()->setUnit(bu); |
| 1443 | for (int dir = 2; dir <= 4; ++dir) |
| 1444 | { |
| 1445 | if (getPathfinding()->isBlocked(getTile(position), 0, dir, 0)) |
| 1446 | return false; |
| 1447 | } |
| 1448 | } |
| 1449 | |
| 1450 | if (testOnly) return true; |
| 1451 | |
| 1452 | for (int x = size; x >= 0; x--) |
| 1453 | { |
| 1454 | for (int y = size; y >= 0; y--) |
| 1455 | { |
| 1456 | if (x==0 && y==0) |
| 1457 | { |
| 1458 | bu->setPosition(position); |
| 1459 | } |
| 1460 | getTile(position + Position(x,y,0))->setUnit(bu, getTile(position + Position(x,y,-1))); |
| 1461 | } |
| 1462 | } |
| 1463 | |
| 1464 | return true; |
| 1465 | } |
| 1466 | |
| 1467 | /** |
| 1468 | * @brief Checks whether anyone on a particular faction is looking at the unit. |
no test coverage detected