OSDN Git Service

[Fix] #39962 read_dead_file() にsize_t 引数を追加 / Added size_t argument to read_dead_file()
[hengband/hengband.git] / src / monster-dist-offsets.c
1 #include "angband.h"
2 #include "monster-dist-offsets.h"
3
4 /*
5  * Hack -- Precompute a bunch of calls to distance() in find_safety() and
6  * find_hiding().
7  *
8  * The pair of arrays dist_offsets_y[n] and dist_offsets_x[n] contain the
9  * offsets of all the locations with a distance of n from a central point,
10  * with an offset of (0,0) indicating no more offsets at this distance.
11  *
12  * This is, of course, fairly unreadable, but it eliminates multiple loops
13  * from the previous version.
14  *
15  * It is probably better to replace these arrays with code to compute
16  * the relevant arrays, even if the storage is pre-allocated in hard
17  * coded sizes.  At the very least, code should be included which is
18  * able to generate and dump these arrays (ala "los()").
19  *
20  * Also, the storage needs could be halved by using bytes.
21  *
22  * These arrays could be combined into two big arrays, using sub-arrays
23  * to hold the offsets and lengths of each portion of the sub-arrays, and
24  * this could perhaps also be used somehow in the "look" code.
25  */
26
27
28 static POSITION d_off_y_0[] = { 0 };
29 static POSITION d_off_x_0[] = { 0 };
30
31 static POSITION d_off_y_1[] = { -1, -1, -1, 0, 0, 1, 1, 1, 0 };
32 static POSITION d_off_x_1[] = { -1, 0, 1, -1, 1, -1, 0, 1, 0 };
33
34 static POSITION d_off_y_2[] = { -1, -1, -2, -2, -2, 0, 0, 1, 1, 2, 2, 2, 0 };
35 static POSITION d_off_x_2[] = { -2, 2, -1, 0, 1, -2, 2, -2, 2, -1, 0, 1, 0 };
36
37 static POSITION d_off_y_3[] = { -1, -1, -2, -2, -3, -3, -3, 0, 0, 1, 1, 2, 2, 3, 3, 3, 0 };
38 static POSITION d_off_x_3[] = { -3, 3, -2, 2, -1, 0, 1, -3, 3, -3, 3, -2, 2, -1, 0, 1, 0 };
39
40 static POSITION d_off_y_4[] = { -1, -1, -2, -2, -3, -3, -3, -3, -4, -4, -4, 0, 0, 1, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 0 };
41 static POSITION d_off_x_4[] = { -4, 4, -3, 3, -2, -3, 2, 3, -1, 0, 1, -4, 4, -4, 4, -3, 3, -2, -3, 2, 3, -1, 0, 1, 0 };
42
43
44 static POSITION d_off_y_5[] =
45 { -1, -1, -2, -2, -3, -3, -4, -4, -4, -4, -5, -5,
46   -5, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 4, 4, 5, 5,
47   5, 0 };
48
49 static POSITION d_off_x_5[] =
50 { -5, 5, -4, 4, -4, 4, -2, -3, 2, 3, -1, 0, 1,
51   -5, 5, -5, 5, -4, 4, -4, 4, -2, -3, 2, 3, -1,
52   0, 1, 0 };
53
54
55 static POSITION d_off_y_6[] =
56 { -1, -1, -2, -2, -3, -3, -4, -4, -5, -5, -5, -5,
57   -6, -6, -6, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5,
58   5, 5, 6, 6, 6, 0 };
59
60 static POSITION d_off_x_6[] =
61 { -6, 6, -5, 5, -5, 5, -4, 4, -2, -3, 2, 3, -1,
62   0, 1, -6, 6, -6, 6, -5, 5, -5, 5, -4, 4, -2,
63   -3, 2, 3, -1, 0, 1, 0 };
64
65
66 static POSITION d_off_y_7[] =
67 { -1, -1, -2, -2, -3, -3, -4, -4, -5, -5, -5, -5,
68   -6, -6, -6, -6, -7, -7, -7, 0, 0, 1, 1, 2, 2, 3,
69   3, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 0 };
70
71 static POSITION d_off_x_7[] =
72 { -7, 7, -6, 6, -6, 6, -5, 5, -4, -5, 4, 5, -2,
73   -3, 2, 3, -1, 0, 1, -7, 7, -7, 7, -6, 6, -6,
74   6, -5, 5, -4, -5, 4, 5, -2, -3, 2, 3, -1, 0,
75   1, 0 };
76
77
78 static POSITION d_off_y_8[] =
79 { -1, -1, -2, -2, -3, -3, -4, -4, -5, -5, -6, -6,
80   -6, -6, -7, -7, -7, -7, -8, -8, -8, 0, 0, 1, 1,
81   2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7,
82   8, 8, 8, 0 };
83
84 static POSITION d_off_x_8[] =
85 { -8, 8, -7, 7, -7, 7, -6, 6, -6, 6, -4, -5, 4,
86   5, -2, -3, 2, 3, -1, 0, 1, -8, 8, -8, 8, -7,
87   7, -7, 7, -6, 6, -6, 6, -4, -5, 4, 5, -2, -3,
88   2, 3, -1, 0, 1, 0 };
89
90
91 static POSITION d_off_y_9[] =
92 { -1, -1, -2, -2, -3, -3, -4, -4, -5, -5, -6, -6,
93   -7, -7, -7, -7, -8, -8, -8, -8, -9, -9, -9, 0,
94   0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 7,
95   7, 8, 8, 8, 8, 9, 9, 9, 0 };
96
97 static POSITION d_off_x_9[] =
98 { -9, 9, -8, 8, -8, 8, -7, 7, -7, 7, -6, 6, -4,
99   -5, 4, 5, -2, -3, 2, 3, -1, 0, 1, -9, 9, -9,
100   9, -8, 8, -8, 8, -7, 7, -7, 7, -6, 6, -4, -5,
101   4, 5, -2, -3, 2, 3, -1, 0, 1, 0 };
102
103
104 const POSITION *dist_offsets_y[10] =
105 {
106         d_off_y_0, d_off_y_1, d_off_y_2, d_off_y_3, d_off_y_4,
107         d_off_y_5, d_off_y_6, d_off_y_7, d_off_y_8, d_off_y_9
108 };
109
110 const POSITION *dist_offsets_x[10] =
111 {
112         d_off_x_0, d_off_x_1, d_off_x_2, d_off_x_3, d_off_x_4,
113         d_off_x_5, d_off_x_6, d_off_x_7, d_off_x_8, d_off_x_9
114 };