1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-24 03:47:18 +02:00

Better pathfinder - it's not fixed completely as arrows for move in adventure map aren't always in appropriate color but it's significantly better. I'm not also sure how this pathfinder deals with different costs of straight and diagonal costs of move through a tile.

This commit is contained in:
mateuszb 2008-06-03 14:44:09 +00:00
parent 25ab2e5d8b
commit 0b16616d7a
2 changed files with 17 additions and 23 deletions

View File

@ -132,9 +132,9 @@ bool CCallback::moveHero(int ID, CPath * path, int idtype, int pathType)
{
hero->pos = endpos;
}*/
if((hero->movement>=CGI->mh->getCost(stpos, endpos, hero)) || player==-1)
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)
{ //performing move
hero->movement-=CGI->mh->getCost(stpos, endpos, hero);
hero->movement-=CGI->mh->getCost(int3(stpos.x-1, stpos.y, stpos.z), int3(endpos.x-1, endpos.y, endpos.z), hero);
std::vector< CGObjectInstance * > vis = CGI->mh->getVisitableObjs(CGHeroInstance::convertPosition(curd.dst,false));
bool blockvis = false;

View File

@ -211,23 +211,10 @@ void CPathfinder::CalcH(Coordinate* node)
if(node->y>=CGI->mh->reader->map.height)
y = CGI->mh->reader->map.height-1;
//Get a copy of the hero we can work with. Cant use const Hero because method is not static.
CGHeroInstance* tempHero = new CGHeroInstance();
*tempHero = *Hero;
//Get the movement cost.
ret = tempHero->getTileCost(CGI->mh->ttiles[x][y][node->z].terType, CGI->mh->reader->map.terrain[x][y].malle,CGI->mh->reader->map.terrain[x][y].nuine);
//Is this right? This part of the code was stolen from getCost and I wasnt sure what parameters
//a and b represented. Seems to work though.
if(!(node->x==End.x || node->y==End.y))
ret*=1.41421;
delete tempHero;
ret = Hero->getTileCost(CGI->mh->ttiles[x][y][node->z].terType, CGI->mh->reader->map.terrain[x][y].malle,CGI->mh->reader->map.terrain[x][y].nuine);
node->h = ret;
return;
}
/*
@ -251,11 +238,12 @@ CPath* CPathfinder::ConvertToOldFormat(vector<Coordinate>* p)
CPath* path = new CPath();
vector<CPathNode> pNodes;
for(int i = 0; i < p->size(); i++)
{
CPathNode temp;
//Set coord
temp.coord = int3(p->at(i).x,p->at(i).y,p->at(i).z);
//Set accesible
if(p->at(i).h == -1)
@ -266,18 +254,24 @@ CPath* CPathfinder::ConvertToOldFormat(vector<Coordinate>* p)
{
temp.accesible = true;
}
//set diagonality
float diagonal = 1.0f; //by default
if(i+1<p->size())
{
if(p->at(i+1).x != temp.coord.x && p->at(i+1).y != temp.coord.y)
{
diagonal = sqrt(2.0f);
}
}
//Set distance
if(i == 0)
temp.dist = p->at(i).h;
temp.dist = p->at(i).h * diagonal;
else
temp.dist = p->at(i).h + path->nodes.back().dist;
temp.dist = p->at(i).h * diagonal + path->nodes.back().dist;
//theNodeBefore is never used outside of pathfinding?
//Set coord
temp.coord = int3(p->at(i).x,p->at(i).y,p->at(i).z);
//Set visited
temp.visited = false;