From 3844c45441d460af3d929ea620e62e68207eb0a6 Mon Sep 17 00:00:00 2001 From: mateuszb Date: Sun, 17 Feb 2008 19:04:27 +0000 Subject: [PATCH] small helpful function --- mapHandler.cpp | 39 +++++++++++++++++++++++++++++++++++++++ mapHandler.h | 1 + 2 files changed, 40 insertions(+) diff --git a/mapHandler.cpp b/mapHandler.cpp index 5b4643ff7..0bf0d7749 100644 --- a/mapHandler.cpp +++ b/mapHandler.cpp @@ -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; + } + +} diff --git a/mapHandler.h b/mapHandler.h index 69359602e..d830f28aa 100644 --- a/mapHandler.h +++ b/mapHandler.h @@ -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] };