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

Method updateFalling

game/state/city/scenery.cpp:1485–1622  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1483}
1484
1485void Scenery::updateFalling(GameState &state, unsigned int ticks)
1486{
1487 auto fallTicksRemaining = ticks;
1488 auto newPosition = currentPosition;
1489 while (fallTicksRemaining-- > 0)
1490 {
1491 fallingSpeed += FALLING_ACCELERATION_MAP_PART;
1492 newPosition -= Vec3<float>{0.0f, 0.0f, (fallingSpeed / TICK_SCALE)} / VELOCITY_SCALE_CITY;
1493 }
1494
1495 if (newPosition.z < 0)
1496 {
1497 die(state);
1498 return;
1499 }
1500
1501 // Collision happens when map part moves from this tile to the next
1502 // With this tile's Into and low Onto, as well as vehicles
1503 // With next tile's None and high Onto
1504 std::set<sp<Scenery>> killedScenery;
1505 if (floorf(newPosition.z) != floorf(currentPosition.z))
1506 {
1507 // Leaving tile: collide with everything left
1508 // NOTE: Vehicle::applyDamage() may destroy a vehicle, removing it from the map invalidating
1509 // the ownedObjects iterator, so keep a reference to all hit vehicles and process them
1510 // outside the ownedObjects iterator loop
1511 std::set<sp<Vehicle>> hitVehicles;
1512 for (auto &obj : tileObject->getOwningTile()->ownedObjects)
1513 {
1514 switch (obj->getType())
1515 {
1516 case TileObject::Type::Scenery:
1517 {
1518 auto mp = std::static_pointer_cast<TileObjectScenery>(obj)->getOwner();
1519 if (mp->tileObject && mp->isAlive())
1520 {
1521 if (mp->type->strength < type->mass)
1522 {
1523 killedScenery.insert(mp);
1524 }
1525 else
1526 {
1527 destroyed = true;
1528 }
1529 }
1530 break;
1531 }
1532 case TileObject::Type::Vehicle:
1533 {
1534 auto v = std::static_pointer_cast<TileObjectVehicle>(obj)->getVehicle();
1535 hitVehicles.insert(v);
1536
1537 break;
1538 }
1539 default:
1540 // Ignore other object types?
1541 break;
1542 }

Callers

nothing calls this directly

Calls 10

getOwningTileMethod · 0.80
insertMethod · 0.80
getVehicleMethod · 0.80
getTileMethod · 0.80
getTypeMethod · 0.45
getOwnerMethod · 0.45
isAliveMethod · 0.45
applyDamageMethod · 0.45
collapseMethod · 0.45
dieMethod · 0.45

Tested by

no test coverage detected