From cdb7c25827b7ba156a3f6294d5bab54332011eda Mon Sep 17 00:00:00 2001 From: Peter Nelson Date: Tue, 24 Oct 2023 14:34:09 +0100 Subject: [PATCH] Fix #11392: Handle industry exclusivity for neutral stations. --- src/economy.cpp | 2 +- src/station.cpp | 10 ++++++++++ src/station_base.h | 3 +++ src/station_cmd.cpp | 2 +- 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/economy.cpp b/src/economy.cpp index bc2bd93878..b478882f45 100644 --- a/src/economy.cpp +++ b/src/economy.cpp @@ -1073,7 +1073,7 @@ static uint DeliverGoodsToIndustry(const Station *st, CargoID cargo_type, uint n /* Check if industry temporarily refuses acceptance */ if (IndustryTemporarilyRefusesCargo(ind, cargo_type)) continue; - if (ind->exclusive_supplier != INVALID_OWNER && ind->exclusive_supplier != st->owner) continue; + if (ind->exclusive_supplier != INVALID_OWNER && ind->exclusive_supplier != st->GetExclusivitySupplier()) continue; /* Insert the industry into _cargo_delivery_destinations, if not yet contained */ include(_cargo_delivery_destinations, ind); diff --git a/src/station.cpp b/src/station.cpp index 99957cd2f1..253760eb9f 100644 --- a/src/station.cpp +++ b/src/station.cpp @@ -430,6 +430,16 @@ void Station::RemoveFromAllNearbyLists() for (Industry *i : Industry::Iterate()) { i->stations_near.erase(this); } } +Owner Station::GetExclusivityConsumer() const +{ + return this->industry == nullptr || this->industry->exclusive_consumer == INVALID_OWNER ? this->owner : this->industry->exclusive_consumer; +} + +Owner Station::GetExclusivitySupplier() const +{ + return this->industry == nullptr || this->industry->exclusive_supplier == INVALID_OWNER ? this->owner : this->industry->exclusive_supplier; +} + /** * Test if the given town ID is covered by our catchment area. * This is used when removing a house tile to determine if it was the last house tile diff --git a/src/station_base.h b/src/station_base.h index 86b43fbf14..d30c22b972 100644 --- a/src/station_base.h +++ b/src/station_base.h @@ -499,6 +499,9 @@ public: void RemoveIndustryToDeliver(Industry *ind); void RemoveFromAllNearbyLists(); + Owner GetExclusivityConsumer() const; + Owner GetExclusivitySupplier() const; + inline bool TileIsInCatchment(TileIndex tile) const { return this->catchment_tiles.HasTile(tile); diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp index bb4faef811..528f8fdc73 100644 --- a/src/station_cmd.cpp +++ b/src/station_cmd.cpp @@ -4179,7 +4179,7 @@ uint MoveGoodsToStation(CargoID type, uint amount, SourceType source_type, Sourc std::vector used_stations; for (Station *st : *all_stations) { - if (exclusivity != INVALID_OWNER && exclusivity != st->owner) continue; + if (exclusivity != INVALID_OWNER && exclusivity != st->GetExclusivityConsumer()) continue; if (!CanMoveGoodsToStation(st, type)) continue; /* Avoid allocating a vector if there is only one station to significantly