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

Function ForAllStationsNearTown

src/town_cmd.cpp:3748–3760  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3746
3747template <typename Func>
3748static void ForAllStationsNearTown(Town *t, Func func)
3749{
3750 /* Ideally the search radius should be close to the actual town zone 0 radius.
3751 * The true radius is not stored or calculated anywhere, only the squared radius. */
3752 /* The efficiency of this search might be improved for large towns and many stations on the map,
3753 * by using an integer square root approximation giving a value not less than the true square root. */
3754 uint search_radius = t->cache.squared_town_zone_radius[to_underlying(HouseZone::TownEdge)] / 2;
3755 ForAllStationsRadius(t->xy, search_radius, [&](const Station * st) {
3756 if (DistanceSquare(st->xy, t->xy) <= t->cache.squared_town_zone_radius[to_underlying(HouseZone::TownEdge)]) {
3757 func(st);
3758 }
3759 });
3760}
3761
3762/**
3763 * Monthly callback to update town and station ratings.

Callers 2

UpdateTownRatingFunction · 0.85
CountActiveStationsFunction · 0.85

Calls 3

to_underlyingFunction · 0.85
ForAllStationsRadiusFunction · 0.85
DistanceSquareFunction · 0.85

Tested by

no test coverage detected