summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authortron <tron@openttd.org>2007-01-21 18:46:19 +0000
committertron <tron@openttd.org>2007-01-21 18:46:19 +0000
commitfb8b0557f9e101515acc71a4a2d8bc709cfe733d (patch)
tree4d9e5dd25c2b463c83295bcfdc1e5420771a2812 /src
parent84f4ca8b566ea73b8a518958b72bd2f7868529a2 (diff)
downloadopenttd-fb8b0557f9e101515acc71a4a2d8bc709cfe733d.tar.xz
(svn r8320) -Fix
Simplify TrainPowerChanged() somewhat by eleminating code duplication
Diffstat (limited to 'src')
-rw-r--r--src/train_cmd.cpp16
1 files changed, 4 insertions, 12 deletions
diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp
index 750745081..8e82f0b4f 100644
--- a/src/train_cmd.cpp
+++ b/src/train_cmd.cpp
@@ -65,22 +65,14 @@ void TrainPowerChanged(Vehicle* v)
uint32 max_te = 0;
for (u = v; u != NULL; u = u->next) {
- const RailVehicleInfo *rvi_u;
- bool engine_has_power = true;
- bool wagon_has_power = true;
-
/* Power is not added for articulated parts */
if (IsArticulatedPart(u)) continue;
- if (IsLevelCrossingTile(u->tile)) {
- if (!HasPowerOnRail(u->u.rail.railtype, GetRailTypeCrossing(u->tile))) engine_has_power = false;
- if (!HasPowerOnRail(v->u.rail.railtype, GetRailTypeCrossing(u->tile))) wagon_has_power = false;
- } else {
- if (!HasPowerOnRail(u->u.rail.railtype, GetRailType(u->tile))) engine_has_power = false;
- if (!HasPowerOnRail(v->u.rail.railtype, GetRailType(u->tile))) wagon_has_power = false;
- }
+ RailType railtype = (IsLevelCrossingTile(u->tile) ? GetRailTypeCrossing(u->tile) : GetRailType(u->tile));
+ bool engine_has_power = HasPowerOnRail(u->u.rail.railtype, railtype);
+ bool wagon_has_power = HasPowerOnRail(v->u.rail.railtype, railtype);
- rvi_u = RailVehInfo(u->engine_type);
+ const RailVehicleInfo *rvi_u = RailVehInfo(u->engine_type);
if (engine_has_power && rvi_u->power != 0) {
power += rvi_u->power;