summaryrefslogtreecommitdiff
path: root/src/cargoaction.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/cargoaction.cpp')
-rw-r--r--src/cargoaction.cpp30
1 files changed, 27 insertions, 3 deletions
diff --git a/src/cargoaction.cpp b/src/cargoaction.cpp
index 51e06f16a..9a13e5329 100644
--- a/src/cargoaction.cpp
+++ b/src/cargoaction.cpp
@@ -12,6 +12,7 @@
#include "stdafx.h"
#include "economy_base.h"
#include "cargoaction.h"
+#include "station_base.h"
/**
* Decides if a packet needs to be split.
@@ -153,7 +154,7 @@ bool CargoReturn::operator()(CargoPacket *cp)
assert(cp_new->Count() <= this->destination->reserved_count);
this->source->RemoveFromMeta(cp_new, VehicleCargoList::MTA_LOAD, cp_new->Count());
this->destination->reserved_count -= cp_new->Count();
- this->destination->Append(cp_new);
+ this->destination->Append(cp_new, this->next);
return cp_new == cp;
}
@@ -167,8 +168,8 @@ bool CargoTransfer::operator()(CargoPacket *cp)
CargoPacket *cp_new = this->Preprocess(cp);
if (cp_new == NULL) return false;
this->source->RemoveFromMeta(cp_new, VehicleCargoList::MTA_TRANSFER, cp_new->Count());
- cp_new->AddFeederShare(this->payment->PayTransfer(cp_new, cp_new->Count()));
- this->destination->Append(cp_new);
+ /* No transfer credits here as they were already granted during Stage(). */
+ this->destination->Append(cp_new, cp_new->NextStation());
return cp_new == cp;
}
@@ -186,6 +187,29 @@ bool CargoShift::operator()(CargoPacket *cp)
return cp_new == cp;
}
+/**
+ * Reroutes some cargo from one Station sublist to another.
+ * @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)
+{
+ CargoPacket *cp_new = this->Preprocess(cp);
+ if (cp_new == NULL) cp_new = cp;
+ StationID next = this->ge->GetVia(cp_new->SourceStation(), this->avoid, this->avoid2);
+ assert(next != this->avoid && next != this->avoid2);
+ if (this->source != this->destination) {
+ this->source->RemoveFromCache(cp_new, cp_new->Count());
+ this->destination->AddToCache(cp_new);
+ }
+
+ /* Legal, as insert doesn't invalidate iterators in the MultiMap, however
+ * this might insert the packet between range.first and range.second (which might be end())
+ * This is why we check for GetKey above to avoid infinite loops. */
+ this->destination->packets.Insert(next, 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);