From f7486e71c12041b5d50af8570f5e6023d8e03532 Mon Sep 17 00:00:00 2001 From: Lemongrass3110 Date: Thu, 22 Jun 2017 15:54:18 +0200 Subject: [PATCH] areawarp cleanup --- doc/script_commands.txt | 12 ++++---- src/map/script.c | 61 +++++++++++++++++++++++++---------------- 2 files changed, 45 insertions(+), 28 deletions(-) diff --git a/doc/script_commands.txt b/doc/script_commands.txt index 8570b9508f..2b3015a8be 100644 --- a/doc/script_commands.txt +++ b/doc/script_commands.txt @@ -3889,7 +3889,7 @@ There are also three special 'map names' you can use. --------------------------------------- -*areawarp "",,,,,"",,{,,}; +*areawarp "",,,,,""{,,,,}; This command is similar to 'warp', however, it will not refer to the invoking character, but instead, all characters within a specified area, defined by the @@ -3903,8 +3903,9 @@ shape, on the map called "place", will be affected, and warped to "place2" X 150 Y 150 areawarp "place",10,10,120,120,"place2",0,0; + areawarp "place",10,10,120,120,"place2"; -By using ,0,0; as the destination coordinates it will take all the characters in +By using zeroes as the destination coordinates or leaving them out it will take all the characters in the affected area to a random set of co-ordinates on "place2". areawarp "place",10,10,120,120,"place2",150,150,200,200; @@ -3912,12 +3913,13 @@ the affected area to a random set of co-ordinates on "place2". By using the optional x4 and y4 parameters, the destination coordinates will be a random place within the defined x3/y3-x4/y4 square. -There are also three special 'map names' you can use. +There are also three special 'map names' you can use: "Random" will warp the player randomly on the current map. "Save" and "SavePoint" will warp the player back to their save point. -Use 0,0 as the x3/y3 values when using a special 'map name'. +It is recommended that you do not supply any target coordinates if you use one of +these maps because they will be ignored anyway. See also 'warp'. @@ -6874,7 +6876,7 @@ There are also three special 'map names' you can use for : "Save" and "SavePoint" will warp the player back to their save point. It is recommended that you do not supply any target coordinates if you use one of -these maps, because they will be ignored anyway. +these maps because they will be ignored anyway. --------------------------------------- \\ diff --git a/src/map/script.c b/src/map/script.c index cf654bc357..fb9c3e7bdd 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -5687,25 +5687,23 @@ BUILDIN_FUNC(warp) * Warp a specified area * @param bl: Player to warp * @param va_list: map index, x2, xy2, x3, y3, warp type - * @return 0 on success and failure otherwise + * @return 0 on success and 1 in case of failure */ static int buildin_areawarp_sub(struct block_list *bl,va_list ap) { int16 x2,y2,x3,y3; - unsigned int index; - const char *str; + const char *mapname; - index = va_arg(ap,unsigned int); x2 = (int16)va_arg(ap,int); y2 = (int16)va_arg(ap,int); x3 = (int16)va_arg(ap,int); y3 = (int16)va_arg(ap,int); - str = va_arg(ap, char *); + mapname = va_arg(ap, char *); if (x3 && y3) { // Warp within given area int16 max, tx, ty, j = 0, m; - m = map_mapindex2mapid(index); + m = map_mapname2mapid(mapname); // choose a suitable max number of attempts if( (max = (y3-y2+1)*(x3-x2+1)*3) > MAX_WARP_ATTEMPTS ) @@ -5715,36 +5713,53 @@ static int buildin_areawarp_sub(struct block_list *bl,va_list ap) do { tx = rnd()%(x3-x2+1)+x2; ty = rnd()%(y3-y2+1)+y2; - } while (map_getcell(m, tx, ty, CELL_CHKNOPASS) && (j++) < max); + } while ((map_getcell(m, tx, ty, CELL_CHKNOPASS) || (!battle_config.teleport_on_portal && npc_check_areanpc(1, m, tx, ty, 1))) && (j++) < max); + + if (j == max){ + return 1; + } - if (buildin_warp_sub((TBL_PC *)bl, str, tx, ty)) - return 1; - } else { // Warp to set location - if (buildin_warp_sub((TBL_PC *)bl, str, x2, y2)) - return 1; + x2 = tx; + y2 = ty; } + + if (buildin_warp_sub((TBL_PC *)bl, mapname, x2, y2) != SETPOS_OK) + return 1; + return 0; } /** * Warp a given area of a map - * areawarp "",,,,,"",,{,,}; + * areawarp "",,,,,"",{,,,}; */ BUILDIN_FUNC(areawarp) { - int16 m, x0,y0,x1,y1, x2,y2,x3=0,y3=0; + int16 m, x0,y0,x1,y1, x2,y2,x3,y3; const char *str; const char *mapname; mapname = script_getstr(st,2); + + if ((m = map_mapname2mapid(mapname)) < 0){ + ShowError( "buildin_areawarp: Unknown source map \"%s\"\n", mapname ); + return SCRIPT_CMD_FAILURE; + } + x0 = script_getnum(st,3); y0 = script_getnum(st,4); x1 = script_getnum(st,5); y1 = script_getnum(st,6); str = script_getstr(st,7); - x2 = script_getnum(st,8); - y2 = script_getnum(st,9); - + + if (script_hasdata(st,9)){ + x2 = script_getnum(st,8); + y2 = script_getnum(st,9); + }else{ + x2 = 0; + y2 = 0; + } + if( script_hasdata(st,10) && script_hasdata(st,11) ) { // Warp area to area if( (x3 = script_getnum(st,10)) < 0 || (y3 = script_getnum(st,11)) < 0 ){ x3 = 0; @@ -5754,12 +5769,12 @@ BUILDIN_FUNC(areawarp) if( x3 < x2 ) swap(x3,x2); if( y3 < y2 ) swap(y3,y2); } + }else{ + x3 = 0; + y3 = 0; } - if ((m = map_mapname2mapid(mapname)) < 0) - return SCRIPT_CMD_FAILURE; - - map_foreachinallarea(buildin_areawarp_sub, m, x0, y0, x1, y1, BL_PC, mapindex_name2id(str), x2, y2, x3, y3, str); + map_foreachinallarea(buildin_areawarp_sub, m, x0, y0, x1, y1, BL_PC, x2, y2, x3, y3, str); return SCRIPT_CMD_SUCCESS; } @@ -13165,7 +13180,7 @@ BUILDIN_FUNC(mapwarp) switch (type) { case MAPWARP_ALL: - map_foreachinmap(buildin_areawarp_sub, m, BL_PC, mapindex_name2id(str), x, y, 0, 0, str); + map_foreachinmap(buildin_areawarp_sub, m, BL_PC, x, y, 0, 0, str); break; case MAPWARP_GUILD: g = guild_search(type_id); @@ -23199,7 +23214,7 @@ struct script_function buildin_func[] = { BUILDIN_DEF(input,"r??"), BUILDIN_DEF(warp,"sii?"), BUILDIN_DEF2(warp, "warpchar", "sii?"), - BUILDIN_DEF(areawarp,"siiiisii??"), + BUILDIN_DEF(areawarp,"siiiis????"), BUILDIN_DEF(warpparty,"siii???"), // [Fredzilla] [Paradox924X] BUILDIN_DEF(warpguild,"siii"), // [Fredzilla] BUILDIN_DEF(setlook,"ii?"),