OpenTTD Source  14.0-beta3
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> {
26  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 */
Ship::GetRunningCost
Money GetRunningCost() const override
Gets the running cost of a vehicle.
Definition: ship_cmd.cpp:253
Vehicle::PreDestructor
void PreDestructor()
Destroy all stuff that (still) needs the virtual functions to work properly.
Definition: vehicle.cpp:826
Ship::IsInDepot
bool IsInDepot() const override
Check whether the vehicle is in the depot.
Definition: ship.h:46
Direction
Direction
Defines the 8 directions on the map.
Definition: direction_type.h:24
Ship::GetDisplaySpeed
int GetDisplaySpeed() const override
Gets the speed in km-ish/h that can be sent into SetDParam for string processing.
Definition: ship.h:42
Ship::GetCurrentMaxSpeed
int GetCurrentMaxSpeed() const override
Calculates the maximum speed of the vehicle under its current conditions.
Definition: ship.h:44
Ship::GetVehicleTrackdir
Trackdir GetVehicleTrackdir() const override
Returns the Trackdir on which the vehicle is currently located.
Definition: ship_cmd.cpp:292
Ship::path
ShipPathCache path
Cached path.
Definition: ship.h:26
Ship::GetDisplayMaxSpeed
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
Ship::Ship
Ship()
We don't want GCC to zero our struct! It already is zeroed and has an index!
Definition: ship.h:32
GetEffectiveWaterClass
WaterClass GetEffectiveWaterClass(TileIndex tile)
Determine the effective WaterClass for a ship travelling on a tile.
Definition: ship_cmd.cpp:55
Ship::rotation
Direction rotation
Visible direction.
Definition: ship.h:27
vehicle_base.h
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > >
EngineImageType
EngineImageType
Visualisation contexts of vehicles and engines.
Definition: vehicle_type.h:85
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:121
Ship::UpdateCache
void UpdateCache()
Update the caches of this ship.
Definition: ship_cmd.cpp:238
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:124
Ship::OnNewEconomyDay
void OnNewEconomyDay() override
Economy day handler.
Definition: ship_cmd.cpp:267
WaterClass
WaterClass
classes of water (for WATER_TILE_CLEAR water tile type).
Definition: water_map.h:47
Vehicle::tile
TileIndex tile
Current tile index.
Definition: vehicle_base.h:260
VehicleSpriteSeq
Sprite sequence for a vehicle part.
Definition: vehicle_base.h:131
SpecializedVehicle
Class defining several overloaded accessors so we don't have to cast vehicle types that often.
Definition: vehicle_base.h:1081
Vehicle::cur_speed
uint16_t cur_speed
current speed
Definition: vehicle_base.h:323
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:976
Ship::rotation_y_pos
int16_t rotation_y_pos
NOSAVE: Y Position before rotation.
Definition: ship.h:29
Ship::~Ship
virtual ~Ship()
We want to 'destruct' the right class.
Definition: ship.h:34
Vehicle::direction
Direction direction
facing
Definition: vehicle_base.h:302
TRACK_BIT_DEPOT
@ TRACK_BIT_DEPOT
Bitflag for a depot.
Definition: track_type.h:53
water_map.h
Vehicle::vcache
VehicleCache vcache
Cache of often used vehicle values.
Definition: vehicle_base.h:361
Ship
All ships have this type.
Definition: ship.h:24
Ship::IsPrimaryVehicle
bool IsPrimaryVehicle() const override
Whether this is the primary vehicle in the chain.
Definition: ship.h:40
Ship::MarkDirty
void MarkDirty() override
Marks the vehicles to be redrawn and updates cached variables.
Definition: ship_cmd.cpp:309
Ship::Tick
bool Tick() override
Calls the tick handler of the vehicle.
Definition: ship_cmd.cpp:886
Ship::state
TrackBits state
The "track" the ship is following.
Definition: ship.h:25
ClosestDepot
Structure to return information about the closest depot location, and whether it could be found.
Definition: vehicle_base.h:226
TrackBits
TrackBits
Allow incrementing of Track variables.
Definition: track_type.h:35
OverflowSafeInt< int64_t >
IsShipDestinationTile
bool IsShipDestinationTile(TileIndex tile, StationID station)
Test if a tile is a docking tile for the given station.
Definition: ship_cmd.cpp:664
Ship::OnNewCalendarDay
void OnNewCalendarDay() override
Calendar day handler.
Definition: ship_cmd.cpp:261
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:335
EngineID
uint16_t EngineID
Unique identification number of an engine.
Definition: engine_type.h:21
Trackdir
Trackdir
Enumeration for tracks and directions.
Definition: track_type.h:67
ExpensesType
ExpensesType
Types of expenses.
Definition: economy_type.h:172
Ship::rotation_x_pos
int16_t rotation_x_pos
NOSAVE: X Position before rotation.
Definition: ship.h:28
EXPENSES_SHIP_RUN
@ EXPENSES_SHIP_RUN
Running costs ships.
Definition: economy_type.h:178
EXPENSES_SHIP_REVENUE
@ EXPENSES_SHIP_REVENUE
Revenue from ships.
Definition: economy_type.h:183