(svn r2104) Simplify implementation of Get{First,Prev}VehicleInChain() and remove a pointless check
This commit is contained in:
		
							
								
								
									
										19
									
								
								vehicle.c
									
									
									
									
									
								
							
							
						
						
									
										19
									
								
								vehicle.c
									
									
									
									
									
								
							@@ -343,27 +343,20 @@ Vehicle *GetLastVehicleInChain(Vehicle *v)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
Vehicle *GetPrevVehicleInChain(const Vehicle *v)
 | 
					Vehicle *GetPrevVehicleInChain(const Vehicle *v)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	const Vehicle *org = v;
 | 
						Vehicle *u;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	FOR_ALL_VEHICLES(v) {
 | 
						FOR_ALL_VEHICLES(u) if (u->next == v) return u;
 | 
				
			||||||
		if (v->type == VEH_Train && org == v->next)
 | 
					 | 
				
			||||||
			return (Vehicle*)v;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return NULL;
 | 
						return NULL;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Vehicle *GetFirstVehicleInChain(const Vehicle *v)
 | 
					Vehicle *GetFirstVehicleInChain(const Vehicle *v)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	while (true) {
 | 
						const Vehicle* u;
 | 
				
			||||||
		const Vehicle* u = v;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
		v = GetPrevVehicleInChain(v);
 | 
						while ((u = GetPrevVehicleInChain(v)) != NULL) v = u;
 | 
				
			||||||
		/* If there is no such vehicle,
 | 
					
 | 
				
			||||||
		    'v' == NULL and so 'u' is the first vehicle in chain */
 | 
						return (Vehicle*)v;
 | 
				
			||||||
		if (v == NULL)
 | 
					 | 
				
			||||||
			return (Vehicle*)u;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int CountVehiclesInChain(Vehicle *v)
 | 
					int CountVehiclesInChain(Vehicle *v)
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user