train_cmd.c
changeset 2952 58522ed8f0f1
parent 2951 2de6d3a59743
child 2962 f0a49b646c48
equal deleted inserted replaced
2951:2de6d3a59743 2952:58522ed8f0f1
   892 
   892 
   893 	if (IsFreeWagon(v)) return;
   893 	if (IsFreeWagon(v)) return;
   894 
   894 
   895 	assert(IsFrontEngine(v));
   895 	assert(IsFrontEngine(v));
   896 
   896 
   897 	for(; v != NULL; v = GetNextVehicle(v)) {
   897 	for (; v != NULL; v = GetNextVehicle(v)) {
   898 		if (!IsMultiheaded(v) || !IsTrainEngine(v)) continue;
   898 		if (!IsMultiheaded(v) || !IsTrainEngine(v)) continue;
   899 
   899 
   900 		/* make sure that there are no free cars before next engine */
   900 		/* make sure that there are no free cars before next engine */
   901 		for(u = v; u->next != NULL && !IsTrainEngine(u->next); u = u->next);
   901 		for (u = v; u->next != NULL && !IsTrainEngine(u->next); u = u->next);
   902 
   902 
   903 		if (u == v->u.rail.other_multiheaded_part) continue;
   903 		if (u == v->u.rail.other_multiheaded_part) continue;
   904 		AddWagonToConsist(v->u.rail.other_multiheaded_part, u);
   904 		AddWagonToConsist(v->u.rail.other_multiheaded_part, u);
   905 
   905 
   906 	}
   906 	}
   972 
   972 
   973 	if (IsTrainEngine(src) && dst_head != NULL) {
   973 	if (IsTrainEngine(src) && dst_head != NULL) {
   974 		/* we need to make sure that we didn't place it between a pair of multiheaded engines */
   974 		/* we need to make sure that we didn't place it between a pair of multiheaded engines */
   975 		Vehicle *u, *engine = NULL;
   975 		Vehicle *u, *engine = NULL;
   976 
   976 
   977 		for(u = dst_head; u != NULL; u = u->next) {
   977 		for (u = dst_head; u != NULL; u = u->next) {
   978 			if (IsTrainEngine(u) && IsMultiheaded(u) && u->u.rail.other_multiheaded_part != NULL) {
   978 			if (IsTrainEngine(u) && IsMultiheaded(u) && u->u.rail.other_multiheaded_part != NULL) {
   979 				engine = u;
   979 				engine = u;
   980 			}
   980 			}
   981 				if (engine != NULL && engine->u.rail.other_multiheaded_part == u) {
   981 				if (engine != NULL && engine->u.rail.other_multiheaded_part == u) {
   982 					engine = NULL;
   982 					engine = NULL;
  2212 				reverse_best = true;
  2212 				reverse_best = true;
  2213 			else
  2213 			else
  2214 				reverse_best = false;
  2214 				reverse_best = false;
  2215 		}
  2215 		}
  2216 	} else {
  2216 	} else {
  2217 		while(true) {
  2217 		for (;;) {
  2218 			fd.best_bird_dist = (uint)-1;
  2218 			fd.best_bird_dist = (uint)-1;
  2219 			fd.best_track_dist = (uint)-1;
  2219 			fd.best_track_dist = (uint)-1;
  2220 
  2220 
  2221 			NewTrainPathfind(v->tile, v->dest_tile, reverse ^ i, (NTPEnumProc*)NtpCallbFindStation, &fd);
  2221 			NewTrainPathfind(v->tile, v->dest_tile, reverse ^ i, (NTPEnumProc*)NtpCallbFindStation, &fd);
  2222 
  2222 
  3534 					}
  3534 					}
  3535 
  3535 
  3536 					{
  3536 					{
  3537 						Vehicle *w;
  3537 						Vehicle *w;
  3538 
  3538 
  3539 						for(w = u->next; w != NULL && (w->engine_type != u->engine_type || w->u.rail.other_multiheaded_part != NULL); w = GetNextVehicle(w));
  3539 						for (w = u->next; w != NULL && (w->engine_type != u->engine_type || w->u.rail.other_multiheaded_part != NULL); w = GetNextVehicle(w));
  3540 						if (w != NULL) {
  3540 						if (w != NULL) {
  3541 							/* we found a car to partner with this engine. Now we will make sure it face the right way */
  3541 							/* we found a car to partner with this engine. Now we will make sure it face the right way */
  3542 							if (IsTrainEngine(w)) {
  3542 							if (IsTrainEngine(w)) {
  3543 								ClearTrainEngine(w);
  3543 								ClearTrainEngine(w);
  3544 								w->spritenum++;
  3544 								w->spritenum++;