فهرست منبع

Moved distance-related functions to path.c/h

git-svn-id: https://svn.code.sf.net/p/rathena/svn/trunk@11981 54d463be-8e91-2dee-dedb-b68131a5f0ec
ultramage 17 سال پیش
والد
کامیت
7906017662
11فایلهای تغییر یافته به همراه64 افزوده شده و 59 حذف شده
  1. 0 46
      src/map/map.c
  2. 0 11
      src/map/map.h
  3. 1 0
      src/map/mob.c
  4. 43 0
      src/map/path.c
  5. 12 0
      src/map/path.h
  6. 1 0
      src/map/pc.c
  7. 1 0
      src/map/pet.c
  8. 2 1
      src/map/script.c
  9. 2 1
      src/map/status.c
  10. 1 0
      src/map/trade.c
  11. 1 0
      src/map/vending.c

+ 0 - 46
src/map/map.c

@@ -177,52 +177,6 @@ int map_getusers(void)
 	return map_users;
 }
 
-//Distance functions, taken from http://www.flipcode.com/articles/article_fastdistance.shtml
-int check_distance(int dx, int dy, int distance)
-{
-#ifdef CIRCULAR_AREA
-	//In this case, we just do a square comparison. Add 1 tile grace for diagonal range checks.
-	return (dx*dx + dy*dy <= distance*distance + (dx&&dy?1:0));
-#else
-	if (dx < 0) dx = -dx;
-	if (dy < 0) dy = -dy;
-	return ((dx<dy?dy:dx) <= distance);
-#endif
-}
-
-unsigned int distance(int dx, int dy)
-{
-#ifdef CIRCULAR_AREA
-	unsigned int min, max;
-
-	if ( dx < 0 ) dx = -dx;
-	if ( dy < 0 ) dy = -dy;
-	//There appears to be something wrong with the aproximation below when either dx/dy is 0! [Skotlex]
-	if ( dx == 0 ) return dy;
-	if ( dy == 0 ) return dx;
-	
-	if ( dx < dy )
-	{
-		min = dx;
-		max = dy;
-	} else {
-		min = dy;
-		max = dx;
-	}
-   // coefficients equivalent to ( 123/128 * max ) and ( 51/128 * min )
-	return ((( max << 8 ) + ( max << 3 ) - ( max << 4 ) - ( max << 1 ) +
-		( min << 7 ) - ( min << 5 ) + ( min << 3 ) - ( min << 1 )) >> 8 );
-#else
-	if (dx < 0) dx = -dx;
-	if (dy < 0) dy = -dy;
-	return (dx<dy?dy:dx);
-#endif
-}
-
-//
-// block削除の安全性確保?理
-//
-
 /*==========================================
  * blockをfreeするときfreeの?わりに呼ぶ
  * ロックされているときはバッファにためる

+ 0 - 11
src/map/map.h

@@ -1343,17 +1343,6 @@ int map_check_dir(int s_dir,int t_dir);
 unsigned char map_calc_dir( struct block_list *src,int x,int y);
 int map_random_dir(struct block_list *bl, short *x, short *y); // [Skotlex]
 
-// distance related functions [Skotlex]
-#define check_distance_bl(bl1, bl2, distance) check_distance((bl1)->x - (bl2)->x, (bl1)->y - (bl2)->y, distance)
-#define check_distance_blxy(bl, x1, y1, distance) check_distance((bl)->x-(x1), (bl)->y-(y1), distance)
-#define check_distance_xy(x0, y0, x1, y1, distance) check_distance((x0)-(x1), (y0)-(y1), distance)
-int check_distance(int dx, int dy, int distance);
-
-#define distance_bl(bl1, bl2) distance((bl1)->x - (bl2)->x, (bl1)->y - (bl2)->y)
-#define distance_blxy(bl, x1, y1) distance((bl)->x-(x1), (bl)->y-(y1))
-#define distance_xy(x0, y0, x1, y1) distance((x0)-(x1), (y0)-(y1))
-unsigned int distance(int dx, int dy);
-
 int cleanup_sub(struct block_list *bl, va_list ap);
 
 void map_helpscreen(int flag); // [Valaris]

+ 1 - 0
src/map/mob.c

@@ -12,6 +12,7 @@
 #include "../common/utils.h"
 
 #include "map.h"
+#include "path.h"
 #include "clif.h"
 #include "intif.h"
 #include "pc.h"

+ 43 - 0
src/map/path.c

@@ -453,3 +453,46 @@ bool path_search(struct walkpath_data *wpd,int m,int x0,int y0,int x1,int y1,int
 
 	return true;
 }
+
+
+//Distance functions, taken from http://www.flipcode.com/articles/article_fastdistance.shtml
+int check_distance(int dx, int dy, int distance)
+{
+#ifdef CIRCULAR_AREA
+	//In this case, we just do a square comparison. Add 1 tile grace for diagonal range checks.
+	return (dx*dx + dy*dy <= distance*distance + (dx&&dy?1:0));
+#else
+	if (dx < 0) dx = -dx;
+	if (dy < 0) dy = -dy;
+	return ((dx<dy?dy:dx) <= distance);
+#endif
+}
+
+unsigned int distance(int dx, int dy)
+{
+#ifdef CIRCULAR_AREA
+	unsigned int min, max;
+
+	if ( dx < 0 ) dx = -dx;
+	if ( dy < 0 ) dy = -dy;
+	//There appears to be something wrong with the aproximation below when either dx/dy is 0! [Skotlex]
+	if ( dx == 0 ) return dy;
+	if ( dy == 0 ) return dx;
+	
+	if ( dx < dy )
+	{
+		min = dx;
+		max = dy;
+	} else {
+		min = dy;
+		max = dx;
+	}
+   // coefficients equivalent to ( 123/128 * max ) and ( 51/128 * min )
+	return ((( max << 8 ) + ( max << 3 ) - ( max << 4 ) - ( max << 1 ) +
+		( min << 7 ) - ( min << 5 ) + ( min << 3 ) - ( min << 1 )) >> 8 );
+#else
+	if (dx < 0) dx = -dx;
+	if (dy < 0) dy = -dy;
+	return (dx<dy?dy:dx);
+#endif
+}

+ 12 - 0
src/map/path.h

@@ -13,4 +13,16 @@ bool path_search(struct walkpath_data *wpd,int m,int x0,int y0,int x1,int y1,int
 // tries to find a shootable path
 bool path_search_long(struct shootpath_data *spd,int m,int x0,int y0,int x1,int y1,cell_t cell);
 
+
+// distance related functions
+int check_distance(int dx, int dy, int distance);
+#define check_distance_bl(bl1, bl2, distance) check_distance((bl1)->x - (bl2)->x, (bl1)->y - (bl2)->y, distance)
+#define check_distance_blxy(bl, x1, y1, distance) check_distance((bl)->x-(x1), (bl)->y-(y1), distance)
+#define check_distance_xy(x0, y0, x1, y1, distance) check_distance((x0)-(x1), (y0)-(y1), distance)
+
+unsigned int distance(int dx, int dy);
+#define distance_bl(bl1, bl2) distance((bl1)->x - (bl2)->x, (bl1)->y - (bl2)->y)
+#define distance_blxy(bl, x1, y1) distance((bl)->x-(x1), (bl)->y-(y1))
+#define distance_xy(x0, y0, x1, y1) distance((x0)-(x1), (y0)-(y1))
+
 #endif /* _PATH_H_ */

+ 1 - 0
src/map/pc.c

@@ -20,6 +20,7 @@
 #include "itemdb.h"
 #include "log.h"
 #include "map.h"
+#include "path.h"
 #include "mercenary.h" // merc_is_hom_active()
 #include "mob.h" // MAX_MOB_RACE_DB
 #include "npc.h" // fake_nd

+ 1 - 0
src/map/pet.c

@@ -13,6 +13,7 @@
 #include "pc.h"
 #include "status.h"
 #include "map.h"
+#include "path.h"
 #include "intif.h"
 #include "clif.h"
 #include "chrif.h"

+ 2 - 1
src/map/script.c

@@ -17,6 +17,7 @@
 #include "../common/utils.h"
 
 #include "map.h"
+#include "path.h"
 #include "clif.h"
 #include "chrif.h"
 #include "itemdb.h"
@@ -11594,7 +11595,7 @@ BUILDIN_FUNC(distance)
 	x1 = script_getnum(st,4);
 	y1 = script_getnum(st,5);
 
-	script_pushint(st,distance(x0-x1, y0-y1));
+	script_pushint(st,distance_xy(x0,y0,x1,y1));
 	return 0;
 }
 

+ 2 - 1
src/map/status.c

@@ -9,8 +9,9 @@
 #include "../common/utils.h"
 #include "../common/ers.h"
 
-#include "pc.h"
 #include "map.h"
+#include "path.h"
+#include "pc.h"
 #include "pet.h"
 #include "npc.h"
 #include "mob.h"

+ 1 - 0
src/map/trade.c

@@ -5,6 +5,7 @@
 #include "clif.h"
 #include "itemdb.h"
 #include "map.h"
+#include "path.h"
 #include "trade.h"
 #include "pc.h"
 #include "npc.h"

+ 1 - 0
src/map/vending.c

@@ -8,6 +8,7 @@
 #include "itemdb.h"
 #include "atcommand.h"
 #include "map.h"
+#include "path.h"
 #include "chrif.h"
 #include "vending.h"
 #include "pc.h"