mateuszb %!s(int64=18) %!d(string=hai) anos
pai
achega
62b69b1f25
Modificáronse 6 ficheiros con 124 adicións e 78 borrados
  1. 3 2
      CCallback.cpp
  2. 48 48
      CMT.cpp
  3. 16 0
      hch/CAmbarCendamo.cpp
  4. 1 1
      hch/CObjectHandler.h
  5. 54 25
      mapHandler.cpp
  6. 2 2
      mapHandler.h

+ 3 - 2
CCallback.cpp

@@ -98,10 +98,10 @@ bool CCallback::moveHero(int ID, CPath * path, int idtype, int pathType)
 		curd.dst = endpos;
 		curd.ho = hero->ourObject;
 		curd.owner = hero->owner;
-		if(player!=-1)
+		/*if(player!=-1)
 		{
 			hero->pos = endpos;
-		}
+		}*/
 		//if(CGI->heroh->heroInstances[ID]->movement>=CGI->mh->getCost(stpos, endpos, CGI->heroh->heroInstances[ID]))
 		{ //performing move
 			int nn=0; //number of interfece of currently browsed player
@@ -118,6 +118,7 @@ bool CCallback::moveHero(int ID, CPath * path, int idtype, int pathType)
 		//else
 			//return true; //move ended - no more movement points
 		hero->pos = curd.dst;
+		hero->ourObject->pos = curd.dst;
 	}
 	return true;
 }

+ 48 - 48
CMT.cpp

@@ -58,24 +58,24 @@ const char * NAME = "VCMI 0.3 \"Tol Galen\"";
 SDL_Surface * ekran, * screen, * screen2;
 TTF_Font * TNRB16, *TNR, *GEOR13, *GEORXX, *GEORM;
 
-//#include "lua.h"
-//#include "lualib.h"
-//#include "lauxlib.h"
-//#include <luabind/luabind.hpp>
-//#include <luabind/function.hpp>
-//#include <luabind/class.hpp>
-//
-//#if (LUA_VERSION_NUM < 500)
-//#  define LUA_OPEN_LIB(L, lib) lib(L)
-//#else
-//#  define LUA_OPEN_LIB(L, lib) \
-//     lua_pushcfunction((L), lib); \
-//     lua_pcall((L), 0, 0, 0);
-//#endif
-//void piszpowitanie2(std::string i)
-//{
-//	std::cout<<"powitanie2zc++. Liczba dnia to " << i;
-//}
+#include "lua.h"
+#include "lualib.h"
+#include "lauxlib.h"
+#include <luabind/luabind.hpp>
+#include <luabind/function.hpp>
+#include <luabind/class.hpp>
+
+#if (LUA_VERSION_NUM < 500)
+#  define LUA_OPEN_LIB(L, lib) lib(L)
+#else
+#  define LUA_OPEN_LIB(L, lib) \
+     lua_pushcfunction((L), lib); \
+     lua_pcall((L), 0, 0, 0);
+#endif
+void piszpowitanie2(std::string i)
+{
+	std::cout<<"powitanie2zc++. Liczba dnia to " << i;
+}
 
 void initGameState(CGameInfo * cgi)
 {
@@ -179,39 +179,39 @@ void initGameState(CGameInfo * cgi)
 int _tmain(int argc, _TCHAR* argv[])
 { 
 
-	//int iErr = 0;
-	//lua_State *lua = lua_open ();  // Open Lua
-	//	LUA_OPEN_LIB(lua, luaopen_base);
-	//	LUA_OPEN_LIB(lua, luaopen_io);
+	int iErr = 0;
+	lua_State *lua = lua_open ();  // Open Lua
+		LUA_OPEN_LIB(lua, luaopen_base);
+		LUA_OPEN_LIB(lua, luaopen_io);
 
-	//if ((iErr = luaL_loadfile (lua, "test.lua")) == 0)
-	//{
-	//	
+	if ((iErr = luaL_loadfile (lua, "test.lua")) == 0)
+	{
+		
 
-	//   // Call main...
-	//   if ((iErr = lua_pcall (lua, 0, LUA_MULTRET, 0)) == 0)
-	//   {    
-	//	   luabind::open(lua);
-	//	   luabind::module(lua)
-	//		[
-	//			luabind::def("powitanie",&piszpowitanie2)
+	   // Call main...
+	   if ((iErr = lua_pcall (lua, 0, LUA_MULTRET, 0)) == 0)
+	   {    
+		   luabind::open(lua);
+		   luabind::module(lua)
+			[
+				luabind::def("powitanie",&piszpowitanie2)
 
-	//		];
+			];
 
-	//   //int ret = luabind::call_function<int>(lua, "helloWorld2");
+	   //int ret = luabind::call_function<int>(lua, "helloWorld2");
 
-	//	  lua_pushstring (lua, "helloWorld2");
-	//	  lua_gettable (lua, LUA_GLOBALSINDEX);  
-	//	  lua_pcall (lua, 0, 0, 0);
+		  lua_pushstring (lua, "helloWorld2");
+		  lua_gettable (lua, LUA_GLOBALSINDEX);  
+		  lua_pcall (lua, 0, 0, 0);
 
-	//	  // Push the function name onto the stack
-	//	  lua_pushstring (lua, "helloWorld");
-	//	  lua_gettable (lua, LUA_GLOBALSINDEX);  
-	//	  lua_pcall (lua, 0, 0, 0);
-	//   }
+		  // Push the function name onto the stack
+		  lua_pushstring (lua, "helloWorld");
+		  lua_gettable (lua, LUA_GLOBALSINDEX);  
+		  lua_pcall (lua, 0, 0, 0);
+	   }
 
-	//}
-	//lua_close (lua);
+	}
+	lua_close (lua);
 
 
 		//CBIKHandler cb;
@@ -358,7 +358,7 @@ int _tmain(int argc, _TCHAR* argv[])
 				}
 			}
 
-			for(int ff=0; ff<cgi->heroh->flags1[q]->ourImages.size(); ++ff)
+			for(int ff=80; ff<cgi->heroh->flags1[q]->ourImages.size(); ++ff)
 			{
 				CSDL_Ext::fullAlphaTransform(cgi->heroh->flags1[q]->ourImages[ff].bitmap);
 			}
@@ -416,7 +416,7 @@ int _tmain(int argc, _TCHAR* argv[])
 				}
 			}
 
-			for(int ff=0; ff<cgi->heroh->flags2[q]->ourImages.size(); ++ff)
+			for(int ff=80; ff<cgi->heroh->flags2[q]->ourImages.size(); ++ff)
 			{
 				CSDL_Ext::fullAlphaTransform(cgi->heroh->flags2[q]->ourImages[ff].bitmap);
 			}
@@ -474,7 +474,7 @@ int _tmain(int argc, _TCHAR* argv[])
 				}
 			}
 
-			for(int ff=0; ff<cgi->heroh->flags3[q]->ourImages.size(); ++ff)
+			for(int ff=80; ff<cgi->heroh->flags3[q]->ourImages.size(); ++ff)
 			{
 				CSDL_Ext::fullAlphaTransform(cgi->heroh->flags3[q]->ourImages[ff].bitmap);
 			}
@@ -572,7 +572,7 @@ int _tmain(int argc, _TCHAR* argv[])
 				}
 			}
 
-			for(int ff=0; ff<cgi->heroh->flags4[q]->ourImages.size(); ++ff)
+			for(int ff=80; ff<cgi->heroh->flags4[q]->ourImages.size(); ++ff)
 			{
 				CSDL_Ext::fullAlphaTransform(cgi->heroh->flags4[q]->ourImages[ff].bitmap);
 			}

+ 16 - 0
hch/CAmbarCendamo.cpp

@@ -2848,6 +2848,22 @@ void CAmbarCendamo::processMap(std::vector<std::string> & defsToUnpack)
 				//((CCastleObjInfo*)CGI->objh->objInstances[j].info)
 				break;
 			}
+		case EDefType::HERO_DEF:
+			{
+				std::vector<DefObjInfo>::iterator pit = std::find(CGameInfo::mainObj->dobjinfo->objs.begin(), CGameInfo::mainObj->dobjinfo->objs.end(), 
+						map.defy[CGI->objh->objInstances[j]->defNumber].name);
+
+				map.defy[CGI->objh->objInstances[j]->defNumber].printPriority = 0;
+				if(pit == CGameInfo::mainObj->dobjinfo->objs.end())
+				{
+					map.defy[CGI->objh->objInstances[j]->defNumber].isOnDefList = false;
+				}
+				else
+				{
+					map.defy[CGI->objh->objInstances[j]->defNumber].isOnDefList = true;
+				}
+				break;
+			}
 		} //end of main switch
 	} //end of main loop
 	for(int j=0; j<CGI->objh->objInstances.size(); ++j) //for creature dwellings on map (they are town type dependent)

+ 1 - 1
hch/CObjectHandler.h

@@ -299,7 +299,7 @@ public:
 	bool isHero; //true if this is a hero
 	unsigned char moveDir; //direction of hero movement (0 - default; 1 - lt; 2 - t; 3 - tr; 4 - r; 5 - br; 6 - b; 7 - bl; 8 - l)
 	bool isStanding; //true if is standing, flase if is moving
-	bool flagPrinted; //true if flag has been printed
+	unsigned char flagPrinted; //true if flag has been printed //number of print hits
 	unsigned char owner; //if 254, object cannot have owner; if it has, it equal to owner's ID (or 255, when no owner)
 	bool operator<(const CObjectInstance & cmp) const;  //screen printing priority comparing
 };

+ 54 - 25
mapHandler.cpp

@@ -358,8 +358,8 @@ void CMapHandler::init()
 	//initializing objects / rects
 	for(int f=0; f<CGI->objh->objInstances.size(); ++f)
 	{	
-		CGI->objh->objInstances[f]->pos.x+=1;
-		CGI->objh->objInstances[f]->pos.y+=1;
+		/*CGI->objh->objInstances[f]->pos.x+=1;
+		CGI->objh->objInstances[f]->pos.y+=1;*/
 		CDefHandler * curd = CGI->ac->map.defy[CGI->objh->objInstances[f]->defNumber].handler;
 		for(int fx=0; fx<curd->ourImages[0].bitmap->w/32; ++fx)
 		{
@@ -371,7 +371,7 @@ void CMapHandler::init()
 				cr.x = fx*32;
 				cr.y = fy*32;
 				std::pair<CObjectInstance *, SDL_Rect> toAdd = std::make_pair(CGI->objh->objInstances[f], cr);
-				if((CGI->objh->objInstances[f]->pos.x + fx - curd->ourImages[0].bitmap->w/32)>=0 && (CGI->objh->objInstances[f]->pos.x + fx - curd->ourImages[0].bitmap->w/32)<ttiles.size()-Woff && (CGI->objh->objInstances[f]->pos.y + fy - curd->ourImages[0].bitmap->h/32)>=0 && (CGI->objh->objInstances[f]->pos.y + fy - curd->ourImages[0].bitmap->h/32)<ttiles[0].size()-Hoff)
+				if((CGI->objh->objInstances[f]->pos.x + fx - curd->ourImages[0].bitmap->w/32+1)>=0 && (CGI->objh->objInstances[f]->pos.x + fx - curd->ourImages[0].bitmap->w/32+1)<ttiles.size()-Woff && (CGI->objh->objInstances[f]->pos.y + fy - curd->ourImages[0].bitmap->h/32+1)>=0 && (CGI->objh->objInstances[f]->pos.y + fy - curd->ourImages[0].bitmap->h/32+1)<ttiles[0].size()-Hoff)
 				{
 					TerrainTile2 & curt = 
 						ttiles
@@ -380,7 +380,7 @@ void CMapHandler::init()
 						  [CGI->objh->objInstances[f]->pos.z];
 
 
-					ttiles[CGI->objh->objInstances[f]->pos.x + fx - curd->ourImages[0].bitmap->w/32][CGI->objh->objInstances[f]->pos.y + fy - curd->ourImages[0].bitmap->h/32][CGI->objh->objInstances[f]->pos.z].objects.push_back(toAdd);
+					ttiles[CGI->objh->objInstances[f]->pos.x + fx - curd->ourImages[0].bitmap->w/32+1][CGI->objh->objInstances[f]->pos.y + fy - curd->ourImages[0].bitmap->h/32+1][CGI->objh->objInstances[f]->pos.z].objects.push_back(toAdd);
 				}
 
 			} // for(int fy=0; fy<curd->ourImages[0].bitmap->h/32; ++fy)
@@ -395,8 +395,8 @@ void CMapHandler::init()
 		{
 			for(int fy=0; fy<6; ++fy)
 			{
-				int xVal = CGI->objh->objInstances[f]->pos.x + fx - 8;
-				int yVal = CGI->objh->objInstances[f]->pos.y + fy - 6;
+				int xVal = CGI->objh->objInstances[f]->pos.x + fx - 7;
+				int yVal = CGI->objh->objInstances[f]->pos.y + fy - 5;
 				int zVal = CGI->objh->objInstances[f]->pos.z;
 				if(xVal>=0 && xVal<ttiles.size()-Woff && yVal>=0 && yVal<ttiles[0].size()-Hoff)
 				{
@@ -583,10 +583,15 @@ SDL_Surface * CMapHandler::terrainRect(int x, int y, int dx, int dy, int level,
 								}
 							}
 							SDL_BlitSurface(tb,&pp,su,&sr);
-							if(!ttiles[x+bx][y+by][level].objects[h].first->flagPrinted)
+							if(ttiles[x+bx][y+by][level].objects[h].first->flagPrinted++==2 )
 							{
-								SDL_BlitSurface(CGI->heroh->flags4[ttiles[x+bx][y+by][level].objects[h].first->owner]->ourImages[gg+anim%imgVal+35].bitmap, NULL, su, &sr);
-								ttiles[x+bx][y+by][level].objects[h].first->flagPrinted = true;
+								SDL_Rect bufr = pp;
+								bufr.w = 3*32;
+								bufr.h = 2*32;
+								bufr.x = 32 - bufr.x + 3*32 + bx + y + 6*32-10;
+								bufr.y = 32 - bufr.y + 2*32 + by + x + 5*32-12;
+								SDL_BlitSurface(CGI->heroh->flags4[ttiles[x+bx][y+by][level].objects[h].first->owner]->ourImages[gg+anim%imgVal+35].bitmap, NULL, su, &bufr);
+								//ttiles[x+bx][y+by][level].objects[h].first->flagPrinted = true;
 							}
 							break;
 						}
@@ -701,9 +706,12 @@ SDL_Surface * CMapHandler::terrainRect(int x, int y, int dx, int dy, int level,
 								}
 							}
 							SDL_BlitSurface(tb,&pp,su,&sr);
-							if(!ttiles[x+bx][y+by][level].objects[h].first->flagPrinted)
+							if(ttiles[x+bx][y+by][level].objects[h].first->pos.x==x+bx && ttiles[x+bx][y+by][level].objects[h].first->pos.y==y+by)
 							{
-								SDL_BlitSurface(CGI->heroh->flags4[ttiles[x+bx][y+by][level].objects[h].first->owner]->ourImages[13*8+anim%imgVal].bitmap, NULL, su, &sr);
+								SDL_Rect bufr = sr;
+								bufr.x-=2*32;
+								bufr.y-=1*32;
+								SDL_BlitSurface(CGI->heroh->flags4[ttiles[x+bx][y+by][level].objects[h].first->owner]->ourImages[13*8+anim%imgVal].bitmap, NULL, su, &bufr);
 								ttiles[x+bx][y+by][level].objects[h].first->flagPrinted = true;
 							}
 							break;
@@ -723,9 +731,12 @@ SDL_Surface * CMapHandler::terrainRect(int x, int y, int dx, int dy, int level,
 								}
 							}
 							SDL_BlitSurface(tb,&pp,su,&sr);
-							if(!ttiles[x+bx][y+by][level].objects[h].first->flagPrinted)
+							if(ttiles[x+bx][y+by][level].objects[h].first->pos.x==x+bx && ttiles[x+bx][y+by][level].objects[h].first->pos.y==y+by)
 							{
-								SDL_BlitSurface(CGI->heroh->flags4[ttiles[x+bx][y+by][level].objects[h].first->owner]->ourImages[anim%imgVal].bitmap, NULL, su, &sr);	
+								SDL_Rect bufr = sr;
+								bufr.x-=2*32;
+								bufr.y-=1*32;
+								SDL_BlitSurface(CGI->heroh->flags4[ttiles[x+bx][y+by][level].objects[h].first->owner]->ourImages[anim%imgVal].bitmap, NULL, su, &bufr);	
 								ttiles[x+bx][y+by][level].objects[h].first->flagPrinted = true;
 							}
 							break;
@@ -745,9 +756,12 @@ SDL_Surface * CMapHandler::terrainRect(int x, int y, int dx, int dy, int level,
 								}
 							}
 							SDL_BlitSurface(tb,&pp,su,&sr);
-							if(!ttiles[x+bx][y+by][level].objects[h].first->flagPrinted)
+							if(ttiles[x+bx][y+by][level].objects[h].first->pos.x==x+bx && ttiles[x+bx][y+by][level].objects[h].first->pos.y==y+by)
 							{
-								SDL_BlitSurface(CGI->heroh->flags4[ttiles[x+bx][y+by][level].objects[h].first->owner]->ourImages[8+anim%imgVal].bitmap, NULL, su, &sr);
+								SDL_Rect bufr = sr;
+								bufr.x-=2*32;
+								bufr.y-=1*32;
+								SDL_BlitSurface(CGI->heroh->flags4[ttiles[x+bx][y+by][level].objects[h].first->owner]->ourImages[8+anim%imgVal].bitmap, NULL, su, &bufr);
 								ttiles[x+bx][y+by][level].objects[h].first->flagPrinted = true;
 							}
 							break;
@@ -767,9 +781,12 @@ SDL_Surface * CMapHandler::terrainRect(int x, int y, int dx, int dy, int level,
 								}
 							}
 							SDL_BlitSurface(tb,&pp,su,&sr);
-							if(!ttiles[x+bx][y+by][level].objects[h].first->flagPrinted)
+							if(ttiles[x+bx][y+by][level].objects[h].first->pos.x==x+bx && ttiles[x+bx][y+by][level].objects[h].first->pos.y==y+by)
 							{
-								SDL_BlitSurface(CGI->heroh->flags4[ttiles[x+bx][y+by][level].objects[h].first->owner]->ourImages[2*8+anim%imgVal].bitmap, NULL, su, &sr);
+								SDL_Rect bufr = sr;
+								bufr.x-=2*32;
+								bufr.y-=1*32;
+								SDL_BlitSurface(CGI->heroh->flags4[ttiles[x+bx][y+by][level].objects[h].first->owner]->ourImages[2*8+anim%imgVal].bitmap, NULL, su, &bufr);
 								ttiles[x+bx][y+by][level].objects[h].first->flagPrinted = true;
 							}
 							break;
@@ -789,9 +806,12 @@ SDL_Surface * CMapHandler::terrainRect(int x, int y, int dx, int dy, int level,
 								}
 							}
 							SDL_BlitSurface(tb,&pp,su,&sr);
-							if(!ttiles[x+bx][y+by][level].objects[h].first->flagPrinted)
+							if(ttiles[x+bx][y+by][level].objects[h].first->pos.x==x+bx && ttiles[x+bx][y+by][level].objects[h].first->pos.y==y+by)
 							{
-								SDL_BlitSurface(CGI->heroh->flags4[ttiles[x+bx][y+by][level].objects[h].first->owner]->ourImages[3*8+anim%imgVal].bitmap, NULL, su, &sr);
+								SDL_Rect bufr = sr;
+								bufr.x-=2*32;
+								bufr.y-=1*32;
+								SDL_BlitSurface(CGI->heroh->flags4[ttiles[x+bx][y+by][level].objects[h].first->owner]->ourImages[3*8+anim%imgVal].bitmap, NULL, su, &bufr);
 								ttiles[x+bx][y+by][level].objects[h].first->flagPrinted = true;
 							}
 							break;
@@ -811,9 +831,12 @@ SDL_Surface * CMapHandler::terrainRect(int x, int y, int dx, int dy, int level,
 								}
 							}
 							SDL_BlitSurface(tb,&pp,su,&sr);
-							if(!ttiles[x+bx][y+by][level].objects[h].first->flagPrinted)
+							if(ttiles[x+bx][y+by][level].objects[h].first->pos.x==x+bx && ttiles[x+bx][y+by][level].objects[h].first->pos.y==y+by)
 							{
-								SDL_BlitSurface(CGI->heroh->flags4[ttiles[x+bx][y+by][level].objects[h].first->owner]->ourImages[4*8+anim%imgVal].bitmap, NULL, su, &sr);
+								SDL_Rect bufr = sr;
+								bufr.x-=2*32;
+								bufr.y-=1*32;
+								SDL_BlitSurface(CGI->heroh->flags4[ttiles[x+bx][y+by][level].objects[h].first->owner]->ourImages[4*8+anim%imgVal].bitmap, NULL, su, &bufr);
 								ttiles[x+bx][y+by][level].objects[h].first->flagPrinted = true;
 							}
 							break;
@@ -833,9 +856,12 @@ SDL_Surface * CMapHandler::terrainRect(int x, int y, int dx, int dy, int level,
 								}
 							}
 							SDL_BlitSurface(tb,&pp,su,&sr);
-							if(!ttiles[x+bx][y+by][level].objects[h].first->flagPrinted)
+							if(ttiles[x+bx][y+by][level].objects[h].first->pos.x==x+bx && ttiles[x+bx][y+by][level].objects[h].first->pos.y==y+by)
 							{
-								SDL_BlitSurface(CGI->heroh->flags4[ttiles[x+bx][y+by][level].objects[h].first->owner]->ourImages[15*8+anim%imgVal].bitmap, NULL, su, &sr);
+								SDL_Rect bufr = sr;
+								bufr.x-=2*32;
+								bufr.y-=1*32;
+								SDL_BlitSurface(CGI->heroh->flags4[ttiles[x+bx][y+by][level].objects[h].first->owner]->ourImages[15*8+anim%imgVal].bitmap, NULL, su, &bufr);
 								ttiles[x+bx][y+by][level].objects[h].first->flagPrinted = true;
 							}
 							break;
@@ -855,9 +881,12 @@ SDL_Surface * CMapHandler::terrainRect(int x, int y, int dx, int dy, int level,
 								}
 							}
 							SDL_BlitSurface(tb,&pp,su,&sr);
-							if(!ttiles[x+bx][y+by][level].objects[h].first->flagPrinted)
+							if(ttiles[x+bx][y+by][level].objects[h].first->pos.x==x+bx && ttiles[x+bx][y+by][level].objects[h].first->pos.y==y+by)
 							{
-								SDL_BlitSurface(CGI->heroh->flags4[ttiles[x+bx][y+by][level].objects[h].first->owner]->ourImages[14*8+anim%imgVal].bitmap, NULL, su, &sr);
+								SDL_Rect bufr = sr;
+								bufr.x-=2*32;
+								bufr.y-=1*32;
+								SDL_BlitSurface(CGI->heroh->flags4[ttiles[x+bx][y+by][level].objects[h].first->owner]->ourImages[14*8+anim%imgVal].bitmap, NULL, su, &bufr);
 								ttiles[x+bx][y+by][level].objects[h].first->flagPrinted = true;
 							}
 							break;

+ 2 - 2
mapHandler.h

@@ -7,8 +7,8 @@
 #include "hch\CDefHandler.h"
 #include <boost/logic/tribool.hpp>
 #include "hch\CObjectHandler.h"
-const int Woff = 4; //width of map's frame
-const int Hoff = 4; 
+const int Woff = 12; //width of map's frame
+const int Hoff = 8; 
 
 struct TerrainTile2
 {