* Checks for an opposing unit on this tile. * @param currentUnit The watcher. * @param tile The tile to check for * @return True if visible. */
| 386 | * @return True if visible. |
| 387 | */ |
| 388 | bool TileEngine::visible(BattleUnit *currentUnit, Tile *tile) |
| 389 | { |
| 390 | // if there is no tile or no unit, we can't see it |
| 391 | if (!tile || !tile->getUnit()) |
| 392 | { |
| 393 | return false; |
| 394 | } |
| 395 | |
| 396 | // aliens can see in the dark, xcom can see at a distance of 9 or less, further if there's enough light. |
| 397 | if (currentUnit->getFaction() == FACTION_PLAYER && |
| 398 | distance(currentUnit->getPosition(), tile->getPosition()) > 9 && |
| 399 | tile->getShade() > MAX_DARKNESS_TO_SEE_UNITS) |
| 400 | { |
| 401 | return false; |
| 402 | } |
| 403 | |
| 404 | if (currentUnit->getFaction() == tile->getUnit()->getFaction()) return true; // friendlies are always seen |
| 405 | |
| 406 | Position originVoxel = getSightOriginVoxel(currentUnit); |
| 407 | |
| 408 | bool unitSeen = false; |
| 409 | // for large units origin voxel is in the middle |
| 410 | |
| 411 | Position scanVoxel; |
| 412 | std::vector<Position> _trajectory; |
| 413 | unitSeen = canTargetUnit(&originVoxel, tile, &scanVoxel, currentUnit); |
| 414 | |
| 415 | if (unitSeen) |
| 416 | { |
| 417 | // now check if we really see it taking into account smoke tiles |
| 418 | // initial smoke "density" of a smoke grenade is around 15 per tile |
| 419 | // we do density/3 to get the decay of visibility |
| 420 | // so in fresh smoke we should only have 4 tiles of visibility |
| 421 | // this is traced in voxel space, with smoke affecting visibility every step of the way |
| 422 | _trajectory.clear(); |
| 423 | calculateLine(originVoxel, scanVoxel, true, &_trajectory, currentUnit); |
| 424 | Tile *t = _save->getTile(currentUnit->getPosition()); |
| 425 | size_t visibleDistance = _trajectory.size(); |
| 426 | for (size_t i = 0; i < _trajectory.size(); i++) |
| 427 | { |
| 428 | if (t != _save->getTile(Position(_trajectory.at(i).x/16,_trajectory.at(i).y/16, _trajectory.at(i).z/24))) |
| 429 | { |
| 430 | t = _save->getTile(Position(_trajectory.at(i).x/16,_trajectory.at(i).y/16, _trajectory.at(i).z/24)); |
| 431 | } |
| 432 | if (t->getFire() == 0) |
| 433 | { |
| 434 | visibleDistance += t->getSmoke() / 3; |
| 435 | } |
| 436 | if (visibleDistance > MAX_VOXEL_VIEW_DISTANCE) |
| 437 | { |
| 438 | unitSeen = false; |
| 439 | break; |
| 440 | } |
| 441 | } |
| 442 | } |
| 443 | return unitSeen; |
| 444 | } |
| 445 |
no test coverage detected