… | |
… | |
527 | x = mon->x; |
527 | x = mon->x; |
528 | y = mon->y; |
528 | y = mon->y; |
529 | m = mon->map; |
529 | m = mon->map; |
530 | dir = rv.direction; |
530 | dir = rv.direction; |
531 | lastdir = firstdir = rv.direction; /* perhaps we stand next to pl, init firstdir too */ |
531 | lastdir = firstdir = rv.direction; /* perhaps we stand next to pl, init firstdir too */ |
532 | diff = FABS (rv.distance_x) > FABS (rv.distance_y) ? FABS (rv.distance_x) : FABS (rv.distance_y); |
532 | diff = ::max (abs (rv.distance_x), abs (rv.distance_y)); |
|
|
533 | |
533 | /* If we can't solve it within the search distance, return now. */ |
534 | /* If we can't solve it within the search distance, return now. */ |
534 | if (diff > max) |
535 | if (diff > max) |
535 | return 0; |
536 | return 0; |
|
|
537 | |
536 | while (diff > 1 && max > 0) |
538 | while (diff > 1 && max > 0) |
537 | { |
539 | { |
538 | lastx = x; |
540 | lastx = x; |
539 | lasty = y; |
541 | lasty = y; |
540 | lastmap = m; |
542 | lastmap = m; |
… | |
… | |
622 | max--; |
624 | max--; |
623 | lastdir = dir; |
625 | lastdir = dir; |
624 | if (!firstdir) |
626 | if (!firstdir) |
625 | firstdir = dir; |
627 | firstdir = dir; |
626 | } |
628 | } |
|
|
629 | |
627 | if (diff <= 1) |
630 | if (diff <= 1) |
628 | { |
631 | { |
629 | /* Recalculate diff (distance) because we may not have actually |
632 | /* Recalculate diff (distance) because we may not have actually |
630 | * headed toward player for entire distance. |
633 | * headed toward player for entire distance. |
631 | */ |
634 | */ |
632 | get_rangevector_from_mapcoord (m, x, y, pl, &rv, 0); |
635 | get_rangevector_from_mapcoord (m, x, y, pl, &rv, 0); |
633 | diff = FABS (rv.distance_x) > FABS (rv.distance_y) ? FABS (rv.distance_x) : FABS (rv.distance_y); |
636 | diff = ::max (abs (rv.distance_x), abs (rv.distance_y)); |
634 | } |
637 | } |
|
|
638 | |
635 | if (diff > max) |
639 | if (diff > max) |
636 | return 0; |
640 | return 0; |
637 | } |
641 | } |
|
|
642 | |
638 | /* If we reached the max, didn't find a direction in time */ |
643 | /* If we reached the max, didn't find a direction in time */ |
639 | if (!max) |
644 | if (!max) |
640 | return 0; |
645 | return 0; |
641 | |
646 | |
642 | return firstdir; |
647 | return firstdir; |