From 8cb6244382cb6e1bb8b2edd13bba6b91f9c67b1f Mon Sep 17 00:00:00 2001 From: zephyrus Date: Sun, 24 Aug 2008 13:33:36 +0000 Subject: - Implemented unit_calc_pos (copy from pet_calc_pos) to implement it on Mercenary/Homunculus and don't use x,y-1 always. - Implemented Mercenary walk to master (same packet as Homunculus). - Starting work on Stats but i will need lot of help. git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@13121 54d463be-8e91-2dee-dedb-b68131a5f0ec --- src/map/unit.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) (limited to 'src/map/unit.c') diff --git a/src/map/unit.c b/src/map/unit.c index 20cd20de6..23789544f 100644 --- a/src/map/unit.c +++ b/src/map/unit.c @@ -1357,7 +1357,63 @@ bool unit_can_reach_bl(struct block_list *bl,struct block_list *tbl, int range, if (y) *y = tbl->y-dy; return path_search(NULL,bl->m,bl->x,bl->y,tbl->x-dx,tbl->y-dy,easy,CELL_CHKNOREACH); } +/*========================================== + * Calculates position of Pet/Mercenary/Homunculus + *------------------------------------------*/ +int unit_calc_pos(struct block_list *bl, int tx, int ty, int dir) +{ + int dx, dy, x, y, i, k; + struct unit_data *ud = unit_bl2ud(bl); + nullpo_retr(0, ud); + + if( dir < 0 || dir > 7 ) + return 1; + ud->to_x = tx; + ud->to_y = ty; + + // 2 cells from Master Position + dx = -dirx[dir] * 2; + dy = -diry[dir] * 2; + x = tx + dx; + y = ty + dy; + + if( !unit_can_reach_pos(bl, x, y, 0) ) + { + 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) ) + { + for( i = 0; i < 12; i++ ) + { + k = rand()%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; + } + } + } + ud->to_x = x; + ud->to_y = y; + + return 0; +} /*========================================== * PC̍U (timer֐) -- cgit v1.2.3-60-g2f50