summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorskyleo <skyleo@skyleo.de>2019-09-12 00:33:54 +0200
committerHaru <haru@dotalux.com>2020-03-08 20:56:28 +0100
commit0817191184bd867836a7fcc30d65305b10964a5f (patch)
tree913c74483d2a29bb6a27a06affec9d573ec6316f
parent43bc7911460a53a2ebed4b54d81c473b9e6567b8 (diff)
downloadhercules-0817191184bd867836a7fcc30d65305b10964a5f.tar.gz
hercules-0817191184bd867836a7fcc30d65305b10964a5f.tar.bz2
hercules-0817191184bd867836a7fcc30d65305b10964a5f.tar.xz
hercules-0817191184bd867836a7fcc30d65305b10964a5f.zip
Change returning error-code in unit->walktoxy to obey code-style guidelines
-rw-r--r--src/map/elemental.c4
-rw-r--r--src/map/mob.c6
-rw-r--r--src/map/pet.c5
-rw-r--r--src/map/script.c17
-rw-r--r--src/map/skill.c2
-rw-r--r--src/map/unit.c28
6 files changed, 35 insertions, 27 deletions
diff --git a/src/map/elemental.c b/src/map/elemental.c
index 1c1d98634..e9b6fa372 100644
--- a/src/map/elemental.c
+++ b/src/map/elemental.c
@@ -788,8 +788,8 @@ static int elemental_ai_sub_timer(struct elemental_data *ed, struct map_session_
return 0; //Already walking to him
if( DIFF_TICK(tick, ed->ud.canmove_tick) < 0 )
return 0; //Can't move yet.
- if( map->search_freecell(&ed->bl, sd->bl.m, &x, &y, MIN_ELEDISTANCE, MIN_ELEDISTANCE, 1)
- && unit->walktoxy(&ed->bl, x, y, 0) )
+ if (map->search_freecell(&ed->bl, sd->bl.m, &x, &y, MIN_ELEDISTANCE, MIN_ELEDISTANCE, 1) != 0
+ && unit->walktoxy(&ed->bl, x, y, 0) == 0)
return 0;
}
diff --git a/src/map/mob.c b/src/map/mob.c
index 0830e5a5a..431bdbe0d 100644
--- a/src/map/mob.c
+++ b/src/map/mob.c
@@ -1462,7 +1462,7 @@ static int mob_ai_sub_hard_slavemob(struct mob_data *md, int64 tick)
// If master is BL_MOB and in battle, lock & chase to master's target instead, unless configured not to.
if ((battle_config.slave_chase_masters_chasetarget == 0 || (m_md != NULL && !mob->is_in_battle_state(m_md)))
&& map->search_freecell(&md->bl, bl->m, &x, &y, MOB_SLAVEDISTANCE, MOB_SLAVEDISTANCE, 1)
- && unit->walktoxy(&md->bl, x, y, 0))
+ && unit->walktoxy(&md->bl, x, y, 0) == 0)
return 1;
}
} else if (bl->m != md->bl.m && map_flag_gvg(md->bl.m)) {
@@ -1576,9 +1576,9 @@ static int mob_randomwalk(struct mob_data *md, int64 tick)
x+=md->bl.x;
y+=md->bl.y;
- if (((x != md->bl.x) || (y != md->bl.y)) && map->getcell(md->bl.m, &md->bl, x, y, CELL_CHKPASS) && unit->walktoxy(&md->bl, x, y, 8)) {
+ if ((x != md->bl.x || y != md->bl.y) && map->getcell(md->bl.m, &md->bl, x, y, CELL_CHKPASS) != 0
+ && unit->walktoxy(&md->bl, x, y, 8) == 0)
break;
- }
}
if(i==retrycount){
md->move_fail_count++;
diff --git a/src/map/pet.c b/src/map/pet.c
index f20de2650..0537baaa7 100644
--- a/src/map/pet.c
+++ b/src/map/pet.c
@@ -891,7 +891,8 @@ static int pet_randomwalk(struct pet_data *pd, int64 tick)
int r=rnd();
int x=pd->bl.x+r%(d*2+1)-d;
int y=pd->bl.y+r/(d*2+1)%(d*2+1)-d;
- if(map->getcell (pd->bl.m, &pd->bl, x, y, CELL_CHKPASS) && unit->walktoxy(&pd->bl, x, y, 0)) {
+ if (map->getcell(pd->bl.m, &pd->bl, x, y, CELL_CHKPASS) != 0
+ && unit->walktoxy(&pd->bl, x, y, 0) == 0) {
pd->move_fail_count=0;
break;
}
@@ -991,7 +992,7 @@ static int pet_ai_sub_hard(struct pet_data *pd, struct map_session_data *sd, int
return 0; //Already walking to him
unit->calc_pos(&pd->bl, sd->bl.x, sd->bl.y, sd->ud.dir);
- if(!unit->walktoxy(&pd->bl,pd->ud.to_x,pd->ud.to_y,0))
+ if (unit->walktoxy(&pd->bl, pd->ud.to_x, pd->ud.to_y, 0) != 0)
pet->randomwalk(pd,tick);
return 0;
diff --git a/src/map/script.c b/src/map/script.c
index 28d06a8f1..d6462384d 100644
--- a/src/map/script.c
+++ b/src/map/script.c
@@ -19680,7 +19680,7 @@ static BUILDIN(setunitdata)
unit->warp(bl, (short) val, (short) val2, (short) val3, CLR_TELEPORT);
break;
case UDT_WALKTOXY:
- if (!unit->walktoxy(bl, (short) val, (short) val2, 2))
+ if (unit->walktoxy(bl, (short)val, (short)val2, 2) != 0)
unit->movepos(bl, (short) val, (short) val2, 0, 0);
break;
case UDT_SPEED:
@@ -19851,7 +19851,7 @@ static BUILDIN(setunitdata)
unit->warp(bl, (short) val, (short) val2, (short) val3, CLR_TELEPORT);
break;
case UDT_WALKTOXY:
- if (!unit->walktoxy(bl, (short) val, (short) val2, 2))
+ if (unit->walktoxy(bl, (short)val, (short)val2, 2) != 0)
unit->movepos(bl, (short) val, (short) val2, 0, 0);
break;
case UDT_SPEED:
@@ -19990,7 +19990,7 @@ static BUILDIN(setunitdata)
unit->warp(bl, (short) val, (short) val2, (short) val3, CLR_TELEPORT);
break;
case UDT_WALKTOXY:
- if (!unit->walktoxy(bl, (short) val, (short) val2, 2))
+ if (unit->walktoxy(bl, (short)val, (short)val2, 2) != 0)
unit->movepos(bl, (short) val, (short) val2, 0, 0);
break;
case UDT_SPEED:
@@ -20123,7 +20123,7 @@ static BUILDIN(setunitdata)
unit->warp(bl, (short) val, (short) val2, (short) val3, CLR_TELEPORT);
break;
case UDT_WALKTOXY:
- if (!unit->walktoxy(bl, (short) val, (short) val2, 2))
+ if (unit->walktoxy(bl, (short)val, (short)val2, 2) != 0)
unit->movepos(bl, (short) val, (short) val2, 0, 0);
break;
case UDT_SPEED:
@@ -20257,7 +20257,7 @@ static BUILDIN(setunitdata)
unit->warp(bl, (short) val, (short) val2, (short) val3, CLR_TELEPORT);
break;
case UDT_WALKTOXY:
- if (!unit->walktoxy(bl, (short) val, (short) val2, 2))
+ if (unit->walktoxy(bl, (short)val, (short)val2, 2) != 0)
unit->movepos(bl, (short) val, (short) val2, 0, 0);
break;
case UDT_SPEED:
@@ -20386,7 +20386,7 @@ static BUILDIN(setunitdata)
unit->warp(bl, (short) val, (short) val2, (short) val3, CLR_TELEPORT);
break;
case UDT_WALKTOXY:
- if (!unit->walktoxy(bl, (short) val, (short) val2, 2))
+ if (unit->walktoxy(bl, (short)val, (short)val2, 2) != 0)
unit->movepos(bl, (short) val, (short) val2, 0, 0);
break;
case UDT_CLASS:
@@ -21121,7 +21121,10 @@ static BUILDIN(unitwalk)
if (script_hasdata(st, 4)) {
int x = script_getnum(st, 3);
int y = script_getnum(st, 4);
- script_pushint(st, unit->walktoxy(bl, x, y, 0));// We'll use harder calculations.
+ if (unit->walktoxy(bl, x, y, 0) == 0) // We'll use harder calculations.
+ script_pushint(st, 1);
+ else
+ script_pushint(st, 0);
}
else {
int target_id = script_getnum(st, 3);
diff --git a/src/map/skill.c b/src/map/skill.c
index 668c1849c..693cbfe2c 100644
--- a/src/map/skill.c
+++ b/src/map/skill.c
@@ -8080,7 +8080,7 @@ static int skill_castend_nodamage_id(struct block_list *src, struct block_list *
unit->stop_attack(src);
//Run skillv tiles overriding the can-move check.
if (unit->walktoxy(src, (src->x + skill_lv * -dirx[dir]),
- (src->y + skill_lv * -diry[dir]), 2) != 0 && md != NULL)
+ (src->y + skill_lv * -diry[dir]), 2) == 0 && md != NULL)
md->state.skillstate = MSS_WALK; //Otherwise it isn't updated in the AI.
}
break;
diff --git a/src/map/unit.c b/src/map/unit.c
index 9526a1f79..ba0dec9dc 100644
--- a/src/map/unit.c
+++ b/src/map/unit.c
@@ -519,43 +519,44 @@ static int unit_delay_walktoxy_timer(int tid, int64 tick, int id, intptr_t data)
//&2 -> force walking
//&4 -> Delay walking if the reason you can't walk is the canwalk delay
//&8 -> Search for an unoccupied cell and cancel if none available
+//@return 0: success, 1: failure
static int unit_walktoxy(struct block_list *bl, short x, short y, int flag)
{
struct unit_data* ud = NULL;
struct status_change* sc = NULL;
struct walkpath_data wpd;
- nullpo_ret(bl);
+ nullpo_retr(1, bl);
ud = unit->bl2ud(bl);
if (ud == NULL)
- return 0;
+ return 1;
if (battle_config.check_occupied_cells != 0 && (flag & 8) != 0 && !map->closest_freecell(bl->m, bl, &x, &y, BL_CHAR | BL_NPC, 1)) // This might change x and y
- return 0;
+ return 1;
if (!path->search(&wpd, bl, bl->m, bl->x, bl->y, x, y, flag&1, CELL_CHKNOPASS)) // Count walk path cells
- return 0;
+ return 1;
#ifdef OFFICIAL_WALKPATH
if( !path->search_long(NULL, bl, bl->m, bl->x, bl->y, x, y, CELL_CHKNOPASS) // Check if there is an obstacle between
&& (wpd.path_len > (battle_config.max_walk_path/17)*14) // Official number of walkable cells is 14 if and only if there is an obstacle between. [malufett]
&& (bl->type != BL_NPC) ) // If type is a NPC, please disregard.
- return 0;
+ return 1;
#endif
if ((wpd.path_len > battle_config.max_walk_path) && (bl->type != BL_NPC))
- return 0;
+ return 1;
if ((flag & 4) != 0 && DIFF_TICK(ud->canmove_tick, timer->gettick()) > 0 &&
DIFF_TICK(ud->canmove_tick, timer->gettick()) < 2000) {
// Delay walking command. [Skotlex]
timer->add(ud->canmove_tick + 1, unit->delay_walktoxy_timer, bl->id, (intptr_t)MakeDWord((uint16)x, (uint16)y));
- return 1;
+ return 0;
}
if ((flag & 2) == 0 && ((status_get_mode(bl) & MD_CANMOVE) == 0 || unit->can_move(bl) == 0))
- return 0;
+ return 1;
ud->state.walk_easy = flag&1;
ud->to_x = x;
@@ -576,7 +577,7 @@ static int unit_walktoxy(struct block_list *bl, short x, short y, int flag)
// When you come to the center of the grid because the change of destination while you're walking right now
// Call a function from a timer unit->walktoxy_sub
ud->state.change_walk_target = 1;
- return 1;
+ return 0;
}
return unit->walktoxy_sub(bl);
@@ -749,14 +750,14 @@ static bool unit_run(struct block_list *bl, struct map_session_data *sd, enum sc
return false;
}
- if( unit->walktoxy(bl, to_x, to_y, 1) )
+ if (unit->walktoxy(bl, to_x, to_y, 1) == 0)
return true;
//There must be an obstacle nearby. Attempt walking one cell at a time.
do {
to_x -= dir_x;
to_y -= dir_y;
- } while (--i > 0 && !unit->walktoxy(bl, to_x, to_y, 1));
+ } while (--i > 0 && unit->walktoxy(bl, to_x, to_y, 1) != 0);
if ( i == 0 ) {
unit->run_hit(bl, sc, sd, type);
@@ -774,7 +775,10 @@ static int unit_escape(struct block_list *bl, struct block_list *target, short d
Assert_retr(1, dir >= UNIT_DIR_FIRST && dir < UNIT_DIR_MAX);
while (dist > 0 && map->getcell(bl->m, bl, bl->x + dist * dirx[dir], bl->y + dist * diry[dir], CELL_CHKNOREACH))
dist--;
- return ( dist > 0 && unit->walktoxy(bl, bl->x + dist*dirx[dir], bl->y + dist*diry[dir], 0) );
+ if (dist > 0 && unit->walktoxy(bl, bl->x + dist * dirx[dir], bl->y + dist * diry[dir], 0) == 0)
+ return 1;
+ else
+ return 0;
}
//Instant warp function.