MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / GetClosestObject

Function GetClosestObject

src/newgrf_object.cpp:214–224  ·  view source on GitHub ↗

* Get the closest object of a given type. * @param tile The tile to start searching from. * @param type The type of the object to search for. * @param current The current object (to ignore). * @return The distance to the closest object. */

Source from the content-addressed store, hash-verified

212 * @return The distance to the closest object.
213 */
214static uint32_t GetClosestObject(TileIndex tile, ObjectType type, const Object *current)
215{
216 uint32_t best_dist = UINT32_MAX;
217 for (const Object *o : Object::Iterate()) {
218 if (o->type != type || o == current) continue;
219
220 best_dist = std::min(best_dist, DistanceManhattan(tile, o->location.tile));
221 }
222
223 return best_dist;
224}
225
226/**
227 * Implementation of var 65

Callers 1

Calls 1

DistanceManhattanFunction · 0.85

Tested by

no test coverage detected