1 /*
2 * Seven Kingdoms: Ancient Adversaries
3 *
4 * Copyright 1997,1998 Enlight Software Ltd.
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 *
19 */
20
21 //Filename : OUNITAAT.CPP
22 //Description : Object UnitArray - table for attacking
23
24 #include <OUNIT.h>
25
26 #ifdef NO_DEBUG_UNIT
27 #undef err_when
28 #undef err_here
29 #undef err_if
30 #undef err_else
31 #undef err_now
32 #define err_when(cond)
33 #define err_here()
34 #define err_if(cond)
35 #define err_else
36 #define err_now(msg)
37 #undef DEBUG
38 #endif
39
40
41 //------------------------------------------------------------------------------//
42 // the codes in this file is used to return a pair of offset. Adding the offsets
43 // with a target location, the attacker can find a suitable space to attack the
44 // target.
45 //------------------------------------------------------------------------------//
46
47 static char attack_x_offset11[ATTACK_DIR][8] // target size 1x1
48 = { { -1, -1, -1, 0, 0, 1, 1, 1},
49 { -1, 0, -1, 1, -1, 1, 0, 1},
50 { 0, 1, -1, 1, -1, 1, -1, 0},
51 { 1, 1, 0, 1, -1, 0, -1, -1},
52 { 1, 1, 1, 0, 0, -1, -1, -1},
53 { 1, 0, 1, -1, 1, -1, 0, -1},
54 { 0, -1, 1, -1, 1, -1, 1, 0},
55 { -1, -1, 0, -1, 1, 0, 1, 1}};
56 static char attack_x_offset12[ATTACK_DIR][10] // target size 1x2
57 = { { -1, -1, -1, -1, 0, 0, 1, 1, 1, 1},
58 { -1, -1, 0, -1, 1, -1, 1, 0, 1, 1},
59 { 0, 1, -1, 1, -1, 1, -1, 1, -1, 0},
60 { 1, 1, 0, 1, -1, 1, -1, 0, -1, -1},
61 { 1, 1, 1, 1, 0, 0, -1, -1, -1, -1},
62 { 1, 1, 0, 1, -1, 1, -1, 0, -1, -1},
63 { 0, -1, 1, -1, 1, -1, 1, -1, 1, 0},
64 { -1, -1, 0, -1, 1, -1, 1, 0, 1, 1}};
65 static char attack_x_offset13[ATTACK_DIR][12] // target size 1x3
66 = { { -1, -1, -1, -1, -1, 0, 0, 1, 1, 1, 1, 1},
67 { -1, -1, 0, -1, 1, -1, 1, -1, 1, 0, 1, 1},
68 { 0, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 0},
69 { 1, 1, 0, 1, -1, 1, -1, 1, -1, 0, -1, -1},
70 { 1, 1, 1, 1, 1, 0, 0, -1, -1, -1, -1, -1},
71 { 1, 1, 0, 1, -1, 1, -1, 1, -1, 0, -1, -1},
72 { 0, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, 0},
73 { -1, -1, 0, -1, 1, -1, 1, -1, 1, 0, 1, 1}};
74 static char attack_x_offset14[ATTACK_DIR][14] // target size 1x4
75 = { { -1, -1, -1, -1, -1, -1, 0, 0, 1, 1, 1, 1, 1, 1},
76 { -1, -1, 0, -1, 1, -1, 1, -1, 1, -1, 1, 0, 1, 1},
77 { 0, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 0},
78 { 1, 1, 0, 1, -1, 1, -1, 1, -1, 1, -1, 0, -1, -1},
79 { 1, 1, 1, 1, 1, 1, 0, 0, -1, -1, -1, -1, -1, -1},
80 { 1, 1, 0, 1, -1, 1, -1, 1, -1, 1, -1, 0, -1, -1},
81 { 0, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, 0},
82 { -1, -1, 0, -1, 1, -1, 1, -1, 1, -1, 1, 0, 1, 1}};
83 static char attack_x_offset21[ATTACK_DIR][10] // target size 2x1
84 = { { -1, -1, -1, 0, 0, 1, 1, 2, 2, 2},
85 { -1, 0, -1, 1, -1, 2, 0, 2, 1, 2},
86 { 0, 1, -1, 2, -1, 2, -1, 2, 0, 1},
87 { 2, 1, 2, 0, 2, -1, 1, -1, 0, -1},
88 { 2, 2, 2, 1, 1, 0, 0, -1, -1, -1},
89 { 2, 1, 2, 0, 2, -1, 1, -1, 0, -1},
90 { 0, 1, -1, 2, -1, 2, -1, 2, 0, 1},
91 { -1, 0, -1, 1, -1, 2, 0, 2, 1, 2}};
92 static char attack_x_offset22[ATTACK_DIR][12] // target size 2x2
93 = { { -1, -1, -1, -1, 0, 0, 1, 1, 2, 2, 2, 2},
94 { -1, 0, -1, 1, -1, 2, -1, 2, 0, 2, 1, 2},
95 { 0, 1, -1, 2, -1, 2, -1, 2, -1, 2, 0, 1},
96 { 2, 2, 1, 2, 0, 2, -1, 1, -1, 0, -1, -1},
97 { 2, 2, 2, 2, 1, 1, 0, 0, -1, -1, -1, -1},
98 { 2, 1, 2, 0, 2, -1, 2, -1, 1, -1, 0, -1},
99 { 1, 0, 2, -1, 2, -1, 2, -1, 2, -1, 1, 0},
100 { -1, -1, 0, -1, 1, -1, 2, 0, 2, 1, 2, 2}};
101 static char attack_x_offset23[ATTACK_DIR][14] // target size 2x3
102 = { { -1, -1, -1, -1, -1, 0, 0, 1, 1, 2, 2, 2, 2, 2},
103 { -1, -1, 0, -1, 1, -1, 2, -1, 2, 0, 2, 1, 2, 2},
104 { 0, 1, -1, 2, -1, 2, -1, 2, -1, 2, -1, 2, 0, 1},
105 { 2, 2, 1, 2, 0, 2, -1, 2, -1, 1, -1, 0, -1, -1},
106 { 2, 2, 2, 2, 2, 1, 1, 0, 0, -1, -1, -1, -1, -1},
107 { 2, 2, 1, 2, 0, 2, -1, 2, -1, 1, -1, 0, -1, -1},
108 { 0, 1, -1, 2, -1, 2, -1, 2, -1, 2, -1, 2, 0, 1},
109 { -1, -1, 0, -1, 1, -1, 2, -1, 2, 0, 2, 1, 2, 2}};
110 static char attack_x_offset24[ATTACK_DIR][16] // target size 2x4
111 = { { -1, -1, -1, -1, -1, -1, 0, 0, 1, 1, 2, 2, 2, 2, 2, 2},
112 { -1, -1, 0, -1, 1, -1, 2, -1, 2, -1, 2, 0, 2, 1, 2, 2},
113 { 0, 1, -1, 2, -1, 2, -1, 2, -1, 2, -1, 2, -1, 2, 0, 1},
114 { 2, 2, 1, 2, 0, 2, -1, 2, -1, 2, -1, 1, -1, 0, -1, -1},
115 { 2, 2, 2, 2, 2, 2, 1, 1, 0, 0, -1, -1, -1, -1, -1, -1},
116 { 2, 2, 1, 2, 0, 2, -1, 2, -1, 2, -1, 1, -1, 0, -1, -1},
117 { 0, 1, -1, 2, -1, 2, -1, 2, -1, 2, -1, 2, -1, 2, 0, 1},
118 { -1, -1, 0, -1, 1, -1, 2, -1, 2, -1, 2, 0, 2, 1, 2, 2}};
119 static char attack_x_offset31[ATTACK_DIR][12] // target size 3x1
120 = { { -1, -1, -1, 0, 0, 1, 1, 2, 2, 3, 3, 3},
121 { -1, 0, -1, 1, -1, 2, 0, 3, 1, 3, 2, 3},
122 { 1, 2, 0, 3, -1, 3, -1, 3, -1, 2, 0, 1},
123 { 3, 2, 3, 1, 3, 0, 2, -1, 1, -1, 0, -1},
124 { 3, 3, 3, 2, 2, 1, 1, 0, 0, -1, -1, -1},
125 { 3, 2, 3, 1, 3, 0, 2, -1, 1, -1, 0, -1},
126 { 1, 0, 2, -1, 3, -1, 3, -1, 3, 0, 2, 1},
127 { -1, 0, -1, 1, -1, 2, 0, 3, 1, 3, 2, 3}};
128 static char attack_x_offset32[ATTACK_DIR][14] // target size 3x2
129 = { { -1, -1, -1, -1, 0, 0, 1, 1, 2, 2, 3, 3, 3, 3},
130 { -1, 0, -1, 1, -1, 2, -1, 3, 0, 3, 1, 3, 2, 3},
131 { 1, 2, 0, 3, -1, 3, -1, 3, -1, 3, -1, 2, 0, 1},
132 { 3, 2, 3, 1, 3, 0, 3, -1, 2, -1, 1, -1, 0, -1},
133 { 3, 3, 3, 3, 2, 2, 1, 1, 0, 0, -1, -1, -1, -1},
134 { 3, 2, 3, 1, 3, 0, 3, -1, 2, -1, 1, -1, 0, -1},
135 { 1, 0, 2, -1, 3, -1, 3, -1, 3, -1, 3, 0, 2, 1},
136 { -1, 0, -1, 1, -1, 2, -1, 3, 0, 3, 1, 3, 2, 3}};
137 static char attack_x_offset33[ATTACK_DIR][16] // target size 3x3
138 = { { -1, -1, -1, -1, -1, 0, 0, 1, 1, 2, 2, 3, 3, 3, 3, 3},
139 { -1, 0, -1, 1, -1, 2, -1, 3, -1, 3, 0, 3, 1, 3, 2, 3},
140 { 1, 2, 0, 3, -1, 3, -1, 3, -1, 3, -1, 3, -1, 2, 0, 1},
141 { 3, 3, 2, 3, 1, 3, 0, 3, -1, 2, -1, 1, -1, 0, -1, -1},
142 { 3, 3, 3, 3, 3, 2, 2, 1, 1, 0, 0, -1, -1, -1, -1, -1},
143 { 3, 2, 3, 1, 3, 0, 3, -1, 3, -1, 2, -1, 1, -1, 0, -1},
144 { 1, 0, 2, -1, 3, -1, 3, -1, 3, -1, 3, -1, 3, 0, 2, 1},
145 { -1, -1, 0, -1, 1, -1, 2, -1, 3, 0, 3, 1, 3, 2, 3, 3}};
146 static char attack_x_offset34[ATTACK_DIR][18] // target size 3x4
147 = { { -1, -1, -1, -1, -1, -1, 0, 0, 1, 1, 2, 2, 3, 3, 3, 3, 3, 3},
148 { -1, -1, 0, -1, 1, -1, 2, -1, 3, -1, 3, 0, 3, 1, 3, 2, 3, 3},
149 { 1, 2, 0, 3, -1, 3, -1, 3, -1, 3, -1, 3, -1, 3, -1, 2, 0, 1},
150 { 3, 3, 2, 3, 1, 3, 0, 3, -1, 3, -1, 2, -1, 1, -1, 0, -1, -1},
151 { 3, 3, 3, 3, 3, 3, 2, 2, 1, 1, 0, 0, -1, -1, -1, -1, -1, -1},
152 { 3, 3, 2, 3, 1, 3, 0, 3, -1, 3, -1, 2, -1, 1, -1, 0, -1, -1},
153 { 1, 0, 2, -1, 3, -1, 3, -1, 3, -1, 3, -1, 3, -1, 3, 0, 2, 1},
154 { -1, -1, 0, -1, 1, -1, 2, -1, 3, -1, 3, 0, 3, 1, 3, 2, 3, 3}};
155 static char attack_x_offset41[ATTACK_DIR][14] // target size 4x1
156 = { { -1, -1, -1, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 4},
157 { -1, 0, -1, 1, -1, 2, 0, 3, 1, 4, 2, 4, 3, 4},
158 { 1, 2, 0, 3, -1, 4, -1, 4, -1, 4, 0, 3, 1, 2},
159 { 4, 3, 4, 2, 4, 1, 3, 0, 2, -1, 1, -1, 0, -1},
160 { 4, 4, 4, 3, 3, 2, 2, 1, 1, 0, 0, -1, -1, -1},
161 { 4, 3, 4, 2, 4, 1, 3, 0, 2, -1, 1, -1, 0, -1},
162 { 1, 2, 0, 3, -1, 4, -1, 4, -1, 4, 0, 3, 1, 2},
163 { -1, 0, -1, 1, -1, 2, 0, 3, 1, 4, 2, 4, 3, 4}};
164 static char attack_x_offset42[ATTACK_DIR][16] // target size 4x2
165 = { { -1, -1, -1, -1, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 4, 4},
166 { -1, 0, -1, 1, -1, 2, -1, 3, 0, 4, 1, 4, 2, 4, 3, 4},
167 { 1, 2, 0, 3, -1, 4, -1, 4, -1, 4, -1, 4, 0, 3, 1, 2},
168 { 4, 3, 4, 2, 4, 1, 4, 0, 3, -1, 2, -1, 1, -1, 0, -1},
169 { 4, 4, 4, 4, 3, 3, 2, 2, 1, 1, 0, 0, -1, -1, -1, -1},
170 { 4, 3, 4, 2, 4, 1, 4, 0, 3, -1, 2, -1, 1, -1, 0, -1},
171 { 1, 2, 0, 3, -1, 4, -1, 4, -1, 4, -1, 4, 0, 3, 1, 2},
172 { -1, 0, -1, 1, -1, 2, -1, 3, 0, 4, 1, 4, 2, 4, 3, 4}};
173 static char attack_x_offset43[ATTACK_DIR][18] // target size 4x3
174 = { { -1, -1, -1, -1, -1, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 4, 4, 4},
175 { -1, 0, -1, 1, -1, 2, -1, 3, -1, 4, 0, 4, 1, 4, 2, 4, 3, 4},
176 { 1, 2, 0, 3, -1, 4, -1, 4, -1, 4, -1, 4, -1, 4, 0, 3, 1, 2},
177 { 4, 3, 4, 2, 4, 1, 4, 0, 4, -1, 3, -1, 2, -1, 1, -1, 0, -1},
178 { 4, 4, 4, 4, 4, 3, 3, 2, 2, 1, 1, 0, 0, -1, -1, -1, -1, -1},
179 { 4, 3, 4, 2, 4, 1, 4, 0, 4, -1, 3, -1, 2, -1, 1, -1, 0, -1},
180 { 1, 2, 0, 3, -1, 4, -1, 4, -1, 4, -1, 4, -1, 4, 0, 3, 1, 2},
181 { -1, 0, -1, 1, -1, 2, -1, 3, -1, 4, 0, 4, 1, 4, 2, 4, 3, 4}};
182 static char attack_x_offset44[ATTACK_DIR][20] // target size 4x4
183 = { { -1, -1, -1, -1, -1, -1, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 4, 4, 4, 4},
184 { -1, 0, -1, 1, -1, 2, -1, 3, -1, 4, -1, 4, 0, 4, 1, 4, 2, 4, 3, 4},
185 { 1, 2, 0, 3, -1, 4, -1, 4, -1, 4, -1, 4, -1, 4, -1, 4, 0, 3, 1, 2},
186 { 4, 4, 3, 4, 2, 4, 1, 4, 0, 4, -1, 3, -1, 2, -1, 1, -1, 0, -1, -1},
187 { 4, 4, 4, 4, 4, 4, 3, 3, 2, 2, 1, 1, 0, 0, -1, -1, -1, -1, -1, -1},
188 { 4, 3, 4, 2, 4, 1, 4, 0, 4, -1, 4, -1, 3, -1, 2, -1, 1, -1, 0, -1},
189 { 2, 1, 3, 0, 4, -1, 4, -1, 4, -1, 4, -1, 4, -1, 4, -1, 3, 0, 2, 1},
190 { -1, -1, 0, -1, 1, -1, 2, -1, 3, -1, 4, 0, 4, 1, 4, 2, 4, 3, 4, 4}};
191
192 static char attack_y_offset11[ATTACK_DIR][8] // target size 1x1
193 = { { 0, 1, -1, 1, -1, 1, -1, 0},
194 { 1, 1, 0, 1, -1, 0, -1, -1},
195 { 1, 1, 1, 0, 0, -1, -1, -1},
196 { 1, 0, 1, -1, 1, -1, 0, -1},
197 { 0, -1, 1, -1, 1, -1, 1, 0},
198 { -1, -1, 0, -1, 1, 0, 1, 1},
199 { -1, -1, -1, 0, 0, 1, 1, 1},
200 { -1, 0, -1, 1, -1, 1, 0, 1}};
201 static char attack_y_offset12[ATTACK_DIR][10] // target size 1x2
202 = { { 0, 1, -1, 2, -1, 2, -1, 2, 0, 1},
203 { 2, 1, 2, 0, 2, -1, 1, -1, 0, -1},
204 { 2, 2, 2, 1, 1, 0, 0, -1, -1, -1},
205 { 2, 1, 2, 0, 2, -1, 1, -1, 0, -1},
206 { 0, 1, -1, 2, -1, 2, -1, 2, 0, 1},
207 { -1, 0, -1, 1, -1, 2, 0, 2, 1, 2},
208 { -1, -1, -1, 0, 0, 1, 1, 2, 2, 2},
209 { -1, 0, -1, 1, -1, 2, 0, 2, 1, 2}};
210 static char attack_y_offset13[ATTACK_DIR][12] // target size 1x3
211 = { { 1, 2, 0, 3, -1, 3, -1, 3, -1, 2, 0, 1},
212 { 3, 2, 3, 1, 3, 0, 2, -1, 1, -1, 0, -1},
213 { 3, 3, 3, 2, 2, 1, 1, 0, 0, -1, -1, -1},
214 { 3, 2, 3, 1, 3, 0, 2, -1, 1, -1, 0, -1},
215 { 1, 0, 2, -1, 3, -1, 3, -1, 3, 0, 2, 1},
216 { -1, 0, -1, 1, -1, 2, 0, 3, 1, 3, 2, 3},
217 { -1, -1, -1, 0, 0, 1, 1, 2, 2, 3, 3, 3},
218 { -1, 0, -1, 1, -1, 2, 0, 3, 1, 3, 2, 3}};
219 static char attack_y_offset14[ATTACK_DIR][14] // target size 1x4
220 = { { 1, 2, 0, 3, -1, 4, -1, 4, -1, 4, 0, 3, 1, 2},
221 { 4, 3, 4, 2, 4, 1, 3, 0, 2, -1, 1, -1, 0, -1},
222 { 4, 4, 4, 3, 3, 2, 2, 1, 1, 0, 0, -1, -1, -1},
223 { 4, 3, 4, 2, 4, 1, 3, 0, 2, -1, 1, -1, 0, -1},
224 { 1, 2, 0, 3, -1, 4, -1, 4, -1, 4, 0, 3, 1, 2},
225 { -1, 0, -1, 1, -1, 2, 0, 3, 1, 4, 2, 4, 3, 4},
226 { -1, -1, -1, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 4},
227 { -1, 0, -1, 1, -1, 2, 0, 3, 1, 4, 2, 4, 3, 4}};
228 static char attack_y_offset21[ATTACK_DIR][10] // target size 2x1
229 = { { 0, 1, -1, 1, -1, 1, -1, 1, -1, 0},
230 { 1, 1, 0, 1, -1, 1, -1, 0, -1, -1},
231 { 1, 1, 1, 1, 0, 0, -1, -1, -1, -1},
232 { 1, 1, 0, 1, -1, 1, -1, 0, -1, -1},
233 { 0, -1, 1, -1, 1, -1, 1, -1, 1, 0},
234 { -1, -1, 0, -1, 1, -1, 1, 0, 1, 1},
235 { -1, -1, -1, -1, 0, 0, 1, 1, 1, 1},
236 { -1, -1, 0, -1, 1, -1, 1, 0, 1, 1}};
237 static char attack_y_offset22[ATTACK_DIR][12] // target size 2x2
238 = { { 0, 1, -1, 2, -1, 2, -1, 2, -1, 2, 0, 1},
239 { 2, 2, 1, 2, 0, 2, -1, 1, -1, 0, -1, -1},
240 { 2, 2, 2, 2, 1, 1, 0, 0, -1, -1, -1, -1},
241 { 2, 1, 2, 0, 2, -1, 2, -1, 1, -1, 0, -1},
242 { 1, 0, 2, -1, 2, -1, 2, -1, 2, -1, 1, 0},
243 { -1, -1, 0, -1, 1, -1, 2, 0, 2, 1, 2, 2},
244 { -1, -1, -1, -1, 0, 0, 1, 1, 2, 2, 2, 2},
245 { -1, 0, -1, 1, -1, 2, -1, 2, 0, 2, 1, 2}};
246 static char attack_y_offset23[ATTACK_DIR][14] // target size 2x3
247 = { { 1, 2, 0, 3, -1, 3, -1, 3, -1, 3, -1, 2, 0, 1},
248 { 3, 2, 3, 1, 3, 0, 3, -1, 2, -1, 1, -1, 0, -1},
249 { 3, 3, 3, 3, 2, 2, 1, 1, 0, 0, -1, -1, -1, -1},
250 { 3, 2, 3, 1, 3, 0, 3, -1, 2, -1, 1, -1, 0, -1},
251 { 1, 0, 2, -1, 3, -1, 3, -1, 3, -1, 3, 0, 2, 1},
252 { -1, 0, -1, 1, -1, 2, -1, 3, 0, 3, 1, 3, 2, 3},
253 { -1, -1, -1, -1, 0, 0, 1, 1, 2, 2, 3, 3, 3, 3},
254 { -1, 0, -1, 1, -1, 2, -1, 3, 0, 3, 1, 3, 2, 3}};
255 static char attack_y_offset24[ATTACK_DIR][16] // target size 2x4
256 = { { 1, 2, 0, 3, -1, 4, -1, 4, -1, 4, -1, 4, 0, 3, 1, 2},
257 { 4, 3, 4, 2, 4, 1, 4, 0, 3, -1, 2, -1, 1, -1, 0, -1},
258 { 4, 4, 4, 4, 3, 3, 2, 2, 1, 1, 0, 0, -1, -1, -1, -1},
259 { 4, 3, 4, 2, 4, 1, 4, 0, 3, -1, 2, -1, 1, -1, 0, -1},
260 { 1, 2, 0, 3, -1, 4, -1, 4, -1, 4, -1, 4, 0, 3, 1, 2},
261 { -1, 0, -1, 1, -1, 2, -1, 3, 0, 4, 1, 4, 2, 4, 3, 4},
262 { -1, -1, -1, -1, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 4, 4},
263 { -1, 0, -1, 1, -1, 2, -1, 3, 0, 4, 1, 4, 2, 4, 3, 4}};
264 static char attack_y_offset31[ATTACK_DIR][12] // target size 3x1
265 = { { 0, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 0},
266 { 1, 1, 0, 1, -1, 1, -1, 1, -1, 0, -1, -1},
267 { 1, 1, 1, 1, 1, 0, 0, -1, -1, -1, -1, -1},
268 { 1, 1, 0, 1, -1, 1, -1, 1, -1, 0, -1, -1},
269 { 0, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, 0},
270 { -1, -1, 0, -1, 1, -1, 1, -1, 1, 0, 1, 1},
271 { -1, -1, -1, -1, -1, 0, 0, 1, 1, 1, 1, 1},
272 { -1, -1, 0, -1, 1, -1, 1, -1, 1, 0, 1, 1}};
273 static char attack_y_offset32[ATTACK_DIR][14] // target size 3x2
274 = { { 0, 1, -1, 2, -1, 2, -1, 2, -1, 2, -1, 2, 0, 1},
275 { 2, 2, 1, 2, 0, 2, -1, 2, -1, 1, -1, 0, -1, -1},
276 { 2, 2, 2, 2, 2, 1, 1, 0, 0, -1, -1, -1, -1, -1},
277 { 2, 2, 1, 2, 0, 2, -1, 2, -1, 1, -1, 0, -1, -1},
278 { 0, 1, -1, 2, -1, 2, -1, 2, -1, 2, -1, 2, 0, 1},
279 { -1, -1, 0, -1, 1, -1, 2, -1, 2, 0, 2, 1, 2, 2},
280 { -1, -1, -1, -1, -1, 0, 0, 1, 1, 2, 2, 2, 2, 2},
281 { -1, -1, 0, -1, 1, -1, 2, -1, 2, 0, 2, 1, 2, 2}};
282 static char attack_y_offset33[ATTACK_DIR][16] // target size 3x3
283 = { { 1, 2, 0, 3, -1, 3, -1, 3, -1, 3, -1, 3, -1, 2, 0, 1},
284 { 3, 3, 2, 3, 1, 3, 0, 3, -1, 2, -1, 1, -1, 0, -1, -1},
285 { 3, 3, 3, 3, 3, 2, 2, 1, 1, 0, 0, -1, -1, -1, -1, -1},
286 { 3, 2, 3, 1, 3, 0, 3, -1, 3, -1, 2, -1, 1, -1, 0, -1},
287 { 1, 0, 2, -1, 3, -1, 3, -1, 3, -1, 3, -1, 3, 0, 2, 1},
288 { -1, -1, 0, -1, 1, -1, 2, -1, 3, 0, 3, 1, 3, 2, 3, 3},
289 { -1, -1, -1, -1, -1, 0, 0, 1, 1, 2, 2, 3, 3, 3, 3, 3},
290 { -1, 0, -1, 1, -1, 2, -1, 3, -1, 3, 0, 3, 1, 3, 2, 3}};
291 static char attack_y_offset34[ATTACK_DIR][18] // target size 3x4
292 = { { 1, 2, 0, 3, -1, 4, -1, 4, -1, 4, -1, 4, -1, 4, 0, 3, 1, 2},
293 { 4, 3, 4, 2, 4, 1, 4, 0, 4, -1, 3, -1, 2, -1, 1, -1, 0, -1},
294 { 4, 4, 4, 4, 4, 3, 3, 2, 2, 1, 1, 0, 0, -1, -1, -1, -1, -1},
295 { 4, 3, 4, 2, 4, 1, 4, 0, 4, -1, 3, -1, 2, -1, 1, -1, 0, -1},
296 { 1, 2, 0, 3, -1, 4, -1, 4, -1, 4, -1, 4, -1, 4, 0, 3, 1, 2},
297 { -1, 0, -1, 1, -1, 2, -1, 3, -1, 4, 0, 4, 1, 4, 2, 4, 3, 4},
298 { -1, -1, -1, -1, -1, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 4, 4, 4},
299 { -1, 0, -1, 1, -1, 2, -1, 3, -1, 4, 0, 4, 1, 4, 2, 4, 3, 4}};
300 static char attack_y_offset41[ATTACK_DIR][14] // target size 4x1
301 = { { 0, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 0},
302 { 1, 1, 0, 1, -1, 1, -1, 1, -1, 1, -1, 0, -1, -1},
303 { 1, 1, 1, 1, 1, 1, 0, 0, -1, -1, -1, -1, -1, -1},
304 { 1, 1, 0, 1, -1, 1, -1, 1, -1, 1, -1, 0, -1, -1},
305 { 0, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, 0},
306 { -1, -1, 0, -1, 1, -1, 1, -1, 1, -1, 1, 0, 1, -1},
307 { -1, -1, -1, -1, -1, -1, 0, 0, 1, 1, 1, 1, 1, 1},
308 { -1, -1, 0, -1, 1, -1, 1, -1, 1, -1, 1, 0, 1, 1}};
309 static char attack_y_offset42[ATTACK_DIR][16] // target size 4x2
310 = { { 0, 1, -1, 2, -1, 2, -1, 2, -1, 2, -1, 2, -1, 2, 0, 1},
311 { 2, 2, 1, 2, 0, 2, -1, 2, -1, 2, -1, 1, -1, 0, -1, -1},
312 { 2, 2, 2, 2, 2, 2, 1, 1, 0, 0, -1, -1, -1, -1, -1, -1},
313 { 2, 2, 1, 2, 0, 2, -1, 2, -1, 2, -1, 1, -1, 0, -1, -1},
314 { 0, 1, -1, 2, -1, 2, -1, 2, -1, 2, -1, 2, -1, 2, 0, 1},
315 { -1, -1, 0, -1, 1, -1, 2, -1, 2, -1, 2, 0, 2, 1, 2, 2},
316 { -1, -1, -1, -1, -1, -1, 0, 0, 1, 1, 2, 2, 2, 2, 2, 2},
317 { -1, -1, 0, -1, 1, -1, 2, -1, 2, -1, 2, 0, 2, 1, 2, 2}};
318 static char attack_y_offset43[ATTACK_DIR][18] // target size 4x3
319 = { { 1, 2, 0, 3, -1, 3, -1, 3, -1, 3, -1, 3, -1, 3, -1, 2, 0, 1},
320 { 3, 3, 2, 3, 1, 3, 0, 3, -1, 3, -1, 2, -1, 1, -1, 0, -1, -1},
321 { 3, 3, 3, 3, 3, 3, 2, 2, 1, 1, 0, 0, -1, -1, -1, -1, -1, -1},
322 { 3, 3, 2, 3, 1, 3, 0, 3, -1, 3, -1, 2, -1, 1, -1, 0, -1, -1},
323 { 1, 0, 2, -1, 3, -1, 3, -1, 3, -1, 3, -1, 3, -1, 3, 0, 2, 1},
324 { -1, -1, 0, -1, 1, -1, 2, -1, 3, -1, 3, 0, 3, 1, 3, 2, 3, 3},
325 { -1, -1, -1, -1, -1, -1, 0, 0, 1, 1, 2, 2, 3, 3, 3, 3, 3, 3},
326 { -1, -1, 0, -1, 1, -1, 2, -1, 3, -1, 3, 0, 3, 1, 3, 2, 3, 3}};
327 static char attack_y_offset44[ATTACK_DIR][20] // target size 4x4
328 = { { 1, 2, 0, 3, -1, 4, -1, 4, -1, 4, -1, 4, -1, 4, -1, 4, 0, 3, 1, 2},
329 { 4, 4, 3, 4, 2, 4, 1, 4, 0, 4, -1, 3, -1, 2, -1, 1, -1, 0, -1, -1},
330 { 4, 4, 4, 4, 4, 4, 3, 3, 2, 2, 1, 1, 0, 0, -1, -1, -1, -1, -1, -1},
331 { 4, 3, 4, 2, 4, 1, 4, 0, 4, -1, 4, -1, 3, -1, 2, -1, 1, -1, 0, -1},
332 { 2, 1, 3, 0, 4, -1, 4, -1, 4, -1, 4, -1, 4, -1, 4, -1, 3, 0, 2, 1},
333 { -1, -1, 0, -1, 1, -1, 2, -1, 3, -1, 4, 0, 4, 1, 4, 2, 4, 3, 4, 4},
334 { -1, -1, -1, -1, -1, -1, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 4, 4, 4, 4},
335 { -1, 0, -1, 1, -1, 2, -1, 3, -1, 4, -1, 4, 0, 4, 1, 4, 2, 4, 3, 4}};
336
337 //--------- Begin of function UnitArray::get_target_x_offset ---------//
338 // return x offset
339 //
340 // <int> targetWidth - width of the target
341 // <int> targetHeight - height of the target
342 // <char> curDir - the direction of attacker to the target
343 //
get_target_x_offset(int targetWidth,int targetHeight,char curDir)344 char* UnitArray::get_target_x_offset(int targetWidth, int targetHeight, char curDir)
345 {
346 err_when(curDir<0 || curDir>ATTACK_DIR);
347 int targetType = targetWidth*10 + targetHeight;
348 switch(targetType)
349 {
350 case 11: return attack_x_offset11[curDir];
351 case 12: return attack_x_offset12[curDir];
352 case 13: return attack_x_offset13[curDir];
353 case 14: return attack_x_offset14[curDir];
354 case 21: return attack_x_offset21[curDir];
355 case 22: return attack_x_offset22[curDir];
356 case 23: return attack_x_offset23[curDir];
357 case 24: return attack_x_offset24[curDir];
358 case 31: return attack_x_offset31[curDir];
359 case 32: return attack_x_offset32[curDir];
360 case 33: return attack_x_offset33[curDir];
361 case 34: return attack_x_offset34[curDir];
362 case 41: return attack_x_offset41[curDir];
363 case 42: return attack_x_offset42[curDir];
364 case 43: return attack_x_offset43[curDir];
365 case 44: return attack_x_offset44[curDir];
366 }
367
368 err_here();
369 return NULL;
370 }
371 //----------- End of function UnitArray::get_target_x_offset -----------//
372
373
374 //--------- Begin of function UnitArray::get_target_y_offset ---------//
375 // return y offset
376 //
377 // <int> targetWidth - width of the target
378 // <int> targetHeight - height of the target
379 // <char> curDir - the direction of attacker to the target
380 //
get_target_y_offset(int targetWidth,int targetHeight,char curDir)381 char* UnitArray::get_target_y_offset(int targetWidth, int targetHeight, char curDir)
382 {
383 err_when(curDir<0 || curDir>ATTACK_DIR);
384 int targetType = targetWidth*10 + targetHeight;
385 switch(targetType)
386 {
387 case 11: return attack_y_offset11[curDir];
388 case 12: return attack_y_offset12[curDir];
389 case 13: return attack_y_offset13[curDir];
390 case 14: return attack_y_offset14[curDir];
391 case 21: return attack_y_offset21[curDir];
392 case 22: return attack_y_offset22[curDir];
393 case 23: return attack_y_offset23[curDir];
394 case 24: return attack_y_offset24[curDir];
395 case 31: return attack_y_offset31[curDir];
396 case 32: return attack_y_offset32[curDir];
397 case 33: return attack_y_offset33[curDir];
398 case 34: return attack_y_offset34[curDir];
399 case 41: return attack_y_offset41[curDir];
400 case 42: return attack_y_offset42[curDir];
401 case 43: return attack_y_offset43[curDir];
402 case 44: return attack_y_offset44[curDir];
403 }
404
405 err_here();
406 return NULL;
407 }
408 //----------- End of function UnitArray::get_target_y_offset -----------//
409