寻路基本工具类定义 AIDefine.h
1 #ifndef __AIDEFINE__H 2 #define __AIDEFINE__H 3 4 #include <math.h> 5 #include "../Common/Path.h" 6 7 #define MATH_SQRT2 1.4142135623731f 8 enum EFindType 9 { 10 EFIND_TYPE4 = 4,//must be 4 11 EFIND_TYPE8 = 8//must be 8 12 }; 13 extern PointI AI_FindHelpPoint[8]; 14 typedef float (*AI_DitanceFun)(int,int,int,int); 15 typedef bool (*AI_VisitFun)(int,int); 16 inline int AI_ABS(int data){return data >= 0?data:-data;} 17 inline float AI_ABS(float data){return data >= 0?data:-data;} 18 inline float AI_Ditance1(int x1, int y1, int x2, int y2) 19 { 20 if(x1 == x2 || y1 == y2){return 1;} 21 return MATH_SQRT2; 22 } 23 inline float AI_Ditance2(int x1, int y1, int x2, int y2) 24 { 25 return (float)sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)); 26 } 27 inline bool AI_CheckVisit(int x,int y,const PointI &size,bool(*visit)(int,int)) 28 { 29 if(x < 0 || y < 0 || x >= size.x || y >= size.y){return false;} 30 return visit(x,y); 31 } 32 inline bool AI_CheckPass(int x1,int y1,int x2,int y2,AI_VisitFun visit) 33 { 34 if(0 != (x1 - x2) * (y1 - y2)) 35 { 36 return visit(x2, y2) && (visit(x2, y1) && visit(x1, y2)); 37 } 38 return visit(x2, y2); 39 } 40 inline bool AI_CheckPass(const PointI &p1, const PointI &p2, AI_VisitFun visit) 41 { 42 return AI_CheckPass(p1.x, p1.y, p2.x, p2.y, visit); 43 } 44 inline bool AI_CheckRange(const PointI &p, const PointI &size) 45 { 46 return !(p.x < 0 || p.y < 0 || p.x >= size.x || p.y >= size.y); 47 } 48 49 #endif