OpenTTD Source  20241108-master-g80f628063a
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 
19 typedef std::deque<Trackdir> ShipPathCache;
20 
24 struct Ship final : public SpecializedVehicle<Ship, VEH_SHIP> {
25  ShipPathCache path;
28  int16_t rotation_x_pos;
29  int16_t rotation_y_pos;
30 
34  virtual ~Ship() { this->PreDestructor(); }
35 
36  void MarkDirty() override;
37  void UpdateDeltaXY() override;
38  ExpensesType GetExpenseType(bool income) const override { return income ? EXPENSES_SHIP_REVENUE : EXPENSES_SHIP_RUN; }
39  void PlayLeaveStationSound(bool force = false) const override;
40  bool IsPrimaryVehicle() const override { return true; }
41  void GetImage(Direction direction, EngineImageType image_type, VehicleSpriteSeq *result) const override;
42  int GetDisplaySpeed() const override { return this->cur_speed / 2; }
43  int GetDisplayMaxSpeed() const override { return this->vcache.cached_max_speed / 2; }
44  int GetCurrentMaxSpeed() const override { return std::min<int>(this->vcache.cached_max_speed, this->current_order.GetMaxSpeed() * 2); }
45  Money GetRunningCost() const override;
46  bool IsInDepot() const override { return this->state == TRACK_BIT_DEPOT; }
47  bool Tick() override;
48  void OnNewCalendarDay() override;
49  void OnNewEconomyDay() override;
50  Trackdir GetVehicleTrackdir() const override;
51  TileIndex GetOrderStationLocation(StationID station) override;
52  ClosestDepot FindClosestDepot() override;
53  void UpdateCache();
54  void SetDestTile(TileIndex tile) override;
55 };
56 
57 bool IsShipDestinationTile(TileIndex tile, StationID station);
58 
59 #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
All ships have this type.
Definition: ship.h:24
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:44
TrackBits state
The "track" the ship is following.
Definition: ship.h:26
int16_t rotation_x_pos
NOSAVE: X Position before rotation.
Definition: ship.h:28
int GetDisplayMaxSpeed() const override
Gets the maximum speed in km-ish/h that can be sent into SetDParam for string processing.
Definition: ship.h:43
Direction rotation
Visible direction.
Definition: ship.h:27
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:29
ShipPathCache path
Cached path.
Definition: ship.h:25
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:40
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:46
Ship()
We don't want GCC to zero our struct! It already is zeroed and has an index!
Definition: ship.h:32
int GetDisplaySpeed() const override
Gets the speed in km-ish/h that can be sent into SetDParam for string processing.
Definition: ship.h:42
void OnNewEconomyDay() override
Economy day handler.
Definition: ship_cmd.cpp:261
virtual ~Ship()
We want to 'destruct' the right class.
Definition: ship.h:34
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
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