From f4edc7e4431b929acc62e4c2427e815ba9d69779 Mon Sep 17 00:00:00 2001 From: skotlex Date: Wed, 6 Dec 2006 18:21:32 +0000 Subject: - Cleaned up the implementation of map_foreachinmovearea so that the number of arguments passed is less. - Moved setting a mob's chase/attack states from the mob_ai to unit_attack and unit_walktobl. - Cleaned the change-target/cast-sensor code to account for the new mob modes. - Cleaned up a bit the mob ai sub hard function. - Made the monster_active_enable config setting take effect on mob load. - Updated the doc explaining mob modes. git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@9422 54d463be-8e91-2dee-dedb-b68131a5f0ec --- src/map/map.c | 69 +++++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 43 insertions(+), 26 deletions(-) (limited to 'src/map/map.c') diff --git a/src/map/map.c b/src/map/map.c index 3a321fc68..1247206ab 100644 --- a/src/map/map.c +++ b/src/map/map.c @@ -629,10 +629,8 @@ int map_foreachinrange(int (*func)(struct block_list*,va_list),struct block_list struct block_list *bl=NULL; int blockcount=bl_list_count,i,c; int x0,x1,y0,y1; - m = center->m; - if (m < 0) - return 0; va_start(ap,type); + m = center->m; x0 = center->x-range; x1 = center->x+range; y0 = center->y-range; @@ -854,14 +852,23 @@ int map_foreachinarea(int (*func)(struct block_list*,va_list),int m,int x0,int y * dx,dyは-1,0,1のみとする(どんな値でもいいっぽい?) *------------------------------------------ */ -int map_foreachinmovearea(int (*func)(struct block_list*,va_list),int m,int x0,int y0,int x1,int y1,int dx,int dy,int type,...) { - int bx,by; +int map_foreachinmovearea(int (*func)(struct block_list*,va_list),struct block_list *center,int range, int dx,int dy,int type,...) { + int bx,by,m; int returnCount =0; //total sum of returned values of func() [Skotlex] struct block_list *bl=NULL; va_list ap; int blockcount=bl_list_count,i,c; + int x0, x1, y0, y1; + if (!range) return 0; + if (!dx && !dy) return 0; //No movement. va_start(ap,type); + m = center->m; + x0 = center->x-range; + x1 = center->x+range; + y0 = center->y-range; + y1 = center->y+range; + if (x1 < x0) { //Swap range bx = x0; @@ -875,19 +882,17 @@ int map_foreachinmovearea(int (*func)(struct block_list*,va_list),int m,int x0,i y1 = bx; } if(dx==0 || dy==0){ - // 矩形領域の場合 + //Movement along one axis only. if(dx==0){ - if(dy<0){ + if(dy<0) //Moving south y0=y1+dy+1; - } else { + else //North y1=y0+dy-1; - } - } else if(dy==0){ - if(dx<0){ + } else { //dy == 0 + if(dx<0) //West x0=x1+dx+1; - } else { + else //East x1=x0+dx-1; - } } if(x0<0) x0=0; if(y0<0) y0=0; @@ -899,7 +904,10 @@ int map_foreachinmovearea(int (*func)(struct block_list*,va_list),int m,int x0,i bl = map[m].block[bx+by*map[m].bxs]; c = map[m].block_count[bx+by*map[m].bxs]; for(i=0;inext){ - if(bl && bl->type&type && bl->x>=x0 && bl->x<=x1 && bl->y>=y0 && bl->y<=y1 && bl_list_counttype&type && + bl->x>=x0 && bl->x<=x1 && + bl->y>=y0 && bl->y<=y1 && + bl_list_countnext){ - if(bl && bl->x>=x0 && bl->x<=x1 && bl->y>=y0 && bl->y<=y1 && bl_list_countx>=x0 && bl->x<=x1 && + bl->y>=y0 && bl->y<=y1 && + bl_list_count=map[m].xs) x1=map[m].xs-1; @@ -926,23 +935,31 @@ int map_foreachinmovearea(int (*func)(struct block_list*,va_list),int m,int x0,i bl = map[m].block[bx+by*map[m].bxs]; c = map[m].block_count[bx+by*map[m].bxs]; for(i=0;inext){ - if(!bl || !(bl->x>=x0 && bl->x<=x1 && bl->y>=y0 && bl->y<=y1)) + if(!(bl->type&type && + bl->x>=x0 && bl->x<=x1 && + bl->y>=y0 && bl->y<=y1 && + bl_list_counttype&type && ((dx>0 && bl->xx>x1+dx) || - (dy>0 && bl->yy>y1+dy)) && - bl_list_count0 && bl->xx>x1+dx) || + (dy>0 && bl->yy>y1+dy)) + bl_list[bl_list_count++]=bl; } } if (type & BL_MOB) { bl = map[m].block_mob[bx+by*map[m].bxs]; c = map[m].block_mob_count[bx+by*map[m].bxs]; for(i=0;inext){ - if(!bl || !(bl->x>=x0 && bl->x<=x1 && bl->y>=y0 && bl->y<=y1)) + if(!( + bl->x>=x0 && bl->x<=x1 && + bl->y>=y0 && bl->y<=y1 && + bl_list_count0 && bl->xx>x1+dx) || - (dy>0 && bl->yy>y1+dy)) && - bl_list_count0 && bl->xx>x1+dx) || + (dy>0 && bl->yy>y1+dy)) bl_list[bl_list_count++]=bl; } } -- cgit v1.2.3-60-g2f50