- handle it more gracefully when user has no techtrees
This commit is contained in:
parent
9128efcfbb
commit
b05c6c1136
|
@ -3233,6 +3233,9 @@ void CheckForDuplicateData() {
|
||||||
|
|
||||||
string duplicateWarnings="";
|
string duplicateWarnings="";
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
|
||||||
{
|
{
|
||||||
//vector<string> results;
|
//vector<string> results;
|
||||||
|
|
||||||
|
@ -3243,7 +3246,7 @@ void CheckForDuplicateData() {
|
||||||
std::sort(maps.begin(),maps.end());
|
std::sort(maps.begin(),maps.end());
|
||||||
|
|
||||||
if(maps.empty() == true) {
|
if(maps.empty() == true) {
|
||||||
throw megaglest_runtime_error("No maps were found!");
|
throw megaglest_runtime_error("No maps were found!",true);
|
||||||
}
|
}
|
||||||
else if(invalidMapList.empty() == false) {
|
else if(invalidMapList.empty() == false) {
|
||||||
string errorMsg = "Warning invalid maps were detected (will be ignored):\n";
|
string errorMsg = "Warning invalid maps were detected (will be ignored):\n";
|
||||||
|
@ -3290,7 +3293,7 @@ void CheckForDuplicateData() {
|
||||||
if(result != 0) {
|
if(result != 0) {
|
||||||
char *errmsg = strerror(errno);
|
char *errmsg = strerror(errno);
|
||||||
snprintf(szBuf,8096,"Error [%s]\nCould not rename [%s] to [%s]!",errmsg,oldFile.c_str(),newFile.c_str());
|
snprintf(szBuf,8096,"Error [%s]\nCould not rename [%s] to [%s]!",errmsg,oldFile.c_str(),newFile.c_str());
|
||||||
throw megaglest_runtime_error(szBuf);
|
throw megaglest_runtime_error(szBuf,true);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
snprintf(szBuf,8096,"map [%s] in [%s]\nwas renamed to [%s]",duplicateMapsToRename[i].c_str(),oldFile.c_str(),newFile.c_str());
|
snprintf(szBuf,8096,"map [%s] in [%s]\nwas renamed to [%s]",duplicateMapsToRename[i].c_str(),oldFile.c_str(),newFile.c_str());
|
||||||
|
@ -3308,7 +3311,7 @@ void CheckForDuplicateData() {
|
||||||
findDirs(tilesetPaths, tileSets, false, true);
|
findDirs(tilesetPaths, tileSets, false, true);
|
||||||
|
|
||||||
if (tileSets.empty()) {
|
if (tileSets.empty()) {
|
||||||
throw megaglest_runtime_error("No tilesets were found!");
|
throw megaglest_runtime_error("No tilesets were found!",true);
|
||||||
}
|
}
|
||||||
|
|
||||||
vector<string> duplicateTilesetsToRename;
|
vector<string> duplicateTilesetsToRename;
|
||||||
|
@ -3341,7 +3344,7 @@ void CheckForDuplicateData() {
|
||||||
if(result != 0) {
|
if(result != 0) {
|
||||||
char *errmsg = strerror(errno);
|
char *errmsg = strerror(errno);
|
||||||
snprintf(szBuf,8096,"Error [%s]\nCould not rename [%s] to [%s]!",errmsg,oldFile.c_str(),newFile.c_str());
|
snprintf(szBuf,8096,"Error [%s]\nCould not rename [%s] to [%s]!",errmsg,oldFile.c_str(),newFile.c_str());
|
||||||
throw megaglest_runtime_error(szBuf);
|
throw megaglest_runtime_error(szBuf,true);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
snprintf(szBuf,8096,"tileset [%s] in [%s]\nwas renamed to [%s]",duplicateTilesetsToRename[i].c_str(),oldFile.c_str(),newFile.c_str());
|
snprintf(szBuf,8096,"tileset [%s] in [%s]\nwas renamed to [%s]",duplicateTilesetsToRename[i].c_str(),oldFile.c_str(),newFile.c_str());
|
||||||
|
@ -3364,7 +3367,7 @@ void CheckForDuplicateData() {
|
||||||
vector<string> techTrees;
|
vector<string> techTrees;
|
||||||
findDirs(techPaths, techTrees, false, true);
|
findDirs(techPaths, techTrees, false, true);
|
||||||
if(techTrees.empty()) {
|
if(techTrees.empty()) {
|
||||||
throw megaglest_runtime_error("No tech-trees were found!");
|
throw megaglest_runtime_error("No tech-trees were found (dup)!",true);
|
||||||
}
|
}
|
||||||
|
|
||||||
vector<string> duplicateTechtreesToRename;
|
vector<string> duplicateTechtreesToRename;
|
||||||
|
@ -3397,7 +3400,7 @@ void CheckForDuplicateData() {
|
||||||
if(result != 0) {
|
if(result != 0) {
|
||||||
char *errmsg = strerror(errno);
|
char *errmsg = strerror(errno);
|
||||||
snprintf(szBuf,8096,"Error [%s]\nCould not rename [%s] to [%s]!",errmsg,oldFile.c_str(),newFile.c_str());
|
snprintf(szBuf,8096,"Error [%s]\nCould not rename [%s] to [%s]!",errmsg,oldFile.c_str(),newFile.c_str());
|
||||||
throw megaglest_runtime_error(szBuf);
|
throw megaglest_runtime_error(szBuf,true);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
snprintf(szBuf,8096,"techtree [%s] in [%s]\nwas renamed to [%s]",duplicateTechtreesToRename[i].c_str(),oldFile.c_str(),newFile.c_str());
|
snprintf(szBuf,8096,"techtree [%s] in [%s]\nwas renamed to [%s]",duplicateTechtreesToRename[i].c_str(),oldFile.c_str(),newFile.c_str());
|
||||||
|
@ -3415,6 +3418,14 @@ void CheckForDuplicateData() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
catch(const megaglest_runtime_error &ex) {
|
||||||
|
if(mainProgram) {
|
||||||
|
mainProgram->getState()->setForceMouseRender(true);
|
||||||
|
}
|
||||||
|
ExceptionHandler::DisplayMessage(ex.what(), false);
|
||||||
|
}
|
||||||
|
|
||||||
if(duplicateWarnings != "") {
|
if(duplicateWarnings != "") {
|
||||||
if(mainProgram) {
|
if(mainProgram) {
|
||||||
mainProgram->getState()->setForceMouseRender(true);
|
mainProgram->getState()->setForceMouseRender(true);
|
||||||
|
|
|
@ -269,7 +269,9 @@ MenuStateCustomGame::MenuStateCustomGame(Program *program, MainMenu *mainMenu,
|
||||||
|
|
||||||
listBoxTechTree.registerGraphicComponent(containerName,"listBoxTechTree");
|
listBoxTechTree.registerGraphicComponent(containerName,"listBoxTechTree");
|
||||||
listBoxTechTree.init(xoffset+650, mapPos, 150);
|
listBoxTechTree.init(xoffset+650, mapPos, 150);
|
||||||
|
if(listBoxTechTree.getItemCount() > 0) {
|
||||||
listBoxTechTree.setSelectedItemIndex(initialTechSelection);
|
listBoxTechTree.setSelectedItemIndex(initialTechSelection);
|
||||||
|
}
|
||||||
|
|
||||||
labelTechTree.registerGraphicComponent(containerName,"labelTechTree");
|
labelTechTree.registerGraphicComponent(containerName,"labelTechTree");
|
||||||
labelTechTree.init(xoffset+650, mapHeadPos);
|
labelTechTree.init(xoffset+650, mapHeadPos);
|
||||||
|
@ -602,7 +604,6 @@ MenuStateCustomGame::MenuStateCustomGame(Program *program, MainMenu *mainMenu,
|
||||||
}
|
}
|
||||||
|
|
||||||
loadMapInfo(Map::getMapPath(getCurrentMapFile()), &mapInfo, true);
|
loadMapInfo(Map::getMapPath(getCurrentMapFile()), &mapInfo, true);
|
||||||
|
|
||||||
labelMapInfo.setText(mapInfo.desc);
|
labelMapInfo.setText(mapInfo.desc);
|
||||||
|
|
||||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
|
||||||
|
@ -1552,6 +1553,18 @@ bool MenuStateCustomGame::checkNetworkPlayerDataSynch(bool checkMapCRC,
|
||||||
}
|
}
|
||||||
|
|
||||||
void MenuStateCustomGame::PlayNow(bool saveGame) {
|
void MenuStateCustomGame::PlayNow(bool saveGame) {
|
||||||
|
if(listBoxTechTree.getItemCount() <= 0) {
|
||||||
|
mainMessageBoxState=1;
|
||||||
|
|
||||||
|
Lang &lang= Lang::getInstance();
|
||||||
|
char szMsg[8096]="";
|
||||||
|
strcpy(szMsg,"Cannot start game.\nThere are no tech-trees!\n");
|
||||||
|
printf("%s",szMsg);
|
||||||
|
|
||||||
|
showMessageBox(szMsg, "", false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
MutexSafeWrapper safeMutex((publishToMasterserverThread != NULL ? publishToMasterserverThread->getMutexThreadObjectAccessor() : NULL),string(__FILE__) + "_" + intToStr(__LINE__));
|
MutexSafeWrapper safeMutex((publishToMasterserverThread != NULL ? publishToMasterserverThread->getMutexThreadObjectAccessor() : NULL),string(__FILE__) + "_" + intToStr(__LINE__));
|
||||||
if(saveGame == true) {
|
if(saveGame == true) {
|
||||||
saveGameSettingsToFile(SAVED_GAME_FILENAME);
|
saveGameSettingsToFile(SAVED_GAME_FILENAME);
|
||||||
|
@ -1572,7 +1585,8 @@ void MenuStateCustomGame::PlayNow(bool saveGame) {
|
||||||
|
|
||||||
// Check for random faction selection and choose the faction now
|
// Check for random faction selection and choose the faction now
|
||||||
if(listBoxControls[i].getSelectedItemIndex() != ctClosed) {
|
if(listBoxControls[i].getSelectedItemIndex() != ctClosed) {
|
||||||
if(listBoxFactions[i].getSelectedItem() == formatString(GameConstants::RANDOMFACTION_SLOTNAME)) {
|
if(listBoxFactions[i].getSelectedItem() == formatString(GameConstants::RANDOMFACTION_SLOTNAME) &&
|
||||||
|
listBoxFactions[i].getItemCount() > 1) {
|
||||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d] i = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,i);
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d] i = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,i);
|
||||||
|
|
||||||
// Max 1000 tries to get a random, unused faction
|
// Max 1000 tries to get a random, unused faction
|
||||||
|
@ -3143,8 +3157,12 @@ void MenuStateCustomGame::loadGameSettings(GameSettings *gameSettings,bool force
|
||||||
gameSettings->setMapFilterIndex(listBoxMapFilter.getSelectedItemIndex());
|
gameSettings->setMapFilterIndex(listBoxMapFilter.getSelectedItemIndex());
|
||||||
gameSettings->setDescription(formatString(getCurrentMapFile()));
|
gameSettings->setDescription(formatString(getCurrentMapFile()));
|
||||||
gameSettings->setMap(getCurrentMapFile());
|
gameSettings->setMap(getCurrentMapFile());
|
||||||
|
if(tilesetFiles.empty() == false) {
|
||||||
gameSettings->setTileset(tilesetFiles[listBoxTileset.getSelectedItemIndex()]);
|
gameSettings->setTileset(tilesetFiles[listBoxTileset.getSelectedItemIndex()]);
|
||||||
|
}
|
||||||
|
if(techTreeFiles.empty() == false) {
|
||||||
gameSettings->setTech(techTreeFiles[listBoxTechTree.getSelectedItemIndex()]);
|
gameSettings->setTech(techTreeFiles[listBoxTechTree.getSelectedItemIndex()]);
|
||||||
|
}
|
||||||
|
|
||||||
if(autoStartSettings != NULL) {
|
if(autoStartSettings != NULL) {
|
||||||
gameSettings->setDefaultUnits(autoStartSettings->getDefaultUnits());
|
gameSettings->setDefaultUnits(autoStartSettings->getDefaultUnits());
|
||||||
|
@ -4161,7 +4179,10 @@ void MenuStateCustomGame::switchToNextMapGroup(const int direction){
|
||||||
string MenuStateCustomGame::getCurrentMapFile(){
|
string MenuStateCustomGame::getCurrentMapFile(){
|
||||||
int i=listBoxMapFilter.getSelectedItemIndex();
|
int i=listBoxMapFilter.getSelectedItemIndex();
|
||||||
int mapIndex=listBoxMap.getSelectedItemIndex();
|
int mapIndex=listBoxMap.getSelectedItemIndex();
|
||||||
|
if(playerSortedMaps[i].empty() == false) {
|
||||||
return playerSortedMaps[i].at(mapIndex);
|
return playerSortedMaps[i].at(mapIndex);
|
||||||
|
}
|
||||||
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
void MenuStateCustomGame::setActiveInputLabel(GraphicLabel *newLable) {
|
void MenuStateCustomGame::setActiveInputLabel(GraphicLabel *newLable) {
|
||||||
|
@ -4582,7 +4603,8 @@ int MenuStateCustomGame::setupTechList(string scenario, bool forceLoad) {
|
||||||
findDirs(techPaths, results);
|
findDirs(techPaths, results);
|
||||||
|
|
||||||
if(results.empty()) {
|
if(results.empty()) {
|
||||||
throw megaglest_runtime_error("No tech-trees were found!");
|
//throw megaglest_runtime_error("No tech-trees were found!");
|
||||||
|
printf("No tech-trees were found (custom)!\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
techTreeFiles= results;
|
techTreeFiles= results;
|
||||||
|
@ -4625,6 +4647,7 @@ void MenuStateCustomGame::reloadFactions(bool keepExistingSelectedItem, string s
|
||||||
|
|
||||||
//printf("#1 techPaths.size() = %d scenarioDir [%s] [%s]\n",techPaths.size(),scenario.c_str(),scenarioDir.c_str());
|
//printf("#1 techPaths.size() = %d scenarioDir [%s] [%s]\n",techPaths.size(),scenario.c_str(),scenarioDir.c_str());
|
||||||
|
|
||||||
|
if(listBoxTechTree.getItemCount() > 0) {
|
||||||
for(int idx = 0; idx < techPaths.size(); idx++) {
|
for(int idx = 0; idx < techPaths.size(); idx++) {
|
||||||
string &techPath = techPaths[idx];
|
string &techPath = techPaths[idx];
|
||||||
endPathWithSlash(techPath);
|
endPathWithSlash(techPath);
|
||||||
|
@ -4637,12 +4660,18 @@ void MenuStateCustomGame::reloadFactions(bool keepExistingSelectedItem, string s
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(results.empty() == true) {
|
if(results.empty() == true) {
|
||||||
//throw megaglest_runtime_error("(2)There are no factions for the tech tree [" + techTreeFiles[listBoxTechTree.getSelectedItemIndex()] + "]");
|
//throw megaglest_runtime_error("(2)There are no factions for the tech tree [" + techTreeFiles[listBoxTechTree.getSelectedItemIndex()] + "]");
|
||||||
showGeneralError=true;
|
showGeneralError=true;
|
||||||
|
if(listBoxTechTree.getItemCount() > 0) {
|
||||||
generalErrorToShow = "[#2] There are no factions for the tech tree [" + techTreeFiles[listBoxTechTree.getSelectedItemIndex()] + "]";
|
generalErrorToShow = "[#2] There are no factions for the tech tree [" + techTreeFiles[listBoxTechTree.getSelectedItemIndex()] + "]";
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
generalErrorToShow = "[#2] There are no factions since there is no tech tree!";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
results.push_back(formatString(GameConstants::RANDOMFACTION_SLOTNAME));
|
results.push_back(formatString(GameConstants::RANDOMFACTION_SLOTNAME));
|
||||||
|
|
||||||
|
@ -4655,7 +4684,11 @@ void MenuStateCustomGame::reloadFactions(bool keepExistingSelectedItem, string s
|
||||||
factionFiles= results;
|
factionFiles= results;
|
||||||
for(int i = 0; i < results.size(); ++i) {
|
for(int i = 0; i < results.size(); ++i) {
|
||||||
results[i]= formatString(results[i]);
|
results[i]= formatString(results[i]);
|
||||||
string translatedString=techTree->getTranslatedFactionName(techTreeFiles[listBoxTechTree.getSelectedItemIndex()],factionFiles[i]);
|
|
||||||
|
string translatedString = "";
|
||||||
|
if(listBoxTechTree.getItemCount() > 0) {
|
||||||
|
translatedString = techTree->getTranslatedFactionName(techTreeFiles[listBoxTechTree.getSelectedItemIndex()],factionFiles[i]);
|
||||||
|
}
|
||||||
//printf("translatedString=%s formatString(results[i])=%s \n",translatedString.c_str(),formatString(results[i]).c_str() );
|
//printf("translatedString=%s formatString(results[i])=%s \n",translatedString.c_str(),formatString(results[i]).c_str() );
|
||||||
if(toLower(translatedString)==toLower(formatString(results[i]))){
|
if(toLower(translatedString)==toLower(formatString(results[i]))){
|
||||||
translatedFactionNames.push_back(formatString(results[i]));
|
translatedFactionNames.push_back(formatString(results[i]));
|
||||||
|
|
|
@ -130,7 +130,8 @@ ServerInterface::ServerInterface(bool publishEnabled) :GameNetworkInterface() {
|
||||||
vector<string> invalidMapList;
|
vector<string> invalidMapList;
|
||||||
vector<string> allMaps = MapPreview::findAllValidMaps(pathList,scenarioDir,false,true,&invalidMapList);
|
vector<string> allMaps = MapPreview::findAllValidMaps(pathList,scenarioDir,false,true,&invalidMapList);
|
||||||
if (allMaps.empty()) {
|
if (allMaps.empty()) {
|
||||||
throw megaglest_runtime_error("No maps were found!");
|
//throw megaglest_runtime_error("No maps were found!");
|
||||||
|
printf("No maps were found (srv)!\n");
|
||||||
}
|
}
|
||||||
std::sort(allMaps.begin(),allMaps.end());
|
std::sort(allMaps.begin(),allMaps.end());
|
||||||
results.clear();
|
results.clear();
|
||||||
|
@ -140,14 +141,16 @@ ServerInterface::ServerInterface(bool publishEnabled) :GameNetworkInterface() {
|
||||||
results.clear();
|
results.clear();
|
||||||
findDirs(config.getPathListForType(ptTilesets), results);
|
findDirs(config.getPathListForType(ptTilesets), results);
|
||||||
if (results.empty()) {
|
if (results.empty()) {
|
||||||
throw megaglest_runtime_error("No tile-sets were found!");
|
//throw megaglest_runtime_error("No tile-sets were found!");
|
||||||
|
printf("No tile-sets were found (srv)!");
|
||||||
}
|
}
|
||||||
tilesetFiles= results;
|
tilesetFiles= results;
|
||||||
|
|
||||||
results.clear();
|
results.clear();
|
||||||
findDirs(config.getPathListForType(ptTechs), results);
|
findDirs(config.getPathListForType(ptTechs), results);
|
||||||
if(results.empty()) {
|
if(results.empty()) {
|
||||||
throw megaglest_runtime_error("No tech-trees were found!");
|
//throw megaglest_runtime_error("No tech-trees were found!");
|
||||||
|
printf("No tech-trees were found (srv)!\n");
|
||||||
}
|
}
|
||||||
techTreeFiles= results;
|
techTreeFiles= results;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user