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