# HG changeset patch # User peter1138 # Date 2007-04-20 21:42:06 # Node ID 6357a0cb600ebc834c3611e7bf291828ea72f6f2 # Parent 0c4e03193684f285be31790f1972aa68c7c307d0 (svn r9703) -Codechange: support callback 36 in vehicle purchase lists diff --git a/src/build_vehicle_gui.cpp b/src/build_vehicle_gui.cpp --- a/src/build_vehicle_gui.cpp +++ b/src/build_vehicle_gui.cpp @@ -423,7 +423,7 @@ static int DrawRailEnginePurchaseInfo(in } /* Running cost */ - SetDParam(0, (rvi->running_cost_base * _price.running_rail[rvi->running_cost_class] >> 8) << multihead); + SetDParam(0, (GetEngineProperty(engine_number, 0x0D, rvi->running_cost_base) * _price.running_rail[rvi->running_cost_class] >> 8) << multihead); DrawString(x, y, STR_PURCHASE_INFO_RUNNINGCOST, 0); y += 10; @@ -481,7 +481,7 @@ static int DrawShipPurchaseInfo(int x, i y += 10; /* Running cost */ - SetDParam(0, svi->running_cost * _price.ship_running >> 8); + SetDParam(0, GetEngineProperty(engine_number, 0x0B, svi->running_cost) * _price.ship_running >> 8); DrawString(x, y, STR_PURCHASE_INFO_RUNNINGCOST, 0); y += 10; @@ -516,7 +516,7 @@ static int DrawAircraftPurchaseInfo(int y += 10; /* Running cost */ - SetDParam(0, avi->running_cost * _price.aircraft_running >> 8); + SetDParam(0, GetEngineProperty(engine_number, 0x0E, avi->running_cost) * _price.aircraft_running >> 8); DrawString(x, y, STR_PURCHASE_INFO_RUNNINGCOST, 0); y += 10; diff --git a/src/newgrf_engine.cpp b/src/newgrf_engine.cpp --- a/src/newgrf_engine.cpp +++ b/src/newgrf_engine.cpp @@ -952,7 +952,7 @@ uint16 GetVehicleCallbackParent(uint16 c } -/* Callback 36 handler */ +/* Callback 36 handlers */ uint GetVehicleProperty(const Vehicle *v, uint8 property, uint orig_value) { uint16 callback = GetVehicleCallback(CBID_VEHICLE_MODIFY_PROPERTY, property, 0, v->engine_type, v); @@ -962,6 +962,15 @@ uint GetVehicleProperty(const Vehicle *v } +uint GetEngineProperty(EngineID engine, uint8 property, uint orig_value) +{ + uint16 callback = GetVehicleCallback(CBID_VEHICLE_MODIFY_PROPERTY, property, 0, engine, NULL); + if (callback != CALLBACK_FAILED) return callback; + + return orig_value; +} + + static void DoTriggerVehicle(Vehicle *v, VehicleTrigger trigger, byte base_random_bits, bool first) { const SpriteGroup *group; diff --git a/src/newgrf_engine.h b/src/newgrf_engine.h --- a/src/newgrf_engine.h +++ b/src/newgrf_engine.h @@ -38,6 +38,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, uint8 property, uint orig_value); +uint GetEngineProperty(EngineID engine, uint8 property, uint orig_value); enum VehicleTrigger { VEHICLE_TRIGGER_NEW_CARGO = 1,