diff --git a/client/CPreGame.cpp b/client/CPreGame.cpp index 0dbdca7e8..32db6196f 100644 --- a/client/CPreGame.cpp +++ b/client/CPreGame.cpp @@ -1077,25 +1077,30 @@ void SelectionTab::parseGames(const std::vector &files, bool multi) ui8 sign[8]; lf >> sign; if(std::memcmp(sign,"VCMISVG",7)) - throw std::runtime_error("not a correct savefile!"); - - allItems.resize(allItems.size() + 1); - allItems[i].mapHeader = std::shared_ptr(new CMapHeader); - allItems[i].scenarioOpts = new StartInfo; - lf >> *(allItems[i].mapHeader.get()) >> allItems[i].scenarioOpts; - allItems[i].fileURI = files[i].getName(); - allItems[i].countPlayers(); - std::time_t time = CFileInfo(CResourceHandler::get()->getResourceName(files[i])).getDate(); - allItems[i].date = std::asctime(std::localtime(&time)); - - if((allItems[i].actualHumanPlayers > 1) != multi) //if multi mode then only multi games, otherwise single { - allItems[i].mapHeader.reset(); + throw std::runtime_error("not a correct savefile!"); } + + // Create the map info object + CMapInfo mapInfo; + mapInfo.mapHeader = std::shared_ptr(new CMapHeader); + mapInfo.scenarioOpts = new StartInfo; + lf >> *(mapInfo.mapHeader.get()) >> mapInfo.scenarioOpts; + mapInfo.fileURI = files[i].getName(); + mapInfo.countPlayers(); + std::time_t time = CFileInfo(CResourceHandler::get()->getResourceName(files[i])).getDate(); + mapInfo.date = std::asctime(std::localtime(&time)); + + // If multi mode then only multi games, otherwise single + if((mapInfo.actualHumanPlayers > 1) != multi) + { + mapInfo.mapHeader.reset(); + } + + allItems.push_back(mapInfo); } - catch(std::exception &e) + catch(std::exception & e) { - allItems.pop_back(); tlog3 << "Failed to process " << files[i].getName() <<": " << e.what() << std::endl; } } @@ -1550,7 +1555,9 @@ RandomMapTab::RandomMapTab() mapSizeBtnGroup->select(1, false); mapSizeBtnGroup->onChange = [&](int btnId) { - options.setMapSize(static_cast(btnId)); + const std::vector mapSizeVal = boost::assign::list_of(36)(72)(108)(144); // Map sizes in this order: S, M, L, XL + options.setWidth(mapSizeVal[btnId]); + options.setHeight(mapSizeVal[btnId]); }; // Two levels diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 10f5cfff4..cab87d50f 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -50,6 +50,8 @@ set(lib_SRCS ) set(lib_HEADERS + Filesystem/CInputStream.h + Filesystem/ISimpleResourceLoader.h AI_Base.h CondSh.h ConstTransitivePtr.h diff --git a/lib/Filesystem/CInputStream.h b/lib/Filesystem/CInputStream.h index 0fd4d20b9..a885ce8cc 100644 --- a/lib/Filesystem/CInputStream.h +++ b/lib/Filesystem/CInputStream.h @@ -14,7 +14,7 @@ /** * Abstract class which provides method definitions for reading from a stream. */ -class DLL_LINKAGE CInputStream : public boost::noncopyable +class DLL_LINKAGE CInputStream : private boost::noncopyable { public: /** diff --git a/lib/Map/CMapService.cpp b/lib/Map/CMapService.cpp index d321725f0..2326efad6 100644 --- a/lib/Map/CMapService.cpp +++ b/lib/Map/CMapService.cpp @@ -99,7 +99,7 @@ void CMapLoaderH3M::initBuffer(CInputStream * stream) std::unique_ptr CMapLoaderH3M::loadMap() { // Init map object by parsing the input buffer - map = new CMap; + map = new CMap(); mapHeader = std::unique_ptr(dynamic_cast(map)); init(); @@ -672,7 +672,7 @@ void CMapLoaderH3M::readPredefinedHeroes() int custom = buffer[pos++]; if(!custom) continue; - CGHeroInstance * hero = new CGHeroInstance; + CGHeroInstance * hero = new CGHeroInstance(); hero->ID = Obj::HERO; hero->subID = z; @@ -851,7 +851,7 @@ CArtifactInstance * CMapLoaderH3M::createArtifact(int aid, int spellID /*= -1*/) } else { - a = new CArtifactInstance; + a = new CArtifactInstance(); } addNewArtifactInstance(a); @@ -923,7 +923,7 @@ void CMapLoaderH3M::readDefInfo() // Read custom defs for(int idd = 0; idd < defAmount; ++idd) { - CGDefInfo * defInfo = new CGDefInfo; + CGDefInfo * defInfo = new CGDefInfo(); // Read name int nameLength = read_le_u32(buffer + pos); @@ -1140,14 +1140,14 @@ void CMapLoaderH3M::readObjects() case 47: //School of Magic case 107: //School of War { - nobj = new CGVisitableOPH; + nobj = new CGVisitableOPH(); break; } case 55: //mystical garden case 112://windmill case 109://water wheel { - nobj = new CGVisitableOPW; + nobj = new CGVisitableOPW(); break; } case 43: //teleport @@ -1156,7 +1156,7 @@ void CMapLoaderH3M::readObjects() case 103://subterranean gate case 111://Whirlpool { - nobj = new CGTeleport; + nobj = new CGTeleport(); break; } case 12: //campfire @@ -1165,14 +1165,14 @@ void CMapLoaderH3M::readObjects() case 86: //Shipwreck Survivor case 101://treasure chest { - nobj = new CGPickable; + nobj = new CGPickable(); break; } case 54: //Monster case 71: case 72: case 73: case 74: case 75: // Random Monster 1 - 4 case 162: case 163: case 164: // Random Monster 5 - 7 { - CGCreature * cre = new CGCreature; + CGCreature * cre = new CGCreature(); nobj = cre; if(map->version > EMapFormat::ROE) @@ -1182,7 +1182,7 @@ void CMapLoaderH3M::readObjects() map->questIdentifierToId[cre->identifier] = idToBeGiven; } - CStackInstance * hlp = new CStackInstance; + CStackInstance * hlp = new CStackInstance(); hlp->count = read_le_u16(buffer + pos); pos += 2; @@ -1247,7 +1247,7 @@ void CMapLoaderH3M::readObjects() } case 59: case 91: //ocean bottle and sign { - CGSignBottle * sb = new CGSignBottle; + CGSignBottle * sb = new CGSignBottle(); nobj = sb; sb->message = readString(buffer, pos); pos += 4; @@ -1261,7 +1261,7 @@ void CMapLoaderH3M::readObjects() } case 113: //witch hut { - CGWitchHut * wh = new CGWitchHut; + CGWitchHut * wh = new CGWitchHut(); nobj = wh; // in reo we cannot specify it - all are allowed (I hope) @@ -1295,7 +1295,7 @@ void CMapLoaderH3M::readObjects() } case 81: //scholar { - CGScholar * sch = new CGScholar; + CGScholar * sch = new CGScholar(); nobj = sch; sch->bonusType = buffer[pos++]; sch->bonusID = buffer[pos++]; @@ -1304,7 +1304,7 @@ void CMapLoaderH3M::readObjects() } case 33: case 219: //garrison { - CGGarrison * gar = new CGGarrison; + CGGarrison * gar = new CGGarrison(); nobj = gar; nobj->setOwner(buffer[pos++]); pos += 3; @@ -1327,7 +1327,7 @@ void CMapLoaderH3M::readObjects() { int artID = -1; int spellID = -1; - CGArtifact * art = new CGArtifact; + CGArtifact * art = new CGArtifact(); nobj = art; bool areSettings = buffer[pos++]; @@ -1359,7 +1359,7 @@ void CMapLoaderH3M::readObjects() } case 76: case 79: //random resource; resource { - CGResource * res = new CGResource; + CGResource * res = new CGResource(); nobj = res; bool isMessGuard = buffer[pos]; @@ -1392,14 +1392,14 @@ void CMapLoaderH3M::readObjects() case 53: case 220://mine (?) { - nobj = new CGMine; + nobj = new CGMine(); nobj->setOwner(buffer[pos++]); pos += 3; break; } case 17: case 18: case 19: case 20: //dwellings { - nobj = new CGDwelling; + nobj = new CGDwelling(); nobj->setOwner(buffer[pos++]); pos += 3; break; @@ -1407,12 +1407,12 @@ void CMapLoaderH3M::readObjects() case 78: //Refugee Camp case 106: //War Machine Factory { - nobj = new CGDwelling; + nobj = new CGDwelling(); break; } case 88: case 89: case 90: //spell shrine { - CGShrine * shr = new CGShrine; + CGShrine * shr = new CGShrine(); nobj = shr; shr->spell = buffer[pos]; pos += 4; @@ -1420,7 +1420,7 @@ void CMapLoaderH3M::readObjects() } case 6: //pandora's box { - CGPandoraBox * box = new CGPandoraBox; + CGPandoraBox * box = new CGPandoraBox(); nobj = box; bool messg = buffer[pos]; ++pos; @@ -1507,13 +1507,13 @@ void CMapLoaderH3M::readObjects() case 217: //same as castle case 218: //level range { - nobj = new CGDwelling; + nobj = new CGDwelling(); CSpecObjInfo * spec = nullptr; switch(defInfo->id) { - break; case 216: spec = new CCreGenLeveledCastleInfo; - break; case 217: spec = new CCreGenAsCastleInfo; - break; case 218: spec = new CCreGenLeveledInfo; + break; case 216: spec = new CCreGenLeveledCastleInfo(); + break; case 217: spec = new CCreGenAsCastleInfo(); + break; case 218: spec = new CCreGenLeveledInfo(); } spec->player = read_le_u32(buffer + pos); @@ -1552,7 +1552,7 @@ void CMapLoaderH3M::readObjects() } case 215: { - CGQuestGuard * guard = new CGQuestGuard; + CGQuestGuard * guard = new CGQuestGuard(); addQuest(guard); readQuest(guard); nobj = guard; @@ -1571,19 +1571,19 @@ void CMapLoaderH3M::readObjects() case 52: //Mermaid case 94: //Stables { - nobj = new CGBonusingObject; + nobj = new CGBonusingObject(); break; } case 49: //Magic Well { - nobj = new CGMagicWell; + nobj = new CGMagicWell(); break; } case 15: //Cover of darkness case 58: //Redwood Observatory case 60: //Pillar of Fire { - nobj = new CGObservatory; + nobj = new CGObservatory(); break; } case 22: //Corpse @@ -1591,29 +1591,29 @@ void CMapLoaderH3M::readObjects() case 105://Wagon case 108://Warrior's Tomb { - nobj = new CGOnceVisitable; + nobj = new CGOnceVisitable(); break; } case 8: //Boat { - nobj = new CGBoat; + nobj = new CGBoat(); break; } case 92: //Sirens { - nobj = new CGSirens; + nobj = new CGSirens(); break; } case 87: //Shipyard { - nobj = new CGShipyard; + nobj = new CGShipyard(); nobj->setOwner(read_le_u32(buffer + pos)); pos += 4; break; } case 214: //hero placeholder { - CGHeroPlaceholder * hp = new CGHeroPlaceholder; + CGHeroPlaceholder * hp = new CGHeroPlaceholder(); nobj = hp; int a = buffer[pos++]; //unknown byte, seems to be always 0 (if not - scream!) @@ -1635,59 +1635,59 @@ void CMapLoaderH3M::readObjects() } case 10: //Keymaster { - nobj = new CGKeymasterTent; + nobj = new CGKeymasterTent(); break; } case 9: //Border Guard { - nobj = new CGBorderGuard; + nobj = new CGBorderGuard(); addQuest(nobj); break; } case 212: //Border Gate { - nobj = new CGBorderGate; + nobj = new CGBorderGate(); addQuest (nobj); break; } case 27: case 37: //Eye and Hut of Magi { - nobj = new CGMagi; + nobj = new CGMagi(); break; } case 16: case 24: case 25: case 84: case 85: //treasure bank { - nobj = new CBank; + nobj = new CBank(); break; } case 63: //Pyramid { - nobj = new CGPyramid; + nobj = new CGPyramid(); break; } case 13: //Cartographer { - nobj = new CCartographer; + nobj = new CCartographer(); break; } case 48: //Magic Spring { - nobj = new CGMagicSpring; + nobj = new CGMagicSpring(); break; } case 97: //den of thieves { - nobj = new CGDenOfthieves; + nobj = new CGDenOfthieves(); break; } case 57: //Obelisk { - nobj = new CGObelisk; + nobj = new CGObelisk(); break; } case 42: //Lighthouse { - nobj = new CGLighthouse; + nobj = new CGLighthouse(); nobj->tempOwner = read_le_u32(buffer + pos); pos += 4; break; @@ -1697,22 +1697,22 @@ void CMapLoaderH3M::readObjects() case 213: //Freelancer's Guild case 221: //Trading Post (snow) { - nobj = new CGMarket; + nobj = new CGMarket(); break; } case 104: //University { - nobj = new CGUniversity; + nobj = new CGUniversity(); break; } case 7: //Black Market { - nobj = new CGBlackMarket; + nobj = new CGBlackMarket(); break; } default: //any other object { - nobj = new CGObjectInstance; + nobj = new CGObjectInstance(); break; } } @@ -1767,7 +1767,7 @@ void CMapLoaderH3M::readCreatureSet(CCreatureSet * out, int number, bool version // Empty slot if(creID == maxID) continue; - CStackInstance * hlp = new CStackInstance; + CStackInstance * hlp = new CStackInstance(); hlp->count = count; if(creID > maxID - 0xf) @@ -1790,7 +1790,7 @@ void CMapLoaderH3M::readCreatureSet(CCreatureSet * out, int number, bool version CGObjectInstance * CMapLoaderH3M::readHero(int idToBeGiven) { - CGHeroInstance * nhi = new CGHeroInstance; + CGHeroInstance * nhi = new CGHeroInstance(); int identifier = 0; if(map->version > EMapFormat::ROE) @@ -1977,7 +1977,7 @@ CGObjectInstance * CMapLoaderH3M::readHero(int idToBeGiven) CGSeerHut * CMapLoaderH3M::readSeerHut() { - CGSeerHut * hut = new CGSeerHut; + CGSeerHut * hut = new CGSeerHut(); if(map->version > EMapFormat::ROE) { @@ -2208,7 +2208,7 @@ void CMapLoaderH3M::addQuest(CGObjectInstance * quest) CGTownInstance * CMapLoaderH3M::readTown(int castleID) { - CGTownInstance * nt = new CGTownInstance; + CGTownInstance * nt = new CGTownInstance(); nt->identifier = 0; if(map->version > EMapFormat::ROE) { @@ -2316,7 +2316,7 @@ CGTownInstance * CMapLoaderH3M::readTown(int castleID) for(int gh = 0; gh < numberOfEvent; ++gh) { - CCastleEvent * nce = new CCastleEvent; + CCastleEvent * nce = new CCastleEvent(); nce->town = nt; nce->name = readString(buffer, pos); nce->message = readString(buffer, pos); @@ -2456,7 +2456,7 @@ void CMapLoaderH3M::readEvents() pos += 4; for(int yyoo = 0; yyoo < numberOfEvents; ++yyoo) { - CMapEvent * ne = new CMapEvent; + CMapEvent * ne = new CMapEvent(); ne->name = std::string(); ne->message = std::string(); int nameLen = read_le_u32(buffer + pos); diff --git a/lib/RMG/CMapGenOptions.cpp b/lib/RMG/CMapGenOptions.cpp index b64665c50..0eb980750 100644 --- a/lib/RMG/CMapGenOptions.cpp +++ b/lib/RMG/CMapGenOptions.cpp @@ -1,21 +1,45 @@ #include "StdInc.h" #include "CMapGenOptions.h" -CMapGenOptions::CMapGenOptions() : mapSize(EMapSize::MEDIUM), hasTwoLevels(true), +CMapGenOptions::CMapGenOptions() : width(72), height(72), hasTwoLevels(true), playersCnt(-1), teamsCnt(-1), compOnlyPlayersCnt(-1), compOnlyTeamsCnt(-1), waterContent(EWaterContent::NORMAL), monsterStrength(EMonsterStrength::NORMAL) { } -EMapSize::EMapSize CMapGenOptions::getMapSize() const +int CMapGenOptions::getWidth() const { - return mapSize; + return width; } -void CMapGenOptions::setMapSize(EMapSize::EMapSize value) +void CMapGenOptions::setWidth(int value) { - mapSize = value; + if(value > 0) + { + width = value; + } + else + { + throw std::runtime_error("Map width lower than 1 not allowed."); + } +} + +int CMapGenOptions::getHeight() const +{ + return height; +} + +void CMapGenOptions::setHeight(int value) +{ + if(value > 0) + { + height = value; + } + else + { + throw std::runtime_error("Map height lower than 1 not allowed."); + } } bool CMapGenOptions::getHasTwoLevels() const diff --git a/lib/RMG/CMapGenOptions.h b/lib/RMG/CMapGenOptions.h index 133019429..cff3e8b0e 100644 --- a/lib/RMG/CMapGenOptions.h +++ b/lib/RMG/CMapGenOptions.h @@ -11,17 +11,6 @@ #pragma once -namespace EMapSize -{ - enum EMapSize - { - SMALL, - MEDIUM, - LARGE, - EXTRA_LARGE - }; -} - namespace EWaterContent { enum EWaterContent @@ -57,23 +46,37 @@ public: CMapGenOptions(); /** - * Gets the size of the map. + * Gets the width of the map. * - * @return size of the map + * @return width of the map in tiles, default is 72 */ - EMapSize::EMapSize getMapSize() const; + int getWidth() const; /** - * Sets the size of the map. + * Sets the width of the map. * - * @param value the size of the map + * @param value the width of the map in tiles, any values higher than 0 are allowed */ - void setMapSize(EMapSize::EMapSize value); + void setWidth(int value); + + /** + * Gets the height of the map. + * + * @return height of the map in tiles, default is 72 + */ + int getHeight() const; + + /** + * Sets the height of the map. + * + * @param value the height of the map in tiles, any values higher than 0 are allowed + */ + void setHeight(int value); /** * Gets the flag whether the map should be generated with two levels. * - * @return true for two level map + * @return true for two level map, default is true */ bool getHasTwoLevels() const; @@ -87,7 +90,7 @@ public: /** * Gets the count of the players. * - * @return the count of the players ranging from 1 to 8, -1 for random + * @return the count of the players ranging from 1 to 8, -1 for random, default is -1 */ int getPlayersCnt() const; @@ -101,7 +104,7 @@ public: /** * Gets the count of the teams. * - * @return the count of the teams ranging from 0 to , -1 for random + * @return the count of the teams ranging from 0 to , -1 for random, default is -1 */ int getTeamsCnt() const; @@ -115,7 +118,7 @@ public: /** * Gets the count of the computer only players. * - * @return the count of the computer only players ranging from 0 to <8 - players count>, -1 for random + * @return the count of the computer only players ranging from 0 to <8 - players count>, -1 for random, default is -1 */ int getCompOnlyPlayersCnt() const; @@ -129,7 +132,7 @@ public: /** * Gets the count of the computer only teams. * - * @return the count of the computer only teams ranging from 0 to , -1 for random + * @return the count of the computer only teams ranging from 0 to , -1 for random, default is -1 */ int getCompOnlyTeamsCnt() const; @@ -143,7 +146,7 @@ public: /** * Gets the water content. * - * @return the water content + * @return the water content, default is normal */ EWaterContent::EWaterContent getWaterContent() const; @@ -157,7 +160,7 @@ public: /** * Gets the strength of the monsters. * - * @return the strenght of the monsters + * @return the strenght of the monsters, default is normal */ EMonsterStrength::EMonsterStrength getMonsterStrength() const; @@ -169,8 +172,11 @@ public: void setMonsterStrength(EMonsterStrength::EMonsterStrength value); private: - /** the size of the map */ - EMapSize::EMapSize mapSize; + /** the width of the map in tiles */ + int width; + + /** the height of the map in tiles */ + int height; /** true if the map has two levels/underground */ bool hasTwoLevels;