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

Method time5Seconds

src/Geoscape/GeoscapeState.cpp:680–977  ·  view source on GitHub ↗

* Takes care of any game logic that has to * run every game second, like craft movement. */

Source from the content-addressed store, hash-verified

678 * run every game second, like craft movement.
679 */
680void 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;

Callers

nothing calls this directly

Calls 15

generateFunction · 0.85
getBasesMethod · 0.80
getSavedGameMethod · 0.80
getUfosMethod · 0.80
isRunningMethod · 0.80
reachedDestinationMethod · 0.80
getTerrorSitesMethod · 0.80
getMissionMethod · 0.80
getDetectedMethod · 0.80
ufoReachedWaypointMethod · 0.80
getFollowersMethod · 0.80
getIDMethod · 0.80

Tested by

no test coverage detected