mirror of
https://github.com/glest/glest-source.git
synced 2025-02-25 04:02:30 +01:00
- added server controlled AI as a game option
This commit is contained in:
parent
3dc9c2c623
commit
e85a269738
@ -31,8 +31,6 @@ using namespace Shared::Graphics;
|
|||||||
|
|
||||||
namespace Glest{ namespace Game{
|
namespace Glest{ namespace Game{
|
||||||
|
|
||||||
bool AiInterface::enableServerControlledAI = false;
|
|
||||||
|
|
||||||
AiInterface::AiInterface(Game &game, int factionIndex, int teamIndex){
|
AiInterface::AiInterface(Game &game, int factionIndex, int teamIndex){
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
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;
|
this->teamIndex= teamIndex;
|
||||||
timer= 0;
|
timer= 0;
|
||||||
|
|
||||||
AiInterface::enableServerControlledAI = Config::getInstance().getBool("ServerControlledAI","false");
|
|
||||||
|
|
||||||
//init ai
|
//init ai
|
||||||
ai.init(this);
|
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){
|
CommandResult AiInterface::giveCommand(int unitIndex, CommandClass commandClass, const Vec2i &pos){
|
||||||
assert(this->gameSettings != NULL);
|
assert(this->gameSettings != NULL);
|
||||||
|
|
||||||
if(enableServerControlledAI == true &&
|
if(this->gameSettings->getEnableServerControlledAI() == true &&
|
||||||
this->gameSettings->isNetworkGame() == true &&
|
this->gameSettings->isNetworkGame() == true &&
|
||||||
NetworkManager::getInstance().getNetworkRole() == nrServer) {
|
NetworkManager::getInstance().getNetworkRole() == nrServer) {
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
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){
|
CommandResult AiInterface::giveCommand(int unitIndex, const CommandType *commandType, const Vec2i &pos){
|
||||||
assert(this->gameSettings != NULL);
|
assert(this->gameSettings != NULL);
|
||||||
|
|
||||||
if(enableServerControlledAI == true &&
|
if(this->gameSettings->getEnableServerControlledAI() == true &&
|
||||||
this->gameSettings->isNetworkGame() == true &&
|
this->gameSettings->isNetworkGame() == true &&
|
||||||
NetworkManager::getInstance().getNetworkRole() == nrServer) {
|
NetworkManager::getInstance().getNetworkRole() == nrServer) {
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
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){
|
CommandResult AiInterface::giveCommand(int unitIndex, const CommandType *commandType, const Vec2i &pos, const UnitType *ut){
|
||||||
assert(this->gameSettings != NULL);
|
assert(this->gameSettings != NULL);
|
||||||
|
|
||||||
if(enableServerControlledAI == true &&
|
if(this->gameSettings->getEnableServerControlledAI() == true &&
|
||||||
this->gameSettings->isNetworkGame() == true &&
|
this->gameSettings->isNetworkGame() == true &&
|
||||||
NetworkManager::getInstance().getNetworkRole() == nrServer) {
|
NetworkManager::getInstance().getNetworkRole() == nrServer) {
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
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){
|
CommandResult AiInterface::giveCommand(int unitIndex, const CommandType *commandType, Unit *u){
|
||||||
assert(this->gameSettings != NULL);
|
assert(this->gameSettings != NULL);
|
||||||
assert(this->commander != NULL);
|
assert(this->commander != NULL);
|
||||||
//assert(u != NULL);
|
|
||||||
//assert(u->getType() != NULL);
|
|
||||||
|
|
||||||
if(enableServerControlledAI == true &&
|
if(this->gameSettings->getEnableServerControlledAI() == true &&
|
||||||
this->gameSettings->isNetworkGame() == true &&
|
this->gameSettings->isNetworkGame() == true &&
|
||||||
NetworkManager::getInstance().getNetworkRole() == nrServer) {
|
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__);
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
|
@ -46,8 +46,6 @@ private:
|
|||||||
bool redir;
|
bool redir;
|
||||||
int logLevel;
|
int logLevel;
|
||||||
|
|
||||||
static bool enableServerControlledAI;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
AiInterface(Game &game, int factionIndex, int teamIndex);
|
AiInterface(Game &game, int factionIndex, int teamIndex);
|
||||||
|
|
||||||
@ -89,8 +87,6 @@ public:
|
|||||||
bool checkCosts(const ProducibleType *pt);
|
bool checkCosts(const ProducibleType *pt);
|
||||||
bool isFreeCells(const Vec2i &pos, int size, Field field);
|
bool isFreeCells(const Vec2i &pos, int size, Field field);
|
||||||
|
|
||||||
static bool getEnableServerControlledAI() { return enableServerControlledAI; }
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
string getLogFilename() const {return "ai"+intToStr(factionIndex)+".log";}
|
string getLogFilename() const {return "ai"+intToStr(factionIndex)+".log";}
|
||||||
};
|
};
|
||||||
|
@ -399,7 +399,7 @@ void Game::update(){
|
|||||||
Renderer &renderer= Renderer::getInstance();
|
Renderer &renderer= Renderer::getInstance();
|
||||||
|
|
||||||
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
if( AiInterface::getEnableServerControlledAI() == false ||
|
if( this->gameSettings.getEnableServerControlledAI() == false ||
|
||||||
this->gameSettings.isNetworkGame() == false ||
|
this->gameSettings.isNetworkGame() == false ||
|
||||||
(this->gameSettings.isNetworkGame() == true && networkManager.getNetworkRole() == nrServer)) {
|
(this->gameSettings.isNetworkGame() == true && networkManager.getNetworkRole() == nrServer)) {
|
||||||
//AiInterface
|
//AiInterface
|
||||||
|
@ -45,6 +45,7 @@ private:
|
|||||||
|
|
||||||
bool fogOfWar;
|
bool fogOfWar;
|
||||||
bool enableObserverModeAtEndGame;
|
bool enableObserverModeAtEndGame;
|
||||||
|
bool enableServerControlledAI;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
@ -52,6 +53,7 @@ public:
|
|||||||
GameSettings() {
|
GameSettings() {
|
||||||
fogOfWar = true;
|
fogOfWar = true;
|
||||||
enableObserverModeAtEndGame = false;
|
enableObserverModeAtEndGame = false;
|
||||||
|
enableServerControlledAI = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// default copy constructor will do fine, and will maintain itself ;)
|
// default copy constructor will do fine, and will maintain itself ;)
|
||||||
@ -88,6 +90,7 @@ public:
|
|||||||
|
|
||||||
bool getFogOfWar() const {return fogOfWar;}
|
bool getFogOfWar() const {return fogOfWar;}
|
||||||
bool getEnableObserverModeAtEndGame() const {return enableObserverModeAtEndGame;}
|
bool getEnableObserverModeAtEndGame() const {return enableObserverModeAtEndGame;}
|
||||||
|
bool getEnableServerControlledAI() const {return enableServerControlledAI;}
|
||||||
|
|
||||||
//set
|
//set
|
||||||
void setDescription(const string& description) {this->description= description;}
|
void setDescription(const string& description) {this->description= description;}
|
||||||
@ -111,6 +114,7 @@ public:
|
|||||||
|
|
||||||
void setFogOfWar(bool fogOfWar) {this->fogOfWar = fogOfWar;}
|
void setFogOfWar(bool fogOfWar) {this->fogOfWar = fogOfWar;}
|
||||||
void setEnableObserverModeAtEndGame(bool value) {this->enableObserverModeAtEndGame = value;}
|
void setEnableObserverModeAtEndGame(bool value) {this->enableObserverModeAtEndGame = value;}
|
||||||
|
void setEnableServerControlledAI(bool value) {this->enableServerControlledAI = value;}
|
||||||
};
|
};
|
||||||
|
|
||||||
}}//end namespace
|
}}//end namespace
|
||||||
|
@ -110,13 +110,19 @@ MenuStateCustomGame::MenuStateCustomGame(Program *program, MainMenu *mainMenu, b
|
|||||||
listBoxFogOfWar.setSelectedItemIndex(0);
|
listBoxFogOfWar.setSelectedItemIndex(0);
|
||||||
|
|
||||||
// Enable Observer Mode
|
// Enable Observer Mode
|
||||||
// @350 ? 300 ?
|
|
||||||
labelEnableObserverMode.init(390, 290, 80);
|
labelEnableObserverMode.init(390, 290, 80);
|
||||||
listBoxEnableObserverMode.init(390, 260, 80);
|
listBoxEnableObserverMode.init(390, 260, 80);
|
||||||
listBoxEnableObserverMode.pushBackItem(lang.get("Yes"));
|
listBoxEnableObserverMode.pushBackItem(lang.get("Yes"));
|
||||||
listBoxEnableObserverMode.pushBackItem(lang.get("No"));
|
listBoxEnableObserverMode.pushBackItem(lang.get("No"));
|
||||||
listBoxEnableObserverMode.setSelectedItemIndex(0);
|
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
|
//tileset listBox
|
||||||
findDirs(config.getPathListForType(ptTilesets), results);
|
findDirs(config.getPathListForType(ptTilesets), results);
|
||||||
if (results.empty()) {
|
if (results.empty()) {
|
||||||
@ -215,6 +221,7 @@ MenuStateCustomGame::MenuStateCustomGame(Program *program, MainMenu *mainMenu, b
|
|||||||
labelTeam.setText(lang.get("Team"));
|
labelTeam.setText(lang.get("Team"));
|
||||||
|
|
||||||
labelEnableObserverMode.setText(lang.get("EnableObserverMode"));
|
labelEnableObserverMode.setText(lang.get("EnableObserverMode"));
|
||||||
|
labelEnableServerControlledAI.setText(lang.get("EnableServerControlledAI"));
|
||||||
|
|
||||||
loadMapInfo(Map::getMapPath(mapFiles[listBoxMap.getSelectedItemIndex()]), &mapInfo);
|
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)) {
|
else if (listBoxEnableObserverMode.mouseClick(x, y)) {
|
||||||
needToRepublishToMasterserver = true;
|
needToRepublishToMasterserver = true;
|
||||||
|
|
||||||
|
if(hasNetworkGameSettings() == true)
|
||||||
|
{
|
||||||
|
needToSetChangedGameSettings = true;
|
||||||
|
lastSetChangedGameSettings = time(NULL);
|
||||||
|
}
|
||||||
|
saveGameSettingsToFile("lastCustomGamSettings.mgg");
|
||||||
|
}
|
||||||
|
else if (listBoxEnableServerControlledAI.mouseClick(x, y)) {
|
||||||
|
needToRepublishToMasterserver = true;
|
||||||
|
|
||||||
if(hasNetworkGameSettings() == true)
|
if(hasNetworkGameSettings() == true)
|
||||||
{
|
{
|
||||||
needToSetChangedGameSettings = true;
|
needToSetChangedGameSettings = true;
|
||||||
@ -552,6 +569,7 @@ void MenuStateCustomGame::mouseMove(int x, int y, const MouseState *ms){
|
|||||||
listBoxTechTree.mouseMove(x, y);
|
listBoxTechTree.mouseMove(x, y);
|
||||||
listBoxPublishServer.mouseMove(x, y);
|
listBoxPublishServer.mouseMove(x, y);
|
||||||
listBoxEnableObserverMode.mouseMove(x, y);
|
listBoxEnableObserverMode.mouseMove(x, y);
|
||||||
|
listBoxEnableServerControlledAI.mouseMove(x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MenuStateCustomGame::render(){
|
void MenuStateCustomGame::render(){
|
||||||
@ -587,12 +605,14 @@ void MenuStateCustomGame::render(){
|
|||||||
renderer.renderLabel(&labelTeam);
|
renderer.renderLabel(&labelTeam);
|
||||||
renderer.renderLabel(&labelMapInfo);
|
renderer.renderLabel(&labelMapInfo);
|
||||||
renderer.renderLabel(&labelEnableObserverMode);
|
renderer.renderLabel(&labelEnableObserverMode);
|
||||||
|
renderer.renderLabel(&labelEnableServerControlledAI);
|
||||||
|
|
||||||
renderer.renderListBox(&listBoxMap);
|
renderer.renderListBox(&listBoxMap);
|
||||||
renderer.renderListBox(&listBoxFogOfWar);
|
renderer.renderListBox(&listBoxFogOfWar);
|
||||||
renderer.renderListBox(&listBoxTileset);
|
renderer.renderListBox(&listBoxTileset);
|
||||||
renderer.renderListBox(&listBoxTechTree);
|
renderer.renderListBox(&listBoxTechTree);
|
||||||
renderer.renderListBox(&listBoxEnableObserverMode);
|
renderer.renderListBox(&listBoxEnableObserverMode);
|
||||||
|
renderer.renderListBox(&listBoxEnableServerControlledAI);
|
||||||
|
|
||||||
renderer.renderChatManager(&chatManager);
|
renderer.renderChatManager(&chatManager);
|
||||||
renderer.renderConsole(&console);
|
renderer.renderConsole(&console);
|
||||||
@ -1014,6 +1034,7 @@ void MenuStateCustomGame::loadGameSettings(GameSettings *gameSettings) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
gameSettings->setFactionCount(factionCount);
|
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->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());
|
//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 << "DefaultVictoryConditions=" << gameSettings.getDefaultVictoryConditions() << std::endl;
|
||||||
saveGameFile << "FogOfWar=" << gameSettings.getFogOfWar() << std::endl;
|
saveGameFile << "FogOfWar=" << gameSettings.getFogOfWar() << std::endl;
|
||||||
saveGameFile << "EnableObserverModeAtEndGame=" << gameSettings.getEnableObserverModeAtEndGame() << std::endl;
|
saveGameFile << "EnableObserverModeAtEndGame=" << gameSettings.getEnableObserverModeAtEndGame() << std::endl;
|
||||||
|
saveGameFile << "EnableServerControlledAI=" << gameSettings.getEnableServerControlledAI() << std::endl;
|
||||||
|
|
||||||
saveGameFile << "FactionThisFactionIndex=" << gameSettings.getThisFactionIndex() << std::endl;
|
saveGameFile << "FactionThisFactionIndex=" << gameSettings.getThisFactionIndex() << std::endl;
|
||||||
saveGameFile << "FactionCount=" << gameSettings.getFactionCount() << std::endl;
|
saveGameFile << "FactionCount=" << gameSettings.getFactionCount() << std::endl;
|
||||||
@ -1095,6 +1117,7 @@ GameSettings MenuStateCustomGame::loadGameSettingsFromFile(std::string fileName)
|
|||||||
gameSettings.setDefaultVictoryConditions(properties.getBool("DefaultVictoryConditions"));
|
gameSettings.setDefaultVictoryConditions(properties.getBool("DefaultVictoryConditions"));
|
||||||
gameSettings.setFogOfWar(properties.getBool("FogOfWar"));
|
gameSettings.setFogOfWar(properties.getBool("FogOfWar"));
|
||||||
gameSettings.setEnableObserverModeAtEndGame(properties.getBool("EnableObserverModeAtEndGame"));
|
gameSettings.setEnableObserverModeAtEndGame(properties.getBool("EnableObserverModeAtEndGame"));
|
||||||
|
gameSettings.setEnableServerControlledAI(properties.getBool("EnableServerControlledAI","false"));
|
||||||
|
|
||||||
gameSettings.setThisFactionIndex(properties.getInt("FactionThisFactionIndex"));
|
gameSettings.setThisFactionIndex(properties.getInt("FactionThisFactionIndex"));
|
||||||
gameSettings.setFactionCount(properties.getInt("FactionCount"));
|
gameSettings.setFactionCount(properties.getInt("FactionCount"));
|
||||||
@ -1135,6 +1158,7 @@ GameSettings MenuStateCustomGame::loadGameSettingsFromFile(std::string fileName)
|
|||||||
Lang &lang= Lang::getInstance();
|
Lang &lang= Lang::getInstance();
|
||||||
listBoxFogOfWar.setSelectedItem(gameSettings.getFogOfWar() == true ? lang.get("Yes") : lang.get("No"));
|
listBoxFogOfWar.setSelectedItem(gameSettings.getFogOfWar() == true ? lang.get("Yes") : lang.get("No"));
|
||||||
listBoxEnableObserverMode.setSelectedItem(gameSettings.getEnableObserverModeAtEndGame() == 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__);
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
|
@ -35,11 +35,15 @@ private:
|
|||||||
GraphicLabel labelTileset;
|
GraphicLabel labelTileset;
|
||||||
GraphicLabel labelMapInfo;
|
GraphicLabel labelMapInfo;
|
||||||
GraphicLabel labelEnableObserverMode;
|
GraphicLabel labelEnableObserverMode;
|
||||||
|
GraphicLabel labelEnableServerControlledAI;
|
||||||
|
|
||||||
GraphicListBox listBoxMap;
|
GraphicListBox listBoxMap;
|
||||||
GraphicListBox listBoxFogOfWar;
|
GraphicListBox listBoxFogOfWar;
|
||||||
GraphicListBox listBoxTechTree;
|
GraphicListBox listBoxTechTree;
|
||||||
GraphicListBox listBoxTileset;
|
GraphicListBox listBoxTileset;
|
||||||
GraphicListBox listBoxEnableObserverMode;
|
GraphicListBox listBoxEnableObserverMode;
|
||||||
|
GraphicListBox listBoxEnableServerControlledAI;
|
||||||
|
|
||||||
vector<string> mapFiles;
|
vector<string> mapFiles;
|
||||||
vector<string> techTreeFiles;
|
vector<string> techTreeFiles;
|
||||||
vector<string> tilesetFiles;
|
vector<string> tilesetFiles;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user