mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-01-19 21:55:40 +00:00
(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:
parent
41201f488c
commit
c2ee8d70e4
@ -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;
|
||||
|
@ -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) {
|
||||
|
@ -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);
|
||||
|
14
map.c
14
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];
|
||||
|
14
map.h
14
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; }
|
||||
|
7
misc.c
7
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() {
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -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;
|
||||
|
@ -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) {
|
||||
|
42
saveload.c
42
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;
|
||||
|
45
saveload.h
45
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,
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
|
@ -302,7 +302,7 @@ static void DrawStationViewWindow(Window *w)
|
||||
int x,y;
|
||||
int pos;
|
||||
StringID str;
|
||||
byte station_id;
|
||||
uint16 station_id;
|
||||
byte *b;
|
||||
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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) {
|
||||
|
@ -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;
|
||||
|
18
vehicle.c
18
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.
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user