OpenTTD: src/vehicle_func.h Source File

OpenTTD

- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files

- File List
- Globals

vehicle_func.h
Go to the documentation of this file.
1 /* $Id: vehicle_func.h 26863 2014-09-20 15:31:26Z rubidium $ */
2
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 */
9
12 #ifndef VEHICLE_FUNC_H
13 #define VEHICLE_FUNC_H
14
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"
24
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)
28
29 static const int VEHICLE_PROFIT_MIN_AGE = DAYS_IN_YEAR * 2;
30 static const Money VEHICLE_PROFIT_THRESHOLD = 10000;
31
38 template <VehicleType T>
39 bool IsValidImageIndex(uint8 image_index);
40
41 typedef Vehicle *VehicleFromPosProc(Vehicle *v, void *data);
42
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);
51
52 void VehicleLengthChanged(const Vehicle *u);
53
54 byte VehicleRandomBits();
55 void ResetVehicleHash();
56 void ResetVehicleColourMap();
57
58 byte GetBestFittingSubType(Vehicle *v_from, Vehicle *v_for, CargoID dest_cargo_type);
59
60 void ViewportAddVehicles(DrawPixelInfo *dpi);
61
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);
64
65 void DecreaseVehicleValue(Vehicle *v);
66 void CheckVehicleBreakdown(Vehicle *v);
67 void AgeVehicle(Vehicle *v);
68 void VehicleEnteredDepotThisTick(Vehicle *v);
69
70 UnitID GetFreeUnitNumber(VehicleType type);
71
72 void VehicleEnterDepot(Vehicle *v);
73
74 bool CanBuildVehicleInfrastructure(VehicleType type);
75
77 struct GetNewVehiclePosResult {
78 int x, y;
79 TileIndex old_tile;
80 TileIndex new_tile;
81 };
82
83 GetNewVehiclePosResult GetNewVehiclePos(const Vehicle *v);
84 Direction GetDirectionTowards(const Vehicle *v, int x, int y);
85
91 static inline bool IsCompanyBuildableVehicleType(VehicleType type)
92 {
93 switch (type) {
94 case VEH_TRAIN:
95 case VEH_ROAD:
96 case VEH_SHIP:
97 case VEH_AIRCRAFT:
98 return true;
99
100 default: return false;
101 }
102 }
103
109 static inline bool IsCompanyBuildableVehicleType(const BaseVehicle *v)
110 {
111 return IsCompanyBuildableVehicleType(v->type);
112 }
113
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);
116
117 SpriteID GetEnginePalette(EngineID engine_type, CompanyID company);
118 SpriteID GetVehiclePalette(const Vehicle *v);
119
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[];
124
125 /* Functions to find the right command for certain vehicle type */
126 static inline uint32 GetCmdBuildVeh(VehicleType type)
127 {
128 return _veh_build_proc_table[type];
129 }
130
131 static inline uint32 GetCmdBuildVeh(const BaseVehicle *v)
132 {
133 return GetCmdBuildVeh(v->type);
134 }
135
136 static inline uint32 GetCmdSellVeh(VehicleType type)
137 {
138 return _veh_sell_proc_table[type];
139 }
140
141 static inline uint32 GetCmdSellVeh(const BaseVehicle *v)
142 {
143 return GetCmdSellVeh(v->type);
144 }
145
146 static inline uint32 GetCmdRefitVeh(VehicleType type)
147 {
148 return _veh_refit_proc_table[type];
149 }
150
151 static inline uint32 GetCmdRefitVeh(const BaseVehicle *v)
152 {
153 return GetCmdRefitVeh(v->type);
154 }
155
156 static inline uint32 GetCmdSendToDepot(VehicleType type)
157 {
158 return _send_to_depot_proc_table[type];
159 }
160
161 static inline uint32 GetCmdSendToDepot(const BaseVehicle *v)
162 {
163 return GetCmdSendToDepot(v->type);
164 }
165
166 CommandCost EnsureNoVehicleOnGround(TileIndex tile);
167 CommandCost EnsureNoTrainOnTrackBits(TileIndex tile, TrackBits track_bits);
168
169 extern VehicleID _new_vehicle_id;
170 extern uint16 _returned_refit_capacity;
171 extern uint16 _returned_mail_refit_capacity;
172
173 bool CanVehicleUseStation(EngineID engine_type, const struct Station *st);
174 bool CanVehicleUseStation(const Vehicle *v, const struct Station *st);
175
176 void ReleaseDisastersTargetingVehicle(VehicleID vehicle);
177
178 typedef SmallVector<VehicleID, 2> VehicleSet;
179 void GetVehicleSet(VehicleSet &set, Vehicle *v, uint8 num_vehicles);
180
181 void CheckCargoCapacity(Vehicle *v);
182
183 #endif /* VEHICLE_FUNC_H */