src/ship_cmd.cpp
changeset 10293 b3ca071d6716
parent 10286 aa0670a976a5
child 10314 9cfcdd5b5ddb
--- a/src/ship_cmd.cpp	Mon Apr 21 17:04:17 2008 +0000
+++ b/src/ship_cmd.cpp	Mon Apr 21 20:50:58 2008 +0000
@@ -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;
 }