Browse Source

` Changed areawarp script command to accept two additional, yet optional, parameters to allow an area warp to an area (instead of just a specific coordinates). See documentation.

git-svn-id: https://svn.code.sf.net/p/rathena/svn/trunk@16636 54d463be-8e91-2dee-dedb-b68131a5f0ec
xantara 12 years ago
parent
commit
0b2fa50754
2 changed files with 58 additions and 23 deletions
  1. 6 1
      doc/script_commands.txt
  2. 52 22
      src/map/script.c

+ 6 - 1
doc/script_commands.txt

@@ -3701,7 +3701,7 @@ There are also three special 'map names' you can use.
 
 
 ---------------------------------------
 ---------------------------------------
 
 
-*areawarp "<from map name>",<x1>,<y1>,<x2>,<y2>,"<to map name>",<x3>,<y3>;
+*areawarp "<from map name>",<x1>,<y1>,<x2>,<y2>,"<to map name>",<x3>,<y3>{,<x4>,<y4>};
 
 
 This command is similar to 'warp', however, it will not refer to the invoking 
 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 
 character, but instead, all characters within a specified area, defined by the 
@@ -3719,6 +3719,11 @@ Y 150
 By using ,0,0; as the destination coordinates it will take all the characters in 
 By using ,0,0; as the destination coordinates it will take all the characters in 
 the affected area to a random set of co-ordinates on "place2".
 the affected area to a random set of co-ordinates on "place2".
 
 
+	areawarp "place",10,10,120,120,"place2",150,150,200,200;
+
+By using the optional x4 and y4 parameters, the destination coordinates will be a 
+random place within the defined x3/y3-x4/y4 square.
+
 Like 'warp', areawarp will also explicitly warp characters randomly into the 
 Like 'warp', areawarp will also explicitly warp characters randomly into the 
 current map if you give the 'to map name' as "Random".
 current map if you give the 'to map name' as "Random".
 
 

+ 52 - 22
src/map/script.c

@@ -5008,43 +5008,73 @@ BUILDIN_FUNC(warp)
  *------------------------------------------*/
  *------------------------------------------*/
 static int buildin_areawarp_sub(struct block_list *bl,va_list ap)
 static int buildin_areawarp_sub(struct block_list *bl,va_list ap)
 {
 {
-	int x,y;
-	unsigned int map;
-	map=va_arg(ap, unsigned int);
-	x=va_arg(ap,int);
-	y=va_arg(ap,int);
-	if(map == 0)
+	int x2,y2,x3,y3;
+	unsigned int index;
+	
+	index = va_arg(ap,unsigned int);
+	x2 = va_arg(ap,int);
+	y2 = va_arg(ap,int);
+	x3 = va_arg(ap,int);
+	y3 = va_arg(ap,int);
+	
+	if(index == 0)
 		pc_randomwarp((TBL_PC *)bl,CLR_TELEPORT);
 		pc_randomwarp((TBL_PC *)bl,CLR_TELEPORT);
+	else if(x3 && y3) {
+		int max, tx, ty, j = 0;
+		
+		// choose a suitable max number of attempts
+		if( (max = (y3-y2+1)*(x3-x2+1)*3) > 1000 )
+			max = 1000;
+		
+		// find a suitable map cell
+		do {
+			tx = rnd()%(x3-x2+1)+x2;
+			ty = rnd()%(y3-y2+1)+y2;
+			j++;
+		} while( map_getcell(index,tx,ty,CELL_CHKNOPASS) && j < max );
+		
+		pc_setpos((TBL_PC *)bl,index,tx,ty,CLR_OUTSIGHT);
+	}
 	else
 	else
-		pc_setpos((TBL_PC *)bl,map,x,y,CLR_OUTSIGHT);
+		pc_setpos((TBL_PC *)bl,index,x2,y2,CLR_OUTSIGHT);
 	return 0;
 	return 0;
 }
 }
 BUILDIN_FUNC(areawarp)
 BUILDIN_FUNC(areawarp)
 {
 {
-	int x,y,m;
+	int m, x0,y0,x1,y1, x2,y2,x3=0,y3=0;
 	unsigned int index;
 	unsigned int index;
 	const char *str;
 	const char *str;
 	const char *mapname;
 	const char *mapname;
-	int x0,y0,x1,y1;
 
 
-	mapname=script_getstr(st,2);
-	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);
-	x=script_getnum(st,8);
-	y=script_getnum(st,9);
+	mapname = script_getstr(st,2);
+	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,10) && script_hasdata(st,11) ) { // Warp area to area
+		if( (x3 = script_getnum(st,10)) < 0 || (y3 = script_getnum(st,11)) < 0 ){
+			x3 = 0;
+			y3 = 0;
+		} else if( x3 && y3 ) {
+			// normalize x3/y3 coordinates
+			if( x3 < x2 ) swap(x3,x2);
+			if( y3 < y2 ) swap(y3,y2);
+		}
+	}
 
 
-	if( (m=map_mapname2mapid(mapname))< 0)
+	if( (m = map_mapname2mapid(mapname)) < 0 )
 		return 0;
 		return 0;
 
 
-	if(strcmp(str,"Random")==0)
+	if( strcmp(str,"Random") == 0 )
 		index = 0;
 		index = 0;
-	else if(!(index=mapindex_name2id(str)))
+	else if( !(index=mapindex_name2id(str)) )
 		return 0;
 		return 0;
 
 
-	map_foreachinarea(buildin_areawarp_sub, m,x0,y0,x1,y1,BL_PC, index,x,y);
+	map_foreachinarea(buildin_areawarp_sub, m,x0,y0,x1,y1, BL_PC, index,x2,y2,x3,y3);
 	return 0;
 	return 0;
 }
 }
 
 
@@ -16914,7 +16944,7 @@ struct script_function buildin_func[] = {
 	BUILDIN_DEF(jobname,"i"),
 	BUILDIN_DEF(jobname,"i"),
 	BUILDIN_DEF(input,"r??"),
 	BUILDIN_DEF(input,"r??"),
 	BUILDIN_DEF(warp,"sii"),
 	BUILDIN_DEF(warp,"sii"),
-	BUILDIN_DEF(areawarp,"siiiisii"),
+	BUILDIN_DEF(areawarp,"siiiisii??"),
 	BUILDIN_DEF(warpchar,"siii"), // [LuzZza]
 	BUILDIN_DEF(warpchar,"siii"), // [LuzZza]
 	BUILDIN_DEF(warpparty,"siii?"), // [Fredzilla] [Paradox924X]
 	BUILDIN_DEF(warpparty,"siii?"), // [Fredzilla] [Paradox924X]
 	BUILDIN_DEF(warpguild,"siii"), // [Fredzilla]
 	BUILDIN_DEF(warpguild,"siii"), // [Fredzilla]