Merge branch 'master' into jgrpp
# Conflicts: # src/industry_cmd.cpp # src/station_cmd.cpp # src/station_func.h
This commit is contained in:
@@ -833,6 +833,7 @@ public:
|
||||
}
|
||||
|
||||
bool CatchmentCoversTown(TownID t) const;
|
||||
void AddIndustryToDeliver(Industry *ind);
|
||||
void RemoveFromAllNearbyLists();
|
||||
|
||||
inline bool TileIsInCatchment(TileIndex tile) const
|
||||
@@ -889,4 +890,42 @@ public:
|
||||
|
||||
void RebuildStationKdtree();
|
||||
|
||||
/**
|
||||
* Call a function on all stations that have any part of the requested area within their catchment.
|
||||
* @tparam Func The type of funcion to call
|
||||
* @param area The TileArea to check
|
||||
* @param func The function to call, must take two parameters: Station* and TileIndex and return true
|
||||
* if coverage of that tile is acceptable for a given station or false if search should continue
|
||||
*/
|
||||
template<typename Func>
|
||||
void ForAllStationsAroundTiles(const TileArea &ta, Func func)
|
||||
{
|
||||
/* Not using, or don't have a nearby stations list, so we need to scan. */
|
||||
btree::btree_set<StationID> seen_stations;
|
||||
|
||||
/* Scan an area around the building covering the maximum possible station
|
||||
* to find the possible nearby stations. */
|
||||
uint max_c = _settings_game.station.modified_catchment ? MAX_CATCHMENT : CA_UNMODIFIED;
|
||||
max_c += _settings_game.station.catchment_increase;
|
||||
TileArea ta_ext = TileArea(ta).Expand(max_c);
|
||||
TILE_AREA_LOOP(tile, ta_ext) {
|
||||
if (IsTileType(tile, MP_STATION)) seen_stations.insert(GetStationIndex(tile));
|
||||
}
|
||||
|
||||
for (StationID stationid : seen_stations) {
|
||||
Station *st = Station::GetIfValid(stationid);
|
||||
if (st == nullptr) continue; /* Waypoint */
|
||||
|
||||
/* Check if station is attached to an industry */
|
||||
if (!_settings_game.station.serve_neutral_industries && st->industry != nullptr) continue;
|
||||
|
||||
/* Test if the tile is within the station's catchment */
|
||||
TILE_AREA_LOOP(tile, ta) {
|
||||
if (st->TileIsInCatchment(tile)) {
|
||||
if (func(st, tile)) break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* STATION_BASE_H */
|
||||
|
Reference in New Issue
Block a user