From 0d32783f87b9a32fa8f0bf539514ed08faebbd2a Mon Sep 17 00:00:00 2001 From: peter1138 Date: Wed, 18 Apr 2007 18:37:40 +0000 Subject: (svn r9671) -Codechange: Implement NewGRF callback 36, which allows changing of various properties which were previously static. Vehicle max speed and train power/te/running costs are adjustable. --- src/train_cmd.cpp | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) (limited to 'src/train_cmd.cpp') diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp index 4855ef8e0..81f0b513d 100644 --- a/src/train_cmd.cpp +++ b/src/train_cmd.cpp @@ -63,7 +63,7 @@ byte FreightWagonMult(CargoID cargo) */ void TrainPowerChanged(Vehicle* v) { - uint32 power = 0; + uint32 total_power = 0; uint32 max_te = 0; for (const Vehicle *u = v; u != NULL; u = u->next) { @@ -76,19 +76,22 @@ void TrainPowerChanged(Vehicle* v) const RailVehicleInfo *rvi_u = RailVehInfo(u->engine_type); - if (engine_has_power && rvi_u->power != 0) { - power += rvi_u->power; - /* Tractive effort in (tonnes * 1000 * 10 =) N */ - max_te += (u->u.rail.cached_veh_weight * 10000 * rvi_u->tractive_effort) / 256; + if (engine_has_power) { + uint16 power = GetVehicleProperty(u, 0x0B, rvi_u->power); + if (power != 0) { + total_power += power; + /* Tractive effort in (tonnes * 1000 * 10 =) N */ + max_te += (u->u.rail.cached_veh_weight * 10000 * GetVehicleProperty(u, 0x1F, rvi_u->tractive_effort)) / 256; + } } if (HASBIT(u->u.rail.flags, VRF_POWEREDWAGON) && (wagon_has_power)) { - power += RailVehInfo(u->u.rail.first_engine)->pow_wag_power; + total_power += RailVehInfo(u->u.rail.first_engine)->pow_wag_power; } } - if (v->u.rail.cached_power != power || v->u.rail.cached_max_te != max_te) { - v->u.rail.cached_power = power; + if (v->u.rail.cached_power != total_power || v->u.rail.cached_max_te != max_te) { + v->u.rail.cached_power = total_power; v->u.rail.cached_max_te = max_te; InvalidateWindow(WC_VEHICLE_DETAILS, v->index); InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); @@ -208,9 +211,10 @@ void TrainConsistChanged(Vehicle* v) } /* max speed is the minimum of the speed limits of all vehicles in the consist */ - if ((rvi_u->railveh_type != RAILVEH_WAGON || _patches.wagon_speed_limits) && - rvi_u->max_speed != 0 && !UsesWagonOverride(u)) - max_speed = min(rvi_u->max_speed, max_speed); + if ((rvi_u->railveh_type != RAILVEH_WAGON || _patches.wagon_speed_limits) && !UsesWagonOverride(u)) { + uint16 speed = GetVehicleProperty(u, 0x09, rvi_u->max_speed); + if (speed != 0) max_speed = min(speed, max_speed); + } } /* check the vehicle length (callback) */ @@ -3473,8 +3477,11 @@ int32 GetTrainRunningCost(const Vehicle *v) do { const RailVehicleInfo *rvi = RailVehInfo(v->engine_type); - if (rvi->running_cost_base > 0) - cost += rvi->running_cost_base * _price.running_rail[rvi->running_cost_class]; + + byte cost_factor = GetVehicleProperty(v, 0x0D, rvi->running_cost_base); + if (cost_factor == 0) continue; + + cost += cost_factor * _price.running_rail[rvi->running_cost_class]; } while ((v = GetNextVehicle(v)) != NULL); return cost; -- cgit v1.2.3-70-g09d2