src/train_cmd.cpp
changeset 6740 72a0840e8ac1
parent 6735 dd792fed65e2
child 6752 ced7607c8c45
equal deleted inserted replaced
6739:ad869251cca9 6740:72a0840e8ac1
  1172 			AddWagonToConsist(src->u.rail.other_multiheaded_part, src);
  1172 			AddWagonToConsist(src->u.rail.other_multiheaded_part, src);
  1173 			/* previous line set the front engine to the old front. We need to clear that */
  1173 			/* previous line set the front engine to the old front. We need to clear that */
  1174 			src->u.rail.other_multiheaded_part->first = NULL;
  1174 			src->u.rail.other_multiheaded_part->first = NULL;
  1175 		}
  1175 		}
  1176 
  1176 
  1177 		if (HASBIT(p2, 0) && src_head != NULL && src_head != src) {
       
  1178 			/* if we stole a rear multiheaded engine, we better give it back to the front end */
       
  1179 			Vehicle *engine = NULL, *u;
       
  1180 			for (u = src_head; u != NULL; u = u->next) {
       
  1181 				if (IsMultiheaded(u)) {
       
  1182 					if (IsTrainEngine(u)) {
       
  1183 						engine = u;
       
  1184 						continue;
       
  1185 					}
       
  1186 					/* we got the rear engine to match with the front one */
       
  1187 					engine = NULL;
       
  1188 				}
       
  1189 			}
       
  1190 			if (engine != NULL && engine->u.rail.other_multiheaded_part != NULL) {
       
  1191 				AddWagonToConsist(engine->u.rail.other_multiheaded_part, engine);
       
  1192 				/* previous line set the front engine to the old front. We need to clear that */
       
  1193 				engine->u.rail.other_multiheaded_part->first = NULL;
       
  1194 			}
       
  1195 		}
       
  1196 
       
  1197 		/* If there is an engine behind first_engine we moved away, it should become new first_engine
  1177 		/* If there is an engine behind first_engine we moved away, it should become new first_engine
  1198 		 * To do this, CmdMoveRailVehicle must be called once more
  1178 		 * To do this, CmdMoveRailVehicle must be called once more
  1199 		 * we can't loop forever here because next time we reach this line we will have a front engine */
  1179 		 * we can't loop forever here because next time we reach this line we will have a front engine */
  1200 		if (src_head != NULL && !IsFrontEngine(src_head) && IsTrainEngine(src_head)) {
  1180 		if (src_head != NULL && !IsFrontEngine(src_head) && IsTrainEngine(src_head)) {
  1201 			/* As in CmdMoveRailVehicle src_head->group_id will be equal to DEFAULT_GROUP
  1181 			/* As in CmdMoveRailVehicle src_head->group_id will be equal to DEFAULT_GROUP