mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-02-08 23:34:15 +00:00
(svn r23174) -Codechange: Deduplicate code between GetEngineProperty() and GetVehicleProperty().
This commit is contained in:
parent
026317bb44
commit
50b480b959
@ -213,7 +213,7 @@ uint Engine::DetermineCapacity(const Vehicle *v, uint16 *mail_capacity) const
|
||||
if (!this->CanCarryCargo()) return 0;
|
||||
|
||||
if (mail_capacity != NULL && this->type == VEH_AIRCRAFT && IsCargoInClass(v->cargo_type, CC_PASSENGERS)) {
|
||||
*mail_capacity = GetVehicleProperty(v, PROP_AIRCRAFT_MAIL_CAPACITY, this->u.air.mail_capacity);
|
||||
*mail_capacity = GetEngineProperty(this->index, PROP_AIRCRAFT_MAIL_CAPACITY, this->u.air.mail_capacity, v);
|
||||
}
|
||||
CargoID default_cargo = this->GetDefaultCargoType();
|
||||
|
||||
@ -228,10 +228,10 @@ uint Engine::DetermineCapacity(const Vehicle *v, uint16 *mail_capacity) const
|
||||
/* Get capacity according to property resp. CB */
|
||||
uint capacity;
|
||||
switch (this->type) {
|
||||
case VEH_TRAIN: capacity = GetVehicleProperty(v, PROP_TRAIN_CARGO_CAPACITY, this->u.rail.capacity); break;
|
||||
case VEH_ROAD: capacity = GetVehicleProperty(v, PROP_ROADVEH_CARGO_CAPACITY, this->u.road.capacity); break;
|
||||
case VEH_SHIP: capacity = GetVehicleProperty(v, PROP_SHIP_CARGO_CAPACITY, this->u.ship.capacity); break;
|
||||
case VEH_AIRCRAFT: capacity = GetVehicleProperty(v, PROP_AIRCRAFT_PASSENGER_CAPACITY, this->u.air.passenger_capacity); break;
|
||||
case VEH_TRAIN: capacity = GetEngineProperty(this->index, PROP_TRAIN_CARGO_CAPACITY, this->u.rail.capacity, v); break;
|
||||
case VEH_ROAD: capacity = GetEngineProperty(this->index, PROP_ROADVEH_CARGO_CAPACITY, this->u.road.capacity, v); break;
|
||||
case VEH_SHIP: capacity = GetEngineProperty(this->index, PROP_SHIP_CARGO_CAPACITY, this->u.ship.capacity, v); break;
|
||||
case VEH_AIRCRAFT: capacity = GetEngineProperty(this->index, PROP_AIRCRAFT_PASSENGER_CAPACITY, this->u.air.passenger_capacity, v); break;
|
||||
default: NOT_REACHED();
|
||||
}
|
||||
|
||||
@ -240,7 +240,7 @@ uint Engine::DetermineCapacity(const Vehicle *v, uint16 *mail_capacity) const
|
||||
if (this->type != VEH_SHIP) {
|
||||
if (this->type == VEH_AIRCRAFT) {
|
||||
if (!IsCargoInClass(v->cargo_type, CC_PASSENGERS)) {
|
||||
capacity += GetVehicleProperty(v, PROP_AIRCRAFT_MAIL_CAPACITY, this->u.air.mail_capacity);
|
||||
capacity += GetEngineProperty(this->index, PROP_AIRCRAFT_MAIL_CAPACITY, this->u.air.mail_capacity, v);
|
||||
}
|
||||
if (v->cargo_type == CT_MAIL) return capacity;
|
||||
} else {
|
||||
|
@ -1079,16 +1079,13 @@ uint16 GetVehicleCallbackParent(CallbackID callback, uint32 param1, uint32 param
|
||||
/* Callback 36 handlers */
|
||||
uint GetVehicleProperty(const Vehicle *v, PropertyID property, uint orig_value)
|
||||
{
|
||||
uint16 callback = GetVehicleCallback(CBID_VEHICLE_MODIFY_PROPERTY, property, 0, v->engine_type, v);
|
||||
if (callback != CALLBACK_FAILED) return callback;
|
||||
|
||||
return orig_value;
|
||||
return GetEngineProperty(v->engine_type, property, orig_value, v);
|
||||
}
|
||||
|
||||
|
||||
uint GetEngineProperty(EngineID engine, PropertyID property, uint orig_value)
|
||||
uint GetEngineProperty(EngineID engine, PropertyID property, uint orig_value, const Vehicle *v)
|
||||
{
|
||||
uint16 callback = GetVehicleCallback(CBID_VEHICLE_MODIFY_PROPERTY, property, 0, engine, NULL);
|
||||
uint16 callback = GetVehicleCallback(CBID_VEHICLE_MODIFY_PROPERTY, property, 0, engine, v);
|
||||
if (callback != CALLBACK_FAILED) return callback;
|
||||
|
||||
return orig_value;
|
||||
|
@ -46,7 +46,7 @@ bool UsesWagonOverride(const Vehicle *v);
|
||||
/* Handler to Evaluate callback 36. If the callback fails (i.e. most of the
|
||||
* time) orig_value is returned */
|
||||
uint GetVehicleProperty(const Vehicle *v, PropertyID property, uint orig_value);
|
||||
uint GetEngineProperty(EngineID engine, PropertyID property, uint orig_value);
|
||||
uint GetEngineProperty(EngineID engine, PropertyID property, uint orig_value, const Vehicle *v = NULL);
|
||||
|
||||
enum VehicleTrigger {
|
||||
VEHICLE_TRIGGER_NEW_CARGO = 0x01,
|
||||
|
Loading…
Reference in New Issue
Block a user