(svn r27724) -Cleanup: Remove pointless usage of IsOpenTTDBaseGRF. System GRFs are...
[openttd.git] / src / vehicle_func.h
blob9eb6b9121927a0233ef5c922db3f79033b474db4
1 /* $Id$ */
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 */
10 /** @file vehicle_func.h Functions related to vehicles. */
12 #ifndef VEHICLE_FUNC_H
13 #define VEHICLE_FUNC_H
15 #include "gfx_type.h"
16 #include "direction_type.h"
17 #include "command_type.h"
18 #include "vehicle_type.h"
19 #include "engine_type.h"
20 #include "transport_type.h"
21 #include "newgrf_config.h"
22 #include "track_type.h"
23 #include "livery.h"
25 #define is_custom_sprite(x) (x >= 0xFD)
26 #define IS_CUSTOM_FIRSTHEAD_SPRITE(x) (x == 0xFD)
27 #define IS_CUSTOM_SECONDHEAD_SPRITE(x) (x == 0xFE)
29 static const int VEHICLE_PROFIT_MIN_AGE = DAYS_IN_YEAR * 2; ///< Only vehicles older than this have a meaningful profit.
30 static const Money VEHICLE_PROFIT_THRESHOLD = 10000; ///< Threshold for a vehicle to be considered making good profit.
32 /**
33 * Helper to check whether an image index is valid for a particular vehicle.
34 * @param <T> The type of vehicle.
35 * @param image_index The image index to check.
36 * @return True iff the image index is valid.
38 template <VehicleType T>
39 bool IsValidImageIndex(uint8 image_index);
41 typedef Vehicle *VehicleFromPosProc(Vehicle *v, void *data);
43 void VehicleServiceInDepot(Vehicle *v);
44 uint CountVehiclesInChain(const Vehicle *v);
45 void FindVehicleOnPos(TileIndex tile, void *data, VehicleFromPosProc *proc);
46 void FindVehicleOnPosXY(int x, int y, void *data, VehicleFromPosProc *proc);
47 bool HasVehicleOnPos(TileIndex tile, void *data, VehicleFromPosProc *proc);
48 bool HasVehicleOnPosXY(int x, int y, void *data, VehicleFromPosProc *proc);
49 void CallVehicleTicks();
50 uint8 CalcPercentVehicleFilled(const Vehicle *v, StringID *colour);
52 void VehicleLengthChanged(const Vehicle *u);
54 byte VehicleRandomBits();
55 void ResetVehicleHash();
56 void ResetVehicleColourMap();
58 byte GetBestFittingSubType(Vehicle *v_from, Vehicle *v_for, CargoID dest_cargo_type);
60 void ViewportAddVehicles(DrawPixelInfo *dpi);
62 void ShowNewGrfVehicleError(EngineID engine, StringID part1, StringID part2, GRFBugs bug_type, bool critical);
63 CommandCost TunnelBridgeIsFree(TileIndex tile, TileIndex endtile, const Vehicle *ignore = NULL);
65 void DecreaseVehicleValue(Vehicle *v);
66 void CheckVehicleBreakdown(Vehicle *v);
67 void AgeVehicle(Vehicle *v);
68 void VehicleEnteredDepotThisTick(Vehicle *v);
70 UnitID GetFreeUnitNumber(VehicleType type);
72 void VehicleEnterDepot(Vehicle *v);
74 bool CanBuildVehicleInfrastructure(VehicleType type);
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 static 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 static 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, byte livery_setting);
117 SpriteID GetEnginePalette(EngineID engine_type, CompanyID company);
118 SpriteID GetVehiclePalette(const Vehicle *v);
120 extern const uint32 _veh_build_proc_table[];
121 extern const uint32 _veh_sell_proc_table[];
122 extern const uint32 _veh_refit_proc_table[];
123 extern const uint32 _send_to_depot_proc_table[];
125 /* Functions to find the right command for certain vehicle type */
126 static inline uint32 GetCmdBuildVeh(VehicleType type)
128 return _veh_build_proc_table[type];
131 static inline uint32 GetCmdBuildVeh(const BaseVehicle *v)
133 return GetCmdBuildVeh(v->type);
136 static inline uint32 GetCmdSellVeh(VehicleType type)
138 return _veh_sell_proc_table[type];
141 static inline uint32 GetCmdSellVeh(const BaseVehicle *v)
143 return GetCmdSellVeh(v->type);
146 static inline uint32 GetCmdRefitVeh(VehicleType type)
148 return _veh_refit_proc_table[type];
151 static inline uint32 GetCmdRefitVeh(const BaseVehicle *v)
153 return GetCmdRefitVeh(v->type);
156 static inline uint32 GetCmdSendToDepot(VehicleType type)
158 return _send_to_depot_proc_table[type];
161 static inline uint32 GetCmdSendToDepot(const BaseVehicle *v)
163 return GetCmdSendToDepot(v->type);
166 CommandCost EnsureNoVehicleOnGround(TileIndex tile);
167 CommandCost EnsureNoTrainOnTrackBits(TileIndex tile, TrackBits track_bits);
169 extern VehicleID _new_vehicle_id;
170 extern uint16 _returned_refit_capacity;
171 extern uint16 _returned_mail_refit_capacity;
173 bool CanVehicleUseStation(EngineID engine_type, const struct Station *st);
174 bool CanVehicleUseStation(const Vehicle *v, const struct Station *st);
176 void ReleaseDisastersTargetingVehicle(VehicleID vehicle);
178 typedef SmallVector<VehicleID, 2> VehicleSet;
179 void GetVehicleSet(VehicleSet &set, Vehicle *v, uint8 num_vehicles);
181 void CheckCargoCapacity(Vehicle *v);
183 #endif /* VEHICLE_FUNC_H */