Changeset - r19758:0924962fbd17
[Not reviewed]
master
0 2 0
frosch - 12 years ago 2012-11-12 20:13:02
frosch@openttd.org
(svn r24713) -Fix [FS#5262]: [NewGRF] Tolerate old NewGRFs returning invalid values via CB 11.
2 files changed with 5 insertions and 4 deletions:
0 comments (0 inline, 0 general)
src/roadveh_cmd.cpp
Show inline comments
 
@@ -166,19 +166,19 @@ static uint GetRoadVehLength(const RoadV
 
	uint length = VEHICLE_LENGTH;
 

	
 
	uint16 veh_len = CALLBACK_FAILED;
 
	if (e->GetGRF() != NULL && e->GetGRF()->grf_version >= 8) {
 
		/* Use callback 36 */
 
		veh_len = GetVehicleProperty(v, PROP_ROADVEH_SHORTEN_FACTOR, CALLBACK_FAILED);
 
		if (veh_len != CALLBACK_FAILED && veh_len >= VEHICLE_LENGTH) ErrorUnknownCallbackResult(e->GetGRFID(), CBID_VEHICLE_LENGTH, veh_len);
 
	} else {
 
		/* Use callback 11 */
 
		veh_len = GetVehicleCallback(CBID_VEHICLE_LENGTH, 0, 0, v->engine_type, v);
 
	}
 
	if (veh_len == CALLBACK_FAILED) veh_len = e->u.road.shorten_factor;
 
	if (veh_len != 0) {
 
		if (veh_len >= VEHICLE_LENGTH) ErrorUnknownCallbackResult(e->GetGRFID(), CBID_VEHICLE_LENGTH, veh_len);
 
		length -= Clamp(veh_len, 0, VEHICLE_LENGTH - 1);
 
	}
 

	
 
	return length;
 
}
 

	
src/train_cmd.cpp
Show inline comments
 
@@ -205,19 +205,20 @@ void Train::ConsistChanged(bool same_len
 

	
 
		/* check the vehicle length (callback) */
 
		uint16 veh_len = CALLBACK_FAILED;
 
		if (e_u->GetGRF() != NULL && e_u->GetGRF()->grf_version >= 8) {
 
			/* Use callback 36 */
 
			veh_len = GetVehicleProperty(u, PROP_TRAIN_SHORTEN_FACTOR, CALLBACK_FAILED);
 

	
 
			if (veh_len != CALLBACK_FAILED && veh_len >= VEHICLE_LENGTH) {
 
				ErrorUnknownCallbackResult(e_u->GetGRFID(), CBID_VEHICLE_LENGTH, veh_len);
 
			}
 
		} else if (HasBit(e_u->info.callback_mask, CBM_VEHICLE_LENGTH)) {
 
			/* Use callback 11 */
 
			veh_len = GetVehicleCallback(CBID_VEHICLE_LENGTH, 0, 0, u->engine_type, u);
 
		}
 
		if (veh_len != CALLBACK_FAILED && veh_len >= VEHICLE_LENGTH) {
 
			ErrorUnknownCallbackResult(e_u->GetGRFID(), CBID_VEHICLE_LENGTH, veh_len);
 
		}
 
		if (veh_len == CALLBACK_FAILED) veh_len = rvi_u->shorten_factor;
 
		veh_len = VEHICLE_LENGTH - Clamp(veh_len, 0, VEHICLE_LENGTH - 1);
 

	
 
		/* verify length hasn't changed */
 
		if (same_length && veh_len != u->gcache.cached_veh_length) VehicleLengthChanged(u);
 

	
0 comments (0 inline, 0 general)