summaryrefslogtreecommitdiff
path: root/src/cargopacket.cpp
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2013-02-17 14:10:15 +0000
committerrubidium <rubidium@openttd.org>2013-02-17 14:10:15 +0000
commit2795ed5b091fa5580976547b3669bac78cd595ce (patch)
tree9b0d3c0b5444157729363fc0323b6a2236e53d49 /src/cargopacket.cpp
parent6647cb917963c4e0d6d633b7a92af78167050893 (diff)
downloadopenttd-2795ed5b091fa5580976547b3669bac78cd595ce.tar.xz
(svn r25008) -Codechange: Make CargoList::Truncate behave similarly to CargoList::MoveTo, i.e. pass the amount to truncate (fonsinchen)
Diffstat (limited to 'src/cargopacket.cpp')
-rw-r--r--src/cargopacket.cpp8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/cargopacket.cpp b/src/cargopacket.cpp
index 0b92de0c8..0603d9125 100644
--- a/src/cargopacket.cpp
+++ b/src/cargopacket.cpp
@@ -209,11 +209,14 @@ void CargoList<Tinst>::Append(CargoPacket *cp)
/**
* Truncates the cargo in this list to the given amount. It leaves the
* first count cargo entities and removes the rest.
- * @param max_remaining Maximum amount of entities to be in the list after the command.
+ * @param max_move Maximum amount of entities to be removed from the list.
+ * @return Amount of entities actually moved.
*/
template <class Tinst>
-void CargoList<Tinst>::Truncate(uint max_remaining)
+uint CargoList<Tinst>::Truncate(uint max_move)
{
+ max_move = min(this->count, max_move);
+ uint max_remaining = this->count - max_move;
for (Iterator it(packets.begin()); it != packets.end(); /* done during loop*/) {
CargoPacket *cp = *it;
if (max_remaining == 0) {
@@ -236,6 +239,7 @@ void CargoList<Tinst>::Truncate(uint max_remaining)
}
++it;
}
+ return max_move;
}
/**