vehicle_func.h

Go to the documentation of this file.
00001 /* $Id: vehicle_func.h 18809 2010-01-15 16:41:15Z 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 "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 FindVehicleOnPos(TileIndex tile, void *data, VehicleFromPosProc *proc);
00033 void FindVehicleOnPosXY(int x, int y, void *data, VehicleFromPosProc *proc);
00034 bool HasVehicleOnPos(TileIndex tile, void *data, VehicleFromPosProc *proc);
00035 bool HasVehicleOnPosXY(int x, int y, void *data, VehicleFromPosProc *proc);
00036 void CallVehicleTicks();
00037 uint8 CalcPercentVehicleFilled(const Vehicle *v, StringID *colour);
00038 
00039 byte VehicleRandomBits();
00040 void ResetVehiclePosHash();
00041 void ResetVehicleColourMap();
00042 
00043 byte GetBestFittingSubType(Vehicle *v_from, Vehicle *v_for);
00044 CommandCost RefitVehicle(Vehicle *v, bool only_this, CargoID new_cid, byte new_subtype, DoCommandFlag flags);
00045 
00046 void ViewportAddVehicles(DrawPixelInfo *dpi);
00047 
00048 void ShowNewGrfVehicleError(EngineID engine, StringID part1, StringID part2, GRFBugs bug_type, bool critical);
00049 bool HasVehicleOnTunnelBridge(TileIndex tile, TileIndex endtile, const Vehicle *ignore = NULL);
00050 
00051 void DecreaseVehicleValue(Vehicle *v);
00052 void CheckVehicleBreakdown(Vehicle *v);
00053 void AgeVehicle(Vehicle *v);
00054 void VehicleEnteredDepotThisTick(Vehicle *v);
00055 
00056 void VehicleMove(Vehicle *v, bool update_viewport);
00057 void MarkSingleVehicleDirty(const Vehicle *v);
00058 
00059 UnitID GetFreeUnitNumber(VehicleType type);
00060 
00061 CommandCost SendAllVehiclesToDepot(VehicleType type, DoCommandFlag flags, bool service, Owner owner, uint16 vlw_flag, uint32 id);
00062 void VehicleEnterDepot(Vehicle *v);
00063 
00064 bool CanBuildVehicleInfrastructure(VehicleType type);
00065 
00067 struct GetNewVehiclePosResult {
00068   int x, y;  
00069   TileIndex old_tile; 
00070   TileIndex new_tile; 
00071 };
00072 
00073 GetNewVehiclePosResult GetNewVehiclePos(const Vehicle *v);
00074 Direction GetDirectionTowards(const Vehicle *v, int x, int y);
00075 
00076 static inline bool IsCompanyBuildableVehicleType(VehicleType type)
00077 {
00078   switch (type) {
00079     case VEH_TRAIN:
00080     case VEH_ROAD:
00081     case VEH_SHIP:
00082     case VEH_AIRCRAFT:
00083       return true;
00084 
00085     default: return false;
00086   }
00087 }
00088 
00089 static inline bool IsCompanyBuildableVehicleType(const BaseVehicle *v)
00090 {
00091   return IsCompanyBuildableVehicleType(v->type);
00092 }
00093 
00094 const struct Livery *GetEngineLivery(EngineID engine_type, CompanyID company, EngineID parent_engine_type, const Vehicle *v);
00095 
00102 SpriteID GetEnginePalette(EngineID engine_type, CompanyID company);
00103 
00109 SpriteID GetVehiclePalette(const Vehicle *v);
00110 
00111 uint GetVehicleCapacity(const Vehicle *v, uint16 *mail_capacity = NULL);
00112 
00113 extern const uint32 _veh_build_proc_table[];
00114 extern const uint32 _veh_sell_proc_table[];
00115 extern const uint32 _veh_refit_proc_table[];
00116 extern const uint32 _send_to_depot_proc_table[];
00117 
00118 /* Functions to find the right command for certain vehicle type */
00119 static inline uint32 GetCmdBuildVeh(VehicleType type)
00120 {
00121   return _veh_build_proc_table[type];
00122 }
00123 
00124 static inline uint32 GetCmdBuildVeh(const BaseVehicle *v)
00125 {
00126   return GetCmdBuildVeh(v->type);
00127 }
00128 
00129 static inline uint32 GetCmdSellVeh(VehicleType type)
00130 {
00131   return _veh_sell_proc_table[type];
00132 }
00133 
00134 static inline uint32 GetCmdSellVeh(const BaseVehicle *v)
00135 {
00136   return GetCmdSellVeh(v->type);
00137 }
00138 
00139 static inline uint32 GetCmdRefitVeh(VehicleType type)
00140 {
00141   return _veh_refit_proc_table[type];
00142 }
00143 
00144 static inline uint32 GetCmdRefitVeh(const BaseVehicle *v)
00145 {
00146   return GetCmdRefitVeh(v->type);
00147 }
00148 
00149 static inline uint32 GetCmdSendToDepot(VehicleType type)
00150 {
00151   return _send_to_depot_proc_table[type];
00152 }
00153 
00154 static inline uint32 GetCmdSendToDepot(const BaseVehicle *v)
00155 {
00156   return GetCmdSendToDepot(v->type);
00157 }
00158 
00159 bool EnsureNoVehicleOnGround(TileIndex tile);
00160 void StopAllVehicles();
00161 
00162 extern VehicleID _vehicle_id_ctr_day;
00163 extern const Vehicle *_place_clicked_vehicle;
00164 extern VehicleID _new_vehicle_id;
00165 extern uint16 _returned_refit_capacity;
00166 extern byte _age_cargo_skip_counter;
00167 
00168 bool CanVehicleUseStation(EngineID engine_type, const struct Station *st);
00169 bool CanVehicleUseStation(const Vehicle *v, const struct Station *st);
00170 
00171 void ReleaseDisastersTargetingVehicle(VehicleID vehicle);
00172 
00173 #endif /* VEHICLE_FUNC_H */

Generated on Sat Jun 5 21:52:12 2010 for OpenTTD by  doxygen 1.6.1