(svn r1429) Change: bumped savegame to revision 5.

- Now orders are bigger
   - Now _map2 is official 16 bits
This commit is contained in:
truelight 2005-01-08 12:47:26 +00:00
parent 3be9515d84
commit 788f543bc3
3 changed files with 46 additions and 30 deletions

View File

@ -7,8 +7,8 @@
#include "saveload.h"
enum {
SAVEGAME_MAJOR_VERSION = 4,
SAVEGAME_MINOR_VERSION = 4,
SAVEGAME_MAJOR_VERSION = 5,
SAVEGAME_MINOR_VERSION = 0,
SAVEGAME_LOADABLE_VERSION = (SAVEGAME_MAJOR_VERSION << 8) + SAVEGAME_MINOR_VERSION
};

View File

@ -2023,10 +2023,6 @@ static void Save_VEHS()
// Write the vehicles
FOR_ALL_VEHICLES(v) {
if (v->type != 0) {
/* XXX - Here for now, because we did not bump the savegame to version 5 yet */
if (_sl.version < 5 && v->last_station_visited == 0xFFFF)
v->last_station_visited = 0xFF;
SlSetArrayIndex(v->index);
SlObject(v, _veh_descs[v->type - 0x10]);
}
@ -2128,7 +2124,7 @@ static void Load_CHKP()
static void Save_ORDR()
{
uint16 orders[lengthof(_order_array)];
uint32 orders[lengthof(_order_array)];
uint len = _ptr_to_next_order - _order_array;
uint i;
@ -2137,22 +2133,38 @@ static void Save_ORDR()
for (i = 0; i < len; ++i)
orders[i] = PackOrder(&_order_array[i]);
SlArray(orders, len, SLE_UINT16);
SlArray(orders, len, SLE_UINT32);
}
static void Load_ORDR()
{
uint16 orders[lengthof(_order_array)];
uint len = SlGetFieldLength() >> 1;
uint len = SlGetFieldLength();
uint i;
if (_sl.version < 5) {
/* Older version had an other layout for orders.. convert them correctly */
uint16 orders[lengthof(_order_array)];
len /= sizeof(uint16);
assert (len <= lengthof(orders));
_ptr_to_next_order = _order_array + len;
SlArray(orders, len, SLE_UINT16);
for (i = 0; i < len; ++i)
_order_array[i] = UnpackVersion4Order(orders[i]);
} else {
uint32 orders[lengthof(_order_array)];
len /= sizeof(uint32);
assert (len <= lengthof(orders));
SlArray(orders, len, SLE_UINT32);
for (i = 0; i < len; ++i)
_order_array[i] = UnpackOrder(orders[i]);
}
_ptr_to_next_order = _order_array + len;
}
const ChunkHandler _veh_chunk_handlers[] = {

View File

@ -4,27 +4,31 @@
#include "vehicle_gui.h"
typedef struct Order {
#ifdef TTD_LITTLE_ENDIAN /* XXX hack to avoid savegame revision bump */
uint8 type:4;
uint8 flags:4;
#else
uint8 flags:4;
uint8 type:4;
#endif
uint8 type;
uint8 flags;
uint16 station;
} Order;
static inline uint16 PackOrder(const Order *order)
static inline uint32 PackOrder(const Order *order)
{
return order->station << 8 | order->flags << 4 | order->type;
return order->station << 16 | order->flags << 8 | order->type;
}
static inline Order UnpackOrder(uint16 packed)
static inline Order UnpackOrder(uint32 packed)
{
Order order;
order.type = (packed & 0x000f);
order.flags = (packed & 0x00f0) >> 4,
order.station = (packed & 0xff00) >> 8;
order.type = (packed & 0x000000FF);
order.flags = (packed & 0x0000FF00) >> 8;
order.station = (packed & 0xFFFF0000) >> 16;
return order;
}
static inline Order UnpackVersion4Order(uint16 packed)
{
Order order;
order.type = (packed & 0x000F);
order.flags = (packed & 0x00F0) >> 4;
order.station = (packed & 0xFF00) >> 8;
return order;
}