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

Method updateProjectiles

game/state/battle/battle.cpp:1356–1421  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1354}
1355
1356void Battle::updateProjectiles(GameState &state, unsigned int ticks)
1357{
1358 for (auto it = this->projectiles.begin(); it != this->projectiles.end();)
1359 {
1360 auto p = *it++;
1361 p->update(state, ticks);
1362 }
1363 // Since projectiles can kill projectiles just kill everyone in the end
1364 std::set<std::tuple<sp<Projectile>, bool, bool>> deadProjectiles;
1365 for (auto &p : projectiles)
1366 {
1367 notifyAction(p->position);
1368 auto c = p->checkProjectileCollision(*map);
1369 if (c)
1370 {
1371 // Alert intended unit that he's on fire
1372 auto unit = c.projectile->trackedUnit;
1373 if (unit)
1374 {
1375 unit->notifyUnderFire(state, c.projectile->firerPosition,
1376 c.projectile->firerUnit->owner == unit->owner ||
1377 visibleUnits[unit->owner].find(c.projectile->firerUnit) !=
1378 visibleUnits[unit->owner].end());
1379 }
1380 // Handle collision
1381 bool playSound = true;
1382 bool displayDoodad = true;
1383 if (c.projectile->damageType->explosive)
1384 {
1385 displayDoodad = false;
1386 }
1387 else
1388 {
1389 switch (c.obj->getType())
1390 {
1391 case TileObject::Type::Unit:
1392 {
1393 auto unit =
1394 std::static_pointer_cast<TileObjectBattleUnit>(c.obj)->getUnit();
1395 displayDoodad = !unit->handleCollision(state, c);
1396 playSound = false;
1397 break;
1398 }
1399 case TileObject::Type::Ground:
1400 case TileObject::Type::LeftWall:
1401 case TileObject::Type::RightWall:
1402 case TileObject::Type::Feature:
1403 {
1404 auto mapPartTile = std::static_pointer_cast<TileObjectBattleMapPart>(c.obj);
1405 displayDoodad = !mapPartTile->getOwner()->handleCollision(state, c);
1406 playSound = displayDoodad;
1407 break;
1408 }
1409 default:
1410 LogError("Collision with non-collidable object");
1411 }
1412 }
1413 deadProjectiles.emplace(c.projectile->shared_from_this(), displayDoodad, playSound);

Callers

nothing calls this directly

Calls 10

endMethod · 0.80
getUnitMethod · 0.80
beginMethod · 0.45
updateMethod · 0.45
notifyUnderFireMethod · 0.45
getTypeMethod · 0.45
handleCollisionMethod · 0.45
getOwnerMethod · 0.45
dieMethod · 0.45

Tested by

no test coverage detected