소스 검색

some stuff to hero moving

mateuszb 18 년 전
부모
커밋
55c0dc0229
7개의 변경된 파일129개의 추가작업 그리고 62개의 파일을 삭제
  1. 4 4
      CCallback.cpp
  2. 58 5
      CGameInterface.cpp
  3. 2 0
      CGameInterface.h
  4. 17 0
      CMT.cpp
  5. 4 0
      hch/CAmbarCendamo.cpp
  6. 2 0
      hch/CHeroHandler.h
  7. 42 53
      mapHandler.cpp

+ 4 - 4
CCallback.cpp

@@ -21,17 +21,17 @@ bool CCallback::moveHero(int ID, int3 destPoint)
 	CPath * ourPath = CGI->pathf->getPath(CGI->heroh->heroInstances[ID]->pos, destPoint, CGI->heroh->heroInstances[ID]);
 	if(!ourPath)
 		return false;
-	for(int i=0; i<ourPath->nodes.size()-1; ++i)
+	for(int i=ourPath->nodes.size()-1; i>0; i--)
 	{
 		int3 stpos, endpos;
 		stpos = int3(ourPath->nodes[i].x, ourPath->nodes[i].y, CGI->heroh->heroInstances[ID]->pos.z);
-		endpos = int3(ourPath->nodes[i+1].x, ourPath->nodes[i+1].y, CGI->heroh->heroInstances[ID]->pos.z);
+		endpos = int3(ourPath->nodes[i-1].x, ourPath->nodes[i-1].y, CGI->heroh->heroInstances[ID]->pos.z);
 		HeroMoveDetails curd;
 		curd.src = stpos;
 		curd.dst = endpos;
 		curd.heroID = ID;
 		curd.owner = CGI->heroh->heroInstances[ID]->owner;
-		if(CGI->heroh->heroInstances[ID]->movement>=CGI->mh->getCost(stpos, endpos, CGI->heroh->heroInstances[ID]))
+		//if(CGI->heroh->heroInstances[ID]->movement>=CGI->mh->getCost(stpos, endpos, CGI->heroh->heroInstances[ID]))
 		{ //performing move
 			for(int j=0; j<CGI->state->players.size(); ++j)
 			{
@@ -41,7 +41,7 @@ bool CCallback::moveHero(int ID, int3 destPoint)
 				}
 			}
 		}
-		else
+		//else
 			return true; //move ended - no more movement points
 	}
 	return true;

+ 58 - 5
CGameInterface.cpp

@@ -6,6 +6,7 @@
 #include "SDL_framerate.h"
 #include "CScreenHandler.h"
 #include "CCursorHandler.h"
+#include "CCallback.h"
 using namespace CSDL_Ext;
 CButtonBase::CButtonBase()
 {
@@ -112,9 +113,9 @@ void CPlayerInterface::yourTurn()
 	//show rest of things
 
 	//initializing framerate keeper
-	FPSmanager * mainLoopFramerateKeeper = new FPSmanager;
-	SDL_initFramerate(mainLoopFramerateKeeper);
-	SDL_setFramerate(mainLoopFramerateKeeper, 24);
+	mainFPSmng = new FPSmanager;
+	SDL_initFramerate(mainFPSmng);
+	SDL_setFramerate(mainFPSmng, 24);
 	SDL_Event sEvent;
 	//framerate keeper initialized
 	for(;;) // main loop
@@ -172,13 +173,65 @@ void CPlayerInterface::yourTurn()
 			LOCPLINT->adventureInt->updateScreen=false;
 		}
 		SDL_Delay(5); //give time for other apps
-		SDL_framerateDelay(mainLoopFramerateKeeper);
+		SDL_framerateDelay(mainFPSmng);
 	}
 }
 
 void CPlayerInterface::heroMoved(const HeroMoveDetails & details)
 {
-	
+	//initializing objects and performing first step of move
+	CObjectInstance * ho = CGI->heroh->heroInstances[details.heroID]->ourObject; //object representing this hero
+	if(details.dst.x+1 == details.src.x && details.dst.y+1 == details.src.y) //tl
+	{
+	}
+	else if(details.dst.x == details.src.x && details.dst.y+1 == details.src.y) //t
+	{
+	}
+	else if(details.dst.x-1 == details.src.x && details.dst.y+1 == details.src.y) //tr
+	{
+	}
+	else if(details.dst.x-1 == details.src.x && details.dst.y == details.src.y) //r
+	{
+	}
+	else if(details.dst.x-1 == details.src.x && details.dst.y-1 == details.src.y) //br
+	{
+	}
+	else if(details.dst.x == details.src.x && details.dst.y-1 == details.src.y) //b
+	{
+	}
+	else if(details.dst.x+1 == details.src.x && details.dst.y-1 == details.src.y) //bl
+	{
+	}
+	else if(details.dst.x+1 == details.src.x && details.dst.y == details.src.y) //l
+	{
+	}
+	for(int i=0; i<32; ++i)
+	{
+		if(details.dst.x+1 == details.src.x && details.dst.y+1 == details.src.y) //tl
+		{
+		}
+		else if(details.dst.x == details.src.x && details.dst.y+1 == details.src.y) //t
+		{
+		}
+		else if(details.dst.x-1 == details.src.x && details.dst.y+1 == details.src.y) //tr
+		{
+		}
+		else if(details.dst.x-1 == details.src.x && details.dst.y == details.src.y) //r
+		{
+		}
+		else if(details.dst.x-1 == details.src.x && details.dst.y-1 == details.src.y) //br
+		{
+		}
+		else if(details.dst.x == details.src.x && details.dst.y-1 == details.src.y) //b
+		{
+		}
+		else if(details.dst.x+1 == details.src.x && details.dst.y-1 == details.src.y) //bl
+		{
+		}
+		else if(details.dst.x+1 == details.src.x && details.dst.y == details.src.y) //l
+		{
+		}
+	}
 }
 
 void CPlayerInterface::handleEvent(SDL_Event *sEvent)

+ 2 - 0
CGameInterface.h

@@ -5,6 +5,7 @@
 #include "hch\CDefHandler.h"
 #include "SDL_Extensions.h"
 #include <boost/logic/tribool.hpp>
+#include "SDL_framerate.h"
 BOOST_TRIBOOL_THIRD_STATE(outOfRange)
 using namespace boost::logic;
 class CAdvMapInt;
@@ -92,6 +93,7 @@ class CPlayerInterface : public CGameInterface
 public:
 	SDL_Event * current;
 	CAdvMapInt * adventureInt;
+	FPSmanager * mainFPSmng;
 	//TODO: town interace, battle interface, other interfaces
 
 	std::vector<ClickableL*> lclickable;

+ 17 - 0
CMT.cpp

@@ -266,6 +266,23 @@ int _tmain(int argc, _TCHAR* argv[])
 		cgi->ac = ac;
 		THC std::cout<<"Reading file: "<<tmh.getDif()<<std::endl;
 		ac->deh3m();
+		//initializing gamestate
+		for(int k=0; k<CGI->state->players.size(); ++k)
+		{
+			CGI->state->players[k].fogOfWarMap.resize(ac->map.width);
+			for(int g=0; g<ac->map.width; ++g)
+				CGI->state->players[k].fogOfWarMap[g].resize(ac->map.height);
+
+			for(int g=0; g<ac->map.width; ++g)
+				for(int h=0; h<ac->map.height; ++h)
+					CGI->state->players[k].fogOfWarMap[g][h].resize(ac->map.twoLevel+1);
+
+			for(int g=0; g<ac->map.width; ++g)
+				for(int h=0; h<ac->map.height; ++h)
+					for(int v=0; v<ac->map.twoLevel+1; ++v)
+						CGI->state->players[k].fogOfWarMap[g][h][v] = 1;
+		}
+		//gamestate nitialized (at least partially)
 		THC std::cout<<"Detecting file (together): "<<tmh.getDif()<<std::endl;
 		ac->loadDefs();
 		THC std::cout<<"Reading terrain defs: "<<tmh.getDif()<<std::endl;

+ 4 - 0
hch/CAmbarCendamo.cpp

@@ -883,6 +883,7 @@ void CAmbarCendamo::deh3m()
 				nhi->pos = nobj->pos;
 				nhi->type = spec->type;
 				nhi->army = spec->garrison;
+				nhi->ourObject = nobj;
 				CGI->heroh->heroInstances.push_back(nhi);
 				break;
 			}
@@ -1468,6 +1469,9 @@ void CAmbarCendamo::deh3m()
 					i+=4;
 					spec->events.push_back(nce);
 				}
+				spec->x = nobj->pos.x;
+				spec->y = nobj->pos.y;
+				spec->z = nobj->pos.z;
 
 				/////// castle events have been read ///////////////////////////
 

+ 2 - 0
hch/CHeroHandler.h

@@ -8,6 +8,7 @@
 #include "../int3.h"
 
 class CHeroClass;
+class CObjectInstance;
 
 
 class CHero
@@ -46,6 +47,7 @@ class CHeroInstance
 public:
 	int owner;
 	CHero * type;
+	CObjectInstance * ourObject;
 	int exp; //experience point
 	int level; //current level of hero
 	std::string name; //may be custom

+ 42 - 53
mapHandler.cpp

@@ -443,12 +443,11 @@ SDL_Surface * CMapHandler::terrainRect(int x, int y, int dx, int dy, int level,
 	{
 		for (int by=0; by<dy; by++)
 		{
-			SDL_Rect * sr = new SDL_Rect;
-			sr->y=by*32;
-			sr->x=bx*32;
-			sr->h=sr->w=32;
-			SDL_BlitSurface(ttiles[x+bx][y+by][level].terbitmap[anim%ttiles[x+bx][y+by][level].terbitmap.size()],NULL,su,sr);
-			delete sr;
+			SDL_Rect sr;
+			sr.y=by*32;
+			sr.x=bx*32;
+			sr.h=sr.w=32;
+			SDL_BlitSurface(ttiles[x+bx][y+by][level].terbitmap[anim%ttiles[x+bx][y+by][level].terbitmap.size()],NULL,su,&sr);
 		}
 	}
 	////terrain printed
@@ -457,13 +456,12 @@ SDL_Surface * CMapHandler::terrainRect(int x, int y, int dx, int dy, int level,
 	{
 		for (int by=0; by<dy; by++)
 		{
-			SDL_Rect * sr = new SDL_Rect;
-			sr->y=by*32;
-			sr->x=bx*32;
-			sr->h=sr->w=32;
+			SDL_Rect sr;
+			sr.y=by*32;
+			sr.x=bx*32;
+			sr.h=sr.w=32;
 			if(ttiles[x+bx][y+by][level].rivbitmap.size())
-				SDL_BlitSurface(ttiles[x+bx][y+by][level].rivbitmap[anim%ttiles[x+bx][y+by][level].rivbitmap.size()],NULL,su,sr);
-			delete sr;
+				SDL_BlitSurface(ttiles[x+bx][y+by][level].rivbitmap[anim%ttiles[x+bx][y+by][level].rivbitmap.size()],NULL,su,&sr);
 		}
 	}
 	////rivers printed
@@ -474,13 +472,12 @@ SDL_Surface * CMapHandler::terrainRect(int x, int y, int dx, int dy, int level,
 		{
 			if(y+by<=-4)
 				continue;
-			SDL_Rect * sr = new SDL_Rect;
-			sr->y=by*32+16;
-			sr->x=bx*32;
-			sr->h=sr->w=32;
+			SDL_Rect sr;
+			sr.y=by*32+16;
+			sr.x=bx*32;
+			sr.h=sr.w=32;
 			if(ttiles[x+bx][y+by][level].roadbitmap.size())
-				SDL_BlitSurface(ttiles[x+bx][y+by][level].roadbitmap[anim%ttiles[x+bx][y+by][level].roadbitmap.size()],NULL,su,sr);
-			delete sr;
+				SDL_BlitSurface(ttiles[x+bx][y+by][level].roadbitmap[anim%ttiles[x+bx][y+by][level].roadbitmap.size()],NULL,su,&sr);
 		}
 	}
 	////roads printed
@@ -492,11 +489,11 @@ SDL_Surface * CMapHandler::terrainRect(int x, int y, int dx, int dy, int level,
 		{
 			for(int h=0; h<ttiles[x+bx][y+by][level].objects.size(); ++h)
 			{
-				SDL_Rect * sr = new SDL_Rect;
-				sr->w = 32;
-				sr->h = 32;
-				sr->x = (bx)*32;
-				sr->y = (by)*32;
+				SDL_Rect sr;
+				sr.w = 32;
+				sr.h = 32;
+				sr.x = (bx)*32;
+				sr.y = (by)*32;
 
 				SDL_Rect pp = ttiles[x+bx][y+by][level].objects[h].second;
 				int imgVal = CGI->ac->map.defy[
@@ -505,8 +502,7 @@ SDL_Surface * CMapHandler::terrainRect(int x, int y, int dx, int dy, int level,
 				SDL_Surface * tb = CGI->ac->map.defy[ttiles[x+bx][y+by][level].objects[h].first->defNumber].handler->ourImages[anim%imgVal].bitmap;
 				SDL_BlitSurface(
 				CGI->ac->map.defy[ttiles[x+bx][y+by][level].objects[h].first->defNumber].handler->ourImages[anim%imgVal].bitmap,
-				&pp,su,sr);
-				delete sr;
+				&pp,su,&sr);
 			}
 		}
 	}
@@ -516,10 +512,10 @@ SDL_Surface * CMapHandler::terrainRect(int x, int y, int dx, int dy, int level,
 	{
 		for (int by=0; by<dy; by++)
 		{
-			SDL_Rect * sr = new SDL_Rect;
-			sr->y=by*32;
-			sr->x=bx*32;
-			sr->h=sr->w=32;
+			SDL_Rect sr;
+			sr.y=by*32;
+			sr.x=bx*32;
+			sr.h=sr.w=32;
 			if (!level)
 			{
 				
@@ -527,7 +523,7 @@ SDL_Surface * CMapHandler::terrainRect(int x, int y, int dx, int dy, int level,
 				{
 					SDL_Surface * hide = getVisBitmap(bx+x, by+y, visibility);
 					SDL_Surface * hide2 = CSDL_Ext::secondAlphaTransform(hide, su);
-					SDL_BlitSurface(hide2, NULL, su, sr);
+					SDL_BlitSurface(hide2, NULL, su, &sr);
 					SDL_FreeSurface(hide2);
 				}
 			}
@@ -537,11 +533,10 @@ SDL_Surface * CMapHandler::terrainRect(int x, int y, int dx, int dy, int level,
 				{
 					SDL_Surface * hide = getVisBitmap(bx+x, by+y, undVisibility);
 					SDL_Surface * hide2 = CSDL_Ext::secondAlphaTransform(hide, su);
-					SDL_BlitSurface(hide2, NULL, su, sr);
+					SDL_BlitSurface(hide2, NULL, su, &sr);
 					SDL_FreeSurface(hide2);
 				}
 			}
-			delete sr;
 		}
 	}
 	////shadow printed
@@ -552,23 +547,21 @@ SDL_Surface * CMapHandler::terrainRect(int x, int y, int dx, int dy, int level,
 		{
 			if(bx+x<0 || by+y<0 || bx+x>reader->map.width+(-1) || by+y>reader->map.height+(-1))
 			{
-				SDL_Rect * sr = new SDL_Rect;
-				sr->y=by*32;
-				sr->x=bx*32;
-				sr->h=sr->w=32;
+				SDL_Rect sr;
+				sr.y=by*32;
+				sr.x=bx*32;
+				sr.h=sr.w=32;
 
-				SDL_BlitSurface(ttiles[x+bx][y+by][level].terbitmap[anim%ttiles[x+bx][y+by][level].terbitmap.size()],NULL,su,sr);
-
-				delete sr;
+				SDL_BlitSurface(ttiles[x+bx][y+by][level].terbitmap[anim%ttiles[x+bx][y+by][level].terbitmap.size()],NULL,su,&sr);
 			}
 			else 
 			{
 				if(MARK_BLOCKED_POSITIONS &&  ttiles[x+bx][y+by][level].blocked) //temporary hiding blocked positions
 				{
-					SDL_Rect * sr = new SDL_Rect;
-					sr->y=by*32;
-					sr->x=bx*32;
-					sr->h=sr->w=32;
+					SDL_Rect sr;
+					sr.y=by*32;
+					sr.x=bx*32;
+					sr.h=sr.w=32;
 
 					SDL_Surface * ns =  SDL_CreateRGBSurface(SDL_SWSURFACE, 32, 32, 32,
 									   rmask, gmask, bmask, amask);
@@ -577,18 +570,16 @@ SDL_Surface * CMapHandler::terrainRect(int x, int y, int dx, int dy, int level,
 						*((unsigned char*)(ns->pixels) + f) = 128;
 					}
 
-					SDL_BlitSurface(ns,NULL,su,sr);
+					SDL_BlitSurface(ns,NULL,su,&sr);
 
 					SDL_FreeSurface(ns);
-
-					delete sr;
 				}
 				if(MARK_VISITABLE_POSITIONS &&  ttiles[x+bx][y+by][level].visitable) //temporary hiding visitable positions
 				{
-					SDL_Rect * sr = new SDL_Rect;
-					sr->y=by*32;
-					sr->x=bx*32;
-					sr->h=sr->w=32;
+					SDL_Rect sr;
+					sr.y=by*32;
+					sr.x=bx*32;
+					sr.h=sr.w=32;
 
 					SDL_Surface * ns =  SDL_CreateRGBSurface(SDL_SWSURFACE, 32, 32, 32,
 									   rmask, gmask, bmask, amask);
@@ -597,11 +588,9 @@ SDL_Surface * CMapHandler::terrainRect(int x, int y, int dx, int dy, int level,
 						*((unsigned char*)(ns->pixels) + f) = 128;
 					}
 
-					SDL_BlitSurface(ns,NULL,su,sr);
+					SDL_BlitSurface(ns,NULL,su,&sr);
 
 					SDL_FreeSurface(ns);
-
-					delete sr;
 				}
 			}
 		}