From 78028c8b652a4edf761b6f250c2fca4b6c576dee Mon Sep 17 00:00:00 2001 From: Piotr HaƂaczkiewicz Date: Tue, 23 Jul 2013 09:56:54 +0200 Subject: 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. --- src/map/unit.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'src/map/unit.c') 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 && -- cgit v1.2.3-60-g2f50