summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortruelight <truelight@openttd.org>2005-01-09 18:49:18 +0000
committertruelight <truelight@openttd.org>2005-01-09 18:49:18 +0000
commit97479f96134ec155375f97a8d12b0f8c4517a7a2 (patch)
tree0709c09c595cc9417b6bc92e6929b308efa10112
parent55e6b4f928656c23b1f8bb5cbb3763152213a0b0 (diff)
downloadopenttd-97479f96134ec155375f97a8d12b0f8c4517a7a2.tar.xz
(svn r1448) -Fix: The current_order of a vehicle is now correctly saved (caused
massive desyncs) Warning: savegames which are made with the nightly of 08-01-2005 will NO LONGER work!!
-rw-r--r--saveload.h3
-rw-r--r--vehicle.c34
-rw-r--r--vehicle.h4
3 files changed, 26 insertions, 15 deletions
diff --git a/saveload.h b/saveload.h
index ab5a15cf5..159252590 100644
--- a/saveload.h
+++ b/saveload.h
@@ -139,9 +139,6 @@ enum {
};
#define SLE_VAR(t,i,c) 0 | (offsetof(t,i) & 0xF), offsetof(t,i) >> 4, c
-#if _MSC_VER == 1200 /* XXX workaround for MSVC6 */
-#define SLE_VAR2(t0,i0, t1, i1, c) 0 | ((offsetof(t0, i0) + offsetof(t1, i1)) & 0xF), (offsetof(t0, i0) + offsetof(t1, i1)) >> 4, c
-#endif
#define SLE_REF(t,i,c) 0x10 | (offsetof(t,i) & 0xF), offsetof(t,i) >> 4, c
#define SLE_ARR(t,i,c,l) 0x20 | (offsetof(t,i) & 0xF), offsetof(t,i) >> 4, c, l
#define SLE_CONDVAR(t,i,c,from,to) 0x40 | (offsetof(t,i) & 0xF), offsetof(t,i) >> 4, c, from, to
diff --git a/vehicle.c b/vehicle.c
index 9591f7441..318bfdc57 100644
--- a/vehicle.c
+++ b/vehicle.c
@@ -1511,7 +1511,7 @@ int32 CmdReplaceVehicle(int x, int y, uint32 flags, uint32 p1, uint32 p2)
// turn the last engine in a multiheaded train if needed
if ( v->next == NULL && rvi->flags & RVI_MULTIHEAD && v->spritenum == rvi->image_index )
v->spritenum++;
-
+
v->cargo_type = rvi->cargo_type;
v->cargo_cap = rvi->capacity;
v->max_speed = rvi->max_speed;
@@ -1834,12 +1834,18 @@ const byte _common_veh_desc[] = {
SLE_VAR(Vehicle,cur_order_index, SLE_UINT8),
SLE_VAR(Vehicle,num_orders, SLE_UINT8),
- SLE_VAR(Vehicle,current_order, SLE_UINT8), /* XXX hack to avoid version bump */
- #if _MSC_VER != 1200
- SLE_VAR(Vehicle,current_order.station, SLE_UINT8),
- #else /* XXX workaround for MSVC6 */
- SLE_VAR2(Vehicle, current_order, Order, station, SLE_UINT8),
- #endif
+
+ /* This next line is for version 4 and prior compatibility.. it temporarily reads
+ type and flags (which were both 4 bits) into type. Later on this is
+ converted correctly */
+ SLE_CONDVARX(offsetof(Vehicle, current_order) + offsetof(Order, type), SLE_UINT8, 0, 4),
+ SLE_CONDVARX(offsetof(Vehicle, current_order) + offsetof(Order, station), SLE_FILE_U8 | SLE_VAR_U16, 0, 4),
+
+ /* Orders for version 5 and on */
+ SLE_CONDVARX(offsetof(Vehicle, current_order) + offsetof(Order, type), SLE_UINT8, 5, 255),
+ SLE_CONDVARX(offsetof(Vehicle, current_order) + offsetof(Order, flags), SLE_UINT8, 5, 255),
+ SLE_CONDVARX(offsetof(Vehicle, current_order) + offsetof(Order, station), SLE_UINT16, 5, 255),
+
SLE_REF(Vehicle,schedule_ptr, REF_SCHEDULE),
SLE_VAR(Vehicle,age, SLE_UINT16),
@@ -1986,11 +1992,8 @@ static const byte _disaster_desc[] = {
SLE_VAR(Vehicle,z_height, SLE_UINT8),
SLE_VAR(Vehicle,owner, SLE_UINT8),
SLE_VAR(Vehicle,vehstatus, SLE_UINT8),
- #if _MSC_VER != 1200
- SLE_VAR(Vehicle,current_order.station, SLE_UINT8),
- #else /* XXX workaround for MSVC6 */
- SLE_VAR2(Vehicle, current_order, Order, station, SLE_UINT8),
- #endif
+ SLE_CONDVARX(offsetof(Vehicle, current_order) + offsetof(Order, station), SLE_FILE_U8 | SLE_VAR_U16, 0, 4),
+ SLE_CONDVARX(offsetof(Vehicle, current_order) + offsetof(Order, station), SLE_UINT16, 5, 255),
SLE_VAR(Vehicle,cur_image, SLE_UINT16),
SLE_VAR(Vehicle,age, SLE_UINT16),
@@ -2045,6 +2048,13 @@ static void Load_VEHS()
/* Old savegames used 'last_station_visited = 0xFF', should be 0xFFFF */
if (_sl.version < 5 && v->last_station_visited == 0xFF)
v->last_station_visited = 0xFFFF;
+
+ if (_sl.version < 5) {
+ /* Convert the current_order.type (which is a mix of type and flags, because
+ in those versions, they both were 4 bits big) to type and flags */
+ v->current_order.flags = (v->current_order.type & 0xF0) >> 4;
+ v->current_order.type = v->current_order.type & 0x0F;
+ }
}
// Iterate through trains and set first_engine appropriately.
diff --git a/vehicle.h b/vehicle.h
index 61db1cce3..0ac1ceaf0 100644
--- a/vehicle.h
+++ b/vehicle.h
@@ -3,6 +3,10 @@
#include "vehicle_gui.h"
+/* If you change this, keep in mind that it is saved on 3 places:
+ - Load_ORDR, all the global orders
+ - Vehicle -> current_order
+ - REF_SHEDULE (all REFs are currently limited to 16 bits!!) */
typedef struct Order {
uint8 type;
uint8 flags;