summaryrefslogtreecommitdiff
path: root/src/map/unit.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/map/unit.c')
-rw-r--r--src/map/unit.c26
1 files changed, 18 insertions, 8 deletions
diff --git a/src/map/unit.c b/src/map/unit.c
index c05b8e25a..f09444b4c 100644
--- a/src/map/unit.c
+++ b/src/map/unit.c
@@ -317,6 +317,11 @@ int unit_walktoxy( struct block_list *bl, int x, int y, int flag)
return unit_walktoxy_sub(bl);
}
+//To set Mob's CHASE/FOLLOW states (shouldn't be done if there's no path to reach)
+#define set_mobstate(bl, flag) \
+ if((bl)->type == BL_MOB && (flag)) \
+ ((TBL_MOB*)(bl))->state.skillstate = ((TBL_MOB*)(bl))->state.aggressive?MSS_FOLLOW:MSS_RUSH;
+
static int unit_walktobl_sub(int tid,unsigned int tick,int id,int data)
{
struct block_list *bl = map_id2bl(id);
@@ -327,7 +332,10 @@ static int unit_walktobl_sub(int tid,unsigned int tick,int id,int data)
if (DIFF_TICK(ud->canmove_tick, tick) > 0) //Keep waiting?
add_timer(ud->canmove_tick+1, unit_walktobl_sub, id, data);
else if (unit_can_move(bl))
- unit_walktoxy_sub(bl);
+ {
+ if (unit_walktoxy_sub(bl))
+ set_mobstate(bl, ud->state.attack_continue);
+ }
}
return 0;
}
@@ -361,13 +369,10 @@ int unit_walktobl(struct block_list *bl, struct block_list *tbl, int range, int
sc = status_get_sc(bl);
if (sc && sc->count && sc->data[SC_CONFUSION].timer != -1) //Randomize the target position
map_random_dir(bl, &ud->to_x, &ud->to_y);
-
- //Set Mob's CHASE/FOLLOW states.
- if(bl->type == BL_MOB && flag&2)
- ((TBL_MOB*)bl)->state.skillstate = ((TBL_MOB*)bl)->state.aggressive?MSS_FOLLOW:MSS_RUSH;
if(ud->walktimer != -1) {
ud->state.change_walk_target = 1;
+ set_mobstate(bl, flag&2);
return 1;
}
@@ -385,8 +390,13 @@ int unit_walktobl(struct block_list *bl, struct block_list *tbl, int range, int
ud->attacktimer = -1;
}
- return unit_walktoxy_sub(bl);
+ if (unit_walktoxy_sub(bl)) {
+ set_mobstate(bl, flag&2);
+ return 1;
+ }
+ return 0;
}
+#undef set_mobstate
int unit_run(struct block_list *bl)
{
@@ -1317,9 +1327,9 @@ int unit_can_reach_bl(struct block_list *bl,struct block_list *tbl, int range, i
dx=(dx>0)?1:((dx<0)?-1:0);
dy=(dy>0)?1:((dy<0)?-1:0);
- if (map_getcell(tbl->m,tbl->x-dx,tbl->y-dy,CELL_CHKNOREACH))
+ if (map_getcell(tbl->m,tbl->x-dx,tbl->y-dy,CELL_CHKNOPASS))
{ //Look for a suitable cell to place in.
- for(i=0;i<9 && map_getcell(tbl->m,tbl->x-dirx[i],tbl->y-diry[i],CELL_CHKNOREACH);i++);
+ for(i=0;i<9 && map_getcell(tbl->m,tbl->x-dirx[i],tbl->y-diry[i],CELL_CHKNOPASS);i++);
if (i==9) return 0; //No valid cells.
dx = dirx[i];
dy = diry[i];