changeset 13934:6c8c9b6e2b7b draft

(svn r18466) -Codechange: use CmdMoveRailWagon to attach a just build wagon to a chain
author rubidium <rubidium@openttd.org>
date Fri, 11 Dec 2009 22:23:48 +0000
parents a71da8c8c5e2
children 28a3a7a5c7f9
files src/train_cmd.cpp
diffstat 1 files changed, 14 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/src/train_cmd.cpp
+++ b/src/train_cmd.cpp
@@ -705,19 +705,6 @@
 	}
 
 	if (flags & DC_EXEC) {
-		Vehicle *u = NULL;
-
-		Train *w;
-		FOR_ALL_TRAINS(w) {
-			/* do not connect new wagon with crashed/flooded consists */
-			if (w->tile == tile && w->IsFreeWagon() &&
-					w->engine_type == engine &&
-					!(w->vehstatus & VS_CRASHED)) {
-				u = w->Last();
-				break;
-			}
-		}
-
 		Train *v = new Train();
 		v->spritenum = rvi->image_index;
 
@@ -742,12 +729,8 @@
 //		v->subtype = 0;
 		v->SetWagon();
 
-		if (u != NULL) {
-			u->SetNext(v);
-		} else {
-			v->SetFreeWagon();
-			InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile);
-		}
+		v->SetFreeWagon();
+		InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile);
 
 		v->cargo_type = e->GetDefaultCargoType();
 //		v->cargo_subtype = 0;
@@ -778,6 +761,18 @@
 		Company::Get(_current_company)->num_engines[engine]++;
 
 		CheckConsistencyOfArticulatedVehicle(v);
+
+		/* Try to connect the vehicle to one of free chains of wagons. */
+		Train *w;
+		FOR_ALL_TRAINS(w) {
+			/* do not connect new wagon with crashed/flooded consists */
+			if (w->tile == tile && w->IsFreeWagon() &&
+					w->engine_type == engine &&
+					!(w->vehstatus & VS_CRASHED)) {
+				DoCommand(0, v->index | (w->Last()->index << 16), 1, DC_EXEC, CMD_MOVE_RAIL_VEHICLE);
+				break;
+			}
+		}
 	}
 
 	return value;