2 #include "monster-dist-offsets.h"
5 * Hack -- Precompute a bunch of calls to distance() in find_safety() and
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.
12 * This is, of course, fairly unreadable, but it eliminates multiple loops
13 * from the previous version.
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()").
20 * Also, the storage needs could be halved by using bytes.
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.
28 static POSITION d_off_y_0[] = { 0 };
29 static POSITION d_off_x_0[] = { 0 };
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 };
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 };
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 };
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 };
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,
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,
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,
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 };
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 };
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,
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,
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,
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 };
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 };
104 const POSITION *dist_offsets_y[10] =
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
110 const POSITION *dist_offsets_x[10] =
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