From 856e6fd88e042010d197bb3237dfaecb2dc2600c Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Sun, 10 Nov 2013 04:26:20 +0000 Subject: [PATCH] when using team switch, AI player will now always answers YES if he already lost the game --- source/glest_game/ai/ai.cpp | 29 ++++++++++++++++++----------- source/glest_game/world/world.cpp | 7 +++++++ source/glest_game/world/world.h | 1 + 3 files changed, 26 insertions(+), 11 deletions(-) diff --git a/source/glest_game/ai/ai.cpp b/source/glest_game/ai/ai.cpp index c75c6bd8..f562509f 100644 --- a/source/glest_game/ai/ai.cpp +++ b/source/glest_game/ai/ai.cpp @@ -355,17 +355,24 @@ void Ai::update() { voteResult->allowSwitchTeam = false; const GameSettings *settings = aiInterface->getWorld()->getGameSettings(); - // Can only ask the AI player 2 times max per game - if(factionSwitchTeamRequestCountCurrent <= 2) { - // x% chance the AI will answer yes - if(settings->getAiAcceptSwitchTeamPercentChance() >= 100) { - voteResult->allowSwitchTeam = true; - } - else if(settings->getAiAcceptSwitchTeamPercentChance() <= 0) { - voteResult->allowSwitchTeam = false; - } - else { - voteResult->allowSwitchTeam = (allowJoinTeam >= (100 - settings->getAiAcceptSwitchTeamPercentChance())); + + // If AI player already lost game they cannot vote + if(aiInterface->getWorld()->factionLostGame(aiInterface->getFactionIndex()) == true) { + voteResult->allowSwitchTeam = true; + } + else { + // Can only ask the AI player 2 times max per game + if(factionSwitchTeamRequestCountCurrent <= 2) { + // x% chance the AI will answer yes + if(settings->getAiAcceptSwitchTeamPercentChance() >= 100) { + voteResult->allowSwitchTeam = true; + } + else if(settings->getAiAcceptSwitchTeamPercentChance() <= 0) { + voteResult->allowSwitchTeam = false; + } + else { + voteResult->allowSwitchTeam = (allowJoinTeam >= (100 - settings->getAiAcceptSwitchTeamPercentChance())); + } } } diff --git a/source/glest_game/world/world.cpp b/source/glest_game/world/world.cpp index 66c2b8d4..b3a6fad7 100644 --- a/source/glest_game/world/world.cpp +++ b/source/glest_game/world/world.cpp @@ -2762,6 +2762,13 @@ string World::getAllFactionsCacheStats() { return result; } +bool World::factionLostGame(int factionIndex) { + if(this->game != NULL) { + return this->game->factionLostGame(factionIndex); + } + return false; +} + std::string World::DumpWorldToLog(bool consoleBasicInfoOnly) const { string debugWorldLogFile = Config::getInstance().getString("DebugWorldLogFile","debugWorld.log"); diff --git a/source/glest_game/world/world.h b/source/glest_game/world/world.h index b81b73ab..1231c50a 100644 --- a/source/glest_game/world/world.h +++ b/source/glest_game/world/world.h @@ -327,6 +327,7 @@ public: void clearCaches(); void refreshAllUnitExplorations(); + bool factionLostGame(int factionIndex); private: void initCells(bool fogOfWar);