(svn r9752) -Codechange: remove some duplication related to BeginLoading.
authorrubidium
Sun, 29 Apr 2007 18:21:24 +0000
changeset 7046 5f11f759f74d
parent 7045 8a2c1c2f8948
child 7047 578d7e38b601
(svn r9752) -Codechange: remove some duplication related to BeginLoading.
src/aircraft_cmd.cpp
src/roadveh_cmd.cpp
src/ship_cmd.cpp
src/train_cmd.cpp
src/vehicle.cpp
--- a/src/aircraft_cmd.cpp	Sun Apr 29 10:14:42 2007 +0000
+++ b/src/aircraft_cmd.cpp	Sun Apr 29 18:21:24 2007 +0000
@@ -1509,15 +1509,7 @@
 			0);
 	}
 
-	Order old_order = v->current_order;
 	v->BeginLoading();
-	v->current_order.flags = 0;
-
-	if (old_order.type == OT_GOTO_STATION &&
-			v->current_order.dest == v->last_station_visited) {
-		v->current_order.flags =
-			(old_order.flags & (OF_FULL_LOAD | OF_UNLOAD | OF_TRANSFER)) | OF_NON_STOP;
-	}
 
 	SET_EXPENSES_TYPE(EXPENSES_AIRCRAFT_INC);
 	LoadUnloadVehicle(v, true);
--- a/src/roadveh_cmd.cpp	Sun Apr 29 10:14:42 2007 +0000
+++ b/src/roadveh_cmd.cpp	Sun Apr 29 18:21:24 2007 +0000
@@ -1569,7 +1569,6 @@
 		if (v->current_order.type != OT_LEAVESTATION &&
 				v->current_order.type != OT_GOTO_DEPOT) {
 			/* Vehicle has arrived at a bay in a road stop */
-			Order old_order;
 
 			if (IsDriveThroughStopTile(v->tile)) {
 				TileIndex next_tile = TILE_ADD(v->tile, TileOffsByDir(v->direction));
@@ -1600,15 +1599,7 @@
 
 			RoadVehArrivesAt(v, st);
 
-			old_order = v->current_order;
 			v->BeginLoading();
-			v->current_order.flags = 0;
-
-			if (old_order.type == OT_GOTO_STATION &&
-					v->current_order.dest == v->last_station_visited) {
-				v->current_order.flags =
-					(old_order.flags & (OF_FULL_LOAD | OF_UNLOAD | OF_TRANSFER)) | OF_NON_STOP;
-			}
 
 			SET_EXPENSES_TYPE(EXPENSES_ROADVEH_INC);
 			if (LoadUnloadVehicle(v, true)) {
--- a/src/ship_cmd.cpp	Sun Apr 29 10:14:42 2007 +0000
+++ b/src/ship_cmd.cpp	Sun Apr 29 18:21:24 2007 +0000
@@ -304,7 +304,7 @@
 {
 	switch (v->current_order.type) {
 		case OT_LOADING: {
-			if (--v->load_unload_time_rem) return;
+			if (--v->load_unload_time_rem != 0) return;
 
 			if (CanFillVehicle(v) && (
 						v->current_order.flags & OF_FULL_LOAD ||
@@ -736,8 +736,6 @@
 							st = GetStation(v->current_order.dest);
 							if (st->facilities & FACIL_DOCK) { // ugly, ugly workaround for problem with ships able to drop off cargo at wrong stations
 								v->BeginLoading();
-								v->current_order.flags &= OF_FULL_LOAD | OF_UNLOAD | OF_TRANSFER;
-								v->current_order.flags |= OF_NON_STOP;
 								ShipArrivesAt(v, st);
 
 								SET_EXPENSES_TYPE(EXPENSES_SHIP_INC);
--- a/src/train_cmd.cpp	Sun Apr 29 10:14:42 2007 +0000
+++ b/src/train_cmd.cpp	Sun Apr 29 18:21:24 2007 +0000
@@ -2634,19 +2634,7 @@
 		);
 	}
 
-	/* Did we reach the final destination? */
-	if (v->current_order.type == OT_GOTO_STATION &&
-			v->current_order.dest == station) {
-		/* Yeah, keep the load/unload flags
-		 * Non Stop now means if the order should be increased. */
-		v->BeginLoading();
-		v->current_order.flags &= OF_FULL_LOAD | OF_UNLOAD | OF_TRANSFER;
-		v->current_order.flags |= OF_NON_STOP;
-	} else {
-		/* No, just do a simple load */
-		v->BeginLoading();
-		v->current_order.flags = 0;
-	}
+	v->BeginLoading();
 	v->current_order.dest = 0;
 
 	SET_EXPENSES_TYPE(EXPENSES_TRAIN_INC);
--- a/src/vehicle.cpp	Sun Apr 29 10:14:42 2007 +0000
+++ b/src/vehicle.cpp	Sun Apr 29 18:21:24 2007 +0000
@@ -2950,6 +2950,24 @@
 void Vehicle::BeginLoading()
 {
 	assert(IsTileType(tile, MP_STATION) || type == VEH_SHIP);
+
+	if (this->current_order.type == OT_GOTO_STATION &&
+			this->current_order.dest == this->last_station_visited) {
+		/* Arriving at the ordered station.
+		 * Keep the load/unload flags, as we (obviously) still need them. */
+		this->current_order.flags &= OF_FULL_LOAD | OF_UNLOAD | OF_TRANSFER;
+
+		/* Furthermore add the Non Stop flag to mark that this station
+		 * is the actual destination of the vehicle, which is (for example)
+		 * necessary to be known for HandleTrainLoading to determine
+		 * whether the train is lost or not; not marking a train lost
+		 * that arrives at random stations is bad. */
+		this->current_order.flags |= OF_NON_STOP;
+	} else {
+		/* This is just an unordered intermediate stop */
+		this->current_order.flags = 0;
+	}
+
 	current_order.type = OT_LOADING;
 	GetStation(this->last_station_visited)->loading_vehicles.push_back(this);
 }