summaryrefslogtreecommitdiff
path: root/src/cargoaction.cpp
diff options
context:
space:
mode:
authorfonsinchen <fonsinchen@openttd.org>2013-06-23 08:28:53 +0000
committerfonsinchen <fonsinchen@openttd.org>2013-06-23 08:28:53 +0000
commit3dd811e1794bc9247d5ace0bad7ade5998a7b54f (patch)
tree61c77b60ec755ead4784c34bc8dcc0310e9b786e /src/cargoaction.cpp
parent57e5a95b6fc9cc0882c08dea75d4d5d35c96d45a (diff)
downloadopenttd-3dd811e1794bc9247d5ace0bad7ade5998a7b54f.tar.xz
(svn r25434) -Fix: reroute cargo staged for unloading if a link breaks
Diffstat (limited to 'src/cargoaction.cpp')
-rw-r--r--src/cargoaction.cpp25
1 files changed, 24 insertions, 1 deletions
diff --git a/src/cargoaction.cpp b/src/cargoaction.cpp
index 9a13e5329..929017506 100644
--- a/src/cargoaction.cpp
+++ b/src/cargoaction.cpp
@@ -192,7 +192,7 @@ bool CargoShift::operator()(CargoPacket *cp)
* @param cp Packet to be rerouted.
* @return True if the packet was completely rerouted, false if part of it was.
*/
-bool CargoReroute::operator()(CargoPacket *cp)
+bool StationCargoReroute::operator()(CargoPacket *cp)
{
CargoPacket *cp_new = this->Preprocess(cp);
if (cp_new == NULL) cp_new = cp;
@@ -210,6 +210,29 @@ bool CargoReroute::operator()(CargoPacket *cp)
return cp_new == cp;
}
+/**
+ * Reroutes some cargo in a VehicleCargoList.
+ * @param cp Packet to be rerouted.
+ * @return True if the packet was completely rerouted, false if part of it was.
+ */
+bool VehicleCargoReroute::operator()(CargoPacket *cp)
+{
+ CargoPacket *cp_new = this->Preprocess(cp);
+ if (cp_new == NULL) cp_new = cp;
+ if (cp_new->NextStation() == this->avoid || cp_new->NextStation() == this->avoid2) {
+ cp->SetNextStation(this->ge->GetVia(cp_new->SourceStation(), this->avoid, this->avoid2));
+ }
+ if (this->source != this->destination) {
+ this->source->RemoveFromMeta(cp_new, VehicleCargoList::MTA_TRANSFER, cp_new->Count());
+ this->source->AddToMeta(cp_new, VehicleCargoList::MTA_TRANSFER);
+ this->destination->action_counts[VehicleCargoList::MTA_TRANSFER] += cp_new->Count();
+ }
+
+ /* Legal, as front pushing doesn't invalidate iterators in std::list. */
+ this->destination->packets.push_front(cp_new);
+ return cp_new == cp;
+}
+
template uint CargoRemoval<VehicleCargoList>::Preprocess(CargoPacket *cp);
template uint CargoRemoval<StationCargoList>::Preprocess(CargoPacket *cp);
template bool CargoRemoval<VehicleCargoList>::Postprocess(CargoPacket *cp, uint remove);