summaryrefslogtreecommitdiff
path: root/src/vehicle.h
diff options
context:
space:
mode:
authorbjarni <bjarni@openttd.org>2007-02-07 19:10:19 +0000
committerbjarni <bjarni@openttd.org>2007-02-07 19:10:19 +0000
commit037d6367349afa5a27ddf2cf015f6490167cf786 (patch)
treeb16bae58b03b0c68fe0ab88a8311dd7f6406238a /src/vehicle.h
parent5666d8d7272ff24116049757dc2405b55cfd4b97 (diff)
downloadopenttd-037d6367349afa5a27ddf2cf015f6490167cf786.tar.xz
(svn r8621) -Codechange: assigned new numbers to the VEH_(type) enum so that VEH_Train is 0, VEH_Road is 1 and so on
This means that "v->type" can be used as array indexes instead of VehTypeToIndex() (or "v->type - VEH_Train/0x10 as the code still used in some places) Surprisingly this can be done without changing the savegame format
Diffstat (limited to 'src/vehicle.h')
-rw-r--r--src/vehicle.h40
1 files changed, 13 insertions, 27 deletions
diff --git a/src/vehicle.h b/src/vehicle.h
index f1500a663..9fa8837d9 100644
--- a/src/vehicle.h
+++ b/src/vehicle.h
@@ -8,13 +8,13 @@
#include "rail.h"
enum {
- VEH_Invalid = 0x00,
- VEH_Train = 0x10,
- VEH_Road = 0x11,
- VEH_Ship = 0x12,
- VEH_Aircraft = 0x13,
- VEH_Special = 0x14,
- VEH_Disaster = 0x15,
+ VEH_Train,
+ VEH_Road,
+ VEH_Ship,
+ VEH_Aircraft,
+ VEH_Special,
+ VEH_Disaster,
+ VEH_Invalid = 0xFF,
} ;
enum VehStatus {
@@ -400,7 +400,7 @@ static inline uint GetNumVehicles(void)
*/
static inline bool IsValidVehicle(const Vehicle *v)
{
- return v->type != 0;
+ return v->type != VEH_Invalid;
}
void DestroyVehicle(Vehicle *v);
@@ -408,7 +408,7 @@ void DestroyVehicle(Vehicle *v);
static inline void DeleteVehicle(Vehicle *v)
{
DestroyVehicle(v);
- v->type = 0;
+ v->type = VEH_Invalid;
}
static inline bool IsPlayerBuildableVehicleType(byte type)
@@ -428,20 +428,6 @@ static inline bool IsPlayerBuildableVehicleType(const Vehicle *v)
return IsPlayerBuildableVehicleType(v->type);
}
-/** Function to give index of a vehicle type
- * Since the return value is 0 for VEH_train, it's perfect for index to arrays
- */
-static inline byte VehTypeToIndex(byte type)
-{
- assert(IsPlayerBuildableVehicleType(type));
- return type - VEH_Train;
-}
-
-static inline byte VehTypeToIndex(const Vehicle *v)
-{
- return VehTypeToIndex(v->type);
-}
-
#define FOR_ALL_VEHICLES_FROM(v, start) for (v = GetVehicle(start); v != NULL; v = (v->index + 1U < GetVehiclePoolSize()) ? GetVehicle(v->index + 1) : NULL) if (IsValidVehicle(v))
#define FOR_ALL_VEHICLES(v) FOR_ALL_VEHICLES_FROM(v, 0)
@@ -523,7 +509,7 @@ extern const uint32 _send_to_depot_proc_table[];
/* Functions to find the right command for certain vehicle type */
static inline uint32 GetCmdBuildVeh(byte type)
{
- return _veh_build_proc_table[VehTypeToIndex(type)];
+ return _veh_build_proc_table[type];
}
static inline uint32 GetCmdBuildVeh(const Vehicle *v)
@@ -533,7 +519,7 @@ static inline uint32 GetCmdBuildVeh(const Vehicle *v)
static inline uint32 GetCmdSellVeh(byte type)
{
- return _veh_sell_proc_table[VehTypeToIndex(type)];
+ return _veh_sell_proc_table[type];
}
static inline uint32 GetCmdSellVeh(const Vehicle *v)
@@ -543,7 +529,7 @@ static inline uint32 GetCmdSellVeh(const Vehicle *v)
static inline uint32 GetCmdRefitVeh(byte type)
{
- return _veh_refit_proc_table[VehTypeToIndex(type)];
+ return _veh_refit_proc_table[type];
}
static inline uint32 GetCmdRefitVeh(const Vehicle *v)
@@ -553,7 +539,7 @@ static inline uint32 GetCmdRefitVeh(const Vehicle *v)
static inline uint32 GetCmdSendToDepot(byte type)
{
- return _send_to_depot_proc_table[VehTypeToIndex(type)];
+ return _send_to_depot_proc_table[type];
}
static inline uint32 GetCmdSendToDepot(const Vehicle *v)