# vehicle_func.h

Go to the documentation of this file.

    00001 /* $Id: vehicle_func.h 16539 2009-06-08 22:53:39Z rubidium $ */
    00002
    00005 #ifndef VEHICLE_FUNC_H
    00006 #define VEHICLE_FUNC_H
    00007
    00008 #include "tile_type.h"
    00009 #include "strings_type.h"
    00010 #include "gfx_type.h"
    00011 #include "direction_type.h"
    00012 #include "cargo_type.h"
    00013 #include "command_type.h"
    00014 #include "vehicle_type.h"
    00015 #include "engine_type.h"
    00016 #include "transport_type.h"
    00017 #include "newgrf_config.h"
    00018
    00019 #define is_custom_sprite(x) (x >= 0xFD)
    00020 #define IS_CUSTOM_FIRSTHEAD_SPRITE(x) (x == 0xFD)
    00021 #define IS_CUSTOM_SECONDHEAD_SPRITE(x) (x == 0xFE)
    00022
    00023 typedef Vehicle *VehicleFromPosProc(Vehicle *v, void *data);
    00024
    00025 void VehicleServiceInDepot(Vehicle *v);
    00026 Vehicle *GetLastVehicleInChain(Vehicle *v);
    00027 const Vehicle *GetLastVehicleInChain(const Vehicle *v);
    00028 uint CountVehiclesInChain(const Vehicle *v);
    00029 bool IsEngineCountable(const Vehicle *v);
    00030 void FindVehicleOnPos(TileIndex tile, void *data, VehicleFromPosProc *proc);
    00031 void FindVehicleOnPosXY(int x, int y, void *data, VehicleFromPosProc *proc);
    00032 bool HasVehicleOnPos(TileIndex tile, void *data, VehicleFromPosProc *proc);
    00033 bool HasVehicleOnPosXY(int x, int y, void *data, VehicleFromPosProc *proc);
    00034 void CallVehicleTicks();
    00035 uint8 CalcPercentVehicleFilled(const Vehicle *v, StringID *colour);
    00036
    00037 void InitializeTrains();
    00038 byte VehicleRandomBits();
    00039 void ResetVehiclePosHash();
    00040 void ResetVehicleColourMap();
    00041
    00042 bool CanRefitTo(EngineID engine_type, CargoID cid_to);
    00043 CargoID FindFirstRefittableCargo(EngineID engine_type);
    00044 CommandCost GetRefitCost(EngineID engine_type);
    00045
    00046 void ViewportAddVehicles(DrawPixelInfo *dpi);
    00047
    00048 SpriteID GetRotorImage(const Vehicle *v);
    00049
    00050 void ShowNewGrfVehicleError(EngineID engine, StringID part1, StringID part2, GRFBugs bug_type, bool critical);
    00051 StringID VehicleInTheWayErrMsg(const Vehicle *v);
    00052 bool HasVehicleOnTunnelBridge(TileIndex tile, TileIndex endtile, const Vehicle *ignore = NULL);
    00053
    00054 void DecreaseVehicleValue(Vehicle *v);
    00055 void CheckVehicleBreakdown(Vehicle *v);
    00056 void AgeVehicle(Vehicle *v);
    00057 void VehicleEnteredDepotThisTick(Vehicle *v);
    00058
    00059 void VehicleMove(Vehicle *v, bool update_viewport);
    00060 void MarkSingleVehicleDirty(const Vehicle *v);
    00061
    00062 UnitID GetFreeUnitNumber(VehicleType type);
    00063
    00064 void TrainConsistChanged(Vehicle *v, bool same_length);
    00065 void TrainPowerChanged(Vehicle *v);
    00066 Money GetTrainRunningCost(const Vehicle *v);
    00067
    00068 CommandCost SendAllVehiclesToDepot(VehicleType type, DoCommandFlag flags, bool service, Owner owner, uint16 vlw_flag, uint32 id);
    00069 void VehicleEnterDepot(Vehicle *v);
    00070
    00071 bool CanBuildVehicleInfrastructure(VehicleType type);
    00072
    00073 void CcCloneVehicle(bool success, TileIndex tile, uint32 p1, uint32 p2);
    00074
    00076 struct GetNewVehiclePosResult {
    00077   int x, y;
    00078   TileIndex old_tile;
    00079   TileIndex new_tile;
    00080 };
    00081
    00082 GetNewVehiclePosResult GetNewVehiclePos(const Vehicle *v);
    00083 Direction GetDirectionTowards(const Vehicle *v, int x, int y);
    00084
    00085 static inline bool IsCompanyBuildableVehicleType(VehicleType type)
    00086 {
    00087   switch (type) {
    00088     case VEH_TRAIN:
    00089     case VEH_ROAD:
    00090     case VEH_SHIP:
    00091     case VEH_AIRCRAFT:
    00092       return true;
    00093
    00094     default: return false;
    00095   }
    00096 }
    00097
    00098 static inline bool IsCompanyBuildableVehicleType(const BaseVehicle *v)
    00099 {
    00100   return IsCompanyBuildableVehicleType(v->type);
    00101 }
    00102
    00103 const struct Livery *GetEngineLivery(EngineID engine_type, CompanyID company, EngineID parent_engine_type, const Vehicle *v);
    00104
    00111 SpriteID GetEnginePalette(EngineID engine_type, CompanyID company);
    00112
    00118 SpriteID GetVehiclePalette(const Vehicle *v);
    00119
    00120 extern const uint32 _veh_build_proc_table[];
    00121 extern const uint32 _veh_sell_proc_table[];
    00122 extern const uint32 _veh_refit_proc_table[];
    00123 extern const uint32 _send_to_depot_proc_table[];
    00124
    00125 /* Functions to find the right command for certain vehicle type */
    00126 static inline uint32 GetCmdBuildVeh(VehicleType type)
    00127 {
    00128   return _veh_build_proc_table[type];
    00129 }
    00130
    00131 static inline uint32 GetCmdBuildVeh(const BaseVehicle *v)
    00132 {
    00133   return GetCmdBuildVeh(v->type);
    00134 }
    00135
    00136 static inline uint32 GetCmdSellVeh(VehicleType type)
    00137 {
    00138   return _veh_sell_proc_table[type];
    00139 }
    00140
    00141 static inline uint32 GetCmdSellVeh(const BaseVehicle *v)
    00142 {
    00143   return GetCmdSellVeh(v->type);
    00144 }
    00145
    00146 static inline uint32 GetCmdRefitVeh(VehicleType type)
    00147 {
    00148   return _veh_refit_proc_table[type];
    00149 }
    00150
    00151 static inline uint32 GetCmdRefitVeh(const BaseVehicle *v)
    00152 {
    00153   return GetCmdRefitVeh(v->type);
    00154 }
    00155
    00156 static inline uint32 GetCmdSendToDepot(VehicleType type)
    00157 {
    00158   return _send_to_depot_proc_table[type];
    00159 }
    00160
    00161 static inline uint32 GetCmdSendToDepot(const BaseVehicle *v)
    00162 {
    00163   return GetCmdSendToDepot(v->type);
    00164 }
    00165
    00166 bool EnsureNoVehicleOnGround(TileIndex tile);
    00167 void StopAllVehicles();
    00168
    00169 extern VehicleID _vehicle_id_ctr_day;
    00170 extern const Vehicle *_place_clicked_vehicle;
    00171 extern VehicleID _new_vehicle_id;
    00172 extern uint16 _returned_refit_capacity;
    00173
    00174 bool CanVehicleUseStation(EngineID engine_type, const struct Station *st);
    00175 bool CanVehicleUseStation(const Vehicle *v, const struct Station *st);
    00176
    00177 void ReleaseDisastersTargetingVehicle(VehicleID vehicle);
    00178
    00179 #endif /* VEHICLE_FUNC_H */