- centralized finding map files and validation of map files. a New report at game start shows a list of invalid maps which will be ignored
- headless server now shows GUI messages in console - made 'blocked player' button font smaller
This commit is contained in:
parent
a0888b8292
commit
dc6cd9281f
|
@ -603,6 +603,7 @@ public:
|
|||
}
|
||||
|
||||
static int DisplayMessage(const char *msg, bool exitApp) {
|
||||
//printf("In [%s::%s Line: %d] msg [%s] exitApp = %d\n",__FILE__,__FUNCTION__,__LINE__,msg,exitApp);
|
||||
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] msg [%s] exitApp = %d\n",__FILE__,__FUNCTION__,__LINE__,msg,exitApp);
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] msg [%s] exitApp = %d\n",__FILE__,__FUNCTION__,__LINE__,msg,exitApp);
|
||||
|
||||
|
@ -2180,8 +2181,10 @@ void CheckForDuplicateData() {
|
|||
string duplicateWarnings="";
|
||||
|
||||
{
|
||||
vector<string> maps;
|
||||
std::vector<std::string> results;
|
||||
// vector<string> maps;
|
||||
vector<string> results;
|
||||
|
||||
/*
|
||||
vector<string> mapPaths = config.getPathListForType(ptMaps);
|
||||
|
||||
findAll(mapPaths, "*.gbm", results, false, false, true);
|
||||
|
@ -2197,6 +2200,26 @@ void CheckForDuplicateData() {
|
|||
if(maps.empty()) {
|
||||
throw runtime_error("No maps were found!");
|
||||
}
|
||||
*/
|
||||
string scenarioDir = "";
|
||||
vector<string> pathList = config.getPathListForType(ptMaps,scenarioDir);
|
||||
vector<string> invalidMapList;
|
||||
vector<string> maps = MapPreview::findAllValidMaps(pathList,scenarioDir,false,true,&invalidMapList);
|
||||
std::sort(maps.begin(),maps.end());
|
||||
|
||||
if(maps.empty() == true) {
|
||||
throw runtime_error("No maps were found!");
|
||||
}
|
||||
else if(invalidMapList.size() > 0) {
|
||||
string errorMsg = "Warning invalid maps were detected (will be ignored):\n";
|
||||
for(int i = 0; i < invalidMapList.size(); ++i) {
|
||||
char szBuf[4096]="";
|
||||
sprintf(szBuf,"map [%s]\n",invalidMapList[i].c_str());
|
||||
|
||||
errorMsg += szBuf;
|
||||
}
|
||||
duplicateWarnings += errorMsg;
|
||||
}
|
||||
|
||||
vector<string> duplicateMapsToRename;
|
||||
for(int i = 0; i < maps.size(); ++i) {
|
||||
|
@ -2218,7 +2241,7 @@ void CheckForDuplicateData() {
|
|||
if(duplicateMapsToRename.empty() == false) {
|
||||
string errorMsg = "Warning duplicate maps were detected and renamed:\n";
|
||||
for(int i = 0; i < duplicateMapsToRename.size(); ++i) {
|
||||
string currentPath = mapPaths[1];
|
||||
string currentPath = pathList[1];
|
||||
endPathWithSlash(currentPath);
|
||||
|
||||
string oldFile = currentPath + duplicateMapsToRename[i];
|
||||
|
|
|
@ -712,6 +712,10 @@ void Program::showMessage(const char *msg) {
|
|||
|
||||
msgBox.setText(msg);
|
||||
msgBox.setEnabled(true);
|
||||
|
||||
if(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == true) {
|
||||
printf("Message:\n%s\n",msg);
|
||||
}
|
||||
}
|
||||
|
||||
void Program::stopSoundSystem() {
|
||||
|
|
|
@ -24,21 +24,6 @@
|
|||
|
||||
namespace Glest{ namespace Game{
|
||||
|
||||
//misc consts
|
||||
class MapInfo {
|
||||
public:
|
||||
|
||||
Vec2i size;
|
||||
int players;
|
||||
string desc;
|
||||
|
||||
MapInfo() {
|
||||
size = Vec2i(0,0);
|
||||
players = 0;
|
||||
desc = "";
|
||||
}
|
||||
};
|
||||
|
||||
class MenuState;
|
||||
|
||||
// =====================================================
|
||||
|
|
|
@ -406,6 +406,8 @@ MenuStateConnectedGame::MenuStateConnectedGame(Program *program, MainMenu *mainM
|
|||
//map listBox
|
||||
// put them all in a set, to weed out duplicates (gbm & mgm with same name)
|
||||
// will also ensure they are alphabetically listed (rather than how the OS provides them)
|
||||
|
||||
/*
|
||||
set<string> allMaps;
|
||||
findAll(config.getPathListForType(ptMaps), "*.gbm", results, true, false);
|
||||
copy(results.begin(), results.end(), std::inserter(allMaps, allMaps.begin()));
|
||||
|
@ -419,19 +421,32 @@ MenuStateConnectedGame::MenuStateConnectedGame(Program *program, MainMenu *mainM
|
|||
}
|
||||
copy(allMaps.begin(), allMaps.end(), std::back_inserter(results));
|
||||
mapFiles = results;
|
||||
*/
|
||||
|
||||
string scenarioDir = "";
|
||||
vector<string> pathList = config.getPathListForType(ptMaps,scenarioDir);
|
||||
vector<string> invalidMapList;
|
||||
vector<string> allMaps = MapPreview::findAllValidMaps(pathList,scenarioDir,false,true,&invalidMapList);
|
||||
if (allMaps.empty()) {
|
||||
throw runtime_error("No maps were found!");
|
||||
}
|
||||
results.clear();
|
||||
copy(allMaps.begin(), allMaps.end(), std::back_inserter(results));
|
||||
mapFiles = results;
|
||||
|
||||
copy(mapFiles.begin(), mapFiles.end(), std::back_inserter(playerSortedMaps[0]));
|
||||
copy(playerSortedMaps[0].begin(), playerSortedMaps[0].end(), std::back_inserter(formattedPlayerSortedMaps[0]));
|
||||
std::for_each(formattedPlayerSortedMaps[0].begin(), formattedPlayerSortedMaps[0].end(), FormatString());
|
||||
|
||||
for(int i= 0; i < mapFiles.size(); i++){// fetch info and put map in right list
|
||||
loadMapInfo(Map::getMapPath(mapFiles.at(i), "", false), &mapInfo, false);
|
||||
playerSortedMaps[mapInfo.players].push_back(mapFiles.at(i));
|
||||
formattedPlayerSortedMaps[mapInfo.players].push_back(formatString(mapFiles.at(i)));
|
||||
formattedMapFiles.push_back(formatString(mapFiles.at(i)));
|
||||
//if(config.getString("InitialMap", "Conflict") == formattedPlayerSortedMaps[mapInfo.players].back()){
|
||||
// initialMapSelection= i;
|
||||
//}
|
||||
if(loadMapInfo(Map::getMapPath(mapFiles.at(i), "", false), &mapInfo, false) == true) {
|
||||
playerSortedMaps[mapInfo.players].push_back(mapFiles.at(i));
|
||||
formattedPlayerSortedMaps[mapInfo.players].push_back(formatString(mapFiles.at(i)));
|
||||
formattedMapFiles.push_back(formatString(mapFiles.at(i)));
|
||||
//if(config.getString("InitialMap", "Conflict") == formattedPlayerSortedMaps[mapInfo.players].back()){
|
||||
// initialMapSelection= i;
|
||||
//}
|
||||
}
|
||||
}
|
||||
//listBoxMap.setItems(formattedPlayerSortedMaps[0]);
|
||||
listBoxMap.setItems(formattedMapFiles);
|
||||
|
@ -1126,8 +1141,12 @@ void MenuStateConnectedGame::mouseClickAdmin(int x, int y, MouseButton mouseButt
|
|||
|
||||
//MutexSafeWrapper safeMutex((publishToMasterserverThread != NULL ? publishToMasterserverThread->getMutexThreadObjectAccessor() : NULL),string(__FILE__) + "_" + intToStr(__LINE__));
|
||||
|
||||
loadMapInfo(Map::getMapPath(getCurrentMapFile(),"",false), &mapInfo, true);
|
||||
labelMapInfo.setText(mapInfo.desc);
|
||||
if(loadMapInfo(Map::getMapPath(getCurrentMapFile(),"",false), &mapInfo, true) == true) {
|
||||
labelMapInfo.setText(mapInfo.desc);
|
||||
}
|
||||
else {
|
||||
labelMapInfo.setText("???");
|
||||
}
|
||||
|
||||
//updateControlers();
|
||||
//updateNetworkSlots();
|
||||
|
@ -2981,6 +3000,8 @@ void MenuStateConnectedGame::loadFactionTexture(string filepath) {
|
|||
|
||||
bool MenuStateConnectedGame::loadMapInfo(string file, MapInfo *mapInfo, bool loadMapPreview) {
|
||||
|
||||
|
||||
/*
|
||||
Lang &lang= Lang::getInstance();
|
||||
|
||||
bool mapLoaded = false;
|
||||
|
@ -3071,6 +3092,77 @@ bool MenuStateConnectedGame::loadMapInfo(string file, MapInfo *mapInfo, bool loa
|
|||
showMessageBox( "Error loading map file: "+file+'\n'+e.what(), "Error", false);
|
||||
}
|
||||
|
||||
return mapLoaded;
|
||||
*/
|
||||
|
||||
bool mapLoaded = false;
|
||||
try {
|
||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] map [%s]\n",__FILE__,__FUNCTION__,__LINE__,file.c_str());
|
||||
|
||||
if(file != "") {
|
||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
lastMissingMap = file;
|
||||
|
||||
Lang &lang= Lang::getInstance();
|
||||
if(MapPreview::loadMapInfo(file, mapInfo, lang.get("MaxPlayers"),lang.get("Size"),true) == true) {
|
||||
for(int i = 0; i < GameConstants::maxPlayers; ++i) {
|
||||
labelPlayers[i].setVisible(i+1 <= mapInfo->players);
|
||||
labelPlayerNames[i].setVisible(i+1 <= mapInfo->players);
|
||||
listBoxControls[i].setVisible(i+1 <= mapInfo->players);
|
||||
listBoxFactions[i].setVisible(i+1 <= mapInfo->players);
|
||||
listBoxTeams[i].setVisible(i+1 <= mapInfo->players);
|
||||
labelNetStatus[i].setVisible(i+1 <= mapInfo->players);
|
||||
}
|
||||
|
||||
// Not painting properly so this is on hold
|
||||
if(loadMapPreview == true) {
|
||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
if(mapPreview.getMapFileLoaded() != file) {
|
||||
mapPreview.loadFromFile(file.c_str());
|
||||
cleanupMapPreviewTexture();
|
||||
}
|
||||
}
|
||||
|
||||
mapLoaded = true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
cleanupMapPreviewTexture();
|
||||
mapInfo->desc = ITEM_MISSING;
|
||||
|
||||
NetworkManager &networkManager= NetworkManager::getInstance();
|
||||
ClientInterface* clientInterface= networkManager.getClientInterface();
|
||||
const GameSettings *gameSettings = clientInterface->getGameSettings();
|
||||
|
||||
if(lastMissingMap != gameSettings->getMap()) {
|
||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
lastMissingMap = gameSettings->getMap();
|
||||
|
||||
Lang &lang= Lang::getInstance();
|
||||
const vector<string> languageList = clientInterface->getGameSettings()->getUniqueNetworkPlayerLanguages();
|
||||
for(unsigned int i = 0; i < languageList.size(); ++i) {
|
||||
|
||||
char szMsg[1024]="";
|
||||
if(lang.hasString("DataMissingMap",languageList[i]) == true) {
|
||||
sprintf(szMsg,lang.get("DataMissingMap",languageList[i]).c_str(),getHumanPlayerName().c_str(),gameSettings->getMap().c_str());
|
||||
}
|
||||
else {
|
||||
sprintf(szMsg,"Player: %s is missing the map: %s",getHumanPlayerName().c_str(),gameSettings->getMap().c_str());
|
||||
}
|
||||
clientInterface->sendTextMessage(szMsg,-1, lang.isLanguageLocal(languageList[i]),languageList[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(exception &e){
|
||||
SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,e.what());
|
||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] error [%s]\n",__FILE__,__FUNCTION__,__LINE__,e.what());
|
||||
|
||||
showMessageBox( "Error loading map file: "+file+'\n'+e.what(), "Error", false);
|
||||
}
|
||||
|
||||
return mapLoaded;
|
||||
}
|
||||
|
||||
|
|
|
@ -173,6 +173,8 @@ MenuStateCustomGame::MenuStateCustomGame(Program *program, MainMenu *mainMenu,
|
|||
//map listBox
|
||||
// put them all in a set, to weed out duplicates (gbm & mgm with same name)
|
||||
// will also ensure they are alphabetically listed (rather than how the OS provides them)
|
||||
|
||||
/*
|
||||
set<string> allMaps;
|
||||
findAll(config.getPathListForType(ptMaps), "*.gbm", results, true, false);
|
||||
copy(results.begin(), results.end(), std::inserter(allMaps, allMaps.begin()));
|
||||
|
@ -187,6 +189,19 @@ MenuStateCustomGame::MenuStateCustomGame(Program *program, MainMenu *mainMenu,
|
|||
copy(allMaps.begin(), allMaps.end(), std::back_inserter(results));
|
||||
mapFiles = results;
|
||||
|
||||
copy(mapFiles.begin(), mapFiles.end(), std::back_inserter(playerSortedMaps[0]));
|
||||
*/
|
||||
string scenarioDir = "";
|
||||
vector<string> pathList = config.getPathListForType(ptMaps,scenarioDir);
|
||||
vector<string> invalidMapList;
|
||||
vector<string> allMaps = MapPreview::findAllValidMaps(pathList,scenarioDir,false,true,&invalidMapList);
|
||||
if (allMaps.empty()) {
|
||||
throw runtime_error("No maps were found!");
|
||||
}
|
||||
results.clear();
|
||||
copy(allMaps.begin(), allMaps.end(), std::back_inserter(results));
|
||||
mapFiles = results;
|
||||
|
||||
copy(mapFiles.begin(), mapFiles.end(), std::back_inserter(playerSortedMaps[0]));
|
||||
copy(playerSortedMaps[0].begin(), playerSortedMaps[0].end(), std::back_inserter(formattedPlayerSortedMaps[0]));
|
||||
std::for_each(formattedPlayerSortedMaps[0].begin(), formattedPlayerSortedMaps[0].end(), FormatString());
|
||||
|
@ -463,6 +478,8 @@ MenuStateCustomGame::MenuStateCustomGame(Program *program, MainMenu *mainMenu,
|
|||
buttonBlockPlayers[i].registerGraphicComponent(containerName,"buttonBlockPlayers" + intToStr(i));
|
||||
buttonBlockPlayers[i].init(xoffset+355, setupPos-30-i*rowHeight, 70);
|
||||
buttonBlockPlayers[i].setText(lang.get("BlockPlayer"));
|
||||
buttonBlockPlayers[i].setFont(CoreData::getInstance().getDisplayFontSmall());
|
||||
buttonBlockPlayers[i].setFont3D(CoreData::getInstance().getDisplayFontSmall3D());
|
||||
|
||||
listBoxRMultiplier[i].registerGraphicComponent(containerName,"listBoxRMultiplier" + intToStr(i));
|
||||
listBoxRMultiplier[i].init(xoffset+350, setupPos-30-i*rowHeight,70);
|
||||
|
@ -3383,6 +3400,9 @@ bool MenuStateCustomGame::hasNetworkGameSettings() {
|
|||
}
|
||||
|
||||
void MenuStateCustomGame::loadMapInfo(string file, MapInfo *mapInfo, bool loadMapPreview) {
|
||||
|
||||
|
||||
/*
|
||||
Lang &lang= Lang::getInstance();
|
||||
|
||||
try{
|
||||
|
@ -3441,7 +3461,47 @@ void MenuStateCustomGame::loadMapInfo(string file, MapInfo *mapInfo, bool loadMa
|
|||
SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s] loading map [%s]\n",__FILE__,__FUNCTION__,__LINE__,e.what(),file.c_str());
|
||||
throw runtime_error("Error loading map file: [" + file + "] msg: " + e.what());
|
||||
}
|
||||
*/
|
||||
|
||||
try {
|
||||
Lang &lang= Lang::getInstance();
|
||||
if(MapPreview::loadMapInfo(file, mapInfo, lang.get("MaxPlayers"),lang.get("Size"),true) == true) {
|
||||
ServerInterface* serverInterface= NetworkManager::getInstance().getServerInterface();
|
||||
for(int i = 0; i < GameConstants::maxPlayers; ++i) {
|
||||
if(serverInterface->getSlot(i) != NULL &&
|
||||
(listBoxControls[i].getSelectedItemIndex() == ctNetwork ||
|
||||
listBoxControls[i].getSelectedItemIndex() == ctNetworkUnassigned)) {
|
||||
if(serverInterface->getSlot(i)->isConnected() == true) {
|
||||
if(i+1 > mapInfo->players &&
|
||||
listBoxControls[i].getSelectedItemIndex() != ctNetworkUnassigned) {
|
||||
listBoxControls[i].setSelectedItemIndex(ctNetworkUnassigned);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
labelPlayers[i].setVisible(i+1 <= mapInfo->players);
|
||||
labelPlayerNames[i].setVisible(i+1 <= mapInfo->players);
|
||||
listBoxControls[i].setVisible(i+1 <= mapInfo->players);
|
||||
listBoxFactions[i].setVisible(i+1 <= mapInfo->players);
|
||||
listBoxTeams[i].setVisible(i+1 <= mapInfo->players);
|
||||
labelNetStatus[i].setVisible(i+1 <= mapInfo->players);
|
||||
}
|
||||
|
||||
// Not painting properly so this is on hold
|
||||
if(loadMapPreview == true) {
|
||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
mapPreview.loadFromFile(file.c_str());
|
||||
|
||||
//printf("Loading map preview MAP\n");
|
||||
cleanupMapPreviewTexture();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(exception &e) {
|
||||
SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s] loading map [%s]\n",__FILE__,__FUNCTION__,__LINE__,e.what(),file.c_str());
|
||||
throw runtime_error("Error loading map file: [" + file + "] msg: " + e.what());
|
||||
}
|
||||
}
|
||||
|
||||
void MenuStateCustomGame::reloadFactions(bool keepExistingSelectedItem) {
|
||||
|
|
|
@ -776,6 +776,9 @@ void MenuStateMods::simpleTask(BaseThread *callingThread) {
|
|||
}
|
||||
|
||||
MapInfo MenuStateMods::loadMapInfo(string file) {
|
||||
|
||||
|
||||
/*
|
||||
Lang &lang= Lang::getInstance();
|
||||
|
||||
MapInfo mapInfo;
|
||||
|
@ -806,6 +809,20 @@ MapInfo MenuStateMods::loadMapInfo(string file) {
|
|||
throw runtime_error("Error loading map file: [" + file + "] msg: " + e.what());
|
||||
}
|
||||
|
||||
return mapInfo;
|
||||
*/
|
||||
|
||||
MapInfo mapInfo;
|
||||
//memset(&mapInfo,0,sizeof(mapInfo));
|
||||
try{
|
||||
Lang &lang= Lang::getInstance();
|
||||
MapPreview::loadMapInfo(file, &mapInfo, lang.get("MaxPlayers"),lang.get("Size"),true);
|
||||
}
|
||||
catch(exception &e) {
|
||||
SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s] loading map [%s]\n",__FILE__,__FUNCTION__,__LINE__,e.what(),file.c_str());
|
||||
throw runtime_error("Error loading map file: [" + file + "] msg: " + e.what());
|
||||
}
|
||||
|
||||
return mapInfo;
|
||||
}
|
||||
|
||||
|
@ -919,6 +936,8 @@ void MenuStateMods::refreshTilesets() {
|
|||
}
|
||||
|
||||
void MenuStateMods::getMapsLocalList() {
|
||||
|
||||
/*
|
||||
Config &config = Config::getInstance();
|
||||
vector<string> results;
|
||||
set<string> allMaps;
|
||||
|
@ -951,6 +970,21 @@ void MenuStateMods::getMapsLocalList() {
|
|||
mapFilesUserData = results2;
|
||||
//printf("\n\nMap path [%s] mapFilesUserData.size() = %d\n\n\n",path.c_str(),mapFilesUserData.size());
|
||||
}
|
||||
*/
|
||||
|
||||
Config &config = Config::getInstance();
|
||||
string scenarioDir = "";
|
||||
vector<string> pathList = config.getPathListForType(ptMaps,scenarioDir);
|
||||
vector<string> invalidMapList;
|
||||
vector<string> allMaps = MapPreview::findAllValidMaps(pathList,scenarioDir,false,false,&invalidMapList);
|
||||
if (allMaps.empty()) {
|
||||
throw runtime_error("No maps were found!");
|
||||
}
|
||||
vector<string> results;
|
||||
copy(allMaps.begin(), allMaps.end(), std::back_inserter(results));
|
||||
mapFiles = results;
|
||||
|
||||
mapFilesUserData = MapPreview::findAllValidMaps(pathList,scenarioDir,true,false,&invalidMapList);
|
||||
}
|
||||
|
||||
string MenuStateMods::refreshMapModInfo(string mapInfo) {
|
||||
|
|
|
@ -25,12 +25,14 @@
|
|||
#include "miniftpserver.h"
|
||||
#include "window.h"
|
||||
#include <set>
|
||||
#include "map_preview.h"
|
||||
|
||||
#include "leak_dumper.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace Shared::Platform;
|
||||
using namespace Shared::Util;
|
||||
using namespace Shared::Map;
|
||||
|
||||
namespace Glest { namespace Game {
|
||||
|
||||
|
@ -89,6 +91,7 @@ ServerInterface::ServerInterface(bool publishEnabled) :GameNetworkInterface() {
|
|||
serverSocket.setBindPort(Config::getInstance().getInt("ServerPort", intToStr(GameConstants::serverPort).c_str()));
|
||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
/*
|
||||
Config &config = Config::getInstance();
|
||||
vector<string> results;
|
||||
set<string> allMaps;
|
||||
|
@ -103,6 +106,21 @@ ServerInterface::ServerInterface(bool publishEnabled) :GameNetworkInterface() {
|
|||
}
|
||||
copy(allMaps.begin(), allMaps.end(), std::back_inserter(results));
|
||||
mapFiles = results;
|
||||
*/
|
||||
|
||||
Config &config = Config::getInstance();
|
||||
vector<string> results;
|
||||
string scenarioDir = "";
|
||||
vector<string> pathList = config.getPathListForType(ptMaps,scenarioDir);
|
||||
vector<string> invalidMapList;
|
||||
vector<string> allMaps = MapPreview::findAllValidMaps(pathList,scenarioDir,false,true,&invalidMapList);
|
||||
if (allMaps.empty()) {
|
||||
throw runtime_error("No maps were found!");
|
||||
}
|
||||
results.clear();
|
||||
copy(allMaps.begin(), allMaps.end(), std::back_inserter(results));
|
||||
mapFiles = results;
|
||||
|
||||
|
||||
//tileset listBox
|
||||
results.clear();
|
||||
|
|
|
@ -15,12 +15,14 @@
|
|||
#include "util.h"
|
||||
#include "types.h"
|
||||
#include "randomgen.h"
|
||||
#include "vec.h"
|
||||
#include <vector>
|
||||
|
||||
using Shared::Platform::int8;
|
||||
using Shared::Platform::int32;
|
||||
using Shared::Platform::float32;
|
||||
using Shared::Util::RandomGen;
|
||||
using Shared::Graphics::Vec2i;
|
||||
|
||||
namespace Shared { namespace Map {
|
||||
|
||||
|
@ -58,7 +60,14 @@ static const int DEFAULT_MAP_CELL_HEIGHT_FACTOR = 3;
|
|||
static const int DEFAULT_MAP_WATER_DEPTH = 4;
|
||||
static const int DEFAULT_CLIFF_HEIGHT = 0;
|
||||
|
||||
static const int MAP_FORMAT_VERSION=2;
|
||||
enum MapVersionType {
|
||||
mapver_1 = 1,
|
||||
mapver_2,
|
||||
|
||||
mapver_MAX
|
||||
};
|
||||
|
||||
static const int MAP_FORMAT_VERSION = mapver_MAX - 1;
|
||||
|
||||
struct MapFileHeader {
|
||||
int32 version;
|
||||
|
@ -81,6 +90,20 @@ struct MapFileHeader {
|
|||
};
|
||||
};
|
||||
|
||||
class MapInfo {
|
||||
public:
|
||||
|
||||
Vec2i size;
|
||||
int players;
|
||||
string desc;
|
||||
|
||||
MapInfo() {
|
||||
size = Vec2i(0,0);
|
||||
players = 0;
|
||||
desc = "";
|
||||
}
|
||||
};
|
||||
|
||||
// ===============================================
|
||||
// class Map
|
||||
// ===============================================
|
||||
|
@ -189,6 +212,12 @@ public:
|
|||
|
||||
bool hasFileLoaded() const {return fileLoaded;}
|
||||
string getMapFileLoaded() const { return mapFileLoaded; }
|
||||
|
||||
static bool loadMapInfo(string file, MapInfo *mapInfo, string i18nMaxMapPlayersTitle,string i18nMapSizeTitle,bool errorOnInvalidMap=true);
|
||||
static string getMapPath(const vector<string> &pathList, const string &mapName, string scenarioDir="", bool errorOnNotFound=true);
|
||||
static vector<string> findAllValidMaps(const vector<string> &pathList,
|
||||
string scenarioDir, bool getUserDataOnly=false, bool cutExtension=true,
|
||||
vector<string> *invalidMapList=NULL);
|
||||
};
|
||||
|
||||
}}// end namespace
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
#include "math_wrapper.h"
|
||||
#include <cstdlib>
|
||||
#include <stdexcept>
|
||||
#include <set>
|
||||
#include "platform_util.h"
|
||||
#include "conversion.h"
|
||||
|
||||
|
@ -924,4 +925,167 @@ void MapPreview::applyNewHeight(float newHeight, int x, int y, int strenght) {
|
|||
cells[x][y].height = static_cast<float>(((cells[x][y].height * strenght) + newHeight) / (strenght + 1));
|
||||
}
|
||||
|
||||
bool MapPreview::loadMapInfo(string file, MapInfo *mapInfo, string i18nMaxMapPlayersTitle,string i18nMapSizeTitle,bool errorOnInvalidMap) {
|
||||
bool validMap = false;
|
||||
FILE *f = NULL;
|
||||
try {
|
||||
#ifdef WIN32
|
||||
f= _wfopen(utf8_decode(file).c_str(), L"rb");
|
||||
#else
|
||||
f= fopen(file.c_str(), "rb");
|
||||
#endif
|
||||
if(f == NULL) {
|
||||
throw runtime_error("Can't open file");
|
||||
}
|
||||
|
||||
MapFileHeader header;
|
||||
size_t readBytes = fread(&header, sizeof(MapFileHeader), 1, f);
|
||||
if(readBytes != 1) {
|
||||
validMap = false;
|
||||
|
||||
if(errorOnInvalidMap == true) {
|
||||
char szBuf[4096]="";
|
||||
sprintf(szBuf,"In [%s::%s Line: %d]\nfile [%s]\nreadBytes != sizeof(MapFileHeader) [%lu] [%lu]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,file.c_str(),readBytes,sizeof(MapFileHeader));
|
||||
SystemFlags::OutputDebug(SystemFlags::debugError,"%s",szBuf);
|
||||
|
||||
throw runtime_error(szBuf);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(header.version < mapver_1 || header.version >= mapver_MAX) {
|
||||
validMap = false;
|
||||
|
||||
if(errorOnInvalidMap == true) {
|
||||
char szBuf[4096]="";
|
||||
printf("In [%s::%s Line: %d]\file [%s]\nheader.version < mapver_1 || header.version >= mapver_MAX [%d] [%d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,file.c_str(),header.version,mapver_MAX);
|
||||
SystemFlags::OutputDebug(SystemFlags::debugError,"%s",szBuf);
|
||||
|
||||
throw runtime_error(szBuf);
|
||||
}
|
||||
}
|
||||
else if(header.maxFactions <= 0 || header.maxFactions > MAX_MAP_FACTIONCOUNT) {
|
||||
validMap = false;
|
||||
|
||||
if(errorOnInvalidMap == true) {
|
||||
char szBuf[4096]="";
|
||||
printf("In [%s::%s Line: %d]\file [%s]\nheader.maxFactions <= 0 || header.maxFactions > MAX_MAP_FACTIONCOUNT [%d] [%d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,file.c_str(),header.maxFactions,MAX_MAP_FACTIONCOUNT);
|
||||
SystemFlags::OutputDebug(SystemFlags::debugError,"%s",szBuf);
|
||||
|
||||
throw runtime_error(szBuf);
|
||||
}
|
||||
}
|
||||
else {
|
||||
mapInfo->size.x = header.width;
|
||||
mapInfo->size.y = header.height;
|
||||
mapInfo->players= header.maxFactions;
|
||||
|
||||
mapInfo->desc = i18nMaxMapPlayersTitle + ": " + intToStr(mapInfo->players) + "\n";
|
||||
mapInfo->desc += i18nMapSizeTitle + ": " + intToStr(mapInfo->size.x) + " x " + intToStr(mapInfo->size.y);
|
||||
|
||||
validMap = true;
|
||||
}
|
||||
}
|
||||
|
||||
if(f) fclose(f);
|
||||
}
|
||||
catch(exception &e) {
|
||||
if(f) fclose(f);
|
||||
|
||||
//assert(0);
|
||||
SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s] loading map [%s]\n",__FILE__,__FUNCTION__,__LINE__,e.what(),file.c_str());
|
||||
throw runtime_error("Error loading map file: [" + file + "] msg: " + e.what() + " errno [" + intToStr(errno) + "] [" + strerror(errno) + "]");
|
||||
}
|
||||
|
||||
return validMap;
|
||||
}
|
||||
|
||||
// static
|
||||
string MapPreview::getMapPath(const vector<string> &pathList, const string &mapName,
|
||||
string scenarioDir, bool errorOnNotFound) {
|
||||
for(int idx = 0; idx < pathList.size(); idx++) {
|
||||
string map_path = pathList[idx];
|
||||
endPathWithSlash(map_path);
|
||||
|
||||
const string original = map_path + mapName;
|
||||
const string mega = map_path + mapName + ".mgm";
|
||||
const string glest = map_path + mapName + ".gbm";
|
||||
|
||||
if((EndsWith(original,".mgm") == true || EndsWith(original,".gbm") == true) &&
|
||||
fileExists(original)) {
|
||||
return original;
|
||||
}
|
||||
else if (fileExists(mega)) {
|
||||
return mega;
|
||||
}
|
||||
else if (fileExists(glest)) {
|
||||
return glest;
|
||||
}
|
||||
}
|
||||
|
||||
if(errorOnNotFound == true) {
|
||||
throw runtime_error("Map [" + mapName + "] not found, scenarioDir [" + scenarioDir + "]");
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
vector<string> MapPreview::findAllValidMaps(const vector<string> &pathList,
|
||||
string scenarioDir, bool getUserDataOnly, bool cutExtension,
|
||||
vector<string> *invalidMapList) {
|
||||
vector<string> results;
|
||||
|
||||
if(getUserDataOnly == true) {
|
||||
if(pathList.size() > 1) {
|
||||
string path = pathList[1];
|
||||
endPathWithSlash(path);
|
||||
|
||||
vector<string> results2;
|
||||
set<string> allMaps2;
|
||||
findAll(path + "*.gbm", results2, cutExtension, false);
|
||||
copy(results2.begin(), results2.end(), std::inserter(allMaps2, allMaps2.begin()));
|
||||
|
||||
results2.clear();
|
||||
findAll(path + "*.mgm", results2, cutExtension, false);
|
||||
copy(results2.begin(), results2.end(), std::inserter(allMaps2, allMaps2.begin()));
|
||||
|
||||
results2.clear();
|
||||
copy(allMaps2.begin(), allMaps2.end(), std::back_inserter(results2));
|
||||
results = results2;
|
||||
//printf("\n\nMap path [%s] mapFilesUserData.size() = %d\n\n\n",path.c_str(),mapFilesUserData.size());
|
||||
}
|
||||
}
|
||||
else {
|
||||
set<string> allMaps;
|
||||
findAll(pathList, "*.gbm", results, cutExtension, false);
|
||||
copy(results.begin(), results.end(), std::inserter(allMaps, allMaps.begin()));
|
||||
|
||||
results.clear();
|
||||
findAll(pathList, "*.mgm", results, cutExtension, false);
|
||||
copy(results.begin(), results.end(), std::inserter(allMaps, allMaps.begin()));
|
||||
results.clear();
|
||||
|
||||
copy(allMaps.begin(), allMaps.end(), std::back_inserter(results));
|
||||
}
|
||||
|
||||
vector<string> mapFiles = results;
|
||||
results.clear();
|
||||
|
||||
MapInfo mapInfo;
|
||||
for(int i= 0; i < mapFiles.size(); i++){// fetch info and put map in right list
|
||||
//loadMapInfo(string file, MapInfo *mapInfo, string i18nMaxMapPlayersTitle,string i18nMapSizeTitle,bool errorOnInvalidMap=true);
|
||||
//printf("getMapPath [%s]\nmapFiles.at(i) [%s]\nscenarioDir [%s] getUserDataOnly = %d cutExtension = %d\n",getMapPath(pathList,mapFiles.at(i), scenarioDir, false).c_str(),mapFiles.at(i).c_str(),scenarioDir.c_str(), getUserDataOnly, cutExtension);
|
||||
|
||||
if(loadMapInfo(getMapPath(pathList,mapFiles.at(i), scenarioDir, false), &mapInfo, "", "", false) == true) {
|
||||
results.push_back(mapFiles.at(i));
|
||||
}
|
||||
else {
|
||||
if(invalidMapList != NULL) {
|
||||
invalidMapList->push_back(getMapPath(pathList,mapFiles.at(i), scenarioDir, false));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
}}// end namespace
|
||||
|
|
Loading…
Reference in New Issue