Changeset - r17273:b5e141ad8e00
[Not reviewed]
master
0 4 0
smatz - 14 years ago 2011-02-08 18:27:21
smatz@openttd.org
(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)
4 files changed with 16 insertions and 3 deletions:
0 comments (0 inline, 0 general)
src/cargopacket.cpp
Show inline comments
 
@@ -85,16 +85,18 @@ CargoPacket::CargoPacket(uint16 count, b
 
	this->source_type = source_type;
 
}
 

	
 
/**
 
 * 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;
 
	this->count -= new_size;
 
	return cp_new;
 
}
 
@@ -312,12 +314,15 @@ bool CargoList<Tinst>::MoveTo(Tother_ins
 
			cp->feeder_share = 0;
 
			cp->count = left;
 
		} else {
 
			/* 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) {
 
				/* Add the feeder share before inserting in dest. */
 
				cp_new->feeder_share += payment->PayTransfer(cp_new, max_move);
 
			} else if (mta == MTA_CARGO_LOAD) {
src/economy.cpp
Show inline comments
 
@@ -1090,12 +1090,16 @@ void PrepareUnload(Vehicle *front_v)
 
				SetBit(v->vehicle_flags, VF_CARGO_UNLOADING);
 
			}
 
		}
 
	}
 

	
 
	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);
 
}
 

	
 
/**
 
 * Loads/unload the vehicle if possible.
 
 * @param v the vehicle to be (un)loaded
src/economy_base.h
Show inline comments
 
@@ -12,14 +12,14 @@
 
#ifndef ECONOMY_BASE_H
 
#define ECONOMY_BASE_H
 

	
 
#include "cargopacket.h"
 
#include "company_type.h"
 

	
 
/** Type of pool to store cargo payments in. */
 
typedef Pool<CargoPayment, CargoPaymentID, 512, 64000> CargoPaymentPool;
 
/** Type of pool to store cargo payments in; little over 1 million. */
 
typedef Pool<CargoPayment, CargoPaymentID, 512, 0xFF000> CargoPaymentPool;
 
/** The actual pool to store cargo payments in. */
 
extern CargoPaymentPool _cargo_payment_pool;
 

	
 
/**
 
 * Helper class to perform the cargo payment.
 
 */
src/station_cmd.cpp
Show inline comments
 
@@ -3162,12 +3162,16 @@ void ModifyStationRatingAround(TileIndex
 
		}
 
	}
 
}
 

	
 
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];
 
	amount += ge.amount_fract;
 
	ge.amount_fract = GB(amount, 0, 8);
 

	
 
	amount >>= 8;
 
	/* No new "real" cargo item yet. */
0 comments (0 inline, 0 general)