diff --git a/source/glest_game/menu/menu_state_custom_game.cpp b/source/glest_game/menu/menu_state_custom_game.cpp index 0d644cfbb..30ebc7c62 100644 --- a/source/glest_game/menu/menu_state_custom_game.cpp +++ b/source/glest_game/menu/menu_state_custom_game.cpp @@ -3823,6 +3823,34 @@ void MenuStateCustomGame::saveGameSettingsToFile(std::string fileName) { if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] Line: %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); } +void MenuStateCustomGame::KeepCurrentHumanPlayerSlots(GameSettings &gameSettings) { + //look for human players + for(int index = 0; index < GameConstants::maxPlayers; ++index) { + ControlType ct= static_cast(listBoxControls[index].getSelectedItemIndex()); + if(ct == ctHuman) { + + bool foundControlType = false; + for(int index2 = 0; index2 < GameConstants::maxPlayers; ++index2) { + ControlType ctFile = static_cast(gameSettings.getFactionControl(index2)); + if(ctFile == ctHuman) { + ControlType ctUI = static_cast(listBoxControls[index2].getSelectedItemIndex()); + if(ctUI != ctNetwork && ctUI != ctNetworkUnassigned) { + foundControlType = true; + //printf("Human found in file [%d]\n",index2); + } + } + } + + //printf("Human found in UI [%d] and file [%d]\n",index,foundControlType); + + if(foundControlType == false) { + gameSettings.setFactionControl(index,ctHuman); + } + gameSettings.setNetworkPlayerName(index,getHumanPlayerName()); + } + } +} + GameSettings MenuStateCustomGame::loadGameSettingsFromFile(std::string fileName) { if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] Line: %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); @@ -3833,10 +3861,7 @@ GameSettings MenuStateCustomGame::loadGameSettingsFromFile(std::string fileName) try { CoreData::getInstance().loadGameSettingsFromFile(fileName, &gameSettings); - - for(int i = 0; i < GameConstants::maxPlayers; ++i) { - gameSettings.setNetworkPlayerName(i,""); - } + KeepCurrentHumanPlayerSlots(gameSettings); // correct game settings for headless: if(this->headlessServerMode == true) { diff --git a/source/glest_game/menu/menu_state_custom_game.h b/source/glest_game/menu/menu_state_custom_game.h index 51af9800a..23a243822 100644 --- a/source/glest_game/menu/menu_state_custom_game.h +++ b/source/glest_game/menu/menu_state_custom_game.h @@ -309,6 +309,7 @@ private: void cleanupThread(SimpleTaskThread **thread); void simpleTaskForMasterServer(BaseThread *callingThread); void simpleTaskForClients(BaseThread *callingThread); + void KeepCurrentHumanPlayerSlots(GameSettings &gameSettings); }; }}//end namespace