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

Method getRandomPoint

src/Ruleset/RuleRegion.cpp:189–214  ·  view source on GitHub ↗

* Gets a random point that is guaranteed to be inside the give zone. * If the region contains cities, they are the sites of zone 0 and the rest of the zones get one index higher. * @param zone The target zone. * @return A pair of longitude and latitude. */

Source from the content-addressed store, hash-verified

187 * @return A pair of longitude and latitude.
188 */
189std::pair<double, double> RuleRegion::getRandomPoint(size_t zone) const
190{
191 if (zone < _missionZones.size())
192 {
193 size_t a = RNG::generate(0, _missionZones[zone].areas.size() - 1);
194 double lonMin = _missionZones[zone].areas[a].lonMin;
195 double lonMax = _missionZones[zone].areas[a].lonMax;
196 double latMin = _missionZones[zone].areas[a].latMin;
197 double latMax = _missionZones[zone].areas[a].latMax;
198 if (lonMin > lonMax)
199 {
200 lonMin = _missionZones[zone].areas[a].lonMax;
201 lonMax = _missionZones[zone].areas[a].lonMin;
202 }
203 if (latMin > latMax)
204 {
205 latMin = _missionZones[zone].areas[a].latMax;
206 latMax = _missionZones[zone].areas[a].latMin;
207 }
208 double lon = RNG::generate(lonMin, lonMax);
209 double lat = RNG::generate(latMin, latMax);
210 return std::make_pair(lon * M_PI / 180, lat * M_PI / 180);
211 }
212 assert(0 && "Invalid zone number");
213 return std::make_pair(0.0, 0.0);
214}
215
216const std::vector<MissionZone> &RuleRegion::getMissionZones() const
217{

Callers 3

spawnUfoMethod · 0.80
getWaypointMethod · 0.80
getLandPointMethod · 0.80

Calls 1

generateFunction · 0.85

Tested by

no test coverage detected