| 418 | } |
| 419 | |
| 420 | void BattleUnit::calculateVisionToLosBlocks(GameState &state, std::set<int> &discoveredBlocks, |
| 421 | std::set<int> &blocksToCheck) |
| 422 | { |
| 423 | auto eyesPos = getEyeLocation(); |
| 424 | auto &battle = *state.current_battle; |
| 425 | auto &map = *battle.map; |
| 426 | |
| 427 | auto &visibleBlocks = battle.visibleBlocks.at(owner); |
| 428 | for (auto &idx : blocksToCheck) |
| 429 | { |
| 430 | // Get block and its center |
| 431 | auto &l = *battle.losBlocks.at(idx); |
| 432 | auto centerXY = Vec3<int>{(l.start.x + l.end.x) / 2, (l.start.y + l.end.y) / 2, 0}; |
| 433 | // Set target to center |
| 434 | bool targetFound = false; |
| 435 | auto target = centerXY; |
| 436 | // Set target's Z to our level (or closest possible) |
| 437 | int posZ = position.z; |
| 438 | if (posZ >= l.start.z && posZ < l.end.z) |
| 439 | { |
| 440 | target.z = posZ; |
| 441 | } |
| 442 | else if (posZ < l.start.z) |
| 443 | { |
| 444 | target.z = l.start.z; |
| 445 | } |
| 446 | else |
| 447 | { |
| 448 | target.z = l.end.z - 1; |
| 449 | } |
| 450 | // Try to target center of LOS block (on our Z level) |
| 451 | if (isWithinVision(target)) |
| 452 | { |
| 453 | targetFound = true; |
| 454 | } |
| 455 | // Try to target point within that is closest to our sight's middlepoint |
| 456 | else |
| 457 | { |
| 458 | // Get point in the middle of our sight forward |
| 459 | int dist = |
| 460 | facing.x != 0 && facing.y != 0 ? VIEW_DISTANCE * 100 / 141 / 2 : VIEW_DISTANCE / 2; |
| 461 | auto sightMiddleXY = (Vec3<int>)position; |
| 462 | sightMiddleXY.x += facing.x * dist; |
| 463 | sightMiddleXY.y += facing.y * dist; |
| 464 | // Get point closest to that point |
| 465 | target.x = |
| 466 | std::abs(l.start.x - sightMiddleXY.x) < std::abs(l.end.x - 1 - sightMiddleXY.x) |
| 467 | ? l.start.x |
| 468 | : l.end.x - 1; |
| 469 | target.y = |
| 470 | std::abs(l.start.y - sightMiddleXY.y) < std::abs(l.end.y - 1 - sightMiddleXY.y) |
| 471 | ? l.start.y |
| 472 | : l.end.y - 1; |
| 473 | if (posZ >= l.start.z && posZ < l.end.z) |
| 474 | { |
| 475 | target.z = posZ; |
| 476 | } |
| 477 | else if (posZ < l.start.z) |
nothing calls this directly
no test coverage detected