Ver código fonte

* fixed some issues with hero moving; actualizing hero position is still broken :(

mateuszb 18 anos atrás
pai
commit
d530bd057d
6 arquivos alterados com 19 adições e 12 exclusões
  1. 4 2
      CAdvmapInterface.cpp
  2. 2 2
      CCallback.cpp
  3. 1 1
      CCallback.h
  4. 1 0
      CGameInterface.cpp
  5. 9 5
      CPathfinder.cpp
  6. 2 2
      CPathfinder.h

+ 4 - 2
CAdvmapInterface.cpp

@@ -598,7 +598,7 @@ void CTerrainRect::clickLeft(tribool down)
 	{
 		if ( (currentPath->endPos()) == mp)
 		{ //move
-			LOCPLINT->cb->moveHero(0,currentPath->endPos());//todo - move selected hero
+			LOCPLINT->cb->moveHero(0,currentPath->endPos(), 1);//todo - move selected hero
 			return;
 		}
 		else
@@ -608,7 +608,9 @@ void CTerrainRect::clickLeft(tribool down)
 		}
 	}
 	const CHeroInstance * currentHero = LOCPLINT->adventureInt->heroList.items[LOCPLINT->adventureInt->heroList.selected].first;
-	currentPath = LOCPLINT->adventureInt->heroList.items[LOCPLINT->adventureInt->heroList.selected].second = CGI->pathf->getPath(currentHero->pos,mp,currentHero);
+	int3 bufpos = currentHero->pos;
+	//bufpos.x-=1;
+	currentPath = LOCPLINT->adventureInt->heroList.items[LOCPLINT->adventureInt->heroList.selected].second = CGI->pathf->getPath(bufpos,mp,currentHero,1);
 }
 void CTerrainRect::clickRight(tribool down)
 {

+ 2 - 2
CCallback.cpp

@@ -40,7 +40,7 @@ void CCallback::newTurn()
 		}
 	}
 }
-bool CCallback::moveHero(int ID, int3 destPoint, int idtype)
+bool CCallback::moveHero(int ID, int3 destPoint, int idtype, unsigned char posType)
 {
 	if(ID<0 || ID>CGI->heroh->heroInstances.size())
 		return false;
@@ -50,7 +50,7 @@ bool CCallback::moveHero(int ID, int3 destPoint, int idtype)
 		return false;
 	if(destPoint.z<0 || destPoint.z>CGI->mh->ttiles[0][0].size()-1)
 		return false;
-	CPath * ourPath = CGI->pathf->getPath(CGI->heroh->heroInstances[ID]->pos, destPoint, CGI->heroh->heroInstances[ID]);
+	CPath * ourPath = CGI->pathf->getPath(CGI->heroh->heroInstances[ID]->pos, destPoint, CGI->heroh->heroInstances[ID], posType);
 	if(!ourPath)
 		return false;
 	for(int i=ourPath->nodes.size()-1; i>0; i--)

+ 1 - 1
CCallback.h

@@ -22,7 +22,7 @@ protected:
 	int player;
 
 public:
-	bool moveHero(int ID, int3 destPoint, int idtype=0);//idtype: 0-position in vector; 1-ID of hero 
+	bool moveHero(int ID, int3 destPoint, int idtype=0, unsigned char posType=0);//idtype: 0-position in vector; 1-ID of hero 
 
 	int howManyTowns();
 	const CTownInstance * getTownInfo(int val, bool mode); //mode = 0 -> val = serial; mode = 1 -> val = ID

+ 1 - 0
CGameInterface.cpp

@@ -673,6 +673,7 @@ void CPlayerInterface::heroMoved(const HeroMoveDetails & details)
 		}
 		LOCPLINT->adventureInt->update(); //updating screen
 		CGI->screenh->updateScreen();
+		LOCPLINT->adventureInt->anim++;
 		SDL_framerateDelay(mainFPSmng); //for animation purposes
 	} //for(int i=1; i<32; i+=4)
 	//main moving done

+ 9 - 5
CPathfinder.cpp

@@ -4,19 +4,23 @@
 #include "CGameInfo.h"
 #include "hch\CAmbarCendamo.h"
 #include "mapHandler.h"
-int3 CPath::endPos()
-{
-	return int3(nodes[0].coord.x,nodes[0].coord.y,nodes[0].coord.z);
-}
 int3 CPath::startPos()
 {
 	return int3(nodes[nodes.size()-1].coord.x,nodes[nodes.size()-1].coord.y,nodes[nodes.size()-1].coord.z);
 }
+int3 CPath::endPos()
+{
+	return int3(nodes[0].coord.x,nodes[0].coord.y,nodes[0].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 :()
+CPath * CPathfinder::getPath(int3 src, int3 dest, const CHeroInstance * hero, unsigned char type) //TODO: test it (seems to be finished, but relies on unwritten functions :()
 {
 	if(src.z!=dest.z) //first check
 		return NULL;
+	if(type==1) //calibrating
+	{
+		src.x-=1;
+	}
 
 	//graph initialization
 	graph.resize(CGI->ac->map.width);

+ 2 - 2
CPathfinder.h

@@ -29,8 +29,8 @@ class CPathfinder
 private:
 	std::vector< std::vector<CPathNode *> > graph;
 public:
-	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
+	CPath * getPath(int3 src, int3 dest, const CHeroInstance * hero, unsigned char type=0); //calculates path between src and dest; returns pointer to CPath or NULL if path does not exists; type - type of calculation: 0 - positions are normal positions of hero; 1 - given places are tiles blocked by hero
+	CPath * getPath(const int3 & src, const int3 & dest, const CHeroInstance * hero, int (*getDist)(int3 & a, int3 & b), unsigned char type=0); //calculates path between src and dest; returns pointer to CPath or NULL if path does not exists; uses getDist to calculate distance; type - type of calculation: 0 - positions are normal positions of hero; 1 - given places are tiles blocked by hero
 };
 
 #endif //CPATHFINDER_H