src/order_cmd.cpp
branchNewGRF_ports
changeset 10192 195d7f6dcf71
parent 10184 fcf5fb2548eb
child 10200 aba3af04cdbd
--- a/src/order_cmd.cpp	Tue Apr 15 00:47:19 2008 +0000
+++ b/src/order_cmd.cpp	Tue Apr 15 19:47:58 2008 +0000
@@ -41,21 +41,6 @@
 
 DEFINE_OLD_POOL_GENERIC(Order, Order);
 
-OrderLoadFlags Order::GetLoadType() const
-{
-	if ((this->flags & OLFB_FULL_LOAD) == 0) return OLF_LOAD_IF_POSSIBLE;
-	return _patches.full_load_any ? OLF_FULL_LOAD_ANY : OLFB_FULL_LOAD;
-}
-
-OrderNonStopFlags Order::GetNonStopType() const
-{
-	if (_patches.new_nonstop) {
-		return (this->flags & 0x08) ? ONSF_NO_STOP_AT_ANY_STATION : ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS;
-	}
-
-	return (this->flags & 0x08) ? ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS : ONSF_STOP_EVERYWHERE;
-}
-
 void Order::Free()
 {
 	this->type  = OT_NOTHING;
@@ -157,6 +142,50 @@
 	this->travel_time   = 0;
 }
 
+void Order::ConvertFromOldSavegame()
+{
+	/* First handle non-stop, because those bits are going to be reused. */
+	if (_patches.sg_new_nonstop) {
+		this->SetNonStopType((this->flags & 0x08) ? ONSF_NO_STOP_AT_ANY_STATION : ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS);
+	} else {
+		this->SetNonStopType((this->flags & 0x08) ? ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS : ONSF_STOP_EVERYWHERE);
+	}
+
+	switch (this->GetType()) {
+		/* Only a few types need the other savegame conversions. */
+		case OT_GOTO_DEPOT: case OT_GOTO_STATION: case OT_LOADING: break;
+		default: return;
+	}
+
+	/* Then the load/depot action flags because those bits are going to be reused too
+	 * and they reuse the non-stop bits. */
+	if (this->GetType() != OT_GOTO_DEPOT) {
+		if ((this->flags & 4) == 0) {
+			this->SetLoadType(OLF_LOAD_IF_POSSIBLE);
+		} else {
+			this->SetLoadType(_patches.sg_full_load_any ? OLF_FULL_LOAD_ANY : OLFB_FULL_LOAD);
+		}
+	} else {
+		this->SetDepotActionType(((this->flags & 6) == 4) ? ODATFB_HALT : ODATF_SERVICE_ONLY);
+	}
+
+	/* Finally fix the unload/depot type flags. */
+	if (this->GetType() != OT_GOTO_DEPOT) {
+		uint t = ((this->flags & 1) == 0) ? OUF_UNLOAD_IF_POSSIBLE : OUFB_TRANSFER;
+		if ((this->flags & 2) != 0) t |= OUFB_UNLOAD;
+		this->SetUnloadType((OrderUnloadFlags)t);
+
+		if ((this->GetUnloadType() & (OUFB_UNLOAD | OUFB_TRANSFER)) == (OUFB_UNLOAD | OUFB_TRANSFER)) {
+			this->SetUnloadType(OUFB_TRANSFER);
+			this->SetLoadType(OLFB_NO_LOAD);
+		}
+	} else {
+		uint t = ((this->flags & 6) == 6) ? ODTFB_SERVICE : ODTF_MANUAL;
+		if ((this->flags & 2) != 0) t |= ODTFB_PART_OF_ORDERS;
+		this->SetDepotOrderType((OrderDepotTypeFlags)t);
+	}
+}
+
 /**
  *
  * Unpacks a order from savegames with version 4 and lower
@@ -322,7 +351,7 @@
 			}
 
 			/* Non stop not allowed for non-trains. */
-			// TODO: implement properly once savegame bump is done. if ((new_order.GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS) != 0 && v->type != VEH_TRAIN) return CMD_ERROR;
+			if (new_order.GetNonStopType() != ONSF_STOP_EVERYWHERE && v->type != VEH_TRAIN) return CMD_ERROR;
 
 			/* Full load and unload are mutual exclusive. */
 			if ((new_order.GetLoadType() & OLFB_FULL_LOAD) && (new_order.GetUnloadType() & OUFB_UNLOAD)) return CMD_ERROR;
@@ -372,7 +401,7 @@
 				}
 			}
 
-			// TODO: implement properly once savegame bump is done. if (new_order.GetNonStopType() != ONSF_STOP_EVERYWHERE && v->type != VEH_TRAIN) return CMD_ERROR;
+			if (new_order.GetNonStopType() != ONSF_STOP_EVERYWHERE && v->type != VEH_TRAIN) return CMD_ERROR;
 			if (new_order.GetDepotOrderType() & ~ODTFB_PART_OF_ORDERS) return CMD_ERROR;
 			if (new_order.GetDepotActionType() & ~ODATFB_HALT) return CMD_ERROR;
 			break;
@@ -390,8 +419,7 @@
 			/* Order flags can be any of the following for waypoints:
 			 * [non-stop]
 			 * non-stop orders (if any) are only valid for trains */
-			// TODO: implement properly once savegame bump is done. if (new_order.GetNonStopType() != ONSF_STOP_EVERYWHERE && v->type != VEH_TRAIN) return CMD_ERROR;
-
+			if (new_order.GetNonStopType() != ONSF_STOP_EVERYWHERE && v->type != VEH_TRAIN) return CMD_ERROR;
 			break;
 		}
 
@@ -773,12 +801,14 @@
 			break;
 
 		case MOF_UNLOAD:
-			if ((data & ~(OUFB_UNLOAD | OUFB_TRANSFER)) != 0) return CMD_ERROR;
+			if ((data & ~(OUFB_UNLOAD | OUFB_TRANSFER | OUFB_NO_UNLOAD)) != 0) return CMD_ERROR;
+			/* Unload and no-unload are mutual exclusive and so are transfer and no unload. */
+			if (data != 0 && ((data & (OUFB_UNLOAD | OUFB_TRANSFER)) != 0) == ((data & OUFB_NO_UNLOAD) != 0)) return CMD_ERROR;
 			if (data == order->GetUnloadType()) return CMD_ERROR;
 			break;
 
 		case MOF_LOAD:
-			if ((data & ~OLFB_FULL_LOAD) != 0) return CMD_ERROR;
+			if (data > OLFB_NO_LOAD || data == 1) return CMD_ERROR;
 			if (data == order->GetLoadType()) return CMD_ERROR;
 			break;
 
@@ -795,17 +825,16 @@
 
 			case MOF_UNLOAD:
 				order->SetUnloadType((OrderUnloadFlags)data);
-				/* Full loading gets disabled when un loading! */
-				if ((data & OUFB_UNLOAD) != 0) {
-					order->SetLoadType((OrderLoadFlags)(order->GetLoadType() & ~(OLFB_FULL_LOAD | OLF_FULL_LOAD_ANY)));
+				if ((data & OUFB_NO_UNLOAD) != 0 && (order->GetLoadType() & OLFB_NO_LOAD) != 0) {
+					order->SetLoadType((OrderLoadFlags)(order->GetLoadType() & ~OLFB_NO_LOAD));
 				}
 				break;
 
 			case MOF_LOAD:
 				order->SetLoadType((OrderLoadFlags)data);
-				/* Unloading gets disabled when full loading! */
-				if ((data & OLFB_FULL_LOAD) != 0) {
-					order->SetUnloadType((OrderUnloadFlags)(order->GetUnloadType() & ~OUFB_UNLOAD));
+				if ((data & OLFB_NO_LOAD) != 0 && (order->GetUnloadType() & OUFB_NO_UNLOAD) != 0) {
+					/* No load + no unload isn't compatible */
+					order->SetUnloadType((OrderUnloadFlags)(order->GetUnloadType() & ~OUFB_NO_UNLOAD));
 				}
 				break;