mirror of https://github.com/OpenTTD/OpenTTD
Codechange: Use reference for non-optional StationList parameter. (#13092)
parent
640a270ed6
commit
6c09dcdd66
|
@ -31,7 +31,7 @@ int UpdateCompanyRatingAndValue(Company *c, bool update);
|
||||||
void StartupIndustryDailyChanges(bool init_counter);
|
void StartupIndustryDailyChanges(bool init_counter);
|
||||||
|
|
||||||
Money GetTransportedGoodsIncome(uint num_pieces, uint dist, uint16_t transit_periods, CargoID cargo_type);
|
Money GetTransportedGoodsIncome(uint num_pieces, uint dist, uint16_t transit_periods, CargoID cargo_type);
|
||||||
uint MoveGoodsToStation(CargoID type, uint amount, SourceType source_type, SourceID source_id, const StationList *all_stations, Owner exclusivity = INVALID_OWNER);
|
uint MoveGoodsToStation(CargoID type, uint amount, SourceType source_type, SourceID source_id, const StationList &all_stations, Owner exclusivity = INVALID_OWNER);
|
||||||
|
|
||||||
void PrepareUnload(Vehicle *front_v);
|
void PrepareUnload(Vehicle *front_v);
|
||||||
void LoadUnloadStation(Station *st);
|
void LoadUnloadStation(Station *st);
|
||||||
|
|
|
@ -535,7 +535,7 @@ static bool TransportIndustryGoods(TileIndex tile)
|
||||||
|
|
||||||
p.history[THIS_MONTH].production += cw;
|
p.history[THIS_MONTH].production += cw;
|
||||||
|
|
||||||
uint am = MoveGoodsToStation(p.cargo, cw, SourceType::Industry, i->index, &i->stations_near, i->exclusive_consumer);
|
uint am = MoveGoodsToStation(p.cargo, cw, SourceType::Industry, i->index, i->stations_near, i->exclusive_consumer);
|
||||||
p.history[THIS_MONTH].transported += am;
|
p.history[THIS_MONTH].transported += am;
|
||||||
|
|
||||||
moved_cargo |= (am != 0);
|
moved_cargo |= (am != 0);
|
||||||
|
|
|
@ -455,11 +455,10 @@ static uint32_t GetDistanceFromNearbyHouse(uint8_t parameter, TileIndex tile, Ho
|
||||||
TileIndex testtile = Map::WrapToMap(this->tile + TileDiffXY(x_offs, y_offs));
|
TileIndex testtile = Map::WrapToMap(this->tile + TileDiffXY(x_offs, y_offs));
|
||||||
|
|
||||||
StationFinder stations(TileArea(testtile, 1, 1));
|
StationFinder stations(TileArea(testtile, 1, 1));
|
||||||
const StationList *sl = stations.GetStations();
|
|
||||||
|
|
||||||
/* Collect acceptance stats. */
|
/* Collect acceptance stats. */
|
||||||
uint32_t res = 0;
|
uint32_t res = 0;
|
||||||
for (Station *st : *sl) {
|
for (Station *st : stations.GetStations()) {
|
||||||
if (HasBit(st->goods[cid].status, GoodsEntry::GES_EVER_ACCEPTED)) SetBit(res, 0);
|
if (HasBit(st->goods[cid].status, GoodsEntry::GES_EVER_ACCEPTED)) SetBit(res, 0);
|
||||||
if (HasBit(st->goods[cid].status, GoodsEntry::GES_LAST_MONTH)) SetBit(res, 1);
|
if (HasBit(st->goods[cid].status, GoodsEntry::GES_LAST_MONTH)) SetBit(res, 1);
|
||||||
if (HasBit(st->goods[cid].status, GoodsEntry::GES_CURRENT_MONTH)) SetBit(res, 2);
|
if (HasBit(st->goods[cid].status, GoodsEntry::GES_CURRENT_MONTH)) SetBit(res, 2);
|
||||||
|
|
|
@ -4344,10 +4344,10 @@ CommandCost CmdRenameStation(DoCommandFlag flags, StationID station_id, const st
|
||||||
return CommandCost();
|
return CommandCost();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void AddNearbyStationsByCatchment(TileIndex tile, StationList *stations, StationList &nearby)
|
static void AddNearbyStationsByCatchment(TileIndex tile, StationList &stations, StationList &nearby)
|
||||||
{
|
{
|
||||||
for (Station *st : nearby) {
|
for (Station *st : nearby) {
|
||||||
if (st->TileIsInCatchment(tile)) stations->insert(st);
|
if (st->TileIsInCatchment(tile)) stations.insert(st);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4355,13 +4355,13 @@ static void AddNearbyStationsByCatchment(TileIndex tile, StationList *stations,
|
||||||
* Run a tile loop to find stations around a tile, on demand. Cache the result for further requests
|
* Run a tile loop to find stations around a tile, on demand. Cache the result for further requests
|
||||||
* @return pointer to a StationList containing all stations found
|
* @return pointer to a StationList containing all stations found
|
||||||
*/
|
*/
|
||||||
const StationList *StationFinder::GetStations()
|
const StationList &StationFinder::GetStations()
|
||||||
{
|
{
|
||||||
if (this->tile != INVALID_TILE) {
|
if (this->tile != INVALID_TILE) {
|
||||||
if (IsTileType(this->tile, MP_HOUSE)) {
|
if (IsTileType(this->tile, MP_HOUSE)) {
|
||||||
/* Town nearby stations need to be filtered per tile. */
|
/* Town nearby stations need to be filtered per tile. */
|
||||||
assert(this->w == 1 && this->h == 1);
|
assert(this->w == 1 && this->h == 1);
|
||||||
AddNearbyStationsByCatchment(this->tile, &this->stations, Town::GetByTile(this->tile)->stations_near);
|
AddNearbyStationsByCatchment(this->tile, this->stations, Town::GetByTile(this->tile)->stations_near);
|
||||||
} else {
|
} else {
|
||||||
ForAllStationsAroundTiles(*this, [this](Station *st, TileIndex) {
|
ForAllStationsAroundTiles(*this, [this](Station *st, TileIndex) {
|
||||||
this->stations.insert(st);
|
this->stations.insert(st);
|
||||||
|
@ -4370,7 +4370,7 @@ const StationList *StationFinder::GetStations()
|
||||||
}
|
}
|
||||||
this->tile = INVALID_TILE;
|
this->tile = INVALID_TILE;
|
||||||
}
|
}
|
||||||
return &this->stations;
|
return this->stations;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -4395,17 +4395,17 @@ static bool CanMoveGoodsToStation(const Station *st, CargoID type)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint MoveGoodsToStation(CargoID type, uint amount, SourceType source_type, SourceID source_id, const StationList *all_stations, Owner exclusivity)
|
uint MoveGoodsToStation(CargoID type, uint amount, SourceType source_type, SourceID source_id, const StationList &all_stations, Owner exclusivity)
|
||||||
{
|
{
|
||||||
/* Return if nothing to do. Also the rounding below fails for 0. */
|
/* Return if nothing to do. Also the rounding below fails for 0. */
|
||||||
if (all_stations->empty()) return 0;
|
if (all_stations.empty()) return 0;
|
||||||
if (amount == 0) return 0;
|
if (amount == 0) return 0;
|
||||||
|
|
||||||
Station *first_station = nullptr;
|
Station *first_station = nullptr;
|
||||||
typedef std::pair<Station *, uint> StationInfo;
|
typedef std::pair<Station *, uint> StationInfo;
|
||||||
std::vector<StationInfo> used_stations;
|
std::vector<StationInfo> used_stations;
|
||||||
|
|
||||||
for (Station *st : *all_stations) {
|
for (Station *st : all_stations) {
|
||||||
if (exclusivity != INVALID_OWNER && exclusivity != st->owner) continue;
|
if (exclusivity != INVALID_OWNER && exclusivity != st->owner) continue;
|
||||||
if (!CanMoveGoodsToStation(st, type)) continue;
|
if (!CanMoveGoodsToStation(st, type)) continue;
|
||||||
|
|
||||||
|
|
|
@ -105,7 +105,7 @@ public:
|
||||||
* @param area the area to search from
|
* @param area the area to search from
|
||||||
*/
|
*/
|
||||||
StationFinder(const TileArea &area) : TileArea(area) {}
|
StationFinder(const TileArea &area) : TileArea(area) {}
|
||||||
const StationList *GetStations();
|
const StationList &GetStations();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* STATION_TYPE_H */
|
#endif /* STATION_TYPE_H */
|
||||||
|
|
Loading…
Reference in New Issue