Mercurial > hg > openttd
diff src/ship_cmd.cpp @ 9022:db43607c4798 draft
(svn r12824) -Codechange: Standardise routines for drawing vehicle images, using correct types and less duplication.
author | peter1138 <peter1138@openttd.org> |
---|---|
date | Mon, 21 Apr 2008 20:50:58 +0000 (2008-04-21) |
parents | 382abce6450f |
children | 74210834ed21 |
line wrap: on
line diff
--- a/src/ship_cmd.cpp +++ b/src/ship_cmd.cpp @@ -58,20 +58,23 @@ return TrackStatusToTrackBits(GetTileTrackStatus(tile, TRANSPORT_WATER, 0)); } -void DrawShipEngine(int x, int y, EngineID engine, SpriteID pal) +static SpriteID GetShipIcon(EngineID engine) { - int spritenum = ShipVehInfo(engine)->image_index; + uint8 spritenum = ShipVehInfo(engine)->image_index; if (is_custom_sprite(spritenum)) { - int sprite = GetCustomVehicleIcon(engine, DIR_W); + SpriteID sprite = GetCustomVehicleIcon(engine, DIR_W); + if (sprite != 0) return sprite; - if (sprite != 0) { - DrawSprite(sprite, pal, x, y); - return; - } spritenum = _orig_ship_vehicle_info[engine - SHIP_ENGINES_INDEX].image_index; } - DrawSprite(6 + _ship_sprites[spritenum], pal, x, y); + + return 6 + _ship_sprites[spritenum]; +} + +void DrawShipEngine(int x, int y, EngineID engine, SpriteID pal) +{ + DrawSprite(GetShipIcon(engine), pal, x, y); } /** Get the size of the sprite of a ship sprite heading west (used for lists) @@ -81,35 +84,23 @@ */ void GetShipSpriteSize(EngineID engine, uint &width, uint &height) { - SpriteID spritenum = ShipVehInfo(engine)->image_index; - SpriteID custom_sprite = 0; - - if (is_custom_sprite(spritenum)) { - custom_sprite = GetCustomVehicleIcon(engine, DIR_W); - spritenum = _orig_ship_vehicle_info[engine - SHIP_ENGINES_INDEX].image_index; - } - if (custom_sprite == 0) { - spritenum = 6 + _ship_sprites[spritenum]; - } else { - spritenum = custom_sprite; - } - - const Sprite *spr = GetSprite(spritenum); + const Sprite *spr = GetSprite(GetShipIcon(engine)); width = spr->width; height = spr->height; } -int Ship::GetImage(Direction direction) const +SpriteID Ship::GetImage(Direction direction) const { - int spritenum = this->spritenum; + uint8 spritenum = this->spritenum; if (is_custom_sprite(spritenum)) { - int sprite = GetCustomVehicleSprite(this, direction); + SpriteID sprite = GetCustomVehicleSprite(this, direction); + if (sprite != 0) return sprite; - if (sprite != 0) return sprite; spritenum = _orig_ship_vehicle_info[this->engine_type - SHIP_ENGINES_INDEX].image_index; } + return _ship_sprites[spritenum] + direction; }