diff options
-rw-r--r-- | src/newgrf.cpp | 4 | ||||
-rw-r--r-- | src/newgrf_properties.h | 2 | ||||
-rw-r--r-- | src/roadveh_cmd.cpp | 10 | ||||
-rw-r--r-- | src/train_cmd.cpp | 13 |
4 files changed, 21 insertions, 8 deletions
diff --git a/src/newgrf.cpp b/src/newgrf.cpp index a34388dc7..0904760c6 100644 --- a/src/newgrf.cpp +++ b/src/newgrf.cpp @@ -1099,7 +1099,7 @@ static ChangeInfoResult RailVehicleChangeInfo(uint engine, int numinfo, int prop rvi->air_drag = buf->ReadByte(); break; - case 0x21: // Shorter vehicle + case PROP_TRAIN_SHORTEN_FACTOR: // 0x21 Shorter vehicle rvi->shorten_factor = buf->ReadByte(); break; @@ -1319,7 +1319,7 @@ static ChangeInfoResult RoadVehicleChangeInfo(uint engine, int numinfo, int prop ei->cargo_age_period = buf->ReadWord(); break; - case 0x23: // Shorter vehicle + case PROP_ROADVEH_SHORTEN_FACTOR: // 0x23 Shorter vehicle rvi->shorten_factor = buf->ReadByte(); break; diff --git a/src/newgrf_properties.h b/src/newgrf_properties.h index 1f18940e0..5b2ba055a 100644 --- a/src/newgrf_properties.h +++ b/src/newgrf_properties.h @@ -25,6 +25,7 @@ enum PropertyID { PROP_TRAIN_WEIGHT = 0x16, ///< Weight in t (if dualheaded: for each single vehicle) PROP_TRAIN_COST_FACTOR = 0x17, ///< Purchase cost (if dualheaded: sum of both vehicles) PROP_TRAIN_TRACTIVE_EFFORT = 0x1F, ///< Tractive effort coefficient in 1/256 + PROP_TRAIN_SHORTEN_FACTOR = 0x21, ///< Shorter vehicles PROP_TRAIN_USER_DATA = 0x25, ///< User defined data for vehicle variable 0x42 PROP_TRAIN_CARGO_AGE_PERIOD = 0x2B, ///< Number of ticks before carried cargo is aged @@ -36,6 +37,7 @@ enum PropertyID { PROP_ROADVEH_SPEED = 0x15, ///< Max. speed: 1 unit = 1/0.8 mph = 2 km-ish/h PROP_ROADVEH_TRACTIVE_EFFORT = 0x18, ///< Tractive effort coefficient in 1/256 PROP_ROADVEH_CARGO_AGE_PERIOD = 0x22, ///< Number of ticks before carried cargo is aged + PROP_ROADVEH_SHORTEN_FACTOR = 0x23, ///< Shorter vehicles PROP_SHIP_COST_FACTOR = 0x0A, ///< Purchase cost PROP_SHIP_SPEED = 0x0B, ///< Max. speed: 1 unit = 1/3.2 mph = 0.5 km-ish/h diff --git a/src/roadveh_cmd.cpp b/src/roadveh_cmd.cpp index 6754874ea..e48cbb349 100644 --- a/src/roadveh_cmd.cpp +++ b/src/roadveh_cmd.cpp @@ -34,6 +34,7 @@ #include "core/random_func.hpp" #include "company_base.h" #include "core/backup_type.hpp" +#include "newgrf.h" #include "table/strings.h" @@ -164,7 +165,14 @@ static uint GetRoadVehLength(const RoadVehicle *v) const Engine *e = v->GetEngine(); uint length = e->u.road.shorten_factor; - uint16 veh_len = GetVehicleCallback(CBID_VEHICLE_LENGTH, 0, 0, v->engine_type, v); + 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); + } else { + /* Use callback 11 */ + veh_len = GetVehicleCallback(CBID_VEHICLE_LENGTH, 0, 0, v->engine_type, v); + } if (veh_len != CALLBACK_FAILED) { if (veh_len >= VEHICLE_LENGTH) ErrorUnknownCallbackResult(e->GetGRFID(), CBID_VEHICLE_LENGTH, veh_len); length -= Clamp(veh_len, 0, VEHICLE_LENGTH - 1); diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp index bc7898667..94921a3eb 100644 --- a/src/train_cmd.cpp +++ b/src/train_cmd.cpp @@ -221,12 +221,15 @@ void Train::ConsistChanged(bool same_length) /* check the vehicle length (callback) */ uint16 veh_len = CALLBACK_FAILED; - if (HasBit(e_u->info.callback_mask, CBM_VEHICLE_LENGTH)) { + if (e_u->GetGRF() != NULL && e_u->GetGRF()->grf_version >= 8) { + /* Use callback 36 */ + veh_len = GetVehicleProperty(u, PROP_TRAIN_SHORTEN_FACTOR, CALLBACK_FAILED); + } 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 >= 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); |