Compare commits

...

6 Commits

Author SHA1 Message Date
Aleos
5083913e0c
Merge branch 'master' into hotfix/issue1950 2018-08-27 20:38:13 -04:00
aleos89
2f557bbbb1 Merge branch 'master' into hotfix/issue1950 2017-11-03 13:20:53 -04:00
aleos89
fad4a81c6d Merge branch 'master' into hotfix/issue1950 2017-09-21 13:47:55 -04:00
aleos
aedb38771a Removed a flag check
* Removed an unneeded check for finding an empty cell for homunculus.
2017-08-09 16:19:55 -04:00
aleos
e1a8f0b7ef Follow up to 80a6932
* Fixed a compile error.
2017-08-08 19:00:30 -04:00
aleos
80a6932658 Updated homunculus walk behavior
* Fixes #1950.
* Updated homunculus walk behavior to closer mimic official behavior.
* Homunculus will now stop in a random 3x3 area around the master.
* Homunculus will no longer get stuck when looking for an empty cell when supporting the master during attacks.
Thanks to @dragonis1701!
2017-08-08 18:54:12 -04:00
7 changed files with 13 additions and 67 deletions

View File

@ -14776,7 +14776,7 @@ void clif_parse_HomMoveToMaster(int fd, struct map_session_data *sd){
else else
return; return;
unit_calc_pos(bl, sd->bl.x, sd->bl.y, sd->ud.dir); unit_calc_pos(bl, sd->bl.x, sd->bl.y);
ud = unit_bl2ud(bl); ud = unit_bl2ud(bl);
unit_walktoxy(bl, ud->to_x, ud->to_y, 4); unit_walktoxy(bl, ud->to_x, ud->to_y, 4);
} }

View File

@ -248,7 +248,7 @@ int elemental_data_received(struct s_elemental *ele, bool flag) {
ed->bl.m = sd->bl.m; ed->bl.m = sd->bl.m;
ed->bl.x = sd->bl.x; ed->bl.x = sd->bl.x;
ed->bl.y = sd->bl.y; ed->bl.y = sd->bl.y;
unit_calc_pos(&ed->bl, sd->bl.x, sd->bl.y, sd->ud.dir); unit_calc_pos(&ed->bl, sd->bl.x, sd->bl.y);
ed->bl.x = ed->ud.to_x; ed->bl.x = ed->ud.to_x;
ed->bl.y = ed->ud.to_y; ed->bl.y = ed->ud.to_y;

View File

@ -1034,7 +1034,7 @@ void hom_alloc(struct map_session_data *sd, struct s_homunculus *hom)
hd->bl.m = sd->bl.m; hd->bl.m = sd->bl.m;
hd->bl.x = sd->bl.x; hd->bl.x = sd->bl.x;
hd->bl.y = sd->bl.y; hd->bl.y = sd->bl.y;
unit_calc_pos(&hd->bl, sd->bl.x, sd->bl.y, sd->ud.dir); unit_calc_pos(&hd->bl, sd->bl.x, sd->bl.y);
hd->bl.x = hd->ud.to_x; hd->bl.x = hd->ud.to_x;
hd->bl.y = hd->ud.to_y; hd->bl.y = hd->ud.to_y;

View File

@ -385,7 +385,7 @@ bool mercenary_recv_data(struct s_mercenary *merc, bool flag)
md->bl.m = sd->bl.m; md->bl.m = sd->bl.m;
md->bl.x = sd->bl.x; md->bl.x = sd->bl.x;
md->bl.y = sd->bl.y; md->bl.y = sd->bl.y;
unit_calc_pos(&md->bl, sd->bl.x, sd->bl.y, sd->ud.dir); unit_calc_pos(&md->bl, sd->bl.x, sd->bl.y);
md->bl.x = md->ud.to_x; md->bl.x = md->ud.to_x;
md->bl.y = md->ud.to_y; md->bl.y = md->ud.to_y;

View File

@ -461,7 +461,7 @@ bool pet_data_init(struct map_session_data *sd, struct s_pet *pet)
pd->bl.m = sd->bl.m; pd->bl.m = sd->bl.m;
pd->bl.x = sd->bl.x; pd->bl.x = sd->bl.x;
pd->bl.y = sd->bl.y; pd->bl.y = sd->bl.y;
unit_calc_pos(&pd->bl, sd->bl.x, sd->bl.y, sd->ud.dir); unit_calc_pos(&pd->bl, sd->bl.x, sd->bl.y);
pd->bl.x = pd->ud.to_x; pd->bl.x = pd->ud.to_x;
pd->bl.y = pd->ud.to_y; pd->bl.y = pd->ud.to_y;
@ -1175,7 +1175,7 @@ static int pet_ai_sub_hard(struct pet_data *pd, struct map_session_data *sd, uns
if(pd->ud.walktimer != INVALID_TIMER && check_distance_blxy(&sd->bl, pd->ud.to_x,pd->ud.to_y, 3)) if(pd->ud.walktimer != INVALID_TIMER && check_distance_blxy(&sd->bl, pd->ud.to_x,pd->ud.to_y, 3))
return 0; // Already walking to him return 0; // Already walking to him
unit_calc_pos(&pd->bl, sd->bl.x, sd->bl.y, sd->ud.dir); unit_calc_pos(&pd->bl, sd->bl.x, sd->bl.y);
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))
pet_randomwalk(pd,tick); pet_randomwalk(pd,tick);

View File

@ -2436,79 +2436,25 @@ bool unit_can_reach_bl(struct block_list *bl,struct block_list *tbl, int range,
* @param bl: Object to calculate position * @param bl: Object to calculate position
* @param tx: X coordinate to go to * @param tx: X coordinate to go to
* @param ty: Y coordinate to go to * @param ty: Y coordinate to go to
* @param dir: Direction which to be 2 cells from master's position
* @return Success(0); Fail(1); * @return Success(0); Fail(1);
*/ */
int unit_calc_pos(struct block_list *bl, int tx, int ty, uint8 dir) int unit_calc_pos(struct block_list *bl, int tx, int ty)
{ {
int dx, dy, x, y;
struct unit_data *ud = unit_bl2ud(bl); struct unit_data *ud = unit_bl2ud(bl);
nullpo_ret(ud); nullpo_ret(ud);
if(dir > 7)
return 1;
ud->to_x = tx; ud->to_x = tx;
ud->to_y = ty; ud->to_y = ty;
// 2 cells from Master Position map_search_freecell(bl, bl->m, &ud->to_x, &ud->to_y, 3, 3, 1|2);
dx = -dirx[dir] * 2;
dy = -diry[dir] * 2;
x = tx + dx;
y = ty + dy;
if( !unit_can_reach_pos(bl, x, y, 0) ) { if (!unit_can_reach_pos(bl, ud->to_x, ud->to_y, 0)) { // Attempt once more
if( dx > 0 ) map_search_freecell(bl, bl->m, &ud->to_x, &ud->to_y, 3, 3, 1|2);
x--;
else if( dx < 0 )
x++;
if( dy > 0 ) if (!unit_can_reach_pos(bl, ud->to_x, ud->to_y, 0))
y--;
else if( dy < 0 )
y++;
if( !unit_can_reach_pos(bl, x, y, 0) ) {
int i;
for( i = 0; i < 12; i++ ) {
int k = rnd()%8; // Pick a Random Dir
dx = -dirx[k] * 2;
dy = -diry[k] * 2;
x = tx + dx;
y = ty + dy;
if( unit_can_reach_pos(bl, x, y, 0) )
break;
else {
if( dx > 0 )
x--;
else if( dx < 0 )
x++;
if( dy > 0 )
y--;
else if( dy < 0 )
y++;
if( unit_can_reach_pos(bl, x, y, 0) )
break;
}
}
if( i == 12 ) {
x = tx; y = tx; // Exactly Master Position
if( !unit_can_reach_pos(bl, x, y, 0) )
return 1; return 1;
} }
}
}
ud->to_x = x;
ud->to_y = y;
return 0; return 0;
} }

View File

@ -109,7 +109,7 @@ int unit_walktoxy(struct block_list *bl, short x, short y, unsigned char flag);
int unit_walktobl(struct block_list *bl, struct block_list *target, int range, unsigned char flag); int unit_walktobl(struct block_list *bl, struct block_list *target, int range, unsigned char flag);
void unit_run_hit(struct block_list *bl, struct status_change *sc, struct map_session_data *sd, enum sc_type type); void unit_run_hit(struct block_list *bl, struct status_change *sc, struct map_session_data *sd, enum sc_type type);
bool unit_run(struct block_list *bl, struct map_session_data *sd, enum sc_type type); bool unit_run(struct block_list *bl, struct map_session_data *sd, enum sc_type type);
int unit_calc_pos(struct block_list *bl, int tx, int ty, uint8 dir); int unit_calc_pos(struct block_list *bl, int tx, int ty);
TIMER_FUNC(unit_delay_walktoxy_timer); TIMER_FUNC(unit_delay_walktoxy_timer);
TIMER_FUNC(unit_delay_walktobl_timer); TIMER_FUNC(unit_delay_walktobl_timer);