saveload.c
changeset 2808 35e0e9c6c227
parent 2749 46aba09ca365
child 2828 996de8e891c7
equal deleted inserted replaced
2807:cdbe90044c33 2808:35e0e9c6c227
  1231 	return def;
  1231 	return def;
  1232 }
  1232 }
  1233 
  1233 
  1234 // actual loader/saver function
  1234 // actual loader/saver function
  1235 void InitializeGame(uint size_x, uint size_y);
  1235 void InitializeGame(uint size_x, uint size_y);
  1236 extern bool AfterLoadGame(uint version);
  1236 extern bool AfterLoadGame(void);
  1237 extern void BeforeSaveGame(void);
  1237 extern void BeforeSaveGame(void);
  1238 extern bool LoadOldSaveGame(const char *file);
  1238 extern bool LoadOldSaveGame(const char *file);
  1239 
  1239 
  1240 /** Small helper function to close the to be loaded savegame an signal error */
  1240 /** Small helper function to close the to be loaded savegame an signal error */
  1241 static inline SaveOrLoadResult AbortSaveLoad(void)
  1241 static inline SaveOrLoadResult AbortSaveLoad(void)
  1363 
  1363 
  1364 	/* Load a TTDLX or TTDPatch game */
  1364 	/* Load a TTDLX or TTDPatch game */
  1365 	if (mode == SL_OLD_LOAD) {
  1365 	if (mode == SL_OLD_LOAD) {
  1366 		InitializeGame(256, 256); // set a mapsize of 256x256 for TTDPatch games or it might get confused
  1366 		InitializeGame(256, 256); // set a mapsize of 256x256 for TTDPatch games or it might get confused
  1367 		if (!LoadOldSaveGame(filename)) return SL_REINIT;
  1367 		if (!LoadOldSaveGame(filename)) return SL_REINIT;
  1368 		AfterLoadGame(0);
  1368 		_sl_version = 0;
       
  1369 		AfterLoadGame();
  1369 		return SL_OK;
  1370 		return SL_OK;
  1370 	}
  1371 	}
  1371 
  1372 
  1372 	_sl.fh = fopen(filename, (mode == SL_SAVE) ? "wb" : "rb");
  1373 	_sl.fh = fopen(filename, (mode == SL_SAVE) ? "wb" : "rb");
  1373 	if (_sl.fh == NULL) {
  1374 	if (_sl.fh == NULL) {
  1492 		fmt->uninit_read();
  1493 		fmt->uninit_read();
  1493 		fclose(_sl.fh);
  1494 		fclose(_sl.fh);
  1494 
  1495 
  1495 		/* After loading fix up savegame for any internal changes that
  1496 		/* After loading fix up savegame for any internal changes that
  1496 		* might've occured since then. If it fails, load back the old game */
  1497 		* might've occured since then. If it fails, load back the old game */
  1497 		if (!AfterLoadGame(version)) return SL_REINIT;
  1498 		if (!AfterLoadGame()) return SL_REINIT;
  1498 	}
  1499 	}
  1499 
  1500 
  1500 	return SL_OK;
  1501 	return SL_OK;
  1501 }
  1502 }
  1502 
  1503