Browse Source

* fixed pathfinder
* fixed problem with battles

mateuszb 17 years ago
parent
commit
bad05fee50
4 changed files with 13 additions and 12 deletions
  1. 1 1
      CBattleInterface.cpp
  2. 3 2
      CCallback.cpp
  3. 1 1
      CGameState.cpp
  4. 8 8
      CPathfinder.cpp

+ 1 - 1
CBattleInterface.cpp

@@ -212,7 +212,7 @@ void CBattleInterface::show(SDL_Surface * to)
 		}
 	}
 	//showing selected unit's range
-	if(creAnims[activeStack]->getType() != 0) //don't show if unit is moving
+	if(activeStack != -1 && creAnims[activeStack]->getType() != 0) //don't show if unit is moving
 	{
 		showRange(to, activeStack);
 	}

+ 3 - 2
CCallback.cpp

@@ -132,9 +132,10 @@ bool CCallback::moveHero(int ID, CPath * path, int idtype, int pathType)
 		{
 			hero->pos = endpos;
 		}*/
-		if((hero->movement>=CGI->mh->getCost(int3(stpos.x-1, stpos.y, stpos.z), int3(endpos.x-1, endpos.y, endpos.z), hero))  || player==-1)
+		if(hero->movement >= (ourPath->nodes.size()>=2 ?  (*(ourPath->nodes.end()-2)).dist : 0) - ourPath->nodes[i].dist  || player==-1)
 		{ //performing move
-			hero->movement-=CGI->mh->getCost(int3(stpos.x-1, stpos.y, stpos.z), int3(endpos.x-1, endpos.y, endpos.z), hero);
+			hero->movement -= (ourPath->nodes.size()>=2 ?  (*(ourPath->nodes.end()-2)).dist : 0) - ourPath->nodes[i].dist;
+			ourPath->nodes.pop_back();
 			
 			std::vector< CGObjectInstance * > vis = CGI->mh->getVisitableObjs(CGHeroInstance::convertPosition(curd.dst,false));
 			bool blockvis = false;

+ 1 - 1
CGameState.cpp

@@ -162,7 +162,7 @@ void CGameState::battle(CCreatureSet * army1, CCreatureSet * army2, int3 tile, C
 			else if(j->first == curB->side2) //player is defender
 				side = true;
 			else 
-				return; //no witnesses
+				continue; //no witnesses
 			if(CGI->playerint[j->second.serial]->human)
 			{
 				((CPlayerInterface*)( CGI->playerint[j->second.serial] ))->battleStart(army1, army2, tile, curB->hero1, curB->hero2, side);

+ 8 - 8
CPathfinder.cpp

@@ -149,29 +149,29 @@ void CPathfinder::AddNeighbors(vector<Coordinate>* branch)
 	//   6  7  8
 
 	Coordinate node = branch->back();
-	Coordinate* c;
+	Coordinate c;
 
 	for(int i = node.x-1; i<node.x+2;i++)
 	{
 		for(int j = node.y-1; j < node.y+2; j++)
 		{
-			if(i > 0 && j > 0 && i < CGI->mh->sizes.x-1 && j < CGI->mh->sizes.y-1)
+			if(i >= 0 && j >= 0 && i < CGI->mh->sizes.x && j < CGI->mh->sizes.y)
 			{
-				c = new Coordinate(i,j,node.z);
+				c = Coordinate(i,j,node.z);
 
 				//Calculate the distance from the end node
-				CalcG(c);
+				CalcG(&c);
 
 				//Calculate the movement cost
-				CalcH(c);
+				CalcH(&c);
 
-				if(c->g != -1 && c->h != -1)
+				if(c.g != -1 && c.h != -1)
 				{
 					vector<Coordinate> toAdd = *branch;
-					toAdd.push_back(*c);
+					toAdd.push_back(c);
 					Open.push(toAdd);
 				}
-				delete c;
+				//delete c;
 			}
 		}
 	}