OpenTTD

ship.h
Go to the documentation of this file.
1 /* $Id: ship.h 27666 2016-10-16 14:57:56Z frosch $ */
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 "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
24 struct Ship FINAL : public SpecializedVehicle<Ship, VEH_SHIP> {
25 TrackBitsByte state;
26
28 Ship() : SpecializedVehicleBase() {}
30 virtual ~Ship() { this->PreDestructor(); }
31
32 void MarkDirty();
33 void UpdateDeltaXY(Direction direction);
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();
45 Trackdir GetVehicleTrackdir() const;
46 TileIndex GetOrderStationLocation(StationID station);
47 bool FindClosestDepot(TileIndex *location, DestinationID *destination, bool *reverse);
48 void UpdateCache();
49 };
50
55 #define FOR_ALL_SHIPS(var) FOR_ALL_VEHICLES_OF_TYPE(Ship, var)
56
57 #endif /* SHIP_H */
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:39
Vehicle::direction
DirectionByte direction
facing
Definition: vehicle_base.h:271
Ship::PlayLeaveStationSound
void PlayLeaveStationSound() const
Play the sound associated with leaving the station.
Definition: ship_cmd.cpp:281
Ship::Tick
bool Tick()
Calls the tick handler of the vehicle.
Definition: ship_cmd.cpp:635
Vehicle::cur_speed
uint16 cur_speed
current speed
Definition: vehicle_base.h:293
Ship::UpdateDeltaXY
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
Ship::IsInDepot
bool IsInDepot() const
Check whether the vehicle is in the depot.
Definition: ship.h:42
Ship::IsPrimaryVehicle
bool IsPrimaryVehicle() const
Whether this is the primary vehicle in the chain.
Definition: ship.h:36
Ship::GetDisplaySpeed
int GetDisplaySpeed() const
Gets the speed in km-ish/h that can be sent into SetDParam for string processing. ...
Definition: ship.h:38
Vehicle::PreDestructor
void PreDestructor()
Destroy all stuff that (still) needs the virtual functions to work properly.
Definition: vehicle.cpp:802
Ship::state
TrackBitsByte state
The "track" the ship is following.
Definition: ship.h:25
EngineImageType
EngineImageType
Visualisation contexts of vehicles and engines.
Definition: vehicle_type.h:87
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:123
Ship::OnNewDay
void OnNewDay()
Calls the new day handler of the vehicle.
Definition: ship_cmd.cpp:224
Direction
Direction
Defines the 8 directions on the map.
Definition: direction_type.h:26
Ship::GetExpenseType
ExpensesType GetExpenseType(bool income) const
Sets the expense type associated to this vehicle type.
Definition: ship.h:34
Ship::~Ship
virtual ~Ship()
We want to &#39;destruct&#39; the right class.
Definition: ship.h:30
SpecializedVehicle
Class defining several overloaded accessors so we don&#39;t have to cast vehicle types that often...
Definition: vehicle_base.h:993
Ship::UpdateCache
void UpdateCache()
Update the caches of this ship.
Definition: ship_cmd.cpp:202
Ship::MarkDirty
void MarkDirty()
Marks the vehicles to be redrawn and updates cached variables.
Definition: ship_cmd.cpp:267
WaterClass
WaterClass
classes of water (for WATER_TILE_CLEAR water tile type).
Definition: water_map.h:49
water_map.h
Map accessors for water tiles.
Trackdir
Trackdir
Enumeration for tracks and directions.
Definition: track_type.h:74
ExpensesType
ExpensesType
Types of expenses.
Definition: economy_type.h:150
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:127
VehicleSpriteSeq
Sprite sequence for a vehicle part.
Definition: vehicle_base.h:130
min
static T min(const T a, const T b)
Returns the minimum of two values.
Definition: math_func.hpp:42
EXPENSES_SHIP_RUN
Running costs ships.
Definition: economy_type.h:156
SimpleTinyEnumT< TrackBits, byte >
Ship
All ships have this type.
Definition: ship.h:24
Ship::GetOrderStationLocation
TileIndex GetOrderStationLocation(StationID station)
Determine the location for the station where the vehicle goes to next.
Definition: ship_cmd.cpp:286
vehicle_base.h
Base class for all vehicles.
EngineID
uint16 EngineID
Unique identification number of an engine.
Definition: engine_type.h:22
TileIndex
uint32 TileIndex
The index/ID of a Tile.
Definition: tile_type.h:80
TRACK_BIT_DEPOT
Bitflag for a depot.
Definition: track_type.h:59
Ship::GetVehicleTrackdir
Trackdir GetVehicleTrackdir() const
Returns the Trackdir on which the vehicle is currently located.
Definition: ship_cmd.cpp:250
EXPENSES_SHIP_INC
Income from ships.
Definition: economy_type.h:161
Ship::GetCurrentMaxSpeed
int GetCurrentMaxSpeed() const
Calculates the maximum speed of the vehicle under its current conditions.
Definition: ship.h:40
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:113
Vehicle::vcache
VehicleCache vcache
Cache of often used vehicle values.
Definition: vehicle_base.h:330
GetEffectiveWaterClass
WaterClass GetEffectiveWaterClass(TileIndex tile)
Determine the effective WaterClass for a ship travelling on a tile.
Definition: ship_cmd.cpp:47
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:715
OverflowSafeInt< int64, INT64_MAX, INT64_MIN >
Ship::GetRunningCost
Money GetRunningCost() const
Gets the running cost of a vehicle.
Definition: ship_cmd.cpp:217
Ship::Ship
Ship()
We don&#39;t want GCC to zero our struct! It already is zeroed and has an index!
Definition: ship.h:28