* Takes care of any game logic that has to * run every game second, like craft movement. */
| 678 | * run every game second, like craft movement. |
| 679 | */ |
| 680 | void GeoscapeState::time5Seconds() |
| 681 | { |
| 682 | // Game over if there are no more bases. |
| 683 | if (_game->getSavedGame()->getBases()->empty()) |
| 684 | { |
| 685 | popup(new DefeatState(_game)); |
| 686 | return; |
| 687 | } |
| 688 | |
| 689 | // Handle UFO logic |
| 690 | for (std::vector<Ufo*>::iterator i = _game->getSavedGame()->getUfos()->begin(); i != _game->getSavedGame()->getUfos()->end(); ++i) |
| 691 | { |
| 692 | switch ((*i)->getStatus()) |
| 693 | { |
| 694 | case Ufo::FLYING: |
| 695 | if (!_zoomInEffectTimer->isRunning() && !_zoomOutEffectTimer->isRunning()) |
| 696 | { |
| 697 | (*i)->think(); |
| 698 | if ((*i)->reachedDestination()) |
| 699 | { |
| 700 | size_t terrorSiteCount = _game->getSavedGame()->getTerrorSites()->size(); |
| 701 | AlienMission *mission = (*i)->getMission(); |
| 702 | bool detected = (*i)->getDetected(); |
| 703 | mission->ufoReachedWaypoint(**i, *_game, *_globe); |
| 704 | if (detected != (*i)->getDetected() && !(*i)->getFollowers()->empty()) |
| 705 | { |
| 706 | if (!((*i)->getTrajectory().getID() == "__RETALIATION_ASSAULT_RUN" && (*i)->getStatus() == Ufo::LANDED)) |
| 707 | popup(new UfoLostState(_game, (*i)->getName(_game->getLanguage()))); |
| 708 | } |
| 709 | if (terrorSiteCount < _game->getSavedGame()->getTerrorSites()->size()) |
| 710 | { |
| 711 | TerrorSite *ts = _game->getSavedGame()->getTerrorSites()->back(); |
| 712 | const City *city = _game->getRuleset()->locateCity(ts->getLongitude(), ts->getLatitude()); |
| 713 | assert(city); |
| 714 | popup(new AlienTerrorState(_game, ts, city->getName(), this)); |
| 715 | } |
| 716 | // If UFO was destroyed, don't spawn missions |
| 717 | if ((*i)->getStatus() == Ufo::DESTROYED) |
| 718 | return; |
| 719 | if (Base *base = dynamic_cast<Base*>((*i)->getDestination())) |
| 720 | { |
| 721 | mission->setWaveCountdown(30 * (RNG::generate(0, 48) + 400)); |
| 722 | (*i)->setDestination(0); |
| 723 | base->setupDefenses(); |
| 724 | timerReset(); |
| 725 | if (!base->getDefenses()->empty()) |
| 726 | { |
| 727 | popup(new BaseDefenseState(_game, base, *i, this)); |
| 728 | } |
| 729 | else |
| 730 | { |
| 731 | handleBaseDefense(base, *i); |
| 732 | return; |
| 733 | } |
| 734 | } |
| 735 | } |
| 736 | } |
| 737 | break; |
nothing calls this directly
no test coverage detected