MCPcopy Create free account
hub / github.com/OpenXcom/OpenXcom / detect

Method detect

src/Savegame/Base.cpp:368–392  ·  view source on GitHub ↗

* 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. */

Source from the content-addressed store, hash-verified

366 * @return 0 - not detected, 1 - detected by conventional radar, 2 - detected by hyper-wave decoder.
367 */
368int 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

Callers 1

time30MinutesMethod · 0.45

Calls 7

percentFunction · 0.85
isHyperwaveMethod · 0.80
getRadarChanceMethod · 0.80
getVisibilityMethod · 0.80
getRadarRangeMethod · 0.45
getRulesMethod · 0.45
getBuildTimeMethod · 0.45

Tested by

no test coverage detected