1 #include "monster-floor/monster-dist-offsets.h"
4 * Hack -- Precompute a bunch of calls to distance() in find_safety() and
7 * The pair of arrays dist_offsets_y[n] and dist_offsets_x[n] contain the
8 * offsets of all the locations with a distance of n from a central point,
9 * with an offset of (0,0) indicating no more offsets at this distance.
11 * This is, of course, fairly unreadable, but it eliminates multiple loops
12 * from the previous version.
14 * It is probably better to replace these arrays with code to compute
15 * the relevant arrays, even if the storage is pre-allocated in hard
16 * coded sizes. At the very least, code should be included which is
17 * able to generate and dump these arrays (ala "los()").
19 * Also, the storage needs could be halved by using bytes.
21 * These arrays could be combined into two big arrays, using sub-arrays
22 * to hold the offsets and lengths of each portion of the sub-arrays, and
23 * this could perhaps also be used somehow in the "look" code.
27 static POSITION d_off_y_0[] = { 0 };
28 static POSITION d_off_x_0[] = { 0 };
30 static POSITION d_off_y_1[] = { -1, -1, -1, 0, 0, 1, 1, 1, 0 };
31 static POSITION d_off_x_1[] = { -1, 0, 1, -1, 1, -1, 0, 1, 0 };
33 static POSITION d_off_y_2[] = { -1, -1, -2, -2, -2, 0, 0, 1, 1, 2, 2, 2, 0 };
34 static POSITION d_off_x_2[] = { -2, 2, -1, 0, 1, -2, 2, -2, 2, -1, 0, 1, 0 };
36 static POSITION d_off_y_3[] = { -1, -1, -2, -2, -3, -3, -3, 0, 0, 1, 1, 2, 2, 3, 3, 3, 0 };
37 static POSITION d_off_x_3[] = { -3, 3, -2, 2, -1, 0, 1, -3, 3, -3, 3, -2, 2, -1, 0, 1, 0 };
39 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 };
40 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 };
43 static POSITION d_off_y_5[] =
44 { -1, -1, -2, -2, -3, -3, -4, -4, -4, -4, -5, -5,
45 -5, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 4, 4, 5, 5,
48 static POSITION d_off_x_5[] =
49 { -5, 5, -4, 4, -4, 4, -2, -3, 2, 3, -1, 0, 1,
50 -5, 5, -5, 5, -4, 4, -4, 4, -2, -3, 2, 3, -1,
54 static POSITION d_off_y_6[] =
55 { -1, -1, -2, -2, -3, -3, -4, -4, -5, -5, -5, -5,
56 -6, -6, -6, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5,
59 static POSITION d_off_x_6[] =
60 { -6, 6, -5, 5, -5, 5, -4, 4, -2, -3, 2, 3, -1,
61 0, 1, -6, 6, -6, 6, -5, 5, -5, 5, -4, 4, -2,
62 -3, 2, 3, -1, 0, 1, 0 };
65 static POSITION d_off_y_7[] =
66 { -1, -1, -2, -2, -3, -3, -4, -4, -5, -5, -5, -5,
67 -6, -6, -6, -6, -7, -7, -7, 0, 0, 1, 1, 2, 2, 3,
68 3, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 0 };
70 static POSITION d_off_x_7[] =
71 { -7, 7, -6, 6, -6, 6, -5, 5, -4, -5, 4, 5, -2,
72 -3, 2, 3, -1, 0, 1, -7, 7, -7, 7, -6, 6, -6,
73 6, -5, 5, -4, -5, 4, 5, -2, -3, 2, 3, -1, 0,
77 static POSITION d_off_y_8[] =
78 { -1, -1, -2, -2, -3, -3, -4, -4, -5, -5, -6, -6,
79 -6, -6, -7, -7, -7, -7, -8, -8, -8, 0, 0, 1, 1,
80 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7,
83 static POSITION d_off_x_8[] =
84 { -8, 8, -7, 7, -7, 7, -6, 6, -6, 6, -4, -5, 4,
85 5, -2, -3, 2, 3, -1, 0, 1, -8, 8, -8, 8, -7,
86 7, -7, 7, -6, 6, -6, 6, -4, -5, 4, 5, -2, -3,
90 static POSITION d_off_y_9[] =
91 { -1, -1, -2, -2, -3, -3, -4, -4, -5, -5, -6, -6,
92 -7, -7, -7, -7, -8, -8, -8, -8, -9, -9, -9, 0,
93 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 7,
94 7, 8, 8, 8, 8, 9, 9, 9, 0 };
96 static POSITION d_off_x_9[] =
97 { -9, 9, -8, 8, -8, 8, -7, 7, -7, 7, -6, 6, -4,
98 -5, 4, 5, -2, -3, 2, 3, -1, 0, 1, -9, 9, -9,
99 9, -8, 8, -8, 8, -7, 7, -7, 7, -6, 6, -4, -5,
100 4, 5, -2, -3, 2, 3, -1, 0, 1, 0 };
103 const POSITION *dist_offsets_y[10] =
105 d_off_y_0, d_off_y_1, d_off_y_2, d_off_y_3, d_off_y_4,
106 d_off_y_5, d_off_y_6, d_off_y_7, d_off_y_8, d_off_y_9
109 const POSITION *dist_offsets_x[10] =
111 d_off_x_0, d_off_x_1, d_off_x_2, d_off_x_3, d_off_x_4,
112 d_off_x_5, d_off_x_6, d_off_x_7, d_off_x_8, d_off_x_9