1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-03-21 21:17:49 +02:00

* sprites from /Sprites folder are handled correctly now

* fixed pathfinder and path arrows
* clicking on a tile in advmap view when a path is shown will not only hide it but also calculate a new one
This commit is contained in:
mateuszb 2008-10-03 15:15:23 +00:00
parent 56ecd03b61
commit b08b29d0d8
5 changed files with 76 additions and 47 deletions

View File

@ -403,7 +403,6 @@ endchkpt:
currentPath=NULL; currentPath=NULL;
LOCPLINT->adventureInt->heroList.items[LOCPLINT->adventureInt->heroList.getPosOfHero(LOCPLINT->adventureInt->selection)].second = NULL; LOCPLINT->adventureInt->heroList.items[LOCPLINT->adventureInt->heroList.getPosOfHero(LOCPLINT->adventureInt->selection)].second = NULL;
} }
return;
} }
const CGHeroInstance * currentHero = (LOCPLINT->adventureInt->heroList.items.size())?(LOCPLINT->adventureInt->heroList.items[LOCPLINT->adventureInt->heroList.selected].first):(NULL); const CGHeroInstance * currentHero = (LOCPLINT->adventureInt->heroList.items.size())?(LOCPLINT->adventureInt->heroList.items[LOCPLINT->adventureInt->heroList.selected].first):(NULL);
if(currentHero) if(currentHero)
@ -488,62 +487,77 @@ void CTerrainRect::showPath()
} }
else else
{ {
/*
* notation of arrow direction:
* 1 2 3
* 4 5 6
* 7 8 9
* ie. 157 means an arrow from left upper tile to left bottom tile through 5 (all arrows go through 5 in this notation)
*/
std::vector<CPathNode> & cv = currentPath->nodes; std::vector<CPathNode> & cv = currentPath->nodes;
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].coord.x == cv[i].coord.x-1 && cv[i+1].coord.y == cv[i].coord.y-1) //15x
{ {
if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y) if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y) //156
{ {
pn = 3; pn = 3;
} }
else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y+1) else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y+1) //159
{ {
pn = 12; pn = 12;
} }
else if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y+1) else if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y+1) //158
{ {
pn = 21; pn = 21;
} }
else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y+1) else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y+1) //157
{ {
pn = 22; pn = 22;
} }
else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y-1) else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y-1) //153
{ {
pn = 2; pn = 2;
} }
} else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y) //154
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].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y-1)
{
pn = 2;
}
if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y)
{
pn = 3;
}
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].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y+1)
{
pn = 13;
}
else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y+1)
{
pn = 22;
}
if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y)
{ {
pn = 23; pn = 23;
} }
if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y-1) else if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y-1) //152
{
pn = 1;
}
}
else if (cv[i+1].coord.x == cv[i].coord.x && cv[i+1].coord.y == cv[i].coord.y-1) //25x
{
if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y-1) //253
{
pn = 2;
}
if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y) //256
{
pn = 3;
}
if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y+1) //259
{
pn = 4;
}
else if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y+1) //258
{
pn = 13;
}
else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y+1) //257
{
pn = 22;
}
if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y) //254
{
pn = 23;
}
if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y-1) //251
{ {
pn = 24; pn = 24;
} }
} }
else if (cv[i+1].coord.x == cv[i].coord.x+1 && cv[i+1].coord.y == cv[i].coord.y-1) else if (cv[i+1].coord.x == cv[i].coord.x+1 && cv[i+1].coord.y == cv[i].coord.y-1) //35x
{ {
if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y+1) if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y+1)
{ {
@ -566,7 +580,7 @@ void CTerrainRect::showPath()
pn = 4; pn = 4;
} }
} }
else if (cv[i+1].coord.x == cv[i].coord.x+1 && cv[i+1].coord.y == cv[i].coord.y) else if (cv[i+1].coord.x == cv[i].coord.x+1 && cv[i+1].coord.y == cv[i].coord.y) //65x
{ {
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].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y+1)
{ {
@ -581,7 +595,7 @@ void CTerrainRect::showPath()
pn = 24; pn = 24;
} }
} }
else if (cv[i+1].coord.x == cv[i].coord.x+1 && cv[i+1].coord.y == cv[i].coord.y+1) else if (cv[i+1].coord.x == cv[i].coord.x+1 && cv[i+1].coord.y == cv[i].coord.y+1) //95x
{ {
if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y) if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y)
{ {
@ -604,7 +618,7 @@ void CTerrainRect::showPath()
pn = 18; pn = 18;
} }
} }
else if (cv[i+1].coord.x == cv[i].coord.x && cv[i+1].coord.y == cv[i].coord.y+1) else if (cv[i+1].coord.x == cv[i].coord.x && cv[i+1].coord.y == cv[i].coord.y+1) //85x
{ {
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].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y+1)
{ {
@ -635,7 +649,7 @@ void CTerrainRect::showPath()
pn = 20; pn = 20;
} }
} }
else if (cv[i+1].coord.x == cv[i].coord.x-1 && cv[i+1].coord.y == cv[i].coord.y+1) else if (cv[i+1].coord.x == cv[i].coord.x-1 && cv[i+1].coord.y == cv[i].coord.y+1) //75x
{ {
if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y-1) if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y-1)
{ {
@ -658,7 +672,7 @@ void CTerrainRect::showPath()
pn = 20; pn = 20;
} }
} }
else if (cv[i+1].coord.x == cv[i].coord.x-1 && cv[i+1].coord.y == cv[i].coord.y) else if (cv[i+1].coord.x == cv[i].coord.x-1 && cv[i+1].coord.y == cv[i].coord.y) //45x
{ {
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].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y-1)
{ {

View File

@ -157,7 +157,7 @@ void CPathfinder::AddNeighbors(vector<Coordinate>* branch)
{ {
for(int j = node.y-1; j < node.y+2; j++) for(int j = node.y-1; j < node.y+2; j++)
{ {
if(i >= 0 && j >= 0 && i < CGI->mh->sizes.x && j < CGI->mh->sizes.y) if(i >= 0 && j >= 0 && i < CGI->mh->sizes.x && j < CGI->mh->sizes.y && (i!=node.x || j!=node.y))
{ {
c = Coordinate(i,j,node.z); c = Coordinate(i,j,node.z);
@ -167,6 +167,11 @@ void CPathfinder::AddNeighbors(vector<Coordinate>* branch)
//Calculate the movement cost //Calculate the movement cost
CalcH(&c); CalcH(&c);
if(i!=node.x && j!=node.y)
c.diagonal = true;
else
c.diagonal = false;
if(c.g != -1 && c.h != -1) if(c.g != -1 && c.h != -1)
{ {
bool pass = true; //checking for allowed visiting direction bool pass = true; //checking for allowed visiting direction
@ -255,7 +260,6 @@ void CPathfinder::AddNeighbors(vector<Coordinate>* branch)
Open.push(toAdd); Open.push(toAdd);
} }
} }
//delete c;
} }
} }
} }
@ -401,11 +405,17 @@ bool Compare::operator()(const vector<Coordinate>& a, const vector<Coordinate>&
for(int i = 0; i < a.size(); i++) for(int i = 0; i < a.size(); i++)
{ {
aTotal += a[i].g*a[i].h; double add = a[i].g*a[i].h;
if(a[i].diagonal)
add*=1.41421356;
aTotal += add;
} }
for(int i = 0; i < b.size(); i++) for(int i = 0; i < b.size(); i++)
{ {
bTotal += b[i].g*b[i].h; double add = b[i].g*b[i].h;
if(b[i].diagonal)
add*=1.41421356;
bTotal += add;
} }
return aTotal > bTotal; return aTotal > bTotal;
@ -418,4 +428,5 @@ void Coordinate::operator =(const Coordinate &other)
this->z = other.z; this->z = other.z;
this->g = other.g; this->g = other.g;
this->h = other.h; this->h = other.h;
this->diagonal = other.diagonal;
} }

View File

@ -16,11 +16,12 @@ public:
int z; int z;
float g; //Distance from goal float g; //Distance from goal
int h; //Movement cost int h; //Movement cost
bool diagonal; //if true, this tile will be crossed by diagonal
Coordinate() : x(NULL), y(NULL), z(NULL), g(NULL), h(NULL) {} Coordinate() : x(NULL), y(NULL), z(NULL), g(NULL), h(NULL), diagonal(false) {}
Coordinate(int3 xyz) : x(xyz.x), y(xyz.y), z(xyz.z){} Coordinate(int3 xyz) : x(xyz.x), y(xyz.y), z(xyz.z), diagonal(false){}
Coordinate(int xCor, int yCor, int zCor) : x(xCor), y(yCor), z(zCor){} Coordinate(int xCor, int yCor, int zCor) : x(xCor), y(yCor), z(zCor), diagonal(false){}
Coordinate(int xCor, int yCor, int zCor, int dist, int penalty) : x(xCor), y(yCor), z(zCor), g(dist), h(penalty){} Coordinate(int xCor, int yCor, int zCor, int dist, int penalty) : x(xCor), y(yCor), z(zCor), g(dist), h(penalty), diagonal(false){}
void operator=(const Coordinate& other); void operator=(const Coordinate& other);
}; };

View File

@ -42,7 +42,8 @@ unsigned char * CLodHandler::giveFile(std::string defName, int * length)
{ {
unsigned char * outp = new unsigned char[ourEntry->realSize]; unsigned char * outp = new unsigned char[ourEntry->realSize];
char name[30];memset(name,0,30); char name[30];memset(name,0,30);
strcat(name,"Data/"); strcat(name, myDir.c_str());
strcat(name, PATHSEPARATOR);
strcat(name,(char*)ourEntry->name); strcat(name,(char*)ourEntry->name);
FILE * f = fopen(name,"rb"); FILE * f = fopen(name,"rb");
int result = fread(outp,1,ourEntry->realSize,f); int result = fread(outp,1,ourEntry->realSize,f);
@ -327,6 +328,7 @@ int CLodHandler::readNormalNr (unsigned char* bufor, int bytCon, bool cyclic)
void CLodHandler::init(std::string lodFile, std::string dirName) void CLodHandler::init(std::string lodFile, std::string dirName)
{ {
myDir = dirName;
mutex = new boost::mutex; mutex = new boost::mutex;
std::string Ts; std::string Ts;
FLOD = fopen(lodFile.c_str(), "rb"); FLOD = fopen(lodFile.c_str(), "rb");

View File

@ -46,6 +46,7 @@ public:
nodrze<Entry> entries; nodrze<Entry> entries;
unsigned int totalFiles; unsigned int totalFiles;
boost::mutex *mutex; boost::mutex *mutex;
std::string myDir; //load files from this dir instead of .lod file
int readNormalNr (unsigned char* bufor, int bytCon, bool cyclic=false); //lod header reading helper int readNormalNr (unsigned char* bufor, int bytCon, bool cyclic=false); //lod header reading helper
int infs(unsigned char * in, int size, int realSize, std::ofstream & out, int wBits=15); //zlib fast handler int infs(unsigned char * in, int size, int realSize, std::ofstream & out, int wBits=15); //zlib fast handler