diff src/ship_cmd.cpp @ 5972:6ece78140826 draft

(svn r8661) -Fix: [depot windows] Enlarge the blocks in the depot window if a sprite is too big to fit (ships and aircraft only) -Codechange: depot windows default now makes a 1x1 matrix and resize the window by block size*number of blocks This will make less vehicle type specific code and easier to read resizing based on sprite sizes
author bjarni <bjarni@openttd.org>
date Sat, 10 Feb 2007 13:37:32 +0000 (2007-02-10)
parents ca95cde4d1b4
children 1b793d99b5ba
line wrap: on
line diff
--- a/src/ship_cmd.cpp
+++ b/src/ship_cmd.cpp
@@ -27,6 +27,7 @@
 #include "newgrf_text.h"
 #include "newgrf_sound.h"
 #include "date.h"
+#include "spritecache.h"
 
 static const uint16 _ship_sprites[] = {0x0E5D, 0x0E55, 0x0E65, 0x0E6D};
 
@@ -59,6 +60,32 @@
 	DrawSprite(6 + _ship_sprites[spritenum], pal, x, y);
 }
 
+/** Get the size of the sprite of a ship sprite heading west (used for lists)
+ * @param engine The engine to get the sprite from
+ * @param &width The width of the sprite
+ * @param &height The height of the sprite
+ */
+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);
+
+	width  = spr->width;
+	height = spr->height;
+}
+
 int GetShipImage(const Vehicle* v, Direction direction)
 {
 	int spritenum = v->spritenum;