MCPcopy Create free account
hub / github.com/OpenXcom/OpenXcom / setUnitPosition

Method setUnitPosition

src/Savegame/SavedBattleGame.cpp:1422–1465  ·  view source on GitHub ↗

* 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. */

Source from the content-addressed store, hash-verified

1420 * @return True if the unit could be successfully placed.
1421 */
1422bool 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.

Callers 5

nextStageMethod · 0.80
addXCOMUnitMethod · 0.80
addAlienMethod · 0.80
addCivilianMethod · 0.80
selectPointNearTargetMethod · 0.80

Calls 10

getMovementTypeMethod · 0.80
hasNoFloorMethod · 0.80
isBlockedMethod · 0.80
PositionClass · 0.70
getSizeMethod · 0.45
getArmorMethod · 0.45
getUnitMethod · 0.45
getTUCostMethod · 0.45
setUnitMethod · 0.45
setPositionMethod · 0.45

Tested by

no test coverage detected