diff --git a/src/economy.cpp b/src/economy.cpp index cc38b0468f..2e0c725793 100644 --- a/src/economy.cpp +++ b/src/economy.cpp @@ -1080,7 +1080,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); @@ -1644,10 +1644,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() == CARGO_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, @@ -1689,7 +1693,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? @@ -1754,7 +1758,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) { diff --git a/src/station.cpp b/src/station.cpp index ef1579d9af..81246bd53c 100644 --- a/src/station.cpp +++ b/src/station.cpp @@ -438,6 +438,16 @@ void Station::RemoveFromAllNearbyLists() for (const IndustryID &industryid : industries) { Industry::Get(industryid)->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 6dda3ca843..65e236366b 100644 --- a/src/station_base.h +++ b/src/station_base.h @@ -496,6 +496,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 82d13ac694..13aa6db34c 100644 --- a/src/station_cmd.cpp +++ b/src/station_cmd.cpp @@ -4406,7 +4406,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