summaryrefslogtreecommitdiff
path: root/vehicle.c
diff options
context:
space:
mode:
authortron <tron@openttd.org>2005-03-29 08:37:44 +0000
committertron <tron@openttd.org>2005-03-29 08:37:44 +0000
commite39cb78b73144ff093ee8ee2e50c7ab075683a0e (patch)
treef66307624da181e35fd2472d1aee5143c4e09c72 /vehicle.c
parenta4e17642a8ebc0fe81dc6383c641e612a5b54b4e (diff)
downloadopenttd-e39cb78b73144ff093ee8ee2e50c7ab075683a0e.tar.xz
(svn r2104) Simplify implementation of Get{First,Prev}VehicleInChain() and remove a pointless check
Diffstat (limited to 'vehicle.c')
-rw-r--r--vehicle.c19
1 files changed, 6 insertions, 13 deletions
diff --git a/vehicle.c b/vehicle.c
index 8636ceb00..d2186e4da 100644
--- a/vehicle.c
+++ b/vehicle.c
@@ -343,27 +343,20 @@ Vehicle *GetLastVehicleInChain(Vehicle *v)
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)