mirror of
https://github.com/vcmi/vcmi.git
synced 2025-02-03 13:01:33 +02:00
small helpful function
This commit is contained in:
parent
a997c41f5c
commit
3844c45441
@ -1644,3 +1644,42 @@ void CMapHandler::validateRectTerr(SDL_Rect * val, const SDL_Rect * ext)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
unsigned char CMapHandler::getDir(const int3 &a, const int3 &b)
|
||||
{
|
||||
if(a.z!=b.z)
|
||||
return -1; //error!
|
||||
if(a.x==b.x+1 && a.y==b.y+1) //lt
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else if(a.x==b.x && a.y==b.y+1) //t
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else if(a.x==b.x-1 && a.y==b.y+1) //rt
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
else if(a.x==b.x-1 && a.y==b.y) //r
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
else if(a.x==b.x-1 && a.y==b.y-1) //rb
|
||||
{
|
||||
return 4;
|
||||
}
|
||||
else if(a.x==b.x && a.y==b.y-1) //b
|
||||
{
|
||||
return 5;
|
||||
}
|
||||
else if(a.x==b.x+1 && a.y==b.y-1) //lb
|
||||
{
|
||||
return 6;
|
||||
}
|
||||
else if(a.x==b.x+1 && a.y==b.y) //l
|
||||
{
|
||||
return 7;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -108,6 +108,7 @@ public:
|
||||
std::string getRandomizedDefName(CGDefInfo* di, CGObjectInstance * obj = NULL); //objinstance needed only for heroes and towns
|
||||
unsigned char getHeroFrameNum(const unsigned char & dir, const bool & isMoving) const; //terrainRect helper function
|
||||
void validateRectTerr(SDL_Rect * val, const SDL_Rect * ext); //terrainRect helper
|
||||
static unsigned char getDir(const int3 & a, const int3 & b); //returns direction number in range 0 - 7 (0 is left top, clockwise) [direction: form a to b]
|
||||
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user