(svn r17897) -Fix [FS#3255]: CB15 and CB36 (capacity) were not always called when they should.

-Codechange: Move capacity calculation to a single function for all vehicle types, so the behaviour can be kept consistent easier.
This commit is contained in:
frosch
2009-10-28 18:31:16 +00:00
parent 9b44d7c1fe
commit 23980e6486
8 changed files with 114 additions and 163 deletions

View File

@@ -1418,6 +1418,65 @@ SpriteID GetVehiclePalette(const Vehicle *v)
return GetEngineColourMap(v->engine_type, v->owner, INVALID_ENGINE, v);
}
/**
* Determines capacity of a given vehicle from scratch.
* For aircraft the main capacity is determined. Mail might be present as well.
* @note Keep this function consistent with Engine::GetDisplayDefaultCapacity().
* @param v Vehicle of interest
* @return Capacity
*/
uint GetVehicleCapacity(const Vehicle *v)
{
const Engine *e = Engine::Get(v->engine_type);
if (!e->CanCarryCargo()) return 0;
CargoID default_cargo = e->GetDefaultCargoType();
/* Check the refit capacity callback if we are not in the default configuration.
* Note: This might change to become more consistent/flexible/sane, esp. when default cargo is first refittable. */
if (HasBit(e->info.callback_mask, CBM_VEHICLE_REFIT_CAPACITY) &&
(default_cargo != v->cargo_type || v->cargo_subtype != 0)) {
uint16 callback = GetVehicleCallback(CBID_VEHICLE_REFIT_CAPACITY, 0, 0, v->engine_type, v);
if (callback != CALLBACK_FAILED) return callback;
}
/* Get capacity according to property resp. CB */
uint capacity;
switch (e->type) {
case VEH_TRAIN: capacity = GetVehicleProperty(v, PROP_TRAIN_CARGO_CAPACITY, e->u.rail.capacity); break;
case VEH_ROAD: capacity = GetVehicleProperty(v, PROP_ROADVEH_CARGO_CAPACITY, e->u.road.capacity); break;
case VEH_SHIP: capacity = GetVehicleProperty(v, PROP_SHIP_CARGO_CAPACITY, e->u.ship.capacity); break;
case VEH_AIRCRAFT: capacity = e->u.air.passenger_capacity; break;
default: NOT_REACHED();
}
/* Apply multipliers depending on cargo- and vehicletype.
* Note: This might change to become more consistent/flexible. */
if (e->type != VEH_SHIP) {
if (e->type == VEH_AIRCRAFT) {
if (v->cargo_type == CT_PASSENGERS) return capacity;
capacity += e->u.air.mail_capacity;
if (v->cargo_type == CT_MAIL) return capacity;
} else {
switch (default_cargo) {
case CT_PASSENGERS: break;
case CT_MAIL:
case CT_GOODS: capacity *= 2; break;
default: capacity *= 4; break;
}
}
switch (v->cargo_type) {
case CT_PASSENGERS: break;
case CT_MAIL:
case CT_GOODS: capacity /= 2; break;
default: capacity /= 4; break;
}
}
return capacity;
}
void Vehicle::BeginLoading()
{