# vehicle_func.h

Go to the documentation of this file.

    00001 /* $Id: vehicle_func.h 26130 2013-11-26 16:08:58Z 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 "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 static const int VEHICLE_PROFIT_MIN_AGE = DAYS_IN_YEAR * 2;
    00030 static const Money VEHICLE_PROFIT_THRESHOLD = 10000;
    00031
    00038 template <VehicleType T>
    00039 bool IsValidImageIndex(uint8 image_index);
    00040
    00041 typedef Vehicle *VehicleFromPosProc(Vehicle *v, void *data);
    00042
    00043 void VehicleServiceInDepot(Vehicle *v);
    00044 uint CountVehiclesInChain(const Vehicle *v);
    00045 void FindVehicleOnPos(TileIndex tile, void *data, VehicleFromPosProc *proc);
    00046 void FindVehicleOnPosXY(int x, int y, void *data, VehicleFromPosProc *proc);
    00047 bool HasVehicleOnPos(TileIndex tile, void *data, VehicleFromPosProc *proc);
    00048 bool HasVehicleOnPosXY(int x, int y, void *data, VehicleFromPosProc *proc);
    00049 void CallVehicleTicks();
    00050 uint8 CalcPercentVehicleFilled(const Vehicle *v, StringID *colour);
    00051
    00052 void VehicleLengthChanged(const Vehicle *u);
    00053
    00054 byte VehicleRandomBits();
    00055 void ResetVehicleHash();
    00056 void ResetVehicleColourMap();
    00057
    00058 byte GetBestFittingSubType(Vehicle *v_from, Vehicle *v_for, CargoID dest_cargo_type);
    00059
    00060 void ViewportAddVehicles(DrawPixelInfo *dpi);
    00061
    00062 void ShowNewGrfVehicleError(EngineID engine, StringID part1, StringID part2, GRFBugs bug_type, bool critical);
    00063 CommandCost TunnelBridgeIsFree(TileIndex tile, TileIndex endtile, const Vehicle *ignore = NULL);
    00064
    00065 void DecreaseVehicleValue(Vehicle *v);
    00066 void CheckVehicleBreakdown(Vehicle *v);
    00067 void AgeVehicle(Vehicle *v);
    00068 void VehicleEnteredDepotThisTick(Vehicle *v);
    00069
    00070 void VehicleUpdatePosition(Vehicle *v);
    00071 void VehicleUpdateViewport(Vehicle *v, bool dirty);
    00072 void VehicleUpdatePositionAndViewport(Vehicle *v);
    00073 void MarkSingleVehicleDirty(const Vehicle *v);
    00074
    00075 UnitID GetFreeUnitNumber(VehicleType type);
    00076
    00077 void VehicleEnterDepot(Vehicle *v);
    00078
    00079 bool CanBuildVehicleInfrastructure(VehicleType type);
    00080
    00082 struct GetNewVehiclePosResult {
    00083   int x, y;
    00084   TileIndex old_tile;
    00085   TileIndex new_tile;
    00086 };
    00087
    00088 GetNewVehiclePosResult GetNewVehiclePos(const Vehicle *v);
    00089 Direction GetDirectionTowards(const Vehicle *v, int x, int y);
    00090
    00096 static inline bool IsCompanyBuildableVehicleType(VehicleType type)
    00097 {
    00098   switch (type) {
    00099     case VEH_TRAIN:
    00100     case VEH_ROAD:
    00101     case VEH_SHIP:
    00102     case VEH_AIRCRAFT:
    00103       return true;
    00104
    00105     default: return false;
    00106   }
    00107 }
    00108
    00114 static inline bool IsCompanyBuildableVehicleType(const BaseVehicle *v)
    00115 {
    00116   return IsCompanyBuildableVehicleType(v->type);
    00117 }
    00118
    00119 LiveryScheme GetEngineLiveryScheme(EngineID engine_type, EngineID parent_engine_type, const Vehicle *v);
    00120 const struct Livery *GetEngineLivery(EngineID engine_type, CompanyID company, EngineID parent_engine_type, const Vehicle *v, byte livery_setting);
    00121
    00122 SpriteID GetEnginePalette(EngineID engine_type, CompanyID company);
    00123 SpriteID GetVehiclePalette(const Vehicle *v);
    00124
    00125 extern const uint32 _veh_build_proc_table[];
    00126 extern const uint32 _veh_sell_proc_table[];
    00127 extern const uint32 _veh_refit_proc_table[];
    00128 extern const uint32 _send_to_depot_proc_table[];
    00129
    00130 /* Functions to find the right command for certain vehicle type */
    00131 static inline uint32 GetCmdBuildVeh(VehicleType type)
    00132 {
    00133   return _veh_build_proc_table[type];
    00134 }
    00135
    00136 static inline uint32 GetCmdBuildVeh(const BaseVehicle *v)
    00137 {
    00138   return GetCmdBuildVeh(v->type);
    00139 }
    00140
    00141 static inline uint32 GetCmdSellVeh(VehicleType type)
    00142 {
    00143   return _veh_sell_proc_table[type];
    00144 }
    00145
    00146 static inline uint32 GetCmdSellVeh(const BaseVehicle *v)
    00147 {
    00148   return GetCmdSellVeh(v->type);
    00149 }
    00150
    00151 static inline uint32 GetCmdRefitVeh(VehicleType type)
    00152 {
    00153   return _veh_refit_proc_table[type];
    00154 }
    00155
    00156 static inline uint32 GetCmdRefitVeh(const BaseVehicle *v)
    00157 {
    00158   return GetCmdRefitVeh(v->type);
    00159 }
    00160
    00161 static inline uint32 GetCmdSendToDepot(VehicleType type)
    00162 {
    00163   return _send_to_depot_proc_table[type];
    00164 }
    00165
    00166 static inline uint32 GetCmdSendToDepot(const BaseVehicle *v)
    00167 {
    00168   return GetCmdSendToDepot(v->type);
    00169 }
    00170
    00171 CommandCost EnsureNoVehicleOnGround(TileIndex tile);
    00172 CommandCost EnsureNoTrainOnTrackBits(TileIndex tile, TrackBits track_bits);
    00173
    00174 extern VehicleID _new_vehicle_id;
    00175 extern uint16 _returned_refit_capacity;
    00176 extern uint16 _returned_mail_refit_capacity;
    00177
    00178 bool CanVehicleUseStation(EngineID engine_type, const struct Station *st);
    00179 bool CanVehicleUseStation(const Vehicle *v, const struct Station *st);
    00180
    00181 void ReleaseDisastersTargetingVehicle(VehicleID vehicle);
    00182
    00183 typedef SmallVector<VehicleID, 2> VehicleSet;
    00184 void GetVehicleSet(VehicleSet &set, Vehicle *v, uint8 num_vehicles);
    00185
    00186 void CheckCargoCapacity(Vehicle *v);
    00187
    00188 #endif /* VEHICLE_FUNC_H */