From bff8a4273ec7cedd86b95055278be824ff566f98 Mon Sep 17 00:00:00 2001 From: ultramage Date: Tue, 3 Jul 2007 15:15:23 +0000 Subject: - Re-coded 'soundeffectall'; removed the third parameter ('coverage') git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@10844 54d463be-8e91-2dee-dedb-b68131a5f0ec --- src/map/atcommand.c | 4 +-- src/map/clif.c | 32 ++++++++----------- src/map/clif.h | 4 +-- src/map/map.c | 12 +++---- src/map/map.h | 15 +++++---- src/map/script.c | 91 +++++++++++++++++++++++++++-------------------------- 6 files changed, 76 insertions(+), 82 deletions(-) (limited to 'src') diff --git a/src/map/atcommand.c b/src/map/atcommand.c index 63d933538..bfcb2600c 100644 --- a/src/map/atcommand.c +++ b/src/map/atcommand.c @@ -7197,7 +7197,7 @@ int atcommand_clearweather(const int fd, struct map_session_data* sd, const char } /*=============================================================== - * Sound Command - plays a sound for everyone! [Codemaster] + * Sound Command - plays a sound for everyone around! [Codemaster] *---------------------------------------------------------------*/ int atcommand_sound(const int fd, struct map_session_data *sd, const char *command, const char *message) { @@ -7213,7 +7213,7 @@ int atcommand_sound(const int fd, struct map_session_data *sd, const char *comma if(strstr(sound_file, ".wav") == NULL) strcat(sound_file, ".wav"); - clif_soundeffectall(&sd->bl, sound_file,0,2); + clif_soundeffectall(&sd->bl, sound_file, 0, AREA); return 0; } diff --git a/src/map/clif.c b/src/map/clif.c index b501d76d4..e7bab9ebc 100644 --- a/src/map/clif.c +++ b/src/map/clif.c @@ -7347,42 +7347,36 @@ int clif_wisall(struct map_session_data *sd,int type,int flag) /*========================================== * サウンドエフェクト *------------------------------------------*/ -void clif_soundeffect(struct map_session_data *sd,struct block_list *bl,const char *name,int type) +void clif_soundeffect(struct map_session_data* sd, struct block_list* bl, const char* name, int type) { int fd; nullpo_retv(sd); nullpo_retv(bl); - fd=sd->fd; + fd = sd->fd; WFIFOHEAD(fd,packet_len(0x1d3)); - WFIFOW(fd,0)=0x1d3; - memcpy(WFIFOP(fd,2),name,NAME_LENGTH); - WFIFOB(fd,26)=type; - WFIFOL(fd,27)=0; - WFIFOL(fd,31)=bl->id; + WFIFOW(fd,0) = 0x1d3; + safestrncpy((char*)WFIFOP(fd,2), name, NAME_LENGTH); + WFIFOB(fd,26) = type; + WFIFOL(fd,27) = 0; + WFIFOL(fd,31) = bl->id; WFIFOSET(fd,packet_len(0x1d3)); return; } -int clif_soundeffectall(struct block_list *bl, const char *name, int type, int coverage) +int clif_soundeffectall(struct block_list* bl, const char* name, int type, enum send_target coverage) { unsigned char buf[40]; - memset(buf, 0, packet_len(0x1d3)); - - if(coverage < 0 || coverage > 22){ - ShowError("clif_soundeffectall: undefined coverage.\n"); - return 0; - } nullpo_retr(0, bl); - WBUFW(buf,0)=0x1d3; - memcpy(WBUFP(buf,2), name, NAME_LENGTH); - WBUFB(buf,26)=type; - WBUFL(buf,27)=0; - WBUFL(buf,31)=bl->id; + WBUFW(buf,0) = 0x1d3; + safestrncpy((char*)WBUFP(buf,2), name, NAME_LENGTH); + WBUFB(buf,26) = type; + WBUFL(buf,27) = 0; + WBUFL(buf,31) = bl->id; clif_send(buf, packet_len(0x1d3), bl, coverage); return 0; diff --git a/src/map/clif.h b/src/map/clif.h index cba09da75..9186d8e7c 100644 --- a/src/map/clif.h +++ b/src/map/clif.h @@ -134,8 +134,8 @@ void clif_wedding_effect(struct block_list *bl); void clif_divorced(struct map_session_data* sd, const char* name); //void clif_callpartner(struct map_session_data *sd); void clif_adopt_process(struct map_session_data *sd); -void clif_soundeffect(struct map_session_data *sd,struct block_list *bl,const char *name,int type); -int clif_soundeffectall(struct block_list *bl, const char *name, int type, int coverage); +void clif_soundeffect(struct map_session_data* sd, struct block_list* bl, const char* name, int type); +int clif_soundeffectall(struct block_list* bl, const char *name, int type, enum send_target coverage); void clif_parse_ActionRequest_sub(struct map_session_data *sd, int action_type, int target_id, unsigned int tick); void clif_parse_LoadEndAck(int fd,struct map_session_data *sd); diff --git a/src/map/map.c b/src/map/map.c index c7173dfdb..89494a65d 100644 --- a/src/map/map.c +++ b/src/map/map.c @@ -608,7 +608,7 @@ struct skill_unit *map_find_skill_unit_oncell(struct block_list *target,int x,in /*========================================== * Adapted from foreachinarea for an easier invocation. [Skotlex] *------------------------------------------*/ -int map_foreachinrange(int (*func)(struct block_list*,va_list),struct block_list *center, int range,int type,...) +int map_foreachinrange(int (*func)(struct block_list*,va_list), struct block_list* center, int range, int type, ...) { va_list ap; int bx,by,m; @@ -682,7 +682,7 @@ int map_foreachinrange(int (*func)(struct block_list*,va_list),struct block_list /*========================================== * Same as foreachinrange, but there must be a shoot-able range between center and target to be counted in. [Skotlex] *------------------------------------------*/ -int map_foreachinshootrange(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,...) { va_list ap; int bx,by,m; @@ -762,7 +762,7 @@ int map_foreachinshootrange(int (*func)(struct block_list*,va_list),struct block * funcを呼ぶ * type!=0 ならその種類のみ *------------------------------------------*/ -int map_foreachinarea(int (*func)(struct block_list*,va_list),int m,int x0,int y0,int x1,int y1,int type,...) +int map_foreachinarea(int (*func)(struct block_list*,va_list), int m, int x0, int y0, int x1, int y1, int type, ...) { va_list ap; int bx,by; @@ -838,7 +838,7 @@ 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),struct block_list *center,int range, int dx,int dy,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 bx,by,m; int returnCount =0; //total sum of returned values of func() [Skotlex] @@ -977,7 +977,7 @@ int map_foreachinmovearea(int (*func)(struct block_list*,va_list),struct block_l // which only checks the exact single x/y passed to it rather than an // area radius - may be more useful in some instances) // -int map_foreachincell(int (*func)(struct block_list*,va_list),int m,int x,int y,int type,...) +int map_foreachincell(int (*func)(struct block_list*,va_list), int m, int x, int y, int type, ...) { int bx,by; int returnCount =0; //total sum of returned values of func() [Skotlex] @@ -1215,7 +1215,7 @@ int map_foreachinpath(int (*func)(struct block_list*,va_list),int m,int x0,int y } // Copy of map_foreachincell, but applied to the whole map. [Skotlex] -int map_foreachinmap(int (*func)(struct block_list*,va_list),int m,int type,...) +int map_foreachinmap(int (*func)(struct block_list*,va_list), int m, int type,...) { int b, bsize; int returnCount =0; //total sum of returned values of func() [Skotlex] diff --git a/src/map/map.h b/src/map/map.h index b929880d8..1ecaf68b7 100644 --- a/src/map/map.h +++ b/src/map/map.h @@ -1300,14 +1300,13 @@ int map_delblock_sub(struct block_list *, int); #define map_addblock(bl) map_addblock_sub(bl,1) #define map_delblock(bl) map_delblock_sub(bl,1) int map_moveblock(struct block_list *, int, int, unsigned int); -int map_foreachinrange(int (*)(struct block_list*,va_list),struct block_list *,int,int,...); -int map_foreachinshootrange(int (*)(struct block_list*,va_list),struct block_list *,int,int,...); -int map_foreachinarea(int (*)(struct block_list*,va_list),int,int,int,int,int,int,...); -// -- moonsoul (added map_foreachincell) -int map_foreachincell(int (*)(struct block_list*,va_list),int,int,int,int,...); -int map_foreachinmovearea(int (*)(struct block_list*,va_list),struct block_list*,int,int,int,int,...); -int map_foreachinpath(int (*func)(struct block_list*,va_list),int m,int x0,int y0,int x1,int y1,int range,int type,...); // Celest -int map_foreachinmap(int (*)(struct block_list*,va_list),int,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_foreachinarea(int (*func)(struct block_list*,va_list), int m, int x0, int y0, int x1, int y1, 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 type, ...); +int map_foreachinmap(int (*func)(struct block_list*,va_list), int m, int type, ...); int map_countnearpc(int,int,int); //block関連に追加 int map_count_oncell(int m,int x,int y,int type); diff --git a/src/map/script.c b/src/map/script.c index c3985a4a3..9e909cadb 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -10845,73 +10845,74 @@ BUILDIN_FUNC(misceffect) *------------------------------------------*/ BUILDIN_FUNC(soundeffect) { + TBL_PC* sd = script_rid2sd(st); + const char* name = script_getstr(st,2); + int type = script_getnum(st,3); - // Redundn - TBL_PC *sd=script_rid2sd(st); - const char *name; - int type=0; - - - name=script_getstr(st,2); - type=script_getnum(st,3); - if(sd){ + if(sd) + { if(!st->rid) clif_soundeffect(sd,map_id2bl(st->oid),name,type); - else{ + else clif_soundeffect(sd,&sd->bl,name,type); - } } return 0; } int soundeffect_sub(struct block_list* bl,va_list ap) { - char *name; - int type; - - nullpo_retr(0, bl); - nullpo_retr(0, ap); - - name = va_arg(ap,char *); - type = va_arg(ap,int); + char* name = va_arg(ap,char*); + int type = va_arg(ap,int); clif_soundeffect((TBL_PC *)bl, bl, name, type); return 0; } +/*========================================== + * Play a sound effect (.wav) on multiple clients + * soundeffectall "",{,""}{,,,,}; + *------------------------------------------*/ BUILDIN_FUNC(soundeffectall) { - // [Lance] - Improved. - const char *name, *map = NULL; - struct block_list *bl; - int type, coverage, x0, y0, x1, y1; + struct block_list* bl; + const char* name; + int type; - name=script_getstr(st,2); - type=script_getnum(st,3); - coverage=script_getnum(st,4); + bl = (st->rid) ? &(script_rid2sd(st)->bl) : map_id2bl(st->oid); + if (!bl) + return 0; - if(!st->rid) - bl = map_id2bl(st->oid); + name = script_getstr(st,2); + type = script_getnum(st,3); + + //FIXME: enumerating map squares (map_foreach) is slower than enumerating the list of online players (map_foreachpc?) + + if(!script_hasdata(st,4)) + { // area around + clif_soundeffectall(bl, name, type, AREA); + } else - bl = &(script_rid2sd(st)->bl); - - if(bl){ - if(coverage < 23){ - clif_soundeffectall(bl,name,type,coverage); - }else { - if(script_hasdata(st,9)){ - map= script_getstr(st,5); - x0 = script_getnum(st,6); - y0 = script_getnum(st,7); - x1 = script_getnum(st,8); - y1 = script_getnum(st,9); - map_foreachinarea(soundeffect_sub,map_mapname2mapid(map),x0,y0,x1,y1,BL_PC,name,type); - } else { - ShowError("buildin_soundeffectall: insufficient arguments for specific area broadcast.\n"); - } - } + if(!script_hasdata(st,5)) + { // entire map + const char* map = script_getstr(st,4); + map_foreachinmap(soundeffect_sub, map_mapname2mapid(map), BL_PC, name, type); + } + else + if(script_hasdata(st,9)) + { // specified part of map + const char* map = script_getstr(st,5); + int x0 = script_getnum(st,6); + int y0 = script_getnum(st,7); + int x1 = script_getnum(st,8); + int y1 = script_getnum(st,9); + map_foreachinarea(soundeffect_sub, map_mapname2mapid(map), x0, y0, x1, y1, BL_PC, name, type); } + else + { + ShowError("buildin_soundeffectall: insufficient arguments for specific area broadcast.\n"); + } + return 0; } /*========================================== -- cgit v1.2.3-70-g09d2