OpenTTD Source: src/ship.h Source File

OpenTTD Source 13.2.1

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);
19 WaterClass GetEffectiveWaterClass(TileIndex tile);
20
21 typedef std::deque<Trackdir> ShipPathCache;
22
26 struct Ship FINAL : public SpecializedVehicle<Ship, VEH_SHIP> {
27 TrackBits state;
28 ShipPathCache path;
29 Direction rotation;
30 int16 rotation_x_pos;
31 int16 rotation_y_pos;
32
34 Ship() : SpecializedVehicleBase() {}
36 virtual ~Ship() { this->PreDestructor(); }
37
38 void MarkDirty();
39 void UpdateDeltaXY();
40 ExpensesType GetExpenseType(bool income) const { return income ? EXPENSES_SHIP_REVENUE : EXPENSES_SHIP_RUN; }
41 void PlayLeaveStationSound(bool force = false) 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 std::min<int>(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();
51 Trackdir GetVehicleTrackdir() const;
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 */
Vehicle::PreDestructor
void PreDestructor()
Destroy all stuff that (still) needs the virtual functions to work properly.
Definition: vehicle.cpp:814
Direction
Direction
Defines the 8 directions on the map.
Definition: direction_type.h:24
Ship::Tick
bool Tick()
Calls the tick handler of the vehicle.
Definition: ship_cmd.cpp:840
Ship::FindClosestDepot
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:927
Ship::GetDisplaySpeed
int GetDisplaySpeed() const
Gets the speed in km-ish/h that can be sent into SetDParam for string processing.
Definition: ship.h:44
Ship::path
ShipPathCache path
Cached path.
Definition: ship.h:28
Ship::Ship
Ship()
We don't want GCC to zero our struct! It already is zeroed and has an index!
Definition: ship.h:34
GetEffectiveWaterClass
WaterClass GetEffectiveWaterClass(TileIndex tile)
Determine the effective WaterClass for a ship travelling on a tile.
Definition: ship_cmd.cpp:48
Ship::rotation
Direction rotation
Visible direction.
Definition: ship.h:29
Ship::PlayLeaveStationSound
void PlayLeaveStationSound(bool force=false) const
Play the sound associated with leaving the station.
Definition: ship_cmd.cpp:275
TileIndex
The index/ID of a Tile.
Definition: tile_type.h:85
vehicle_base.h
Ship::IsInDepot
bool IsInDepot() const
Check whether the vehicle is in the depot.
Definition: ship.h:48
EngineImageType
EngineImageType
Visualisation contexts of vehicles and engines.
Definition: vehicle_type.h:86
Vehicle::cur_speed
uint16 cur_speed
current speed
Definition: vehicle_base.h:307
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:114
Ship::UpdateCache
void UpdateCache()
Update the caches of this ship.
Definition: ship_cmd.cpp:203
Ship::IsPrimaryVehicle
bool IsPrimaryVehicle() const
Whether this is the primary vehicle in the chain.
Definition: ship.h:42
Ship::rotation_y_pos
int16 rotation_y_pos
NOSAVE: Y Position before rotation.
Definition: ship.h:31
EngineID
uint16 EngineID
Unique identification number of an engine.
Definition: engine_type.h:21
WaterClass
WaterClass
classes of water (for WATER_TILE_CLEAR water tile type).
Definition: water_map.h:47
Ship::GetExpenseType
ExpensesType GetExpenseType(bool income) const
Sets the expense type associated to this vehicle type.
Definition: ship.h:40
Vehicle::tile
TileIndex tile
Current tile index.
Definition: vehicle_base.h:245
Ship::MarkDirty
void MarkDirty()
Marks the vehicles to be redrawn and updates cached variables.
Definition: ship_cmd.cpp:268
VehicleSpriteSeq
Sprite sequence for a vehicle part.
Definition: vehicle_base.h:132
Ship::OnNewDay
void OnNewDay()
Calls the new day handler of the vehicle.
Definition: ship_cmd.cpp:225
SpecializedVehicle
Class defining several overloaded accessors so we don't have to cast vehicle types that often.
Definition: vehicle_base.h:1063
Ship::GetImage
void GetImage(Direction direction, EngineImageType image_type, VehicleSpriteSeq *result) const
Gets the sprite to show for the given direction.
Definition: ship_cmd.cpp:128
Ship::UpdateDeltaXY
void UpdateDeltaXY()
Updates the x and y offsets and the size of the sprite used for this vehicle.
Definition: ship_cmd.cpp:294
Ship::~Ship
virtual ~Ship()
We want to 'destruct' the right class.
Definition: ship.h:36
Ship::GetVehicleTrackdir
Trackdir GetVehicleTrackdir() const
Returns the Trackdir on which the vehicle is currently located.
Definition: ship_cmd.cpp:251
Vehicle::direction
Direction direction
facing
Definition: vehicle_base.h:286
TRACK_BIT_DEPOT
@ TRACK_BIT_DEPOT
Bitflag for a depot.
Definition: track_type.h:56
water_map.h
Vehicle::vcache
VehicleCache vcache
Cache of often used vehicle values.
Definition: vehicle_base.h:345
Ship
All ships have this type.
Definition: ship.h:26
Ship::GetOrderStationLocation
TileIndex GetOrderStationLocation(StationID station)
Determine the location for the station where the vehicle goes to next.
Definition: ship_cmd.cpp:281
Ship::state
TrackBits state
The "track" the ship is following.
Definition: ship.h:27
VehicleCache::cached_max_speed
uint16 cached_max_speed
Maximum speed of the consist (minimum of the max speed of all vehicles in the consist).
Definition: vehicle_base.h:125
TrackBits
TrackBits
Bitfield corresponding to Track.
Definition: track_type.h:38
Ship::rotation_x_pos
int16 rotation_x_pos
NOSAVE: X Position before rotation.
Definition: ship.h:30
OverflowSafeInt< int64 >
IsShipDestinationTile
bool IsShipDestinationTile(TileIndex tile, StationID station)
Test if a tile is a docking tile for the given station.
Definition: ship_cmd.cpp:620
Ship::GetRunningCost
Money GetRunningCost() const
Gets the running cost of a vehicle.
Definition: ship_cmd.cpp:218
Trackdir
Trackdir
Enumeration for tracks and directions.
Definition: track_type.h:70
Ship::GetDisplayMaxSpeed
int GetDisplayMaxSpeed() const
Gets the maximum speed in km-ish/h that can be sent into SetDParam for string processing.
Definition: ship.h:45
ExpensesType
ExpensesType
Types of expenses.
Definition: economy_type.h:157
EXPENSES_SHIP_RUN
@ EXPENSES_SHIP_RUN
Running costs ships.
Definition: economy_type.h:163
EXPENSES_SHIP_REVENUE
@ EXPENSES_SHIP_REVENUE
Revenue from ships.
Definition: economy_type.h:168
Ship::GetCurrentMaxSpeed
int GetCurrentMaxSpeed() const
Calculates the maximum speed of the vehicle under its current conditions.
Definition: ship.h:46