summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/map/map.c46
-rw-r--r--src/map/map.h11
-rw-r--r--src/map/mob.c1
-rw-r--r--src/map/path.c43
-rw-r--r--src/map/path.h12
-rw-r--r--src/map/pc.c1
-rw-r--r--src/map/pet.c1
-rw-r--r--src/map/script.c3
-rw-r--r--src/map/status.c3
-rw-r--r--src/map/trade.c1
-rw-r--r--src/map/vending.c1
11 files changed, 64 insertions, 59 deletions
diff --git a/src/map/map.c b/src/map/map.c
index c4a0847b6..59eef42cc 100644
--- a/src/map/map.c
+++ b/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の?わりに呼ぶ
* ロックされているときはバッファにためる
diff --git a/src/map/map.h b/src/map/map.h
index 32b3ed6d5..3ee4e0c7d 100644
--- a/src/map/map.h
+++ b/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]
diff --git a/src/map/mob.c b/src/map/mob.c
index d5105597f..3e3e7719d 100644
--- a/src/map/mob.c
+++ b/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"
diff --git a/src/map/path.c b/src/map/path.c
index 52dcd0ac8..549144d7b 100644
--- a/src/map/path.c
+++ b/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
+}
diff --git a/src/map/path.h b/src/map/path.h
index 138845dc4..83992b546 100644
--- a/src/map/path.h
+++ b/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_ */
diff --git a/src/map/pc.c b/src/map/pc.c
index 9caff12db..959503654 100644
--- a/src/map/pc.c
+++ b/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
diff --git a/src/map/pet.c b/src/map/pet.c
index e52753085..a792924f5 100644
--- a/src/map/pet.c
+++ b/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"
diff --git a/src/map/script.c b/src/map/script.c
index 249d4c321..b0621aa40 100644
--- a/src/map/script.c
+++ b/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;
}
diff --git a/src/map/status.c b/src/map/status.c
index 4d36ddec3..611f7e02e 100644
--- a/src/map/status.c
+++ b/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"
diff --git a/src/map/trade.c b/src/map/trade.c
index fcb116d06..fa092c49c 100644
--- a/src/map/trade.c
+++ b/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"
diff --git a/src/map/vending.c b/src/map/vending.c
index 4e4a9b729..dd0f7ad76 100644
--- a/src/map/vending.c
+++ b/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"