MCPcopy Create free account
hub / github.com/diasurgical/devilution / GetDirection8

Function GetDirection8

Source/missiles.cpp:257–300  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

255}
256
257int GetDirection8(int x1, int y1, int x2, int y2)
258{
259 BYTE Dirs[16][16] = {
260 { 99, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
261 { 2, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
262 { 2, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
263 { 2, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0 },
264 { 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0 },
265 { 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0 },
266 { 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
267 { 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
268 { 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
269 { 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
270 { 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
271 { 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
272 { 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
273 { 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
274 { 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
275 { 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }
276 };
277 int mx, my, md;
278 ALIGN_BY_1 BYTE urtoll[] = { 3, 4, 5 },
279 ultolr[] = { 3, 2, 1 },
280 lrtoul[] = { 7, 6, 5 },
281 lltour[] = { 7, 0, 1 };
282
283 mx = abs(x2 - x1);
284 if (mx > 15)
285 mx = 15;
286 my = abs(y2 - y1);
287 if (my > 15)
288 my = 15;
289 md = Dirs[my][mx];
290 if (x1 > x2) {
291 if (y1 > y2)
292 md = urtoll[md];
293 else
294 md = ultolr[md];
295 } else if (y1 > y2)
296 md = lrtoul[md];
297 else
298 md = lltour[md];
299 return md;
300}
301
302int GetDirection16(int x1, int y1, int x2, int y2)
303{

Callers 4

AddElementFunction · 0.85
AddBoneSpiritFunction · 0.85
MI_ElementFunction · 0.85
MI_BonespiritFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected