OSDN Git Service

[Refactor] #37353 geometry.c/h を作成して coords_to_dir() を移動。 / Move coords_to_dir()...
[hengband/hengband.git] / src / geometry.c
1 #include "angband.h"
2
3 /*!
4  * @brief プレイヤーから指定の座標がどの方角にあるかを返す /
5  * Convert an adjacent location to a direction.
6  * @param y 方角を確認したY座標
7  * @param x 方角を確認したX座標
8  * @return 方向ID
9  */
10 DIRECTION coords_to_dir(POSITION y, POSITION x)
11 {
12         DIRECTION d[3][3] = { {7, 4, 1}, {8, 5, 2}, {9, 6, 3} };
13         POSITION dy, dx;
14
15         dy = y - p_ptr->y;
16         dx = x - p_ptr->x;
17
18         /* Paranoia */
19         if (ABS(dx) > 1 || ABS(dy) > 1) return (0);
20
21         return d[dx + 1][dy + 1];
22 }