Browse Source

small helpful function

mateuszb 17 years ago
parent
commit
3844c45441
2 changed files with 40 additions and 0 deletions
  1. 39 0
      mapHandler.cpp
  2. 1 0
      mapHandler.h

+ 39 - 0
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;
+	}
+
+}

+ 1 - 0
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]
 
 };