summaryrefslogtreecommitdiff
path: root/src/map/mob.c
diff options
context:
space:
mode:
authorskotlex <skotlex@54d463be-8e91-2dee-dedb-b68131a5f0ec>2006-05-04 16:44:15 +0000
committerskotlex <skotlex@54d463be-8e91-2dee-dedb-b68131a5f0ec>2006-05-04 16:44:15 +0000
commit11c193241c6b1b45814ac8c4fb44842da9a42e46 (patch)
tree8922ccd36e7a20c8a36603c4fd6276f1a7c82fd3 /src/map/mob.c
parenta8ed5bce482007aa96ff5f6674d6dfe6bbfaa487 (diff)
downloadhercules-11c193241c6b1b45814ac8c4fb44842da9a42e46.tar.gz
hercules-11c193241c6b1b45814ac8c4fb44842da9a42e46.tar.bz2
hercules-11c193241c6b1b45814ac8c4fb44842da9a42e46.tar.xz
hercules-11c193241c6b1b45814ac8c4fb44842da9a42e46.zip
- Cleaned up the mob-random-walking code.
git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@6468 54d463be-8e91-2dee-dedb-b68131a5f0ec
Diffstat (limited to 'src/map/mob.c')
-rw-r--r--src/map/mob.c79
1 files changed, 37 insertions, 42 deletions
diff --git a/src/map/mob.c b/src/map/mob.c
index e56163ce9..e05d8e2b6 100644
--- a/src/map/mob.c
+++ b/src/map/mob.c
@@ -982,46 +982,48 @@ int mob_unlocktarget(struct mob_data *md,int tick)
int mob_randomwalk(struct mob_data *md,int tick)
{
const int retrycount=20;
+ int i,x,y,c,d;
int speed;
nullpo_retr(0, md);
- if(DIFF_TICK(md->next_walktime,tick)<0 && unit_can_move(&md->bl)){
- int i,x,y,c,d=12-md->move_fail_count;
- speed=status_get_speed(&md->bl);
- if(d<5) d=5;
- for(i=0;i<retrycount;i++){ // Search of a movable place
- int r=rand();
- x=r%(d*2+1)-d;
- y=r/(d*2+1)%(d*2+1)-d;
- x+=md->bl.x;
- y+=md->bl.y;
-
- if((map_getcell(md->bl.m,x,y,CELL_CHKPASS)) && unit_walktoxy(&md->bl,x,y,1)){
- md->move_fail_count=0;
- break;
- }
- if(i+1>=retrycount){
- md->move_fail_count++;
- if(md->move_fail_count>1000){
- if(battle_config.error_log)
- ShowWarning("MOB cant move. random spawn %d, class = %d\n",md->bl.id,md->class_);
- md->move_fail_count=0;
- mob_spawn(md);
- }
- }
+ if(DIFF_TICK(md->next_walktime,tick)>0 || !unit_can_move(&md->bl))
+ return 0;
+
+ d =12-md->move_fail_count;
+ if(d<5) d=5;
+ for(i=0;i<retrycount;i++){ // Search of a movable place
+ int r=rand();
+ x=r%(d*2+1)-d;
+ y=r/(d*2+1)%(d*2+1)-d;
+ x+=md->bl.x;
+ y+=md->bl.y;
+
+ if((map_getcell(md->bl.m,x,y,CELL_CHKPASS)) && unit_walktoxy(&md->bl,x,y,1)){
+ break;
}
- for(i=c=0;i<md->ud.walkpath.path_len;i++){ // The next walk start time is calculated.
- if(md->ud.walkpath.path[i]&1)
- c+=speed*14/10;
- else
- c+=speed;
+ }
+ if(i==retrycount){
+ md->move_fail_count++;
+ if(md->move_fail_count>1000){
+ if(battle_config.error_log)
+ ShowWarning("MOB cant move. random spawn %d, class = %d\n",md->bl.id,md->class_);
+ md->move_fail_count=0;
+ mob_spawn(md);
}
- md->next_walktime = tick+rand()%3000+3000+c;
- md->state.skillstate=MSS_WALK;
- return 1;
+ return 0;
}
- return 0;
+ speed=status_get_speed(&md->bl);
+ for(i=c=0;i<md->ud.walkpath.path_len;i++){ // The next walk start time is calculated.
+ if(md->ud.walkpath.path[i]&1)
+ c+=speed*14/10;
+ else
+ c+=speed;
+ }
+ md->state.skillstate=MSS_WALK;
+ md->move_fail_count=0;
+ md->next_walktime = tick+rand()%3000+3000+c;
+ return 1;
}
/*==========================================
@@ -1259,15 +1261,8 @@ static int mob_ai_sub_hard(struct block_list *bl,va_list ap)
}
// Nothing else to do... except random walking.
// Slaves do not random walk! [Skotlex]
- if (can_move && !md->master_id)
- {
- if (DIFF_TICK(md->next_walktime, tick) > 7000 &&
- (md->ud.walkpath.path_len == 0 || md->ud.walkpath.path_pos >= md->ud.walkpath.path_len))
- md->next_walktime = tick + 3000 + rand() % 2000;
- // Random movement
- if (mob_randomwalk(md,tick))
- return 0;
- }
+ if (can_move && !md->master_id && DIFF_TICK(md->next_walktime, tick) <= 0)
+ mob_randomwalk(md,tick);
return 0;
}