--- a/src/ship_cmd.cpp Fri Apr 25 02:15:34 2008 +0000
+++ b/src/ship_cmd.cpp Mon May 26 20:45:25 2008 +0000
@@ -1,6 +1,6 @@
/* $Id$ */
-/** @file ship_cmd.cpp */
+/** @file ship_cmd.cpp Handling of ships. */
#include "stdafx.h"
#include "openttd.h"
@@ -14,6 +14,7 @@
#include "station_base.h"
#include "news_func.h"
#include "engine_func.h"
+#include "engine_base.h"
#include "player_func.h"
#include "player_base.h"
#include "npf.h"
@@ -28,7 +29,6 @@
#include "newgrf_text.h"
#include "newgrf_sound.h"
#include "spritecache.h"
-#include "misc/autoptr.hpp"
#include "strings_func.h"
#include "functions.h"
#include "window_func.h"
@@ -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;
+ spritenum = GetEngine(engine)->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;
+ spritenum = GetEngine(this->engine_type)->image_index;
}
+
return _ship_sprites[spritenum] + direction;
}
@@ -292,26 +283,22 @@
static void CheckShipLeaveDepot(Vehicle *v)
{
- TileIndex tile;
- Axis axis;
- uint m;
-
if (!v->IsInDepot()) return;
- tile = v->tile;
- axis = GetShipDepotAxis(tile);
+ TileIndex tile = v->tile;
+ Axis axis = GetShipDepotAxis(tile);
- /* Check first side */
+ /* Check first (north) side */
if (_ship_sometracks[axis] & GetTileShipTrackStatus(TILE_ADD(tile, ToTileIndexDiff(_ship_leave_depot_offs[axis])))) {
- m = (axis == AXIS_X) ? 0x101 : 0x207;
- /* Check second side */
+ v->direction = ReverseDir(AxisToDirection(axis));
+ /* Check second (south) side */
} else if (_ship_sometracks[axis + 2] & GetTileShipTrackStatus(TILE_ADD(tile, -2 * ToTileIndexDiff(_ship_leave_depot_offs[axis])))) {
- m = (axis == AXIS_X) ? 0x105 : 0x203;
+ v->direction = AxisToDirection(axis);
} else {
return;
}
- v->direction = (Direction)GB(m, 0, 8);
- v->u.ship.state = (TrackBits)GB(m, 8, 8);
+
+ v->u.ship.state = AxisToTrackBits(axis);
v->vehstatus &= ~VS_HIDDEN;
v->cur_speed = 0;
@@ -362,7 +349,7 @@
SetDParam(0, st->index);
AddNewsItem(
STR_9833_CITIZENS_CELEBRATE_FIRST,
- NM_THIN, NF_VIEWPORT | NF_VEHICLE, (v->owner == _local_player) ? NT_ARRIVAL_PLAYER : NT_ARRIVAL_OTHER, DNC_NONE,
+ (v->owner == _local_player) ? NS_ARRIVAL_PLAYER : NS_ARRIVAL_OTHER,
v->index,
0);
}
@@ -882,19 +869,16 @@
*/
CommandCost CmdStartStopShip(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
{
- Vehicle *v;
- uint16 callback;
-
if (!IsValidVehicleID(p1)) return CMD_ERROR;
- v = GetVehicle(p1);
+ Vehicle *v = GetVehicle(p1);
if (v->type != VEH_SHIP || !CheckOwnership(v->owner)) return CMD_ERROR;
/* Check if this ship can be started/stopped. The callback will fail or
* return 0xFF if it can. */
- callback = GetVehicleCallback(CBID_VEHICLE_START_STOP_CHECK, 0, 0, v->engine_type, v);
- if (callback != CALLBACK_FAILED && callback != 0xFF) {
+ uint16 callback = GetVehicleCallback(CBID_VEHICLE_START_STOP_CHECK, 0, 0, v->engine_type, v);
+ if (callback != CALLBACK_FAILED && GB(callback, 0, 8) != 0xFF) {
StringID error = GetGRFStringID(GetEngineGRFID(v->engine_type), 0xD000 + callback);
return_cmd_error(error);
}