summaryrefslogtreecommitdiff
path: root/src/saveload/order_sl.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/saveload/order_sl.cpp')
-rw-r--r--src/saveload/order_sl.cpp27
1 files changed, 16 insertions, 11 deletions
diff --git a/src/saveload/order_sl.cpp b/src/saveload/order_sl.cpp
index 6325b3cca..d9283a2be 100644
--- a/src/saveload/order_sl.cpp
+++ b/src/saveload/order_sl.cpp
@@ -81,7 +81,7 @@ Order UnpackOldOrder(uint16 packed)
* Sanity check
* TTD stores invalid orders as OT_NOTHING with non-zero flags/station
*/
- if (!order.IsValid() && packed != 0) order.MakeDummy();
+ if (order.IsType(OT_NOTHING) && packed != 0) order.MakeDummy();
return order;
}
@@ -123,7 +123,6 @@ static void Load_ORDR()
/* Version older than 5.2 did not have a ->next pointer. Convert them
* (in the old days, the orderlist was 5000 items big) */
size_t len = SlGetFieldLength();
- uint i;
if (CheckSavegameVersion(5)) {
/* Pre-version 5 had an other layout for orders
@@ -133,9 +132,9 @@ static void Load_ORDR()
SlArray(orders, len, SLE_UINT16);
- for (i = 0; i < len; ++i) {
- Order *order = new (i) Order();
- order->AssignOrder(UnpackVersion4Order(orders[i]));
+ for (size_t i = 0; i < len; ++i) {
+ Order *o = new (i) Order();
+ o->AssignOrder(UnpackVersion4Order(orders[i]));
}
free(orders);
@@ -145,7 +144,7 @@ static void Load_ORDR()
SlArray(orders, len, SLE_UINT32);
- for (i = 0; i < len; ++i) {
+ for (size_t i = 0; i < len; ++i) {
new (i) Order(orders[i]);
}
@@ -153,12 +152,17 @@ static void Load_ORDR()
}
/* Update all the next pointer */
- for (i = 1; i < len; ++i) {
+ Order *o;
+ FOR_ALL_ORDERS(o) {
+ /* Delete invalid orders */
+ if (o->IsType(OT_NOTHING)) {
+ delete o;
+ continue;
+ }
/* The orders were built like this:
- * While the order is valid, set the previous will get it's next pointer set
- * We start with index 1 because no order will have the first in it's next pointer */
- if (Order::Get(i)->IsValid())
- Order::Get(i - 1)->next = Order::Get(i);
+ * While the order is valid, set the previous will get its next pointer set */
+ Order *prev = Order::GetIfValid(order_index - 1);
+ if (prev != NULL) prev->next = o;
}
} else {
int index;
@@ -172,6 +176,7 @@ static void Load_ORDR()
static void Ptrs_ORDR()
{
+ /* Orders from old savegames have pointers corrected in Load_ORDR */
if (CheckSavegameVersionOldStyle(5, 2)) return;
Order *o;