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

Method calculateVisionToUnit

game/state/battle/battleunit.cpp:574–599  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

572}
573
574bool BattleUnit::calculateVisionToUnit(GameState &state, BattleUnit &u)
575{
576 auto eyesPos = getEyeLocation();
577 auto &map = *state.current_battle->map;
578
579 // Unit unconscious, we own this unit or can't see it, skip
580 if (!u.isConscious() || u.owner == owner || !isWithinVision(u.position))
581 {
582 return false;
583 }
584 auto target = u.tileObject->getCenter();
585 if (u.isLarge())
586 {
587 // Offset search for large units as they can get caught up in ground
588 // that is supposed to allow units to go through it but blocks LOS
589 auto targetvVectorDelta = glm::normalize(target - eyesPos) * 0.75f;
590 target -= targetvVectorDelta;
591 }
592 auto c = map.findCollision(eyesPos, target, mapPartSet, tileObject, true, false,
593 VIEW_DISTANCE / (u.isCloaked() ? 2 : 1));
594 if (c || c.outOfRange)
595 {
596 return false;
597 }
598 return true;
599}
600
601void BattleUnit::calculateVisionToUnits(GameState &state)
602{

Callers

nothing calls this directly

Calls 5

isConsciousMethod · 0.80
getCenterMethod · 0.80
isLargeMethod · 0.80
findCollisionMethod · 0.80
isCloakedMethod · 0.45

Tested by

no test coverage detected