summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2009-05-26 08:53:16 +0000
committerrubidium <rubidium@openttd.org>2009-05-26 08:53:16 +0000
commit984bd3b98d6a7ad40fdfa9ef74da79dbd7de8840 (patch)
treec327cfdd375c86670b3c671a5985c32828a2514c
parent462c1ec4f3f3bb5745bb5b541bd2a93b1784d829 (diff)
downloadopenttd-984bd3b98d6a7ad40fdfa9ef74da79dbd7de8840.tar.xz
(svn r16427) -Codechange: replace a few magic numbers with an existing constant and unduplicate a few lines.
-rw-r--r--src/aircraft_cmd.cpp2
-rw-r--r--src/roadveh_cmd.cpp2
-rw-r--r--src/ship_cmd.cpp2
-rw-r--r--src/train_cmd.cpp9
4 files changed, 10 insertions, 5 deletions
diff --git a/src/aircraft_cmd.cpp b/src/aircraft_cmd.cpp
index ff16b54cc..1b6c2d3bd 100644
--- a/src/aircraft_cmd.cpp
+++ b/src/aircraft_cmd.cpp
@@ -187,7 +187,7 @@ static SpriteID GetAircraftIcon(EngineID engine)
spritenum = Engine::Get(engine)->image_index;
}
- return 6 + _aircraft_sprite[spritenum];
+ return DIR_W + _aircraft_sprite[spritenum];
}
void DrawAircraftEngine(int x, int y, EngineID engine, SpriteID pal)
diff --git a/src/roadveh_cmd.cpp b/src/roadveh_cmd.cpp
index 1af83b6e6..41213de94 100644
--- a/src/roadveh_cmd.cpp
+++ b/src/roadveh_cmd.cpp
@@ -93,7 +93,7 @@ static SpriteID GetRoadVehIcon(EngineID engine)
spritenum = Engine::Get(engine)->image_index;
}
- return 6 + _roadveh_images[spritenum];
+ return DIR_W + _roadveh_images[spritenum];
}
SpriteID RoadVehicle::GetImage(Direction direction) const
diff --git a/src/ship_cmd.cpp b/src/ship_cmd.cpp
index a164b94f0..0e947eccd 100644
--- a/src/ship_cmd.cpp
+++ b/src/ship_cmd.cpp
@@ -59,7 +59,7 @@ static SpriteID GetShipIcon(EngineID engine)
spritenum = Engine::Get(engine)->image_index;
}
- return 6 + _ship_sprites[spritenum];
+ return DIR_W + _ship_sprites[spritenum];
}
void DrawShipEngine(int x, int y, EngineID engine, SpriteID pal)
diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp
index 8f635b0db..eef3ebe82 100644
--- a/src/train_cmd.cpp
+++ b/src/train_cmd.cpp
@@ -568,6 +568,11 @@ void UpdateTrainAcceleration(Train *v)
v->acceleration = Clamp(power / weight * 4, 1, 255);
}
+static SpriteID GetDefaultTrainSprite(uint8 spritenum, Direction direction)
+{
+ return ((direction + _engine_sprite_add[spritenum]) & _engine_sprite_and[spritenum]) + _engine_sprite_base[spritenum];
+}
+
SpriteID Train::GetImage(Direction direction) const
{
uint8 spritenum = this->spritenum;
@@ -582,7 +587,7 @@ SpriteID Train::GetImage(Direction direction) const
spritenum = Engine::Get(this->engine_type)->image_index;
}
- sprite = _engine_sprite_base[spritenum] + ((direction + _engine_sprite_add[spritenum]) & _engine_sprite_and[spritenum]);
+ sprite = GetDefaultTrainSprite(spritenum, direction);
if (this->cargo.Count() >= this->cargo_cap / 2U) sprite += _wagon_full_adder[spritenum];
@@ -606,7 +611,7 @@ static SpriteID GetRailIcon(EngineID engine, bool rear_head, int &y)
if (rear_head) spritenum++;
- return ((6 + _engine_sprite_add[spritenum]) & _engine_sprite_and[spritenum]) + _engine_sprite_base[spritenum];
+ return GetDefaultTrainSprite(spritenum, DIR_W);
}
void DrawTrainEngine(int x, int y, EngineID engine, SpriteID pal)