------------------------------------------------- UPDATE -------------------------------------------------
| 34 | |
| 35 | //------------------------------------------------- UPDATE ------------------------------------------------- |
| 36 | void GameImpl::update() |
| 37 | { |
| 38 | //this function is called every frame from a hook attached in DllMain.cpp |
| 39 | this->inGame = true; |
| 40 | |
| 41 | // Calculate APM, FPS, etc. |
| 42 | updateStatistics(); |
| 43 | |
| 44 | //the first time update() is called, we also call onGameStart to initialize some things |
| 45 | if ( !onStartCalled ) |
| 46 | this->onGameStart(); |
| 47 | |
| 48 | if ( !this->calledMatchEnd && frameCount > 1 ) |
| 49 | { |
| 50 | bool win = false; |
| 51 | bool allDone = false; |
| 52 | if ( this->BWAPIPlayer ) |
| 53 | { |
| 54 | if ( this->BWAPIPlayer->isVictorious() ) |
| 55 | { |
| 56 | win = true; |
| 57 | allDone = true; |
| 58 | } |
| 59 | if ( this->BWAPIPlayer->isDefeated() ) |
| 60 | { |
| 61 | win = false; |
| 62 | allDone = true; |
| 63 | } |
| 64 | } |
| 65 | else |
| 66 | { |
| 67 | allDone = true; |
| 68 | for(PlayerImpl* p : this->players) |
| 69 | { |
| 70 | if (p->getIndex() >= BW::PLAYABLE_PLAYER_COUNT) |
| 71 | continue; |
| 72 | if ( !p->isDefeated() && !p->isVictorious() && !p->leftGame() ) |
| 73 | allDone = false; |
| 74 | } |
| 75 | } |
| 76 | if ( allDone) |
| 77 | { |
| 78 | if (win) |
| 79 | rn_GameResult = "win"; |
| 80 | this->calledMatchEnd = true; |
| 81 | events.push_back(Event::MatchFrame()); |
| 82 | events.push_back(Event::MatchEnd(win)); |
| 83 | server.update(); |
| 84 | this->inGame = false; |
| 85 | events.push_back(Event::MenuFrame()); |
| 86 | server.update(); |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | //don't have any more MatchFrame events after MatchEnd until MatchStart is called. |
| 91 | if ( this->calledMatchEnd ) return; |
| 92 | |
| 93 | // Update unit selection |
no test coverage detected