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

Function Tile_GetTileInDirectionOf

src/tile.c:155–184  ·  view source on GitHub ↗

* Get a tile in the direction of a destination, randomized a bit. * * @param packed_from The origin. * @param packed_to The destination. * @return A packed tile. */

Source from the content-addressed store, hash-verified

153 * @return A packed tile.
154 */
155uint16 Tile_GetTileInDirectionOf(uint16 packed_from, uint16 packed_to)
156{
157 int16 distance;
158 uint8 direction;
159
160 if (packed_from == 0 || packed_to == 0) return 0;
161
162 distance = Tile_GetDistancePacked(packed_from, packed_to);
163 direction = Tile_GetDirectionPacked(packed_to, packed_from);
164
165 if (distance <= 10) return 0;
166
167 while (true) {
168 int16 dir;
169 tile32 position;
170 uint16 packed;
171
172 dir = 31 + (Tools_Random_256() & 0x3F);
173
174 if ((Tools_Random_256() & 1) != 0) dir = -dir;
175
176 position = Tile_UnpackTile(packed_to);
177 position = Tile_MoveByDirection(position, direction + dir, min(distance, 20) << 8);
178 packed = Tile_PackTile(position);
179
180 if (Map_IsValidPosition(packed)) return packed;
181 }
182
183 return 0;
184}
185
186/**
187 * Get to direction to follow to go from packed_from to packed_to.

Callers 1

Calls 6

Tile_GetDistancePackedFunction · 0.85
Tile_GetDirectionPackedFunction · 0.85
Tools_Random_256Function · 0.85
Tile_UnpackTileFunction · 0.85
Tile_MoveByDirectionFunction · 0.85
Map_IsValidPositionFunction · 0.85

Tested by

no test coverage detected