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

Method endTurn

src/Savegame/SavedBattleGame.cpp:781–862  ·  view source on GitHub ↗

* Ends the current turn and progresses to the next one. */

Source from the content-addressed store, hash-verified

779 * Ends the current turn and progresses to the next one.
780 */
781void SavedBattleGame::endTurn()
782{
783 if (_side == FACTION_PLAYER)
784 {
785 if (_selectedUnit && _selectedUnit->getOriginalFaction() == FACTION_PLAYER)
786 _lastSelectedUnit = _selectedUnit;
787 _selectedUnit = 0;
788 _side = FACTION_HOSTILE;
789 }
790 else if (_side == FACTION_HOSTILE)
791 {
792 _side = FACTION_NEUTRAL;
793 // if there is no neutral team, we skip this and instantly prepare the new turn for the player
794 if (selectNextPlayerUnit() == 0)
795 {
796 prepareNewTurn();
797 _turn++;
798 _side = FACTION_PLAYER;
799 if (_lastSelectedUnit && _lastSelectedUnit->isSelectable(FACTION_PLAYER, false, false))
800 _selectedUnit = _lastSelectedUnit;
801 else
802 selectNextPlayerUnit();
803 while (_selectedUnit && _selectedUnit->getFaction() != FACTION_PLAYER)
804 selectNextPlayerUnit();
805 }
806
807 }
808 else if (_side == FACTION_NEUTRAL)
809 {
810 prepareNewTurn();
811 _turn++;
812 _side = FACTION_PLAYER;
813 if (_lastSelectedUnit && _lastSelectedUnit->isSelectable(FACTION_PLAYER, false, false))
814 _selectedUnit = _lastSelectedUnit;
815 else
816 selectNextPlayerUnit();
817 while (_selectedUnit && _selectedUnit->getFaction() != FACTION_PLAYER)
818 selectNextPlayerUnit();
819 }
820 int liveSoldiers, liveAliens;
821
822 _battleState->getBattleGame()->tallyUnits(liveAliens, liveSoldiers, false);
823
824 if (_turn >= 20 || liveAliens < 2)
825 {
826 _cheating = true;
827 }
828
829 if (_side == FACTION_PLAYER)
830 {
831 // update the "number of turns since last spotted"
832 for (std::vector<BattleUnit*>::iterator i = _units.begin(); i != _units.end(); ++i)
833 {
834 if ((*i)->getTurnsSinceSpotted() < 255)
835 {
836 (*i)->setTurnsSinceSpotted((*i)->getTurnsSinceSpotted() + 1);
837 }
838 if (_cheating && (*i)->getFaction() == FACTION_PLAYER && !(*i)->isOut())

Callers

nothing calls this directly

Calls 11

getOriginalFactionMethod · 0.80
isSelectableMethod · 0.80
getFactionMethod · 0.80
tallyUnitsMethod · 0.80
getTurnsSinceSpottedMethod · 0.80
setTurnsSinceSpottedMethod · 0.80
isOutMethod · 0.80
recalculateFOVMethod · 0.80
getBattleGameMethod · 0.45
prepareNewTurnMethod · 0.45
setVisibleMethod · 0.45

Tested by

no test coverage detected