mirror of https://github.com/OpenTTD/OpenTTD
(svn r11741) -Feature: Add support for NewGRF's train 'tilt' flag. Trains with tilt capability (specific details are per NewGRF set) will be given a 20% speed limit bonus on curves.
parent
9a2547b5a7
commit
47082fec5c
|
@ -164,12 +164,16 @@ void TrainConsistChanged(Vehicle* v)
|
||||||
v->u.rail.cached_total_length = 0;
|
v->u.rail.cached_total_length = 0;
|
||||||
v->u.rail.compatible_railtypes = 0;
|
v->u.rail.compatible_railtypes = 0;
|
||||||
|
|
||||||
|
bool train_can_tilt = true;
|
||||||
|
|
||||||
for (Vehicle *u = v; u != NULL; u = u->Next()) {
|
for (Vehicle *u = v; u != NULL; u = u->Next()) {
|
||||||
const RailVehicleInfo *rvi_u = RailVehInfo(u->engine_type);
|
const RailVehicleInfo *rvi_u = RailVehInfo(u->engine_type);
|
||||||
|
|
||||||
/* Check the v->first cache. */
|
/* Check the v->first cache. */
|
||||||
assert(u->First() == v);
|
assert(u->First() == v);
|
||||||
|
|
||||||
|
if (!HasBit(EngInfo(u->engine_type)->misc_flags, EF_RAIL_TILTS)) train_can_tilt = false;
|
||||||
|
|
||||||
/* update the 'first engine' */
|
/* update the 'first engine' */
|
||||||
u->u.rail.first_engine = v == u ? INVALID_ENGINE : first_engine;
|
u->u.rail.first_engine = v == u ? INVALID_ENGINE : first_engine;
|
||||||
u->u.rail.railtype = rvi_u->railtype;
|
u->u.rail.railtype = rvi_u->railtype;
|
||||||
|
@ -253,6 +257,7 @@ void TrainConsistChanged(Vehicle* v)
|
||||||
|
|
||||||
/* store consist weight/max speed in cache */
|
/* store consist weight/max speed in cache */
|
||||||
v->u.rail.cached_max_speed = max_speed;
|
v->u.rail.cached_max_speed = max_speed;
|
||||||
|
v->u.rail.cached_tilt = train_can_tilt;
|
||||||
|
|
||||||
/* recalculate cached weights and power too (we do this *after* the rest, so it is known which wagons are powered and need extra weight added) */
|
/* recalculate cached weights and power too (we do this *after* the rest, so it is known which wagons are powered and need extra weight added) */
|
||||||
TrainCargoChanged(v);
|
TrainCargoChanged(v);
|
||||||
|
@ -338,6 +343,11 @@ static int GetTrainAcceleration(Vehicle *v, bool mode)
|
||||||
/* Apply the engine's rail type curve speed advantage, if it slowed by curves */
|
/* Apply the engine's rail type curve speed advantage, if it slowed by curves */
|
||||||
const RailtypeInfo *rti = GetRailTypeInfo(v->u.rail.railtype);
|
const RailtypeInfo *rti = GetRailTypeInfo(v->u.rail.railtype);
|
||||||
max_speed += (max_speed / 2) * rti->curve_speed;
|
max_speed += (max_speed / 2) * rti->curve_speed;
|
||||||
|
|
||||||
|
if (v->u.rail.cached_tilt) {
|
||||||
|
/* Apply max_speed bonus of 20% for a tilting train */
|
||||||
|
max_speed += max_speed / 5;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IsTileType(v->tile, MP_STATION) && IsFrontEngine(v)) {
|
if (IsTileType(v->tile, MP_STATION) && IsFrontEngine(v)) {
|
||||||
|
|
|
@ -81,6 +81,7 @@ struct VehicleRail {
|
||||||
/* cached values, recalculated on load and each time a vehicle is added to/removed from the consist. */
|
/* cached values, recalculated on load and each time a vehicle is added to/removed from the consist. */
|
||||||
uint16 cached_max_speed; // max speed of the consist. (minimum of the max speed of all vehicles in the consist)
|
uint16 cached_max_speed; // max speed of the consist. (minimum of the max speed of all vehicles in the consist)
|
||||||
uint32 cached_power; // total power of the consist.
|
uint32 cached_power; // total power of the consist.
|
||||||
|
bool cached_tilt; // train can tilt; feature provides a bonus in curves
|
||||||
uint8 cached_veh_length; // length of this vehicle in units of 1/8 of normal length, cached because this can be set by a callback
|
uint8 cached_veh_length; // length of this vehicle in units of 1/8 of normal length, cached because this can be set by a callback
|
||||||
uint16 cached_total_length; ///< Length of the whole train, valid only for first engine.
|
uint16 cached_total_length; ///< Length of the whole train, valid only for first engine.
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue