* 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. */
| 274 | * @return The tile. |
| 275 | */ |
| 276 | tile32 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. |
no outgoing calls
no test coverage detected