(svn r1288) -Codechange: changed _map2 to an uint16. It is still saved and loaded as

an uint8 till the savegame version is bumped to version 5. Then it works 
automaticly as a fully uint16. So _stations[] can not be increased till 
after the bump!!
This commit is contained in:
truelight 2004-12-28 11:51:31 +00:00
parent 41201f488c
commit c2ee8d70e4
20 changed files with 109 additions and 86 deletions

View File

@ -180,7 +180,7 @@ int32 CmdBuildAircraft(int x, int y, uint32 flags, uint32 p1, uint32 p2)
// v->load_unload_time_rem = 0; // v->load_unload_time_rem = 0;
// v->progress = 0; // v->progress = 0;
v->last_station_visited = 0xFF; v->last_station_visited = 0xFFFF;
// v->destination_coords = 0; // v->destination_coords = 0;
v->max_speed = avi->max_speed; v->max_speed = avi->max_speed;

View File

@ -837,7 +837,7 @@ void DeleteIndustry(Industry *i)
BEGIN_TILE_LOOP(tile_cur, i->width, i->height, i->xy); BEGIN_TILE_LOOP(tile_cur, i->width, i->height, i->xy);
if (IS_TILETYPE(tile_cur, MP_INDUSTRY)) { if (IS_TILETYPE(tile_cur, MP_INDUSTRY)) {
if (_map2[tile_cur] == (byte)index) { if (_map2[tile_cur] == (uint16)index) {
DoClearSquare(tile_cur); DoClearSquare(tile_cur);
} }
} else if (IS_TILETYPE(tile_cur, MP_STATION) && _map5[tile_cur] == 0x4B) { } else if (IS_TILETYPE(tile_cur, MP_STATION) && _map5[tile_cur] == 0x4B) {

View File

@ -484,7 +484,7 @@ void InitializeLandscape()
int i; int i;
memset(_map_owner, OWNER_NONE, map_size); memset(_map_owner, OWNER_NONE, map_size);
memset(_map2, 0, map_size); memset(_map2, 0, map_size * sizeof(uint16));
memset(_map3_lo, 0, map_size); memset(_map3_lo, 0, map_size);
memset(_map3_hi, 0, map_size); memset(_map3_hi, 0, map_size);
memset(_map_extra_bits, 0, map_size / 4); memset(_map_extra_bits, 0, map_size / 4);

14
map.c
View File

@ -5,10 +5,10 @@
uint _map_log_x = TILE_X_BITS; uint _map_log_x = TILE_X_BITS;
uint _map_log_y = TILE_Y_BITS; uint _map_log_y = TILE_Y_BITS;
byte _map_type_and_height[TILES_X * TILES_Y]; byte _map_type_and_height [TILES_X * TILES_Y];
byte _map5[TILES_X * TILES_Y]; byte _map5 [TILES_X * TILES_Y];
byte _map3_lo[TILES_X * TILES_Y]; byte _map3_lo [TILES_X * TILES_Y];
byte _map3_hi[TILES_X * TILES_Y]; byte _map3_hi [TILES_X * TILES_Y];
byte _map_owner[TILES_X * TILES_Y]; byte _map_owner [TILES_X * TILES_Y];
byte _map2[TILES_X * TILES_Y]; uint16 _map2 [TILES_X * TILES_Y];
byte _map_extra_bits[TILES_X * TILES_Y / 4]; byte _map_extra_bits [TILES_X * TILES_Y / 4];

14
map.h
View File

@ -10,13 +10,13 @@
#define TILE_X_MAX (TILES_X - 1) #define TILE_X_MAX (TILES_X - 1)
#define TILE_Y_MAX (TILES_Y - 1) #define TILE_Y_MAX (TILES_Y - 1)
extern byte _map_type_and_height[]; extern byte _map_type_and_height[];
extern byte _map5[]; extern byte _map5[];
extern byte _map3_lo[]; extern byte _map3_lo[];
extern byte _map3_hi[]; extern byte _map3_hi[];
extern byte _map_owner[]; extern byte _map_owner[];
extern byte _map2[]; extern uint16 _map2[];
extern byte _map_extra_bits[]; extern byte _map_extra_bits[];
// binary logarithm of the map size, try to avoid using this one // binary logarithm of the map size, try to avoid using this one
static inline uint MapLogX(void) { extern uint _map_log_x; return _map_log_x; } static inline uint MapLogX(void) { extern uint _map_log_x; return _map_log_x; }

7
misc.c
View File

@ -837,7 +837,12 @@ static void SaveLoad_MAPT() {
} }
static void SaveLoad_MAP2() { static void SaveLoad_MAP2() {
SlArray(_map2, MapSize(), SLE_UINT8); if (_sl.version < 5) {
/* In those versions the _map2 was 8 bits */
SlArray(_map2, MapSize(), SLE_FILE_U8 | SLE_VAR_U16);
} else {
SlArray(_map2, MapSize(), SLE_UINT16);
}
} }
static void SaveLoad_M3LO() { static void SaveLoad_M3LO() {

View File

@ -1383,10 +1383,10 @@ bool LoadOldSaveGame(const char *file)
// copy sections of it to our datastructures. // copy sections of it to our datastructures.
map_size = MapSize(); map_size = MapSize();
memcpy(_map_owner, m->map_owner, map_size); memcpy(_map_owner, m->map_owner, map_size);
memcpy(_map2, m->map2, map_size);
memcpy(_map_type_and_height, m->map_type_and_height, map_size); memcpy(_map_type_and_height, m->map_type_and_height, map_size);
memcpy(_map5, m->map5, map_size); memcpy(_map5, m->map5, map_size);
for (i = 0; i != map_size; i++) { for (i = 0; i != map_size; i++) {
_map2[i] = m->map2[i];
_map3_lo[i] = m->map3[i] & 0xFF; _map3_lo[i] = m->map3[i] & 0xFF;
_map3_hi[i] = m->map3[i] >> 8; _map3_hi[i] = m->map3[i] >> 8;
} }

View File

@ -1836,7 +1836,7 @@ static void ChangeSignalStates(SetSignalsData *ssd)
for(i=0; i!=ssd->cur; i++) { for(i=0; i!=ssd->cur; i++) {
uint tile = ssd->tile[i]; uint tile = ssd->tile[i];
byte bit = _signals_table[ssd->bit[i]]; byte bit = _signals_table[ssd->bit[i]];
byte m2 = _map2[tile]; uint16 m2 = _map2[tile];
// presignals don't turn green if there is at least one presignal exit and none are free // presignals don't turn green if there is at least one presignal exit and none are free
if (_map3_hi[tile] & 1) { if (_map3_hi[tile] & 1) {
@ -1985,7 +1985,7 @@ static void TileLoop_Track(uint tile)
{ {
byte a2; byte a2;
byte rail; byte rail;
byte m2; uint16 m2;
byte owner; byte owner;
m2 = _map2[tile] & 0xF; m2 = _map2[tile] & 0xF;
@ -2068,7 +2068,8 @@ modify_me:;
static uint32 GetTileTrackStatus_Track(uint tile, TransportType mode) { static uint32 GetTileTrackStatus_Track(uint tile, TransportType mode) {
byte m5, a, b; byte m5, a;
uint16 b;
uint32 ret; uint32 ret;
if (mode != TRANSPORT_RAIL) if (mode != TRANSPORT_RAIL)

View File

@ -727,7 +727,7 @@ const byte _road_sloped_sprites[14] = {
static void DrawTile_Road(TileInfo *ti) static void DrawTile_Road(TileInfo *ti)
{ {
uint32 image; uint32 image;
byte m2; uint16 m2;
const byte *s; const byte *s;
if ( (ti->map5 & 0xF0) == 0) { // if it is a road the upper 4 bits are 0 if ( (ti->map5 & 0xF0) == 0) { // if it is a road the upper 4 bits are 0
@ -1006,7 +1006,7 @@ static void TileLoop_Road(uint tile)
} else { } else {
// Handle road work // Handle road work
byte b = _map2[tile]; uint16 b = _map2[tile];
if (b < 0x80) { if (b < 0x80) {
_map2[tile] = b + 8; _map2[tile] = b + 8;
return; return;

View File

@ -159,7 +159,7 @@ int32 CmdBuildRoadVeh(int x, int y, uint32 flags, uint32 p1, uint32 p2)
// v->u.road.unk2 = 0; // v->u.road.unk2 = 0;
// v->u.road.overtaking = 0; // v->u.road.overtaking = 0;
v->last_station_visited = 0xFF; v->last_station_visited = 0xFFFF;
v->max_speed = rvi->max_speed; v->max_speed = rvi->max_speed;
v->engine_type = (byte)p1; v->engine_type = (byte)p1;
@ -597,7 +597,7 @@ static void ProcessRoadVehOrder(Vehicle *v)
if (order.type == OT_GOTO_STATION) { if (order.type == OT_GOTO_STATION) {
if (order.station == v->last_station_visited) if (order.station == v->last_station_visited)
v->last_station_visited = 0xFF; v->last_station_visited = 0xFFFF;
st = DEREF_STATION(order.station); st = DEREF_STATION(order.station);
v->dest_tile = v->cargo_type==CT_PASSENGERS ? st->bus_tile : st->lorry_tile; v->dest_tile = v->cargo_type==CT_PASSENGERS ? st->bus_tile : st->lorry_tile;
} else if (order.type == OT_GOTO_DEPOT) { } else if (order.type == OT_GOTO_DEPOT) {

View File

@ -5,7 +5,6 @@
#include "town.h" #include "town.h"
#include "player.h" #include "player.h"
#include "saveload.h" #include "saveload.h"
#include <setjmp.h>
enum { enum {
SAVEGAME_MAJOR_VERSION = 4, SAVEGAME_MAJOR_VERSION = 4,
@ -18,47 +17,6 @@ enum {
/******************************************************/ /******************************************************/
/******************************************************/ /******************************************************/
typedef void WriterProc(uint len);
typedef uint ReaderProc();
typedef uint ReferenceToIntProc(void *v, uint t);
typedef void *IntToReferenceProc(uint r, uint t);
typedef struct {
bool save;
byte need_length;
byte block_mode;
bool error;
byte version;
int obj_len;
int array_index, last_array_index;
uint32 offs_base;
WriterProc *write_bytes;
ReaderProc *read_bytes;
ReferenceToIntProc *ref_to_int_proc;
IntToReferenceProc *int_to_ref_proc;
const ChunkHandler * const * chs;
const byte * const *includes;
byte *bufp, *bufe;
int tmp;
// these 3 may be used by compressor/decompressors.
byte *buf; // pointer and size to read/write, initialized by init
uint bufsize;
FILE *fh;
void (*excpt_uninit)();
const char *excpt_msg;
jmp_buf excpt; // used to jump to "exception handler"
} SaverLoader;
enum NeedLengthValues { NL_NONE = 0,NL_WANTLENGTH = 1,NL_CALCLENGTH = 2}; enum NeedLengthValues { NL_NONE = 0,NL_WANTLENGTH = 1,NL_CALCLENGTH = 2};
SaverLoader _sl; SaverLoader _sl;

View File

@ -1,6 +1,8 @@
#ifndef SAVELOAD_H #ifndef SAVELOAD_H
#define SAVELOAD_H #define SAVELOAD_H
#include <setjmp.h>
typedef void ChunkSaveLoadProc(); typedef void ChunkSaveLoadProc();
typedef void AutolengthProc(void *arg); typedef void AutolengthProc(void *arg);
@ -23,6 +25,49 @@ typedef struct {
byte null; byte null;
} NullStruct; } NullStruct;
typedef void WriterProc(uint len);
typedef uint ReaderProc();
typedef uint ReferenceToIntProc(void *v, uint t);
typedef void *IntToReferenceProc(uint r, uint t);
typedef struct {
bool save;
byte need_length;
byte block_mode;
bool error;
byte version;
int obj_len;
int array_index, last_array_index;
uint32 offs_base;
WriterProc *write_bytes;
ReaderProc *read_bytes;
ReferenceToIntProc *ref_to_int_proc;
IntToReferenceProc *int_to_ref_proc;
const ChunkHandler * const * chs;
const byte * const *includes;
byte *bufp, *bufe;
int tmp;
// these 3 may be used by compressor/decompressors.
byte *buf; // pointer and size to read/write, initialized by init
uint bufsize;
FILE *fh;
void (*excpt_uninit)();
const char *excpt_msg;
jmp_buf excpt; // used to jump to "exception handler"
} SaverLoader;
extern SaverLoader _sl;
enum { enum {
REF_SCHEDULE = 0, REF_SCHEDULE = 0,
REF_VEHICLE = 1, REF_VEHICLE = 1,

View File

@ -241,7 +241,7 @@ static void ProcessShipOrder(Vehicle *v)
if (order.type == OT_GOTO_STATION) { if (order.type == OT_GOTO_STATION) {
if (order.station == v->last_station_visited) if (order.station == v->last_station_visited)
v->last_station_visited = 0xFF; v->last_station_visited = 0xFFFF;
st = DEREF_STATION(order.station); st = DEREF_STATION(order.station);
if (st->dock_tile != 0) { if (st->dock_tile != 0) {
@ -846,7 +846,7 @@ int32 CmdBuildShip(int x, int y, uint32 flags, uint32 p1, uint32 p2)
v->cargo_cap = svi->capacity; v->cargo_cap = svi->capacity;
v->value = value; v->value = value;
v->last_station_visited = 255; v->last_station_visited = 0xFFFF;
v->max_speed = svi->max_speed; v->max_speed = svi->max_speed;
v->engine_type = (byte)p1; v->engine_type = (byte)p1;

View File

@ -105,7 +105,7 @@ TileIndex GetStationTileForVehicle(Vehicle *v, Station *st)
static bool CheckStationSpreadOut(Station *st, uint tile, int w, int h) static bool CheckStationSpreadOut(Station *st, uint tile, int w, int h)
{ {
byte station_index = st->index; uint16 station_index = st->index;
uint i; uint i;
uint x1 = GET_TILE_X(tile); uint x1 = GET_TILE_X(tile);
uint y1 = GET_TILE_Y(tile); uint y1 = GET_TILE_Y(tile);
@ -2168,7 +2168,7 @@ static const byte _enter_station_speedtable[12] = {
static uint32 VehicleEnter_Station(Vehicle *v, uint tile, int x, int y) static uint32 VehicleEnter_Station(Vehicle *v, uint tile, int x, int y)
{ {
byte station_id; uint16 station_id;
byte dir; byte dir;
uint16 spd; uint16 spd;
@ -2482,7 +2482,8 @@ int32 CmdRenameStation(int x, int y, uint32 flags, uint32 p1, uint32 p2)
uint MoveGoodsToStation(uint tile, int w, int h, int type, uint amount) uint MoveGoodsToStation(uint tile, int w, int h, int type, uint amount)
{ {
Station *around_ptr[8]; Station *around_ptr[8];
byte around[8], st_index; byte around[8];
uint16 st_index;
int i; int i;
Station *st; Station *st;
uint moved; uint moved;

View File

@ -302,7 +302,7 @@ static void DrawStationViewWindow(Window *w)
int x,y; int x,y;
int pos; int pos;
StringID str; StringID str;
byte station_id; uint16 station_id;
byte *b; byte *b;

View File

@ -63,7 +63,7 @@ static void DrawTile_Town(TileInfo *ti)
/* Retrieve pointer to the draw town tile struct */ /* Retrieve pointer to the draw town tile struct */
{ {
/* this "randomizes" on the (up to) 4 variants of a building */ /* this "randomizes" on the (up to) 4 variants of a building */
byte gfx = _map2[ti->tile]; byte gfx = (byte)_map2[ti->tile];
byte stage = _map3_lo[ti->tile] >> 6; byte stage = _map3_lo[ti->tile] >> 6;
uint variant; uint variant;
variant = ti->x >> 4; variant = ti->x >> 4;

View File

@ -433,7 +433,7 @@ int32 CmdBuildRailVehicle(int x, int y, uint32 flags, uint32 p1, uint32 p2)
// v->progress = 0; // v->progress = 0;
// v->targetairport = 0; // v->targetairport = 0;
// v->crash_anim_pos = 0; // v->crash_anim_pos = 0;
v->last_station_visited = 0xff; v->last_station_visited = 0xFFFF;
v->dest_tile = 0; v->dest_tile = 0;
// v->profit_last_year = 0; // v->profit_last_year = 0;
// v->profit_this_year = 0; // v->profit_this_year = 0;
@ -1666,7 +1666,7 @@ static bool ProcessTrainOrder(Vehicle *v)
result = false; result = false;
if (order.type == OT_GOTO_STATION) { if (order.type == OT_GOTO_STATION) {
if (order.station == v->last_station_visited) if (order.station == v->last_station_visited)
v->last_station_visited = 0xFF; v->last_station_visited = 0xFFFF;
v->dest_tile = DEREF_STATION(order.station)->xy; v->dest_tile = DEREF_STATION(order.station)->xy;
result = CheckReverseTrain(v); result = CheckReverseTrain(v);
} else if (order.type == OT_GOTO_DEPOT) { } else if (order.type == OT_GOTO_DEPOT) {

View File

@ -240,7 +240,7 @@ typedef struct TreeListEnt {
static void DrawTile_Trees(TileInfo *ti) static void DrawTile_Trees(TileInfo *ti)
{ {
byte m2; uint16 m2;
const uint32 *s; const uint32 *s;
const byte *d; const byte *d;
byte z; byte z;
@ -459,7 +459,8 @@ static void TileLoopTreesAlps(uint tile)
static void TileLoop_Trees(uint tile) static void TileLoop_Trees(uint tile)
{ {
byte m5, m2; byte m5;
uint16 m2;
static const TileIndexDiff _tileloop_trees_dir[] = { static const TileIndexDiff _tileloop_trees_dir[] = {
TILE_XY(-1,-1), TILE_XY(-1,-1),
@ -482,7 +483,7 @@ static void TileLoop_Trees(uint tile)
/* increase counter */ /* increase counter */
{ {
byte m2 = _map2[tile]; uint16 m2 = _map2[tile];
_map2[tile] = m2 = (m2 & 0xF0) | ((m2+1)&0xF); _map2[tile] = m2 = (m2 & 0xF0) | ((m2+1)&0xF);
if (m2 & 0xF) if (m2 & 0xF)
return; return;

View File

@ -490,7 +490,7 @@ void DeleteCommandFromVehicleSchedule(Order cmd)
// clear last station visited // clear last station visited
if (v->last_station_visited == cmd.station && cmd.type == OT_GOTO_STATION) if (v->last_station_visited == cmd.station && cmd.type == OT_GOTO_STATION)
v->last_station_visited = 0xFF; v->last_station_visited = 0xFFFF;
// check the next order // check the next order
if (v->current_order.type == cmd.type && if (v->current_order.type == cmd.type &&
@ -1655,7 +1655,8 @@ const byte _common_veh_desc[] = {
SLE_VAR(Vehicle,progress, SLE_UINT8), SLE_VAR(Vehicle,progress, SLE_UINT8),
SLE_VAR(Vehicle,vehstatus, SLE_UINT8), SLE_VAR(Vehicle,vehstatus, SLE_UINT8),
SLE_VAR(Vehicle,last_station_visited,SLE_UINT8), SLE_CONDVAR(Vehicle,last_station_visited, SLE_FILE_U8 | SLE_VAR_U16, 0, 4),
SLE_CONDVAR(Vehicle,last_station_visited, SLE_UINT16, 5, 255),
SLE_VAR(Vehicle,cargo_type, SLE_UINT8), SLE_VAR(Vehicle,cargo_type, SLE_UINT8),
SLE_VAR(Vehicle,cargo_days, SLE_UINT8), SLE_VAR(Vehicle,cargo_days, SLE_UINT8),
@ -1756,7 +1757,10 @@ static const byte _aircraft_desc[] = {
SLE_INCLUDEX(0, INC_VEHICLE_COMMON), SLE_INCLUDEX(0, INC_VEHICLE_COMMON),
SLE_VARX(offsetof(Vehicle,u)+offsetof(VehicleAir,crashed_counter), SLE_UINT16), SLE_VARX(offsetof(Vehicle,u)+offsetof(VehicleAir,crashed_counter), SLE_UINT16),
SLE_VARX(offsetof(Vehicle,u)+offsetof(VehicleAir,pos), SLE_UINT8), SLE_VARX(offsetof(Vehicle,u)+offsetof(VehicleAir,pos), SLE_UINT8),
SLE_VARX(offsetof(Vehicle,u)+offsetof(VehicleAir,targetairport), SLE_UINT8),
SLE_CONDVARX(offsetof(Vehicle,u)+offsetof(VehicleAir,targetairport), SLE_FILE_U8 | SLE_VAR_U16, 0, 4),
SLE_CONDVARX(offsetof(Vehicle,u)+offsetof(VehicleAir,targetairport), SLE_UINT16, 5, 255),
SLE_VARX(offsetof(Vehicle,u)+offsetof(VehicleAir,state), SLE_UINT8), SLE_VARX(offsetof(Vehicle,u)+offsetof(VehicleAir,state), SLE_UINT8),
SLE_CONDVARX(offsetof(Vehicle,u)+offsetof(VehicleAir,previous_pos), SLE_UINT8, 2, 255), SLE_CONDVARX(offsetof(Vehicle,u)+offsetof(VehicleAir,previous_pos), SLE_UINT8, 2, 255),
@ -1854,6 +1858,10 @@ static void Save_VEHS()
// Write the vehicles // Write the vehicles
FOR_ALL_VEHICLES(v) { FOR_ALL_VEHICLES(v) {
if (v->type != 0) { 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); SlSetArrayIndex(v->index);
v->next_in_chain_old = v->next ? v->next->index : INVALID_VEHICLE; v->next_in_chain_old = v->next ? v->next->index : INVALID_VEHICLE;
SlObject(v, _veh_descs[v->type - 0x10]); SlObject(v, _veh_descs[v->type - 0x10]);
@ -1874,6 +1882,10 @@ static void Load_VEHS()
v->next = v->next_in_chain_old == INVALID_VEHICLE ? NULL : &_vehicles[v->next_in_chain_old]; v->next = v->next_in_chain_old == INVALID_VEHICLE ? NULL : &_vehicles[v->next_in_chain_old];
if (v->type == VEH_Train) if (v->type == VEH_Train)
v->u.rail.first_engine = 0xffff; v->u.rail.first_engine = 0xffff;
/* Old savegames used 'last_station_visited = 0xFF', should be 0xFFFF */
if (_sl.version < 5 && v->last_station_visited == 0xFF)
v->last_station_visited = 0xFFFF;
} }
// Iterate through trains and set first_engine appropriately. // Iterate through trains and set first_engine appropriately.

View File

@ -11,7 +11,7 @@ typedef struct Order {
uint8 flags:4; uint8 flags:4;
uint8 type:4; uint8 type:4;
#endif #endif
uint8 station; uint16 station;
} Order; } Order;
static inline uint16 PackOrder(const Order *order) static inline uint16 PackOrder(const Order *order)
@ -62,7 +62,7 @@ typedef struct VehicleAir {
uint16 crashed_counter; uint16 crashed_counter;
byte pos; byte pos;
byte previous_pos; byte previous_pos;
byte targetairport; uint16 targetairport;
byte state; byte state;
} VehicleAir; } VehicleAir;
@ -159,7 +159,7 @@ struct Vehicle {
byte progress; byte progress;
byte vehstatus; // Status byte vehstatus; // Status
byte last_station_visited; uint16 last_station_visited;
byte cargo_type; // type of cargo this vehicle is carrying byte cargo_type; // type of cargo this vehicle is carrying
byte cargo_days; // how many days have the pieces been in transit byte cargo_days; // how many days have the pieces been in transit