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

Function Tile_MoveByRandom

src/tile.c:306–333  ·  view source on GitHub ↗

* 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. */

Source from the content-addressed store, hash-verified

304 * @return The tile.
305 */
306tile32 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.

Callers 11

Map_Bloom_ExplodeSpecialFunction · 0.85
Map_FindLocationTileFunction · 0.85
Map_CreateLandscapeFunction · 0.85
Unit_CreateBulletFunction · 0.85
Unit_LaunchHouseMissileFunction · 0.85
Script_Structure_DestroyFunction · 0.85
Script_Team_Unknown0543Function · 0.85

Calls 2

Tools_Random_256Function · 0.85
Tile_CenterFunction · 0.85

Tested by

no test coverage detected