summaryrefslogtreecommitdiff
path: root/src/map/unit.c
diff options
context:
space:
mode:
authorzephyrus <zephyrus@54d463be-8e91-2dee-dedb-b68131a5f0ec>2008-08-24 13:33:36 +0000
committerzephyrus <zephyrus@54d463be-8e91-2dee-dedb-b68131a5f0ec>2008-08-24 13:33:36 +0000
commit8cb6244382cb6e1bb8b2edd13bba6b91f9c67b1f (patch)
tree8f7a613a82dbc47716983718bfaf8bbf2f69793c /src/map/unit.c
parent9ef83b403e59be7824e55e2526b5163bdf17f2b6 (diff)
downloadhercules-8cb6244382cb6e1bb8b2edd13bba6b91f9c67b1f.tar.gz
hercules-8cb6244382cb6e1bb8b2edd13bba6b91f9c67b1f.tar.bz2
hercules-8cb6244382cb6e1bb8b2edd13bba6b91f9c67b1f.tar.xz
hercules-8cb6244382cb6e1bb8b2edd13bba6b91f9c67b1f.zip
- 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
Diffstat (limited to 'src/map/unit.c')
-rw-r--r--src/map/unit.c56
1 files changed, 56 insertions, 0 deletions
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֐)