* Ends the current turn and progresses to the next one. */
| 779 | * Ends the current turn and progresses to the next one. |
| 780 | */ |
| 781 | void 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()) |
nothing calls this directly
no test coverage detected