# Ship Struct Reference

All ships have this type. More...

`#include <ship.h>`

Inheritance diagram for Ship:

## Public Member Functions

| Ship ()
| We don't want GCC to zero our struct! It already is zeroed and has an index!
virtual | ~Ship ()
| We want to 'destruct' the right class.
const char * | GetTypeString () const
| Get a string 'representation' of the vehicle type.
void | MarkDirty ()
| Marks the vehicles to be redrawn and updates cached variables.
void | UpdateDeltaXY (Direction direction)
| Updates the x and y offsets and the size of the sprite used for this vehicle.
ExpensesType | GetExpenseType (bool income) const
| Sets the expense type associated to this vehicle type.
void | PlayLeaveStationSound () const
| Play the sound associated with leaving the station.
bool | IsPrimaryVehicle () const
| Whether this is the primary vehicle in the chain.
SpriteID | GetImage (Direction direction) const
| Gets the sprite to show for the given direction.
int | GetDisplaySpeed () const
| Gets the speed in km-ish/h that can be sent into SetDParam for string processing.
int | GetDisplayMaxSpeed () const
| Gets the maximum speed in km-ish/h that can be sent into SetDParam for string processing.
Money | GetRunningCost () const
| Gets the running cost of a vehicle.
bool | IsInDepot () const
| Check whether the vehicle is in the depot.
bool | Tick ()
| Calls the tick handler of the vehicle.
void | OnNewDay ()
| Calls the new day handler of the vehicle.
Trackdir | GetVehicleTrackdir () const
| Returns the Trackdir on which the vehicle is currently located.
TileIndex | GetOrderStationLocation (StationID station)
| Determine the location for the station where the vehicle goes to next.
bool | FindClosestDepot (TileIndex *location, DestinationID *destination, bool *reverse)
| Find the closest depot for this vehicle and tell us the location, DestinationID and whether we should reverse.

## Data Fields

TrackBitsByte | state

## Detailed Description

All ships have this type.

Definition at line 23 of file ship.h.

## Constructor & Destructor Documentation

virtual Ship::~Ship | ( |  | ) | `[inline, virtual]`

We want to 'destruct' the right class.

Definition at line 29 of file ship.h.

References Vehicle::PreDestructor().

## Member Function Documentation

bool Ship::FindClosestDepot | ( | TileIndex * | location,
|  | DestinationID * | destination,
|  | bool * | reverse |
| ) |  |  | `[virtual]`

Find the closest depot for this vehicle and tell us the location, DestinationID and whether we should reverse.

Parameters:

  | location | where do we go to?
  | destination | what hangar do we go to?
  | reverse | should the vehicle be reversed?

Returns:
  true if a depot could be found.

Reimplemented from Vehicle.

Definition at line 729 of file ship_cmd.cpp.

References Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem< Tpool >::index.

int Ship::GetDisplayMaxSpeed | ( |  | ) | const`[inline, virtual]`

Gets the maximum speed in km-ish/h that can be sent into SetDParam for string processing.

Returns:
  the vehicle's maximum speed

Reimplemented from Vehicle.

Definition at line 39 of file ship.h.

References Vehicle::max_speed.

int Ship::GetDisplaySpeed | ( |  | ) | const`[inline, virtual]`

Gets the speed in km-ish/h that can be sent into SetDParam for string processing.

Returns:
  the vehicle's speed

Reimplemented from Vehicle.

Definition at line 38 of file ship.h.

References Vehicle::cur_speed.

ExpensesType Ship::GetExpenseType | ( | bool | income | ) | const`[inline, virtual]`

Sets the expense type associated to this vehicle type.

Parameters:

  | income | whether this is income or (running) expenses of the vehicle

Reimplemented from Vehicle.

Definition at line 34 of file ship.h.

References EXPENSES_SHIP_INC, and EXPENSES_SHIP_RUN.

SpriteID Ship::GetImage | ( | Direction | direction | ) | const`[virtual]`

Gets the sprite to show for the given direction.

Parameters:

  | direction | the direction the vehicle is facing

Returns:
  the sprite for the given vehicle in the given direction

Reimplemented from Vehicle.

Definition at line 89 of file ship_cmd.cpp.

References SpecializedVehicle< Ship, VEH_SHIP >::Get().

TileIndex Ship::GetOrderStationLocation | ( | StationID | station | ) | `[virtual]`

Determine the location for the station where the vehicle goes to next.

Things done for example are allocating slots in a road stop or exact location of the platform is determined for ships.

Parameters:

  | station | the station to make the next location of the vehicle.

Returns:
  the location (tile) to aim for.

Reimplemented from Vehicle.

Definition at line 259 of file ship_cmd.cpp.

References Station::dock_tile, SpecializedVehicle< Ship, VEH_SHIP >::Get(), GetDockOffset(), Vehicle::IncrementOrderIndex(), INVALID_TILE, TILE_ADD, and ToTileIndexDiff().

Money Ship::GetRunningCost | ( |  | ) | const`[virtual]`

Gets the running cost of a vehicle.

Returns:
  the vehicle's running cost

Reimplemented from Vehicle.

Definition at line 160 of file ship_cmd.cpp.

References SpecializedVehicle< Ship, VEH_SHIP >::Get(), GetPrice(), and PROP_SHIP_RUNNING_COST_FACTOR.

Referenced by OnNewDay().

const char* Ship::GetTypeString | ( |  | ) | const`[inline, virtual]`

Get a string 'representation' of the vehicle type.

Returns:
  the string representation.

Reimplemented from Vehicle.

Definition at line 31 of file ship.h.

Trackdir Ship::GetVehicleTrackdir | ( |  | ) | const`[virtual]`

Returns the Trackdir on which the vehicle is currently located.

Works for trains and ships. Currently works only sortof for road vehicles, since they have a fuzzy concept of being "on" a trackdir. Dunno really what it returns for a road vehicle that is halfway a tile, never really understood that part. For road vehicles that are at the beginning or end of the tile, should just return the diagonal trackdir on which they are driving. I _think_. For other vehicles types, or vehicles with no clear trackdir (such as those in depots), returns 0xFF.

Returns:
  the trackdir of the vehicle

Reimplemented from Vehicle.

Definition at line 192 of file ship_cmd.cpp.

References DiagDirToDiagTrackdir(), DirToDiagDir(), FindFirstTrack(), INVALID_TRACKDIR, IsInDepot(), TRACK_BIT_WORMHOLE, TrackDirectionToTrackdir(), and Vehicle::vehstatus.

Referenced by NPFShipChooseTrack().

bool Ship::IsInDepot | ( |  | ) | const`[inline, virtual]`

Check whether the vehicle is in the depot.

Returns:
  true if and only if the vehicle is in the depot.

Reimplemented from Vehicle.

Definition at line 41 of file ship.h.

References TRACK_BIT_DEPOT.

Referenced by GetVehicleTrackdir().

void Ship::MarkDirty | ( |  | ) | `[virtual]`

Marks the vehicles to be redrawn and updates cached variables.

This method marks the area of the vehicle on the screen as dirty. It can be use to repaint the vehicle.

Reimplemented from Vehicle.

Definition at line 242 of file ship_cmd.cpp.

References Vehicle::UpdateViewport().

bool Ship::Tick | ( |  | ) | `[virtual]`

Calls the tick handler of the vehicle.

Returns:
  is this vehicle still valid?

Reimplemented from Vehicle.

Definition at line 595 of file ship_cmd.cpp.

References Vehicle::running_ticks, and Vehicle::vehstatus.

void Ship::UpdateDeltaXY | ( | Direction | direction | ) | `[virtual]`

Updates the x and y offsets and the size of the sprite used for this vehicle.

Parameters:

  | direction | the direction the vehicle is facing

Reimplemented from Vehicle.

Definition at line 272 of file ship_cmd.cpp.

References GB().

Referenced by CmdBuildShip().

The documentation for this struct was generated from the following files:

- src/ship.h
- src/ship_cmd.cpp