Go to the documentation of this file.
1 /* $Id: ship.h 27666 2016-10-16 14:57:56Z frosch $ */
3 /*
4  * This file is part of OpenTTD.
5  * 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.
6  * 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.
7  * 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 <>.
8  */
12 #ifndef SHIP_H
13 #define SHIP_H
15 #include "vehicle_base.h"
16 #include "water_map.h"
18 void GetShipSpriteSize(EngineID engine, uint &width, uint &height, int &xoffs, int &yoffs, EngineImageType image_type);
24 struct Ship FINAL : public SpecializedVehicle<Ship, VEH_SHIP> {
30  virtual ~Ship() { this->PreDestructor(); }
32  void MarkDirty();
34  ExpensesType GetExpenseType(bool income) const { return income ? EXPENSES_SHIP_INC : EXPENSES_SHIP_RUN; }
35  void PlayLeaveStationSound() const;
36  bool IsPrimaryVehicle() const { return true; }
37  void GetImage(Direction direction, EngineImageType image_type, VehicleSpriteSeq *result) const;
38  int GetDisplaySpeed() const { return this->cur_speed / 2; }
39  int GetDisplayMaxSpeed() const { return this->vcache.cached_max_speed / 2; }
40  int GetCurrentMaxSpeed() const { return min(this->vcache.cached_max_speed, this->current_order.GetMaxSpeed() * 2); }
41  Money GetRunningCost() const;
42  bool IsInDepot() const { return this->state == TRACK_BIT_DEPOT; }
43  bool Tick();
44  void OnNewDay();
46  TileIndex GetOrderStationLocation(StationID station);
47  bool FindClosestDepot(TileIndex *location, DestinationID *destination, bool *reverse);
48  void UpdateCache();
49 };
55 #define FOR_ALL_SHIPS(var) FOR_ALL_VEHICLES_OF_TYPE(Ship, var)
57 #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:39
DirectionByte direction
Definition: vehicle_base.h:271
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:635
uint16 cur_speed
current speed
Definition: vehicle_base.h:293
void UpdateDeltaXY(Direction direction)
Updates the x and y offsets and the size of the sprite used for this vehicle.
Definition: ship_cmd.cpp:299
bool IsInDepot() const
Check whether the vehicle is in the depot.
Definition: ship.h:42
bool IsPrimaryVehicle() const
Whether this is the primary vehicle in the chain.
Definition: ship.h:36
int GetDisplaySpeed() const
Gets the speed in km-ish/h that can be sent into SetDParam for string processing. ...
Definition: ship.h:38
void PreDestructor()
Destroy all stuff that (still) needs the virtual functions to work properly.
Definition: vehicle.cpp:802
TrackBitsByte state
The "track" the ship is following.
Definition: ship.h:25
Visualisation contexts of vehicles and engines.
Definition: vehicle_type.h:87
uint16 cached_max_speed
Maximum speed of the consist (minimum of the max speed of all vehicles in the consist).
Definition: vehicle_base.h:123
void OnNewDay()
Calls the new day handler of the vehicle.
Definition: ship_cmd.cpp:224
Defines the 8 directions on the map.
ExpensesType GetExpenseType(bool income) const
Sets the expense type associated to this vehicle type.
Definition: ship.h:34
virtual ~Ship()
We want to &#39;destruct&#39; the right class.
Definition: ship.h:30
Class defining several overloaded accessors so we don&#39;t have to cast vehicle types that often...
Definition: vehicle_base.h:993
void UpdateCache()
Update the caches of this ship.
Definition: ship_cmd.cpp:202
void MarkDirty()
Marks the vehicles to be redrawn and updates cached variables.
Definition: ship_cmd.cpp:267
classes of water (for WATER_TILE_CLEAR water tile type).
Definition: water_map.h:49
Map accessors for water tiles.
Enumeration for tracks and directions.
Definition: track_type.h:74
Types of expenses.
Definition: economy_type.h:150
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:130
static T min(const T a, const T b)
Returns the minimum of two values.
Definition: math_func.hpp:42
Running costs ships.
Definition: economy_type.h:156
All ships have this type.
Definition: ship.h:24
TileIndex GetOrderStationLocation(StationID station)
Determine the location for the station where the vehicle goes to next.
Definition: ship_cmd.cpp:286
Base class for all vehicles.
uint16 EngineID
Unique identification number of an engine.
Definition: engine_type.h:22
uint32 TileIndex
The index/ID of a Tile.
Definition: tile_type.h:80
Bitflag for a depot.
Definition: track_type.h:59
Trackdir GetVehicleTrackdir() const
Returns the Trackdir on which the vehicle is currently located.
Definition: ship_cmd.cpp:250
Income from ships.
Definition: economy_type.h:161
int GetCurrentMaxSpeed() const
Calculates the maximum speed of the vehicle under its current conditions.
Definition: ship.h:40
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:330
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:715
Money GetRunningCost() const
Gets the running cost of a vehicle.
Definition: ship_cmd.cpp:217
We don&#39;t want GCC to zero our struct! It already is zeroed and has an index!
Definition: ship.h:28