src/ship_cmd.cpp
changeset 9022 8fa9e902b06e
parent 9019 fe04abd3f58f
child 9036 6368fe55fd6d
equal deleted inserted replaced
9021:02ce84bd2368 9022:8fa9e902b06e
    56 static inline TrackBits GetTileShipTrackStatus(TileIndex tile)
    56 static inline TrackBits GetTileShipTrackStatus(TileIndex tile)
    57 {
    57 {
    58 	return TrackStatusToTrackBits(GetTileTrackStatus(tile, TRANSPORT_WATER, 0));
    58 	return TrackStatusToTrackBits(GetTileTrackStatus(tile, TRANSPORT_WATER, 0));
    59 }
    59 }
    60 
    60 
       
    61 static SpriteID GetShipIcon(EngineID engine)
       
    62 {
       
    63 	uint8 spritenum = ShipVehInfo(engine)->image_index;
       
    64 
       
    65 	if (is_custom_sprite(spritenum)) {
       
    66 		SpriteID sprite = GetCustomVehicleIcon(engine, DIR_W);
       
    67 		if (sprite != 0) return sprite;
       
    68 
       
    69 		spritenum = _orig_ship_vehicle_info[engine - SHIP_ENGINES_INDEX].image_index;
       
    70 	}
       
    71 
       
    72 	return 6 + _ship_sprites[spritenum];
       
    73 }
       
    74 
    61 void DrawShipEngine(int x, int y, EngineID engine, SpriteID pal)
    75 void DrawShipEngine(int x, int y, EngineID engine, SpriteID pal)
    62 {
    76 {
    63 	int spritenum = ShipVehInfo(engine)->image_index;
    77 	DrawSprite(GetShipIcon(engine), pal, x, y);
    64 
       
    65 	if (is_custom_sprite(spritenum)) {
       
    66 		int sprite = GetCustomVehicleIcon(engine, DIR_W);
       
    67 
       
    68 		if (sprite != 0) {
       
    69 			DrawSprite(sprite, pal, x, y);
       
    70 			return;
       
    71 		}
       
    72 		spritenum = _orig_ship_vehicle_info[engine - SHIP_ENGINES_INDEX].image_index;
       
    73 	}
       
    74 	DrawSprite(6 + _ship_sprites[spritenum], pal, x, y);
       
    75 }
    78 }
    76 
    79 
    77 /** Get the size of the sprite of a ship sprite heading west (used for lists)
    80 /** Get the size of the sprite of a ship sprite heading west (used for lists)
    78  * @param engine The engine to get the sprite from
    81  * @param engine The engine to get the sprite from
    79  * @param width The width of the sprite
    82  * @param width The width of the sprite
    80  * @param height The height of the sprite
    83  * @param height The height of the sprite
    81  */
    84  */
    82 void GetShipSpriteSize(EngineID engine, uint &width, uint &height)
    85 void GetShipSpriteSize(EngineID engine, uint &width, uint &height)
    83 {
    86 {
    84 	SpriteID spritenum = ShipVehInfo(engine)->image_index;
    87 	const Sprite *spr = GetSprite(GetShipIcon(engine));
    85 	SpriteID custom_sprite = 0;
       
    86 
       
    87 	if (is_custom_sprite(spritenum)) {
       
    88 		custom_sprite = GetCustomVehicleIcon(engine, DIR_W);
       
    89 		spritenum = _orig_ship_vehicle_info[engine - SHIP_ENGINES_INDEX].image_index;
       
    90 	}
       
    91 	if (custom_sprite == 0) {
       
    92 		spritenum = 6 + _ship_sprites[spritenum];
       
    93 	} else {
       
    94 		spritenum = custom_sprite;
       
    95 	}
       
    96 
       
    97 	const Sprite *spr = GetSprite(spritenum);
       
    98 
    88 
    99 	width  = spr->width;
    89 	width  = spr->width;
   100 	height = spr->height;
    90 	height = spr->height;
   101 }
    91 }
   102 
    92 
   103 int Ship::GetImage(Direction direction) const
    93 SpriteID Ship::GetImage(Direction direction) const
   104 {
    94 {
   105 	int spritenum = this->spritenum;
    95 	uint8 spritenum = this->spritenum;
   106 
    96 
   107 	if (is_custom_sprite(spritenum)) {
    97 	if (is_custom_sprite(spritenum)) {
   108 		int sprite = GetCustomVehicleSprite(this, direction);
    98 		SpriteID sprite = GetCustomVehicleSprite(this, direction);
   109 
       
   110 		if (sprite != 0) return sprite;
    99 		if (sprite != 0) return sprite;
       
   100 
   111 		spritenum = _orig_ship_vehicle_info[this->engine_type - SHIP_ENGINES_INDEX].image_index;
   101 		spritenum = _orig_ship_vehicle_info[this->engine_type - SHIP_ENGINES_INDEX].image_index;
   112 	}
   102 	}
       
   103 
   113 	return _ship_sprites[spritenum] + direction;
   104 	return _ship_sprites[spritenum] + direction;
   114 }
   105 }
   115 
   106 
   116 static const Depot* FindClosestShipDepot(const Vehicle* v)
   107 static const Depot* FindClosestShipDepot(const Vehicle* v)
   117 {
   108 {