summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortruelight <truelight@openttd.org>2004-12-28 11:51:31 +0000
committertruelight <truelight@openttd.org>2004-12-28 11:51:31 +0000
commit2f9e0b8e0ca58ed9cbb907170631294baa706156 (patch)
tree31c4abf8c556a50cc2cb6846bddb8f40f21986c9
parent16cd779efe9afff09afe7ec5a930b50fa8365d3b (diff)
downloadopenttd-2f9e0b8e0ca58ed9cbb907170631294baa706156.tar.xz
(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!!
-rw-r--r--aircraft_cmd.c2
-rw-r--r--industry_cmd.c2
-rw-r--r--landscape.c2
-rw-r--r--map.c14
-rw-r--r--map.h14
-rw-r--r--misc.c7
-rw-r--r--oldloader.c2
-rw-r--r--rail_cmd.c7
-rw-r--r--road_cmd.c4
-rw-r--r--roadveh_cmd.c4
-rw-r--r--saveload.c42
-rw-r--r--saveload.h45
-rw-r--r--ship_cmd.c4
-rw-r--r--station_cmd.c7
-rw-r--r--station_gui.c2
-rw-r--r--town_cmd.c2
-rw-r--r--train_cmd.c4
-rw-r--r--tree_cmd.c7
-rw-r--r--vehicle.c18
-rw-r--r--vehicle.h6
20 files changed, 109 insertions, 86 deletions
diff --git a/aircraft_cmd.c b/aircraft_cmd.c
index 300e2efb3..8236e414a 100644
--- a/aircraft_cmd.c
+++ b/aircraft_cmd.c
@@ -180,7 +180,7 @@ int32 CmdBuildAircraft(int x, int y, uint32 flags, uint32 p1, uint32 p2)
// 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 --git a/industry_cmd.c b/industry_cmd.c
index 528fc231c..1cf301282 100644
--- a/industry_cmd.c
+++ b/industry_cmd.c
@@ -837,7 +837,7 @@ void DeleteIndustry(Industry *i)
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 --git a/landscape.c b/landscape.c
index 28fca9648..63e3fdd87 100644
--- a/landscape.c
+++ b/landscape.c
@@ -484,7 +484,7 @@ void InitializeLandscape()
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 --git a/map.c b/map.c
index 48e16c046..034d4fa70 100644
--- a/map.c
+++ b/map.c
@@ -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 --git a/map.h b/map.h
index 9c8c4b52b..4d2e66413 100644
--- a/map.h
+++ b/map.h
@@ -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 --git a/misc.c b/misc.c
index 34ad3bfac..a96d09eb1 100644
--- a/misc.c
+++ b/misc.c
@@ -837,7 +837,12 @@ static void SaveLoad_MAPT() {
}
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 --git a/oldloader.c b/oldloader.c
index d2220eca0..93b395119 100644
--- a/oldloader.c
+++ b/oldloader.c
@@ -1383,10 +1383,10 @@ bool LoadOldSaveGame(const char *file)
// 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 --git a/rail_cmd.c b/rail_cmd.c
index 1bb4172bf..50854d612 100644
--- a/rail_cmd.c
+++ b/rail_cmd.c
@@ -1836,7 +1836,7 @@ static void ChangeSignalStates(SetSignalsData *ssd)
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 @@ static void TileLoop_Track(uint tile)
{
byte a2;
byte rail;
- byte m2;
+ uint16 m2;
byte owner;
m2 = _map2[tile] & 0xF;
@@ -2068,7 +2068,8 @@ modify_me:;
static uint32 GetTileTrackStatus_Track(uint tile, TransportType mode) {
- byte m5, a, b;
+ byte m5, a;
+ uint16 b;
uint32 ret;
if (mode != TRANSPORT_RAIL)
diff --git a/road_cmd.c b/road_cmd.c
index 07874499f..0676293ab 100644
--- a/road_cmd.c
+++ b/road_cmd.c
@@ -727,7 +727,7 @@ const byte _road_sloped_sprites[14] = {
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 @@ static void TileLoop_Road(uint tile)
} else {
// Handle road work
- byte b = _map2[tile];
+ uint16 b = _map2[tile];
if (b < 0x80) {
_map2[tile] = b + 8;
return;
diff --git a/roadveh_cmd.c b/roadveh_cmd.c
index c72416160..ccca06923 100644
--- a/roadveh_cmd.c
+++ b/roadveh_cmd.c
@@ -159,7 +159,7 @@ int32 CmdBuildRoadVeh(int x, int y, uint32 flags, uint32 p1, uint32 p2)
// 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 @@ static void ProcessRoadVehOrder(Vehicle *v)
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 --git a/saveload.c b/saveload.c
index 736e98dc9..83b46c137 100644
--- a/saveload.c
+++ b/saveload.c
@@ -5,7 +5,6 @@
#include "town.h"
#include "player.h"
#include "saveload.h"
-#include <setjmp.h>
enum {
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};
SaverLoader _sl;
diff --git a/saveload.h b/saveload.h
index 4bacf895e..d9ba00765 100644
--- a/saveload.h
+++ b/saveload.h
@@ -1,6 +1,8 @@
#ifndef SAVELOAD_H
#define SAVELOAD_H
+#include <setjmp.h>
+
typedef void ChunkSaveLoadProc();
typedef void AutolengthProc(void *arg);
@@ -23,6 +25,49 @@ typedef struct {
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 --git a/ship_cmd.c b/ship_cmd.c
index 8b2879b7e..3c350d938 100644
--- a/ship_cmd.c
+++ b/ship_cmd.c
@@ -241,7 +241,7 @@ static void ProcessShipOrder(Vehicle *v)
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 @@ int32 CmdBuildShip(int x, int y, uint32 flags, uint32 p1, uint32 p2)
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 --git a/station_cmd.c b/station_cmd.c
index 72ea344e5..53d21947b 100644
--- a/station_cmd.c
+++ b/station_cmd.c
@@ -105,7 +105,7 @@ TileIndex GetStationTileForVehicle(Vehicle *v, Station *st)
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 const byte _enter_station_speedtable[12] = {
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 @@ int32 CmdRenameStation(int x, int y, uint32 flags, uint32 p1, uint32 p2)
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 --git a/station_gui.c b/station_gui.c
index 222da540b..081e883b5 100644
--- a/station_gui.c
+++ b/station_gui.c
@@ -302,7 +302,7 @@ static void DrawStationViewWindow(Window *w)
int x,y;
int pos;
StringID str;
- byte station_id;
+ uint16 station_id;
byte *b;
diff --git a/town_cmd.c b/town_cmd.c
index 8208cf0a5..2830ea23b 100644
--- a/town_cmd.c
+++ b/town_cmd.c
@@ -63,7 +63,7 @@ static void DrawTile_Town(TileInfo *ti)
/* 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 --git a/train_cmd.c b/train_cmd.c
index e6ef3cb18..5386addf4 100644
--- a/train_cmd.c
+++ b/train_cmd.c
@@ -433,7 +433,7 @@ int32 CmdBuildRailVehicle(int x, int y, uint32 flags, uint32 p1, uint32 p2)
// 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 @@ static bool ProcessTrainOrder(Vehicle *v)
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 --git a/tree_cmd.c b/tree_cmd.c
index f5830c88b..8e1b334cf 100644
--- a/tree_cmd.c
+++ b/tree_cmd.c
@@ -240,7 +240,7 @@ typedef struct TreeListEnt {
static void DrawTile_Trees(TileInfo *ti)
{
- byte m2;
+ uint16 m2;
const uint32 *s;
const byte *d;
byte z;
@@ -459,7 +459,8 @@ static void TileLoopTreesAlps(uint tile)
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 @@ static void TileLoop_Trees(uint tile)
/* increase counter */
{
- byte m2 = _map2[tile];
+ uint16 m2 = _map2[tile];
_map2[tile] = m2 = (m2 & 0xF0) | ((m2+1)&0xF);
if (m2 & 0xF)
return;
diff --git a/vehicle.c b/vehicle.c
index 79a3c3d8d..a8ad3160a 100644
--- a/vehicle.c
+++ b/vehicle.c
@@ -490,7 +490,7 @@ void DeleteCommandFromVehicleSchedule(Order cmd)
// 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 @@ const byte _common_veh_desc[] = {
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 @@ static const byte _aircraft_desc[] = {
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 @@ 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);
v->next_in_chain_old = v->next ? v->next->index : INVALID_VEHICLE;
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];
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 --git a/vehicle.h b/vehicle.h
index de9aac5b2..09fbac9f5 100644
--- a/vehicle.h
+++ b/vehicle.h
@@ -11,7 +11,7 @@ typedef struct Order {
uint8 flags:4;
uint8 type:4;
#endif
- uint8 station;
+ uint16 station;
} Order;
static inline uint16 PackOrder(const Order *order)
@@ -62,7 +62,7 @@ typedef struct VehicleAir {
uint16 crashed_counter;
byte pos;
byte previous_pos;
- byte targetairport;
+ uint16 targetairport;
byte state;
} VehicleAir;
@@ -159,7 +159,7 @@ struct Vehicle {
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