- attempt to bugfix out of synch when players disconnect and we switch to AI

This commit is contained in:
Mark Vejvoda 2012-10-10 00:27:34 +00:00
parent b7d3bc6a5a
commit 0449fbea2b
3 changed files with 13 additions and 1 deletions

View File

@ -889,6 +889,8 @@ void Commander::giveNetworkCommand(NetworkCommand* networkCommand) const {
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"nctPlayerStatusChange factionIndex = %d playerStatus = %d\n",factionIndex,playerStatus);
//printf("#1 nctPlayerStatusChange factionIndex = %d playerStatus = %d\n",factionIndex,playerStatus);
GameSettings *settings = world->getGameSettingsPtr();
if(playerStatus == npst_Disconnected) {
settings->setNetworkPlayerStatuses(factionIndex,npst_Disconnected);
@ -896,8 +898,13 @@ void Commander::giveNetworkCommand(NetworkCommand* networkCommand) const {
//printf("nctPlayerStatusChange -> faction->getPersonalityType() = %d index [%d] control [%d] networkstatus [%d]\n",
// world->getFaction(factionIndex)->getPersonalityType(),world->getFaction(factionIndex)->getIndex(),world->getFaction(factionIndex)->getControlType(),settings->getNetworkPlayerStatuses(factionIndex));
//printf("#2 nctPlayerStatusChange factionIndex = %d playerStatus = %d\n",factionIndex,playerStatus);
settings->setFactionControl(factionIndex,ctCpuUltra);
settings->setResourceMultiplierIndex(factionIndex,settings->getFallbackCpuMultiplier());
//Game *game = this->world->getGame();
//game->get
Faction *faction = this->world->getFaction(factionIndex);
faction->setControlType(ctCpuUltra);
if(!world->getGame()->getGameOver()&& !this->world->getGame()->factionLostGame(factionIndex)){
// use the fallback multiplier here

View File

@ -1451,11 +1451,15 @@ void Game::update() {
if(commander.hasReplayCommandListForFrame() == false) {
for(int j = 0; j < world.getFactionCount(); ++j) {
Faction *faction = world.getFaction(j);
//printf("Faction Index = %d enableServerControlledAI = %d, isNetworkGame = %d, role = %d isCPU player = %d scriptManager.getPlayerModifiers(j)->getAiEnabled() = %d\n",j,enableServerControlledAI,isNetworkGame,role,faction->getCpuControl(enableServerControlledAI,isNetworkGame,role),scriptManager.getPlayerModifiers(j)->getAiEnabled());
if( faction->getCpuControl(enableServerControlledAI,isNetworkGame,role) == true &&
scriptManager.getPlayerModifiers(j)->getAiEnabled() == true) {
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] [i = %d] faction = %d, factionCount = %d, took msecs: %lld [before AI updates]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,i,j,world.getFactionCount(),chrono.getMillis());
//printf("Faction Index = %d telling AI to do something pendingQuitError = %d\n",j,pendingQuitError);
if(pendingQuitError == false) aiInterfaces[j]->update();
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] [i = %d] faction = %d, factionCount = %d, took msecs: %lld [after AI updates]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,i,j,world.getFactionCount(),chrono.getMillis());

View File

@ -195,7 +195,8 @@ public:
bool isNetworkGame() const {
bool result = false;
for(int idx = 0; idx < GameConstants::maxPlayers; ++idx) {
if(factionControls[idx] == ctNetwork || factionControls[idx] == ctNetworkUnassigned) {
if(factionControls[idx] == ctNetwork || factionControls[idx] == ctNetworkUnassigned ||
networkPlayerStatuses[idx] == npst_Disconnected) {
result = true;
break;
}