* Returns if a certain target is covered by the base's * radar range, taking in account the range and chance. * @param target Pointer to target to compare. * @return 0 - not detected, 1 - detected by conventional radar, 2 - detected by hyper-wave decoder. */
| 366 | * @return 0 - not detected, 1 - detected by conventional radar, 2 - detected by hyper-wave decoder. |
| 367 | */ |
| 368 | int Base::detect(Target *target) const |
| 369 | { |
| 370 | int chance = 0; |
| 371 | double distance = getDistance(target) * 60.0 * (180.0 / M_PI); |
| 372 | for (std::vector<BaseFacility*>::const_iterator i = _facilities.begin(); i != _facilities.end(); ++i) |
| 373 | { |
| 374 | if ((*i)->getRules()->getRadarRange() >= distance && (*i)->getBuildTime() == 0) |
| 375 | { |
| 376 | if ((*i)->getRules()->isHyperwave()) |
| 377 | { |
| 378 | return 2; |
| 379 | } |
| 380 | chance += (*i)->getRules()->getRadarChance(); |
| 381 | } |
| 382 | } |
| 383 | if (chance == 0) return 0; |
| 384 | |
| 385 | Ufo *u = dynamic_cast<Ufo*>(target); |
| 386 | if (u != 0) |
| 387 | { |
| 388 | chance = chance * (100 + u->getVisibility()) / 100; |
| 389 | } |
| 390 | |
| 391 | return RNG::percent(chance)? 1 : 0; |
| 392 | } |
| 393 | |
| 394 | /** |
| 395 | * Returns if a certain target is inside the base's |
no test coverage detected