/** * 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. */ int Base::detect(Target *target) const { int chance = 0; double distance = getDistance(target) * 60.0 * (180.0 / M_PI); for (std::vector<BaseFacility*>::const_iterator i = _facilities.begin(); i != _facilities.end(); ++i) { if ((*i)->getRules()->getRadarRange() >= distance && (*i)->getBuildTime() == 0) { if ((*i)->getRules()->isHyperwave()) { return 2; } chance += (*i)->getRules()->getRadarChance(); } } if (chance == 0) return 0; Ufo *u = dynamic_cast<Ufo*>(target); if (u != 0) { chance = chance * (100 + u->getVisibility()) / 100; } return RNG::percent(chance)? 1 : 0; }
/** * Returns if a certain target is detected by the craft's * radar, taking in account the range and chance. * @param target Pointer to target to compare. * @return True if it's detected, False otherwise. */ bool Craft::detect(Target *target) const { if (_rules->getRadarRange() == 0 || !insideRadarRange(target)) return false; // backward compatibility with vanilla if (_rules->getRadarChance() == 100) return true; Ufo *u = dynamic_cast<Ufo*>(target); int chance = _rules->getRadarChance() * (100 + u->getVisibility()) / 100; return RNG::percent(chance); }