- bugfixes to winner / loser logic to keep calculating stats and publish to masterserver after we determine a winner or loser as the game may not yet be fully over and we want accurate game stats on the masterserver.

This commit is contained in:
SoftCoder
2013-11-30 20:33:25 -08:00
parent 4b50560ca9
commit b868a8468b
2 changed files with 171 additions and 135 deletions

View File

@@ -5600,7 +5600,10 @@ void Game::render2d() {
// ==================== misc ==================== // ==================== misc ====================
void Game::checkWinner() { void Game::checkWinner() {
if(gameOver == false) { // lookup int is team #, value is players alive on team
std::map<int, int> teamsAlive = getTeamsAlive();
if(gameOver == false || teamsAlive.size() > 1) {
if(gameSettings.getDefaultVictoryConditions()) { if(gameSettings.getDefaultVictoryConditions()) {
checkWinnerStandard(); checkWinnerStandard();
} }
@@ -5675,55 +5678,62 @@ void Game::setEndGameTeamWinnersAndLosers() {
} }
} }
void Game::checkWinnerStandard() { std::map<int, int> Game::getTeamsAlive() {
if(world.getFactionCount() <= 0) { std::map<int, int> teamsAlive;
return; for (int factionIndex = 0; factionIndex < world.getFactionCount(); ++factionIndex) {
if (factionIndex != world.getThisFactionIndex()) {
//if(hasBuilding(world.getFaction(i))) {
if (factionLostGame(world.getFaction(factionIndex)) == false) {
teamsAlive[world.getFaction(factionIndex)->getTeam()] =
teamsAlive[world.getFaction(factionIndex)->getTeam()] + 1;
}
}
} }
if(this->masterserverMode == true || world.getThisFaction()->getPersonalityType() == fpt_Observer) { // did some team win
// lookup int is team #, value is players alive on team return teamsAlive;
std::map<int,int> teamsAlive; }
for(int i = 0; i < world.getFactionCount(); ++i) {
if(i != world.getThisFactionIndex()) { void Game::checkWinnerStandardHeadlessOrObserver() {
//if(hasBuilding(world.getFaction(i))) { // lookup int is team #, value is players alive on team
if(factionLostGame(world.getFaction(i)) == false) { std::map<int, int> teamsAlive = getTeamsAlive();
teamsAlive[world.getFaction(i)->getTeam()] = teamsAlive[world.getFaction(i)->getTeam()] + 1;
// did some team win
if (teamsAlive.size() <= 1) {
if (this->masterserverMode == true) {
printf("Game finished...\n");
}
for (int factionIndex = 0; factionIndex < world.getFactionCount(); ++factionIndex) {
Faction* faction = world.getFaction(factionIndex);
if (factionIndex != world.getThisFactionIndex() &&
teamsAlive.find(faction->getTeam()) != teamsAlive.end()) {
world.getStats()->setVictorious(factionIndex);
if (this->masterserverMode == true) {
printf("Player: %s is on the winning team #: %d\n",
this->gameSettings.getNetworkPlayerName(factionIndex).c_str(),
faction->getTeam());
} }
} }
} }
bool wasGameOverAlready = gameOver;
gameOver = true;
// did some team win // Only need to process this once
if(teamsAlive.size() <= 1) { if(wasGameOverAlready == false) {
if(this->masterserverMode == true) { if (this->gameSettings.isNetworkGame() == false ||
printf("Game finished...\n"); this->gameSettings.getEnableObserverModeAtEndGame()
} == true) {
for(int i=0; i< world.getFactionCount(); ++i) {
Faction *faction = world.getFaction(i);
if(i != world.getThisFactionIndex() && teamsAlive.find(faction->getTeam()) != teamsAlive.end()) {
world.getStats()->setVictorious(i);
if(this->masterserverMode == true) {
printf("Player: %s is on the winning team #: %d\n",this->gameSettings.getNetworkPlayerName(i).c_str(),faction->getTeam());
}
}
}
gameOver= true;
if( this->gameSettings.isNetworkGame() == false ||
this->gameSettings.getEnableObserverModeAtEndGame() == true) {
// Let the happy winner view everything left in the world // Let the happy winner view everything left in the world
// This caused too much LAG for network games // This caused too much LAG for network games
if(this->gameSettings.isNetworkGame() == false) { if (this->gameSettings.isNetworkGame() == false) {
Renderer::getInstance().setPhotoMode(true); Renderer::getInstance().setPhotoMode(true);
gameCamera.setMaxHeight(PHOTO_MODE_MAXHEIGHT); gameCamera.setMaxHeight(PHOTO_MODE_MAXHEIGHT);
} }
// END // END
} }
scriptManager.onGameOver(true); scriptManager.onGameOver(true);
if (world.getFactionCount() == 1 &&
if(world.getFactionCount() == 1 && world.getFaction(0)->getPersonalityType() == fpt_Observer) { world.getFaction(0)->getPersonalityType() == fpt_Observer) {
//printf("!!!!!!!!!!!!!!!!!!!!"); //printf("!!!!!!!!!!!!!!!!!!!!");
//gameCamera.setMoveY(100.0); //gameCamera.setMoveY(100.0);
gameCamera.zoom(-300); gameCamera.zoom(-300);
//gameCamera.update(); //gameCamera.update();
@@ -5733,23 +5743,121 @@ void Game::checkWinnerStandard() {
} }
} }
} }
else { }
//lose
bool lose= false; void Game::checkWinnerStandardPlayer() {
//if(hasBuilding(world.getThisFaction()) == false) { //lose
if(factionLostGame(world.getThisFaction()) == true) { bool lose = false;
lose= true; //if(hasBuilding(world.getThisFaction()) == false) {
for(int i=0; i<world.getFactionCount(); ++i) { if (factionLostGame(world.getThisFaction()) == true) {
if(world.getFaction(i)->getPersonalityType() != fpt_Observer) { lose = true;
if(world.getFaction(i)->isAlly(world.getThisFaction()) == false) { for (int factionIndex = 0; factionIndex < world.getFactionCount(); ++factionIndex) {
world.getStats()->setVictorious(i); if (world.getFaction(factionIndex)->getPersonalityType() != fpt_Observer) {
if (world.getFaction(factionIndex)->isAlly(world.getThisFaction()) == false) {
world.getStats()->setVictorious(factionIndex);
}
}
}
bool wasGameOverAlready = gameOver;
gameOver = true;
// Only need to process losing once
if(wasGameOverAlready == false) {
if (this->gameSettings.isNetworkGame() == false ||
this->gameSettings.getEnableObserverModeAtEndGame()
== true) {
// Let the poor user watch everything unfold
// This caused too much LAG for network games
if (this->gameSettings.isNetworkGame() == false) {
Renderer::getInstance().setPhotoMode(true);
gameCamera.setMaxHeight(PHOTO_MODE_MAXHEIGHT);
}
// END
// but don't let him cheat via teamchat
chatManager.setDisableTeamMode(true);
}
scriptManager.onGameOver(!lose);
showLoseMessageBox();
}
}
//win
if (lose == false) {
bool win = true;
for (int factionIndex = 0; factionIndex < world.getFactionCount(); ++factionIndex) {
if (factionIndex != world.getThisFactionIndex()) {
if (world.getFaction(factionIndex)->getPersonalityType() != fpt_Observer) {
//if(hasBuilding(world.getFaction(i)) &&
if (factionLostGame(world.getFaction(factionIndex)) == false &&
world.getFaction(factionIndex)->isAlly(world.getThisFaction()) == false) {
win = false;
} }
} }
} }
gameOver= true; }
//if win
if (win) {
for (int factionIndex = 0; factionIndex < world.getFactionCount(); ++factionIndex) {
if (world.getFaction(factionIndex)->getPersonalityType() != fpt_Observer) {
if (world.getFaction(factionIndex)->isAlly(world.getThisFaction())) {
world.getStats()->setVictorious(factionIndex);
}
}
}
bool wasGameOverAlready = gameOver;
gameOver = true;
// Only need to process winning once
if(wasGameOverAlready == false) {
if (this->gameSettings.isNetworkGame() == false ||
this->gameSettings.getEnableObserverModeAtEndGame() == true) {
// Let the happy winner view everything left in the world
//world.setFogOfWar(false);
// This caused too much LAG for network games
if (this->gameSettings.isNetworkGame() == false) {
Renderer::getInstance().setPhotoMode(true);
gameCamera.setMaxHeight(PHOTO_MODE_MAXHEIGHT);
}
// END
}
scriptManager.onGameOver(win);
showWinMessageBox();
}
}
}
}
void Game::checkWinnerStandard() {
if(world.getFactionCount() <= 0) {
return;
}
if(this->masterserverMode == true ||
world.getThisFaction()->getPersonalityType() == fpt_Observer) {
checkWinnerStandardHeadlessOrObserver();
}
else {
checkWinnerStandardPlayer();
}
}
void Game::checkWinnerScripted() {
if(scriptManager.getIsGameOver()) {
bool wasGameOverAlready = gameOver;
gameOver= true;
for(int i= 0; i<world.getFactionCount(); ++i) {
if(scriptManager.getPlayerModifiers(i)->getWinner()) {
world.getStats()->setVictorious(i);
}
}
// Only need to process winning once
if(wasGameOverAlready == false) {
if( this->gameSettings.isNetworkGame() == false || if( this->gameSettings.isNetworkGame() == false ||
this->gameSettings.getEnableObserverModeAtEndGame() == true) { this->gameSettings.getEnableObserverModeAtEndGame() == true) {
// Let the poor user watch everything unfold // Let the happy winner view everything left in the world
//world.setFogOfWar(false);
// This caused too much LAG for network games // This caused too much LAG for network games
if(this->gameSettings.isNetworkGame() == false) { if(this->gameSettings.isNetworkGame() == false) {
@@ -5757,95 +5865,20 @@ void Game::checkWinnerStandard() {
gameCamera.setMaxHeight(PHOTO_MODE_MAXHEIGHT); gameCamera.setMaxHeight(PHOTO_MODE_MAXHEIGHT);
} }
// END // END
// but don't let him cheat via teamchat
chatManager.setDisableTeamMode(true);
} }
scriptManager.onGameOver(!lose); if(this->masterserverMode == true || world.getThisFaction()->getPersonalityType() == fpt_Observer) {
showLoseMessageBox();
}
//win
if(lose == false) {
bool win= true;
for(int i = 0; i < world.getFactionCount(); ++i) {
if(i != world.getThisFactionIndex()) {
if(world.getFaction(i)->getPersonalityType() != fpt_Observer) {
//if(hasBuilding(world.getFaction(i)) &&
if(factionLostGame(world.getFaction(i)) == false &&
world.getFaction(i)->isAlly(world.getThisFaction()) == false) {
win= false;
}
}
}
}
//if win
if(win) {
for(int i=0; i< world.getFactionCount(); ++i) {
if(world.getFaction(i)->getPersonalityType() != fpt_Observer) {
if(world.getFaction(i)->isAlly(world.getThisFaction())) {
world.getStats()->setVictorious(i);
}
}
}
gameOver= true;
if( this->gameSettings.isNetworkGame() == false ||
this->gameSettings.getEnableObserverModeAtEndGame() == true) {
// Let the happy winner view everything left in the world
//world.setFogOfWar(false);
// This caused too much LAG for network games
if(this->gameSettings.isNetworkGame() == false) {
Renderer::getInstance().setPhotoMode(true);
gameCamera.setMaxHeight(PHOTO_MODE_MAXHEIGHT);
}
// END
}
scriptManager.onGameOver(win);
showWinMessageBox(); showWinMessageBox();
} }
} else {
} scriptManager.onGameOver(scriptManager.getPlayerModifiers(world.getThisFactionIndex())->getWinner());
}
void Game::checkWinnerScripted() { if(scriptManager.getPlayerModifiers(world.getThisFactionIndex())->getWinner()){
if(scriptManager.getIsGameOver()) { showWinMessageBox();
gameOver= true; }
for(int i= 0; i<world.getFactionCount(); ++i) { else {
if(scriptManager.getPlayerModifiers(i)->getWinner()) { showLoseMessageBox();
world.getStats()->setVictorious(i); }
}
}
if( this->gameSettings.isNetworkGame() == false ||
this->gameSettings.getEnableObserverModeAtEndGame() == true) {
// Let the happy winner view everything left in the world
//world.setFogOfWar(false);
// This caused too much LAG for network games
if(this->gameSettings.isNetworkGame() == false) {
Renderer::getInstance().setPhotoMode(true);
gameCamera.setMaxHeight(PHOTO_MODE_MAXHEIGHT);
}
// END
}
if(this->masterserverMode == true || world.getThisFaction()->getPersonalityType() == fpt_Observer) {
showWinMessageBox();
}
else {
scriptManager.onGameOver(scriptManager.getPlayerModifiers(world.getThisFactionIndex())->getWinner());
if(scriptManager.getPlayerModifiers(world.getThisFactionIndex())->getWinner()){
showWinMessageBox();
}
else{
showLoseMessageBox();
} }
} }
} }
@@ -5857,10 +5890,10 @@ bool Game::factionLostGame(int factionIndex) {
bool Game::factionLostGame(const Faction *faction) { bool Game::factionLostGame(const Faction *faction) {
if(faction != NULL) { if(faction != NULL) {
for(int i=0; i<faction->getUnitCount(); ++i) { for(int factionIndex=0; factionIndex<faction->getUnitCount(); ++factionIndex) {
const UnitType *ut = faction->getUnit(i)->getType(); const UnitType *ut = faction->getUnit(factionIndex)->getType();
if(ut->getCountInVictoryConditions() == ucvcNotSet) { if(ut->getCountInVictoryConditions() == ucvcNotSet) {
if(faction->getUnit(i)->getType()->hasSkillClass(scBeBuilt)) { if(faction->getUnit(factionIndex)->getType()->hasSkillClass(scBeBuilt)) {
return false; return false;
} }
} }

View File

@@ -395,6 +395,9 @@ private:
int startIndex, int endIndex, bool onlyNetworkUnassigned); int startIndex, int endIndex, bool onlyNetworkUnassigned);
void processNetworkSynchChecksIfRequired(); void processNetworkSynchChecksIfRequired();
Stats getEndGameStats(); Stats getEndGameStats();
void checkWinnerStandardHeadlessOrObserver();
void checkWinnerStandardPlayer();
std::map<int, int> getTeamsAlive();
}; };
}}//end namespace }}//end namespace