# vehicle_func.h

Go to the documentation of this file.

    00001 /* $Id: vehicle_func.h 18498 2009-12-14 19:17:18Z rubidium $ */
    00002
    00003 /*
    00004  * This file is part of OpenTTD.
    00005  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
    00006  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    00007  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
    00008  */
    00009
    00012 #ifndef VEHICLE_FUNC_H
    00013 #define VEHICLE_FUNC_H
    00014
    00015 #include "tile_type.h"
    00016 #include "strings_type.h"
    00017 #include "gfx_type.h"
    00018 #include "direction_type.h"
    00019 #include "cargo_type.h"
    00020 #include "command_type.h"
    00021 #include "vehicle_type.h"
    00022 #include "engine_type.h"
    00023 #include "transport_type.h"
    00024 #include "newgrf_config.h"
    00025
    00026 #define is_custom_sprite(x) (x >= 0xFD)
    00027 #define IS_CUSTOM_FIRSTHEAD_SPRITE(x) (x == 0xFD)
    00028 #define IS_CUSTOM_SECONDHEAD_SPRITE(x) (x == 0xFE)
    00029
    00030 typedef Vehicle *VehicleFromPosProc(Vehicle *v, void *data);
    00031
    00032 void VehicleServiceInDepot(Vehicle *v);
    00033 uint CountVehiclesInChain(const Vehicle *v);
    00034 void FindVehicleOnPos(TileIndex tile, void *data, VehicleFromPosProc *proc);
    00035 void FindVehicleOnPosXY(int x, int y, void *data, VehicleFromPosProc *proc);
    00036 bool HasVehicleOnPos(TileIndex tile, void *data, VehicleFromPosProc *proc);
    00037 bool HasVehicleOnPosXY(int x, int y, void *data, VehicleFromPosProc *proc);
    00038 void CallVehicleTicks();
    00039 uint8 CalcPercentVehicleFilled(const Vehicle *v, StringID *colour);
    00040
    00041 byte VehicleRandomBits();
    00042 void ResetVehiclePosHash();
    00043 void ResetVehicleColourMap();
    00044
    00045 byte GetBestFittingSubType(Vehicle *v_from, Vehicle *v_for);
    00046 CommandCost RefitVehicle(Vehicle *v, bool only_this, CargoID new_cid, byte new_subtype, DoCommandFlag flags);
    00047
    00048 void ViewportAddVehicles(DrawPixelInfo *dpi);
    00049
    00050 void ShowNewGrfVehicleError(EngineID engine, StringID part1, StringID part2, GRFBugs bug_type, bool critical);
    00051 bool HasVehicleOnTunnelBridge(TileIndex tile, TileIndex endtile, const Vehicle *ignore = NULL);
    00052
    00053 void DecreaseVehicleValue(Vehicle *v);
    00054 void CheckVehicleBreakdown(Vehicle *v);
    00055 void AgeVehicle(Vehicle *v);
    00056 void VehicleEnteredDepotThisTick(Vehicle *v);
    00057
    00058 void VehicleMove(Vehicle *v, bool update_viewport);
    00059 void MarkSingleVehicleDirty(const Vehicle *v);
    00060
    00061 UnitID GetFreeUnitNumber(VehicleType type);
    00062
    00063 CommandCost SendAllVehiclesToDepot(VehicleType type, DoCommandFlag flags, bool service, Owner owner, uint16 vlw_flag, uint32 id);
    00064 void VehicleEnterDepot(Vehicle *v);
    00065
    00066 bool CanBuildVehicleInfrastructure(VehicleType type);
    00067
    00068 void CcCloneVehicle(bool success, TileIndex tile, uint32 p1, uint32 p2);
    00069
    00071 struct GetNewVehiclePosResult {
    00072   int x, y;
    00073   TileIndex old_tile;
    00074   TileIndex new_tile;
    00075 };
    00076
    00077 GetNewVehiclePosResult GetNewVehiclePos(const Vehicle *v);
    00078 Direction GetDirectionTowards(const Vehicle *v, int x, int y);
    00079
    00080 static inline bool IsCompanyBuildableVehicleType(VehicleType type)
    00081 {
    00082   switch (type) {
    00083     case VEH_TRAIN:
    00084     case VEH_ROAD:
    00085     case VEH_SHIP:
    00086     case VEH_AIRCRAFT:
    00087       return true;
    00088
    00089     default: return false;
    00090   }
    00091 }
    00092
    00093 static inline bool IsCompanyBuildableVehicleType(const BaseVehicle *v)
    00094 {
    00095   return IsCompanyBuildableVehicleType(v->type);
    00096 }
    00097
    00098 const struct Livery *GetEngineLivery(EngineID engine_type, CompanyID company, EngineID parent_engine_type, const Vehicle *v);
    00099
    00106 SpriteID GetEnginePalette(EngineID engine_type, CompanyID company);
    00107
    00113 SpriteID GetVehiclePalette(const Vehicle *v);
    00114
    00115 uint GetVehicleCapacity(const Vehicle *v, uint16 *mail_capacity = NULL);
    00116
    00117 extern const uint32 _veh_build_proc_table[];
    00118 extern const uint32 _veh_sell_proc_table[];
    00119 extern const uint32 _veh_refit_proc_table[];
    00120 extern const uint32 _send_to_depot_proc_table[];
    00121
    00122 /* Functions to find the right command for certain vehicle type */
    00123 static inline uint32 GetCmdBuildVeh(VehicleType type)
    00124 {
    00125   return _veh_build_proc_table[type];
    00126 }
    00127
    00128 static inline uint32 GetCmdBuildVeh(const BaseVehicle *v)
    00129 {
    00130   return GetCmdBuildVeh(v->type);
    00131 }
    00132
    00133 static inline uint32 GetCmdSellVeh(VehicleType type)
    00134 {
    00135   return _veh_sell_proc_table[type];
    00136 }
    00137
    00138 static inline uint32 GetCmdSellVeh(const BaseVehicle *v)
    00139 {
    00140   return GetCmdSellVeh(v->type);
    00141 }
    00142
    00143 static inline uint32 GetCmdRefitVeh(VehicleType type)
    00144 {
    00145   return _veh_refit_proc_table[type];
    00146 }
    00147
    00148 static inline uint32 GetCmdRefitVeh(const BaseVehicle *v)
    00149 {
    00150   return GetCmdRefitVeh(v->type);
    00151 }
    00152
    00153 static inline uint32 GetCmdSendToDepot(VehicleType type)
    00154 {
    00155   return _send_to_depot_proc_table[type];
    00156 }
    00157
    00158 static inline uint32 GetCmdSendToDepot(const BaseVehicle *v)
    00159 {
    00160   return GetCmdSendToDepot(v->type);
    00161 }
    00162
    00163 bool EnsureNoVehicleOnGround(TileIndex tile);
    00164 void StopAllVehicles();
    00165
    00166 extern VehicleID _vehicle_id_ctr_day;
    00167 extern const Vehicle *_place_clicked_vehicle;
    00168 extern VehicleID _new_vehicle_id;
    00169 extern uint16 _returned_refit_capacity;
    00170 extern byte _age_cargo_skip_counter;
    00171
    00172 bool CanVehicleUseStation(EngineID engine_type, const struct Station *st);
    00173 bool CanVehicleUseStation(const Vehicle *v, const struct Station *st);
    00174
    00175 void ReleaseDisastersTargetingVehicle(VehicleID vehicle);
    00176
    00177 #endif /* VEHICLE_FUNC_H */