瀏覽代碼

* partial handling of advmap objects changing battle background (like clover field) (their existence should change the background but nothing else)
* map should be drawn faster because empty tiles are no more blitted (according to info from .msk files) - I hope it will work correctly, if not please report or turn it off if too hard to make it work

mateuszb 16 年之前
父節點
當前提交
50a49460bf
共有 7 個文件被更改,包括 64 次插入28 次删除
  1. 11 0
      hch/CDefObjInfoHandler.cpp
  2. 2 1
      hch/CDefObjInfoHandler.h
  3. 8 0
      hch/CObjectHandler.cpp
  4. 1 0
      hch/CObjectHandler.h
  5. 31 27
      lib/CGameState.cpp
  6. 9 0
      lib/map.cpp
  7. 2 0
      mapHandler.cpp

+ 11 - 0
hch/CDefObjInfoHandler.cpp

@@ -55,6 +55,7 @@ void CDefObjInfoHandler::load()
 		{
 			nobj->blockMap[o] = 0xff;
 			nobj->visitMap[o] = 0x00;
+			nobj->coverageMap[0] = 0x00;
 		}
 		inp>>mapStr;
 		std::reverse(mapStr.begin(), mapStr.end());
@@ -100,6 +101,16 @@ void CDefObjInfoHandler::load()
 			}
 		}
 		inp >> nobj->printPriority;
+
+		//coverageMap calculating
+		std::string nameCopy = nobj->name;
+		std::string msk = spriteh->getTextFile(nameCopy.replace( nameCopy.size()-4, 4, ".MSK" ));
+		for(int i=0; i<6; ++i)
+		{
+			nobj->coverageMap[i] = msk[i+2];
+		}
+
+
 		gobjs[nobj->id][nobj->subid] = nobj;
 		if(nobj->id==TOWNI_TYPE)
 			castles[nobj->subid]=nobj;

+ 2 - 1
hch/CDefObjInfoHandler.h

@@ -23,6 +23,7 @@ public:
 
 	ui8 visitMap[6];
 	ui8 blockMap[6];
+	ui8 coverageMap[6]; //to determine which tiles are covered by picture of this object
 	ui8 visitDir; //directions from which object can be entered, format same as for moveDir in CGHeroInstance(but 0 - 7)
 	si32 id, subid; //of object described by this defInfo
 	si32 serial;
@@ -43,7 +44,7 @@ public:
 	template <typename Handler> void serialize(Handler &h, const int version)
 	{
 		h & name & serial & visitMap & blockMap & visitDir & id & subid &terrainAllowed
-			& terrainMenu & width & height & type & printPriority;
+			& terrainMenu & width & height & type & printPriority & coverageMap;
 	}
 	CGDefInfo();
 };

+ 8 - 0
hch/CObjectHandler.cpp

@@ -186,6 +186,14 @@ bool CGObjectInstance::blockingAt(int x, int y) const
 		return true;
 	return false;
 }
+
+bool CGObjectInstance::coveringAt(int x, int y) const
+{
+	if((defInfo->coverageMap[y] >> (7-(x) )) & 1)
+		return true;
+	return false;
+}
+
 bool CGObjectInstance::operator<(const CGObjectInstance & cmp) const  //screen printing priority comparing
 {
 	if(defInfo->printPriority==1 && cmp.defInfo->printPriority==0)

+ 1 - 0
hch/CObjectHandler.h

@@ -126,6 +126,7 @@ public:
 	int getHeight() const; //returns height of object graphic in tiles
 	bool visitableAt(int x, int y) const; //returns true if object is visitable at location (x, y) form left top tile of image (x, y in tiles)
 	bool blockingAt(int x, int y) const; //returns true if object is blocking location (x, y) form left top tile of image (x, y in tiles)
+	bool coveringAt(int x, int y) const; //returns true if object covers with picture location (x, y) form left top tile of maximal possible image (8 x 6 tiles) (x, y in tiles)
 	bool operator<(const CGObjectInstance & cmp) const;  //screen printing priority comparing
 	CGObjectInstance();
 	virtual ~CGObjectInstance();

+ 31 - 27
lib/CGameState.cpp

@@ -1343,33 +1343,37 @@ int CGameState::battleGetBattlefieldType(int3 tile)
 	else if(tile==int3() && !curB)
 		return -1;
 
-	//std::vector < std::pair<const CGObjectInstance*,SDL_Rect> > & objs = CGI->mh->ttiles[tile.x][tile.y][tile.z].objects;
-	//for(int g=0; g<objs.size(); ++g)
-	//{
-	//	switch(objs[g].first->ID)
-	//	{
-	//	case 222: //clover field
-	//		return 19;
-	//	case 223: //cursed ground
-	//		return 22;
-	//	case 224: //evil fog
-	//		return 20;
-	//	case 225: //favourable winds
-	//		return 21;
-	//	case 226: //fiery fields
-	//		return 14;
-	//	case 227: //holy ground
-	//		return 18;
-	//	case 228: //lucid pools
-	//		return 17;
-	//	case 229: //magic clouds
-	//		return 16;
-	//	case 230: //magic plains
-	//		return 9;
-	//	case 231: //rocklands
-	//		return 15;
-	//	}
-	//}
+	std::vector <CGObjectInstance*> & objs = map->objects;
+	for(int g=0; g<objs.size(); ++g)
+	{
+		if( objs[g]->pos.x - tile.x < 0 || objs[g]->pos.x - tile.x >= 8 || tile.y - objs[g]->pos.y + 5 < 0 || tile.y - objs[g]->pos.y + 5 >=6 ||
+			!objs[g]->coveringAt(objs[g]->pos.x - tile.x, tile.y - objs[g]->pos.y + 5)
+			) //look only for objects covering given tile
+			continue;
+		switch(objs[g]->ID)
+		{
+		case 222: //clover field
+			return 19;
+		case 223: //cursed ground
+			return 22;
+		case 224: //evil fog
+			return 20;
+		case 225: //favourable winds
+			return 21;
+		case 226: //fiery fields
+			return 14;
+		case 227: //holy ground
+			return 18;
+		case 228: //lucid pools
+			return 17;
+		case 229: //magic clouds
+			return 16;
+		case 230: //magic plains
+			return 9;
+		case 231: //rocklands
+			return 15;
+		}
+	}
 
 	switch(map->terrain[tile.x][tile.y][tile.z].tertype)
 	{

+ 9 - 0
lib/map.cpp

@@ -6,6 +6,7 @@
 #include "VCMI_Lib.h"
 #include <zlib.h>
 #include <boost/crc.hpp>
+#include "../hch/CLodHandler.h"
 
 /*
  * map.cpp, part of VCMI engine
@@ -1358,6 +1359,14 @@ void Mapa::readDefInfo( unsigned char * bufor, int &i)
 		if(vinya->id == 26)
 			std::memset(vinya->blockMap,255,6);
 
+		//calculating coverageMap
+		std::string nameCopy = vinya->name;
+		std::string msk = spriteh->getTextFile(nameCopy.replace( nameCopy.size()-4, 4, ".MSK" ));
+		for(int i=0; i<6; ++i)
+		{
+			vinya->coverageMap[i] = msk[i+2];
+		}
+
 		defy.push_back(vinya); // add this def to the vector
 	}
 }

+ 2 - 0
mapHandler.cpp

@@ -762,6 +762,8 @@ void CMapHandler::terrainRect(int3 top_tile, unsigned char anim, std::vector< st
 
 			for(int h=0; h < objects.size(); ++h)
 			{
+				if(!objects[h].first->coveringAt(objects[h].first->pos.x - (top_tile.x + bx), top_tile.y + by - objects[h].first->pos.y + 5))
+					continue;
 				SDL_Rect sr;
 
 				sr.x = srx;