* Appends the given cargo packet. Tries to merge it with another one in the * packets list. If no fitting packet is found, appends it. You can only append * packets to the ranges of packets designated for keeping or loading. * Furthermore if there are already packets reserved for loading you cannot * directly add packets to the "keep" list. You first have to load the reserved * ones. * @warn
| 253 | * @pre action == MTA_LOAD || (action == MTA_KEEP && this->designation_counts[MTA_LOAD] == 0) |
| 254 | */ |
| 255 | void VehicleCargoList::Append(CargoPacket *cp, MoveToAction action) |
| 256 | { |
| 257 | assert(cp != nullptr); |
| 258 | assert(action == MTA_LOAD || |
| 259 | (action == MTA_KEEP && this->action_counts[MTA_LOAD] == 0)); |
| 260 | this->AddToMeta(cp, action); |
| 261 | |
| 262 | if (this->count == cp->count) { |
| 263 | this->packets.push_back(cp); |
| 264 | return; |
| 265 | } |
| 266 | |
| 267 | uint sum = cp->count; |
| 268 | for (ReverseIterator it(this->packets.rbegin()); it != this->packets.rend(); it++) { |
| 269 | CargoPacket *icp = *it; |
| 270 | if (VehicleCargoList::TryMerge(icp, cp)) return; |
| 271 | sum += icp->count; |
| 272 | if (sum >= this->action_counts[action]) { |
| 273 | this->packets.push_back(cp); |
| 274 | return; |
| 275 | } |
| 276 | } |
| 277 | |
| 278 | NOT_REACHED(); |
| 279 | } |
| 280 | |
| 281 | /** |
| 282 | * Shifts cargo from the front of the packet list and applies some action to it. |
no test coverage detected