summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfonsinchen <fonsinchen@openttd.org>2013-10-22 16:15:59 +0000
committerfonsinchen <fonsinchen@openttd.org>2013-10-22 16:15:59 +0000
commitbd230f34f415c6c89b40e504c8a56e1bca29ac2e (patch)
tree3d4b1482b0031240a19741e49a929c5e80ce324c
parent6524849386fa7b24814db93746c2c07c3de8f1c0 (diff)
downloadopenttd-bd230f34f415c6c89b40e504c8a56e1bca29ac2e.tar.xz
(svn r25900) -Change [FS#5677]: Allow restricted flows to be picked for kept cargo.
-rw-r--r--src/cargopacket.cpp43
-rw-r--r--src/cargopacket.h3
-rw-r--r--src/saveload/saveload.cpp2
3 files changed, 39 insertions, 9 deletions
diff --git a/src/cargopacket.cpp b/src/cargopacket.cpp
index 9a1ba8568..3820d8c77 100644
--- a/src/cargopacket.cpp
+++ b/src/cargopacket.cpp
@@ -409,6 +409,29 @@ void VehicleCargoList::SetTransferLoadPlace(TileIndex xy)
}
/**
+ * Choose action to be performed with the given cargo packet.
+ * @param cp The packet.
+ * @param cargo_next Next hop the cargo wants to pass.
+ * @param current_station Current station of the vehicle carrying the cargo.
+ * @param accepted If the cargo is accepted at the current station.
+ * @param next_station Next station(s) the vehicle may stop at.
+ * @return MoveToAction to be performed.
+ */
+/* static */ VehicleCargoList::MoveToAction VehicleCargoList::ChooseAction(const CargoPacket *cp, StationID cargo_next,
+ StationID current_station, bool accepted, StationIDStack next_station)
+{
+ if (cargo_next == INVALID_STATION) {
+ return (accepted && cp->source != current_station) ? MTA_DELIVER : MTA_KEEP;
+ } else if (cargo_next == current_station) {
+ return MTA_DELIVER;
+ } else if (next_station.Contains(cargo_next)) {
+ return MTA_KEEP;
+ } else {
+ return MTA_TRANSFER;
+ }
+}
+
+/**
* Stages cargo for unloading. The cargo is sorted so that packets to be
* transferred, delivered or kept are in consecutive chunks in the list. At the
* same time the designation_counts are updated to reflect the size of those
@@ -470,15 +493,19 @@ bool VehicleCargoList::Stage(bool accepted, StationID current_station, StationID
if (cp->source == INVALID_STATION && !ge->flows.empty()) {
cp->source = ge->flows.begin()->first;
}
- cargo_next = ge->GetVia(cp->source);
- if (cargo_next == INVALID_STATION) {
- action = (accepted && cp->source != current_station) ? MTA_DELIVER : MTA_KEEP;
- } else if (cargo_next == current_station) {
- action = MTA_DELIVER;
- } else if (next_station.Contains(cargo_next)) {
- action = MTA_KEEP;
+ bool restricted = false;
+ FlowStatMap::const_iterator flow_it(ge->flows.find(cp->source));
+ if (flow_it == ge->flows.end()) {
+ cargo_next = INVALID_STATION;
} else {
- action = MTA_TRANSFER;
+ cargo_next = flow_it->second.GetViaWithRestricted(restricted);
+ }
+ action = VehicleCargoList::ChooseAction(cp, cargo_next, current_station, accepted, next_station);
+ if (restricted && action == MTA_TRANSFER) {
+ /* If the flow is restricted we can't transfer to it. Choose an
+ * unrestricted one instead. */
+ cargo_next = flow_it->second.GetVia();
+ action = VehicleCargoList::ChooseAction(cp, cargo_next, current_station, accepted, next_station);
}
}
Money share;
diff --git a/src/cargopacket.h b/src/cargopacket.h
index 3ae9e9927..d425f30f5 100644
--- a/src/cargopacket.h
+++ b/src/cargopacket.h
@@ -311,6 +311,9 @@ protected:
void AddToMeta(const CargoPacket *cp, MoveToAction action);
void RemoveFromMeta(const CargoPacket *cp, MoveToAction action, uint count);
+ static MoveToAction ChooseAction(const CargoPacket *cp, StationID cargo_next,
+ StationID current_station, bool accepted, StationIDStack next_station);
+
public:
/** The station cargo list needs to control the unloading. */
friend class StationCargoList;
diff --git a/src/saveload/saveload.cpp b/src/saveload/saveload.cpp
index 88f812097..4bffa40c7 100644
--- a/src/saveload/saveload.cpp
+++ b/src/saveload/saveload.cpp
@@ -252,7 +252,7 @@
* 184 25508
* 185 25620
* 186 25833
- * 187 ?????
+ * 187 25899
*/
extern const uint16 SAVEGAME_VERSION = 187; ///< Current savegame version of OpenTTD.