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

Function Tile_MoveByDirection

src/tile.c:276–296  ·  view source on GitHub ↗

* Get the tile from given tile at given distance in given direction. * * @param tile The origin. * @param orientation The direction to follow. * @param distance The distance. * @return The tile. */

Source from the content-addressed store, hash-verified

274 * @return The tile.
275 */
276tile32 Tile_MoveByDirection(tile32 tile, int16 orientation, uint16 distance)
277{
278 int diffX, diffY;
279 int roundingOffsetX, roundingOffsetY;
280
281 distance = min(distance, 0xFF);
282
283 if (distance == 0) return tile;
284
285 diffX = _stepX[orientation & 0xFF];
286 diffY = _stepY[orientation & 0xFF];
287
288 /* Always round away from zero */
289 roundingOffsetX = diffX < 0 ? -64 : 64;
290 roundingOffsetY = diffY < 0 ? -64 : 64;
291
292 tile.x += (diffX * distance + roundingOffsetX) / 128;
293 tile.y -= (diffY * distance + roundingOffsetY) / 128;
294
295 return tile;
296}
297
298/**
299 * Get the tile from given tile at given maximum distance in random direction.

Callers 4

Unit_MoveFunction · 0.85
Unit_CreateBulletFunction · 0.85
Script_Team_Unknown0788Function · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected