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

Method handleCollision

game/state/battle/battleunit.cpp:1876–1916  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1874}
1875
1876bool BattleUnit::handleCollision(GameState &state, Collision &c)
1877{
1878 std::ignore = state;
1879
1880 // Corpses do not handle collision
1881 if (isDead())
1882 return false;
1883
1884 if (!this->tileObject)
1885 {
1886 LogError("It's possible multiple projectiles hit the same tile in the same tick (?)");
1887 return false;
1888 }
1889
1890 auto projectile = c.projectile.get();
1891 if (projectile)
1892 {
1893 auto partHit =
1894 determineBodyPartHit(projectile->damageType, c.position, projectile->velocity);
1895 // If hit in helmet with brainsucker attached -> hit brainsucker instead
1896 if (brainSucker && partHit == BodyPart::Helmet)
1897 {
1898 brainSucker->handleCollision(state, c);
1899 return false;
1900 }
1901 else
1902 {
1903 state.current_battle->giveInterruptChanceToUnit(
1904 state, {&state, id}, {&state, id},
1905 projectile->firerUnit->agent->getReactionValue());
1906 notifyHit(position - glm::normalize(projectile->velocity) * 1.41f);
1907 if (projectile->firerUnit)
1908 {
1909 projectile->firerUnit->experiencePoints.accuracy++;
1910 }
1911 return applyDamage(state, projectile->damage, projectile->damageType, partHit,
1912 DamageSource::Impact, projectile->firerUnit);
1913 }
1914 }
1915 return false;
1916}
1917
1918void BattleUnit::update(GameState &state, unsigned int ticks)
1919{

Callers 1

updateProjectilesMethod · 0.45

Calls 3

getReactionValueMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected