* Get the tile from given tile at given maximum distance in random direction. * * @param tile The origin. * @param distance The distance maximum. * @param center Wether to center the offset of the tile. * @return The tile. */
| 304 | * @return The tile. |
| 305 | */ |
| 306 | tile32 Tile_MoveByRandom(tile32 tile, uint16 distance, bool center) |
| 307 | { |
| 308 | uint16 x; |
| 309 | uint16 y; |
| 310 | tile32 ret; |
| 311 | uint8 orientation; |
| 312 | uint16 newDistance; |
| 313 | |
| 314 | if (distance == 0) return tile; |
| 315 | |
| 316 | x = Tile_GetX(tile); |
| 317 | y = Tile_GetY(tile); |
| 318 | |
| 319 | newDistance = Tools_Random_256(); |
| 320 | while (newDistance > distance) newDistance /= 2; |
| 321 | distance = newDistance; |
| 322 | |
| 323 | orientation = Tools_Random_256(); |
| 324 | x += ((_stepX[orientation] * distance) / 128) * 16; |
| 325 | y -= ((_stepY[orientation] * distance) / 128) * 16; |
| 326 | |
| 327 | if (x > 16384 || y > 16384) return tile; |
| 328 | |
| 329 | ret.x = x; |
| 330 | ret.y = y; |
| 331 | |
| 332 | return center ? Tile_Center(ret) : ret; |
| 333 | } |
| 334 | |
| 335 | /** |
| 336 | * Get to direction to follow to go from \a from to \a to. |
no test coverage detected