Changeset - r18281:b4005aa8879f
[Not reviewed]
master
0 1 0
michi_cc - 13 years ago 2011-11-06 22:14:55
michi_cc@openttd.org
(svn r23127) -Fix [FS#4819] (r23086): Don't crash when refitting default vehicles.
1 file changed with 12 insertions and 8 deletions:
0 comments (0 inline, 0 general)
src/vehicle_cmd.cpp
Show inline comments
 
@@ -212,15 +212,19 @@ static int GetRefitCostFactor(const Vehi
 
{
 
	/* 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];
 

	
 
	/* 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;
 
		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;
0 comments (0 inline, 0 general)