Browse Source

* added selecting path by clicking on terrain (experimental)
* coordinates in CPathNode are stored in int3
* minor improvements

Michał W. Urbańczyk 18 years ago
parent
commit
cfc94847a1
7 changed files with 134 additions and 91 deletions
  1. 75 47
      CAdvmapInterface.cpp
  2. 3 1
      CAdvmapInterface.h
  3. 2 2
      CCallback.cpp
  4. 46 36
      CPathfinder.cpp
  5. 6 3
      CPathfinder.h
  6. 1 1
      mapHandler.cpp
  7. 1 1
      mapHandler.h

+ 75 - 47
CAdvmapInterface.cpp

@@ -552,7 +552,7 @@ CTerrainRect::CTerrainRect():currentPath(NULL)
 	tilesh=18;
 	pos.x=7;
 	pos.y=6;
-	pos.w=594;
+	pos.w=593;
 	pos.h=547;
 	arrows = CGI->spriteh->giveDef("ADAG.DEF");
 	for(int y=0; y<arrows->ourImages.size(); ++y)
@@ -574,8 +574,35 @@ void CTerrainRect::deactivate()
 	Hoverable::deactivate();
 	KeyInterested::deactivate();
 }; 
-void CTerrainRect::clickLeft(tribool down){}
-void CTerrainRect::clickRight(tribool down){}
+void CTerrainRect::clickLeft(tribool down)
+{
+	if ((down==false) || indeterminate(down))
+		return;
+	int3 mp;
+	mp.x = LOCPLINT->adventureInt->position.x + ((LOCPLINT->current->motion.x-pos.x)/32);
+	mp.y = LOCPLINT->adventureInt->position.y + ((LOCPLINT->current->motion.y-pos.y)/32);
+	mp.z = LOCPLINT->adventureInt->position.z;
+	if (currentPath)
+	{
+		if ( (currentPath->endPos()) == mp)
+		{ //move
+			return;
+		}
+		else
+		{
+			delete currentPath;
+		}
+	}
+	const CHeroInstance * currentHero = LOCPLINT->adventureInt->heroList.items[LOCPLINT->adventureInt->heroList.selected];
+	currentPath = CGI->pathf->getPath(currentHero->pos,mp,currentHero);
+}
+void CTerrainRect::clickRight(tribool down)
+{
+}
+void CTerrainRect::mouseMoved (SDL_MouseMotionEvent & sEvent)
+{
+	//TODO: print names of objects in toolbar
+}
 void CTerrainRect::hover(bool on){}
 void CTerrainRect::keyPressed (SDL_KeyboardEvent & key){}
 void CTerrainRect::show()
@@ -592,8 +619,8 @@ void CTerrainRect::show()
 			int pn=-1;//number of picture
 			if (i==0) //last tile
 			{
-				int x = 32*(currentPath->nodes[i].x-LOCPLINT->adventureInt->position.x)+7,
-					y = 32*(currentPath->nodes[i].y-LOCPLINT->adventureInt->position.y)+6;
+				int x = 32*(currentPath->nodes[i].coord.x-LOCPLINT->adventureInt->position.x)+7,
+					y = 32*(currentPath->nodes[i].coord.y-LOCPLINT->adventureInt->position.y)+6;
 				if (x<0 || y<0 || x>pos.w || y>pos.h)
 					continue;
 				pn=0;
@@ -601,154 +628,154 @@ void CTerrainRect::show()
 			else
 			{
 				std::vector<CPathNode> & cv = currentPath->nodes;
-				if (cv[i+1].x == cv[i].x-1 && cv[i+1].y == cv[i].y-1)
+				if (cv[i+1].coord.x == cv[i].coord.x-1 && cv[i+1].coord.y == cv[i].coord.y-1)
 				{
-					if(cv[i-1].x == cv[i].x+1 && cv[i-1].y == cv[i].y)
+					if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y)
 					{
 						pn = 3;
 					}
-					else if(cv[i-1].x == cv[i].x+1 && cv[i-1].y == cv[i].y+1)
+					else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y+1)
 					{
 						pn = 12;
 					}
-					else if(cv[i-1].x == cv[i].x && cv[i-1].y == cv[i].y+1)
+					else if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y+1)
 					{
 						pn = 21;
 					}
-					else if(cv[i-1].x == cv[i].x-1 && cv[i-1].y == cv[i].y+1)
+					else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y+1)
 					{
 						pn = 22;
 					}
-					else if(cv[i-1].x == cv[i].x+1 && cv[i-1].y == cv[i].y-1)
+					else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y-1)
 					{
 						pn = 2;
 					}
 				}
-				else if (cv[i+1].x == cv[i].x && cv[i+1].y == cv[i].y-1)
+				else if (cv[i+1].coord.x == cv[i].coord.x && cv[i+1].coord.y == cv[i].coord.y-1)
 				{
-					if(cv[i-1].x == cv[i].x+1 && cv[i-1].y == cv[i].y+1)
+					if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y+1)
 					{
 						pn = 4;
 					}
-					else if(cv[i-1].x == cv[i].x && cv[i-1].y == cv[i].y+1)
+					else if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y+1)
 					{
 						pn = 13;
 					}
-					else if(cv[i-1].x == cv[i].x-1 && cv[i-1].y == cv[i].y+1)
+					else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y+1)
 					{
 						pn = 22;
 					}
 				}
-				else if (cv[i+1].x == cv[i].x+1 && cv[i+1].y == cv[i].y-1)
+				else if (cv[i+1].coord.x == cv[i].coord.x+1 && cv[i+1].coord.y == cv[i].coord.y-1)
 				{
-					if(cv[i-1].x == cv[i].x && cv[i-1].y == cv[i].y+1)
+					if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y+1)
 					{
 						pn = 5;
 					}
-					else if(cv[i-1].x == cv[i].x-1 && cv[i-1].y == cv[i].y+1)
+					else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y+1)
 					{
 						pn = 14;
 					}
-					else if(cv[i-1].x-1 == cv[i].x && cv[i-1].y == cv[i].y)
+					else if(cv[i-1].coord.x-1 == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y)
 					{
 						pn = 23;
 					}
-					else if(cv[i-1].x == cv[i].x-1 && cv[i-1].y == cv[i].y-1)
+					else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y-1)
 					{
 						pn = 24;
 					}
-					else if(cv[i-1].x == cv[i].x+1 && cv[i-1].y == cv[i].y+1)
+					else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y+1)
 					{
 						pn = 4;
 					}
 				}
-				else if (cv[i+1].x == cv[i].x+1 && cv[i+1].y == cv[i].y)
+				else if (cv[i+1].coord.x == cv[i].coord.x+1 && cv[i+1].coord.y == cv[i].coord.y)
 				{
-					if(cv[i-1].x == cv[i].x-1 && cv[i-1].y == cv[i].y+1)
+					if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y+1)
 					{
 						pn = 6;
 					}
-					else if(cv[i-1].x == cv[i].x-1 && cv[i-1].y == cv[i].y)
+					else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y)
 					{
 						pn = 15;
 					}
-					else if(cv[i-1].x == cv[i].x-1 && cv[i-1].y == cv[i].y-1)
+					else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y-1)
 					{
 						pn = 24;
 					}
 				}
-				else if (cv[i+1].x == cv[i].x+1 && cv[i+1].y == cv[i].y+1)
+				else if (cv[i+1].coord.x == cv[i].coord.x+1 && cv[i+1].coord.y == cv[i].coord.y+1)
 				{
-					if(cv[i-1].x == cv[i].x-1 && cv[i-1].y == cv[i].y)
+					if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y)
 					{
 						pn = 7;
 					}
-					else if(cv[i-1].x == cv[i].x-1 && cv[i-1].y == cv[i].y-1)
+					else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y-1)
 					{
 						pn = 16;
 					}
-					else if(cv[i-1].x == cv[i].x && cv[i-1].y == cv[i].y-1)
+					else if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y-1)
 					{
 						pn = 17;
 					}
-					else if(cv[i-1].x == cv[i].x-1 && cv[i-1].y == cv[i].y+1)
+					else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y+1)
 					{
 						pn = 6;
 					}
-					else if(cv[i-1].x == cv[i].x+1 && cv[i-1].y == cv[i].y-1)
+					else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y-1)
 					{
 						pn = 18;
 					}
 				}
-				else if (cv[i+1].x == cv[i].x && cv[i+1].y == cv[i].y+1)
+				else if (cv[i+1].coord.x == cv[i].coord.x && cv[i+1].coord.y == cv[i].coord.y+1)
 				{
-					if(cv[i-1].x == cv[i].x-1 && cv[i-1].y == cv[i].y-1)
+					if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y-1)
 					{
 						pn = 8;
 					}
-					else if(cv[i-1].x == cv[i].x && cv[i-1].y == cv[i].y-1)
+					else if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y-1)
 					{
 						pn = 9;
 					}
-					else if(cv[i-1].x == cv[i].x+1 && cv[i-1].y == cv[i].y-1)
+					else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y-1)
 					{
 						pn = 18;
 					}
 				}
-				else if (cv[i+1].x == cv[i].x-1 && cv[i+1].y == cv[i].y+1)
+				else if (cv[i+1].coord.x == cv[i].coord.x-1 && cv[i+1].coord.y == cv[i].coord.y+1)
 				{
-					if(cv[i-1].x == cv[i].x && cv[i-1].y == cv[i].y-1)
+					if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y-1)
 					{
 						pn = 1;
 					}
-					else if(cv[i-1].x == cv[i].x+1 && cv[i-1].y == cv[i].y-1)
+					else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y-1)
 					{
 						pn = 10;
 					}
-					else if(cv[i-1].x == cv[i].x+1 && cv[i-1].y == cv[i].y)
+					else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y)
 					{
 						pn = 19;
 					}
-					else if(cv[i-1].x == cv[i].x-1 && cv[i-1].y == cv[i].y-1)
+					else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y-1)
 					{
 						pn = 8;
 					}
-					else if(cv[i-1].x == cv[i].x+1 && cv[i-1].y == cv[i].y+1)
+					else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y+1)
 					{
 						pn = 20;
 					}
 				}
-				else if (cv[i+1].x == cv[i].x-1 && cv[i+1].y == cv[i].y)
+				else if (cv[i+1].coord.x == cv[i].coord.x-1 && cv[i+1].coord.y == cv[i].coord.y)
 				{
-					if(cv[i-1].x == cv[i].x+1 && cv[i-1].y == cv[i].y-1)
+					if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y-1)
 					{
 						pn = 2;
 					}
-					else if(cv[i-1].x == cv[i].x+1 && cv[i-1].y == cv[i].y)
+					else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y)
 					{
 						pn = 11;
 					}
-					else if(cv[i-1].x == cv[i].x+1 && cv[i-1].y == cv[i].y+1)
+					else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y+1)
 					{
 						pn = 20;
 					}
@@ -756,8 +783,8 @@ void CTerrainRect::show()
 			}
 			if (pn>=0)
 			{				
-				int x = 32*(currentPath->nodes[i].x-LOCPLINT->adventureInt->position.x)+7,
-					y = 32*(currentPath->nodes[i].y-LOCPLINT->adventureInt->position.y)+6;
+				int x = 32*(currentPath->nodes[i].coord.x-LOCPLINT->adventureInt->position.x)+7,
+					y = 32*(currentPath->nodes[i].coord.y-LOCPLINT->adventureInt->position.y)+6;
 				if (x<0 || y<0 || x>pos.w || y>pos.h)
 					continue;
 				int hvx = (x+arrows->ourImages[pn].bitmap->w)-(pos.x+pos.w),
@@ -967,6 +994,7 @@ void CAdvMapInt::show()
 	heroList.draw();
 	townList.activate();
 	townList.draw();
+	terrain.activate();
 
 	resdatabar.draw();
 

+ 3 - 1
CAdvmapInterface.h

@@ -144,7 +144,8 @@ public:
 	void deactivate(); // makes button inactive (but don't deletes)
 };
 class CTerrainRect
-	:  public ClickableL, public ClickableR, public Hoverable, public virtual CIntObject, public KeyInterested
+	:  public ClickableL, public ClickableR, public Hoverable, public virtual CIntObject, public KeyInterested,
+	public MotionInterested
 {
 public:
 	int tilesw, tilesh;
@@ -156,6 +157,7 @@ public:
 	void clickLeft(tribool down);
 	void clickRight(tribool down);
 	void hover(bool on);
+	void mouseMoved (SDL_MouseMotionEvent & sEvent);
 	void keyPressed (SDL_KeyboardEvent & key);
 	void show();
 };

+ 2 - 2
CCallback.cpp

@@ -25,8 +25,8 @@ bool CCallback::moveHero(int ID, int3 destPoint)
 	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);
+		stpos = int3(ourPath->nodes[i].coord.x, ourPath->nodes[i].coord.y, CGI->heroh->heroInstances[ID]->pos.z);
+		endpos = int3(ourPath->nodes[i-1].coord.x, ourPath->nodes[i-1].coord.y, CGI->heroh->heroInstances[ID]->pos.z);
 		HeroMoveDetails curd;
 		curd.src = stpos;
 		curd.dst = endpos;

+ 46 - 36
CPathfinder.cpp

@@ -4,7 +4,16 @@
 #include "CGameInfo.h"
 #include "hch\CAmbarCendamo.h"
 #include "mapHandler.h"
-CPath * CPathfinder::getPath(int3 &src, int3 &dest, CHeroInstance * hero) //TODO: test it (seems to be finished, but relies on unwritten functions :()
+int3 CPath::startPos()
+{
+	return int3(nodes[0].coord.x,nodes[0].coord.y,nodes[0].coord.z);
+}
+int3 CPath::endPos()
+{
+	return int3(nodes[nodes.size()-1].coord.x,nodes[nodes.size()-1].coord.y,nodes[nodes.size()-1].coord.z);
+}
+
+CPath * CPathfinder::getPath(const int3 &src, const int3 &dest, const CHeroInstance * hero) //TODO: test it (seems to be finished, but relies on unwritten functions :()
 {
 	if(src.z!=dest.z) //first check
 		return NULL;
@@ -23,8 +32,9 @@ CPath * CPathfinder::getPath(int3 &src, int3 &dest, CHeroInstance * hero) //TODO
 			graph[i][j]->dist = -1;
 			graph[i][j]->theNodeBefore = NULL;
 			graph[i][j]->visited = false;
-			graph[i][j]->x = i;
-			graph[i][j]->y = j;
+			graph[i][j]->coord.x = i;
+			graph[i][j]->coord.y = j;
+			graph[i][j]->coord.z = dest.z;
 		}
 	}
 
@@ -41,7 +51,7 @@ CPath * CPathfinder::getPath(int3 &src, int3 &dest, CHeroInstance * hero) //TODO
 	{
 		CPathNode * cp = mq.front();
 		mq.pop();
-		if ((cp->x == dest.x) && (cp->y==dest.y))
+		if ((cp->coord.x == dest.x) && (cp->coord.y==dest.y))
 		{
 			if (cp->dist < curDist)
 				curDist=cp->dist;
@@ -51,82 +61,82 @@ CPath * CPathfinder::getPath(int3 &src, int3 &dest, CHeroInstance * hero) //TODO
 			if (cp->dist > curDist)
 				continue;
 		}
-		if(cp->x>0)
+		if(cp->coord.x>0)
 		{
-			CPathNode * dp = graph[cp->x-1][cp->y];
-			if((dp->dist==-1 || (dp->dist > cp->dist + CGI->mh->getCost(int3(cp->x, cp->y, src.z), int3(cp->x-1, cp->y, src.z), hero))) && dp->accesible)
+			CPathNode * dp = graph[cp->coord.x-1][cp->coord.y];
+			if((dp->dist==-1 || (dp->dist > cp->dist + CGI->mh->getCost(int3(cp->coord.x, cp->coord.y, src.z), int3(cp->coord.x-1, cp->coord.y, src.z), hero))) && dp->accesible)
 			{
-				dp->dist = cp->dist + CGI->mh->getCost(int3(cp->x, cp->y, src.z), int3(cp->x-1, cp->y, src.z), hero);
+				dp->dist = cp->dist + CGI->mh->getCost(int3(cp->coord.x, cp->coord.y, src.z), int3(cp->coord.x-1, cp->coord.y, src.z), hero);
 				dp->theNodeBefore = cp;
 				mq.push(dp);
 			}
 		}
-		if(cp->y>0)
+		if(cp->coord.y>0)
 		{
-			CPathNode * dp = graph[cp->x][cp->y-1];
-			if((dp->dist==-1 || (dp->dist > cp->dist + CGI->mh->getCost(int3(cp->x, cp->y, src.z), int3(cp->x, cp->y-1, src.z), hero))) && dp->accesible)
+			CPathNode * dp = graph[cp->coord.x][cp->coord.y-1];
+			if((dp->dist==-1 || (dp->dist > cp->dist + CGI->mh->getCost(int3(cp->coord.x, cp->coord.y, src.z), int3(cp->coord.x, cp->coord.y-1, src.z), hero))) && dp->accesible)
 			{
-				dp->dist = cp->dist + CGI->mh->getCost(int3(cp->x, cp->y, src.z), int3(cp->x-1, cp->y, src.z), hero);
+				dp->dist = cp->dist + CGI->mh->getCost(int3(cp->coord.x, cp->coord.y, src.z), int3(cp->coord.x-1, cp->coord.y, src.z), hero);
 				dp->theNodeBefore = cp;
 				mq.push(dp);
 			}
 		}
-		if(cp->x>0 && cp->y>0)
+		if(cp->coord.x>0 && cp->coord.y>0)
 		{
-			CPathNode * dp = graph[cp->x-1][cp->y-1];
-			if((dp->dist==-1 || (dp->dist > cp->dist + CGI->mh->getCost(int3(cp->x, cp->y, src.z), int3(cp->x-1, cp->y-1, src.z), hero))) && dp->accesible)
+			CPathNode * dp = graph[cp->coord.x-1][cp->coord.y-1];
+			if((dp->dist==-1 || (dp->dist > cp->dist + CGI->mh->getCost(int3(cp->coord.x, cp->coord.y, src.z), int3(cp->coord.x-1, cp->coord.y-1, src.z), hero))) && dp->accesible)
 			{
-				dp->dist = cp->dist + CGI->mh->getCost(int3(cp->x, cp->y, src.z), int3(cp->x-1, cp->y-1, src.z), hero);
+				dp->dist = cp->dist + CGI->mh->getCost(int3(cp->coord.x, cp->coord.y, src.z), int3(cp->coord.x-1, cp->coord.y-1, src.z), hero);
 				dp->theNodeBefore = cp;
 				mq.push(dp);
 			}
 		}
-		if(cp->x<graph.size()-1)
+		if(cp->coord.x<graph.size()-1)
 		{
-			CPathNode * dp = graph[cp->x+1][cp->y];
-			if((dp->dist==-1 || (dp->dist > cp->dist + CGI->mh->getCost(int3(cp->x, cp->y, src.z), int3(cp->x+1, cp->y, src.z), hero))) && dp->accesible)
+			CPathNode * dp = graph[cp->coord.x+1][cp->coord.y];
+			if((dp->dist==-1 || (dp->dist > cp->dist + CGI->mh->getCost(int3(cp->coord.x, cp->coord.y, src.z), int3(cp->coord.x+1, cp->coord.y, src.z), hero))) && dp->accesible)
 			{
-				dp->dist = cp->dist + CGI->mh->getCost(int3(cp->x, cp->y, src.z), int3(cp->x+1, cp->y, src.z), hero);
+				dp->dist = cp->dist + CGI->mh->getCost(int3(cp->coord.x, cp->coord.y, src.z), int3(cp->coord.x+1, cp->coord.y, src.z), hero);
 				dp->theNodeBefore = cp;
 				mq.push(dp);
 			}
 		}
-		if(cp->y<graph[0].size()-1)
+		if(cp->coord.y<graph[0].size()-1)
 		{
-			CPathNode * dp = graph[cp->x][cp->y+1];
-			if((dp->dist==-1 || (dp->dist > cp->dist + CGI->mh->getCost(int3(cp->x, cp->y, src.z), int3(cp->x, cp->y+1, src.z), hero))) && dp->accesible)
+			CPathNode * dp = graph[cp->coord.x][cp->coord.y+1];
+			if((dp->dist==-1 || (dp->dist > cp->dist + CGI->mh->getCost(int3(cp->coord.x, cp->coord.y, src.z), int3(cp->coord.x, cp->coord.y+1, src.z), hero))) && dp->accesible)
 			{
-				dp->dist = cp->dist + CGI->mh->getCost(int3(cp->x, cp->y, src.z), int3(cp->x, cp->y+1, src.z), hero);
+				dp->dist = cp->dist + CGI->mh->getCost(int3(cp->coord.x, cp->coord.y, src.z), int3(cp->coord.x, cp->coord.y+1, src.z), hero);
 				dp->theNodeBefore = cp;
 				mq.push(dp);
 			}
 		}
-		if(cp->x<graph.size()-1 && cp->y<graph[0].size()-1)
+		if(cp->coord.x<graph.size()-1 && cp->coord.y<graph[0].size()-1)
 		{
-			CPathNode * dp = graph[cp->x+1][cp->y+1];
-			if((dp->dist==-1 || (dp->dist > cp->dist + CGI->mh->getCost(int3(cp->x, cp->y, src.z), int3(cp->x+1, cp->y+1, src.z), hero))) && dp->accesible)
+			CPathNode * dp = graph[cp->coord.x+1][cp->coord.y+1];
+			if((dp->dist==-1 || (dp->dist > cp->dist + CGI->mh->getCost(int3(cp->coord.x, cp->coord.y, src.z), int3(cp->coord.x+1, cp->coord.y+1, src.z), hero))) && dp->accesible)
 			{
-				dp->dist = cp->dist + CGI->mh->getCost(int3(cp->x, cp->y, src.z), int3(cp->x+1, cp->y+1, src.z), hero);
+				dp->dist = cp->dist + CGI->mh->getCost(int3(cp->coord.x, cp->coord.y, src.z), int3(cp->coord.x+1, cp->coord.y+1, src.z), hero);
 				dp->theNodeBefore = cp;
 				mq.push(dp);
 			}
 		}
-		if(cp->x>0 && cp->y<graph[0].size()-1)
+		if(cp->coord.x>0 && cp->coord.y<graph[0].size()-1)
 		{
-			CPathNode * dp = graph[cp->x-1][cp->y+1];
-			if((dp->dist==-1 || (dp->dist > cp->dist + CGI->mh->getCost(int3(cp->x, cp->y, src.z), int3(cp->x-1, cp->y+1, src.z), hero))) && dp->accesible)
+			CPathNode * dp = graph[cp->coord.x-1][cp->coord.y+1];
+			if((dp->dist==-1 || (dp->dist > cp->dist + CGI->mh->getCost(int3(cp->coord.x, cp->coord.y, src.z), int3(cp->coord.x-1, cp->coord.y+1, src.z), hero))) && dp->accesible)
 			{
-				dp->dist = cp->dist + CGI->mh->getCost(int3(cp->x, cp->y, src.z), int3(cp->x-1, cp->y+1, src.z), hero);
+				dp->dist = cp->dist + CGI->mh->getCost(int3(cp->coord.x, cp->coord.y, src.z), int3(cp->coord.x-1, cp->coord.y+1, src.z), hero);
 				dp->theNodeBefore = cp;
 				mq.push(dp);
 			}
 		}
-		if(cp->x<graph.size()-1 && cp->y>0)
+		if(cp->coord.x<graph.size()-1 && cp->coord.y>0)
 		{
-			CPathNode * dp = graph[cp->x+1][cp->y-1];
-			if((dp->dist==-1 || (dp->dist > cp->dist + CGI->mh->getCost(int3(cp->x, cp->y, src.z), int3(cp->x+1, cp->y-1, src.z), hero))) && dp->accesible)
+			CPathNode * dp = graph[cp->coord.x+1][cp->coord.y-1];
+			if((dp->dist==-1 || (dp->dist > cp->dist + CGI->mh->getCost(int3(cp->coord.x, cp->coord.y, src.z), int3(cp->coord.x+1, cp->coord.y-1, src.z), hero))) && dp->accesible)
 			{
-				dp->dist = cp->dist + CGI->mh->getCost(int3(cp->x, cp->y, src.z), int3(cp->x+1, cp->y-1, src.z), hero);
+				dp->dist = cp->dist + CGI->mh->getCost(int3(cp->coord.x, cp->coord.y, src.z), int3(cp->coord.x+1, cp->coord.y-1, src.z), hero);
 				dp->theNodeBefore = cp;
 				mq.push(dp);
 			}

+ 6 - 3
CPathfinder.h

@@ -9,13 +9,16 @@ struct CPathNode
 	bool accesible; //true if a hero can be on this node
 	int dist; //distance from the first node of searching; -1 is infinity
 	CPathNode * theNodeBefore;
-	int x, y; //coordiantes
+	int3 coord; //coordiantes
 	bool visited;
 };
 
 struct CPath
 {
 	std::vector<CPathNode> nodes; //just get node by node
+
+	int3 startPos(); // start point
+	int3 endPos(); //destination point
 };
 
 /**
@@ -26,8 +29,8 @@ class CPathfinder
 private:
 	std::vector< std::vector<CPathNode *> > graph;
 public:
-	CPath * getPath(int3 & src, int3 & dest, CHeroInstance * hero); //calculates path between src and dest; returns pointer to CPath or NULL if path does not exists
-	CPath * getPath(int3 & src, int3 & dest, CHeroInstance * hero, int (*getDist)(int3 & a, int3 & b)); //calculates path between src and dest; returns pointer to CPath or NULL if path does not exists; uses getDist to calculate distance
+	CPath * getPath(const int3 & src, const int3 & dest, const CHeroInstance * hero); //calculates path between src and dest; returns pointer to CPath or NULL if path does not exists
+	CPath * getPath(const int3 & src, const int3 & dest, const CHeroInstance * hero, int (*getDist)(int3 & a, int3 & b)); //calculates path between src and dest; returns pointer to CPath or NULL if path does not exists; uses getDist to calculate distance
 };
 
 #endif //CPATHFINDER_H

+ 1 - 1
mapHandler.cpp

@@ -937,7 +937,7 @@ char & CMapHandler::undVisAccess(int x, int y)
 	return undVisibility[x+Woff][y+Hoff];
 }
 
-int CMapHandler::getCost(int3 &a, int3 &b, CHeroInstance *hero)
+int CMapHandler::getCost(int3 &a, int3 &b, const CHeroInstance *hero)
 {
 	int ret = hero->type->heroClass->terrCosts[CGI->mh->ttiles[a.x][a.y][a.z].malle];
 	if(!(a.x==b.x || a.y==b.y))

+ 1 - 1
mapHandler.h

@@ -76,7 +76,7 @@ public:
 	SDL_Surface mirrorImage(SDL_Surface *src); //what is this??
 	SDL_Surface * getVisBitmap(int x, int y, std::vector< std::vector<char> > & visibility);
 
-	int getCost(int3 & a, int3 & b, CHeroInstance * hero);
+	int getCost(int3 & a, int3 & b, const CHeroInstance * hero);
 	void init();
 	SDL_Surface * terrainRect(int x, int y, int dx, int dy, int level=0, unsigned char anim=0);
 	SDL_Surface * terrBitmap(int x, int y);