diff options
author | tron <tron@openttd.org> | 2005-01-25 21:43:57 +0000 |
---|---|---|
committer | tron <tron@openttd.org> | 2005-01-25 21:43:57 +0000 |
commit | 07cb3068ae71ce331b540426cd098c6a33ca598a (patch) | |
tree | c41ff658c058ac5448d20ea2b75c1855bd443d93 | |
parent | cb1f1921f65ac6ad582c7387b8629c3b5391d9d7 (diff) | |
download | openttd-07cb3068ae71ce331b540426cd098c6a33ca598a.tar.xz |
(svn r1676) Increase the size of TileIndex and TileIndexDiff to 32bits and adapt the save/load data and some other parts of the code to that change
WARNING: If i made any mistake here it WILL lead to corrupted savegames!
-rw-r--r-- | ai.c | 2 | ||||
-rw-r--r-- | industry_cmd.c | 3 | ||||
-rw-r--r-- | landscape.c | 4 | ||||
-rw-r--r-- | macros.h | 1 | ||||
-rw-r--r-- | map.h | 6 | ||||
-rw-r--r-- | players.c | 24 | ||||
-rw-r--r-- | station_cmd.c | 18 | ||||
-rw-r--r-- | texteff.c | 6 | ||||
-rw-r--r-- | town_cmd.c | 3 | ||||
-rw-r--r-- | train_cmd.c | 4 | ||||
-rw-r--r-- | vehicle.c | 43 | ||||
-rw-r--r-- | vehicle.h | 4 |
12 files changed, 76 insertions, 42 deletions
@@ -3762,7 +3762,7 @@ static void AiStateRemoveTrack(Player *p) uint tile = ++p->ai.state_counter; // Iterated all tiles? - if (tile == 0) { + if (tile >= MapSize()) { p->ai.state = AIS_REMOVE_STATION; return; } diff --git a/industry_cmd.c b/industry_cmd.c index ab33e1f4d..b22ab058e 100644 --- a/industry_cmd.c +++ b/industry_cmd.c @@ -1876,7 +1876,8 @@ const TileTypeProcs _tile_type_industry_procs = { }; static const byte _industry_desc[] = { - SLE_VAR(Industry,xy, SLE_UINT16), + SLE_CONDVAR(Industry, xy, SLE_FILE_U16 | SLE_VAR_U32, 0, 5), + SLE_CONDVAR(Industry, xy, SLE_UINT32, 6, 255), SLE_VAR(Industry,width, SLE_UINT8), SLE_VAR(Industry,height, SLE_UINT8), SLE_REF(Industry,town, REF_TOWN), diff --git a/landscape.c b/landscape.c index 4dfe9953e..bb8454eb0 100644 --- a/landscape.c +++ b/landscape.c @@ -730,10 +730,10 @@ TileIndex AdjustTileCoordRandomly(TileIndex a, byte rng) int rn = rng; uint32 r = Random(); - return TILE_XY( + return TILE_MASK(TILE_XY( TileX(a) + ((byte)r * rn * 2 >> 8) - rn, TileY(a) + ((byte)(r >> 8) * rn * 2 >> 8) - rn - ); + )); } // This function checks if we add addx/addy to tile, if we @@ -160,6 +160,7 @@ static inline int64 myabs64(int64 a) { if (a<0) a = -a; return a; } static inline void swap_byte(byte *a, byte *b) { byte t = *a; *a = *b; *b = t; } static inline void swap_uint16(uint16 *a, uint16 *b) { uint16 t = *a; *a = *b; *b = t; } static inline void swap_int16(int16 *a, int16 *b) { int16 t = *a; *a = *b; *b = t; } +static inline void swap_int32(int32 *a, int32 *b) { int32 t = *a; *a = *b; *b = t; } static inline void swap_tile(TileIndex *a, TileIndex *b) { TileIndex t = *a; *a = *b; *b = t; } @@ -2,7 +2,7 @@ #define MAP_H #define TILE_FROM_XY(x,y) (int)((((y) >> 4) << MapLogX()) + ((x) >> 4)) -#define TILE_XY(x,y) (int)(((y) << MapLogX()) + (x)) +#define TILE_XY(x,y) (((y) << MapLogX()) + (x)) #define TILE_MASK(x) ((x) & ((1 << (MapLogX() + MapLogY())) - 1)) @@ -26,8 +26,8 @@ static inline uint MapMaxY(void) { return MapSizeY() - 1; } /* The number of tiles in the map */ static inline uint MapSize(void) { return MapSizeX() * MapSizeY(); } +typedef uint32 TileIndex; -typedef uint16 TileIndex; static inline uint TileX(TileIndex tile) { @@ -40,7 +40,7 @@ static inline uint TileY(TileIndex tile) } -typedef int16 TileIndexDiff; +typedef int32 TileIndexDiff; typedef struct TileIndexDiffC { int16 x; @@ -923,8 +923,10 @@ static const byte _player_desc[] = { SLE_VAR(Player,block_preview, SLE_UINT8), SLE_VAR(Player,cargo_types, SLE_UINT16), - SLE_VAR(Player,location_of_house,SLE_UINT16), - SLE_VAR(Player,last_build_coordinate,SLE_UINT16), + SLE_CONDVAR(Player, location_of_house, SLE_FILE_U16 | SLE_VAR_U32, 0, 5), + SLE_CONDVAR(Player, location_of_house, SLE_UINT32, 6, 255), + SLE_CONDVAR(Player, last_build_coordinate, SLE_FILE_U16 | SLE_VAR_U32, 0, 5), + SLE_CONDVAR(Player, last_build_coordinate, SLE_UINT32, 6, 255), SLE_VAR(Player,inaugurated_year,SLE_UINT8), SLE_ARR(Player,share_owners, SLE_UINT8, 4), @@ -983,13 +985,17 @@ static const byte _player_ai_desc[] = { SLE_VAR(PlayerAI,route_type_mask, SLE_UINT8), - SLE_VAR(PlayerAI,start_tile_a, SLE_UINT16), - SLE_VAR(PlayerAI,cur_tile_a, SLE_UINT16), + SLE_CONDVAR(PlayerAI, start_tile_a, SLE_FILE_U16 | SLE_VAR_U32, 0, 5), + SLE_CONDVAR(PlayerAI, start_tile_a, SLE_UINT32, 6, 255), + SLE_CONDVAR(PlayerAI, cur_tile_a, SLE_FILE_U16 | SLE_VAR_U32, 0, 5), + SLE_CONDVAR(PlayerAI, cur_tile_a, SLE_UINT32, 6, 255), SLE_VAR(PlayerAI,start_dir_a, SLE_UINT8), SLE_VAR(PlayerAI,cur_dir_a, SLE_UINT8), - SLE_VAR(PlayerAI,start_tile_b, SLE_UINT16), - SLE_VAR(PlayerAI,cur_tile_b, SLE_UINT16), + SLE_CONDVAR(PlayerAI, start_tile_b, SLE_FILE_U16 | SLE_VAR_U32, 0, 5), + SLE_CONDVAR(PlayerAI, start_tile_b, SLE_UINT32, 6, 255), + SLE_CONDVAR(PlayerAI, cur_tile_b, SLE_FILE_U16 | SLE_VAR_U32, 0, 5), + SLE_CONDVAR(PlayerAI, cur_tile_b, SLE_UINT32, 6, 255), SLE_VAR(PlayerAI,start_dir_b, SLE_UINT8), SLE_VAR(PlayerAI,cur_dir_b, SLE_UINT8), @@ -1004,8 +1010,10 @@ static const byte _player_ai_desc[] = { }; static const byte _player_ai_build_rec_desc[] = { - SLE_VAR(AiBuildRec,spec_tile, SLE_UINT16), - SLE_VAR(AiBuildRec,use_tile, SLE_UINT16), + SLE_CONDVAR(AiBuildRec,spec_tile, SLE_FILE_U16 | SLE_VAR_U32, 0, 5), + SLE_CONDVAR(AiBuildRec,spec_tile, SLE_UINT32, 6, 255), + SLE_CONDVAR(AiBuildRec,use_tile, SLE_FILE_U16 | SLE_VAR_U32, 0, 5), + SLE_CONDVAR(AiBuildRec,use_tile, SLE_UINT32, 6, 255), SLE_VAR(AiBuildRec,rand_rng, SLE_UINT8), SLE_VAR(AiBuildRec,cur_building_rule,SLE_UINT8), SLE_VAR(AiBuildRec,unk6, SLE_UINT8), diff --git a/station_cmd.c b/station_cmd.c index e856e7f2e..dd6fa1204 100644 --- a/station_cmd.c +++ b/station_cmd.c @@ -2810,12 +2810,18 @@ const TileTypeProcs _tile_type_station_procs = { static const byte _station_desc[] = { - SLE_VAR(Station,xy, SLE_UINT16), - SLE_VAR(Station,bus_tile, SLE_UINT16), - SLE_VAR(Station,lorry_tile, SLE_UINT16), - SLE_VAR(Station,train_tile, SLE_UINT16), - SLE_VAR(Station,airport_tile, SLE_UINT16), - SLE_VAR(Station,dock_tile, SLE_UINT16), + SLE_CONDVAR(Station, xy, SLE_FILE_U16 | SLE_VAR_U32, 0, 5), + SLE_CONDVAR(Station, xy, SLE_UINT32, 6, 255), + SLE_CONDVAR(Station, bus_tile, SLE_FILE_U16 | SLE_VAR_U32, 0, 5), + SLE_CONDVAR(Station, bus_tile, SLE_UINT32, 6, 255), + SLE_CONDVAR(Station, lorry_tile, SLE_FILE_U16 | SLE_VAR_U32, 0, 5), + SLE_CONDVAR(Station, lorry_tile, SLE_UINT32, 6, 255), + SLE_CONDVAR(Station, train_tile, SLE_FILE_U16 | SLE_VAR_U32, 0, 5), + SLE_CONDVAR(Station, train_tile, SLE_UINT32, 6, 255), + SLE_CONDVAR(Station, airport_tile, SLE_FILE_U16 | SLE_VAR_U32, 0, 5), + SLE_CONDVAR(Station, airport_tile, SLE_UINT32, 6, 255), + SLE_CONDVAR(Station, dock_tile, SLE_FILE_U16 | SLE_VAR_U32, 0, 5), + SLE_CONDVAR(Station, dock_tile, SLE_UINT32, 6, 255), SLE_REF(Station,town, REF_TOWN), SLE_VAR(Station,trainst_w, SLE_UINT8), SLE_CONDVAR(Station,trainst_h, SLE_UINT8, 2, 255), @@ -351,7 +351,11 @@ void InitializeAnimatedTiles(void) static void SaveLoad_ANIT(void) { - SlArray(_animated_tile_list, lengthof(_animated_tile_list), SLE_UINT16); + if (_sl.version < 6) + SlArray(_animated_tile_list, lengthof(_animated_tile_list), + SLE_FILE_U16 | SLE_VAR_U32); + else + SlArray(_animated_tile_list, lengthof(_animated_tile_list), SLE_UINT32); } diff --git a/town_cmd.c b/town_cmd.c index 54f5f861b..73cab9989 100644 --- a/town_cmd.c +++ b/town_cmd.c @@ -1865,7 +1865,8 @@ const TileTypeProcs _tile_type_town_procs = { // Save and load of towns. static const byte _town_desc[] = { - SLE_VAR(Town,xy, SLE_UINT16), + SLE_CONDVAR(Town, xy, SLE_FILE_U16 | SLE_VAR_U32, 0, 5), + SLE_CONDVAR(Town, xy, SLE_UINT32, 6, 255), SLE_CONDVAR(Town,population, SLE_FILE_U16 | SLE_VAR_U32, 0, 2), SLE_CONDVAR(Town,population, SLE_UINT32, 3, 255), diff --git a/train_cmd.c b/train_cmd.c index df41334e6..32b89974e 100644 --- a/train_cmd.c +++ b/train_cmd.c @@ -947,8 +947,8 @@ static void ReverseTrainSwapVeh(Vehicle *v, int l, int r) if (!(b->u.rail.track & 0x80)) b->direction ^= 4; /* swap more variables */ - swap_int16(&a->x_pos, &b->x_pos); - swap_int16(&a->y_pos, &b->y_pos); + swap_int32(&a->x_pos, &b->x_pos); + swap_int32(&a->y_pos, &b->y_pos); swap_tile(&a->tile, &b->tile); swap_byte(&a->z_pos, &b->z_pos); @@ -1765,11 +1765,15 @@ const byte _common_veh_desc[] = { SLE_VAR(Vehicle,string_id, SLE_STRINGID), SLE_VAR(Vehicle,unitnumber, SLE_UINT8), SLE_VAR(Vehicle,owner, SLE_UINT8), - SLE_VAR(Vehicle,tile, SLE_UINT16), - SLE_VAR(Vehicle,dest_tile, SLE_UINT16), - - SLE_VAR(Vehicle,x_pos, SLE_INT16), - SLE_VAR(Vehicle,y_pos, SLE_INT16), + SLE_CONDVAR(Vehicle,tile, SLE_FILE_U16 | SLE_VAR_U32, 0, 5), + SLE_CONDVAR(Vehicle,tile, SLE_UINT32, 6, 255), + SLE_CONDVAR(Vehicle,dest_tile, SLE_FILE_U16 | SLE_VAR_U32, 0, 5), + SLE_CONDVAR(Vehicle,dest_tile, SLE_UINT32, 6, 255), + + SLE_CONDVAR(Vehicle,x_pos, SLE_FILE_U16 | SLE_VAR_U32, 0, 5), + SLE_CONDVAR(Vehicle,x_pos, SLE_UINT32, 6, 255), + SLE_CONDVAR(Vehicle,y_pos, SLE_FILE_U16 | SLE_VAR_U32, 0, 5), + SLE_CONDVAR(Vehicle,y_pos, SLE_UINT32, 6, 255), SLE_VAR(Vehicle,z_pos, SLE_UINT8), SLE_VAR(Vehicle,direction, SLE_UINT8), @@ -1918,10 +1922,13 @@ static const byte _special_desc[] = { SLE_VAR(Vehicle,subtype, SLE_UINT8), - SLE_VAR(Vehicle,tile, SLE_UINT16), + SLE_CONDVAR(Vehicle,tile, SLE_FILE_U16 | SLE_VAR_U32, 0, 5), + SLE_CONDVAR(Vehicle,tile, SLE_UINT32, 6, 255), - SLE_VAR(Vehicle,x_pos, SLE_INT16), - SLE_VAR(Vehicle,y_pos, SLE_INT16), + SLE_CONDVAR(Vehicle,x_pos, SLE_FILE_I16 | SLE_VAR_I32, 0, 5), + SLE_CONDVAR(Vehicle,x_pos, SLE_INT32, 6, 255), + SLE_CONDVAR(Vehicle,y_pos, SLE_FILE_I16 | SLE_VAR_I32, 0, 5), + SLE_CONDVAR(Vehicle,y_pos, SLE_INT32, 6, 255), SLE_VAR(Vehicle,z_pos, SLE_UINT8), SLE_VAR(Vehicle,cur_image, SLE_UINT16), @@ -1948,11 +1955,15 @@ static const byte _disaster_desc[] = { SLE_REF(Vehicle,next, REF_VEHICLE_OLD), SLE_VAR(Vehicle,subtype, SLE_UINT8), - SLE_VAR(Vehicle,tile, SLE_UINT16), - SLE_VAR(Vehicle,dest_tile, SLE_UINT16), - - SLE_VAR(Vehicle,x_pos, SLE_INT16), - SLE_VAR(Vehicle,y_pos, SLE_INT16), + SLE_CONDVAR(Vehicle,tile, SLE_FILE_U16 | SLE_VAR_U32, 0, 5), + SLE_CONDVAR(Vehicle,tile, SLE_UINT32, 6, 255), + SLE_CONDVAR(Vehicle,dest_tile, SLE_FILE_U16 | SLE_VAR_U32, 0, 5), + SLE_CONDVAR(Vehicle,dest_tile, SLE_UINT32, 6, 255), + + SLE_CONDVAR(Vehicle,x_pos, SLE_FILE_I16 | SLE_VAR_I32, 0, 5), + SLE_CONDVAR(Vehicle,x_pos, SLE_INT32, 6, 255), + SLE_CONDVAR(Vehicle,y_pos, SLE_FILE_I16 | SLE_VAR_I32, 0, 5), + SLE_CONDVAR(Vehicle,y_pos, SLE_INT32, 6, 255), SLE_VAR(Vehicle,z_pos, SLE_UINT8), SLE_VAR(Vehicle,direction, SLE_UINT8), @@ -2069,7 +2080,8 @@ static void Load_VEHS(void) } static const byte _depot_desc[] = { - SLE_VAR(Depot,xy, SLE_UINT16), + SLE_CONDVAR(Depot, xy, SLE_FILE_U16 | SLE_VAR_U32, 0, 5), + SLE_CONDVAR(Depot, xy, SLE_UINT32, 6, 255), SLE_VAR(Depot,town_index, SLE_UINT16), SLE_END() }; @@ -2095,7 +2107,8 @@ static void Load_DEPT(void) } static const byte _waypoint_desc[] = { - SLE_VAR(Waypoint,xy, SLE_UINT16), + SLE_CONDVAR(Waypoint, xy, SLE_FILE_U16 | SLE_VAR_U32, 0, 5), + SLE_CONDVAR(Waypoint, xy, SLE_UINT32, 6, 255), SLE_VAR(Waypoint,town_or_string, SLE_UINT16), SLE_VAR(Waypoint,deleted, SLE_UINT8), @@ -102,8 +102,8 @@ struct Vehicle { TileIndex tile; // Current tile index TileIndex dest_tile; // Heading for this tile - int16 x_pos; // coordinates - int16 y_pos; + int32 x_pos; // coordinates + int32 y_pos; byte z_pos; byte direction; // facing |