Public Member Functions | Data Fields

Ship Struct Reference

All ships have this type. More...

#include <ship.h>

Inheritance diagram for Ship:
SpecializedVehicle< Ship, VEH_SHIP > Vehicle Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_vehicle_pool > BaseVehicle BaseConsist

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.
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, EngineImageType image_type) 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.
int GetCurrentMaxSpeed () const
 Calculates the maximum speed of the vehicle under its current conditions.
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.
void UpdateCache ()
 Update the caches of this ship.

Data Fields

TrackBitsByte state
 The "track" the ship is following.

Detailed Description

All ships have this type.

Definition at line 24 of file ship.h.


Constructor & Destructor Documentation

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

We want to 'destruct' the right class.

Definition at line 30 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 691 of file ship_cmd.cpp.

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

int Ship::GetCurrentMaxSpeed (  )  const [inline, virtual]

Calculates the maximum speed of the vehicle under its current conditions.

Returns:
Current maximum speed in native units.

Reimplemented from Vehicle.

Definition at line 40 of file ship.h.

References VehicleCache::cached_max_speed, min(), and Vehicle::vcache.

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 VehicleCache::cached_max_speed, and Vehicle::vcache.

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.

SpriteID Ship::GetImage ( Direction  direction,
EngineImageType  image_type 
) 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 102 of file ship_cmd.cpp.

References Vehicle::GetEngine(), and Engine::original_image_index.

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::IncrementRealOrderIndex(), INVALID_TILE, Vehicle::last_station_visited, 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 191 of file ship_cmd.cpp.

References Vehicle::GetEngine(), Engine::GetGRF(), GetPrice(), and PROP_SHIP_RUNNING_COST_FACTOR.

Referenced by OnNewDay().

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 224 of file ship_cmd.cpp.

References DiagDirToDiagTrackdir(), Vehicle::direction, DirToDiagDir(), FindFirstTrack(), GetShipDepotDirection(), IsInDepot(), state, TRACK_BIT_WORMHOLE, TrackDirectionToTrackdir(), Vehicle::vehstatus, and VS_CRASHED.

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 42 of file ship.h.

References state.

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 241 of file ship_cmd.cpp.

References UpdateCache(), and SpecializedVehicle< Ship, VEH_SHIP >::UpdateViewport().

bool Ship::Tick (  )  [virtual]

Calls the tick handler of the vehicle.

Returns:
is this vehicle still valid?

Reimplemented from Vehicle.

Definition at line 613 of file ship_cmd.cpp.

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

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 Vehicle::x_extent, Vehicle::x_offs, Vehicle::y_extent, Vehicle::y_offs, and Vehicle::z_extent.

Referenced by CmdBuildShip().


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