Update: Translations from eints
[openttd-github.git] / src / vehicle_func.h
blob8047a1952edbf0cb3a3b6d3c83319eaefbeba4b4
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 */
8 /** @file vehicle_func.h Functions related to vehicles. */
10 #ifndef VEHICLE_FUNC_H
11 #define VEHICLE_FUNC_H
13 #include "gfx_type.h"
14 #include "direction_type.h"
15 #include "timer/timer_game_economy.h"
16 #include "command_type.h"
17 #include "vehicle_type.h"
18 #include "engine_type.h"
19 #include "transport_type.h"
20 #include "newgrf_config.h"
21 #include "track_type.h"
22 #include "livery.h"
24 #define is_custom_sprite(x) (x >= 0xFD)
25 #define IS_CUSTOM_FIRSTHEAD_SPRITE(x) (x == 0xFD)
26 #define IS_CUSTOM_SECONDHEAD_SPRITE(x) (x == 0xFE)
28 static const TimerGameEconomy::Date VEHICLE_PROFIT_MIN_AGE = CalendarTime::DAYS_IN_YEAR * 2; ///< Only vehicles older than this have a meaningful profit.
29 static const Money VEHICLE_PROFIT_THRESHOLD = 10000; ///< Threshold for a vehicle to be considered making good profit.
31 /**
32 * Helper to check whether an image index is valid for a particular vehicle.
33 * @tparam T The type of vehicle.
34 * @param image_index The image index to check.
35 * @return True iff the image index is valid.
37 template <VehicleType T>
38 bool IsValidImageIndex(uint8_t image_index);
40 typedef Vehicle *VehicleFromPosProc(Vehicle *v, void *data);
42 void VehicleServiceInDepot(Vehicle *v);
43 uint CountVehiclesInChain(const Vehicle *v);
44 void FindVehicleOnPos(TileIndex tile, void *data, VehicleFromPosProc *proc);
45 void FindVehicleOnPosXY(int x, int y, void *data, VehicleFromPosProc *proc);
46 bool HasVehicleOnPos(TileIndex tile, void *data, VehicleFromPosProc *proc);
47 bool HasVehicleOnPosXY(int x, int y, void *data, VehicleFromPosProc *proc);
48 void CallVehicleTicks();
49 uint8_t CalcPercentVehicleFilled(const Vehicle *v, StringID *colour);
51 void VehicleLengthChanged(const Vehicle *u);
53 void ResetVehicleHash();
54 void ResetVehicleColourMap();
56 uint8_t GetBestFittingSubType(Vehicle *v_from, Vehicle *v_for, CargoID dest_cargo_type);
58 void ViewportAddVehicles(DrawPixelInfo *dpi);
60 void ShowNewGrfVehicleError(EngineID engine, StringID part1, StringID part2, GRFBugs bug_type, bool critical);
61 CommandCost TunnelBridgeIsFree(TileIndex tile, TileIndex endtile, const Vehicle *ignore = nullptr);
63 void DecreaseVehicleValue(Vehicle *v);
64 void CheckVehicleBreakdown(Vehicle *v);
65 void EconomyAgeVehicle(Vehicle *v);
66 void AgeVehicle(Vehicle *v);
67 void RunVehicleCalendarDayProc();
68 void VehicleEnteredDepotThisTick(Vehicle *v);
70 UnitID GetFreeUnitNumber(VehicleType type);
72 void VehicleEnterDepot(Vehicle *v);
74 bool CanBuildVehicleInfrastructure(VehicleType type, uint8_t subtype = 0);
76 /** Position information of a vehicle after it moved */
77 struct GetNewVehiclePosResult {
78 int x, y; ///< x and y position of the vehicle after moving
79 TileIndex old_tile; ///< Current tile of the vehicle
80 TileIndex new_tile; ///< Tile of the vehicle after moving
83 GetNewVehiclePosResult GetNewVehiclePos(const Vehicle *v);
84 Direction GetDirectionTowards(const Vehicle *v, int x, int y);
86 /**
87 * Is the given vehicle type buildable by a company?
88 * @param type Vehicle type being queried.
89 * @return Vehicle type is buildable by a company.
91 inline bool IsCompanyBuildableVehicleType(VehicleType type)
93 switch (type) {
94 case VEH_TRAIN:
95 case VEH_ROAD:
96 case VEH_SHIP:
97 case VEH_AIRCRAFT:
98 return true;
100 default: return false;
105 * Is the given vehicle buildable by a company?
106 * @param v Vehicle being queried.
107 * @return Vehicle is buildable by a company.
109 inline bool IsCompanyBuildableVehicleType(const BaseVehicle *v)
111 return IsCompanyBuildableVehicleType(v->type);
114 LiveryScheme GetEngineLiveryScheme(EngineID engine_type, EngineID parent_engine_type, const Vehicle *v);
115 const struct Livery *GetEngineLivery(EngineID engine_type, CompanyID company, EngineID parent_engine_type, const Vehicle *v, uint8_t livery_setting);
117 SpriteID GetEnginePalette(EngineID engine_type, CompanyID company);
118 SpriteID GetVehiclePalette(const Vehicle *v);
120 extern const StringID _veh_build_msg_table[];
121 extern const StringID _veh_sell_msg_table[];
122 extern const StringID _veh_refit_msg_table[];
123 extern const StringID _send_to_depot_msg_table[];
125 /* Functions to find the right command for certain vehicle type */
126 inline StringID GetCmdBuildVehMsg(VehicleType type)
128 return _veh_build_msg_table[type];
131 inline StringID GetCmdBuildVehMsg(const BaseVehicle *v)
133 return GetCmdBuildVehMsg(v->type);
136 inline StringID GetCmdSellVehMsg(VehicleType type)
138 return _veh_sell_msg_table[type];
141 inline StringID GetCmdSellVehMsg(const BaseVehicle *v)
143 return GetCmdSellVehMsg(v->type);
146 inline StringID GetCmdRefitVehMsg(VehicleType type)
148 return _veh_refit_msg_table[type];
151 inline StringID GetCmdRefitVehMsg(const BaseVehicle *v)
153 return GetCmdRefitVehMsg(v->type);
156 inline StringID GetCmdSendToDepotMsg(VehicleType type)
158 return _send_to_depot_msg_table[type];
161 inline StringID GetCmdSendToDepotMsg(const BaseVehicle *v)
163 return GetCmdSendToDepotMsg(v->type);
166 CommandCost EnsureNoVehicleOnGround(TileIndex tile);
167 CommandCost EnsureNoTrainOnTrackBits(TileIndex tile, TrackBits track_bits);
169 bool CanVehicleUseStation(EngineID engine_type, const struct Station *st);
170 bool CanVehicleUseStation(const Vehicle *v, const struct Station *st);
171 StringID GetVehicleCannotUseStationReason(const Vehicle *v, const Station *st);
173 void ReleaseDisasterVehicle(VehicleID vehicle);
175 typedef std::vector<VehicleID> VehicleSet;
176 void GetVehicleSet(VehicleSet &set, Vehicle *v, uint8_t num_vehicles);
178 void CheckCargoCapacity(Vehicle *v);
180 bool VehiclesHaveSameEngineList(const Vehicle *v1, const Vehicle *v2);
181 bool VehiclesHaveSameOrderList(const Vehicle *v1, const Vehicle *v2);
183 bool IsUniqueVehicleName(const std::string &name);
185 #endif /* VEHICLE_FUNC_H */