OpenTTD Source  20241120-master-g6d3adc6169
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 <http://www.gnu.org/licenses/>.
6  */
7 
10 #ifndef SHIP_H
11 #define SHIP_H
12 
13 #include "vehicle_base.h"
14 #include "water_map.h"
15 
16 void GetShipSpriteSize(EngineID engine, uint &width, uint &height, int &xoffs, int &yoffs, EngineImageType image_type);
18 
22 
23  constexpr ShipPathElement() : trackdir(INVALID_TRACKDIR) {}
25 };
26 
27 using ShipPathCache = std::vector<ShipPathElement>;
28 
32 struct Ship final : public SpecializedVehicle<Ship, VEH_SHIP> {
33  ShipPathCache path;
36  int16_t rotation_x_pos;
37  int16_t rotation_y_pos;
38 
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 
65 bool IsShipDestinationTile(TileIndex tile, StationID station);
66 
67 #endif /* SHIP_H */
Direction
Defines the 8 directions on the map.
ExpensesType
Types of expenses.
Definition: economy_type.h:172
@ EXPENSES_SHIP_REVENUE
Revenue from ships.
Definition: economy_type.h:183
@ EXPENSES_SHIP_RUN
Running costs ships.
Definition: economy_type.h:178
uint16_t EngineID
Unique identification number of an engine.
Definition: engine_type.h:21
bool IsShipDestinationTile(TileIndex tile, StationID station)
Test if a tile is a docking tile for the given station.
Definition: ship_cmd.cpp:647
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:120
WaterClass GetEffectiveWaterClass(TileIndex tile)
Determine the effective WaterClass for a ship travelling on a tile.
Definition: ship_cmd.cpp:54
Structure to return information about the closest depot location, and whether it could be found.
Definition: vehicle_base.h:230
Element of the ShipPathCache.
Definition: ship.h:20
Trackdir trackdir
Trackdir for this element.
Definition: ship.h:21
All ships have this type.
Definition: ship.h:32
bool Tick() override
Calls the tick handler of the vehicle.
Definition: ship_cmd.cpp:869
Money GetRunningCost() const override
Gets the running cost of a vehicle.
Definition: ship_cmd.cpp:247
int GetCurrentMaxSpeed() const override
Calculates the maximum speed of the vehicle under its current conditions.
Definition: ship.h:52
TrackBits state
The "track" the ship is following.
Definition: ship.h:34
int16_t rotation_x_pos
NOSAVE: X Position before rotation.
Definition: ship.h:36
int GetDisplayMaxSpeed() const override
Gets the maximum speed in km-ish/h that can be sent into SetDParam for string processing.
Definition: ship.h:51
Direction rotation
Visible direction.
Definition: ship.h:35
void UpdateDeltaXY() override
Updates the x and y offsets and the size of the sprite used for this vehicle.
Definition: ship_cmd.cpp:331
void OnNewCalendarDay() override
Calendar day handler.
Definition: ship_cmd.cpp:255
int16_t rotation_y_pos
NOSAVE: Y Position before rotation.
Definition: ship.h:37
ShipPathCache path
Cached path.
Definition: ship.h:33
ClosestDepot FindClosestDepot() override
Find the closest depot for this vehicle and tell us the location, DestinationID and whether we should...
Definition: ship_cmd.cpp:959
void MarkDirty() override
Marks the vehicles to be redrawn and updates cached variables.
Definition: ship_cmd.cpp:305
bool IsPrimaryVehicle() const override
Whether this is the primary vehicle in the chain.
Definition: ship.h:48
Trackdir GetVehicleTrackdir() const override
Returns the Trackdir on which the vehicle is currently located.
Definition: ship_cmd.cpp:288
bool IsInDepot() const override
Check whether the vehicle is in the depot.
Definition: ship.h:54
Ship()
We don't want GCC to zero our struct! It already is zeroed and has an index!
Definition: ship.h:40
int GetDisplaySpeed() const override
Gets the speed in km-ish/h that can be sent into SetDParam for string processing.
Definition: ship.h:50
void OnNewEconomyDay() override
Economy day handler.
Definition: ship_cmd.cpp:261
virtual ~Ship()
We want to 'destruct' the right class.
Definition: ship.h:42
void UpdateCache()
Update the caches of this ship.
Definition: ship_cmd.cpp:232
Class defining several overloaded accessors so we don't have to cast vehicle types that often.
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:126
Sprite sequence for a vehicle part.
Definition: vehicle_base.h:135
Direction direction
facing
Definition: vehicle_base.h:307
void PreDestructor()
Destroy all stuff that (still) needs the virtual functions to work properly.
Definition: vehicle.cpp:826
VehicleCache vcache
Cache of often used vehicle values.
Definition: vehicle_base.h:364
uint16_t cur_speed
current speed
Definition: vehicle_base.h:328
TileIndex tile
Current tile index.
Definition: vehicle_base.h:264
TrackBits
Allow incrementing of Track variables.
Definition: track_type.h:35
@ TRACK_BIT_DEPOT
Bitflag for a depot.
Definition: track_type.h:53
Trackdir
Enumeration for tracks and directions.
Definition: track_type.h:67
@ INVALID_TRACKDIR
Flag for an invalid trackdir.
Definition: track_type.h:86
Base class for all vehicles.
EngineImageType
Visualisation contexts of vehicles and engines.
Definition: vehicle_type.h:78
Map accessors for water tiles.
WaterClass
classes of water (for WATER_TILE_CLEAR water tile type).
Definition: water_map.h:39