summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormichi_cc <michi_cc@openttd.org>2011-11-06 22:14:55 +0000
committermichi_cc <michi_cc@openttd.org>2011-11-06 22:14:55 +0000
commita58b975fd005840c5340e37bb9141b26c2a293fc (patch)
treea8d8dcfed3e9f0cfafe822023da23f1db3bf9f1c
parent09c10af4800ec23811f02cfa691221caed93aa60 (diff)
downloadopenttd-a58b975fd005840c5340e37bb9141b26c2a293fc.tar.xz
(svn r23127) -Fix [FS#4819] (r23086): Don't crash when refitting default vehicles.
-rw-r--r--src/vehicle_cmd.cpp22
1 files changed, 13 insertions, 9 deletions
diff --git a/src/vehicle_cmd.cpp b/src/vehicle_cmd.cpp
index 7c6e33ae0..a237b1941 100644
--- a/src/vehicle_cmd.cpp
+++ b/src/vehicle_cmd.cpp
@@ -212,15 +212,19 @@ static int GetRefitCostFactor(const Vehicle *v, EngineID engine_type, CargoID ne
{
/* Prepare callback param with info about the new cargo type. */
const Engine *e = Engine::Get(engine_type);
- const CargoSpec *cs = CargoSpec::Get(new_cid);
- uint32 param1 = (cs->classes << 16) | (new_subtype << 8) | e->GetGRF()->cargo_map[new_cid];
-
- uint16 cb_res = GetVehicleCallback(CBID_VEHICLE_REFIT_COST, param1, 0, engine_type, v);
- if (cb_res != CALLBACK_FAILED) {
- *auto_refit_allowed = HasBit(cb_res, 14);
- int factor = GB(cb_res, 0, 14);
- if (factor >= 0x2000) factor -= 0x4000; // Treat as signed integer.
- return factor;
+
+ /* Is this vehicle a NewGRF vehicle? */
+ if (e->GetGRF() != NULL) {
+ const CargoSpec *cs = CargoSpec::Get(new_cid);
+ uint32 param1 = (cs->classes << 16) | (new_subtype << 8) | e->GetGRF()->cargo_map[new_cid];
+
+ uint16 cb_res = GetVehicleCallback(CBID_VEHICLE_REFIT_COST, param1, 0, engine_type, v);
+ if (cb_res != CALLBACK_FAILED) {
+ *auto_refit_allowed = HasBit(cb_res, 14);
+ int factor = GB(cb_res, 0, 14);
+ if (factor >= 0x2000) factor -= 0x4000; // Treat as signed integer.
+ return factor;
+ }
}
*auto_refit_allowed = e->info.refit_cost == 0;