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

Method calculateVisionToTerrain

game/state/battle/battleunit.cpp:357–418  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

355}
356
357void BattleUnit::calculateVisionToTerrain(GameState &state)
358{
359 auto &battle = *state.current_battle;
360
361 static const int lazyLimit = 5 * 9;
362 std::set<int> discoveredBlocks;
363 auto &visibleBlocks = battle.visibleBlocks.at(owner);
364
365 // Update unit's vision of los block he's standing in
366 {
367 auto idx = battle.getLosBlockID(position.x, position.y, position.z);
368 if (!visibleBlocks.at(idx))
369 {
370 visibleBlocks.at(idx) = true;
371 discoveredBlocks.insert(idx);
372 }
373 }
374
375 auto blocksToCheck = std::set<int>();
376 int totalChecks = 0;
377 // Calc los to other blocks we haven't seen yet
378 for (int idx = 0; idx < (int)visibleBlocks.size(); idx++)
379 {
380 // Block already seen
381 if (visibleBlocks.at(idx))
382 {
383 continue;
384 }
385
386 totalChecks++;
387 blocksToCheck.insert(idx);
388 if (totalChecks >= lazyLimit)
389 {
390 break;
391 }
392 }
393
394 if (totalChecks >= lazyLimit)
395 {
396 calculateVisionToLosBlocksLazy(state, discoveredBlocks);
397 }
398 else
399 {
400 calculateVisionToLosBlocks(state, discoveredBlocks, blocksToCheck);
401 }
402
403 // Reveal all discovered blocks
404 for (auto &idx : discoveredBlocks)
405 {
406 auto l = battle.losBlocks.at(idx);
407 for (int x = l->start.x; x < l->end.x; x++)
408 {
409 for (int y = l->start.y; y < l->end.y; y++)
410 {
411 for (int z = l->start.z; z < l->end.z; z++)
412 {
413 battle.setVisible(owner, x, y, z);
414 }

Callers

nothing calls this directly

Calls 4

getLosBlockIDMethod · 0.80
insertMethod · 0.80
sizeMethod · 0.45
setVisibleMethod · 0.45

Tested by

no test coverage detected