From cdb7c25827b7ba156a3f6294d5bab54332011eda Mon Sep 17 00:00:00 2001 From: Peter Nelson Date: Tue, 24 Oct 2023 14:34:09 +0100 Subject: [PATCH 1/2] 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 From 9f8978ce95f660a565efbae6a820988f45a4bcee Mon Sep 17 00:00:00 2001 From: Peter Nelson Date: Tue, 24 Oct 2023 14:16:06 +0100 Subject: [PATCH 2/2] Fix #11392: Check exclusivity of neutral station when (un)loading vehicles. Neutral stations do not have an owner, so the vehicle owner needs to be checked instead. --- src/economy.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/economy.cpp b/src/economy.cpp index b478882f45..d6817cd1ca 100644 --- a/src/economy.cpp +++ b/src/economy.cpp @@ -1635,10 +1635,14 @@ static void LoadUnloadVehicle(Vehicle *front) StationID last_visited = front->last_station_visited; Station *st = Station::Get(last_visited); + /* If this is a neutral station, check its industry for exclusivity. */ + bool can_load = front->owner == st->GetExclusivityConsumer(); + bool can_unload = front->owner == st->GetExclusivitySupplier(); + StationIDStack next_station = front->GetNextStoppingStation(); bool use_autorefit = front->current_order.IsRefit() && front->current_order.GetRefitCargo() == CT_AUTO_REFIT; CargoArray consist_capleft{}; - if (_settings_game.order.improved_load && use_autorefit ? + if (can_load && _settings_game.order.improved_load && use_autorefit ? front->cargo_payment == nullptr : (front->current_order.GetLoadType() & OLFB_FULL_LOAD) != 0) { ReserveConsist(st, front, (use_autorefit && front->load_unload_ticks != 0) ? &consist_capleft : nullptr, @@ -1680,7 +1684,7 @@ static void LoadUnloadVehicle(Vehicle *front) GoodsEntry *ge = &st->goods[v->cargo_type]; - if (HasBit(v->vehicle_flags, VF_CARGO_UNLOADING) && (front->current_order.GetUnloadType() & OUFB_NO_UNLOAD) == 0) { + if (can_unload && HasBit(v->vehicle_flags, VF_CARGO_UNLOADING) && (front->current_order.GetUnloadType() & OUFB_NO_UNLOAD) == 0) { uint cargo_count = v->cargo.UnloadCount(); uint amount_unloaded = _settings_game.order.gradual_loading ? std::min(cargo_count, GetLoadAmount(v)) : cargo_count; bool remaining = false; // Are there cargo entities in this vehicle that can still be unloaded here? @@ -1747,7 +1751,7 @@ static void LoadUnloadVehicle(Vehicle *front) } /* Do not pick up goods when we have no-load set or loading is stopped. */ - if (front->current_order.GetLoadType() & OLFB_NO_LOAD || HasBit(front->vehicle_flags, VF_STOP_LOADING)) continue; + if (!can_load || front->current_order.GetLoadType() & OLFB_NO_LOAD || HasBit(front->vehicle_flags, VF_STOP_LOADING)) continue; /* This order has a refit, if this is the first vehicle part carrying cargo and the whole vehicle is empty, try refitting. */ if (front->current_order.IsRefit() && artic_part == 1) {