Fix: Don't allow right-click to close world generation progress window. (#13084)
[openttd-github.git] / src / vehicle_func.h
blob48ecfb2da00575c322376eb3c73e7948c301a5ec
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 return type < VEH_COMPANY_END;
96 /**
97 * Is the given vehicle buildable by a company?
98 * @param v Vehicle being queried.
99 * @return Vehicle is buildable by a company.
101 inline bool IsCompanyBuildableVehicleType(const BaseVehicle *v)
103 return IsCompanyBuildableVehicleType(v->type);
106 LiveryScheme GetEngineLiveryScheme(EngineID engine_type, EngineID parent_engine_type, const Vehicle *v);
107 const struct Livery *GetEngineLivery(EngineID engine_type, CompanyID company, EngineID parent_engine_type, const Vehicle *v, uint8_t livery_setting);
109 SpriteID GetEnginePalette(EngineID engine_type, CompanyID company);
110 SpriteID GetVehiclePalette(const Vehicle *v);
112 extern const StringID _veh_build_msg_table[];
113 extern const StringID _veh_sell_msg_table[];
114 extern const StringID _veh_refit_msg_table[];
115 extern const StringID _send_to_depot_msg_table[];
117 /* Functions to find the right command for certain vehicle type */
118 inline StringID GetCmdBuildVehMsg(VehicleType type)
120 return _veh_build_msg_table[type];
123 inline StringID GetCmdBuildVehMsg(const BaseVehicle *v)
125 return GetCmdBuildVehMsg(v->type);
128 inline StringID GetCmdSellVehMsg(VehicleType type)
130 return _veh_sell_msg_table[type];
133 inline StringID GetCmdSellVehMsg(const BaseVehicle *v)
135 return GetCmdSellVehMsg(v->type);
138 inline StringID GetCmdRefitVehMsg(VehicleType type)
140 return _veh_refit_msg_table[type];
143 inline StringID GetCmdRefitVehMsg(const BaseVehicle *v)
145 return GetCmdRefitVehMsg(v->type);
148 inline StringID GetCmdSendToDepotMsg(VehicleType type)
150 return _send_to_depot_msg_table[type];
153 inline StringID GetCmdSendToDepotMsg(const BaseVehicle *v)
155 return GetCmdSendToDepotMsg(v->type);
158 CommandCost EnsureNoVehicleOnGround(TileIndex tile);
159 CommandCost EnsureNoTrainOnTrackBits(TileIndex tile, TrackBits track_bits);
161 bool CanVehicleUseStation(EngineID engine_type, const struct Station *st);
162 bool CanVehicleUseStation(const Vehicle *v, const struct Station *st);
163 StringID GetVehicleCannotUseStationReason(const Vehicle *v, const Station *st);
165 void ReleaseDisasterVehicle(VehicleID vehicle);
167 typedef std::vector<VehicleID> VehicleSet;
168 void GetVehicleSet(VehicleSet &set, Vehicle *v, uint8_t num_vehicles);
170 void CheckCargoCapacity(Vehicle *v);
172 bool VehiclesHaveSameEngineList(const Vehicle *v1, const Vehicle *v2);
173 bool VehiclesHaveSameOrderList(const Vehicle *v1, const Vehicle *v2);
175 bool IsUniqueVehicleName(const std::string &name);
177 #endif /* VEHICLE_FUNC_H */