# HG changeset patch # User truelight # Date 1104234691 0 # Node ID 4f9377b7fd2b39af3e2d221927234c61764014b2 # Parent e1c4b6f5742e191b2a2820207a72a8fc6fd9e4c6 (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!! diff -r e1c4b6f5742e -r 4f9377b7fd2b aircraft_cmd.c --- a/aircraft_cmd.c Tue Dec 28 09:55:55 2004 +0000 +++ b/aircraft_cmd.c Tue Dec 28 11:51:31 2004 +0000 @@ -180,7 +180,7 @@ // v->load_unload_time_rem = 0; // v->progress = 0; - v->last_station_visited = 0xFF; + v->last_station_visited = 0xFFFF; // v->destination_coords = 0; v->max_speed = avi->max_speed; diff -r e1c4b6f5742e -r 4f9377b7fd2b industry_cmd.c --- a/industry_cmd.c Tue Dec 28 09:55:55 2004 +0000 +++ b/industry_cmd.c Tue Dec 28 11:51:31 2004 +0000 @@ -837,7 +837,7 @@ BEGIN_TILE_LOOP(tile_cur, i->width, i->height, i->xy); if (IS_TILETYPE(tile_cur, MP_INDUSTRY)) { - if (_map2[tile_cur] == (byte)index) { + if (_map2[tile_cur] == (uint16)index) { DoClearSquare(tile_cur); } } else if (IS_TILETYPE(tile_cur, MP_STATION) && _map5[tile_cur] == 0x4B) { diff -r e1c4b6f5742e -r 4f9377b7fd2b landscape.c --- a/landscape.c Tue Dec 28 09:55:55 2004 +0000 +++ b/landscape.c Tue Dec 28 11:51:31 2004 +0000 @@ -484,7 +484,7 @@ int i; 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_hi, 0, map_size); memset(_map_extra_bits, 0, map_size / 4); diff -r e1c4b6f5742e -r 4f9377b7fd2b map.c --- a/map.c Tue Dec 28 09:55:55 2004 +0000 +++ b/map.c Tue Dec 28 11:51:31 2004 +0000 @@ -5,10 +5,10 @@ uint _map_log_x = TILE_X_BITS; uint _map_log_y = TILE_Y_BITS; -byte _map_type_and_height[TILES_X * TILES_Y]; -byte _map5[TILES_X * TILES_Y]; -byte _map3_lo[TILES_X * TILES_Y]; -byte _map3_hi[TILES_X * TILES_Y]; -byte _map_owner[TILES_X * TILES_Y]; -byte _map2[TILES_X * TILES_Y]; -byte _map_extra_bits[TILES_X * TILES_Y / 4]; +byte _map_type_and_height [TILES_X * TILES_Y]; +byte _map5 [TILES_X * TILES_Y]; +byte _map3_lo [TILES_X * TILES_Y]; +byte _map3_hi [TILES_X * TILES_Y]; +byte _map_owner [TILES_X * TILES_Y]; +uint16 _map2 [TILES_X * TILES_Y]; +byte _map_extra_bits [TILES_X * TILES_Y / 4]; diff -r e1c4b6f5742e -r 4f9377b7fd2b map.h --- a/map.h Tue Dec 28 09:55:55 2004 +0000 +++ b/map.h Tue Dec 28 11:51:31 2004 +0000 @@ -10,13 +10,13 @@ #define TILE_X_MAX (TILES_X - 1) #define TILE_Y_MAX (TILES_Y - 1) -extern byte _map_type_and_height[]; -extern byte _map5[]; -extern byte _map3_lo[]; -extern byte _map3_hi[]; -extern byte _map_owner[]; -extern byte _map2[]; -extern byte _map_extra_bits[]; +extern byte _map_type_and_height[]; +extern byte _map5[]; +extern byte _map3_lo[]; +extern byte _map3_hi[]; +extern byte _map_owner[]; +extern uint16 _map2[]; +extern byte _map_extra_bits[]; // 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; } diff -r e1c4b6f5742e -r 4f9377b7fd2b misc.c --- a/misc.c Tue Dec 28 09:55:55 2004 +0000 +++ b/misc.c Tue Dec 28 11:51:31 2004 +0000 @@ -837,7 +837,12 @@ } 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() { diff -r e1c4b6f5742e -r 4f9377b7fd2b oldloader.c --- a/oldloader.c Tue Dec 28 09:55:55 2004 +0000 +++ b/oldloader.c Tue Dec 28 11:51:31 2004 +0000 @@ -1383,10 +1383,10 @@ // copy sections of it to our datastructures. map_size = MapSize(); 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(_map5, m->map5, map_size); for (i = 0; i != map_size; i++) { + _map2[i] = m->map2[i]; _map3_lo[i] = m->map3[i] & 0xFF; _map3_hi[i] = m->map3[i] >> 8; } diff -r e1c4b6f5742e -r 4f9377b7fd2b rail_cmd.c --- a/rail_cmd.c Tue Dec 28 09:55:55 2004 +0000 +++ b/rail_cmd.c Tue Dec 28 11:51:31 2004 +0000 @@ -1836,7 +1836,7 @@ for(i=0; i!=ssd->cur; i++) { uint tile = ssd->tile[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 if (_map3_hi[tile] & 1) { @@ -1985,7 +1985,7 @@ { byte a2; byte rail; - byte m2; + uint16 m2; byte owner; m2 = _map2[tile] & 0xF; @@ -2068,7 +2068,8 @@ static uint32 GetTileTrackStatus_Track(uint tile, TransportType mode) { - byte m5, a, b; + byte m5, a; + uint16 b; uint32 ret; if (mode != TRANSPORT_RAIL) diff -r e1c4b6f5742e -r 4f9377b7fd2b road_cmd.c --- a/road_cmd.c Tue Dec 28 09:55:55 2004 +0000 +++ b/road_cmd.c Tue Dec 28 11:51:31 2004 +0000 @@ -727,7 +727,7 @@ static void DrawTile_Road(TileInfo *ti) { uint32 image; - byte m2; + uint16 m2; const byte *s; if ( (ti->map5 & 0xF0) == 0) { // if it is a road the upper 4 bits are 0 @@ -1006,7 +1006,7 @@ } else { // Handle road work - byte b = _map2[tile]; + uint16 b = _map2[tile]; if (b < 0x80) { _map2[tile] = b + 8; return; diff -r e1c4b6f5742e -r 4f9377b7fd2b roadveh_cmd.c --- a/roadveh_cmd.c Tue Dec 28 09:55:55 2004 +0000 +++ b/roadveh_cmd.c Tue Dec 28 11:51:31 2004 +0000 @@ -159,7 +159,7 @@ // v->u.road.unk2 = 0; // v->u.road.overtaking = 0; - v->last_station_visited = 0xFF; + v->last_station_visited = 0xFFFF; v->max_speed = rvi->max_speed; v->engine_type = (byte)p1; @@ -597,7 +597,7 @@ if (order.type == OT_GOTO_STATION) { if (order.station == v->last_station_visited) - v->last_station_visited = 0xFF; + v->last_station_visited = 0xFFFF; st = DEREF_STATION(order.station); v->dest_tile = v->cargo_type==CT_PASSENGERS ? st->bus_tile : st->lorry_tile; } else if (order.type == OT_GOTO_DEPOT) { diff -r e1c4b6f5742e -r 4f9377b7fd2b saveload.c --- a/saveload.c Tue Dec 28 09:55:55 2004 +0000 +++ b/saveload.c Tue Dec 28 11:51:31 2004 +0000 @@ -5,7 +5,6 @@ #include "town.h" #include "player.h" #include "saveload.h" -#include enum { SAVEGAME_MAJOR_VERSION = 4, @@ -18,47 +17,6 @@ /******************************************************/ /******************************************************/ -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}; SaverLoader _sl; diff -r e1c4b6f5742e -r 4f9377b7fd2b saveload.h --- a/saveload.h Tue Dec 28 09:55:55 2004 +0000 +++ b/saveload.h Tue Dec 28 11:51:31 2004 +0000 @@ -1,6 +1,8 @@ #ifndef SAVELOAD_H #define SAVELOAD_H +#include + typedef void ChunkSaveLoadProc(); typedef void AutolengthProc(void *arg); @@ -23,6 +25,49 @@ byte null; } 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 { REF_SCHEDULE = 0, REF_VEHICLE = 1, diff -r e1c4b6f5742e -r 4f9377b7fd2b ship_cmd.c --- a/ship_cmd.c Tue Dec 28 09:55:55 2004 +0000 +++ b/ship_cmd.c Tue Dec 28 11:51:31 2004 +0000 @@ -241,7 +241,7 @@ if (order.type == OT_GOTO_STATION) { if (order.station == v->last_station_visited) - v->last_station_visited = 0xFF; + v->last_station_visited = 0xFFFF; st = DEREF_STATION(order.station); if (st->dock_tile != 0) { @@ -846,7 +846,7 @@ v->cargo_cap = svi->capacity; v->value = value; - v->last_station_visited = 255; + v->last_station_visited = 0xFFFF; v->max_speed = svi->max_speed; v->engine_type = (byte)p1; diff -r e1c4b6f5742e -r 4f9377b7fd2b station_cmd.c --- a/station_cmd.c Tue Dec 28 09:55:55 2004 +0000 +++ b/station_cmd.c Tue Dec 28 11:51:31 2004 +0000 @@ -105,7 +105,7 @@ static bool CheckStationSpreadOut(Station *st, uint tile, int w, int h) { - byte station_index = st->index; + uint16 station_index = st->index; uint i; uint x1 = GET_TILE_X(tile); uint y1 = GET_TILE_Y(tile); @@ -2168,7 +2168,7 @@ static uint32 VehicleEnter_Station(Vehicle *v, uint tile, int x, int y) { - byte station_id; + uint16 station_id; byte dir; uint16 spd; @@ -2482,7 +2482,8 @@ uint MoveGoodsToStation(uint tile, int w, int h, int type, uint amount) { Station *around_ptr[8]; - byte around[8], st_index; + byte around[8]; + uint16 st_index; int i; Station *st; uint moved; diff -r e1c4b6f5742e -r 4f9377b7fd2b station_gui.c --- a/station_gui.c Tue Dec 28 09:55:55 2004 +0000 +++ b/station_gui.c Tue Dec 28 11:51:31 2004 +0000 @@ -302,7 +302,7 @@ int x,y; int pos; StringID str; - byte station_id; + uint16 station_id; byte *b; diff -r e1c4b6f5742e -r 4f9377b7fd2b town_cmd.c --- a/town_cmd.c Tue Dec 28 09:55:55 2004 +0000 +++ b/town_cmd.c Tue Dec 28 11:51:31 2004 +0000 @@ -63,7 +63,7 @@ /* Retrieve pointer to the draw town tile struct */ { /* 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; uint variant; variant = ti->x >> 4; diff -r e1c4b6f5742e -r 4f9377b7fd2b train_cmd.c --- a/train_cmd.c Tue Dec 28 09:55:55 2004 +0000 +++ b/train_cmd.c Tue Dec 28 11:51:31 2004 +0000 @@ -433,7 +433,7 @@ // v->progress = 0; // v->targetairport = 0; // v->crash_anim_pos = 0; - v->last_station_visited = 0xff; + v->last_station_visited = 0xFFFF; v->dest_tile = 0; // v->profit_last_year = 0; // v->profit_this_year = 0; @@ -1666,7 +1666,7 @@ result = false; if (order.type == OT_GOTO_STATION) { 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; result = CheckReverseTrain(v); } else if (order.type == OT_GOTO_DEPOT) { diff -r e1c4b6f5742e -r 4f9377b7fd2b tree_cmd.c --- a/tree_cmd.c Tue Dec 28 09:55:55 2004 +0000 +++ b/tree_cmd.c Tue Dec 28 11:51:31 2004 +0000 @@ -240,7 +240,7 @@ static void DrawTile_Trees(TileInfo *ti) { - byte m2; + uint16 m2; const uint32 *s; const byte *d; byte z; @@ -459,7 +459,8 @@ static void TileLoop_Trees(uint tile) { - byte m5, m2; + byte m5; + uint16 m2; static const TileIndexDiff _tileloop_trees_dir[] = { TILE_XY(-1,-1), @@ -482,7 +483,7 @@ /* increase counter */ { - byte m2 = _map2[tile]; + uint16 m2 = _map2[tile]; _map2[tile] = m2 = (m2 & 0xF0) | ((m2+1)&0xF); if (m2 & 0xF) return; diff -r e1c4b6f5742e -r 4f9377b7fd2b vehicle.c --- a/vehicle.c Tue Dec 28 09:55:55 2004 +0000 +++ b/vehicle.c Tue Dec 28 11:51:31 2004 +0000 @@ -490,7 +490,7 @@ // clear last station visited 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 if (v->current_order.type == cmd.type && @@ -1655,7 +1655,8 @@ SLE_VAR(Vehicle,progress, 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_days, SLE_UINT8), @@ -1756,7 +1757,10 @@ SLE_INCLUDEX(0, INC_VEHICLE_COMMON), 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,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_CONDVARX(offsetof(Vehicle,u)+offsetof(VehicleAir,previous_pos), SLE_UINT8, 2, 255), @@ -1854,6 +1858,10 @@ // 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); v->next_in_chain_old = v->next ? v->next->index : INVALID_VEHICLE; SlObject(v, _veh_descs[v->type - 0x10]); @@ -1874,6 +1882,10 @@ v->next = v->next_in_chain_old == INVALID_VEHICLE ? NULL : &_vehicles[v->next_in_chain_old]; if (v->type == VEH_Train) 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. diff -r e1c4b6f5742e -r 4f9377b7fd2b vehicle.h --- a/vehicle.h Tue Dec 28 09:55:55 2004 +0000 +++ b/vehicle.h Tue Dec 28 11:51:31 2004 +0000 @@ -11,7 +11,7 @@ uint8 flags:4; uint8 type:4; #endif - uint8 station; + uint16 station; } Order; static inline uint16 PackOrder(const Order *order) @@ -62,7 +62,7 @@ uint16 crashed_counter; byte pos; byte previous_pos; - byte targetairport; + uint16 targetairport; byte state; } VehicleAir; @@ -159,7 +159,7 @@ byte progress; byte vehstatus; // Status - byte last_station_visited; + uint16 last_station_visited; byte cargo_type; // type of cargo this vehicle is carrying byte cargo_days; // how many days have the pieces been in transit