vehicle.c
changeset 1600 b2bd1eaed056
parent 1542 2ca6d1624e6d
child 1601 9fd461d00287
--- a/vehicle.c	Mon Mar 28 21:14:36 2005 +0000
+++ b/vehicle.c	Tue Mar 29 08:37:44 2005 +0000
@@ -343,27 +343,20 @@
 
 Vehicle *GetPrevVehicleInChain(const Vehicle *v)
 {
-	const Vehicle *org = v;
+	Vehicle *u;
 
-	FOR_ALL_VEHICLES(v) {
-		if (v->type == VEH_Train && org == v->next)
-			return (Vehicle*)v;
-	}
+	FOR_ALL_VEHICLES(u) if (u->next == v) return u;
 
 	return NULL;
 }
 
 Vehicle *GetFirstVehicleInChain(const Vehicle *v)
 {
-	while (true) {
-		const Vehicle* u = v;
+	const Vehicle* u;
 
-		v = GetPrevVehicleInChain(v);
-		/* If there is no such vehicle,
-		    'v' == NULL and so 'u' is the first vehicle in chain */
-		if (v == NULL)
-			return (Vehicle*)u;
-	}
+	while ((u = GetPrevVehicleInChain(v)) != NULL) v = u;
+
+	return (Vehicle*)v;
 }
 
 int CountVehiclesInChain(Vehicle *v)