| 509 | } |
| 510 | |
| 511 | void BattleUnit::calculateVisionToLosBlocksLazy(GameState &state, std::set<int> &discoveredBlocks) |
| 512 | { |
| 513 | auto eyesPos = getEyeLocation(); |
| 514 | auto &battle = *state.current_battle; |
| 515 | auto &map = *battle.map; |
| 516 | |
| 517 | auto &visibleBlocks = battle.visibleBlocks.at(owner); |
| 518 | auto &tileToLosBlock = battle.tileToLosBlock; |
| 519 | |
| 520 | // Basically, we're checking in five directions on Z-scale, and in five directions on XY scale |
| 521 | // Values are picked so that atan of these values give relatively even angle distributions |
| 522 | |
| 523 | // First value is multiplier for XY part of vector, second value is vector's Z |
| 524 | static const std::vector<Vec2<float>> zTarget = {{0.18f, 1.0f}, {1.0f, 1.0f}, {1.0f, 0.55f}, |
| 525 | {1.0f, 0.18f}, {1.0f, 0.0f}, {1.0f, -0.18f}, |
| 526 | {1.0f, -0.55f}, {1.0f, -1.0f}, {0.18f, -1.0f}}; |
| 527 | // First value is X, second value is Y |
| 528 | static const std::vector<Vec2<float>> diagTarget = { |
| 529 | {0.18f, 1.0f}, {0.55f, 1.0f}, {1.0f, 1.0f}, {1.0f, 0.55f}, {1.0f, 0.18f}}; |
| 530 | |
| 531 | // Value for the coordinate which is zero in the facing (Y if facing along X etc.) |
| 532 | static const std::vector<float> dirTarget = {-0.82f, -0.45f, 0.0f, 0.45f, 0.82f}; |
| 533 | |
| 534 | for (int z = 0; z < 9; z++) |
| 535 | { |
| 536 | for (int xy = 0; xy < 5; xy++) |
| 537 | { |
| 538 | Vec3<float> targetVector; |
| 539 | if (facing.x != 0 && facing.y != 0) |
| 540 | { |
| 541 | targetVector = {(float)facing.x * diagTarget.at(xy).x * zTarget.at(z).x, |
| 542 | (float)facing.y * diagTarget.at(xy).y * zTarget.at(z).x, |
| 543 | zTarget.at(z).y}; |
| 544 | } |
| 545 | else if (facing.x != 0) |
| 546 | { |
| 547 | targetVector = {(float)facing.x * zTarget.at(z).x, |
| 548 | dirTarget.at(xy) * zTarget.at(z).x, zTarget.at(z).y}; |
| 549 | } |
| 550 | else |
| 551 | { |
| 552 | targetVector = {dirTarget.at(xy) * zTarget.at(z).x, |
| 553 | (float)facing.y * zTarget.at(z).x, zTarget.at(z).y}; |
| 554 | } |
| 555 | targetVector = glm::normalize(targetVector) * (float)VIEW_DISTANCE; |
| 556 | |
| 557 | auto c = map.findCollision(eyesPos, eyesPos + targetVector, mapPartSet, tileObject, |
| 558 | true, false, VIEW_DISTANCE, true); |
| 559 | |
| 560 | for (auto &t : c.passedTiles) |
| 561 | { |
| 562 | auto idx = tileToLosBlock.at(t.z * battle.size.x * battle.size.y + |
| 563 | t.y * battle.size.x + t.x); |
| 564 | if (!visibleBlocks.at(idx)) |
| 565 | { |
| 566 | visibleBlocks.at(idx) = true; |
| 567 | discoveredBlocks.insert(idx); |
| 568 | } |
nothing calls this directly
no test coverage detected