summaryrefslogtreecommitdiff
path: root/src/map/unit.c
diff options
context:
space:
mode:
authorPiotr HaƂaczkiewicz <piotr.halaczkiewicz@gmail.com>2013-07-23 09:56:54 +0200
committerPiotr HaƂaczkiewicz <piotr.halaczkiewicz@gmail.com>2013-07-23 18:04:17 +0200
commit78028c8b652a4edf761b6f250c2fca4b6c576dee (patch)
treecfe66856a33bfe12f9ce9dbfee16ab18128364e5 /src/map/unit.c
parent056c181e1c163b7d49c87bc07bf82ef11fdbd539 (diff)
downloadhercules-78028c8b652a4edf761b6f250c2fca4b6c576dee.tar.gz
hercules-78028c8b652a4edf761b6f250c2fca4b6c576dee.tar.bz2
hercules-78028c8b652a4edf761b6f250c2fca4b6c576dee.tar.xz
hercules-78028c8b652a4edf761b6f250c2fca4b6c576dee.zip
Pathfinding code cleanup.
Now uses binary heap defined in `db.h`. Walk requests now use A* (hard) pathfinding only to match game client behavior. Added defines for movement cost. Added some documentation & comments.
Diffstat (limited to 'src/map/unit.c')
-rw-r--r--src/map/unit.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/src/map/unit.c b/src/map/unit.c
index 4a8a87920..7c65594ca 100644
--- a/src/map/unit.c
+++ b/src/map/unit.c
@@ -107,9 +107,9 @@ int unit_walktoxy_sub(struct block_list *bl)
ud->walkpath.path_len--;
dir = ud->walkpath.path[ud->walkpath.path_len];
if(dir&1)
- i-=14;
+ i -= MOVE_DIAGONAL_COST;
else
- i-=10;
+ i -= MOVE_COST;
ud->to_x -= dirx[dir];
ud->to_y -= diry[dir];
}
@@ -126,7 +126,7 @@ int unit_walktoxy_sub(struct block_list *bl)
if(ud->walkpath.path_pos>=ud->walkpath.path_len)
i = -1;
else if(ud->walkpath.path[ud->walkpath.path_pos]&1)
- i = iStatus->get_speed(bl)*14/10;
+ i = iStatus->get_speed(bl)*MOVE_DIAGONAL_COST/MOVE_COST;
else
i = iStatus->get_speed(bl);
if( i > 0)
@@ -346,14 +346,16 @@ int unit_walktoxy( struct block_list *bl, short x, short y, int flag)
if( ud == NULL) return 0;
- path_search(&wpd, bl->m, bl->x, bl->y, x, y, flag&1, CELL_CHKNOPASS); // Count walk path cells
+ if (!path_search(&wpd, bl->m, bl->x, bl->y, x, y, flag&1, CELL_CHKNOPASS)) // Count walk path cells
+ return 0;
+
#ifdef OFFICIAL_WALKPATH
if( !path_search_long(NULL, bl->m, bl->x, bl->y, x, y, CELL_CHKNOPASS) // Check if there is an obstacle between
&& (wpd.path_len > (battle_config.max_walk_path/17)*14) // Official number of walkable cells is 14 if and only if there is an obstacle between. [malufett]
&& (bl->type != BL_NPC) ) // If type is a NPC, please disregard.
return 0;
#endif
- if( (battle_config.max_walk_path < wpd.path_len) && (bl->type != BL_NPC) )
+ if ((wpd.path_len > battle_config.max_walk_path) && (bl->type != BL_NPC))
return 0;
if (flag&4 && DIFF_TICK(ud->canmove_tick, iTimer->gettick()) > 0 &&