vehicle_func.h

00001 /* $Id: vehicle_func.h 14259 2008-09-07 11:54:00Z 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 
00016 #define is_custom_sprite(x) (x >= 0xFD)
00017 #define IS_CUSTOM_FIRSTHEAD_SPRITE(x) (x == 0xFD)
00018 #define IS_CUSTOM_SECONDHEAD_SPRITE(x) (x == 0xFE)
00019 
00020 typedef void *VehicleFromPosProc(Vehicle *v, void *data);
00021 
00022 void VehicleServiceInDepot(Vehicle *v);
00023 void VehiclePositionChanged(Vehicle *v);
00024 Vehicle *GetLastVehicleInChain(Vehicle *v);
00025 uint CountVehiclesInChain(const Vehicle *v);
00026 bool IsEngineCountable(const Vehicle *v);
00027 void DeleteVehicleChain(Vehicle *v);
00028 void FindVehicleOnPos(TileIndex tile, void *data, VehicleFromPosProc *proc);
00029 void FindVehicleOnPosXY(int x, int y, void *data, VehicleFromPosProc *proc);
00030 bool HasVehicleOnPos(TileIndex tile, void *data, VehicleFromPosProc *proc);
00031 bool HasVehicleOnPosXY(int x, int y, void *data, VehicleFromPosProc *proc);
00032 void CallVehicleTicks();
00033 uint8 CalcPercentVehicleFilled(Vehicle *v, StringID *color);
00034 
00035 void InitializeTrains();
00036 byte VehicleRandomBits();
00037 void ResetVehiclePosHash();
00038 void ResetVehicleColorMap();
00039 
00040 bool CanRefitTo(EngineID engine_type, CargoID cid_to);
00041 CargoID FindFirstRefittableCargo(EngineID engine_type);
00042 CommandCost GetRefitCost(EngineID engine_type);
00043 
00044 void ViewportAddVehicles(DrawPixelInfo *dpi);
00045 
00046 SpriteID GetRotorImage(const Vehicle *v);
00047 
00048 uint32 VehicleEnterTile(Vehicle *v, TileIndex tile, int x, int y);
00049 
00050 StringID VehicleInTheWayErrMsg(const Vehicle* v);
00051 bool HasVehicleOnTunnelBridge(TileIndex tile, TileIndex endtile);
00052 
00053 Vehicle *CheckClickOnVehicle(const ViewPort *vp, int x, int y);
00054 
00055 void DecreaseVehicleValue(Vehicle *v);
00056 void CheckVehicleBreakdown(Vehicle *v);
00057 void AgeVehicle(Vehicle *v);
00058 void VehicleEnteredDepotThisTick(Vehicle *v);
00059 
00060 void BeginVehicleMove(const Vehicle *v);
00061 void EndVehicleMove(const Vehicle *v);
00062 void MarkSingleVehicleDirty(const Vehicle *v);
00063 
00064 UnitID GetFreeUnitNumber(VehicleType type);
00065 
00066 void TrainConsistChanged(Vehicle *v, bool same_length);
00067 void TrainPowerChanged(Vehicle *v);
00068 Money GetTrainRunningCost(const Vehicle *v);
00069 
00070 uint GenerateVehicleSortList(const Vehicle*** sort_list, uint16 *length_of_array, VehicleType type, PlayerID owner, uint32 index, uint16 window_type);
00071 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);
00072 CommandCost SendAllVehiclesToDepot(VehicleType type, uint32 flags, bool service, PlayerID owner, uint16 vlw_flag, uint32 id);
00073 void VehicleEnterDepot(Vehicle *v);
00074 
00075 CommandCost MaybeReplaceVehicle(Vehicle *v, bool check, bool display_costs);
00076 bool CanBuildVehicleInfrastructure(VehicleType type);
00077 
00078 void CcCloneVehicle(bool success, TileIndex tile, uint32 p1, uint32 p2);
00079 
00080 /* Flags to add to p2 for goto depot commands */
00081 /* Note: bits 8-10 are used for VLW flags */
00082 enum {
00083   DEPOT_SERVICE       = (1 << 0), // The vehicle will leave the depot right after arrival (serivce only)
00084   DEPOT_MASS_SEND     = (1 << 1), // Tells that it's a mass send to depot command (type in VLW flag)
00085   DEPOT_DONT_CANCEL   = (1 << 2), // Don't cancel current goto depot command if any
00086   DEPOT_LOCATE_HANGAR = (1 << 3), // Find another airport if the target one lacks a hangar
00087 };
00088 
00089 struct GetNewVehiclePosResult {
00090   int x, y;
00091   TileIndex old_tile;
00092   TileIndex new_tile;
00093 };
00094 
00095 /* returns true if staying in the same tile */
00096 GetNewVehiclePosResult GetNewVehiclePos(const Vehicle *v);
00097 Direction GetDirectionTowards(const Vehicle *v, int x, int y);
00098 
00099 static inline bool IsPlayerBuildableVehicleType(VehicleType type)
00100 {
00101   switch (type) {
00102     case VEH_TRAIN:
00103     case VEH_ROAD:
00104     case VEH_SHIP:
00105     case VEH_AIRCRAFT:
00106       return true;
00107 
00108     default: return false;
00109   }
00110 }
00111 
00112 static inline bool IsPlayerBuildableVehicleType(const BaseVehicle *v)
00113 {
00114   return IsPlayerBuildableVehicleType(v->type);
00115 }
00116 
00117 const struct Livery *GetEngineLivery(EngineID engine_type, PlayerID player, EngineID parent_engine_type, const Vehicle *v);
00118 
00125 SpriteID GetEnginePalette(EngineID engine_type, PlayerID player);
00126 
00132 SpriteID GetVehiclePalette(const Vehicle *v);
00133 
00134 extern const uint32 _veh_build_proc_table[];
00135 extern const uint32 _veh_sell_proc_table[];
00136 extern const uint32 _veh_refit_proc_table[];
00137 extern const uint32 _send_to_depot_proc_table[];
00138 
00139 /* Functions to find the right command for certain vehicle type */
00140 static inline uint32 GetCmdBuildVeh(VehicleType type)
00141 {
00142   return _veh_build_proc_table[type];
00143 }
00144 
00145 static inline uint32 GetCmdBuildVeh(const BaseVehicle *v)
00146 {
00147   return GetCmdBuildVeh(v->type);
00148 }
00149 
00150 static inline uint32 GetCmdSellVeh(VehicleType type)
00151 {
00152   return _veh_sell_proc_table[type];
00153 }
00154 
00155 static inline uint32 GetCmdSellVeh(const BaseVehicle *v)
00156 {
00157   return GetCmdSellVeh(v->type);
00158 }
00159 
00160 static inline uint32 GetCmdRefitVeh(VehicleType type)
00161 {
00162   return _veh_refit_proc_table[type];
00163 }
00164 
00165 static inline uint32 GetCmdRefitVeh(const BaseVehicle *v)
00166 {
00167   return GetCmdRefitVeh(v->type);
00168 }
00169 
00170 static inline uint32 GetCmdSendToDepot(VehicleType type)
00171 {
00172   return _send_to_depot_proc_table[type];
00173 }
00174 
00175 static inline uint32 GetCmdSendToDepot(const BaseVehicle *v)
00176 {
00177   return GetCmdSendToDepot(v->type);
00178 }
00179 
00180 bool EnsureNoVehicleOnGround(TileIndex tile);
00181 void StopAllVehicles();
00182 
00183 Vehicle *CreateEffectVehicle(int x, int y, int z, EffectVehicle type);
00184 Vehicle *CreateEffectVehicleAbove(int x, int y, int z, EffectVehicle type);
00185 Vehicle *CreateEffectVehicleRel(const Vehicle *v, int x, int y, int z, EffectVehicle type);
00186 
00187 extern VehicleID _vehicle_id_ctr_day;
00188 extern Vehicle *_place_clicked_vehicle;
00189 extern VehicleID _new_vehicle_id;
00190 extern uint16 _returned_refit_capacity;
00191 
00192 #endif /* VEHICLE_H */

Generated on Wed Oct 1 17:03:25 2008 for openttd by  doxygen 1.5.6