OpenTTD Source 20241224-master-gf74b0cf984
|
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 "depot_base.h"
#include "station_base.h"
#include "newgrf_engine.h"
#include "pathfinder/yapf/yapf.h"
#include "pathfinder/yapf/yapf_ship_regions.h"
#include "newgrf_sound.h"
#include "spritecache.h"
#include "strings_func.h"
#include "window_func.h"
#include "timer/timer_game_calendar.h"
#include "timer/timer_game_economy.h"
#include "vehicle_func.h"
#include "sound_func.h"
#include "ai/ai.hpp"
#include "game/game.hpp"
#include "engine_base.h"
#include "company_base.h"
#include "tunnelbridge_map.h"
#include "zoom_func.h"
#include "framerate_type.h"
#include "industry.h"
#include "industry_map.h"
#include "ship_cmd.h"
#include "table/strings.h"
#include <unordered_set>
#include "safeguards.h"
Go to the source code of this file.
Data Structures | |
struct | ShipSubcoordData |
Structure for ship sub-coordinate data for moving into a new tile via a Diagdir onto a Track. More... | |
Functions | |
WaterClass | GetEffectiveWaterClass (TileIndex tile) |
Determine the effective WaterClass for a ship travelling on a tile. | |
template<> | |
bool | IsValidImageIndex< VEH_SHIP > (uint8_t 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). | |
static const Depot * | FindClosestShipDepot (const Vehicle *v, uint max_distance) |
static void | CheckIfShipNeedsService (Vehicle *v) |
static Vehicle * | EnsureNoMovingShipProc (Vehicle *v, void *) |
Test-procedure for HasVehicleOnPos to check for any ships which are moving. | |
static bool | CheckReverseShip (const Ship *v, Trackdir *trackdir=nullptr) |
static bool | CheckShipLeaveDepot (Ship *v) |
static uint | ShipAccelerate (Vehicle *v) |
Accelerates the ship towards its target speed. | |
static void | ShipArrivesAt (const Vehicle *v, Station *st) |
Ship arrives at a dock. | |
static Track | ChooseShipTrack (Ship *v, TileIndex tile, TrackBits tracks) |
Runs the pathfinder to choose a track to continue along. | |
static TrackBits | GetAvailShipTracks (TileIndex tile, DiagDirection dir) |
Get the available water tracks on a tile for a ship entering a tile. | |
static int | ShipTestUpDownOnLock (const Ship *v) |
Test if a ship is in the centre of a lock and should move up or down. | |
static bool | ShipMoveUpDownOnLock (Ship *v) |
Test and move a ship up or down in a lock. | |
bool | IsShipDestinationTile (TileIndex tile, StationID station) |
Test if a tile is a docking tile for the given station. | |
static void | ReverseShipIntoTrackdir (Ship *v, Trackdir trackdir) |
static void | ReverseShip (Ship *v) |
static void | ShipController (Ship *v) |
CommandCost | CmdBuildShip (DoCommandFlag flags, TileIndex tile, const Engine *e, Vehicle **ret) |
Build a ship. | |
Variables | |
constexpr int | MAX_SHIP_DEPOT_SEARCH_DISTANCE = 80 |
Max distance in tiles (as the crow flies) to search for depots when user clicks "go to depot". | |
static const uint16_t | _ship_sprites [] = {0x0E5D, 0x0E55, 0x0E65, 0x0E6D} |
static const ShipSubcoordData | _ship_subcoord [DIAGDIR_END][TRACK_END] |
Ship sub-coordinate data for moving into a new tile via a Diagdir onto a Track. | |
Handling of ships.
Definition in file ship_cmd.cpp.
|
static |
Definition at line 204 of file ship_cmd.cpp.
Definition at line 370 of file ship_cmd.cpp.
|
static |
Definition at line 376 of file ship_cmd.cpp.
Runs the pathfinder to choose a track to continue along.
v | Ship to navigate |
tile | Tile, the ship is about to enter |
tracks | Available track choices on tile |
Definition at line 495 of file ship_cmd.cpp.
References Vehicle::dest_tile, FindFirstTrack(), Vehicle::HandlePathfindingResult(), HasBit(), IsDiagonalTrack(), Ship::path, Ship::state, TrackBitsToTrack(), TrackdirToTrack(), TrackToOppositeTrack(), and YapfShipChooseTrack().
CommandCost CmdBuildShip | ( | DoCommandFlag | flags, |
TileIndex | tile, | ||
const Engine * | e, | ||
Vehicle ** | ret | ||
) |
Build a ship.
flags | type of operation. | |
tile | tile of the depot where ship is built. | |
e | the engine to build. | |
[out] | ret | the vehicle that has been built. |
Definition at line 895 of file ship_cmd.cpp.
References _current_company, ShipVehicleInfo::acceleration, Vehicle::acceleration, Vehicle::build_year, Vehicle::cargo_cap, Vehicle::cargo_type, TimerGameCalendar::date, TimerGameEconomy::date, Vehicle::date_of_last_service, Vehicle::date_of_last_service_newgrf, DC_EXEC, Engine::DetermineCapacity(), ENGINE_EXCLUSIVE_PREVIEW, Vehicle::engine_type, Engine::flags, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::Get(), Engine::GetDefaultCargoType(), Engine::GetLifeLengthInDays(), GetShipDepotNorthTile(), GetSlopePixelZ(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, Vehicle::InvalidateNewGRFCacheOfChain(), IsValidCargoID(), Vehicle::last_loading_station, Vehicle::last_station_visited, Vehicle::max_age, Vehicle::owner, Vehicle::random_bits, Vehicle::refit_cap, Engine::reliability, Vehicle::reliability, Engine::reliability_spd_dec, Vehicle::reliability_spd_dec, VehicleSpriteSeq::Set(), SetBit(), settings, Vehicle::sprite_cache, MutableSpriteCache::sprite_seq, Vehicle::spritenum, Ship::state, Vehicle::tile, TILE_SIZE, TileX(), TileY(), TRACK_BIT_DEPOT, Ship::UpdateCache(), Ship::UpdateDeltaXY(), Vehicle::UpdatePosition(), BaseConsist::vehicle_flags, Vehicle::vehstatus, VF_BUILT_AS_PROTOTYPE, VS_DEFPAL, VS_HIDDEN, VS_STOPPED, Vehicle::x_pos, Vehicle::y_pos, TimerGameCalendar::year, and Vehicle::z_pos.
Referenced by CmdBuildVehicle().
void DrawShipEngine | ( | int | left, |
int | right, | ||
int | preferred_x, | ||
int | y, | ||
EngineID | engine, | ||
PaletteID | pal, | ||
EngineImageType | image_type | ||
) |
Definition at line 97 of file ship_cmd.cpp.
Test-procedure for HasVehicleOnPos to check for any ships which are moving.
Definition at line 365 of file ship_cmd.cpp.
References Vehicle::cur_speed, BaseVehicle::type, and VEH_SHIP.
Definition at line 151 of file ship_cmd.cpp.
|
inlinestatic |
Get the available water tracks on a tile for a ship entering a tile.
tile | The tile about to enter. |
dir | The entry direction. |
Definition at line 534 of file ship_cmd.cpp.
References DiagdirReachesTracks().
WaterClass GetEffectiveWaterClass | ( | TileIndex | tile | ) |
Determine the effective WaterClass for a ship travelling on a tile.
tile | Tile of interest |
Definition at line 54 of file ship_cmd.cpp.
References GetTunnelBridgeTransportType(), GetWaterClass(), HasTileWaterClass(), IsTileType(), MP_RAILWAY, MP_TUNNELBRIDGE, RAIL_GROUND_WATER, TRANSPORT_WATER, WATER_CLASS_CANAL, and WATER_CLASS_SEA.
Referenced by CYapfCostShipT< Types >::PfCalcCost(), and Ship::UpdateCache().
|
static |
Definition at line 81 of file ship_cmd.cpp.
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).
engine | The engine to get the sprite from. | |
[out] | width | The width of the sprite. |
[out] | height | The height of the sprite. |
[out] | xoffs | Number of pixels to shift the sprite to the right. |
[out] | yoffs | Number of pixels to shift the sprite downwards. |
image_type | Context the sprite is used in. |
Definition at line 120 of file ship_cmd.cpp.
References VehicleSpriteSeq::GetBounds(), Rect::Height(), UnScaleGUI(), and Rect::Width().
Referenced by EnginePreviewWindow::UpdateWidgetSize().
Definition at line 76 of file ship_cmd.cpp.
bool IsShipDestinationTile | ( | TileIndex | tile, |
StationID | station | ||
) |
Test if a tile is a docking tile for the given station.
tile | Docking tile to test. |
station | Destination station. |
Definition at line 647 of file ship_cmd.cpp.
References DIAGDIR_BEGIN, DIAGDIR_END, Industry::GetByTile(), GetStationIndex(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, IsDockingTile(), IsDockTile(), IsDockWaterPart(), IsOilRig(), IsTileType(), IsValidTile(), MP_INDUSTRY, MP_STATION, Industry::neutral_station, and TileOffsByDiagDir().
Referenced by RemoveDock().
bool IsValidImageIndex< VEH_SHIP > | ( | uint8_t | image_index | ) |
Definition at line 71 of file ship_cmd.cpp.
|
static |
Definition at line 685 of file ship_cmd.cpp.
Definition at line 664 of file ship_cmd.cpp.
|
static |
Accelerates the ship towards its target speed.
v | Ship to accelerate. |
Definition at line 443 of file ship_cmd.cpp.
References Vehicle::acceleration, VehicleCache::cached_max_speed, Vehicle::cur_speed, Vehicle::current_order, Vehicle::GetAdvanceDistance(), Vehicle::GetAdvanceSpeed(), Order::GetMaxSpeed(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, Vehicle::progress, SetWindowWidgetDirty(), Vehicle::vcache, WC_VEHICLE_VIEW, and WID_VV_START_STOP.
Ship arrives at a dock.
If it is the first time, send out a news item.
Definition at line 468 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().
|
static |
Definition at line 699 of file ship_cmd.cpp.
|
static |
Test and move a ship up or down in a lock.
v | Ship to move. |
Definition at line 621 of file ship_cmd.cpp.
References Vehicle::cur_speed, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, SetWindowWidgetDirty(), ShipTestUpDownOnLock(), Vehicle::tick_counter, Vehicle::UpdatePosition(), SpecializedVehicle< T, Type >::UpdateViewport(), WC_VEHICLE_VIEW, WID_VV_START_STOP, and Vehicle::z_pos.
|
static |
Test if a ship is in the centre of a lock and should move up or down.
v | Ship being tested. |
Definition at line 596 of file ship_cmd.cpp.
References Vehicle::direction, DirToDiagDir(), GetInclinedSlopeDirection(), GetLockPart(), GetTileMaxZ(), GetTileSlope(), GetTileZ(), IsLock(), IsTileType(), IsValidDiagDirection(), LOCK_PART_MIDDLE, MP_WATER, Vehicle::tile, TILE_HEIGHT, Vehicle::x_pos, Vehicle::y_pos, and Vehicle::z_pos.
Referenced by ShipMoveUpDownOnLock().
|
static |
Definition at line 68 of file ship_cmd.cpp.
|
static |
Ship sub-coordinate data for moving into a new tile via a Diagdir onto a Track.
Array indexes are Diagdir, Track. There will always be three possible tracks going into an adjacent tile via a Diagdir, so each Diagdir sub-array will have three valid and three invalid structures per Track.
Definition at line 552 of file ship_cmd.cpp.
|
constexpr |
Max distance in tiles (as the crow flies) to search for depots when user clicks "go to depot".
Definition at line 47 of file ship_cmd.cpp.
Referenced by Ship::FindClosestDepot().