diff options
-rw-r--r-- | oldloader.c | 3 | ||||
-rw-r--r-- | vehicle.c | 20 | ||||
-rw-r--r-- | vehicle.h | 3 |
3 files changed, 24 insertions, 2 deletions
diff --git a/oldloader.c b/oldloader.c index 32e8e0abe..522d3ec70 100644 --- a/oldloader.c +++ b/oldloader.c @@ -1400,7 +1400,8 @@ bool LoadOldSaveGame(const char *file) } } - memcpy(_order_array, m->order_list, sizeof(m->order_list)); + for (i = 0; i < lengthof(m->order_list); ++i) + _order_array[i] = UnpackOldOrder(m->order_list[i]); _ptr_to_next_order = _order_array + REMAP_ORDER_IDX(m->ptr_to_next_order); FixTown(_towns, m->town_list, lengthof(m->town_list), m->town_name_type); @@ -16,6 +16,24 @@ #define GEN_HASH(x,y) (((x & 0x1F80)>>7) + ((y & 0xFC0))) +Order UnpackOldOrder(uint16 packed) +{ + Order order; + order.type = (packed & 0x000f); + order.flags = (packed & 0x00f0) >> 4, + order.station = (packed & 0xff00) >> 8; + + // Sanity check + // TTD stores invalid orders as OT_NOTHING with non-zero flags/station + if (order.type == OT_NOTHING && (order.flags != 0 || order.station != 0)) { + order.type = OT_DUMMY; + order.flags = 0; + } + + return order; +} + + void VehicleInTheWayErrMsg(Vehicle *v) { StringID id; @@ -1896,7 +1914,7 @@ static void Load_ORDR() SlArray(orders, len, SLE_UINT16); for (i = 0; i < len; ++i) - _order_array[i] = UnpackOrder(orders[i]); + _order_array[i] = UnpackOldOrder(orders[i]); } const ChunkHandler _veh_chunk_handlers[] = { @@ -28,6 +28,9 @@ static inline Order UnpackOrder(uint16 packed) return order; } +Order UnpackOldOrder(uint16 packed); + + typedef struct VehicleRail { uint16 last_speed; // NOSAVE: only used in UI uint16 crash_anim_pos; |