9723
|
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 |
CommandCost MaybeReplaceVehicle(Vehicle *v, bool check, bool display_costs);
|
|
80 |
bool CanBuildVehicleInfrastructure(VehicleType type);
|
|
81 |
|
|
82 |
void CcCloneVehicle(bool success, TileIndex tile, uint32 p1, uint32 p2);
|
|
83 |
|
|
84 |
/* Flags to add to p2 for goto depot commands */
|
|
85 |
/* Note: bits 8-10 are used for VLW flags */
|
|
86 |
enum {
|
|
87 |
DEPOT_SERVICE = (1 << 0), // The vehicle will leave the depot right after arrival (serivce only)
|
|
88 |
DEPOT_MASS_SEND = (1 << 1), // Tells that it's a mass send to depot command (type in VLW flag)
|
|
89 |
DEPOT_DONT_CANCEL = (1 << 2), // Don't cancel current goto depot command if any
|
|
90 |
DEPOT_LOCATE_HANGAR = (1 << 3), // Find another airport if the target one lacks a hangar
|
|
91 |
};
|
|
92 |
|
|
93 |
struct GetNewVehiclePosResult {
|
|
94 |
int x, y;
|
|
95 |
TileIndex old_tile;
|
|
96 |
TileIndex new_tile;
|
|
97 |
};
|
|
98 |
|
|
99 |
/* returns true if staying in the same tile */
|
|
100 |
GetNewVehiclePosResult GetNewVehiclePos(const Vehicle *v);
|
|
101 |
Direction GetDirectionTowards(const Vehicle *v, int x, int y);
|
|
102 |
|
|
103 |
static inline bool IsPlayerBuildableVehicleType(VehicleType type)
|
|
104 |
{
|
|
105 |
switch (type) {
|
|
106 |
case VEH_TRAIN:
|
|
107 |
case VEH_ROAD:
|
|
108 |
case VEH_SHIP:
|
|
109 |
case VEH_AIRCRAFT:
|
|
110 |
return true;
|
|
111 |
|
|
112 |
default: return false;
|
|
113 |
}
|
|
114 |
}
|
|
115 |
|
|
116 |
static inline bool IsPlayerBuildableVehicleType(const BaseVehicle *v)
|
|
117 |
{
|
|
118 |
return IsPlayerBuildableVehicleType(v->type);
|
|
119 |
}
|
|
120 |
|
|
121 |
const struct Livery *GetEngineLivery(EngineID engine_type, PlayerID player, EngineID parent_engine_type, const Vehicle *v);
|
|
122 |
|
|
123 |
/**
|
|
124 |
* Get the colour map for an engine. This used for unbuilt engines in the user interface.
|
|
125 |
* @param engine_type ID of engine
|
|
126 |
* @param player ID of player
|
|
127 |
* @return A ready-to-use palette modifier
|
|
128 |
*/
|
|
129 |
SpriteID GetEnginePalette(EngineID engine_type, PlayerID player);
|
|
130 |
|
|
131 |
/**
|
|
132 |
* Get the colour map for a vehicle.
|
|
133 |
* @param v Vehicle to get colour map for
|
|
134 |
* @return A ready-to-use palette modifier
|
|
135 |
*/
|
|
136 |
SpriteID GetVehiclePalette(const Vehicle *v);
|
|
137 |
|
|
138 |
/* A lot of code calls for the invalidation of the status bar, which is widget 5.
|
|
139 |
* Best is to have a virtual value for it when it needs to change again */
|
|
140 |
#define STATUS_BAR 5
|
|
141 |
|
|
142 |
extern const uint32 _veh_build_proc_table[];
|
|
143 |
extern const uint32 _veh_sell_proc_table[];
|
|
144 |
extern const uint32 _veh_refit_proc_table[];
|
|
145 |
extern const uint32 _send_to_depot_proc_table[];
|
|
146 |
|
|
147 |
/* Functions to find the right command for certain vehicle type */
|
|
148 |
static inline uint32 GetCmdBuildVeh(VehicleType type)
|
|
149 |
{
|
|
150 |
return _veh_build_proc_table[type];
|
|
151 |
}
|
|
152 |
|
|
153 |
static inline uint32 GetCmdBuildVeh(const BaseVehicle *v)
|
|
154 |
{
|
|
155 |
return GetCmdBuildVeh(v->type);
|
|
156 |
}
|
|
157 |
|
|
158 |
static inline uint32 GetCmdSellVeh(VehicleType type)
|
|
159 |
{
|
|
160 |
return _veh_sell_proc_table[type];
|
|
161 |
}
|
|
162 |
|
|
163 |
static inline uint32 GetCmdSellVeh(const BaseVehicle *v)
|
|
164 |
{
|
|
165 |
return GetCmdSellVeh(v->type);
|
|
166 |
}
|
|
167 |
|
|
168 |
static inline uint32 GetCmdRefitVeh(VehicleType type)
|
|
169 |
{
|
|
170 |
return _veh_refit_proc_table[type];
|
|
171 |
}
|
|
172 |
|
|
173 |
static inline uint32 GetCmdRefitVeh(const BaseVehicle *v)
|
|
174 |
{
|
|
175 |
return GetCmdRefitVeh(v->type);
|
|
176 |
}
|
|
177 |
|
|
178 |
static inline uint32 GetCmdSendToDepot(VehicleType type)
|
|
179 |
{
|
|
180 |
return _send_to_depot_proc_table[type];
|
|
181 |
}
|
|
182 |
|
|
183 |
static inline uint32 GetCmdSendToDepot(const BaseVehicle *v)
|
|
184 |
{
|
|
185 |
return GetCmdSendToDepot(v->type);
|
|
186 |
}
|
|
187 |
|
|
188 |
bool EnsureNoVehicleOnGround(TileIndex tile);
|
|
189 |
void StopAllVehicles();
|
|
190 |
|
|
191 |
Vehicle *CreateEffectVehicle(int x, int y, int z, EffectVehicle type);
|
|
192 |
Vehicle *CreateEffectVehicleAbove(int x, int y, int z, EffectVehicle type);
|
|
193 |
Vehicle *CreateEffectVehicleRel(const Vehicle *v, int x, int y, int z, EffectVehicle type);
|
|
194 |
|
|
195 |
extern VehicleID _vehicle_id_ctr_day;
|
|
196 |
extern Vehicle *_place_clicked_vehicle;
|
|
197 |
extern VehicleID _new_vehicle_id;
|
|
198 |
extern uint16 _returned_refit_capacity;
|
|
199 |
|
|
200 |
#endif /* VEHICLE_H */
|