MCPcopy Create free account
hub / github.com/OpenApoc/OpenApoc / canProne

Method canProne

game/state/battle/battleunit.cpp:1517–1548  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1515}
1516
1517bool BattleUnit::canProne(Vec3<int> pos, Vec2<int> fac) const
1518{
1519 if (isLarge())
1520 {
1521 LogError("Large unit attempting to go prone? WTF? Should large units ever acces this?");
1522 return false;
1523 }
1524 // Check if agent can go prone and stand in its current tile
1525 if (!agent->isBodyStateAllowed(BodyState::Prone) || !tileObject->getOwningTile()->getCanStand())
1526 return false;
1527 // Check if agent can put legs in the tile behind. Conditions
1528 // 1) Target tile provides standing ability
1529 // 2) Target tile height is not too big compared to current tile
1530 // 3) Target tile is passable
1531 // 4) Target tile has no unit occupying it (other than us)
1532 Vec3<int> legsPos = pos - Vec3<int>{fac.x, fac.y, 0};
1533 if ((legsPos.x >= 0) && (legsPos.x < tileObject->map.size.x) && (legsPos.y >= 0) &&
1534 (legsPos.y < tileObject->map.size.y) && (legsPos.z >= 0) &&
1535 (legsPos.z < tileObject->map.size.z))
1536 {
1537 auto bodyTile = tileObject->map.getTile(pos);
1538 auto legsTile = tileObject->map.getTile(legsPos);
1539 if (legsTile->canStand && bodyTile->canStand &&
1540 std::abs(legsTile->height - bodyTile->height) <= 0.25f &&
1541 legsTile->getPassable(false, agent->type->bodyType->height.at(BodyState::Prone)) &&
1542 (legsPos == (Vec3<int>)position || !legsTile->getUnitIfPresent(true, true)))
1543 {
1544 return true;
1545 }
1546 }
1547 return false;
1548}
1549
1550bool BattleUnit::canKneel() const
1551{

Callers 1

advanceAlongPathMethod · 0.80

Calls 6

isBodyStateAllowedMethod · 0.80
getCanStandMethod · 0.80
getOwningTileMethod · 0.80
getTileMethod · 0.80
getPassableMethod · 0.80
getUnitIfPresentMethod · 0.80

Tested by

no test coverage detected