summaryrefslogtreecommitdiff
path: root/src/ai
diff options
context:
space:
mode:
Diffstat (limited to 'src/ai')
-rw-r--r--src/ai/api/ai_vehicle.cpp5
1 files changed, 3 insertions, 2 deletions
diff --git a/src/ai/api/ai_vehicle.cpp b/src/ai/api/ai_vehicle.cpp
index fb6c8abdc..a905d42c6 100644
--- a/src/ai/api/ai_vehicle.cpp
+++ b/src/ai/api/ai_vehicle.cpp
@@ -28,8 +28,9 @@
if (!IsValidVehicle(vehicle_id)) return -1;
int num = 1;
- if (::Vehicle::Get(vehicle_id)->type == VEH_TRAIN) {
- const Train *v = (Train *)::Vehicle::Get(vehicle_id);
+
+ const Train *v = ::Train::GetIfValid(vehicle_id);
+ if (v != NULL) {
while ((v = GetNextUnit(v)) != NULL) num++;
}