OpenTTD
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 <deque>
14 
15 #include "vehicle_base.h"
16 #include "water_map.h"
17 
18 void GetShipSpriteSize(EngineID engine, uint &width, uint &height, int &xoffs, int &yoffs, EngineImageType image_type);
20 
21 typedef std::deque<Trackdir> ShipPathCache;
22 
26 struct Ship FINAL : public SpecializedVehicle<Ship, VEH_SHIP> {
28  ShipPathCache path;
32 
36  virtual ~Ship() { this->PreDestructor(); }
37 
38  void MarkDirty();
39  void UpdateDeltaXY();
40  ExpensesType GetExpenseType(bool income) const { return income ? EXPENSES_SHIP_INC : EXPENSES_SHIP_RUN; }
41  void PlayLeaveStationSound() const;
42  bool IsPrimaryVehicle() const { return true; }
43  void GetImage(Direction direction, EngineImageType image_type, VehicleSpriteSeq *result) const;
44  int GetDisplaySpeed() const { return this->cur_speed / 2; }
45  int GetDisplayMaxSpeed() const { return this->vcache.cached_max_speed / 2; }
46  int GetCurrentMaxSpeed() const { return min(this->vcache.cached_max_speed, this->current_order.GetMaxSpeed() * 2); }
47  Money GetRunningCost() const;
48  bool IsInDepot() const { return this->state == TRACK_BIT_DEPOT; }
49  bool Tick();
50  void OnNewDay();
52  TileIndex GetOrderStationLocation(StationID station);
53  bool FindClosestDepot(TileIndex *location, DestinationID *destination, bool *reverse);
54  void UpdateCache();
55  void SetDestTile(TileIndex tile);
56 };
57 
58 bool IsShipDestinationTile(TileIndex tile, StationID station);
59 
60 #endif /* SHIP_H */
int GetDisplayMaxSpeed() const
Gets the maximum speed in km-ish/h that can be sent into SetDParam for string processing.
Definition: ship.h:45
Direction direction
facing
Definition: vehicle_base.h:269
ShipPathCache path
Cached path.
Definition: ship.h:28
void PlayLeaveStationSound() const
Play the sound associated with leaving the station.
Definition: ship_cmd.cpp:281
bool Tick()
Calls the tick handler of the vehicle.
Definition: ship_cmd.cpp:798
Trackdir
Enumeration for tracks and directions.
Definition: track_type.h:70
uint16 cur_speed
current speed
Definition: vehicle_base.h:291
bool IsInDepot() const
Check whether the vehicle is in the depot.
Definition: ship.h:48
bool IsPrimaryVehicle() const
Whether this is the primary vehicle in the chain.
Definition: ship.h:42
int GetDisplaySpeed() const
Gets the speed in km-ish/h that can be sent into SetDParam for string processing. ...
Definition: ship.h:44
void PreDestructor()
Destroy all stuff that (still) needs the virtual functions to work properly.
Definition: vehicle.cpp:800
Direction rotation
Visible direction.
Definition: ship.h:29
int16 rotation_y_pos
NOSAVE: Y Position before rotation.
Definition: ship.h:31
EngineImageType
Visualisation contexts of vehicles and engines.
Definition: vehicle_type.h:85
uint16 cached_max_speed
Maximum speed of the consist (minimum of the max speed of all vehicles in the consist).
Definition: vehicle_base.h:121
void OnNewDay()
Calls the new day handler of the vehicle.
Definition: ship_cmd.cpp:224
Income from ships.
Definition: economy_type.h:159
ExpensesType GetExpenseType(bool income) const
Sets the expense type associated to this vehicle type.
Definition: ship.h:40
virtual ~Ship()
We want to &#39;destruct&#39; the right class.
Definition: ship.h:36
Class defining several overloaded accessors so we don&#39;t have to cast vehicle types that often...
Definition: vehicle_base.h:979
void UpdateCache()
Update the caches of this ship.
Definition: ship_cmd.cpp:202
void UpdateDeltaXY()
Updates the x and y offsets and the size of the sprite used for this vehicle.
Definition: ship_cmd.cpp:299
void MarkDirty()
Marks the vehicles to be redrawn and updates cached variables.
Definition: ship_cmd.cpp:267
WaterClass
classes of water (for WATER_TILE_CLEAR water tile type).
Definition: water_map.h:47
Map accessors for water tiles.
Direction
Defines the 8 directions on the map.
TrackBits
Bitfield corresponding to Track.
Definition: track_type.h:38
TileIndex tile
Current tile index.
Definition: vehicle_base.h:228
void GetImage(Direction direction, EngineImageType image_type, VehicleSpriteSeq *result) const
Gets the sprite to show for the given direction.
Definition: ship_cmd.cpp:127
Sprite sequence for a vehicle part.
Definition: vehicle_base.h:128
bool IsShipDestinationTile(TileIndex tile, StationID station)
Test if a tile is a docking tile for the given station.
Definition: ship_cmd.cpp:605
static T min(const T a, const T b)
Returns the minimum of two values.
Definition: math_func.hpp:40
All ships have this type.
Definition: ship.h:26
TileIndex GetOrderStationLocation(StationID station)
Determine the location for the station where the vehicle goes to next.
Definition: ship_cmd.cpp:286
Bitflag for a depot.
Definition: track_type.h:56
TrackBits state
The "track" the ship is following.
Definition: ship.h:27
Base class for all vehicles.
uint16 EngineID
Unique identification number of an engine.
Definition: engine_type.h:21
uint32 TileIndex
The index/ID of a Tile.
Definition: tile_type.h:78
Trackdir GetVehicleTrackdir() const
Returns the Trackdir on which the vehicle is currently located.
Definition: ship_cmd.cpp:250
Running costs ships.
Definition: economy_type.h:154
int GetCurrentMaxSpeed() const
Calculates the maximum speed of the vehicle under its current conditions.
Definition: ship.h:46
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:113
VehicleCache vcache
Cache of often used vehicle values.
Definition: vehicle_base.h:328
WaterClass GetEffectiveWaterClass(TileIndex tile)
Determine the effective WaterClass for a ship travelling on a tile.
Definition: ship_cmd.cpp:47
bool FindClosestDepot(TileIndex *location, DestinationID *destination, bool *reverse)
Find the closest depot for this vehicle and tell us the location, DestinationID and whether we should...
Definition: ship_cmd.cpp:887
ExpensesType
Types of expenses.
Definition: economy_type.h:148
Money GetRunningCost() const
Gets the running cost of a vehicle.
Definition: ship_cmd.cpp:217
int16 rotation_x_pos
NOSAVE: X Position before rotation.
Definition: ship.h:30
Ship()
We don&#39;t want GCC to zero our struct! It already is zeroed and has an index!
Definition: ship.h:34