# vehicle_func.h

Go to the documentation of this file.

    00001 /* $Id$ */
    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 "track_type.h"
    00023 #include "livery.h"
    00024
    00025 #define is_custom_sprite(x) (x >= 0xFD)
    00026 #define IS_CUSTOM_FIRSTHEAD_SPRITE(x) (x == 0xFD)
    00027 #define IS_CUSTOM_SECONDHEAD_SPRITE(x) (x == 0xFE)
    00028
    00029 typedef Vehicle *VehicleFromPosProc(Vehicle *v, void *data);
    00030
    00031 void VehicleServiceInDepot(Vehicle *v);
    00032 uint CountVehiclesInChain(const Vehicle *v);
    00033 void CountCompanyVehicles(CompanyID cid, uint counts[4]);
    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
    00047 void ViewportAddVehicles(DrawPixelInfo *dpi);
    00048
    00049 void ShowNewGrfVehicleError(EngineID engine, StringID part1, StringID part2, GRFBugs bug_type, bool critical);
    00050 CommandCost TunnelBridgeIsFree(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 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
    00081 static inline bool IsCompanyBuildableVehicleType(VehicleType type)
    00082 {
    00083   switch (type) {
    00084     case VEH_TRAIN:
    00085     case VEH_ROAD:
    00086     case VEH_SHIP:
    00087     case VEH_AIRCRAFT:
    00088       return true;
    00089
    00090     default: return false;
    00091   }
    00092 }
    00093
    00099 static inline bool IsCompanyBuildableVehicleType(const BaseVehicle *v)
    00100 {
    00101   return IsCompanyBuildableVehicleType(v->type);
    00102 }
    00103
    00104 LiveryScheme GetEngineLiveryScheme(EngineID engine_type, EngineID parent_engine_type, const Vehicle *v);
    00105 const struct Livery *GetEngineLivery(EngineID engine_type, CompanyID company, EngineID parent_engine_type, const Vehicle *v, byte livery_setting);
    00106
    00107 SpriteID GetEnginePalette(EngineID engine_type, CompanyID company);
    00108 SpriteID GetVehiclePalette(const Vehicle *v);
    00109
    00110 uint GetVehicleCapacity(const Vehicle *v, uint16 *mail_capacity = NULL);
    00111
    00112 extern const uint32 _veh_build_proc_table[];
    00113 extern const uint32 _veh_sell_proc_table[];
    00114 extern const uint32 _veh_refit_proc_table[];
    00115 extern const uint32 _send_to_depot_proc_table[];
    00116
    00117 /* Functions to find the right command for certain vehicle type */
    00118 static inline uint32 GetCmdBuildVeh(VehicleType type)
    00119 {
    00120   return _veh_build_proc_table[type];
    00121 }
    00122
    00123 static inline uint32 GetCmdBuildVeh(const BaseVehicle *v)
    00124 {
    00125   return GetCmdBuildVeh(v->type);
    00126 }
    00127
    00128 static inline uint32 GetCmdSellVeh(VehicleType type)
    00129 {
    00130   return _veh_sell_proc_table[type];
    00131 }
    00132
    00133 static inline uint32 GetCmdSellVeh(const BaseVehicle *v)
    00134 {
    00135   return GetCmdSellVeh(v->type);
    00136 }
    00137
    00138 static inline uint32 GetCmdRefitVeh(VehicleType type)
    00139 {
    00140   return _veh_refit_proc_table[type];
    00141 }
    00142
    00143 static inline uint32 GetCmdRefitVeh(const BaseVehicle *v)
    00144 {
    00145   return GetCmdRefitVeh(v->type);
    00146 }
    00147
    00148 static inline uint32 GetCmdSendToDepot(VehicleType type)
    00149 {
    00150   return _send_to_depot_proc_table[type];
    00151 }
    00152
    00153 static inline uint32 GetCmdSendToDepot(const BaseVehicle *v)
    00154 {
    00155   return GetCmdSendToDepot(v->type);
    00156 }
    00157
    00158 CommandCost EnsureNoVehicleOnGround(TileIndex tile);
    00159 CommandCost EnsureNoTrainOnTrackBits(TileIndex tile, TrackBits track_bits);
    00160
    00161 extern VehicleID _new_vehicle_id;
    00162 extern uint16 _returned_refit_capacity;
    00163 extern uint16 _returned_mail_refit_capacity;
    00164 extern byte _age_cargo_skip_counter;
    00165
    00166 bool CanVehicleUseStation(EngineID engine_type, const struct Station *st);
    00167 bool CanVehicleUseStation(const Vehicle *v, const struct Station *st);
    00168
    00169 void ReleaseDisastersTargetingVehicle(VehicleID vehicle);
    00170
    00171 typedef SmallVector<VehicleID, 2> VehicleSet;
    00172 void GetVehicleSet(VehicleSet &set, Vehicle *v, uint8 num_vehicles);
    00173
    00174 #endif /* VEHICLE_FUNC_H */