mirror of https://github.com/OpenTTD/OpenTTD
(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)release/1.1
parent
7af2470a78
commit
b4273bcd35
|
@ -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.
|
* Split this packet in two and return the split off part.
|
||||||
* @param new_size Size of the remaining 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)
|
FORCEINLINE CargoPacket *CargoPacket::Split(uint new_size)
|
||||||
{
|
{
|
||||||
|
if (!CargoPacket::CanAllocateItem()) return NULL;
|
||||||
|
|
||||||
Money fs = this->feeder_share * new_size / static_cast<uint>(this->count);
|
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);
|
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;
|
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. */
|
/* But... the rest needs package splitting. */
|
||||||
CargoPacket *cp_new = cp->Split(max_move);
|
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.
|
static_cast<Tinst *>(this)->RemoveFromCache(cp_new); // this reflects the changes in cp.
|
||||||
|
|
||||||
if (mta == MTA_TRANSFER) {
|
if (mta == MTA_TRANSFER) {
|
||||||
|
|
|
@ -1093,6 +1093,10 @@ void PrepareUnload(Vehicle *front_v)
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(front_v->cargo_payment == NULL);
|
assert(front_v->cargo_payment == NULL);
|
||||||
|
/* One CargoPayment per vehicle and the vehicle limit equals the
|
||||||
|
* limit in number of CargoPayments. Can't go wrong. */
|
||||||
|
assert_compile(CargoPaymentPool::MAX_SIZE == VehiclePool::MAX_SIZE);
|
||||||
|
assert(CargoPayment::CanAllocateItem());
|
||||||
front_v->cargo_payment = new CargoPayment(front_v);
|
front_v->cargo_payment = new CargoPayment(front_v);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,8 +15,8 @@
|
||||||
#include "cargopacket.h"
|
#include "cargopacket.h"
|
||||||
#include "company_type.h"
|
#include "company_type.h"
|
||||||
|
|
||||||
/** Type of pool to store cargo payments in. */
|
/** Type of pool to store cargo payments in; little over 1 million. */
|
||||||
typedef Pool<CargoPayment, CargoPaymentID, 512, 64000> CargoPaymentPool;
|
typedef Pool<CargoPayment, CargoPaymentID, 512, 0xFF000> CargoPaymentPool;
|
||||||
/** The actual pool to store cargo payments in. */
|
/** The actual pool to store cargo payments in. */
|
||||||
extern CargoPaymentPool _cargo_payment_pool;
|
extern CargoPaymentPool _cargo_payment_pool;
|
||||||
|
|
||||||
|
|
|
@ -3165,6 +3165,10 @@ void ModifyStationRatingAround(TileIndex tile, Owner owner, int amount, uint rad
|
||||||
|
|
||||||
static uint UpdateStationWaiting(Station *st, CargoID type, uint amount, SourceType source_type, SourceID source_id)
|
static uint UpdateStationWaiting(Station *st, CargoID type, uint amount, SourceType source_type, SourceID source_id)
|
||||||
{
|
{
|
||||||
|
/* We can't allocate a CargoPacket? Then don't do anything
|
||||||
|
* at all; i.e. just discard the incoming cargo. */
|
||||||
|
if (!CargoPacket::CanAllocateItem()) return 0;
|
||||||
|
|
||||||
GoodsEntry &ge = st->goods[type];
|
GoodsEntry &ge = st->goods[type];
|
||||||
amount += ge.amount_fract;
|
amount += ge.amount_fract;
|
||||||
ge.amount_fract = GB(amount, 0, 8);
|
ge.amount_fract = GB(amount, 0, 8);
|
||||||
|
|
Loading…
Reference in New Issue