OpenTTD Source: src/ship.h Source File

OpenTTD Source 15.3

ship.h
Go to the documentation of this file.
1/*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
6 */
7
10#ifndef SHIP_H
11#define SHIP_H
12
13#include "vehicle_base.h"
14#include "water_map.h"
15
16void GetShipSpriteSize(EngineID engine, uint &width, uint &height, int &xoffs, int &yoffs, EngineImageType image_type);
17 WaterClass GetEffectiveWaterClass(TileIndex tile);
18
20 struct ShipPathElement {
21 Trackdir trackdir = INVALID_TRACKDIR;
22
23 constexpr ShipPathElement() {}
24 constexpr ShipPathElement(Trackdir trackdir) : trackdir(trackdir) {}
25};
26
27using ShipPathCache = std::vector<ShipPathElement>;
28
32 struct Ship final : public SpecializedVehicle<Ship, VEH_SHIP> {
33 ShipPathCache path{};
34 TrackBits state{};
35 Direction rotation = INVALID_DIR;
36 int16_t rotation_x_pos = 0;
37 int16_t rotation_y_pos = 0;
38
40 Ship() : SpecializedVehicleBase() {}
42 virtual ~Ship() { this->PreDestructor(); }
43
44 void MarkDirty() override;
45 void UpdateDeltaXY() override;
46 ExpensesType GetExpenseType(bool income) const override { return income ? EXPENSES_SHIP_REVENUE : EXPENSES_SHIP_RUN; }
47 void PlayLeaveStationSound(bool force = false) const override;
48 bool IsPrimaryVehicle() const override { return true; }
49 void GetImage(Direction direction, EngineImageType image_type, VehicleSpriteSeq *result) const override;
50 int GetDisplaySpeed() const override { return this->cur_speed / 2; }
51 int GetDisplayMaxSpeed() const override { return this->vcache.cached_max_speed / 2; }
52 int GetCurrentMaxSpeed() const override { return std::min<int>(this->vcache.cached_max_speed, this->current_order.GetMaxSpeed() * 2); }
53 Money GetRunningCost() const override;
54 bool IsInDepot() const override { return this->state == TRACK_BIT_DEPOT; }
55 bool Tick() override;
56 void OnNewCalendarDay() override;
57 void OnNewEconomyDay() override;
58 Trackdir GetVehicleTrackdir() const override;
59 TileIndex GetOrderStationLocation(StationID station) override;
60 ClosestDepot FindClosestDepot() override;
61 void UpdateCache();
62 void SetDestTile(TileIndex tile) override;
63};
64
65bool IsShipDestinationTile(TileIndex tile, StationID station);
66
67#endif /* SHIP_H */
OverflowSafeInt< int64_t >
Direction
Direction
Defines the 8 directions on the map.
Definition direction_type.h:24
INVALID_DIR
@ INVALID_DIR
Flag for an invalid direction.
Definition direction_type.h:35
ExpensesType
ExpensesType
Types of expenses.
Definition economy_type.h:178
EXPENSES_SHIP_REVENUE
@ EXPENSES_SHIP_REVENUE
Revenue from ships.
Definition economy_type.h:189
EXPENSES_SHIP_RUN
@ EXPENSES_SHIP_RUN
Running costs ships.
Definition economy_type.h:184
IsShipDestinationTile
bool IsShipDestinationTile(TileIndex tile, StationID station)
Test if a tile is a docking tile for the given station.
Definition ship_cmd.cpp:617
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).
Definition ship_cmd.cpp:119
GetEffectiveWaterClass
WaterClass GetEffectiveWaterClass(TileIndex tile)
Determine the effective WaterClass for a ship travelling on a tile.
Definition ship_cmd.cpp:53
ClosestDepot
Structure to return information about the closest depot location, and whether it could be found.
Definition vehicle_base.h:192
PoolID< uint16_t, struct EngineIDTag, 64000, 0xFFFF >
ShipPathElement
Element of the ShipPathCache.
Definition ship.h:20
ShipPathElement::trackdir
Trackdir trackdir
Trackdir for this element.
Definition ship.h:21
Ship
All ships have this type.
Definition ship.h:32
Ship::Tick
bool Tick() override
Calls the tick handler of the vehicle.
Definition ship_cmd.cpp:839
Ship::GetRunningCost
Money GetRunningCost() const override
Gets the running cost of a vehicle.
Definition ship_cmd.cpp:246
Ship::GetOrderStationLocation
TileIndex GetOrderStationLocation(StationID station) override
Determine the location for the station where the vehicle goes to next.
Definition ship_cmd.cpp:317
Ship::GetCurrentMaxSpeed
int GetCurrentMaxSpeed() const override
Calculates the maximum speed of the vehicle under its current conditions.
Definition ship.h:52
Ship::state
TrackBits state
The "track" the ship is following.
Definition ship.h:34
Ship::rotation_x_pos
int16_t rotation_x_pos
NOSAVE: X Position before rotation.
Definition ship.h:36
Ship::GetDisplayMaxSpeed
int GetDisplayMaxSpeed() const override
Gets the maximum speed in km-ish/h that can be sent into string parameters for string processing.
Definition ship.h:51
Ship::rotation
Direction rotation
Visible direction.
Definition ship.h:35
Ship::UpdateDeltaXY
void UpdateDeltaXY() override
Updates the x and y offsets and the size of the sprite used for this vehicle.
Definition ship_cmd.cpp:330
Ship::OnNewCalendarDay
void OnNewCalendarDay() override
Calendar day handler.
Definition ship_cmd.cpp:254
Ship::rotation_y_pos
int16_t rotation_y_pos
NOSAVE: Y Position before rotation.
Definition ship.h:37
Ship::path
ShipPathCache path
Cached path.
Definition ship.h:33
Ship::FindClosestDepot
ClosestDepot FindClosestDepot() override
Find the closest depot for this vehicle and tell us the location, DestinationID and whether we should...
Definition ship_cmd.cpp:934
Ship::MarkDirty
void MarkDirty() override
Marks the vehicles to be redrawn and updates cached variables.
Definition ship_cmd.cpp:304
Ship::IsPrimaryVehicle
bool IsPrimaryVehicle() const override
Whether this is the primary vehicle in the chain.
Definition ship.h:48
Ship::GetVehicleTrackdir
Trackdir GetVehicleTrackdir() const override
Returns the Trackdir on which the vehicle is currently located.
Definition ship_cmd.cpp:287
Ship::IsInDepot
bool IsInDepot() const override
Check whether the vehicle is in the depot.
Definition ship.h:54
Ship::Ship
Ship()
We don't want GCC to zero our struct! It already is zeroed and has an index!
Definition ship.h:40
Ship::PlayLeaveStationSound
void PlayLeaveStationSound(bool force=false) const override
Play the sound associated with leaving the station.
Definition ship_cmd.cpp:311
Ship::GetDisplaySpeed
int GetDisplaySpeed() const override
Gets the speed in km-ish/h that can be sent into string parameters for string processing.
Definition ship.h:50
Ship::OnNewEconomyDay
void OnNewEconomyDay() override
Economy day handler.
Definition ship_cmd.cpp:260
Ship::~Ship
virtual ~Ship()
We want to 'destruct' the right class.
Definition ship.h:42
Ship::GetImage
void GetImage(Direction direction, EngineImageType image_type, VehicleSpriteSeq *result) const override
Gets the sprite to show for the given direction.
Definition ship_cmd.cpp:133
Ship::UpdateCache
void UpdateCache()
Update the caches of this ship.
Definition ship_cmd.cpp:231
Ship::GetExpenseType
ExpensesType GetExpenseType(bool income) const override
Sets the expense type associated to this vehicle type.
Definition ship.h:46
SpecializedVehicle
Class defining several overloaded accessors so we don't have to cast vehicle types that often.
Definition vehicle_base.h:1014
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > >
VehicleCache::cached_max_speed
uint16_t cached_max_speed
Maximum speed of the consist (minimum of the max speed of all vehicles in the consist).
Definition vehicle_base.h:93
VehicleSpriteSeq
Sprite sequence for a vehicle part.
Definition vehicle_base.h:102
Vehicle::direction
Direction direction
facing
Definition vehicle_base.h:268
Vehicle::PreDestructor
void PreDestructor()
Destroy all stuff that (still) needs the virtual functions to work properly.
Definition vehicle.cpp:796
Vehicle::vcache
VehicleCache vcache
Cache of often used vehicle values.
Definition vehicle_base.h:319
Vehicle::cur_speed
uint16_t cur_speed
current speed
Definition vehicle_base.h:283
Vehicle::tile
TileIndex tile
Current tile index.
Definition vehicle_base.h:225
TrackBits
TrackBits
Allow incrementing of Track variables.
Definition track_type.h:35
TRACK_BIT_DEPOT
@ TRACK_BIT_DEPOT
Bitflag for a depot.
Definition track_type.h:53
Trackdir
Trackdir
Enumeration for tracks and directions.
Definition track_type.h:66
INVALID_TRACKDIR
@ INVALID_TRACKDIR
Flag for an invalid trackdir.
Definition track_type.h:85
vehicle_base.h
Base class for all vehicles.
EngineImageType
EngineImageType
Visualisation contexts of vehicles and engines.
Definition vehicle_type.h:74
water_map.h
Map accessors for water tiles.
WaterClass
WaterClass
classes of water (for WaterTileType::Clear water tile type).
Definition water_map.h:39