diff options
author | smatz <smatz@openttd.org> | 2011-02-08 18:27:21 +0000 |
---|---|---|
committer | smatz <smatz@openttd.org> | 2011-02-08 18:27:21 +0000 |
commit | b4273bcd35d4d0083dc9bd88a207283b4e3ba014 (patch) | |
tree | 80b6912d15868478bcd766083f738c8d197415fd /src/cargopacket.cpp | |
parent | 7af2470a78d73ac2953a6ed2eb36bca15c03d3e4 (diff) | |
download | openttd-b4273bcd35d4d0083dc9bd88a207283b4e3ba014.tar.xz |
(svn r22023) -Fix: verify we can allocate a CargoPacket and CargoPayment before we actually try to do so
-Codechange: increase the limit of number of CargoPayments to match the limit of Vehicles (Rubidium)
Diffstat (limited to 'src/cargopacket.cpp')
-rw-r--r-- | src/cargopacket.cpp | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/src/cargopacket.cpp b/src/cargopacket.cpp index 676e408ea..f7d4348f9 100644 --- a/src/cargopacket.cpp +++ b/src/cargopacket.cpp @@ -88,10 +88,12 @@ CargoPacket::CargoPacket(uint16 count, byte days_in_transit, StationID source, T /** * Split this packet in two and return the split off part. * @param new_size Size of the remaining part. - * @return Split off part. + * @return Split off part, or NULL if no packet could be allocated! */ FORCEINLINE CargoPacket *CargoPacket::Split(uint new_size) { + if (!CargoPacket::CanAllocateItem()) return NULL; + Money fs = this->feeder_share * new_size / static_cast<uint>(this->count); CargoPacket *cp_new = new CargoPacket(new_size, this->days_in_transit, this->source, this->source_xy, this->loaded_at_xy, fs, this->source_type, this->source_id); this->feeder_share -= fs; @@ -315,6 +317,9 @@ bool CargoList<Tinst>::MoveTo(Tother_inst *dest, uint max_move, MoveToAction mta /* But... the rest needs package splitting. */ CargoPacket *cp_new = cp->Split(max_move); + /* We could not allocate a CargoPacket? Is the map that full? */ + if (cp_new == NULL) return false; + static_cast<Tinst *>(this)->RemoveFromCache(cp_new); // this reflects the changes in cp. if (mta == MTA_TRANSFER) { |