- added server controlled AI as a game option

This commit is contained in:
Mark Vejvoda 2010-06-03 01:10:40 +00:00
parent 3dc9c2c623
commit e85a269738
6 changed files with 39 additions and 20 deletions

View File

@ -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__);

View File

@ -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";}
};

View File

@ -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; i<world.getFactionCount(); ++i){

View File

@ -45,6 +45,7 @@ private:
bool fogOfWar;
bool enableObserverModeAtEndGame;
bool enableServerControlledAI;
public:
@ -52,6 +53,7 @@ public:
GameSettings() {
fogOfWar = true;
enableObserverModeAtEndGame = false;
enableServerControlledAI = false;
}
// default copy constructor will do fine, and will maintain itself ;)
@ -88,6 +90,7 @@ public:
bool getFogOfWar() const {return fogOfWar;}
bool getEnableObserverModeAtEndGame() const {return enableObserverModeAtEndGame;}
bool getEnableServerControlledAI() const {return enableServerControlledAI;}
//set
void setDescription(const string& description) {this->description= 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

View File

@ -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__);

View File

@ -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<string> mapFiles;
vector<string> techTreeFiles;
vector<string> tilesetFiles;