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

Method isWithinVision

game/state/battle/battleunit.cpp:307–355  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

305}
306
307bool BattleUnit::isWithinVision(Vec3<int> pos)
308{
309 auto diff = pos - (Vec3<int>)position;
310 // Distance quick check
311 if (diff.x * diff.x + diff.y * diff.y > VIEW_DISTANCE * VIEW_DISTANCE)
312 {
313 return false;
314 }
315 // Static units have 360 vision
316 if (agent->type->bodyType->allowed_movement_states.size() == 1)
317 {
318 return true;
319 }
320 // Facing: Any, check if we're at the correct side
321 if (diff.x * facing.x < 0 || diff.y * facing.y < 0)
322 {
323 return false;
324 }
325 // Facing: Diagonally
326 if (facing.x != 0 && facing.y != 0)
327 {
328 // Nothing to be done, we already checked above
329 }
330 // Facing: Along one of axes
331 else
332 {
333 // Facing: Along X
334 if (facing.x != 0)
335 {
336 // Already checked if we're at the correct side above
337 // Now we only need to check if we're inside the cone
338 if (std::abs(diff.x) < std::abs(diff.y))
339 {
340 return false;
341 }
342 }
343 // Facing: Along Y
344 else
345 {
346 // Already checked if we're at the correct side above
347 // Now we only need to check if we're inside the cone
348 if (std::abs(diff.x) > std::abs(diff.y))
349 {
350 return false;
351 }
352 }
353 }
354 return true;
355}
356
357void BattleUnit::calculateVisionToTerrain(GameState &state)
358{

Callers 1

refreshUnitVisibilityMethod · 0.80

Calls 1

sizeMethod · 0.45

Tested by

no test coverage detected