* This function is called when one of the mission's UFOs arrives at it's current destination. * It takes care of sending the UFO to the next waypoint, landing UFOs and * marking them for removal as required. It must set the game data in a way that the rest of the code * understands what to do. * @param ufo The UFO that reached it's waypoint. * @param engine The game engine, required to get ac
| 358 | * @param globe The earth globe, required to get access to land checks. |
| 359 | */ |
| 360 | void AlienMission::ufoReachedWaypoint(Ufo &ufo, Game &engine, const Globe &globe) |
| 361 | { |
| 362 | const Ruleset &rules = *engine.getRuleset(); |
| 363 | SavedGame &game = *engine.getSavedGame(); |
| 364 | const size_t curWaypoint = ufo.getTrajectoryPoint(); |
| 365 | const size_t nextWaypoint = curWaypoint + 1; |
| 366 | const UfoTrajectory &trajectory = ufo.getTrajectory(); |
| 367 | if (nextWaypoint >= trajectory.getWaypointCount()) |
| 368 | { |
| 369 | ufo.setDetected(false); |
| 370 | ufo.setStatus(Ufo::DESTROYED); |
| 371 | return; |
| 372 | } |
| 373 | ufo.setAltitude(trajectory.getAltitude(nextWaypoint)); |
| 374 | ufo.setTrajectoryPoint(nextWaypoint); |
| 375 | std::pair<double, double> pos = getWaypoint(trajectory, nextWaypoint, globe, *rules.getRegion(_region)); |
| 376 | |
| 377 | // screw it, we're not taking any chances, use the city's lon/lat info instead of the region's |
| 378 | // TODO: find out why there is a discrepency between generated city mission zones and the cities that generated them. |
| 379 | // honolulu: 3.6141230952747376, -0.37332941766009109 |
| 380 | // UFO: lon: 3.61412 lat: -0.373329 |
| 381 | // Zone: Longitudes: 3.61412 to 3.61412 Lattitudes: -0.373329 to -0.373329 |
| 382 | // http://openxcom.org/bugs/openxcom/issues/615#comment_3292 |
| 383 | if (ufo.getRules()->getType() == "STR_TERROR_SHIP" && _rule.getType() == "STR_ALIEN_TERROR" && trajectory.getZone(nextWaypoint) == RuleRegion::CITY_MISSION_ZONE) |
| 384 | { |
| 385 | while(!rules.locateCity(pos.first, pos.second)) |
| 386 | { |
| 387 | Log(LOG_DEBUG) << "Longitude: " << pos.first << "Lattitude: " << pos.second << " invalid"; |
| 388 | size_t city = RNG::generate(0, rules.getRegion(_region)->getCities()->size() - 1); |
| 389 | pos.first = rules.getRegion(_region)->getCities()->at(city)->getLongitude(); |
| 390 | pos.second = rules.getRegion(_region)->getCities()->at(city)->getLatitude(); |
| 391 | } |
| 392 | } |
| 393 | |
| 394 | Waypoint *wp = new Waypoint(); |
| 395 | wp->setLongitude(pos.first); |
| 396 | wp->setLatitude(pos.second); |
| 397 | ufo.setDestination(wp); |
| 398 | if (ufo.getAltitude() != "STR_GROUND") |
| 399 | { |
| 400 | if (ufo.getLandId() != 0) |
| 401 | { |
| 402 | ufo.setLandId(0); |
| 403 | } |
| 404 | // Set next waypoint. |
| 405 | ufo.setSpeed((int)(ufo.getRules()->getMaxSpeed() * trajectory.getSpeedPercentage(nextWaypoint))); |
| 406 | } |
| 407 | else |
| 408 | { |
| 409 | // UFO landed. |
| 410 | |
| 411 | if (ufo.getRules()->getType() == "STR_TERROR_SHIP" && _rule.getType() == "STR_ALIEN_TERROR" && trajectory.getZone(curWaypoint) == RuleRegion::CITY_MISSION_ZONE) |
| 412 | { |
| 413 | // Specialized: STR_ALIEN_TERROR |
| 414 | // Remove UFO, replace with TerrorSite. |
| 415 | addScore(ufo.getLongitude(), ufo.getLatitude(), engine); |
| 416 | ufo.setStatus(Ufo::DESTROYED); |
| 417 | TerrorSite *terrorSite = new TerrorSite(); |
no test coverage detected