|
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 Vehicle *CheckClickOnVehicle(const ViewPort *vp, int x, int y); |
|
54 |
|
55 void DecreaseVehicleValue(Vehicle *v); |
|
56 void CheckVehicleBreakdown(Vehicle *v); |
|
57 void AgeVehicle(Vehicle *v); |
|
58 void VehicleEnteredDepotThisTick(Vehicle *v); |
|
59 |
|
60 void BeginVehicleMove(const Vehicle *v); |
|
61 void EndVehicleMove(const Vehicle *v); |
|
62 void MarkSingleVehicleDirty(const Vehicle *v); |
|
63 |
|
64 UnitID GetFreeUnitNumber(VehicleType type); |
|
65 |
|
66 void TrainConsistChanged(Vehicle *v); |
|
67 void TrainPowerChanged(Vehicle *v); |
|
68 Money GetTrainRunningCost(const Vehicle *v); |
|
69 |
|
70 bool VehicleNeedsService(const Vehicle *v); |
|
71 |
|
72 uint GenerateVehicleSortList(const Vehicle*** sort_list, uint16 *length_of_array, VehicleType type, PlayerID owner, uint32 index, uint16 window_type); |
|
73 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); |
|
74 CommandCost SendAllVehiclesToDepot(VehicleType type, uint32 flags, bool service, PlayerID owner, uint16 vlw_flag, uint32 id); |
|
75 void VehicleEnterDepot(Vehicle *v); |
|
76 |
|
77 CommandCost MaybeReplaceVehicle(Vehicle *v, bool check, bool display_costs); |
|
78 bool CanBuildVehicleInfrastructure(VehicleType type); |
|
79 |
|
80 void CcCloneVehicle(bool success, TileIndex tile, uint32 p1, uint32 p2); |
|
81 |
|
82 /* Flags to add to p2 for goto depot commands */ |
|
83 /* Note: bits 8-10 are used for VLW flags */ |
|
84 enum { |
|
85 DEPOT_SERVICE = (1 << 0), // The vehicle will leave the depot right after arrival (serivce only) |
|
86 DEPOT_MASS_SEND = (1 << 1), // Tells that it's a mass send to depot command (type in VLW flag) |
|
87 DEPOT_DONT_CANCEL = (1 << 2), // Don't cancel current goto depot command if any |
|
88 DEPOT_LOCATE_HANGAR = (1 << 3), // Find another airport if the target one lacks a hangar |
|
89 }; |
|
90 |
|
91 struct GetNewVehiclePosResult { |
|
92 int x, y; |
|
93 TileIndex old_tile; |
|
94 TileIndex new_tile; |
|
95 }; |
|
96 |
|
97 /* returns true if staying in the same tile */ |
|
98 GetNewVehiclePosResult GetNewVehiclePos(const Vehicle *v); |
|
99 Direction GetDirectionTowards(const Vehicle *v, int x, int y); |
|
100 |
|
101 static inline bool IsPlayerBuildableVehicleType(VehicleType type) |
|
102 { |
|
103 switch (type) { |
|
104 case VEH_TRAIN: |
|
105 case VEH_ROAD: |
|
106 case VEH_SHIP: |
|
107 case VEH_AIRCRAFT: |
|
108 return true; |
|
109 |
|
110 default: return false; |
|
111 } |
|
112 } |
|
113 |
|
114 static inline bool IsPlayerBuildableVehicleType(const BaseVehicle *v) |
|
115 { |
|
116 return IsPlayerBuildableVehicleType(v->type); |
|
117 } |
|
118 |
|
119 const struct Livery *GetEngineLivery(EngineID engine_type, PlayerID player, EngineID parent_engine_type, const Vehicle *v); |
|
120 |
|
121 /** |
|
122 * Get the colour map for an engine. This used for unbuilt engines in the user interface. |
|
123 * @param engine_type ID of engine |
|
124 * @param player ID of player |
|
125 * @return A ready-to-use palette modifier |
|
126 */ |
|
127 SpriteID GetEnginePalette(EngineID engine_type, PlayerID player); |
|
128 |
|
129 /** |
|
130 * Get the colour map for a vehicle. |
|
131 * @param v Vehicle to get colour map for |
|
132 * @return A ready-to-use palette modifier |
|
133 */ |
|
134 SpriteID GetVehiclePalette(const Vehicle *v); |
|
135 |
|
136 extern const uint32 _veh_build_proc_table[]; |
|
137 extern const uint32 _veh_sell_proc_table[]; |
|
138 extern const uint32 _veh_refit_proc_table[]; |
|
139 extern const uint32 _send_to_depot_proc_table[]; |
|
140 |
|
141 /* Functions to find the right command for certain vehicle type */ |
|
142 static inline uint32 GetCmdBuildVeh(VehicleType type) |
|
143 { |
|
144 return _veh_build_proc_table[type]; |
|
145 } |
|
146 |
|
147 static inline uint32 GetCmdBuildVeh(const BaseVehicle *v) |
|
148 { |
|
149 return GetCmdBuildVeh(v->type); |
|
150 } |
|
151 |
|
152 static inline uint32 GetCmdSellVeh(VehicleType type) |
|
153 { |
|
154 return _veh_sell_proc_table[type]; |
|
155 } |
|
156 |
|
157 static inline uint32 GetCmdSellVeh(const BaseVehicle *v) |
|
158 { |
|
159 return GetCmdSellVeh(v->type); |
|
160 } |
|
161 |
|
162 static inline uint32 GetCmdRefitVeh(VehicleType type) |
|
163 { |
|
164 return _veh_refit_proc_table[type]; |
|
165 } |
|
166 |
|
167 static inline uint32 GetCmdRefitVeh(const BaseVehicle *v) |
|
168 { |
|
169 return GetCmdRefitVeh(v->type); |
|
170 } |
|
171 |
|
172 static inline uint32 GetCmdSendToDepot(VehicleType type) |
|
173 { |
|
174 return _send_to_depot_proc_table[type]; |
|
175 } |
|
176 |
|
177 static inline uint32 GetCmdSendToDepot(const BaseVehicle *v) |
|
178 { |
|
179 return GetCmdSendToDepot(v->type); |
|
180 } |
|
181 |
|
182 bool EnsureNoVehicleOnGround(TileIndex tile); |
|
183 void StopAllVehicles(); |
|
184 |
|
185 Vehicle *CreateEffectVehicle(int x, int y, int z, EffectVehicle type); |
|
186 Vehicle *CreateEffectVehicleAbove(int x, int y, int z, EffectVehicle type); |
|
187 Vehicle *CreateEffectVehicleRel(const Vehicle *v, int x, int y, int z, EffectVehicle type); |
|
188 |
|
189 extern VehicleID _vehicle_id_ctr_day; |
|
190 extern Vehicle *_place_clicked_vehicle; |
|
191 extern VehicleID _new_vehicle_id; |
|
192 extern uint16 _returned_refit_capacity; |
|
193 |
|
194 #endif /* VEHICLE_H */ |