OpenTTD
ship_cmd.cpp File Reference

Handling of ships. More...

#include "stdafx.h"
#include "ship.h"
#include "landscape.h"
#include "timetable.h"
#include "news_func.h"
#include "company_func.h"
#include "pathfinder/npf/npf_func.h"
#include "depot_base.h"
#include "station_base.h"
#include "newgrf_engine.h"
#include "pathfinder/yapf/yapf.h"
#include "newgrf_sound.h"
#include "spritecache.h"
#include "strings_func.h"
#include "window_func.h"
#include "date_func.h"
#include "vehicle_func.h"
#include "sound_func.h"
#include "ai/ai.hpp"
#include "game/game.hpp"
#include "pathfinder/opf/opf_ship.h"
#include "engine_base.h"
#include "company_base.h"
#include "tunnelbridge_map.h"
#include "zoom_func.h"
#include "framerate_type.h"
#include "table/strings.h"
#include "safeguards.h"

Go to the source code of this file.

Functions

WaterClass GetEffectiveWaterClass (TileIndex tile)
 Determine the effective WaterClass for a ship travelling on a tile. More...
 
template<>
bool IsValidImageIndex< VEH_SHIP > (uint8 image_index)
 
static TrackBits GetTileShipTrackStatus (TileIndex tile)
 
static void GetShipIcon (EngineID engine, EngineImageType image_type, VehicleSpriteSeq *result)
 
void DrawShipEngine (int left, int right, int preferred_x, int y, EngineID engine, PaletteID pal, EngineImageType image_type)
 
void GetShipSpriteSize (EngineID engine, uint &width, uint &height, int &xoffs, int &yoffs, EngineImageType image_type)
 Get the size of the sprite of a ship sprite heading west (used for lists). More...
 
static const DepotFindClosestShipDepot (const Vehicle *v, uint max_distance)
 
static void CheckIfShipNeedsService (Vehicle *v)
 
static void PlayShipSound (const Vehicle *v)
 
static VehicleEnsureNoVisibleShipProc (Vehicle *v, void *data)
 Test-procedure for HasVehicleOnPos to check for a ship.
 
static bool CheckShipLeaveDepot (Ship *v)
 
static bool ShipAccelerate (Vehicle *v)
 
static void ShipArrivesAt (const Vehicle *v, Station *st)
 Ship arrives at a dock. More...
 
static Track ChooseShipTrack (Ship *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks)
 Runs the pathfinder to choose a track to continue along. More...
 
static TrackBits GetAvailShipTracks (TileIndex tile, DiagDirection dir, Trackdir trackdir)
 Get the available water tracks on a tile for a ship entering a tile. More...
 
static int ShipTestUpDownOnLock (const Ship *v)
 Test if a ship is in the centre of a lock and should move up or down. More...
 
static bool ShipMoveUpDownOnLock (Ship *v)
 Test and move a ship up or down in a lock. More...
 
static void ShipController (Ship *v)
 
CommandCost CmdBuildShip (TileIndex tile, DoCommandFlag flags, const Engine *e, uint16 data, Vehicle **ret)
 Build a ship. More...
 

Variables

static const uint16 _ship_sprites [] = {0x0E5D, 0x0E55, 0x0E65, 0x0E6D}
 
static const byte _ship_subcoord [4][6][3]
 

Detailed Description

Handling of ships.

Definition in file ship_cmd.cpp.

Function Documentation

◆ ChooseShipTrack()

static Track ChooseShipTrack ( Ship v,
TileIndex  tile,
DiagDirection  enterdir,
TrackBits  tracks 
)
static

Runs the pathfinder to choose a track to continue along.

Parameters
vShip to navigate
tileTile, the ship is about to enter
enterdirDirection of entering
tracksAvailable track choices on tile
Returns
Track to choose, or INVALID_TRACK when to reverse.

Definition at line 466 of file ship_cmd.cpp.

Referenced by YapfShipChooseTrack().

◆ CmdBuildShip()

CommandCost CmdBuildShip ( TileIndex  tile,
DoCommandFlag  flags,
const Engine e,
uint16  data,
Vehicle **  ret 
)

Build a ship.

Parameters
tiletile of the depot where ship is built.
flagstype of operation.
ethe engine to build.
dataunused.
[out]retthe vehicle that has been built.
Returns
the cost of this operation or an error.

Definition at line 821 of file ship_cmd.cpp.

References DC_EXEC, and GetShipDepotNorthTile().

◆ GetAvailShipTracks()

static TrackBits GetAvailShipTracks ( TileIndex  tile,
DiagDirection  dir,
Trackdir  trackdir 
)
inlinestatic

Get the available water tracks on a tile for a ship entering a tile.

Parameters
tileThe tile about to enter.
dirThe entry direction.
trackdirThe trackdir the ship has on the old tile.
Returns
The available trackbits on the next tile.

Definition at line 520 of file ship_cmd.cpp.

◆ GetEffectiveWaterClass()

WaterClass GetEffectiveWaterClass ( TileIndex  tile)

Determine the effective WaterClass for a ship travelling on a tile.

Parameters
tileTile of interest
Returns
the waterclass to be used by the ship.

Definition at line 48 of file ship_cmd.cpp.

References GetWaterClass(), HasTileWaterClass(), IsTileType(), and MP_TUNNELBRIDGE.

◆ GetShipSpriteSize()

void GetShipSpriteSize ( EngineID  engine,
uint &  width,
uint &  height,
int &  xoffs,
int &  yoffs,
EngineImageType  image_type 
)

Get the size of the sprite of a ship sprite heading west (used for lists).

Parameters
engineThe engine to get the sprite from.
[out]widthThe width of the sprite.
[out]heightThe height of the sprite.
[out]xoffsNumber of pixels to shift the sprite to the right.
[out]yoffsNumber of pixels to shift the sprite downwards.
image_typeContext the sprite is used in.

Definition at line 114 of file ship_cmd.cpp.

◆ ShipArrivesAt()

static void ShipArrivesAt ( const Vehicle v,
Station st 
)
static

Ship arrives at a dock.

If it is the first time, send out a news item.

Parameters
vShip that arrived.
stStation being visited.

Definition at line 438 of file ship_cmd.cpp.

References _local_company, AddVehicleNewsItem(), HVOT_SHIP, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, Game::NewEvent(), AI::NewEvent(), NT_ARRIVAL_COMPANY, NT_ARRIVAL_OTHER, Vehicle::owner, and SetDParam().

◆ ShipMoveUpDownOnLock()

static bool ShipMoveUpDownOnLock ( Ship v)
static

◆ ShipTestUpDownOnLock()

static int ShipTestUpDownOnLock ( const Ship v)
static

Test if a ship is in the centre of a lock and should move up or down.

Parameters
vShip being tested.
Returns
0 if ship is not moving in lock, or -1 to move down, 1 to move up.

Definition at line 570 of file ship_cmd.cpp.

References GetInclinedSlopeDirection(), GetLockPart(), GetTileSlope(), IsLock(), IsTileType(), LOCK_PART_MIDDLE, MP_WATER, Vehicle::tile, Vehicle::x_pos, and Vehicle::y_pos.

Referenced by ShipMoveUpDownOnLock().