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

Method determineBodyPartHit

game/state/battle/battleunit.cpp:1837–1874  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1835}
1836
1837BodyPart BattleUnit::determineBodyPartHit(StateRef<DamageType> damageType, Vec3<float> cposition,
1838 Vec3<float> direction)
1839{
1840 BodyPart bodyPartHit = BodyPart::Body;
1841
1842 // FIXME: Ensure body part determination is correct
1843 // Assume top 25% is head, lower 25% is legs, and middle 50% is body/left/right
1844 float altitude = (cposition.z - position.z) * 40.0f / (float)getCurrentHeight();
1845 if (damageType->alwaysImpactsHead()) // gas deals damage to the head
1846 {
1847 bodyPartHit = BodyPart::Helmet;
1848 }
1849 else if (altitude > 0.75f)
1850 {
1851 bodyPartHit = BodyPart::Helmet;
1852 }
1853 else if (altitude < 0.25f)
1854 {
1855 bodyPartHit = BodyPart::Legs;
1856 }
1857 else
1858 {
1859 auto unitDir = glm::normalize(Vec3<float>{facing.x, facing.y, 0.0f});
1860 auto projectileDir = glm::normalize(Vec3<float>{direction.x, direction.y, 0.0f});
1861 auto cross = glm::cross(unitDir, projectileDir);
1862 int angle =
1863 (int)((cross.z >= 0 ? -1 : 1) * glm::angle(unitDir, -projectileDir) / M_PI * 180.0f);
1864 if (angle > 45 && angle < 135)
1865 {
1866 bodyPartHit = BodyPart::RightArm;
1867 }
1868 else if (angle < -45 && angle > -135)
1869 {
1870 bodyPartHit = BodyPart::LeftArm;
1871 }
1872 }
1873 return bodyPartHit;
1874}
1875
1876bool BattleUnit::handleCollision(GameState &state, Collision &c)
1877{

Callers 2

applyEffectMethod · 0.80
damageMethod · 0.80

Calls 1

alwaysImpactsHeadMethod · 0.80

Tested by

no test coverage detected