MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / Append

Method Append

src/cargopacket.cpp:255–279  ·  view source on GitHub ↗

* 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

Source from the content-addressed store, hash-verified

253 * @pre action == MTA_LOAD || (action == MTA_KEEP && this->designation_counts[MTA_LOAD] == 0)
254 */
255void 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.

Callers 5

CheckMD5Method · 0.45
UpdateStationWaitingFunction · 0.45
CalcGRFMD5SumFunction · 0.45
AddFileMethod · 0.45
operator()Method · 0.45

Calls 4

AddToMetaMethod · 0.95
NOT_REACHEDFunction · 0.85
push_backMethod · 0.80
AddToCacheMethod · 0.80

Tested by

no test coverage detected