- initial code to try out network based scenarios (not yet implemented for masterserver)

This commit is contained in:
Mark Vejvoda 2011-12-26 06:29:14 +00:00
parent dfa8f4a7e2
commit 0338841689
11 changed files with 400 additions and 235 deletions

View File

@ -361,7 +361,13 @@ void GraphicListBox::pushBackItem(string item){
void GraphicListBox::setItems(const vector<string> &items){
this->items= items;
setSelectedItemIndex(0);
if(items.empty() == false) {
setSelectedItemIndex(0);
}
else {
selectedItemIndex=-1;
setText("");
}
}
void GraphicListBox::setSelectedItemIndex(int index, bool errorOnMissing){

View File

@ -27,7 +27,7 @@ using namespace Shared::Platform;
namespace Glest { namespace Game {
const char *mailString = " http://bugs.megaglest.org";
const string glestVersionString = "v3.6.0.2";
const string glestVersionString = "v3.6.1-dev";
#if defined(SVNVERSION)
const string SVN_Rev = string("Rev: ") + string(SVNVERSION);
#elif defined(SVNVERSIONHEADER)

View File

@ -118,6 +118,12 @@ MenuStateConnectedGame::MenuStateConnectedGame(Program *program, MainMenu *mainM
enableFactionTexturePreview = config.getBool("FactionPreview","true");
enableMapPreview = config.getBool("MapPreview","true");
enableScenarioTexturePreview = Config::getInstance().getBool("EnableScenarioTexturePreview","true");
scenarioLogoTexture=NULL;
previewLoadDelayTimer=time(NULL);
needToLoadTextures=true;
this->dirList = Config::getInstance().getPathListForType(ptScenarios);
vector<string> teamItems, controlItems, results, rMultiplier, playerStatuses;
int labelOffset=23;
int setupPos=590;
@ -488,6 +494,44 @@ MenuStateConnectedGame::MenuStateConnectedGame(Program *program, MainMenu *mainM
listBoxTechTree.setItems(techsFormatted);
listBoxTechTree.setSelectedItemIndex(initialTechSelection);
labelScenario.registerGraphicComponent(containerName,"labelScenario");
labelScenario.init(320, 670);
labelScenario.setText(lang.get("Scenario"));
listBoxScenario.registerGraphicComponent(containerName,"listBoxScenario");
listBoxScenario.init(320, 645);
checkBoxScenario.registerGraphicComponent(containerName,"checkBoxScenario");
checkBoxScenario.init(410, 670);
checkBoxScenario.setValue(false);
//scenario listbox
vector<string> resultsScenarios;
findDirs(dirList, resultsScenarios);
// Filter out only scenarios with no network slots
for(int i= 0; i < resultsScenarios.size(); ++i) {
string scenario = resultsScenarios[i];
string file = Scenario::getScenarioPath(dirList, scenario);
Scenario::loadScenarioInfo(file, &scenarioInfo);
bool isNetworkScenario = false;
for(unsigned int j = 0; isNetworkScenario == false && j < GameConstants::maxPlayers; ++j) {
if(scenarioInfo.factionControls[j] == ctNetwork) {
isNetworkScenario = true;
}
}
if(isNetworkScenario == true) {
scenarioFiles.push_back(scenario);
}
}
resultsScenarios.clear();
for(int i = 0; i < scenarioFiles.size(); ++i) {
resultsScenarios.push_back(formatString(scenarioFiles[i]));
}
listBoxScenario.setItems(resultsScenarios);
//if(resultsScenarios.empty() == true) {
checkBoxScenario.setEnabled(false);
//}
if(config.getBool("EnableFTPXfer","true") == true) {
ClientInterface *clientInterface = networkManager.getClientInterface();
@ -662,6 +706,8 @@ void MenuStateConnectedGame::reloadUI() {
}
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
labelScenario.setText(lang.get("Scenario"));
buttonPlayNow.setText(lang.get("PlayNow"));
buttonRestoreLastSettings.setText(lang.get("ReloadLastGameSettings"));
@ -1518,6 +1564,15 @@ void MenuStateConnectedGame::loadGameSettings(GameSettings *gameSettings) {
//gameSettings->setMapFilterIndex(listBoxMapFilter.getSelectedItemIndex());
if(checkBoxScenario.getValue() == true) {
gameSettings->setScenario(scenarioInfo.name);
gameSettings->setScenarioDir(Scenario::getScenarioPath(dirList, scenarioInfo.name));
}
else {
gameSettings->setScenario("");
gameSettings->setScenarioDir("");
}
if(listBoxMap.getSelectedItemIndex() >= 0 && listBoxMap.getSelectedItemIndex() < mapFiles.size()) {
gameSettings->setDescription(formatString(getCurrentMapFile()));
gameSettings->setMap(getCurrentMapFile());
@ -1846,6 +1901,9 @@ void MenuStateConnectedGame::mouseMove(int x, int y, const MouseState *ms) {
listBoxTechTree.mouseMove(x, y);
listBoxPlayerStatus.mouseMove(x,y);
checkBoxScenario.mouseMove(x, y);
listBoxScenario.mouseMove(x, y);
buttonPlayNow.mouseMove(x, y);
buttonRestoreLastSettings.mouseMove(x, y);
}
@ -1869,6 +1927,11 @@ void MenuStateConnectedGame::render() {
//printf("=================> Rendering map preview texture\n");
}
if(scenarioLogoTexture != NULL) {
renderer.renderTextureQuad(300,350,400,300,scenarioLogoTexture,1.0f);
//renderer.renderBackground(scenarioLogoTexture);
}
renderer.renderButton(&buttonDisconnect);
// Get a reference to the player texture cache
@ -2011,6 +2074,13 @@ void MenuStateConnectedGame::render() {
renderer.renderButton(&buttonPlayNow);
renderer.renderButton(&buttonRestoreLastSettings);
//renderer.renderLabel(&labelInfo);
renderer.renderCheckBox(&checkBoxScenario);
renderer.renderLabel(&labelScenario);
if(checkBoxScenario.getValue() == true) {
renderer.renderListBox(&listBoxScenario);
}
MutexSafeWrapper safeMutexFTPProgress((ftpClientThread != NULL ? ftpClientThread->getProgressMutex() : NULL),string(__FILE__) + "_" + intToStr(__LINE__));
if(fileFTPProgressList.empty() == false) {
Lang &lang= Lang::getInstance();
@ -2611,7 +2681,7 @@ void MenuStateConnectedGame::update() {
lastGameSettingsReceivedCount = clientInterface->getGameSettingsReceivedCount();
bool errorOnMissingData = (clientInterface->getAllowGameDataSynchCheck() == false);
const GameSettings *gameSettings = clientInterface->getGameSettings();
GameSettings *gameSettings = clientInterface->getGameSettingsPtr();
setupUIFromGameSettings(gameSettings, errorOnMissingData);
}
@ -3479,7 +3549,7 @@ void MenuStateConnectedGame::FTPClient_CallbackEvent(string itemName,
}
}
void MenuStateConnectedGame::setupUIFromGameSettings(const GameSettings *gameSettings, bool errorOnMissingData) {
void MenuStateConnectedGame::setupUIFromGameSettings(GameSettings *gameSettings, bool errorOnMissingData) {
Lang &lang= Lang::getInstance();
NetworkManager &networkManager= NetworkManager::getInstance();
ClientInterface *clientInterface = networkManager.getClientInterface();
@ -3491,6 +3561,16 @@ void MenuStateConnectedGame::setupUIFromGameSettings(const GameSettings *gameSet
throw runtime_error("gameSettings == NULL");
}
checkBoxScenario.setValue((gameSettings->getScenario() != ""));
if(checkBoxScenario.getValue() == true) {
string scenario = gameSettings->getScenario();
listBoxScenario.setSelectedItem(formatString(scenario));
string file = Scenario::getScenarioPath(dirList, scenario);
Scenario::loadScenarioInfo(file, &scenarioInfo);
gameSettings->setScenarioDir(Scenario::getScenarioPath(dirList, scenarioInfo.name));
}
//printf("A gameSettings->getTileset() [%s]\n",gameSettings->getTileset().c_str());
if(getMissingTilesetFromFTPServerInProgress == false && gameSettings->getTileset() != "") {

View File

@ -180,6 +180,19 @@ private:
GraphicButton buttonPlayNow;
GraphicCheckBox checkBoxScenario;
GraphicLabel labelScenario;
GraphicListBox listBoxScenario;
vector<string> scenarioFiles;
ScenarioInfo scenarioInfo;
vector<string> dirList;
string autoloadScenarioName;
time_t previewLoadDelayTimer;
bool needToLoadTextures;
bool enableScenarioTexturePreview;
Texture2D *scenarioLogoTexture;
bool needToBroadcastServerSettings;
time_t broadcastServerSettingsDelayTimer;
int lastGameSettingsReceivedCount;
@ -231,7 +244,7 @@ private:
void updateResourceMultiplier(const int index);
void RestoreLastGameSettings();
void setupUIFromGameSettings(const GameSettings *gameSettings, bool errorOnMissingData);
void setupUIFromGameSettings(GameSettings *gameSettings, bool errorOnMissingData);
};
}}//end namespace

View File

@ -54,9 +54,11 @@ struct FormatString {
MenuStateCustomGame::MenuStateCustomGame(Program *program, MainMenu *mainMenu,
bool openNetworkSlots,ParentMenuState parentMenuState, bool autostart,
GameSettings *settings, bool masterserverMode) :
MenuState(program, mainMenu, "new-game")
{
GameSettings *settings, bool masterserverMode,
string autoloadScenarioName) :
MenuState(program, mainMenu, "new-game") {
try {
this->masterserverMode = masterserverMode;
if(this->masterserverMode == true) {
printf("Waiting for players to join and start a game...\n");
@ -104,6 +106,13 @@ MenuStateCustomGame::MenuStateCustomGame(Program *program, MainMenu *mainMenu,
showFullConsole=false;
enableScenarioTexturePreview = Config::getInstance().getBool("EnableScenarioTexturePreview","true");
scenarioLogoTexture=NULL;
previewLoadDelayTimer=time(NULL);
needToLoadTextures=true;
this->autoloadScenarioName = autoloadScenarioName;
this->dirList = Config::getInstance().getPathListForType(ptScenarios);
mainMessageBox.registerGraphicComponent(containerName,"mainMessageBox");
mainMessageBox.init(lang.get("Ok"));
mainMessageBox.setEnabled(false);
@ -574,7 +583,7 @@ MenuStateCustomGame::MenuStateCustomGame(Program *program, MainMenu *mainMenu,
generalErrorToShow = "[#1] There are no factions for the tech tree [" + techTreeFiles[listBoxTechTree.getSelectedItemIndex()] + "]";
}
for(int i=0; i<GameConstants::maxPlayers; ++i){
for(int i=0; i < GameConstants::maxPlayers; ++i) {
labelPlayerStatus[i].setText("");
labelPlayers[i].setText(lang.get("Player")+" "+intToStr(i));
@ -647,6 +656,43 @@ MenuStateCustomGame::MenuStateCustomGame(Program *program, MainMenu *mainMenu,
listBoxPlayerStatus.setLighted(false);
listBoxPlayerStatus.setVisible(true);
labelScenario.registerGraphicComponent(containerName,"labelScenario");
labelScenario.init(320, 670);
labelScenario.setText(lang.get("Scenario"));
listBoxScenario.registerGraphicComponent(containerName,"listBoxScenario");
listBoxScenario.init(320, 645);
checkBoxScenario.registerGraphicComponent(containerName,"checkBoxScenario");
checkBoxScenario.init(410, 670);
checkBoxScenario.setValue(false);
//scenario listbox
vector<string> resultsScenarios;
findDirs(dirList, resultsScenarios);
// Filter out only scenarios with no network slots
for(int i= 0; i < resultsScenarios.size(); ++i) {
string scenario = resultsScenarios[i];
string file = Scenario::getScenarioPath(dirList, scenario);
Scenario::loadScenarioInfo(file, &scenarioInfo);
bool isNetworkScenario = false;
for(unsigned int j = 0; isNetworkScenario == false && j < GameConstants::maxPlayers; ++j) {
if(scenarioInfo.factionControls[j] == ctNetwork) {
isNetworkScenario = true;
}
}
if(isNetworkScenario == true) {
scenarioFiles.push_back(scenario);
}
}
resultsScenarios.clear();
for(int i = 0; i < scenarioFiles.size(); ++i) {
resultsScenarios.push_back(formatString(scenarioFiles[i]));
}
listBoxScenario.setItems(resultsScenarios);
if(resultsScenarios.empty() == true) {
checkBoxScenario.setEnabled(false);
}
// write hint to console:
Config &configKeys = Config::getInstance(std::pair<ConfigType,ConfigType>(cfgMainKeys,cfgUserKeys));
@ -661,6 +707,16 @@ MenuStateCustomGame::MenuStateCustomGame(Program *program, MainMenu *mainMenu,
publishToMasterserverThread->start();
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
}
catch(const std::exception &ex) {
char szBuf[4096]="";
sprintf(szBuf,"In [%s::%s %d] Error detected:\n%s\n",__FILE__,__FUNCTION__,__LINE__,ex.what());
SystemFlags::OutputDebug(SystemFlags::debugError,szBuf);
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"%s",szBuf);
throw runtime_error(szBuf);
}
}
void MenuStateCustomGame::reloadUI() {
@ -827,6 +883,8 @@ void MenuStateCustomGame::reloadUI() {
playerStatuses.push_back(lang.get("PlayerStatusReady"));
listBoxPlayerStatus.setItems(playerStatuses);
labelScenario.setText(lang.get("Scenario"));
// write hint to console:
Config &configKeys = Config::getInstance(std::pair<ConfigType,ConfigType>(cfgMainKeys,cfgUserKeys));
@ -1160,6 +1218,9 @@ void MenuStateCustomGame::mouseClick(int x, int y, MouseButton mouseButton) {
soundRenderer.playFx(coreData.getClickSoundC());
}
else if(listBoxScenario.mouseClick(x, y) || checkBoxScenario.mouseClick(x,y)) {
processScenario();
}
else {
for(int i = 0; i < mapInfo.players; ++i) {
MutexSafeWrapper safeMutex((publishToMasterserverThread != NULL ? publishToMasterserverThread->getMutexThreadObjectAccessor() : NULL),string(__FILE__) + "_" + intToStr(__LINE__));
@ -1677,6 +1738,9 @@ void MenuStateCustomGame::mouseMove(int x, int y, const MouseState *ms) {
listBoxPublishServer.mouseMove(x, y);
listBoxAdvanced.mouseMove(x, y);
checkBoxScenario.mouseMove(x, y);
listBoxScenario.mouseMove(x, y);
}
bool MenuStateCustomGame::isMasterserverMode() const {
@ -1696,6 +1760,11 @@ void MenuStateCustomGame::render() {
//printf("=================> Rendering map preview texture\n");
}
if(scenarioLogoTexture != NULL) {
renderer.renderTextureQuad(300,350,400,300,scenarioLogoTexture,1.0f);
//renderer.renderBackground(scenarioLogoTexture);
}
if(mainMessageBox.getEnabled()) {
renderer.renderMessageBox(&mainMessageBox);
}
@ -1857,6 +1926,13 @@ void MenuStateCustomGame::render() {
}
}
//renderer.renderLabel(&labelInfo);
renderer.renderCheckBox(&checkBoxScenario);
renderer.renderLabel(&labelScenario);
if(checkBoxScenario.getValue() == true) {
renderer.renderListBox(&listBoxScenario);
}
if(program != NULL) program->renderProgramMsgBox();
if( enableMapPreview == true &&
@ -2002,6 +2078,35 @@ void MenuStateCustomGame::update() {
ServerInterface* serverInterface= NetworkManager::getInstance().getServerInterface();
Lang& lang= Lang::getInstance();
if(this->autoloadScenarioName != "") {
listBoxScenario.setSelectedItem(formatString(this->autoloadScenarioName),false);
if(listBoxScenario.getSelectedItem() != formatString(this->autoloadScenarioName)) {
mainMessageBoxState=1;
showMessageBox( "Could not find scenario name: " + formatString(this->autoloadScenarioName), "Scenario Missing", false);
this->autoloadScenarioName = "";
}
else {
loadScenarioInfo(Scenario::getScenarioPath(dirList, scenarioFiles[listBoxScenario.getSelectedItemIndex()]), &scenarioInfo);
//labelInfo.setText(scenarioInfo.desc);
SoundRenderer &soundRenderer= SoundRenderer::getInstance();
CoreData &coreData= CoreData::getInstance();
soundRenderer.playFx(coreData.getClickSoundC());
//launchGame();
PlayNow(true);
return;
}
}
if(needToLoadTextures) {
// this delay is done to make it possible to switch faster
if(difftime(time(NULL), previewLoadDelayTimer) >= 2){
//loadScenarioPreviewTexture();
needToLoadTextures= false;
}
}
//bool haveAtLeastOneNetworkClientConnected = false;
bool hasOneNetworkSlotOpen = false;
int currentConnectionCount=0;
@ -2796,6 +2901,15 @@ void MenuStateCustomGame::loadGameSettings(GameSettings *gameSettings,bool force
//gameSettings->setFlagTypes1(ft1_show_map_resources);
//
if(checkBoxScenario.getValue() == true) {
gameSettings->setScenario(scenarioInfo.name);
gameSettings->setScenarioDir(Scenario::getScenarioPath(dirList, scenarioInfo.name));
}
else {
gameSettings->setScenario("");
gameSettings->setScenarioDir("");
}
gameSettings->setMapFilterIndex(listBoxMapFilter.getSelectedItemIndex());
gameSettings->setDescription(formatString(getCurrentMapFile()));
gameSettings->setMap(getCurrentMapFile());
@ -3149,79 +3263,7 @@ GameSettings MenuStateCustomGame::loadGameSettingsFromFile(std::string fileName)
GameSettings originalGameSettings;
loadGameSettings(&originalGameSettings);
// Config &config = Config::getInstance();
// string userData = config.getString("UserData_Root","");
// if(userData != "") {
// endPathWithSlash(userData);
// }
// fileName = userData + fileName;
//
// if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] fileName = [%s]\n",__FILE__,__FUNCTION__,__LINE__,fileName.c_str());
//
// if(fileExists(fileName) == false) {
// return gameSettings;
// }
try {
// Properties properties;
// if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] fileName = [%s]\n",__FILE__,__FUNCTION__,__LINE__,fileName.c_str());
//
// properties.load(fileName);
//
// if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] fileName = [%s]\n",__FILE__,__FUNCTION__,__LINE__,fileName.c_str());
//
// gameSettings.setMapFilterIndex(properties.getInt("MapFilterIndex","0"));
// gameSettings.setDescription(properties.getString("Description"));
// gameSettings.setMap(properties.getString("Map"));
// gameSettings.setTileset(properties.getString("Tileset"));
// gameSettings.setTech(properties.getString("TechTree"));
// gameSettings.setDefaultUnits(properties.getBool("DefaultUnits"));
// gameSettings.setDefaultResources(properties.getBool("DefaultResources"));
// gameSettings.setDefaultVictoryConditions(properties.getBool("DefaultVictoryConditions"));
// gameSettings.setFogOfWar(properties.getBool("FogOfWar"));
// listBoxAdvanced.setSelectedItemIndex(properties.getInt("AdvancedIndex","0"));
//
// gameSettings.setAllowObservers(properties.getBool("AllowObservers","false"));
//
// gameSettings.setFlagTypes1(properties.getInt("FlagTypes1","0"));
//
// gameSettings.setEnableObserverModeAtEndGame(properties.getBool("EnableObserverModeAtEndGame"));
//
// gameSettings.setAiAcceptSwitchTeamPercentChance(properties.getInt("AiAcceptSwitchTeamPercentChance","30"));
//
// gameSettings.setPathFinderType(static_cast<PathFinderType>(properties.getInt("PathFinderType",intToStr(pfBasic).c_str())));
// gameSettings.setEnableServerControlledAI(properties.getBool("EnableServerControlledAI","true"));
// gameSettings.setNetworkFramePeriod(properties.getInt("NetworkFramePeriod",intToStr(GameConstants::networkFramePeriod).c_str()));
// gameSettings.setNetworkPauseGameForLaggedClients(properties.getBool("NetworkPauseGameForLaggedClients","false"));
//
// gameSettings.setThisFactionIndex(properties.getInt("FactionThisFactionIndex"));
// gameSettings.setFactionCount(properties.getInt("FactionCount"));
//
// //for(int i = 0; i < gameSettings.getFactionCount(); ++i) {
// for(int i = 0; i < GameConstants::maxPlayers; ++i) {
// gameSettings.setFactionControl(i,(ControlType)properties.getInt(string("FactionControlForIndex") + intToStr(i),intToStr(ctClosed).c_str()) );
//
// if(gameSettings.getFactionControl(i) == ctNetworkUnassigned) {
// gameSettings.setFactionControl(i,ctNetwork);
// }
//
// gameSettings.setResourceMultiplierIndex(i,properties.getInt(string("ResourceMultiplierIndex") + intToStr(i),"5"));
// gameSettings.setTeam(i,properties.getInt(string("FactionTeamForIndex") + intToStr(i),"0") );
// gameSettings.setStartLocationIndex(i,properties.getInt(string("FactionStartLocationForIndex") + intToStr(i),intToStr(i).c_str()) );
// gameSettings.setFactionTypeName(i,properties.getString(string("FactionTypeNameForIndex") + intToStr(i),"?") );
//
// if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] i = %d, factionTypeName [%s]\n",__FILE__,__FUNCTION__,__LINE__,i,gameSettings.getFactionTypeName(i).c_str());
//
// if(gameSettings.getFactionControl(i) == ctHuman) {
// gameSettings.setNetworkPlayerName(i,properties.getString(string("FactionPlayerNameForIndex") + intToStr(i),"") );
// }
// else {
// gameSettings.setNetworkPlayerName(i,"");
// }
// }
//
// if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
CoreData::getInstance().loadGameSettingsFromFile(fileName, &gameSettings);
setupUIFromGameSettings(gameSettings);
}
@ -3245,6 +3287,11 @@ void MenuStateCustomGame::setupUIFromGameSettings(const GameSettings &gameSettin
//printf("In [%s::%s line %d] map [%s]\n",__FILE__,__FUNCTION__,__LINE__,gameSettings.getMap().c_str());
checkBoxScenario.setValue((gameSettings.getScenario() != ""));
if(checkBoxScenario.getValue() == true) {
listBoxScenario.setSelectedItem(formatString(gameSettings.getScenario()));
}
string mapFile = gameSettings.getMap();
if(find(mapFiles.begin(),mapFiles.end(),mapFile) != mapFiles.end()) {
mapFile = formatString(mapFile);
@ -3988,9 +4035,154 @@ int32 MenuStateCustomGame::getNetworkPlayerStatus() {
return result;
}
void MenuStateCustomGame::loadScenarioInfo(string file, ScenarioInfo *scenarioInfo) {
//printf("Load scenario file [%s]\n",file.c_str());
Scenario::loadScenarioInfo(file, scenarioInfo);
//cleanupPreviewTexture();
previewLoadDelayTimer=time(NULL);
needToLoadTextures=true;
}
bool MenuStateCustomGame::isInSpecialKeyCaptureEvent() {
bool result = (chatManager.getEditEnabled() || activeInputLabel != NULL);
return result;
}
void MenuStateCustomGame::processScenario() {
try {
if(checkBoxScenario.getValue() == true) {
//printf("listBoxScenario.getSelectedItemIndex() = %d [%s] scenarioFiles.size() = %d\n",listBoxScenario.getSelectedItemIndex(),listBoxScenario.getSelectedItem().c_str(),scenarioFiles.size());
loadScenarioInfo(Scenario::getScenarioPath(dirList, scenarioFiles[listBoxScenario.getSelectedItemIndex()]), &scenarioInfo);
listBoxTechTree.setSelectedItem(formatString(scenarioInfo.techTreeName));
reloadFactions(false);
listBoxTileset.setSelectedItem(formatString(scenarioInfo.tilesetName));
listBoxMap.setSelectedItem(formatString(scenarioInfo.mapName));
loadMapInfo(Map::getMapPath(getCurrentMapFile(),"",false), &mapInfo, true);
labelMapInfo.setText(mapInfo.desc);
for(int i = 0; i < mapInfo.players; ++i) {
listBoxRMultiplier[i].setSelectedItem(floatToStr(scenarioInfo.resourceMultipliers[i],1));
updateResourceMultiplier(i);
ServerInterface* serverInterface= NetworkManager::getInstance().getServerInterface();
ConnectionSlot *slot = serverInterface->getSlot(i);
bool checkControTypeClicked = false;
int selectedControlItemIndex = listBoxControls[i].getSelectedItemIndex();
if(selectedControlItemIndex != ctNetwork ||
(selectedControlItemIndex == ctNetwork && (slot == NULL || slot->isConnected() == false))) {
checkControTypeClicked = true;
}
listBoxControls[i].setSelectedItemIndex(scenarioInfo.factionControls[i]);
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
// Skip over networkunassigned
//if(listBoxControls[i].getSelectedItemIndex() == ctNetworkUnassigned &&
// selectedControlItemIndex != ctNetworkUnassigned) {
// listBoxControls[i].mouseClick(x, y);
//}
//look for human players
int humanIndex1= -1;
int humanIndex2= -1;
for(int j = 0; j < GameConstants::maxPlayers; ++j) {
ControlType ct= static_cast<ControlType>(listBoxControls[j].getSelectedItemIndex());
if(ct == ctHuman) {
if(humanIndex1 == -1) {
humanIndex1= j;
}
else {
humanIndex2= j;
}
}
}
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d] humanIndex1 = %d, humanIndex2 = %d\n",__FILE__,__FUNCTION__,__LINE__,humanIndex1,humanIndex2);
//no human
if(humanIndex1 == -1 && humanIndex2 == -1) {
listBoxControls[i].setSelectedItemIndex(ctHuman);
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d] i = %d, labelPlayerNames[i].getText() [%s]\n",__FILE__,__FUNCTION__,__LINE__,i,labelPlayerNames[i].getText().c_str());
//printf("humanIndex1 = %d humanIndex2 = %d i = %d listBoxControls[i].getSelectedItemIndex() = %d\n",humanIndex1,humanIndex2,i,listBoxControls[i].getSelectedItemIndex());
}
//2 humans
else if(humanIndex1 != -1 && humanIndex2 != -1) {
int closeSlotIndex = (humanIndex1 == i ? humanIndex2: humanIndex1);
int humanSlotIndex = (closeSlotIndex == humanIndex1 ? humanIndex2 : humanIndex1);
string origPlayName = labelPlayerNames[closeSlotIndex].getText();
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d] closeSlotIndex = %d, origPlayName [%s]\n",__FILE__,__FUNCTION__,__LINE__,closeSlotIndex,origPlayName.c_str());
//printf("humanIndex1 = %d humanIndex2 = %d i = %d closeSlotIndex = %d humanSlotIndex = %d\n",humanIndex1,humanIndex2,i,closeSlotIndex,humanSlotIndex);
listBoxControls[closeSlotIndex].setSelectedItemIndex(ctClosed);
labelPlayerNames[humanSlotIndex].setText((origPlayName != "" ? origPlayName : getHumanPlayerName()));
}
//updateNetworkSlots();
//updateResourceMultiplier(i);
listBoxFactions[i].setSelectedItem(formatString(scenarioInfo.factionTypeNames[i]));
// Disallow CPU players to be observers
if(factionFiles[listBoxFactions[i].getSelectedItemIndex()] == formatString(GameConstants::OBSERVER_SLOTNAME) &&
(listBoxControls[i].getSelectedItemIndex() == ctCpuEasy || listBoxControls[i].getSelectedItemIndex() == ctCpu ||
listBoxControls[i].getSelectedItemIndex() == ctCpuUltra || listBoxControls[i].getSelectedItemIndex() == ctCpuMega)) {
listBoxFactions[i].setSelectedItemIndex(0);
}
//
listBoxTeams[i].setSelectedItem(intToStr(scenarioInfo.teams[i]));
if(factionFiles[listBoxFactions[i].getSelectedItemIndex()] != formatString(GameConstants::OBSERVER_SLOTNAME)) {
if(listBoxTeams[i].getSelectedItemIndex() + 1 != (GameConstants::maxPlayers + fpt_Observer)) {
lastSelectedTeamIndex[i] = listBoxTeams[i].getSelectedItemIndex();
}
}
else {
lastSelectedTeamIndex[i] = -1;
}
if(listBoxPublishServer.getSelectedItemIndex() == 0) {
needToRepublishToMasterserver = true;
}
if(hasNetworkGameSettings() == true)
{
needToSetChangedGameSettings = true;
lastSetChangedGameSettings = time(NULL);;
}
}
updateControlers();
updateNetworkSlots();
MutexSafeWrapper safeMutex((publishToMasterserverThread != NULL ? publishToMasterserverThread->getMutexThreadObjectAccessor() : NULL),string(__FILE__) + "_" + intToStr(__LINE__));
if(listBoxPublishServer.getSelectedItemIndex() == 0) {
needToRepublishToMasterserver = true;
}
if(hasNetworkGameSettings() == true) {
needToSetChangedGameSettings = true;
lastSetChangedGameSettings = time(NULL);
}
//labelInfo.setText(scenarioInfo.desc);
}
}
catch(const std::exception &ex) {
char szBuf[4096]="";
sprintf(szBuf,"In [%s::%s %d] Error detected:\n%s\n",__FILE__,__FUNCTION__,__LINE__,ex.what());
SystemFlags::OutputDebug(SystemFlags::debugError,szBuf);
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"%s",szBuf);
mainMessageBoxState=1;
showMessageBox( "Error: " + string(ex.what()), "Error detected", false);
}
}
}}//end namespace

View File

@ -114,6 +114,18 @@ private:
GraphicLabel labelAISwitchTeamAcceptPercent;
GraphicListBox listBoxAISwitchTeamAcceptPercent;
GraphicCheckBox checkBoxScenario;
GraphicLabel labelScenario;
GraphicListBox listBoxScenario;
vector<string> scenarioFiles;
ScenarioInfo scenarioInfo;
vector<string> dirList;
string autoloadScenarioName;
time_t previewLoadDelayTimer;
bool needToLoadTextures;
bool enableScenarioTexturePreview;
Texture2D *scenarioLogoTexture;
bool needToSetChangedGameSettings;
time_t lastSetChangedGameSettings;
time_t lastMasterserverPublishing;
@ -181,7 +193,8 @@ private:
public:
MenuStateCustomGame(Program *program, MainMenu *mainMenu ,
bool openNetworkSlots= false, ParentMenuState parentMenuState=pNewGame,
bool autostart=false,GameSettings *settings=NULL,bool masterserverMode=false);
bool autostart=false,GameSettings *settings=NULL,bool masterserverMode=false,
string autoloadScenarioName="");
virtual ~MenuStateCustomGame();
void mouseClick(int x, int y, MouseButton mouseButton);
@ -241,6 +254,8 @@ private:
bool onlyNetworkUnassigned);
void reloadUI();
void loadScenarioInfo(string file, ScenarioInfo *scenarioInfo);
void processScenario();
};
}}//end namespace

View File

@ -261,112 +261,6 @@ void MenuStateScenario::setScenario(int i) {
}
void MenuStateScenario::loadScenarioInfo(string file, ScenarioInfo *scenarioInfo) {
// Lang &lang= Lang::getInstance();
//
// XmlTree xmlTree;
// xmlTree.load(file,Properties::getTagReplacementValues());
//
// const XmlNode *scenarioNode= xmlTree.getRootNode();
// const XmlNode *difficultyNode= scenarioNode->getChild("difficulty");
// scenarioInfo->difficulty = difficultyNode->getAttribute("value")->getIntValue();
// if( scenarioInfo->difficulty < dVeryEasy || scenarioInfo->difficulty > dInsane ) {
// char szBuf[4096]="";
// sprintf(szBuf,"Invalid difficulty value specified in scenario: %d must be between %d and %d",scenarioInfo->difficulty,dVeryEasy,dInsane);
// throw std::runtime_error(szBuf);
// }
//
// const XmlNode *playersNode= scenarioNode->getChild("players");
//
// for(int i= 0; i < GameConstants::maxPlayers; ++i) {
// XmlNode* playerNode=NULL;
// string factionTypeName="";
// ControlType factionControl;
//
// if(playersNode->hasChildAtIndex("player",i)){
// playerNode = playersNode->getChild("player", i);
// factionControl = strToControllerType( playerNode->getAttribute("control")->getValue() );
//
// if(playerNode->getAttribute("resource_multiplier",false)!=NULL) {
// // if a multiplier exists use it
// scenarioInfo->resourceMultipliers[i]=playerNode->getAttribute("resource_multiplier")->getFloatValue();
// }
// else {
// // if no multiplier exists use defaults
// scenarioInfo->resourceMultipliers[i]=GameConstants::normalMultiplier;
// if(factionControl==ctCpuEasy) {
// scenarioInfo->resourceMultipliers[i]=GameConstants::easyMultiplier;
// }
// if(factionControl==ctCpuUltra) {
// scenarioInfo->resourceMultipliers[i]=GameConstants::ultraMultiplier;
// }
// else if(factionControl==ctCpuMega) {
// scenarioInfo->resourceMultipliers[i]=GameConstants::megaMultiplier;
// }
// }
//
// }
// else {
// factionControl=ctClosed;
// }
//
// scenarioInfo->factionControls[i] = factionControl;
//
// if(factionControl != ctClosed){
// int teamIndex = playerNode->getAttribute("team")->getIntValue();
//
// if( teamIndex < 1 || teamIndex > GameConstants::maxPlayers ) {
// char szBuf[4096]="";
// sprintf(szBuf,"Invalid team value specified in scenario: %d must be between %d and %d",teamIndex,1,GameConstants::maxPlayers);
// throw std::runtime_error(szBuf);
// }
//
// scenarioInfo->teams[i]= playerNode->getAttribute("team")->getIntValue();
// scenarioInfo->factionTypeNames[i]= playerNode->getAttribute("faction")->getValue();
// }
//
// scenarioInfo->mapName = scenarioNode->getChild("map")->getAttribute("value")->getValue();
// scenarioInfo->tilesetName = scenarioNode->getChild("tileset")->getAttribute("value")->getValue();
// scenarioInfo->techTreeName = scenarioNode->getChild("tech-tree")->getAttribute("value")->getValue();
// scenarioInfo->defaultUnits = scenarioNode->getChild("default-units")->getAttribute("value")->getBoolValue();
// scenarioInfo->defaultResources = scenarioNode->getChild("default-resources")->getAttribute("value")->getBoolValue();
// scenarioInfo->defaultVictoryConditions = scenarioNode->getChild("default-victory-conditions")->getAttribute("value")->getBoolValue();
// }
//
// //add player info
// scenarioInfo->desc= lang.get("Player") + ": ";
// for(int i=0; i<GameConstants::maxPlayers; ++i) {
// if(scenarioInfo->factionControls[i] == ctHuman) {
// scenarioInfo->desc+= formatString(scenarioInfo->factionTypeNames[i]);
// break;
// }
// }
//
// //add misc info
// string difficultyString = "Difficulty" + intToStr(scenarioInfo->difficulty);
//
// scenarioInfo->desc+= "\n";
// scenarioInfo->desc+= lang.get("Difficulty") + ": " + lang.get(difficultyString) +"\n";
// scenarioInfo->desc+= lang.get("Map") + ": " + formatString(scenarioInfo->mapName) + "\n";
// scenarioInfo->desc+= lang.get("Tileset") + ": " + formatString(scenarioInfo->tilesetName) + "\n";
// scenarioInfo->desc+= lang.get("TechTree") + ": " + formatString(scenarioInfo->techTreeName) + "\n";
//
// if(scenarioNode->hasChild("fog-of-war") == true) {
// if(scenarioNode->getChild("fog-of-war")->getAttribute("value")->getValue() == "explored") {
// scenarioInfo->fogOfWar = true;
// scenarioInfo->fogOfWar_exploredFlag = true;
// }
// else {
// scenarioInfo->fogOfWar = scenarioNode->getChild("fog-of-war")->getAttribute("value")->getBoolValue();
// scenarioInfo->fogOfWar_exploredFlag = false;
// }
// //printf("\nFOG OF WAR is set to [%d]\n",scenarioInfo->fogOfWar);
// }
// else {
// scenarioInfo->fogOfWar = true;
// scenarioInfo->fogOfWar_exploredFlag = false;
// }
//scenarioLogoTexture = NULL;
Scenario::loadScenarioInfo(file, scenarioInfo);
cleanupPreviewTexture();
@ -410,49 +304,6 @@ void MenuStateScenario::loadGameSettings(const ScenarioInfo *scenarioInfo, GameS
}
Scenario::loadGameSettings(dirList,scenarioInfo, gameSettings, formatString(scenarioFiles[listBoxScenario.getSelectedItemIndex()]));
// int factionCount= 0;
//
// //printf("\n\n\n$$$$$$$$$$$$$ [%s]\n\n\n",scenarioFiles[listBoxScenario.getSelectedItemIndex()].c_str());
//
// gameSettings->setDescription(formatString(scenarioFiles[listBoxScenario.getSelectedItemIndex()]));
// gameSettings->setMap(scenarioInfo->mapName);
// gameSettings->setTileset(scenarioInfo->tilesetName);
// gameSettings->setTech(scenarioInfo->techTreeName);
// gameSettings->setScenario(scenarioFiles[listBoxScenario.getSelectedItemIndex()]);
// gameSettings->setScenarioDir(Scenario::getScenarioPath(dirList, scenarioFiles[listBoxScenario.getSelectedItemIndex()]));
// gameSettings->setDefaultUnits(scenarioInfo->defaultUnits);
// gameSettings->setDefaultResources(scenarioInfo->defaultResources);
// gameSettings->setDefaultVictoryConditions(scenarioInfo->defaultVictoryConditions);
//
// for(int i=0; i<GameConstants::maxPlayers; ++i){
// ControlType ct= static_cast<ControlType>(scenarioInfo->factionControls[i]);
// if(ct!=ctClosed){
// if(ct==ctHuman){
// gameSettings->setThisFactionIndex(factionCount);
// }
// gameSettings->setFactionControl(factionCount, ct);
// gameSettings->setResourceMultiplierIndex(factionCount, (scenarioInfo->resourceMultipliers[i]-0.5f)/0.1f);
// gameSettings->setTeam(factionCount, scenarioInfo->teams[i]-1);
// gameSettings->setStartLocationIndex(factionCount, i);
// gameSettings->setFactionTypeName(factionCount, scenarioInfo->factionTypeNames[i]);
// factionCount++;
// }
// }
//
// gameSettings->setFactionCount(factionCount);
// gameSettings->setFogOfWar(scenarioInfo->fogOfWar);
// uint32 valueFlags1 = gameSettings->getFlagTypes1();
// if(scenarioInfo->fogOfWar == false || scenarioInfo->fogOfWar_exploredFlag) {
// valueFlags1 |= ft1_show_map_resources;
// gameSettings->setFlagTypes1(valueFlags1);
// }
// else {
// valueFlags1 &= ~ft1_show_map_resources;
// gameSettings->setFlagTypes1(valueFlags1);
// }
//
// gameSettings->setPathFinderType(static_cast<PathFinderType>(Config::getInstance().getInt("ScenarioPathFinderType",intToStr(pfBasic).c_str())));
}
void MenuStateScenario::showMessageBox(const string &text, const string &header, bool toggle){
@ -472,11 +323,8 @@ void MenuStateScenario::showMessageBox(const string &text, const string &header,
void MenuStateScenario::keyDown(SDL_KeyboardEvent key) {
Config &configKeys = Config::getInstance(std::pair<ConfigType,ConfigType>(cfgMainKeys,cfgUserKeys));
//if(key == configKeys.getCharKey("SaveGUILayout")) {
if(isKeyPressed(configKeys.getSDLKey("SaveGUILayout"),key) == true) {
GraphicComponent::saveAllCustomProperties(containerName);
//Lang &lang= Lang::getInstance();
//console.addLine(lang.get("GUILayoutSaved") + " [" + (saved ? lang.get("Yes") : lang.get("No"))+ "]");
}
}

View File

@ -126,6 +126,7 @@ public:
virtual bool isConnected();
const virtual GameSettings * getGameSettings() { return &gameSettings; }
GameSettings * getGameSettingsPtr() { return &gameSettings; }
static void setAllowDownloadDataSynch(bool value) { allowDownloadDataSynch = value; }
static bool getAllowDownloadDataSynch() { return allowDownloadDataSynch; }

View File

@ -244,6 +244,8 @@ NetworkMessageLaunch::NetworkMessageLaunch(const GameSettings *gameSettings,int8
data.aiAcceptSwitchTeamPercentChance = gameSettings->getAiAcceptSwitchTeamPercentChance();
data.masterserver_admin = gameSettings->getMasterserver_admin();
data.scenario = gameSettings->getScenario();
}
void NetworkMessageLaunch::buildGameSettings(GameSettings *gameSettings) const {
@ -292,6 +294,8 @@ void NetworkMessageLaunch::buildGameSettings(GameSettings *gameSettings) const {
gameSettings->setAiAcceptSwitchTeamPercentChance(data.aiAcceptSwitchTeamPercentChance);
gameSettings->setMasterserver_admin(data.masterserver_admin);
gameSettings->setScenario(data.scenario.getString());
}
vector<pair<string,int32> > NetworkMessageLaunch::getFactionCRCList() const {
@ -320,6 +324,7 @@ bool NetworkMessageLaunch::receive(Socket* socket) {
data.factionNameList[i].nullTerminate();
}
data.scenario.nullTerminate();
return result;
}

View File

@ -235,6 +235,8 @@ private:
int8 aiAcceptSwitchTeamPercentChance;
int32 masterserver_admin;
NetworkString<maxStringSize> scenario;
};
private:

View File

@ -159,7 +159,7 @@ void Scenario::loadScenarioInfo(string file, ScenarioInfo *scenarioInfo) {
playerNode = playersNode->getChild("player", i);
factionControl = strToControllerType( playerNode->getAttribute("control")->getValue() );
if(playerNode->getAttribute("resource_multiplier",false)!=NULL) {
if(playerNode->getAttribute("resource_multiplier",false) != NULL) {
// if a multiplier exists use it
scenarioInfo->resourceMultipliers[i]=playerNode->getAttribute("resource_multiplier")->getFloatValue();
}
@ -268,6 +268,9 @@ ControlType Scenario::strToControllerType(const string &str) {
else if(str=="human"){
return ctHuman;
}
else if(str=="network"){
return ctNetwork;
}
char szBuf[4096]="";
sprintf(szBuf,"Invalid controller value specified in scenario: [%s] must be one of the following: closed, cpu-easy, cpu, cpu-ultra, cpu-mega, human",str.c_str());