OpenTTD Source 20241224-master-gf74b0cf984
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 "vehicle_base.h"
14#include "water_map.h"
15
16void GetShipSpriteSize(EngineID engine, uint &width, uint &height, int &xoffs, int &yoffs, EngineImageType image_type);
18
26
27using ShipPathCache = std::vector<ShipPathElement>;
28
32struct Ship final : public SpecializedVehicle<Ship, VEH_SHIP> {
33 ShipPathCache path;
38
42 virtual ~Ship() { this->PreDestructor(); }
43
44 void MarkDirty() override;
45 void UpdateDeltaXY() override;
46 ExpensesType GetExpenseType(bool income) const override { return income ? EXPENSES_SHIP_REVENUE : EXPENSES_SHIP_RUN; }
47 void PlayLeaveStationSound(bool force = false) const override;
48 bool IsPrimaryVehicle() const override { return true; }
49 void GetImage(Direction direction, EngineImageType image_type, VehicleSpriteSeq *result) const override;
50 int GetDisplaySpeed() const override { return this->cur_speed / 2; }
51 int GetDisplayMaxSpeed() const override { return this->vcache.cached_max_speed / 2; }
52 int GetCurrentMaxSpeed() const override { return std::min<int>(this->vcache.cached_max_speed, this->current_order.GetMaxSpeed() * 2); }
53 Money GetRunningCost() const override;
54 bool IsInDepot() const override { return this->state == TRACK_BIT_DEPOT; }
55 bool Tick() override;
56 void OnNewCalendarDay() override;
57 void OnNewEconomyDay() override;
58 Trackdir GetVehicleTrackdir() const override;
59 TileIndex GetOrderStationLocation(StationID station) override;
61 void UpdateCache();
62 void SetDestTile(TileIndex tile) override;
63};
64
65bool IsShipDestinationTile(TileIndex tile, StationID station);
66
67#endif /* SHIP_H */
Direction
Defines the 8 directions on the map.
ExpensesType
Types of expenses.
@ EXPENSES_SHIP_REVENUE
Revenue from ships.
@ EXPENSES_SHIP_RUN
Running costs ships.
uint16_t EngineID
Unique identification number of an engine.
Definition engine_type.h:21
bool IsShipDestinationTile(TileIndex tile, StationID station)
Test if a tile is a docking tile for the given station.
Definition ship_cmd.cpp:647
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:120
WaterClass GetEffectiveWaterClass(TileIndex tile)
Determine the effective WaterClass for a ship travelling on a tile.
Definition ship_cmd.cpp:54
Structure to return information about the closest depot location, and whether it could be found.
Element of the ShipPathCache.
Definition ship.h:20
Trackdir trackdir
Trackdir for this element.
Definition ship.h:21
All ships have this type.
Definition ship.h:32
bool Tick() override
Calls the tick handler of the vehicle.
Definition ship_cmd.cpp:869
Money GetRunningCost() const override
Gets the running cost of a vehicle.
Definition ship_cmd.cpp:247
TileIndex GetOrderStationLocation(StationID station) override
Determine the location for the station where the vehicle goes to next.
Definition ship_cmd.cpp:318
int GetCurrentMaxSpeed() const override
Calculates the maximum speed of the vehicle under its current conditions.
Definition ship.h:52
TrackBits state
The "track" the ship is following.
Definition ship.h:34
int16_t rotation_x_pos
NOSAVE: X Position before rotation.
Definition ship.h:36
int GetDisplayMaxSpeed() const override
Gets the maximum speed in km-ish/h that can be sent into SetDParam for string processing.
Definition ship.h:51
Direction rotation
Visible direction.
Definition ship.h:35
void UpdateDeltaXY() override
Updates the x and y offsets and the size of the sprite used for this vehicle.
Definition ship_cmd.cpp:331
void OnNewCalendarDay() override
Calendar day handler.
Definition ship_cmd.cpp:255
int16_t rotation_y_pos
NOSAVE: Y Position before rotation.
Definition ship.h:37
ShipPathCache path
Cached path.
Definition ship.h:33
ClosestDepot FindClosestDepot() override
Find the closest depot for this vehicle and tell us the location, DestinationID and whether we should...
Definition ship_cmd.cpp:959
void MarkDirty() override
Marks the vehicles to be redrawn and updates cached variables.
Definition ship_cmd.cpp:305
bool IsPrimaryVehicle() const override
Whether this is the primary vehicle in the chain.
Definition ship.h:48
Trackdir GetVehicleTrackdir() const override
Returns the Trackdir on which the vehicle is currently located.
Definition ship_cmd.cpp:288
bool IsInDepot() const override
Check whether the vehicle is in the depot.
Definition ship.h:54
Ship()
We don't want GCC to zero our struct! It already is zeroed and has an index!
Definition ship.h:40
void PlayLeaveStationSound(bool force=false) const override
Play the sound associated with leaving the station.
Definition ship_cmd.cpp:312
int GetDisplaySpeed() const override
Gets the speed in km-ish/h that can be sent into SetDParam for string processing.
Definition ship.h:50
void OnNewEconomyDay() override
Economy day handler.
Definition ship_cmd.cpp:261
virtual ~Ship()
We want to 'destruct' the right class.
Definition ship.h:42
void GetImage(Direction direction, EngineImageType image_type, VehicleSpriteSeq *result) const override
Gets the sprite to show for the given direction.
Definition ship_cmd.cpp:134
void UpdateCache()
Update the caches of this ship.
Definition ship_cmd.cpp:232
ExpensesType GetExpenseType(bool income) const override
Sets the expense type associated to this vehicle type.
Definition ship.h:46
Class defining several overloaded accessors so we don't have to cast vehicle types that often.
uint16_t cached_max_speed
Maximum speed of the consist (minimum of the max speed of all vehicles in the consist).
Sprite sequence for a vehicle part.
Direction direction
facing
void PreDestructor()
Destroy all stuff that (still) needs the virtual functions to work properly.
Definition vehicle.cpp:826
VehicleCache vcache
Cache of often used vehicle values.
uint16_t cur_speed
current speed
TileIndex tile
Current tile index.
TrackBits
Allow incrementing of Track variables.
Definition track_type.h:35
@ TRACK_BIT_DEPOT
Bitflag for a depot.
Definition track_type.h:53
Trackdir
Enumeration for tracks and directions.
Definition track_type.h:67
@ INVALID_TRACKDIR
Flag for an invalid trackdir.
Definition track_type.h:86
Base class for all vehicles.
EngineImageType
Visualisation contexts of vehicles and engines.
Map accessors for water tiles.
WaterClass
classes of water (for WATER_TILE_CLEAR water tile type).
Definition water_map.h:39