From b5300be8f74ab64d90d71e20a11d2f0d5497c8bd Mon Sep 17 00:00:00 2001 From: skotlex Date: Mon, 18 Dec 2006 19:15:41 +0000 Subject: - When walking into a Guild Dungeon your pvp_points will be set to 5 so you have to die twice before being warped out. - If jobchanging while disguised, the disguise will be removed, since it can't be kept and still calculate correctly the new job class to use. - Fuuma shurikens are now unbreakable code-wise (like all maces, books, etc) - Applied Meruru's patch to increase speed of easy path seeks. git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@9518 54d463be-8e91-2dee-dedb-b68131a5f0ec --- src/map/path.c | 71 ++++++++++++++++++++++++++++++++-------------------------- 1 file changed, 39 insertions(+), 32 deletions(-) (limited to 'src/map/path.c') diff --git a/src/map/path.c b/src/map/path.c index 9e247f366..550defaa8 100644 --- a/src/map/path.c +++ b/src/map/path.c @@ -23,6 +23,13 @@ struct tmp_path { short x,y,dist,before,cost,flag;}; #define calc_index(x,y) (((x)+(y)*MAX_WALKPATH) & (MAX_WALKPATH*MAX_WALKPATH-1)) +const char walk_choices [3][3] = +{ + {1,0,7}, + {2,-1,6}, + {3,4,5}, +}; + /*========================================== * 経路探索補助heap push *------------------------------------------ @@ -307,14 +314,14 @@ int path_search_long_real(struct shootpath_data *spd,int m,int x0,int y0,int x1, * path探索 (x0,y0)->(x1,y1) *------------------------------------------ */ + int path_search_real(struct walkpath_data *wpd,int m,int x0,int y0,int x1,int y1,int flag,cell_t flag2) { int heap[MAX_HEAP+1]; struct tmp_path tp[MAX_WALKPATH*MAX_WALKPATH]; - int i,rp,x,y; - int xs,ys; + register int i,x,y,dx,dy; + int rp,xs,ys; struct map_data *md; - int dx,dy; nullpo_retr(0, wpd); @@ -331,36 +338,36 @@ int path_search_real(struct walkpath_data *wpd,int m,int x0,int y0,int x1,int y1 if(x1<0 || x1>=md->xs || y1<0 || y1>=md->ys || map_getcellp(md,x1,y1,flag2)) return -1; - // easy - // この内部では、0 <= x+dx < sx, 0 <= y+dy < sy は保証されている - dx = (x1-x0<0) ? -1 : 1; - dy = (y1-y0<0) ? -1 : 1; - for(x=x0,y=y0,i=0;x!=x1 || y!=y1;){ - if(i>=sizeof(wpd->path)) - return -1; - if(x!=x1 && y!=y1){ - if(map_getcellp(md,x+dx,y ,flag2)) - break; - if(map_getcellp(md,x ,y+dy,flag2)) - break; - if(map_getcellp(md,x+dx,y+dy,flag2)) - break; - x+=dx; - y+=dy; - wpd->path[i++]=(dx<0) ? ((dy>0)? 1 : 3) : ((dy<0)? 5 : 7); - } else if(x!=x1){ - if(map_getcellp(md,x+dx,y ,flag2)) - break; - x+=dx; - wpd->path[i++]=(dx<0) ? 2 : 6; - } else if(y!=y1){ - if(map_getcellp(md,x ,y+dy,flag2)) - break; - y+=dy; - wpd->path[i++]=(dy>0) ? 0 : 4; - } + // easy and better [Meruru] + dx = ((dx = x1-x0)) ? ((dx<0) ? -1 : 1) : 0; + dy = ((dy = y1-y0)) ? ((dy<0) ? -1 : 1) : 0; + + //Better faster stronger simple path algo. [Meruru] + for(x=x0,y=y0,i=0;i < sizeof(wpd->path);) + { + wpd->path[i++] = walk_choices[-dy + 1][dx + 1]; + + x += dx; + y += dy; + + if(x == x1) dx = 0; + if(y == y1) dy = 0; + + if((!dx && !dy) || map_getcellp(md,x,y,flag2)) + break; } - if (x==x1 && y==y1) { //easy path successful. + + /* + You may be thinking what about diagonal + moves? Cant they cause a error with this some how? + Answer is NO! The only time this can cause a error + is if the target block lies on the diagonal and + is non walkable. But rember we already checked that + up above! So no problems here... I think [Meruru] + */ + + if (x==x1 && y==y1) + { //easy path successful. wpd->path_len=i; wpd->path_pos=0; wpd->path_half=0; -- cgit v1.2.3-60-g2f50