summaryrefslogtreecommitdiff
path: root/src/map/unit.c
diff options
context:
space:
mode:
authorskotlex <skotlex@54d463be-8e91-2dee-dedb-b68131a5f0ec>2006-03-24 18:20:55 +0000
committerskotlex <skotlex@54d463be-8e91-2dee-dedb-b68131a5f0ec>2006-03-24 18:20:55 +0000
commitdc3d23e60aaad210be711844ab24b3a0a2b113aa (patch)
tree66c7b2bd3cb80ec53091059ebdc674ed03791629 /src/map/unit.c
parentaf0c947f3ce68479a1d41612ace459e74dead363 (diff)
downloadhercules-dc3d23e60aaad210be711844ab24b3a0a2b113aa.tar.gz
hercules-dc3d23e60aaad210be711844ab24b3a0a2b113aa.tar.bz2
hercules-dc3d23e60aaad210be711844ab24b3a0a2b113aa.tar.xz
hercules-dc3d23e60aaad210be711844ab24b3a0a2b113aa.zip
- Added function map_search_freecell to locate an available cell around an area (for recall/warping skills)
git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@5732 54d463be-8e91-2dee-dedb-b68131a5f0ec
Diffstat (limited to 'src/map/unit.c')
-rw-r--r--src/map/unit.c36
1 files changed, 19 insertions, 17 deletions
diff --git a/src/map/unit.c b/src/map/unit.c
index f41796d26..1e2e2268b 100644
--- a/src/map/unit.c
+++ b/src/map/unit.c
@@ -393,7 +393,6 @@ int unit_getdir(struct block_list *bl)
//it respects the no warp flags, so it is safe to call this without doing nowarpto/nowarp checks.
int unit_warp(struct block_list *bl,int m,int x,int y,int type)
{
- int i=0,xs=9,ys=9,bx=x,by=y;
struct unit_data *ud;
nullpo_retr(0, bl);
ud = unit_bl2ud(bl);
@@ -419,25 +418,28 @@ int unit_warp(struct block_list *bl,int m,int x,int y,int type)
break;
}
- if(bx>0 && by>0)
- xs=ys=9;
-
- while( ( x<0 || y<0 || map_getcell(m,x,y,CELL_CHKNOPASS)) && (i++)<1000 ){
- if( xs>0 && ys>0 && i<250 ){
- x=bx+rand()%xs-xs/2;
- y=by+rand()%ys-ys/2;
- }else{
- x=rand()%(map[m].xs-2)+1;
- y=rand()%(map[m].ys-2)+1;
+ if (x<0 || y<0)
+ { //Random map position.
+
+ if (!map_search_freecell(NULL, m, &x, &y, -1, -1, 1)) {
+ if(battle_config.error_log)
+ ShowWarning("unit_warp failed. Unit Id:%d/Type:%d, target position map %d (%s) at [%d,%d]\n", bl->id, bl->type, m, map[m].name, x, y);
+ return 2;
+
}
- }
-
- if(i>=1000){
+ } else if (map_getcell(m,x,y,CELL_CHKNOREACH))
+ { //Invalid target cell
if(battle_config.error_log)
- ShowWarning("unit_warp failed. Unit Id:%d/Type:%d, target position map %d (%s) at [%d,%d]\n", bl->id, bl->type, m, map[m].name, bx,by);
- return 2;
+ ShowWarning("unit_warp: Specified non-walkable target cell: %d (%s) at [%d,%d]\n", m, map[m].name, x,y);
+
+ if (!map_search_freecell(NULL, m, &x, &y, 4, 4, 1))
+ { //Can't find a nearby cell
+ if(battle_config.error_log)
+ ShowWarning("unit_warp failed. Unit Id:%d/Type:%d, target position map %d (%s) at [%d,%d]\n", bl->id, bl->type, m, map[m].name, x, y);
+ return 2;
+ }
}
-
+
if (bl->type == BL_PC) //Use pc_setpos
return pc_setpos((TBL_PC*)bl, map[m].index, x, y, type);