From e85a2697389817fef9c396a80c48d2590cfa59ea Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Thu, 3 Jun 2010 01:10:40 +0000 Subject: [PATCH] - added server controlled AI as a game option --- source/glest_game/ai/ai_interface.cpp | 17 +++--------- source/glest_game/ai/ai_interface.h | 4 --- source/glest_game/game/game.cpp | 4 +-- source/glest_game/game/game_settings.h | 4 +++ .../menu/menu_state_custom_game.cpp | 26 ++++++++++++++++++- .../glest_game/menu/menu_state_custom_game.h | 4 +++ 6 files changed, 39 insertions(+), 20 deletions(-) diff --git a/source/glest_game/ai/ai_interface.cpp b/source/glest_game/ai/ai_interface.cpp index 9284f0ee..cbafa7a2 100644 --- a/source/glest_game/ai/ai_interface.cpp +++ b/source/glest_game/ai/ai_interface.cpp @@ -31,8 +31,6 @@ using namespace Shared::Graphics; namespace Glest{ namespace Game{ -bool AiInterface::enableServerControlledAI = false; - AiInterface::AiInterface(Game &game, int factionIndex, int teamIndex){ SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); @@ -45,8 +43,6 @@ AiInterface::AiInterface(Game &game, int factionIndex, int teamIndex){ this->teamIndex= teamIndex; timer= 0; - AiInterface::enableServerControlledAI = Config::getInstance().getBool("ServerControlledAI","false"); - //init ai ai.init(this); @@ -99,7 +95,7 @@ void AiInterface::printLog(int logLevel, const string &s){ CommandResult AiInterface::giveCommand(int unitIndex, CommandClass commandClass, const Vec2i &pos){ assert(this->gameSettings != NULL); - if(enableServerControlledAI == true && + if(this->gameSettings->getEnableServerControlledAI() == true && this->gameSettings->isNetworkGame() == true && NetworkManager::getInstance().getNetworkRole() == nrServer) { SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); @@ -124,7 +120,7 @@ CommandResult AiInterface::giveCommand(int unitIndex, CommandClass commandClass, CommandResult AiInterface::giveCommand(int unitIndex, const CommandType *commandType, const Vec2i &pos){ assert(this->gameSettings != NULL); - if(enableServerControlledAI == true && + if(this->gameSettings->getEnableServerControlledAI() == true && this->gameSettings->isNetworkGame() == true && NetworkManager::getInstance().getNetworkRole() == nrServer) { SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); @@ -149,7 +145,7 @@ CommandResult AiInterface::giveCommand(int unitIndex, const CommandType *command CommandResult AiInterface::giveCommand(int unitIndex, const CommandType *commandType, const Vec2i &pos, const UnitType *ut){ assert(this->gameSettings != NULL); - if(enableServerControlledAI == true && + if(this->gameSettings->getEnableServerControlledAI() == true && this->gameSettings->isNetworkGame() == true && NetworkManager::getInstance().getNetworkRole() == nrServer) { SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); @@ -174,15 +170,10 @@ CommandResult AiInterface::giveCommand(int unitIndex, const CommandType *command CommandResult AiInterface::giveCommand(int unitIndex, const CommandType *commandType, Unit *u){ assert(this->gameSettings != NULL); assert(this->commander != NULL); - //assert(u != NULL); - //assert(u->getType() != NULL); - if(enableServerControlledAI == true && + if(this->gameSettings->getEnableServerControlledAI() == true && this->gameSettings->isNetworkGame() == true && NetworkManager::getInstance().getNetworkRole() == nrServer) { - SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); - - //assert(u != NULL); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); diff --git a/source/glest_game/ai/ai_interface.h b/source/glest_game/ai/ai_interface.h index 80c45f80..cd206180 100644 --- a/source/glest_game/ai/ai_interface.h +++ b/source/glest_game/ai/ai_interface.h @@ -46,8 +46,6 @@ private: bool redir; int logLevel; - static bool enableServerControlledAI; - public: AiInterface(Game &game, int factionIndex, int teamIndex); @@ -89,8 +87,6 @@ public: bool checkCosts(const ProducibleType *pt); bool isFreeCells(const Vec2i &pos, int size, Field field); - static bool getEnableServerControlledAI() { return enableServerControlledAI; } - private: string getLogFilename() const {return "ai"+intToStr(factionIndex)+".log";} }; diff --git a/source/glest_game/game/game.cpp b/source/glest_game/game/game.cpp index 748b4278..a17faa34 100644 --- a/source/glest_game/game/game.cpp +++ b/source/glest_game/game/game.cpp @@ -399,8 +399,8 @@ void Game::update(){ Renderer &renderer= Renderer::getInstance(); //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); - if( AiInterface::getEnableServerControlledAI() == false || - this->gameSettings.isNetworkGame() == false || + if( this->gameSettings.getEnableServerControlledAI() == false || + this->gameSettings.isNetworkGame() == false || (this->gameSettings.isNetworkGame() == true && networkManager.getNetworkRole() == nrServer)) { //AiInterface for(int i=0; idescription= description;} @@ -111,6 +114,7 @@ public: void setFogOfWar(bool fogOfWar) {this->fogOfWar = fogOfWar;} void setEnableObserverModeAtEndGame(bool value) {this->enableObserverModeAtEndGame = value;} + void setEnableServerControlledAI(bool value) {this->enableServerControlledAI = value;} }; }}//end namespace diff --git a/source/glest_game/menu/menu_state_custom_game.cpp b/source/glest_game/menu/menu_state_custom_game.cpp index ff90bceb..8d5752a5 100644 --- a/source/glest_game/menu/menu_state_custom_game.cpp +++ b/source/glest_game/menu/menu_state_custom_game.cpp @@ -110,13 +110,19 @@ MenuStateCustomGame::MenuStateCustomGame(Program *program, MainMenu *mainMenu, b listBoxFogOfWar.setSelectedItemIndex(0); // Enable Observer Mode - // @350 ? 300 ? labelEnableObserverMode.init(390, 290, 80); listBoxEnableObserverMode.init(390, 260, 80); listBoxEnableObserverMode.pushBackItem(lang.get("Yes")); listBoxEnableObserverMode.pushBackItem(lang.get("No")); listBoxEnableObserverMode.setSelectedItemIndex(0); + // Enable Server Controlled AI + labelEnableServerControlledAI.init(390, 235, 80); + listBoxEnableServerControlledAI.init(390, 215, 80); + listBoxEnableServerControlledAI.pushBackItem(lang.get("Yes")); + listBoxEnableServerControlledAI.pushBackItem(lang.get("No")); + listBoxEnableServerControlledAI.setSelectedItemIndex(1); + //tileset listBox findDirs(config.getPathListForType(ptTilesets), results); if (results.empty()) { @@ -215,6 +221,7 @@ MenuStateCustomGame::MenuStateCustomGame(Program *program, MainMenu *mainMenu, b labelTeam.setText(lang.get("Team")); labelEnableObserverMode.setText(lang.get("EnableObserverMode")); + labelEnableServerControlledAI.setText(lang.get("EnableServerControlledAI")); loadMapInfo(Map::getMapPath(mapFiles[listBoxMap.getSelectedItemIndex()]), &mapInfo); @@ -431,6 +438,16 @@ void MenuStateCustomGame::mouseClick(int x, int y, MouseButton mouseButton){ else if (listBoxEnableObserverMode.mouseClick(x, y)) { needToRepublishToMasterserver = true; + if(hasNetworkGameSettings() == true) + { + needToSetChangedGameSettings = true; + lastSetChangedGameSettings = time(NULL); + } + saveGameSettingsToFile("lastCustomGamSettings.mgg"); + } + else if (listBoxEnableServerControlledAI.mouseClick(x, y)) { + needToRepublishToMasterserver = true; + if(hasNetworkGameSettings() == true) { needToSetChangedGameSettings = true; @@ -552,6 +569,7 @@ void MenuStateCustomGame::mouseMove(int x, int y, const MouseState *ms){ listBoxTechTree.mouseMove(x, y); listBoxPublishServer.mouseMove(x, y); listBoxEnableObserverMode.mouseMove(x, y); + listBoxEnableServerControlledAI.mouseMove(x, y); } void MenuStateCustomGame::render(){ @@ -587,12 +605,14 @@ void MenuStateCustomGame::render(){ renderer.renderLabel(&labelTeam); renderer.renderLabel(&labelMapInfo); renderer.renderLabel(&labelEnableObserverMode); + renderer.renderLabel(&labelEnableServerControlledAI); renderer.renderListBox(&listBoxMap); renderer.renderListBox(&listBoxFogOfWar); renderer.renderListBox(&listBoxTileset); renderer.renderListBox(&listBoxTechTree); renderer.renderListBox(&listBoxEnableObserverMode); + renderer.renderListBox(&listBoxEnableServerControlledAI); renderer.renderChatManager(&chatManager); renderer.renderConsole(&console); @@ -1014,6 +1034,7 @@ void MenuStateCustomGame::loadGameSettings(GameSettings *gameSettings) { } } gameSettings->setFactionCount(factionCount); + gameSettings->setEnableServerControlledAI(listBoxEnableServerControlledAI.getSelectedItemIndex() == 0); //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] gameSettings->getTileset() = [%s]\n",__FILE__,__FUNCTION__,gameSettings->getTileset().c_str()); //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] gameSettings->getTech() = [%s]\n",__FILE__,__FUNCTION__,gameSettings->getTech().c_str()); @@ -1050,6 +1071,7 @@ void MenuStateCustomGame::saveGameSettingsToFile(std::string fileName) { saveGameFile << "DefaultVictoryConditions=" << gameSettings.getDefaultVictoryConditions() << std::endl; saveGameFile << "FogOfWar=" << gameSettings.getFogOfWar() << std::endl; saveGameFile << "EnableObserverModeAtEndGame=" << gameSettings.getEnableObserverModeAtEndGame() << std::endl; + saveGameFile << "EnableServerControlledAI=" << gameSettings.getEnableServerControlledAI() << std::endl; saveGameFile << "FactionThisFactionIndex=" << gameSettings.getThisFactionIndex() << std::endl; saveGameFile << "FactionCount=" << gameSettings.getFactionCount() << std::endl; @@ -1095,6 +1117,7 @@ GameSettings MenuStateCustomGame::loadGameSettingsFromFile(std::string fileName) gameSettings.setDefaultVictoryConditions(properties.getBool("DefaultVictoryConditions")); gameSettings.setFogOfWar(properties.getBool("FogOfWar")); gameSettings.setEnableObserverModeAtEndGame(properties.getBool("EnableObserverModeAtEndGame")); + gameSettings.setEnableServerControlledAI(properties.getBool("EnableServerControlledAI","false")); gameSettings.setThisFactionIndex(properties.getInt("FactionThisFactionIndex")); gameSettings.setFactionCount(properties.getInt("FactionCount")); @@ -1135,6 +1158,7 @@ GameSettings MenuStateCustomGame::loadGameSettingsFromFile(std::string fileName) Lang &lang= Lang::getInstance(); listBoxFogOfWar.setSelectedItem(gameSettings.getFogOfWar() == true ? lang.get("Yes") : lang.get("No")); listBoxEnableObserverMode.setSelectedItem(gameSettings.getEnableObserverModeAtEndGame() == true ? lang.get("Yes") : lang.get("No")); + listBoxEnableServerControlledAI.setSelectedItem(gameSettings.getEnableServerControlledAI() == true ? lang.get("Yes") : lang.get("No")); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); diff --git a/source/glest_game/menu/menu_state_custom_game.h b/source/glest_game/menu/menu_state_custom_game.h index 2427837e..29a72e9d 100644 --- a/source/glest_game/menu/menu_state_custom_game.h +++ b/source/glest_game/menu/menu_state_custom_game.h @@ -35,11 +35,15 @@ private: GraphicLabel labelTileset; GraphicLabel labelMapInfo; GraphicLabel labelEnableObserverMode; + GraphicLabel labelEnableServerControlledAI; + GraphicListBox listBoxMap; GraphicListBox listBoxFogOfWar; GraphicListBox listBoxTechTree; GraphicListBox listBoxTileset; GraphicListBox listBoxEnableObserverMode; + GraphicListBox listBoxEnableServerControlledAI; + vector mapFiles; vector techTreeFiles; vector tilesetFiles;