src/vehicle.cpp
changeset 7510 acb7cfe27b60
parent 7506 e52d89f5c7c1
child 7534 30004d242e19
equal deleted inserted replaced
7509:5adc45aa7c3c 7510:acb7cfe27b60
  2269 }
  2269 }
  2270 
  2270 
  2271 /**
  2271 /**
  2272  * Calculates how full a vehicle is.
  2272  * Calculates how full a vehicle is.
  2273  * @param v The Vehicle to check. For trains, use the first engine.
  2273  * @param v The Vehicle to check. For trains, use the first engine.
       
  2274  * @param color The string to show depending on if we are unloading or loading
  2274  * @return A percentage of how full the Vehicle is.
  2275  * @return A percentage of how full the Vehicle is.
  2275  */
  2276  */
  2276 uint8 CalcPercentVehicleFilled(Vehicle *v)
  2277 uint8 CalcPercentVehicleFilled(Vehicle *v, StringID *color)
  2277 {
  2278 {
  2278 	int count = 0;
  2279 	int count = 0;
  2279 	int max = 0;
  2280 	int max = 0;
       
  2281 	int cars = 0;
       
  2282 	int unloading = 0;
       
  2283 
       
  2284 	assert(color != NULL);
  2280 
  2285 
  2281 	/* Count up max and used */
  2286 	/* Count up max and used */
  2282 	for (; v != NULL; v = v->next) {
  2287 	for (; v != NULL; v = v->next) {
  2283 		count += v->cargo.Count();
  2288 		count += v->cargo.Count();
  2284 		max += v->cargo_cap;
  2289 		max += v->cargo_cap;
  2285 	}
  2290 		if (v->cargo_cap != 0) {
       
  2291 			unloading += HASBIT(v->vehicle_flags, VF_CARGO_UNLOADING) ? 1 : 0;
       
  2292 			cars++;
       
  2293 		}
       
  2294 	}
       
  2295 
       
  2296 	if (unloading == 0)         *color = STR_PERCENT_UP;
       
  2297 	else if (cars == unloading) *color = STR_PERCENT_DOWN;
       
  2298 	else                        *color = STR_PERCENT_UP_DOWN;
  2286 
  2299 
  2287 	/* Train without capacity */
  2300 	/* Train without capacity */
  2288 	if (max == 0) return 100;
  2301 	if (max == 0) return 100;
  2289 
  2302 
  2290 	/* Return the percentage */
  2303 	/* Return the percentage */