2007-12-27 13:35:39 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2008-05-06 15:11:33 +00:00
|
|
|
/** @file vehicle_func.h Functions related to vehicles. */
|
2007-12-27 13:35:39 +00:00
|
|
|
|
|
|
|
#ifndef VEHICLE_FUNC_H
|
|
|
|
#define VEHICLE_FUNC_H
|
|
|
|
|
|
|
|
#include "tile_type.h"
|
|
|
|
#include "strings_type.h"
|
|
|
|
#include "gfx_type.h"
|
|
|
|
#include "direction_type.h"
|
|
|
|
#include "cargo_type.h"
|
|
|
|
#include "command_type.h"
|
|
|
|
#include "vehicle_type.h"
|
2008-03-28 18:00:38 +00:00
|
|
|
#include "engine_type.h"
|
2008-05-07 09:07:19 +00:00
|
|
|
#include "transport_type.h"
|
2009-03-13 21:28:40 +00:00
|
|
|
#include "newgrf_config.h"
|
2007-12-27 13:35:39 +00:00
|
|
|
|
|
|
|
#define is_custom_sprite(x) (x >= 0xFD)
|
|
|
|
#define IS_CUSTOM_FIRSTHEAD_SPRITE(x) (x == 0xFD)
|
|
|
|
#define IS_CUSTOM_SECONDHEAD_SPRITE(x) (x == 0xFE)
|
|
|
|
|
2008-08-01 15:07:31 +00:00
|
|
|
typedef Vehicle *VehicleFromPosProc(Vehicle *v, void *data);
|
2007-12-27 13:35:39 +00:00
|
|
|
|
|
|
|
void VehicleServiceInDepot(Vehicle *v);
|
|
|
|
Vehicle *GetLastVehicleInChain(Vehicle *v);
|
2008-05-25 09:40:44 +00:00
|
|
|
const Vehicle *GetLastVehicleInChain(const Vehicle *v);
|
2007-12-27 13:35:39 +00:00
|
|
|
uint CountVehiclesInChain(const Vehicle *v);
|
|
|
|
bool IsEngineCountable(const Vehicle *v);
|
2008-09-07 11:23:10 +00:00
|
|
|
void FindVehicleOnPos(TileIndex tile, void *data, VehicleFromPosProc *proc);
|
|
|
|
void FindVehicleOnPosXY(int x, int y, void *data, VehicleFromPosProc *proc);
|
|
|
|
bool HasVehicleOnPos(TileIndex tile, void *data, VehicleFromPosProc *proc);
|
|
|
|
bool HasVehicleOnPosXY(int x, int y, void *data, VehicleFromPosProc *proc);
|
2007-12-27 13:35:39 +00:00
|
|
|
void CallVehicleTicks();
|
2009-02-09 02:57:15 +00:00
|
|
|
uint8 CalcPercentVehicleFilled(const Vehicle *v, StringID *colour);
|
2007-12-27 13:35:39 +00:00
|
|
|
|
|
|
|
void InitializeTrains();
|
|
|
|
byte VehicleRandomBits();
|
|
|
|
void ResetVehiclePosHash();
|
2009-02-09 02:57:15 +00:00
|
|
|
void ResetVehicleColourMap();
|
2007-12-27 13:35:39 +00:00
|
|
|
|
|
|
|
bool CanRefitTo(EngineID engine_type, CargoID cid_to);
|
|
|
|
CargoID FindFirstRefittableCargo(EngineID engine_type);
|
|
|
|
CommandCost GetRefitCost(EngineID engine_type);
|
|
|
|
|
|
|
|
void ViewportAddVehicles(DrawPixelInfo *dpi);
|
|
|
|
|
2009-03-13 21:28:40 +00:00
|
|
|
void ShowNewGrfVehicleError(EngineID engine, StringID part1, StringID part2, GRFBugs bug_type, bool critical);
|
2009-01-10 00:31:47 +00:00
|
|
|
StringID VehicleInTheWayErrMsg(const Vehicle *v);
|
2008-09-09 19:02:47 +00:00
|
|
|
bool HasVehicleOnTunnelBridge(TileIndex tile, TileIndex endtile, const Vehicle *ignore = NULL);
|
2007-12-27 13:35:39 +00:00
|
|
|
|
|
|
|
void DecreaseVehicleValue(Vehicle *v);
|
|
|
|
void CheckVehicleBreakdown(Vehicle *v);
|
|
|
|
void AgeVehicle(Vehicle *v);
|
|
|
|
void VehicleEnteredDepotThisTick(Vehicle *v);
|
|
|
|
|
2009-03-11 20:43:14 +00:00
|
|
|
void VehicleMove(Vehicle *v, bool update_viewport);
|
2008-01-16 21:17:31 +00:00
|
|
|
void MarkSingleVehicleDirty(const Vehicle *v);
|
2007-12-27 13:35:39 +00:00
|
|
|
|
|
|
|
UnitID GetFreeUnitNumber(VehicleType type);
|
|
|
|
|
2009-02-09 21:20:05 +00:00
|
|
|
CommandCost SendAllVehiclesToDepot(VehicleType type, DoCommandFlag flags, bool service, Owner owner, uint16 vlw_flag, uint32 id);
|
2007-12-27 13:35:39 +00:00
|
|
|
void VehicleEnterDepot(Vehicle *v);
|
|
|
|
|
|
|
|
bool CanBuildVehicleInfrastructure(VehicleType type);
|
|
|
|
|
|
|
|
void CcCloneVehicle(bool success, TileIndex tile, uint32 p1, uint32 p2);
|
|
|
|
|
2008-10-19 15:39:12 +00:00
|
|
|
/** Position information of a vehicle after it moved */
|
2007-12-27 13:35:39 +00:00
|
|
|
struct GetNewVehiclePosResult {
|
2008-10-19 15:39:12 +00:00
|
|
|
int x, y; ///< x and y position of the vehicle after moving
|
|
|
|
TileIndex old_tile; ///< Current tile of the vehicle
|
|
|
|
TileIndex new_tile; ///< Tile of the vehicle after moving
|
2007-12-27 13:35:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
GetNewVehiclePosResult GetNewVehiclePos(const Vehicle *v);
|
|
|
|
Direction GetDirectionTowards(const Vehicle *v, int x, int y);
|
|
|
|
|
2008-09-30 20:39:50 +00:00
|
|
|
static inline bool IsCompanyBuildableVehicleType(VehicleType type)
|
2007-12-27 13:35:39 +00:00
|
|
|
{
|
|
|
|
switch (type) {
|
|
|
|
case VEH_TRAIN:
|
|
|
|
case VEH_ROAD:
|
|
|
|
case VEH_SHIP:
|
|
|
|
case VEH_AIRCRAFT:
|
|
|
|
return true;
|
|
|
|
|
|
|
|
default: return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-30 20:39:50 +00:00
|
|
|
static inline bool IsCompanyBuildableVehicleType(const BaseVehicle *v)
|
2007-12-27 13:35:39 +00:00
|
|
|
{
|
2008-09-30 20:39:50 +00:00
|
|
|
return IsCompanyBuildableVehicleType(v->type);
|
2007-12-27 13:35:39 +00:00
|
|
|
}
|
|
|
|
|
2008-09-30 20:39:50 +00:00
|
|
|
const struct Livery *GetEngineLivery(EngineID engine_type, CompanyID company, EngineID parent_engine_type, const Vehicle *v);
|
2007-12-27 13:35:39 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the colour map for an engine. This used for unbuilt engines in the user interface.
|
|
|
|
* @param engine_type ID of engine
|
2008-09-30 20:39:50 +00:00
|
|
|
* @param company ID of company
|
2007-12-27 13:35:39 +00:00
|
|
|
* @return A ready-to-use palette modifier
|
|
|
|
*/
|
2008-09-30 20:39:50 +00:00
|
|
|
SpriteID GetEnginePalette(EngineID engine_type, CompanyID company);
|
2007-12-27 13:35:39 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the colour map for a vehicle.
|
|
|
|
* @param v Vehicle to get colour map for
|
|
|
|
* @return A ready-to-use palette modifier
|
|
|
|
*/
|
|
|
|
SpriteID GetVehiclePalette(const Vehicle *v);
|
|
|
|
|
|
|
|
extern const uint32 _veh_build_proc_table[];
|
|
|
|
extern const uint32 _veh_sell_proc_table[];
|
|
|
|
extern const uint32 _veh_refit_proc_table[];
|
|
|
|
extern const uint32 _send_to_depot_proc_table[];
|
|
|
|
|
|
|
|
/* Functions to find the right command for certain vehicle type */
|
|
|
|
static inline uint32 GetCmdBuildVeh(VehicleType type)
|
|
|
|
{
|
|
|
|
return _veh_build_proc_table[type];
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline uint32 GetCmdBuildVeh(const BaseVehicle *v)
|
|
|
|
{
|
|
|
|
return GetCmdBuildVeh(v->type);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline uint32 GetCmdSellVeh(VehicleType type)
|
|
|
|
{
|
|
|
|
return _veh_sell_proc_table[type];
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline uint32 GetCmdSellVeh(const BaseVehicle *v)
|
|
|
|
{
|
|
|
|
return GetCmdSellVeh(v->type);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline uint32 GetCmdRefitVeh(VehicleType type)
|
|
|
|
{
|
|
|
|
return _veh_refit_proc_table[type];
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline uint32 GetCmdRefitVeh(const BaseVehicle *v)
|
|
|
|
{
|
|
|
|
return GetCmdRefitVeh(v->type);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline uint32 GetCmdSendToDepot(VehicleType type)
|
|
|
|
{
|
|
|
|
return _send_to_depot_proc_table[type];
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline uint32 GetCmdSendToDepot(const BaseVehicle *v)
|
|
|
|
{
|
|
|
|
return GetCmdSendToDepot(v->type);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool EnsureNoVehicleOnGround(TileIndex tile);
|
|
|
|
void StopAllVehicles();
|
|
|
|
|
|
|
|
extern VehicleID _vehicle_id_ctr_day;
|
2008-05-25 09:40:44 +00:00
|
|
|
extern const Vehicle *_place_clicked_vehicle;
|
2007-12-27 13:35:39 +00:00
|
|
|
extern VehicleID _new_vehicle_id;
|
|
|
|
extern uint16 _returned_refit_capacity;
|
|
|
|
|
2009-01-10 09:51:14 +00:00
|
|
|
bool CanVehicleUseStation(EngineID engine_type, const struct Station *st);
|
|
|
|
bool CanVehicleUseStation(const Vehicle *v, const struct Station *st);
|
|
|
|
|
2008-04-20 11:12:07 +00:00
|
|
|
#endif /* VEHICLE_FUNC_H */
|