MCPcopy Create free account
hub / github.com/OpenDUNE/OpenDUNE / Tile_GetDirectionPacked

Function Tile_GetDirectionPacked

src/tile.c:193–228  ·  view source on GitHub ↗

* Get to direction to follow to go from packed_from to packed_to. * * @param packed_from The origin. * @param packed_to The destination. * @return The direction. */

Source from the content-addressed store, hash-verified

191 * @return The direction.
192 */
193uint8 Tile_GetDirectionPacked(uint16 packed_from, uint16 packed_to)
194{
195 static const uint8 returnValues[16] = {0x20, 0x40, 0x20, 0x00, 0xE0, 0xC0, 0xE0, 0x00, 0x60, 0x40, 0x60, 0x80, 0xA0, 0xC0, 0xA0, 0x80};
196
197 int16 x1, y1, x2, y2;
198 int16 dx, dy;
199 uint16 index;
200
201 x1 = Tile_GetPackedX(packed_from);
202 y1 = Tile_GetPackedY(packed_from);
203 x2 = Tile_GetPackedX(packed_to);
204 y2 = Tile_GetPackedY(packed_to);
205
206 index = 0;
207
208 dy = y1 - y2;
209 if (dy < 0) {
210 index |= 0x8;
211 dy = -dy;
212 }
213
214 dx = x2 - x1;
215 if (dx < 0) {
216 index |= 0x4;
217 dx = -dx;
218 }
219
220 if (dx >= dy) {
221 if (((dx + 1) / 2) > dy) index |= 0x1;
222 } else {
223 index |= 0x2;
224 if (((dy + 1) / 2) > dx) index |= 0x1;
225 }
226
227 return returnValues[index];
228}
229
230static const int8 _stepX[256] = {
231 0, 3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45,

Callers 2

Script_Unit_PathfinderFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected