summaryrefslogtreecommitdiff
path: root/src/vehicle.h
diff options
context:
space:
mode:
authorbjarni <bjarni@openttd.org>2007-01-22 01:13:10 +0000
committerbjarni <bjarni@openttd.org>2007-01-22 01:13:10 +0000
commit8f4e2e80402b3a393dbbb9b317d04b93940dd670 (patch)
tree744f7b7a7591bbc8d1bffcf90c3d0bdeb42c9ca7 /src/vehicle.h
parent14b29980230f2862329bb3228e1051c0a316f62b (diff)
downloadopenttd-8f4e2e80402b3a393dbbb9b317d04b93940dd670.tar.xz
(svn r8336) -Codechange: added function to translate vehicle types to 0,1,2... for use for index to arrays
Used this function to get rid of some switch-cases in build_vehicle_gui.cpp -Fix (r8335): ship build window didn't remember assending/decending sort setting
Diffstat (limited to 'src/vehicle.h')
-rw-r--r--src/vehicle.h13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/vehicle.h b/src/vehicle.h
index 1e23fe78c..cb0025a9d 100644
--- a/src/vehicle.h
+++ b/src/vehicle.h
@@ -424,6 +424,19 @@ 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)
+{
+ 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)