Merge branch 'master' into jgrpp

# Conflicts:
#	src/economy.cpp
#	src/linkgraph/refresh.cpp
#	src/order_cmd.cpp
#	src/saveload/vehicle_sl.cpp
#	src/station.cpp
#	src/station_base.h
#	src/timetable_cmd.cpp
#	src/timetable_gui.cpp
#	src/vehicle.cpp
#	src/vehicle_base.h
#	src/vehicle_cmd.cpp
This commit is contained in:
Jonathan G Rennison
2022-03-04 18:17:44 +00:00
37 changed files with 296 additions and 245 deletions

View File

@@ -408,12 +408,24 @@ bool Station::IsWithinRangeOfDockingTile(TileIndex tile, uint max_distance) cons
/**
* Add nearby industry to station's industries_near list if it accepts cargo.
* @param ind Industry
* For industries that are already on the list update distance if it's closer.
* @param ind Industry
* @param tile Tile of the industry to measure distance to.
*/
void Station::AddIndustryToDeliver(Industry *ind)
void Station::AddIndustryToDeliver(Industry *ind, TileIndex tile)
{
/* Don't check further if this industry is already in the list */
if (this->industries_near.find(ind) != this->industries_near.end()) return;
/* Using DistanceMax to get about the same order as with previously used CircularTileSearch. */
uint distance = DistanceMax(this->xy, tile);
/* Don't check further if this industry is already in the list but update the distance if it's closer */
auto pos = std::find_if(this->industries_near.begin(), this->industries_near.end(), [&](const IndustryListEntry &e) { return e.industry->index == ind->index; });
if (pos != this->industries_near.end()) {
if (pos->distance > distance) {
this->industries_near.erase(pos);
this->industries_near.insert(IndustryListEntry{distance, ind});
}
return;
}
/* Include only industries that can accept cargo */
uint cargo_index;
@@ -422,9 +434,21 @@ void Station::AddIndustryToDeliver(Industry *ind)
}
if (cargo_index >= lengthof(ind->accepts_cargo)) return;
this->industries_near.insert(ind);
this->industries_near.insert(IndustryListEntry{distance, ind});
}
/**
* Remove nearby industry from station's industries_near list.
* @param ind Industry
*/
void Station::RemoveIndustryToDeliver(Industry *ind) {
auto pos = std::find_if(this->industries_near.begin(), this->industries_near.end(), [&](const IndustryListEntry &e) { return e.industry->index == ind->index; });
if (pos != this->industries_near.end()) {
this->industries_near.erase(pos);
}
}
/**
* Remove this station from the nearby stations lists of all towns and industries.
*/
@@ -474,11 +498,11 @@ void Station::RecomputeCatchment(bool no_clear_nearby_lists)
}
/* The industry's stations_near may have been computed before its neutral station was built so clear and re-add here. */
for (Station *st : this->industry->stations_near) {
st->industries_near.erase(this->industry);
st->RemoveIndustryToDeliver(this->industry);
}
this->industry->stations_near.clear();
this->industry->stations_near.insert(this);
this->industries_near.insert(this->industry);
this->industries_near.insert(IndustryListEntry{0, this->industry});
/* Loop finding all station tiles */
TileArea ta(TileXY(this->rect.left, this->rect.top), TileXY(this->rect.right, this->rect.bottom));
@@ -524,7 +548,7 @@ void Station::RecomputeCatchment(bool no_clear_nearby_lists)
i->stations_near.insert(this);
/* Add if we can deliver to this industry as well */
this->AddIndustryToDeliver(i);
this->AddIndustryToDeliver(i, tile);
}
}
}