src/autoreplace_cmd.cpp
changeset 7010 6f0d9f03180d
parent 6990 136a08baf0ed
child 7049 0ebe47348074
equal deleted inserted replaced
7009:9992ccf17e58 7010:6f0d9f03180d
    23  * move the cargo from one engine to another if possible
    23  * move the cargo from one engine to another if possible
    24  */
    24  */
    25 static void MoveVehicleCargo(Vehicle *dest, Vehicle *source)
    25 static void MoveVehicleCargo(Vehicle *dest, Vehicle *source)
    26 {
    26 {
    27 	Vehicle *v = dest;
    27 	Vehicle *v = dest;
    28 	int units_moved;
       
    29 
    28 
    30 	do {
    29 	do {
    31 		do {
    30 		do {
    32 			if (source->cargo_type != dest->cargo_type)
    31 			if (source->cargo_type != dest->cargo_type)
    33 				continue; // cargo not compatible
    32 				continue; // cargo not compatible
    34 
    33 
    35 			if (dest->cargo_count == dest->cargo_cap)
    34 			if (dest->cargo.Count() == dest->cargo_cap)
    36 				continue; // the destination vehicle is already full
    35 				continue; // the destination vehicle is already full
    37 
    36 
    38 			units_moved = min(source->cargo_count, dest->cargo_cap - dest->cargo_count);
    37 			uint units_moved = min(source->cargo.Count(), dest->cargo_cap - dest->cargo.Count());
    39 			source->cargo_count -= units_moved;
    38 			source->cargo.MoveTo(&dest->cargo, units_moved);
    40 			dest->cargo_count   += units_moved;
       
    41 			dest->cargo_source   = source->cargo_source;
       
    42 
    39 
    43 			// copy the age of the cargo
    40 			// copy the age of the cargo
    44 			dest->cargo_days   = source->cargo_days;
       
    45 			dest->day_counter  = source->day_counter;
    41 			dest->day_counter  = source->day_counter;
    46 			dest->tick_counter = source->tick_counter;
    42 			dest->tick_counter = source->tick_counter;
    47 
    43 
    48 		} while (source->cargo_count > 0 && (dest = dest->next) != NULL);
    44 		} while (source->cargo.Count() > 0 && (dest = dest->next) != NULL);
    49 		dest = v;
    45 		dest = v;
    50 	} while ((source = source->next) != NULL);
    46 	} while ((source = source->next) != NULL);
    51 
    47 
    52 	/*
    48 	/*
    53 	 * The of the train will be incorrect at this moment. This is due
    49 	 * The of the train will be incorrect at this moment. This is due