diff options
Diffstat (limited to 'src/map/map.c')
-rw-r--r-- | src/map/map.c | 64 |
1 files changed, 37 insertions, 27 deletions
diff --git a/src/map/map.c b/src/map/map.c index 89494a65d..cac652ae8 100644 --- a/src/map/map.c +++ b/src/map/map.c @@ -2146,36 +2146,46 @@ int map_check_dir(int s_dir,int t_dir) } /*========================================== - * Returns the direction of the given cell in absolute relation to the char - * (regardless of where the char is facing) + * Returns the direction of the given cell, relative to 'src' *------------------------------------------*/ -int map_calc_dir( struct block_list *src,int x,int y) +int map_calc_dir(struct block_list* src, int x, int y) { - int dir=0; - int dx,dy; - + int dir = 0; + int dx, dy; + nullpo_retr(0, src); - - dx=x-src->x; - dy=y-src->y; - if( dx==0 && dy==0 ){ // �މ�̏ꏊ��v - dir=0; // �� - }else if( dx>=0 && dy>=0 ){ // �����I�ɉE�� - dir=7; // �E�� - if( dx*2-1<dy ) dir=0; // �� - if( dx>dy*2 ) dir=6; // �E - }else if( dx>=0 && dy<=0 ){ // �����I�ɉE�� - dir=5; // �E�� - if( dx*2-1<-dy ) dir=4; // �� - if( dx>-dy*2 ) dir=6; // �E - }else if( dx<=0 && dy<=0 ){ // �����I�ɍ��� - dir=3; // ���� - if( dx*2+1>dy ) dir=4; // �� - if( dx<dy*2 ) dir=2; // �� - }else{ // �����I�ɍ��� - dir=1; // ���� - if( -dx*2-1<dy ) dir=0; // �� - if( -dx>dy*2 ) dir=2; // �� + + dx = x-src->x; + dy = y-src->y; + if( dx == 0 && dy == 0 ) + { // both are standing on the same spot + //dir = 6; // aegis-style, causes knockback to the left + dir = unit_getdir(src); // athena-style, causes knockback opposite to src's current direction + } + else if( dx >= 0 && dy >=0 ) + { // upper-right + if( dx*2-1 < dy ) dir = 0; // up + else if( dx > dy*2 ) dir = 6; // right + else dir = 7; // up-right + } + else if( dx >= 0 && dy <= 0 ) + { // lower-right + if( dx*2-1 < -dy ) dir = 4; // down + else if( dx > -dy*2 ) dir = 6; // right + else dir = 5; // down-right + } + else if( dx <= 0 && dy <= 0 ) + { // lower-left + if( dx*2+1 > dy ) dir = 4; // down + else if( dx < dy*2 ) dir = 2; // left + else dir = 3; // down-left + } + else + { // upper-left + if( -dx*2-1 < dy ) dir = 0; // up + else if( -dx > dy*2 ) dir = 2; // left + else dir = 1; // up-left + } return dir; } |