(svn r23005) -Fix (r23004): Of course there's still the 16-sprite version for shore...
[openttd/fttd.git] / src / vehicle_func.h
blobefc07ed075436423dbe8294ce204fb276f6e3e91
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 typedef Vehicle *VehicleFromPosProc(Vehicle *v, void *data);
34 void VehicleServiceInDepot(Vehicle *v);
35 uint CountVehiclesInChain(const Vehicle *v);
36 void FindVehicleOnPos(TileIndex tile, void *data, VehicleFromPosProc *proc);
37 void FindVehicleOnPosXY(int x, int y, void *data, VehicleFromPosProc *proc);
38 bool HasVehicleOnPos(TileIndex tile, void *data, VehicleFromPosProc *proc);
39 bool HasVehicleOnPosXY(int x, int y, void *data, VehicleFromPosProc *proc);
40 void CallVehicleTicks();
41 uint8 CalcPercentVehicleFilled(const Vehicle *v, StringID *colour);
43 byte VehicleRandomBits();
44 void ResetVehiclePosHash();
45 void ResetVehicleColourMap();
47 byte GetBestFittingSubType(Vehicle *v_from, Vehicle *v_for);
49 void ViewportAddVehicles(DrawPixelInfo *dpi);
51 void ShowNewGrfVehicleError(EngineID engine, StringID part1, StringID part2, GRFBugs bug_type, bool critical);
52 CommandCost TunnelBridgeIsFree(TileIndex tile, TileIndex endtile, const Vehicle *ignore = NULL);
54 void DecreaseVehicleValue(Vehicle *v);
55 void CheckVehicleBreakdown(Vehicle *v);
56 void AgeVehicle(Vehicle *v);
57 void VehicleEnteredDepotThisTick(Vehicle *v);
59 void VehicleMove(Vehicle *v, bool update_viewport);
60 void MarkSingleVehicleDirty(const Vehicle *v);
62 UnitID GetFreeUnitNumber(VehicleType type);
64 void VehicleEnterDepot(Vehicle *v);
66 bool CanBuildVehicleInfrastructure(VehicleType type);
68 /** Position information of a vehicle after it moved */
69 struct GetNewVehiclePosResult {
70 int x, y; ///< x and y position of the vehicle after moving
71 TileIndex old_tile; ///< Current tile of the vehicle
72 TileIndex new_tile; ///< Tile of the vehicle after moving
75 GetNewVehiclePosResult GetNewVehiclePos(const Vehicle *v);
76 Direction GetDirectionTowards(const Vehicle *v, int x, int y);
78 /**
79 * Is the given vehicle type buildable by a company?
80 * @param type Vehicle type being queried.
81 * @return Vehicle type is buildable by a company.
83 static inline bool IsCompanyBuildableVehicleType(VehicleType type)
85 switch (type) {
86 case VEH_TRAIN:
87 case VEH_ROAD:
88 case VEH_SHIP:
89 case VEH_AIRCRAFT:
90 return true;
92 default: return false;
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 static 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, byte livery_setting);
109 SpriteID GetEnginePalette(EngineID engine_type, CompanyID company);
110 SpriteID GetVehiclePalette(const Vehicle *v);
112 uint GetVehicleCapacity(const Vehicle *v, uint16 *mail_capacity = NULL);
114 extern const uint32 _veh_build_proc_table[];
115 extern const uint32 _veh_sell_proc_table[];
116 extern const uint32 _veh_refit_proc_table[];
117 extern const uint32 _send_to_depot_proc_table[];
119 /* Functions to find the right command for certain vehicle type */
120 static inline uint32 GetCmdBuildVeh(VehicleType type)
122 return _veh_build_proc_table[type];
125 static inline uint32 GetCmdBuildVeh(const BaseVehicle *v)
127 return GetCmdBuildVeh(v->type);
130 static inline uint32 GetCmdSellVeh(VehicleType type)
132 return _veh_sell_proc_table[type];
135 static inline uint32 GetCmdSellVeh(const BaseVehicle *v)
137 return GetCmdSellVeh(v->type);
140 static inline uint32 GetCmdRefitVeh(VehicleType type)
142 return _veh_refit_proc_table[type];
145 static inline uint32 GetCmdRefitVeh(const BaseVehicle *v)
147 return GetCmdRefitVeh(v->type);
150 static inline uint32 GetCmdSendToDepot(VehicleType type)
152 return _send_to_depot_proc_table[type];
155 static inline uint32 GetCmdSendToDepot(const BaseVehicle *v)
157 return GetCmdSendToDepot(v->type);
160 CommandCost EnsureNoVehicleOnGround(TileIndex tile);
161 CommandCost EnsureNoTrainOnTrackBits(TileIndex tile, TrackBits track_bits);
163 extern VehicleID _new_vehicle_id;
164 extern uint16 _returned_refit_capacity;
165 extern uint16 _returned_mail_refit_capacity;
167 bool CanVehicleUseStation(EngineID engine_type, const struct Station *st);
168 bool CanVehicleUseStation(const Vehicle *v, const struct Station *st);
170 void ReleaseDisastersTargetingVehicle(VehicleID vehicle);
172 typedef SmallVector<VehicleID, 2> VehicleSet;
173 void GetVehicleSet(VehicleSet &set, Vehicle *v, uint8 num_vehicles);
175 #endif /* VEHICLE_FUNC_H */