OpenTTD
ship.h
Go to the documentation of this file.
1 /* $Id$ */
2 
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 <http://www.gnu.org/licenses/>.
8  */
9 
12 #ifndef SHIP_H
13 #define SHIP_H
14 
15 #include <deque>
16 
17 #include "vehicle_base.h"
18 #include "water_map.h"
19 
20 void GetShipSpriteSize(EngineID engine, uint &width, uint &height, int &xoffs, int &yoffs, EngineImageType image_type);
22 
23 typedef std::deque<TrackdirByte> ShipPathCache;
24 
28 struct Ship FINAL : public SpecializedVehicle<Ship, VEH_SHIP> {
30  ShipPathCache path;
34 
38  virtual ~Ship() { this->PreDestructor(); }
39 
40  void MarkDirty();
41  void UpdateDeltaXY();
42  ExpensesType GetExpenseType(bool income) const { return income ? EXPENSES_SHIP_INC : EXPENSES_SHIP_RUN; }
43  void PlayLeaveStationSound() const;
44  bool IsPrimaryVehicle() const { return true; }
45  void GetImage(Direction direction, EngineImageType image_type, VehicleSpriteSeq *result) const;
46  int GetDisplaySpeed() const { return this->cur_speed / 2; }
47  int GetDisplayMaxSpeed() const { return this->vcache.cached_max_speed / 2; }
48  int GetCurrentMaxSpeed() const { return min(this->vcache.cached_max_speed, this->current_order.GetMaxSpeed() * 2); }
49  Money GetRunningCost() const;
50  bool IsInDepot() const { return this->state == TRACK_BIT_DEPOT; }
51  bool Tick();
52  void OnNewDay();
54  TileIndex GetOrderStationLocation(StationID station);
55  bool FindClosestDepot(TileIndex *location, DestinationID *destination, bool *reverse);
56  void UpdateCache();
57  void SetDestTile(TileIndex tile);
58 };
59 
60 static const uint SHIP_MAX_ORDER_DISTANCE = 130;
61 
66 #define FOR_ALL_SHIPS(var) FOR_ALL_VEHICLES_OF_TYPE(Ship, var)
67 
68 #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:47
ShipPathCache path
Cached path.
Definition: ship.h:30
DirectionByte direction
facing
Definition: vehicle_base.h:271
void PlayLeaveStationSound() const
Play the sound associated with leaving the station.
Definition: ship_cmd.cpp:284
bool Tick()
Calls the tick handler of the vehicle.
Definition: ship_cmd.cpp:794
uint16 cur_speed
current speed
Definition: vehicle_base.h:293
bool IsInDepot() const
Check whether the vehicle is in the depot.
Definition: ship.h:50
bool IsPrimaryVehicle() const
Whether this is the primary vehicle in the chain.
Definition: ship.h:44
int GetDisplaySpeed() const
Gets the speed in km-ish/h that can be sent into SetDParam for string processing. ...
Definition: ship.h:46
void PreDestructor()
Destroy all stuff that (still) needs the virtual functions to work properly.
Definition: vehicle.cpp:803
TrackBitsByte state
The "track" the ship is following.
Definition: ship.h:29
DirectionByte rotation
Visible direction.
Definition: ship.h:31
int16 rotation_y_pos
NOSAVE: Y Position before rotation.
Definition: ship.h:33
EngineImageType
Visualisation contexts of vehicles and engines.
Definition: vehicle_type.h:89
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:227
Direction
Defines the 8 directions on the map.
ExpensesType GetExpenseType(bool income) const
Sets the expense type associated to this vehicle type.
Definition: ship.h:42
virtual ~Ship()
We want to &#39;destruct&#39; the right class.
Definition: ship.h:38
Class defining several overloaded accessors so we don&#39;t have to cast vehicle types that often...
Definition: vehicle_base.h:994
void UpdateCache()
Update the caches of this ship.
Definition: ship_cmd.cpp:205
void UpdateDeltaXY()
Updates the x and y offsets and the size of the sprite used for this vehicle.
Definition: ship_cmd.cpp:302
void MarkDirty()
Marks the vehicles to be redrawn and updates cached variables.
Definition: ship_cmd.cpp:270
WaterClass
classes of water (for WATER_TILE_CLEAR water tile type).
Definition: water_map.h:49
Map accessors for water tiles.
Trackdir
Enumeration for tracks and directions.
Definition: track_type.h:74
TileIndex tile
Current tile index.
Definition: vehicle_base.h:230
ExpensesType
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:128
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:28
TileIndex GetOrderStationLocation(StationID station)
Determine the location for the station where the vehicle goes to next.
Definition: ship_cmd.cpp:289
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:253
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:48
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:114
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:48
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:883
Money GetRunningCost() const
Gets the running cost of a vehicle.
Definition: ship_cmd.cpp:220
int16 rotation_x_pos
NOSAVE: X Position before rotation.
Definition: ship.h:32
Ship()
We don&#39;t want GCC to zero our struct! It already is zeroed and has an index!
Definition: ship.h:36