|
1 /* $Id$ */ |
|
2 |
|
3 /** @vehicle.h Functions related to vehicles. */ |
|
4 |
|
5 #ifndef VEHICLE_FUNC_H |
|
6 #define VEHICLE_FUNC_H |
|
7 |
|
8 #include "tile_type.h" |
|
9 #include "strings_type.h" |
|
10 #include "gfx_type.h" |
|
11 #include "direction_type.h" |
|
12 #include "cargo_type.h" |
|
13 #include "command_type.h" |
|
14 #include "vehicle_type.h" |
|
15 |
|
16 #define is_custom_sprite(x) (x >= 0xFD) |
|
17 #define IS_CUSTOM_FIRSTHEAD_SPRITE(x) (x == 0xFD) |
|
18 #define IS_CUSTOM_SECONDHEAD_SPRITE(x) (x == 0xFE) |
|
19 |
|
20 typedef void *VehicleFromPosProc(Vehicle *v, void *data); |
|
21 |
|
22 void VehicleServiceInDepot(Vehicle *v); |
|
23 void VehiclePositionChanged(Vehicle *v); |
|
24 Vehicle *GetLastVehicleInChain(Vehicle *v); |
|
25 uint CountVehiclesInChain(const Vehicle *v); |
|
26 bool IsEngineCountable(const Vehicle *v); |
|
27 void DeleteVehicleChain(Vehicle *v); |
|
28 void *VehicleFromPos(TileIndex tile, void *data, VehicleFromPosProc *proc); |
|
29 void *VehicleFromPosXY(int x, int y, void *data, VehicleFromPosProc *proc); |
|
30 void CallVehicleTicks(); |
|
31 Vehicle *FindVehicleOnTileZ(TileIndex tile, byte z); |
|
32 uint8 CalcPercentVehicleFilled(Vehicle *v, StringID *color); |
|
33 |
|
34 void InitializeTrains(); |
|
35 byte VehicleRandomBits(); |
|
36 void ResetVehiclePosHash(); |
|
37 void ResetVehicleColorMap(); |
|
38 |
|
39 bool CanRefitTo(EngineID engine_type, CargoID cid_to); |
|
40 CargoID FindFirstRefittableCargo(EngineID engine_type); |
|
41 CommandCost GetRefitCost(EngineID engine_type); |
|
42 |
|
43 void ViewportAddVehicles(DrawPixelInfo *dpi); |
|
44 |
|
45 SpriteID GetRotorImage(const Vehicle *v); |
|
46 |
|
47 uint32 VehicleEnterTile(Vehicle *v, TileIndex tile, int x, int y); |
|
48 |
|
49 StringID VehicleInTheWayErrMsg(const Vehicle* v); |
|
50 Vehicle *FindVehicleBetween(TileIndex from, TileIndex to, byte z, bool without_crashed = false); |
|
51 Vehicle *GetVehicleTunnelBridge(TileIndex tile, TileIndex endtile); |
|
52 |
|
53 bool UpdateSignalsOnSegment(TileIndex tile, DiagDirection direction); |
|
54 void SetSignalsOnBothDir(TileIndex tile, byte track); |
|
55 |
|
56 Vehicle *CheckClickOnVehicle(const ViewPort *vp, int x, int y); |
|
57 |
|
58 void DecreaseVehicleValue(Vehicle *v); |
|
59 void CheckVehicleBreakdown(Vehicle *v); |
|
60 void AgeVehicle(Vehicle *v); |
|
61 void VehicleEnteredDepotThisTick(Vehicle *v); |
|
62 |
|
63 void BeginVehicleMove(Vehicle *v); |
|
64 void EndVehicleMove(Vehicle *v); |
|
65 |
|
66 UnitID GetFreeUnitNumber(VehicleType type); |
|
67 |
|
68 void TrainConsistChanged(Vehicle *v); |
|
69 void TrainPowerChanged(Vehicle *v); |
|
70 Money GetTrainRunningCost(const Vehicle *v); |
|
71 |
|
72 bool VehicleNeedsService(const Vehicle *v); |
|
73 |
|
74 uint GenerateVehicleSortList(const Vehicle*** sort_list, uint16 *length_of_array, VehicleType type, PlayerID owner, uint32 index, uint16 window_type); |
|
75 void BuildDepotVehicleList(VehicleType type, TileIndex tile, Vehicle ***engine_list, uint16 *engine_list_length, uint16 *engine_count, Vehicle ***wagon_list, uint16 *wagon_list_length, uint16 *wagon_count); |
|
76 CommandCost SendAllVehiclesToDepot(VehicleType type, uint32 flags, bool service, PlayerID owner, uint16 vlw_flag, uint32 id); |
|
77 void VehicleEnterDepot(Vehicle *v); |
|
78 |
|
79 void InvalidateAutoreplaceWindow(EngineID e, GroupID id_g); |
|
80 |
|
81 CommandCost MaybeReplaceVehicle(Vehicle *v, bool check, bool display_costs); |
|
82 bool CanBuildVehicleInfrastructure(VehicleType type); |
|
83 |
|
84 void CcCloneVehicle(bool success, TileIndex tile, uint32 p1, uint32 p2); |
|
85 |
|
86 /* Flags to add to p2 for goto depot commands */ |
|
87 /* Note: bits 8-10 are used for VLW flags */ |
|
88 enum { |
|
89 DEPOT_SERVICE = (1 << 0), // The vehicle will leave the depot right after arrival (serivce only) |
|
90 DEPOT_MASS_SEND = (1 << 1), // Tells that it's a mass send to depot command (type in VLW flag) |
|
91 DEPOT_DONT_CANCEL = (1 << 2), // Don't cancel current goto depot command if any |
|
92 DEPOT_LOCATE_HANGAR = (1 << 3), // Find another airport if the target one lacks a hangar |
|
93 }; |
|
94 |
|
95 struct GetNewVehiclePosResult { |
|
96 int x, y; |
|
97 TileIndex old_tile; |
|
98 TileIndex new_tile; |
|
99 }; |
|
100 |
|
101 /* returns true if staying in the same tile */ |
|
102 GetNewVehiclePosResult GetNewVehiclePos(const Vehicle *v); |
|
103 Direction GetDirectionTowards(const Vehicle *v, int x, int y); |
|
104 |
|
105 static inline bool IsPlayerBuildableVehicleType(VehicleType type) |
|
106 { |
|
107 switch (type) { |
|
108 case VEH_TRAIN: |
|
109 case VEH_ROAD: |
|
110 case VEH_SHIP: |
|
111 case VEH_AIRCRAFT: |
|
112 return true; |
|
113 |
|
114 default: return false; |
|
115 } |
|
116 } |
|
117 |
|
118 static inline bool IsPlayerBuildableVehicleType(const BaseVehicle *v) |
|
119 { |
|
120 return IsPlayerBuildableVehicleType(v->type); |
|
121 } |
|
122 |
|
123 const struct Livery *GetEngineLivery(EngineID engine_type, PlayerID player, EngineID parent_engine_type, const Vehicle *v); |
|
124 |
|
125 /** |
|
126 * Get the colour map for an engine. This used for unbuilt engines in the user interface. |
|
127 * @param engine_type ID of engine |
|
128 * @param player ID of player |
|
129 * @return A ready-to-use palette modifier |
|
130 */ |
|
131 SpriteID GetEnginePalette(EngineID engine_type, PlayerID player); |
|
132 |
|
133 /** |
|
134 * Get the colour map for a vehicle. |
|
135 * @param v Vehicle to get colour map for |
|
136 * @return A ready-to-use palette modifier |
|
137 */ |
|
138 SpriteID GetVehiclePalette(const Vehicle *v); |
|
139 |
|
140 /* A lot of code calls for the invalidation of the status bar, which is widget 5. |
|
141 * Best is to have a virtual value for it when it needs to change again */ |
|
142 #define STATUS_BAR 5 |
|
143 |
|
144 extern const uint32 _veh_build_proc_table[]; |
|
145 extern const uint32 _veh_sell_proc_table[]; |
|
146 extern const uint32 _veh_refit_proc_table[]; |
|
147 extern const uint32 _send_to_depot_proc_table[]; |
|
148 |
|
149 /* Functions to find the right command for certain vehicle type */ |
|
150 static inline uint32 GetCmdBuildVeh(VehicleType type) |
|
151 { |
|
152 return _veh_build_proc_table[type]; |
|
153 } |
|
154 |
|
155 static inline uint32 GetCmdBuildVeh(const BaseVehicle *v) |
|
156 { |
|
157 return GetCmdBuildVeh(v->type); |
|
158 } |
|
159 |
|
160 static inline uint32 GetCmdSellVeh(VehicleType type) |
|
161 { |
|
162 return _veh_sell_proc_table[type]; |
|
163 } |
|
164 |
|
165 static inline uint32 GetCmdSellVeh(const BaseVehicle *v) |
|
166 { |
|
167 return GetCmdSellVeh(v->type); |
|
168 } |
|
169 |
|
170 static inline uint32 GetCmdRefitVeh(VehicleType type) |
|
171 { |
|
172 return _veh_refit_proc_table[type]; |
|
173 } |
|
174 |
|
175 static inline uint32 GetCmdRefitVeh(const BaseVehicle *v) |
|
176 { |
|
177 return GetCmdRefitVeh(v->type); |
|
178 } |
|
179 |
|
180 static inline uint32 GetCmdSendToDepot(VehicleType type) |
|
181 { |
|
182 return _send_to_depot_proc_table[type]; |
|
183 } |
|
184 |
|
185 static inline uint32 GetCmdSendToDepot(const BaseVehicle *v) |
|
186 { |
|
187 return GetCmdSendToDepot(v->type); |
|
188 } |
|
189 |
|
190 bool EnsureNoVehicleOnGround(TileIndex tile); |
|
191 void StopAllVehicles(); |
|
192 |
|
193 Vehicle *CreateEffectVehicle(int x, int y, int z, EffectVehicle type); |
|
194 Vehicle *CreateEffectVehicleAbove(int x, int y, int z, EffectVehicle type); |
|
195 Vehicle *CreateEffectVehicleRel(const Vehicle *v, int x, int y, int z, EffectVehicle type); |
|
196 |
|
197 extern VehicleID _vehicle_id_ctr_day; |
|
198 extern Vehicle *_place_clicked_vehicle; |
|
199 extern VehicleID _new_vehicle_id; |
|
200 extern uint16 _returned_refit_capacity; |
|
201 |
|
202 #endif /* VEHICLE_H */ |