Browse Source

Start integration of map format into engine

AlexVinS 9 years ago
parent
commit
0c21efb202

+ 7 - 0
Mods/vcmi/Sprites/ScSelC.json

@@ -0,0 +1,7 @@
+{
+        "basepath" : "mapFormatIcons/",
+	"images" :
+	[
+		{ "group" : 1, "frame" : 0, "file" : "vcmi1.png"}
+	]
+}

BIN
Mods/vcmi/Sprites/mapFormatIcons/vcmi1.png


+ 20 - 10
client/CPreGame.cpp

@@ -1117,8 +1117,9 @@ void SelectionTab::parseMaps(const std::unordered_set<ResourceID> &files)
 			CMapInfo mapInfo;
 			CMapInfo mapInfo;
 			mapInfo.mapInit(file.getName());
 			mapInfo.mapInit(file.getName());
 
 
-			// ignore unsupported map versions (e.g. WoG maps without WoG
-			if (mapInfo.mapHeader->version <= CGI->modh->settings.data["textData"]["mapVersion"].Float())
+			// ignore unsupported map versions (e.g. WoG maps without WoG)
+			// but accept VCMI maps
+			if((mapInfo.mapHeader->version >= EMapFormat::VCMI) || (mapInfo.mapHeader->version <= CGI->modh->settings.data["textData"]["mapVersion"].Float()))
 				allItems.push_back(std::move(mapInfo));
 				allItems.push_back(std::move(mapInfo));
 		}
 		}
 		catch(std::exception & e)
 		catch(std::exception & e)
@@ -1283,7 +1284,9 @@ SelectionTab::SelectionTab(CMenuScreen::EState Type, const std::function<void(CM
 
 
 	slider = new CSlider(Point(372, 86), tabType != CMenuScreen::saveGame ? 480 : 430, std::bind(&SelectionTab::sliderMove, this, _1), positions, curItems.size(), 0, false, CSlider::BLUE);
 	slider = new CSlider(Point(372, 86), tabType != CMenuScreen::saveGame ? 480 : 430, std::bind(&SelectionTab::sliderMove, this, _1), positions, curItems.size(), 0, false, CSlider::BLUE);
 	slider->addUsedEvents(WHEEL);
 	slider->addUsedEvents(WHEEL);
-	format =  CDefHandler::giveDef("SCSELC.DEF");
+
+	formatIcons = new CAnimation("SCSELC.DEF");
+	formatIcons->load();
 
 
 	sortingBy = _format;
 	sortingBy = _format;
 	ascending = true;
 	ascending = true;
@@ -1312,7 +1315,7 @@ SelectionTab::SelectionTab(CMenuScreen::EState Type, const std::function<void(CM
 
 
 SelectionTab::~SelectionTab()
 SelectionTab::~SelectionTab()
 {
 {
-	delete format;
+	delete formatIcons;
 }
 }
 
 
 void SelectionTab::sortBy( int criteria )
 void SelectionTab::sortBy( int criteria )
@@ -1437,27 +1440,34 @@ void SelectionTab::printMaps(SDL_Surface *to)
 			}
 			}
 			printAtMiddleLoc(temp2, 70, 128 + line * 25, FONT_SMALL, itemColor, to);
 			printAtMiddleLoc(temp2, 70, 128 + line * 25, FONT_SMALL, itemColor, to);
 
 
-			int temp=-1;
+			int frame = -1, group = 0;
 			switch (currentItem->mapHeader->version)
 			switch (currentItem->mapHeader->version)
 			{
 			{
 			case EMapFormat::ROE:
 			case EMapFormat::ROE:
-				temp=0;
+				frame = 0;
 				break;
 				break;
 			case EMapFormat::AB:
 			case EMapFormat::AB:
-				temp=1;
+				frame = 1;
 				break;
 				break;
 			case EMapFormat::SOD:
 			case EMapFormat::SOD:
-				temp=2;
+				frame = 2;
 				break;
 				break;
 			case EMapFormat::WOG:
 			case EMapFormat::WOG:
-				temp=3;
+				frame = 3;
+				break;
+			case EMapFormat::VCMI:
+				frame = 0;
+				group = 1;
 				break;
 				break;
 			default:
 			default:
 				// Unknown version. Be safe and ignore that map
 				// Unknown version. Be safe and ignore that map
                 logGlobal->warnStream() << "Warning: " << currentItem->fileURI << " has wrong version!";
                 logGlobal->warnStream() << "Warning: " << currentItem->fileURI << " has wrong version!";
 				continue;
 				continue;
 			}
 			}
-			blitAtLoc(format->ourImages[temp].bitmap, 88, 117 + line * 25, to);
+			IImage * icon = formatIcons->getImage(frame,group);
+			if(icon)
+				icon->draw(to, pos.x + 88, pos.y + 117 + line * 25);
+
 
 
 			//victory conditions
 			//victory conditions
 			blitAtLoc(CGP->victory->ourImages[currentItem->mapHeader->victoryIconIndex].bitmap, 306, 117 + line * 25, to);
 			blitAtLoc(CGP->victory->ourImages[currentItem->mapHeader->victoryIconIndex].bitmap, 306, 117 + line * 25, to);

+ 1 - 1
client/CPreGame.h

@@ -149,7 +149,7 @@ public:
 class SelectionTab : public CIntObject
 class SelectionTab : public CIntObject
 {
 {
 private:
 private:
-	CDefHandler *format; //map size
+	CAnimation * formatIcons;
 
 
     void parseMaps(const std::unordered_set<ResourceID> &files);
     void parseMaps(const std::unordered_set<ResourceID> &files);
 	void parseGames(const std::unordered_set<ResourceID> &files, bool multi);
 	void parseGames(const std::unordered_set<ResourceID> &files, bool multi);

+ 2 - 1
lib/filesystem/ResourceID.cpp

@@ -136,7 +136,8 @@ EResType::Type EResTypeHelper::getTypeFromExtension(std::string extension)
 		{".VSGM1", EResType::SERVER_SAVEGAME},
 		{".VSGM1", EResType::SERVER_SAVEGAME},
 		{".ERM",   EResType::ERM},
 		{".ERM",   EResType::ERM},
 		{".ERT",   EResType::ERT},
 		{".ERT",   EResType::ERT},
-		{".ERS",   EResType::ERS}
+		{".ERS",   EResType::ERS},
+		{".VMAP",  EResType::MAP}
 	};
 	};
 
 
 	auto iter = stringToRes.find(extension);
 	auto iter = stringToRes.find(extension);

+ 2 - 1
lib/mapping/CMap.h

@@ -215,7 +215,8 @@ enum EMapFormat
 	AB  = 0x15, // 21
 	AB  = 0x15, // 21
 	SOD = 0x1c, // 28
 	SOD = 0x1c, // 28
 // HOTA = 0x1e ... 0x20 // 28 ... 30
 // HOTA = 0x1e ... 0x20 // 28 ... 30
-	WOG = 0x33  // 51
+	WOG = 0x33,  // 51
+	VCMI = 0xF0
 };
 };
 }
 }
 
 

+ 25 - 14
lib/mapping/CMapService.cpp

@@ -68,21 +68,32 @@ std::unique_ptr<IMapLoader> CMapService::getMapLoader(std::unique_ptr<CInputStre
 	ui32 header = reader.readUInt32();
 	ui32 header = reader.readUInt32();
 	reader.getStream()->seek(0);
 	reader.getStream()->seek(0);
 
 
-	// Check which map format is used
-	// gzip header is 3 bytes only in size
-	switch(header & 0xffffff)
+	//check for ZIP magic. Zip files are VCMI maps
+	switch(header)
 	{
 	{
-		// gzip header magic number, reversed for LE
-		case 0x00088B1F:
-			stream = std::unique_ptr<CInputStream>(new CCompressedStream(std::move(stream), true));
-			return std::unique_ptr<IMapLoader>(new CMapLoaderH3M(stream.get()));
-		case EMapFormat::WOG :
-		case EMapFormat::AB  :
-		case EMapFormat::ROE :
-		case EMapFormat::SOD :
-			return std::unique_ptr<IMapLoader>(new CMapLoaderH3M(stream.get()));
-		default :
-			throw std::runtime_error("Unknown map format");
+	case 0x06054b50:
+	case 0x04034b50:
+	case 0x02014b50:
+		//return std::unique_ptr<IMapLoader>(new CMapLoaderJson(stream.get()));
+		throw std::runtime_error("Not implemented map format");
+		break;
+	default:
+		// Check which map format is used
+		// gzip header is 3 bytes only in size
+		switch(header & 0xffffff)
+		{
+			// gzip header magic number, reversed for LE
+			case 0x00088B1F:
+				stream = std::unique_ptr<CInputStream>(new CCompressedStream(std::move(stream), true));
+				return std::unique_ptr<IMapLoader>(new CMapLoaderH3M(stream.get()));
+			case EMapFormat::WOG :
+			case EMapFormat::AB  :
+			case EMapFormat::ROE :
+			case EMapFormat::SOD :
+				return std::unique_ptr<IMapLoader>(new CMapLoaderH3M(stream.get()));
+			default :
+				throw std::runtime_error("Unknown map format");
+		}
 	}
 	}
 }
 }
 
 

+ 1 - 2
lib/mapping/MapFormatJson.cpp

@@ -299,8 +299,7 @@ void CMapLoaderJson::readHeader()
 	//do not use map field here, use only mapHeader
 	//do not use map field here, use only mapHeader
 	const JsonNode header = readJson(HEADER_FILE_NAME);
 	const JsonNode header = readJson(HEADER_FILE_NAME);
 
 
-	//TODO: read such data like map name & size
-	//mapHeader->version = ??? //todo: new version field
+	mapHeader->version = EMapFormat::VCMI;//todo: new version field
 
 
 	//todo: multilevel map load support
 	//todo: multilevel map load support
 	const JsonNode levels = header["mapLevels"];
 	const JsonNode levels = header["mapLevels"];

+ 1 - 1
lib/rmg/CMapGenerator.cpp

@@ -578,7 +578,7 @@ void CMapGenerator::createConnections()
 
 
 void CMapGenerator::addHeaderInfo()
 void CMapGenerator::addHeaderInfo()
 {
 {
-	map->version = EMapFormat::SOD;
+	map->version = EMapFormat::VCMI;
 	map->width = mapGenOptions->getWidth();
 	map->width = mapGenOptions->getWidth();
 	map->height = mapGenOptions->getHeight();
 	map->height = mapGenOptions->getHeight();
 	map->twoLevel = mapGenOptions->getHasTwoLevels();
 	map->twoLevel = mapGenOptions->getHasTwoLevels();