summaryrefslogtreecommitdiff
path: root/src/roadveh_cmd.cpp
diff options
context:
space:
mode:
authorpeter1138 <peter1138@openttd.org>2008-04-21 20:50:58 +0000
committerpeter1138 <peter1138@openttd.org>2008-04-21 20:50:58 +0000
commit5dcd689f5662d93ade95e3fd04332b8456605add (patch)
treeb307e9b6916fb53727cd6a80f2c5478a0b4ab819 /src/roadveh_cmd.cpp
parent173ac52da5c933f35e5cae799679bed8c580078f (diff)
downloadopenttd-5dcd689f5662d93ade95e3fd04332b8456605add.tar.xz
(svn r12824) -Codechange: Standardise routines for drawing vehicle images, using correct types and less duplication.
Diffstat (limited to 'src/roadveh_cmd.cpp')
-rw-r--r--src/roadveh_cmd.cpp44
1 files changed, 25 insertions, 19 deletions
diff --git a/src/roadveh_cmd.cpp b/src/roadveh_cmd.cpp
index 19578162f..28d515330 100644
--- a/src/roadveh_cmd.cpp
+++ b/src/roadveh_cmd.cpp
@@ -94,36 +94,42 @@ static const Trackdir _roadveh_depot_exit_trackdir[DIAGDIR_END] = {
TRACKDIR_X_NE, TRACKDIR_Y_SE, TRACKDIR_X_SW, TRACKDIR_Y_NW
};
-int RoadVehicle::GetImage(Direction direction) const
+static SpriteID GetRoadVehIcon(EngineID engine)
{
- int img = this->spritenum;
- int image;
+ uint8 spritenum = RoadVehInfo(engine)->image_index;
- if (is_custom_sprite(img)) {
- image = GetCustomVehicleSprite(this, (Direction)(direction + 4 * IS_CUSTOM_SECONDHEAD_SPRITE(img)));
- if (image != 0) return image;
- img = _orig_road_vehicle_info[this->engine_type - ROAD_ENGINES_INDEX].image_index;
+ if (is_custom_sprite(spritenum)) {
+ SpriteID sprite = GetCustomVehicleIcon(engine, DIR_W);
+ if (sprite != 0) return sprite;
+
+ spritenum = _orig_road_vehicle_info[engine - ROAD_ENGINES_INDEX].image_index;
}
- image = direction + _roadveh_images[img];
- if (this->cargo.Count() >= this->cargo_cap / 2U) image += _roadveh_full_adder[img];
- return image;
+ return 6 + _roadveh_images[spritenum];
}
-void DrawRoadVehEngine(int x, int y, EngineID engine, SpriteID pal)
+SpriteID RoadVehicle::GetImage(Direction direction) const
{
- int spritenum = RoadVehInfo(engine)->image_index;
+ uint8 spritenum = this->spritenum;
+ SpriteID sprite;
if (is_custom_sprite(spritenum)) {
- int sprite = GetCustomVehicleIcon(engine, DIR_W);
+ sprite = GetCustomVehicleSprite(this, (Direction)(direction + 4 * IS_CUSTOM_SECONDHEAD_SPRITE(spritenum)));
+ if (sprite != 0) return sprite;
- if (sprite != 0) {
- DrawSprite(sprite, pal, x, y);
- return;
- }
- spritenum = _orig_road_vehicle_info[engine - ROAD_ENGINES_INDEX].image_index;
+ spritenum = _orig_road_vehicle_info[this->engine_type - ROAD_ENGINES_INDEX].image_index;
}
- DrawSprite(6 + _roadveh_images[spritenum], pal, x, y);
+
+ sprite = direction + _roadveh_images[spritenum];
+
+ if (this->cargo.Count() >= this->cargo_cap / 2U) sprite += _roadveh_full_adder[spritenum];
+
+ return sprite;
+}
+
+void DrawRoadVehEngine(int x, int y, EngineID engine, SpriteID pal)
+{
+ DrawSprite(GetRoadVehIcon(engine), pal, x, y);
}
static CommandCost EstimateRoadVehCost(EngineID engine_type)