1
0
Fork 0

(svn r23174) -Codechange: Deduplicate code between GetEngineProperty() and GetVehicleProperty().

release/1.2
frosch 2011-11-09 16:39:34 +00:00
parent 026317bb44
commit 50b480b959
3 changed files with 10 additions and 13 deletions

View File

@ -213,7 +213,7 @@ uint Engine::DetermineCapacity(const Vehicle *v, uint16 *mail_capacity) const
if (!this->CanCarryCargo()) return 0; if (!this->CanCarryCargo()) return 0;
if (mail_capacity != NULL && this->type == VEH_AIRCRAFT && IsCargoInClass(v->cargo_type, CC_PASSENGERS)) { 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(); 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 */ /* Get capacity according to property resp. CB */
uint capacity; uint capacity;
switch (this->type) { switch (this->type) {
case VEH_TRAIN: capacity = GetVehicleProperty(v, PROP_TRAIN_CARGO_CAPACITY, this->u.rail.capacity); break; case VEH_TRAIN: capacity = GetEngineProperty(this->index, PROP_TRAIN_CARGO_CAPACITY, this->u.rail.capacity, v); break;
case VEH_ROAD: capacity = GetVehicleProperty(v, PROP_ROADVEH_CARGO_CAPACITY, this->u.road.capacity); break; case VEH_ROAD: capacity = GetEngineProperty(this->index, PROP_ROADVEH_CARGO_CAPACITY, this->u.road.capacity, v); break;
case VEH_SHIP: capacity = GetVehicleProperty(v, PROP_SHIP_CARGO_CAPACITY, this->u.ship.capacity); break; case VEH_SHIP: capacity = GetEngineProperty(this->index, PROP_SHIP_CARGO_CAPACITY, this->u.ship.capacity, v); break;
case VEH_AIRCRAFT: capacity = GetVehicleProperty(v, PROP_AIRCRAFT_PASSENGER_CAPACITY, this->u.air.passenger_capacity); break; case VEH_AIRCRAFT: capacity = GetEngineProperty(this->index, PROP_AIRCRAFT_PASSENGER_CAPACITY, this->u.air.passenger_capacity, v); break;
default: NOT_REACHED(); 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_SHIP) {
if (this->type == VEH_AIRCRAFT) { if (this->type == VEH_AIRCRAFT) {
if (!IsCargoInClass(v->cargo_type, CC_PASSENGERS)) { 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; if (v->cargo_type == CT_MAIL) return capacity;
} else { } else {

View File

@ -1079,16 +1079,13 @@ uint16 GetVehicleCallbackParent(CallbackID callback, uint32 param1, uint32 param
/* Callback 36 handlers */ /* Callback 36 handlers */
uint GetVehicleProperty(const Vehicle *v, PropertyID property, uint orig_value) uint GetVehicleProperty(const Vehicle *v, PropertyID property, uint orig_value)
{ {
uint16 callback = GetVehicleCallback(CBID_VEHICLE_MODIFY_PROPERTY, property, 0, v->engine_type, v); return GetEngineProperty(v->engine_type, property, orig_value, v);
if (callback != CALLBACK_FAILED) return callback;
return orig_value;
} }
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; if (callback != CALLBACK_FAILED) return callback;
return orig_value; return orig_value;

View File

@ -46,7 +46,7 @@ bool UsesWagonOverride(const Vehicle *v);
/* Handler to Evaluate callback 36. If the callback fails (i.e. most of the /* Handler to Evaluate callback 36. If the callback fails (i.e. most of the
* time) orig_value is returned */ * time) orig_value is returned */
uint GetVehicleProperty(const Vehicle *v, PropertyID property, uint orig_value); 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 { enum VehicleTrigger {
VEHICLE_TRIGGER_NEW_CARGO = 0x01, VEHICLE_TRIGGER_NEW_CARGO = 0x01,