vehicle_func.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00012 #ifndef VEHICLE_FUNC_H
00013 #define VEHICLE_FUNC_H
00014
00015 #include "gfx_type.h"
00016 #include "direction_type.h"
00017 #include "command_type.h"
00018 #include "vehicle_type.h"
00019 #include "engine_type.h"
00020 #include "transport_type.h"
00021 #include "newgrf_config.h"
00022 #include "company_type.h"
00023
00024 #define is_custom_sprite(x) (x >= 0xFD)
00025 #define IS_CUSTOM_FIRSTHEAD_SPRITE(x) (x == 0xFD)
00026 #define IS_CUSTOM_SECONDHEAD_SPRITE(x) (x == 0xFE)
00027
00028 typedef Vehicle *VehicleFromPosProc(Vehicle *v, void *data);
00029
00030 void VehicleServiceInDepot(Vehicle *v);
00031 uint CountVehiclesInChain(const Vehicle *v);
00032 void CountCompanyVehicles(CompanyID cid, uint counts[4]);
00033 void FindVehicleOnPos(TileIndex tile, void *data, VehicleFromPosProc *proc);
00034 void FindVehicleOnPosXY(int x, int y, void *data, VehicleFromPosProc *proc);
00035 bool HasVehicleOnPos(TileIndex tile, void *data, VehicleFromPosProc *proc);
00036 bool HasVehicleOnPosXY(int x, int y, void *data, VehicleFromPosProc *proc);
00037 void CallVehicleTicks();
00038 uint8 CalcPercentVehicleFilled(const Vehicle *v, StringID *colour);
00039
00040 byte VehicleRandomBits();
00041 void ResetVehiclePosHash();
00042 void ResetVehicleColourMap();
00043
00044 byte GetBestFittingSubType(Vehicle *v_from, Vehicle *v_for);
00045 CommandCost RefitVehicle(Vehicle *v, bool only_this, CargoID new_cid, byte new_subtype, DoCommandFlag flags);
00046
00047 void ViewportAddVehicles(DrawPixelInfo *dpi);
00048
00049 void ShowNewGrfVehicleError(EngineID engine, StringID part1, StringID part2, GRFBugs bug_type, bool critical);
00050 bool HasVehicleOnTunnelBridge(TileIndex tile, TileIndex endtile, const Vehicle *ignore = NULL);
00051
00052 void DecreaseVehicleValue(Vehicle *v);
00053 void CheckVehicleBreakdown(Vehicle *v);
00054 void AgeVehicle(Vehicle *v);
00055 void VehicleEnteredDepotThisTick(Vehicle *v);
00056
00057 void VehicleMove(Vehicle *v, bool update_viewport);
00058 void MarkSingleVehicleDirty(const Vehicle *v);
00059
00060 UnitID GetFreeUnitNumber(VehicleType type);
00061
00062 CommandCost SendAllVehiclesToDepot(VehicleType type, DoCommandFlag flags, bool service, Owner owner, uint16 vlw_flag, uint32 id);
00063 void VehicleEnterDepot(Vehicle *v);
00064
00065 bool CanBuildVehicleInfrastructure(VehicleType type);
00066
00068 struct GetNewVehiclePosResult {
00069 int x, y;
00070 TileIndex old_tile;
00071 TileIndex new_tile;
00072 };
00073
00074 GetNewVehiclePosResult GetNewVehiclePos(const Vehicle *v);
00075 Direction GetDirectionTowards(const Vehicle *v, int x, int y);
00076
00077 static inline bool IsCompanyBuildableVehicleType(VehicleType type)
00078 {
00079 switch (type) {
00080 case VEH_TRAIN:
00081 case VEH_ROAD:
00082 case VEH_SHIP:
00083 case VEH_AIRCRAFT:
00084 return true;
00085
00086 default: return false;
00087 }
00088 }
00089
00090 static inline bool IsCompanyBuildableVehicleType(const BaseVehicle *v)
00091 {
00092 return IsCompanyBuildableVehicleType(v->type);
00093 }
00094
00095 const struct Livery *GetEngineLivery(EngineID engine_type, CompanyID company, EngineID parent_engine_type, const Vehicle *v, byte livery_setting);
00096
00103 SpriteID GetEnginePalette(EngineID engine_type, CompanyID company);
00104
00110 SpriteID GetVehiclePalette(const Vehicle *v);
00111
00112 uint GetVehicleCapacity(const Vehicle *v, uint16 *mail_capacity = NULL);
00113
00114 extern const uint32 _veh_build_proc_table[];
00115 extern const uint32 _veh_sell_proc_table[];
00116 extern const uint32 _veh_refit_proc_table[];
00117 extern const uint32 _send_to_depot_proc_table[];
00118
00119
00120 static inline uint32 GetCmdBuildVeh(VehicleType type)
00121 {
00122 return _veh_build_proc_table[type];
00123 }
00124
00125 static inline uint32 GetCmdBuildVeh(const BaseVehicle *v)
00126 {
00127 return GetCmdBuildVeh(v->type);
00128 }
00129
00130 static inline uint32 GetCmdSellVeh(VehicleType type)
00131 {
00132 return _veh_sell_proc_table[type];
00133 }
00134
00135 static inline uint32 GetCmdSellVeh(const BaseVehicle *v)
00136 {
00137 return GetCmdSellVeh(v->type);
00138 }
00139
00140 static inline uint32 GetCmdRefitVeh(VehicleType type)
00141 {
00142 return _veh_refit_proc_table[type];
00143 }
00144
00145 static inline uint32 GetCmdRefitVeh(const BaseVehicle *v)
00146 {
00147 return GetCmdRefitVeh(v->type);
00148 }
00149
00150 static inline uint32 GetCmdSendToDepot(VehicleType type)
00151 {
00152 return _send_to_depot_proc_table[type];
00153 }
00154
00155 static inline uint32 GetCmdSendToDepot(const BaseVehicle *v)
00156 {
00157 return GetCmdSendToDepot(v->type);
00158 }
00159
00160 bool EnsureNoVehicleOnGround(TileIndex tile);
00161 void StopAllVehicles();
00162
00163 extern VehicleID _vehicle_id_ctr_day;
00164 extern const Vehicle *_place_clicked_vehicle;
00165 extern VehicleID _new_vehicle_id;
00166 extern uint16 _returned_refit_capacity;
00167 extern byte _age_cargo_skip_counter;
00168
00169 bool CanVehicleUseStation(EngineID engine_type, const struct Station *st);
00170 bool CanVehicleUseStation(const Vehicle *v, const struct Station *st);
00171
00172 void ReleaseDisastersTargetingVehicle(VehicleID vehicle);
00173
00174 #endif