From 8dc2ec08666cac608e391fa6c47b9248dd273f99 Mon Sep 17 00:00:00 2001 From: Inkfish Date: Sun, 25 Oct 2009 11:20:47 +0000 Subject: Reverted renaming foreach functions and create a new one for OnTouch so that last commit will hopefully break NOTHING in use. git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@14098 54d463be-8e91-2dee-dedb-b68131a5f0ec --- src/map/atcommand.c | 8 +++---- src/map/clif.c | 8 +++---- src/map/map.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++++---- src/map/map.h | 3 ++- src/map/npc.c | 6 ++--- src/map/script.c | 18 +++++++------- src/map/skill.c | 42 ++++++++++++++++----------------- src/map/status.c | 4 ++-- 8 files changed, 109 insertions(+), 48 deletions(-) (limited to 'src/map') diff --git a/src/map/atcommand.c b/src/map/atcommand.c index ae5c3bea1..e638d6513 100644 --- a/src/map/atcommand.c +++ b/src/map/atcommand.c @@ -6367,9 +6367,9 @@ static int atcommand_cleanmap_sub(struct block_list *bl, va_list ap) int atcommand_cleanmap(const int fd, struct map_session_data* sd, const char* command, const char* message) { - map_forsomeinarea(atcommand_cleanmap_sub, sd->bl.m, + map_foreachinarea(atcommand_cleanmap_sub, sd->bl.m, sd->bl.x-AREA_SIZE*2, sd->bl.y-AREA_SIZE*2, - sd->bl.x+AREA_SIZE*2, sd->bl.y+AREA_SIZE*2,0, + sd->bl.x+AREA_SIZE*2, sd->bl.y+AREA_SIZE*2, BL_ITEM); clif_displaymessage(fd, "All dropped items have been cleaned up."); return 0; @@ -7593,9 +7593,9 @@ int atcommand_mutearea(const int fd, struct map_session_data* sd, const char* co time = atoi(message); - map_forsomeinarea(atcommand_mutearea_sub,sd->bl.m, + map_foreachinarea(atcommand_mutearea_sub,sd->bl.m, sd->bl.x-AREA_SIZE, sd->bl.y-AREA_SIZE, - sd->bl.x+AREA_SIZE, sd->bl.y+AREA_SIZE, 0, BL_PC, sd->bl.id, time); + sd->bl.x+AREA_SIZE, sd->bl.y+AREA_SIZE, BL_PC, sd->bl.id, time); return 0; } diff --git a/src/map/clif.c b/src/map/clif.c index a1c413398..ddda47612 100644 --- a/src/map/clif.c +++ b/src/map/clif.c @@ -278,12 +278,12 @@ int clif_send(const uint8* buf, int len, struct block_list* bl, enum send_target clif_send (buf, len, bl, SELF); case AREA_WOC: case AREA_WOS: - map_forsomeinarea(clif_send_sub, bl->m, bl->x-AREA_SIZE, bl->y-AREA_SIZE, bl->x+AREA_SIZE, bl->y+AREA_SIZE, 0, + map_foreachinarea(clif_send_sub, bl->m, bl->x-AREA_SIZE, bl->y-AREA_SIZE, bl->x+AREA_SIZE, bl->y+AREA_SIZE, BL_PC, buf, len, bl, type); break; case AREA_CHAT_WOC: - map_forsomeinarea(clif_send_sub, bl->m, bl->x-(AREA_SIZE-5), bl->y-(AREA_SIZE-5), - bl->x+(AREA_SIZE-5), bl->y+(AREA_SIZE-5), 0, BL_PC, buf, len, bl, AREA_WOC); + map_foreachinarea(clif_send_sub, bl->m, bl->x-(AREA_SIZE-5), bl->y-(AREA_SIZE-5), + bl->x+(AREA_SIZE-5), bl->y+(AREA_SIZE-5), BL_PC, buf, len, bl, AREA_WOC); break; case CHAT: @@ -8142,7 +8142,7 @@ void clif_parse_LoadEndAck(int fd,struct map_session_data *sd) // info about nearby objects // must use foreachinarea (CIRCULAR_AREA interferes with foreachinrange) - map_forsomeinarea(clif_getareachar, sd->bl.m, sd->bl.x-AREA_SIZE, sd->bl.y-AREA_SIZE, sd->bl.x+AREA_SIZE, sd->bl.y+AREA_SIZE, 0, BL_ALL, sd); + map_foreachinarea(clif_getareachar, sd->bl.m, sd->bl.x-AREA_SIZE, sd->bl.y-AREA_SIZE, sd->bl.x+AREA_SIZE, sd->bl.y+AREA_SIZE, BL_ALL, sd); //TODO: merge it with the code below if (battle_config.pet_no_gvg && map_flag_gvg(sd->bl.m) && sd->pd) diff --git a/src/map/map.c b/src/map/map.c index ed706bcdb..203a31733 100644 --- a/src/map/map.c +++ b/src/map/map.c @@ -650,7 +650,7 @@ int map_foreachinshootrange(int (*func)(struct block_list*,va_list),struct block * funcを呼ぶ * type!=0 ならその種類のみ *------------------------------------------*/ -int map_forsomeinarea(int (*func)(struct block_list*,va_list), int m, int x0, int y0, int x1, int y1, int count, int type, ...) +int map_foreachinarea(int (*func)(struct block_list*,va_list), int m, int x0, int y0, int x1, int y1, int type, ...) { int bx,by; int returnCount =0; //total sum of returned values of func() [Skotlex] @@ -702,7 +702,67 @@ int map_forsomeinarea(int (*func)(struct block_list*,va_list), int m, int x0, in va_start(ap, type); returnCount += func(bl_list[i], ap); va_end(ap); - if( count && returnCount >= count) + } + + map_freeblock_unlock(); // 解放を許可する + + bl_list_count = blockcount; + return returnCount; //[Skotlex] +} + +int map_forcountinarea(int (*func)(struct block_list*,va_list), int m, int x0, int y0, int x1, int y1, int count, int type, ...) +{ + int bx,by; + int returnCount =0; //total sum of returned values of func() [Skotlex] + struct block_list *bl; + int blockcount=bl_list_count,i; + + if (m < 0) + return 0; + if (x1 < x0) + { //Swap range + bx = x0; + x0 = x1; + x1 = bx; + } + if (y1 < y0) + { + bx = y0; + y0 = y1; + y1 = bx; + } + if (x0 < 0) x0 = 0; + if (y0 < 0) y0 = 0; + if (x1 >= map[m].xs) x1 = map[m].xs-1; + if (y1 >= map[m].ys) y1 = map[m].ys-1; + + if (type&~BL_MOB) + for(by = y0 / BLOCK_SIZE; by <= y1 / BLOCK_SIZE; by++) + for(bx = x0 / BLOCK_SIZE; bx <= x1 / BLOCK_SIZE; bx++) + for( bl = map[m].block[bx+by*map[m].bxs] ; bl != NULL ; bl = bl->next ) + if(bl->type&type && bl->x>=x0 && bl->x<=x1 && bl->y>=y0 && bl->y<=y1 && bl_list_countnext ) + if(bl->x>=x0 && bl->x<=x1 && bl->y>=y0 && bl->y<=y1 && bl_list_count=BL_LIST_MAX) + ShowWarning("map_foreachinarea: block count too many!\n"); + + map_freeblock_lock(); // メモリからの解放を禁止する + + for(i=blockcount;iprev) // 有?かどうかチェック + { + va_list ap; + va_start(ap, type); + returnCount += func(bl_list[i], ap); + va_end(ap); + if( count && returnCount >= count ) break; } @@ -1297,9 +1357,9 @@ int map_search_freecell(struct block_list *src, int m, short *x,short *y, int rx if(flag&4) { if (spawn >= 100) return 0; //Limit of retries reached. if (spawn++ < battle_config.no_spawn_on_player && - map_forsomeinarea(map_count_sub, m, + map_foreachinarea(map_count_sub, m, *x-AREA_SIZE, *y-AREA_SIZE, - *x+AREA_SIZE, *y+AREA_SIZE, 0, BL_PC) + *x+AREA_SIZE, *y+AREA_SIZE, BL_PC) ) continue; } diff --git a/src/map/map.h b/src/map/map.h index 98e15ab5a..5fc6739a1 100644 --- a/src/map/map.h +++ b/src/map/map.h @@ -530,7 +530,8 @@ int map_delblock(struct block_list* bl); int map_moveblock(struct block_list *, int, int, unsigned int); int map_foreachinrange(int (*func)(struct block_list*,va_list), struct block_list* center, int range, int type, ...); int map_foreachinshootrange(int (*func)(struct block_list*,va_list), struct block_list* center, int range, int type, ...); -int map_forsomeinarea(int (*func)(struct block_list*,va_list), int m, int x0, int y0, int x1, int y1, int count, int type, ...); +int map_foreachinarea(int (*func)(struct block_list*,va_list), int m, int x0, int y0, int x1, int y1, int type, ...); +int map_forcountinarea(int (*func)(struct block_list*,va_list), int m, int x0, int y0, int x1, int y1, int count, int type, ...); int map_foreachinmovearea(int (*func)(struct block_list*,va_list), struct block_list* center, int range, int dx, int dy, int type, ...); int map_foreachincell(int (*func)(struct block_list*,va_list), int m, int x, int y, int type, ...); int map_foreachinpath(int (*func)(struct block_list*,va_list), int m, int x0, int y0, int x1, int y1, int range, int length, int type, ...); diff --git a/src/map/npc.c b/src/map/npc.c index 2e3ca2c63..0a412de41 100644 --- a/src/map/npc.c +++ b/src/map/npc.c @@ -161,7 +161,7 @@ int npc_enable(const char* name, int flag) clif_changeoption(&nd->bl); if( flag&3 && (nd->u.scr.xs >= 0 || nd->u.scr.ys >= 0) ) - map_forsomeinarea( npc_enable_sub, nd->bl.m, nd->bl.x-nd->u.scr.xs, nd->bl.y-nd->u.scr.ys, nd->bl.x+nd->u.scr.xs, nd->bl.y+nd->u.scr.ys, 0, BL_PC, nd ); + map_foreachinarea( npc_enable_sub, nd->bl.m, nd->bl.x-nd->u.scr.xs, nd->bl.y-nd->u.scr.ys, nd->bl.x+nd->u.scr.xs, nd->bl.y+nd->u.scr.ys, BL_PC, nd ); return 0; } @@ -838,7 +838,7 @@ int npc_touchnext_areanpc(struct map_session_data* sd, bool logout) memset(&sd->ontouch,0,sizeof(sd->ontouch)); nd->touching_id = 0; snprintf(name, ARRAYLENGTH(name), "%s::%s", nd->exname, script_config.ontouch_name); - map_forsomeinarea(npc_touch_areanpc_sub,nd->bl.m,nd->bl.m - xs,nd->bl.y - ys,nd->bl.x + xs,nd->bl.y + ys,1,BL_PC,sd->bl.id,nd->bl.id,name); + map_forcountinarea(npc_touch_areanpc_sub,nd->bl.m,nd->bl.m - xs,nd->bl.y - ys,nd->bl.x + xs,nd->bl.y + ys,1,BL_PC,sd->bl.id,nd->bl.id,name); } return 0; } @@ -2535,7 +2535,7 @@ void npc_unsetcells(struct npc_data* nd) map_setcell(m, j, i, CELL_NPC, false); //Re-deploy NPC cells for other nearby npcs. - map_forsomeinarea( npc_unsetcells_sub, m, x0, y0, x1, y1, 0, BL_NPC, nd->bl.id ); + map_foreachinarea( npc_unsetcells_sub, m, x0, y0, x1, y1, BL_NPC, nd->bl.id ); } void npc_movenpc(struct npc_data* nd, int x, int y) diff --git a/src/map/script.c b/src/map/script.c index 6f34e3058..e3f1dddc1 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -4118,7 +4118,7 @@ BUILDIN_FUNC(areawarp) else if(!(index=mapindex_name2id(str))) return 0; - map_forsomeinarea(buildin_areawarp_sub, m,x0,y0,x1,y1,0,BL_PC, index,x,y); + map_foreachinarea(buildin_areawarp_sub, m,x0,y0,x1,y1,BL_PC, index,x,y); return 0; } @@ -4150,7 +4150,7 @@ BUILDIN_FUNC(areapercentheal) if( (m=map_mapname2mapid(mapname))< 0) return 0; - map_forsomeinarea(buildin_areapercentheal_sub,m,x0,y0,x1,y1,0,BL_PC,hp,sp); + map_foreachinarea(buildin_areapercentheal_sub,m,x0,y0,x1,y1,BL_PC,hp,sp); return 0; } @@ -8178,8 +8178,8 @@ BUILDIN_FUNC(areaannounce) if( (m=map_mapname2mapid(map))<0 ) return 0; - map_forsomeinarea(buildin_mapannounce_sub, - m,x0,y0,x1,y1,0,BL_PC, str,strlen(str)+1,flag&0x10, color); + map_foreachinarea(buildin_mapannounce_sub, + m,x0,y0,x1,y1,BL_PC, str,strlen(str)+1,flag&0x10, color); return 0; } @@ -8289,8 +8289,8 @@ BUILDIN_FUNC(getareausers) script_pushint(st,-1); return 0; } - map_forsomeinarea(buildin_getareausers_sub, - m,x0,y0,x1,y1,0,BL_PC,&users); + map_foreachinarea(buildin_getareausers_sub, + m,x0,y0,x1,y1,BL_PC,&users); script_pushint(st,users); return 0; } @@ -8336,8 +8336,8 @@ BUILDIN_FUNC(getareadropitem) script_pushint(st,-1); return 0; } - map_forsomeinarea(buildin_getareadropitem_sub, - m,x0,y0,x1,y1,0,BL_ITEM,item,&amount); + map_foreachinarea(buildin_getareadropitem_sub, + m,x0,y0,x1,y1,BL_ITEM,item,&amount); script_pushint(st,amount); return 0; } @@ -10647,7 +10647,7 @@ BUILDIN_FUNC(soundeffectall) int y0 = script_getnum(st,6); int x1 = script_getnum(st,7); int y1 = script_getnum(st,8); - map_forsomeinarea(soundeffect_sub, map_mapname2mapid(map), x0, y0, x1, y1, 0, BL_PC, name, type); + map_foreachinarea(soundeffect_sub, map_mapname2mapid(map), x0, y0, x1, y1, BL_PC, name, type); } else { diff --git a/src/map/skill.c b/src/map/skill.c index 715c00558..ba897b7c2 100644 --- a/src/map/skill.c +++ b/src/map/skill.c @@ -2073,7 +2073,7 @@ static int skill_check_unit_range (struct block_list *bl, int x, int y, int skil } range += layout_type; - return map_forsomeinarea(skill_check_unit_range_sub,bl->m,x-range,y-range,x+range,y+range,0,BL_SKILL,skillid); + return map_foreachinarea(skill_check_unit_range_sub,bl->m,x-range,y-range,x+range,y+range,BL_SKILL,skillid); } static int skill_check_unit_range2_sub (struct block_list *bl, va_list ap) @@ -2123,8 +2123,8 @@ static int skill_check_unit_range2 (struct block_list *bl, int x, int y, int ski else type = BL_PC; - return map_forsomeinarea(skill_check_unit_range2_sub, bl->m, - x - range, y - range, x + range, y + range,0, + return map_foreachinarea(skill_check_unit_range2_sub, bl->m, + x - range, y - range, x + range, y + range, type, skillid); } @@ -2334,8 +2334,8 @@ static int skill_timerskill(int tid, unsigned int tick, int id, intptr data) case BA_FROSTJOKER: case DC_SCREAM: range= skill_get_splash(skl->skill_id, skl->skill_lv); - map_forsomeinarea(skill_frostjoke_scream,skl->map,skl->x-range,skl->y-range, - skl->x+range,skl->y+range,0,BL_CHAR,src,skl->skill_id,skl->skill_lv,tick); + map_foreachinarea(skill_frostjoke_scream,skl->map,skl->x-range,skl->y-range, + skl->x+range,skl->y+range,BL_CHAR,src,skl->skill_id,skl->skill_lv,tick); break; case NPC_EARTHQUAKE: skill_area_temp[0] = map_foreachinrange(skill_area_sub, src, skill_get_splash(skl->skill_id, skl->skill_lv), BL_CHAR, src, skl->skill_id, skl->skill_lv, tick, BCT_ENEMY, skill_area_sub_count); @@ -6179,32 +6179,32 @@ int skill_castend_pos2(struct block_list* src, int x, int y, int skillid, int sk case PR_BENEDICTIO: skill_area_temp[1] = src->id; i = skill_get_splash(skillid, skilllv); - map_forsomeinarea(skill_area_sub, - src->m, x-i, y-i, x+i, y+i, 0,BL_PC, + map_foreachinarea(skill_area_sub, + src->m, x-i, y-i, x+i, y+i, BL_PC, src, skillid, skilllv, tick, flag|BCT_ALL|1, skill_castend_nodamage_id); - map_forsomeinarea(skill_area_sub, - src->m, x-i, y-i, x+i, y+i, 0,BL_CHAR, + map_foreachinarea(skill_area_sub, + src->m, x-i, y-i, x+i, y+i, BL_CHAR, src, skillid, skilllv, tick, flag|BCT_ENEMY|1, skill_castend_damage_id); break; case BS_HAMMERFALL: i = skill_get_splash(skillid, skilllv); - map_forsomeinarea (skill_area_sub, - src->m, x-i, y-i, x+i, y+i, 0,BL_CHAR, + map_foreachinarea (skill_area_sub, + src->m, x-i, y-i, x+i, y+i, BL_CHAR, src, skillid, skilllv, tick, flag|BCT_ENEMY|2, skill_castend_nodamage_id); break; case HT_DETECTING: i = skill_get_splash(skillid, skilllv); - map_forsomeinarea( status_change_timer_sub, - src->m, x-i, y-i, x+i,y+i,0,BL_CHAR, + map_foreachinarea( status_change_timer_sub, + src->m, x-i, y-i, x+i,y+i,BL_CHAR, src,NULL,SC_SIGHT,tick); if(battle_config.traps_setting&1) - map_forsomeinarea( skill_reveal_trap, - src->m, x-i, y-i, x+i,y+i,0,BL_SKILL); + map_foreachinarea( skill_reveal_trap, + src->m, x-i, y-i, x+i,y+i,BL_SKILL); break; case SA_VOLCANO: @@ -6319,7 +6319,7 @@ int skill_castend_pos2(struct block_list* src, int x, int y, int skillid, int sk break; case RG_CLEANER: // [Valaris] i = skill_get_splash(skillid, skilllv); - map_forsomeinarea(skill_graffitiremover,src->m,x-i,y-i,x+i,y+i,0,BL_SKILL); + map_foreachinarea(skill_graffitiremover,src->m,x-i,y-i,x+i,y+i,BL_SKILL); break; case WZ_METEOR: @@ -6424,8 +6424,8 @@ int skill_castend_pos2(struct block_list* src, int x, int y, int skillid, int sk if(potion_hp > 0 || potion_sp > 0) { i = skill_get_splash(skillid, skilllv); - map_forsomeinarea(skill_area_sub, - src->m,x-i,y-i,x+i,y+i,0,BL_CHAR, + map_foreachinarea(skill_area_sub, + src->m,x-i,y-i,x+i,y+i,BL_CHAR, src,skillid,skilllv,tick,flag|BCT_PARTY|BCT_GUILD|1, skill_castend_nodamage_id); } @@ -6446,8 +6446,8 @@ int skill_castend_pos2(struct block_list* src, int x, int y, int skillid, int sk if(potion_hp > 0 || potion_sp > 0) { i = skill_get_splash(skillid, skilllv); - map_forsomeinarea(skill_area_sub, - src->m,x-i,y-i,x+i,y+i,0,BL_CHAR, + map_foreachinarea(skill_area_sub, + src->m,x-i,y-i,x+i,y+i,BL_CHAR, src,skillid,skilllv,tick,flag|BCT_PARTY|BCT_GUILD|1, skill_castend_nodamage_id); } @@ -6459,7 +6459,7 @@ int skill_castend_pos2(struct block_list* src, int x, int y, int skillid, int sk int dummy = 1; clif_skill_poseffect(src,skillid,skilllv,x,y,tick); i = skill_get_splash(skillid, skilllv); - map_forsomeinarea(skill_cell_overlap, src->m, x-i, y-i, x+i, y+i, BL_SKILL, HW_GANBANTEIN, &dummy, src); + map_foreachinarea(skill_cell_overlap, src->m, x-i, y-i, x+i, y+i, BL_SKILL, HW_GANBANTEIN, &dummy, src); } else { if (sd) clif_skill_fail(sd,skillid,0,0); return 1; diff --git a/src/map/status.c b/src/map/status.c index bd9bba811..71d0f6770 100644 --- a/src/map/status.c +++ b/src/map/status.c @@ -6498,8 +6498,8 @@ int status_change_end(struct block_list* bl, enum sc_type type, int tid) int range = 1 +skill_get_range2(bl, status_sc2skill(type), sce->val1) +skill_get_range2(bl, TF_BACKSLIDING, 1); //Since most people use this to escape the hold.... - map_forsomeinarea(status_change_timer_sub, - bl->m, bl->x-range, bl->y-range, bl->x+range,bl->y+range,0,BL_CHAR,bl,sce,type,gettick()); + map_foreachinarea(status_change_timer_sub, + bl->m, bl->x-range, bl->y-range, bl->x+range,bl->y+range,BL_CHAR,bl,sce,type,gettick()); } break; case SC_COMBO: //Clear last used skill when it is part of a combo. -- cgit v1.2.3-60-g2f50