src/saveload.cpp
changeset 7506 e52d89f5c7c1
parent 7476 7f086e4b2a76
child 7532 66c79dd999af
equal deleted inserted replaced
7505:94a7391e0377 7506:e52d89f5c7c1
    27 #include "network/network.h"
    27 #include "network/network.h"
    28 #include "variables.h"
    28 #include "variables.h"
    29 #include <setjmp.h>
    29 #include <setjmp.h>
    30 #include <list>
    30 #include <list>
    31 
    31 
    32 extern const uint16 SAVEGAME_VERSION = 67;
    32 extern const uint16 SAVEGAME_VERSION = 68;
    33 uint16 _sl_version;       ///< the major savegame version identifier
    33 uint16 _sl_version;       ///< the major savegame version identifier
    34 byte   _sl_minor_version; ///< the minor savegame version, DO NOT USE!
    34 byte   _sl_minor_version; ///< the minor savegame version, DO NOT USE!
    35 
    35 
    36 typedef void WriterProc(uint len);
    36 typedef void WriterProc(uint len);
    37 typedef uint ReaderProc();
    37 typedef uint ReaderProc();
   818 		SlSetLength(SlCalcObjLength(object, sld));
   818 		SlSetLength(SlCalcObjLength(object, sld));
   819 		if (_sl.need_length == NL_CALCLENGTH) return;
   819 		if (_sl.need_length == NL_CALCLENGTH) return;
   820 	}
   820 	}
   821 
   821 
   822 	for (; sld->cmd != SL_END; sld++) {
   822 	for (; sld->cmd != SL_END; sld++) {
   823 		void *ptr = GetVariableAddress(object, sld);
   823 		void *ptr = sld->global ? sld->address : GetVariableAddress(object, sld);
   824 		SlObjectMember(ptr, sld);
   824 		SlObjectMember(ptr, sld);
   825 	}
   825 	}
   826 }
   826 }
   827 
   827 
   828 /**
   828 /**
   829  * Save or Load (a list of) global variables
   829  * Save or Load (a list of) global variables
   830  * @param sldg The global variable that is being loaded or saved
   830  * @param sldg The global variable that is being loaded or saved
   831  */
   831  */
   832 void SlGlobList(const SaveLoadGlobVarList *sldg)
   832 void SlGlobList(const SaveLoadGlobVarList *sldg)
   833 {
   833 {
   834 	if (_sl.need_length != NL_NONE) {
   834 	SlObject(NULL, (const SaveLoad*)sldg);
   835 		SlSetLength(SlCalcObjLength(NULL, (const SaveLoad*)sldg));
       
   836 		if (_sl.need_length == NL_CALCLENGTH) return;
       
   837 	}
       
   838 
       
   839 	for (; sldg->cmd != SL_END; sldg++) {
       
   840 		SlObjectMember(sldg->address, (const SaveLoad*)sldg);
       
   841 	}
       
   842 }
   835 }
   843 
   836 
   844 /**
   837 /**
   845  * Do something of which I have no idea what it is :P
   838  * Do something of which I have no idea what it is :P
   846  * @param proc The callback procedure that is called
   839  * @param proc The callback procedure that is called
  1256 extern const ChunkHandler _industry_chunk_handlers[];
  1249 extern const ChunkHandler _industry_chunk_handlers[];
  1257 extern const ChunkHandler _economy_chunk_handlers[];
  1250 extern const ChunkHandler _economy_chunk_handlers[];
  1258 extern const ChunkHandler _animated_tile_chunk_handlers[];
  1251 extern const ChunkHandler _animated_tile_chunk_handlers[];
  1259 extern const ChunkHandler _newgrf_chunk_handlers[];
  1252 extern const ChunkHandler _newgrf_chunk_handlers[];
  1260 extern const ChunkHandler _group_chunk_handlers[];
  1253 extern const ChunkHandler _group_chunk_handlers[];
       
  1254 extern const ChunkHandler _cargopacket_chunk_handlers[];
  1261 
  1255 
  1262 static const ChunkHandler * const _chunk_handlers[] = {
  1256 static const ChunkHandler * const _chunk_handlers[] = {
  1263 	_misc_chunk_handlers,
  1257 	_misc_chunk_handlers,
  1264 	_setting_chunk_handlers,
  1258 	_setting_chunk_handlers,
  1265 	_veh_chunk_handlers,
  1259 	_veh_chunk_handlers,
  1274 	_station_chunk_handlers,
  1268 	_station_chunk_handlers,
  1275 	_player_chunk_handlers,
  1269 	_player_chunk_handlers,
  1276 	_animated_tile_chunk_handlers,
  1270 	_animated_tile_chunk_handlers,
  1277 	_newgrf_chunk_handlers,
  1271 	_newgrf_chunk_handlers,
  1278 	_group_chunk_handlers,
  1272 	_group_chunk_handlers,
       
  1273 	_cargopacket_chunk_handlers,
  1279 	NULL,
  1274 	NULL,
  1280 };
  1275 };
  1281 
  1276 
  1282 /* used to include a vehicle desc in another desc. */
  1277 /* used to include a vehicle desc in another desc. */
  1283 extern const SaveLoad _common_veh_desc[];
  1278 extern const SaveLoad _common_veh_desc[];
  1305 		case REF_STATION:   return ((const  Station*)obj)->index + 1;
  1300 		case REF_STATION:   return ((const  Station*)obj)->index + 1;
  1306 		case REF_TOWN:      return ((const     Town*)obj)->index + 1;
  1301 		case REF_TOWN:      return ((const     Town*)obj)->index + 1;
  1307 		case REF_ORDER:     return ((const    Order*)obj)->index + 1;
  1302 		case REF_ORDER:     return ((const    Order*)obj)->index + 1;
  1308 		case REF_ROADSTOPS: return ((const RoadStop*)obj)->index + 1;
  1303 		case REF_ROADSTOPS: return ((const RoadStop*)obj)->index + 1;
  1309 		case REF_ENGINE_RENEWS: return ((const EngineRenew*)obj)->index + 1;
  1304 		case REF_ENGINE_RENEWS: return ((const EngineRenew*)obj)->index + 1;
       
  1305 		case REF_CARGO_PACKET:  return ((const CargoPacket*)obj)->index + 1;
  1310 		default: NOT_REACHED();
  1306 		default: NOT_REACHED();
  1311 	}
  1307 	}
  1312 
  1308 
  1313 	return 0; // avoid compiler warning
  1309 	return 0; // avoid compiler warning
  1314 }
  1310 }
  1364 		}
  1360 		}
  1365 		case REF_ENGINE_RENEWS: {
  1361 		case REF_ENGINE_RENEWS: {
  1366 			if (!AddBlockIfNeeded(&_EngineRenew_pool, index))
  1362 			if (!AddBlockIfNeeded(&_EngineRenew_pool, index))
  1367 				error("EngineRenews: failed loading savegame: too many EngineRenews");
  1363 				error("EngineRenews: failed loading savegame: too many EngineRenews");
  1368 			return GetEngineRenew(index);
  1364 			return GetEngineRenew(index);
       
  1365 		}
       
  1366 		case REF_CARGO_PACKET: {
       
  1367 			if (!AddBlockIfNeeded(&_CargoPacket_pool, index))
       
  1368 				error("CargoPackets: failed loading savegame: too many Cargo packets");
       
  1369 			return GetCargoPacket(index);
  1369 		}
  1370 		}
  1370 
  1371 
  1371 		case REF_VEHICLE_OLD: {
  1372 		case REF_VEHICLE_OLD: {
  1372 			/* Old vehicles were saved differently:
  1373 			/* Old vehicles were saved differently:
  1373 			 * invalid vehicle was 0xFFFF,
  1374 			 * invalid vehicle was 0xFFFF,