2007-05-30 21:56:52 +00:00
/* ScummVM - Graphic Adventure Engine
2006-05-23 23:43:52 +00:00
*
2007-05-30 21:56:52 +00:00
* ScummVM is the legal property of its developers , whose names
* are too numerous to list here . Please refer to the COPYRIGHT
* file distributed with this source distribution .
2006-05-23 23:43:52 +00:00
*
* This program is free software ; you can redistribute it and / or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation ; either version 2
* of the License , or ( at your option ) any later version .
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
* You should have received a copy of the GNU General Public License
* along with this program ; if not , write to the Free Software
* Foundation , Inc . , 51 Franklin Street , Fifth Floor , Boston , MA 02110 - 1301 , USA .
*
* $ URL $
* $ Id $
*
*/
/*
* Savegame support by Vasyl Tsvirkunov < vasyl @ pacbell . net >
* Multi - slots by Claudio Matsuoka < claudio @ helllabs . org >
*/
2008-11-10 19:02:47 +00:00
# include <time.h> // for extended infos
2007-09-19 08:40:12 +00:00
2006-12-06 19:27:02 +00:00
# include "common/file.h"
2008-11-10 19:02:47 +00:00
# include "graphics/thumbnail.h"
2006-05-23 23:43:52 +00:00
# include "agi/agi.h"
# include "agi/graphics.h"
# include "agi/sprite.h"
# include "agi/keyboard.h"
# include "agi/menu.h"
2008-11-10 19:02:47 +00:00
# define SAVEGAME_VERSION 4
2006-05-23 23:43:52 +00:00
/*
2007-01-12 02:29:20 +00:00
* Version 0 ( Sarien ) : view table has 64 entries
* Version 1 ( Sarien ) : view table has 256 entries ( needed in KQ3 )
* Version 2 ( ScummVM ) : first ScummVM version
2008-11-10 19:02:47 +00:00
* Version 3 ( ScummVM ) : added AGIPAL save / load support
2009-01-01 15:06:43 +00:00
* Version 4 ( ScummVM ) : added thumbnails and save creation date / time
2006-05-23 23:43:52 +00:00
*/
2007-01-12 02:29:20 +00:00
namespace Agi {
static const uint32 AGIflag = MKID_BE ( ' AGI : ' ) ;
2006-05-23 23:43:52 +00:00
2007-01-12 02:29:20 +00:00
int AgiEngine : : saveGame ( const char * fileName , const char * description ) {
char gameIDstring [ 8 ] = " gameIDX " ;
int i ;
Common : : OutSaveFile * out ;
2007-08-04 06:18:28 +00:00
int result = errOK ;
2006-05-23 23:43:52 +00:00
2007-01-12 02:29:20 +00:00
debugC ( 3 , kDebugLevelMain | kDebugLevelSavegame , " AgiEngine::saveGame(%s, %s) " , fileName , description ) ;
if ( ! ( out = _saveFileMan - > openForSaving ( fileName ) ) ) {
warning ( " Can't create file '%s', game not saved " , fileName ) ;
2007-01-16 12:40:51 +00:00
return errBadFileOpen ;
2007-01-12 02:29:20 +00:00
} else {
debugC ( 3 , kDebugLevelMain | kDebugLevelSavegame , " Successfully opened %s for writing " , fileName ) ;
}
out - > writeUint32BE ( AGIflag ) ;
out - > write ( description , 31 ) ;
2006-05-23 23:43:52 +00:00
2007-01-12 02:29:20 +00:00
out - > writeByte ( SAVEGAME_VERSION ) ;
debugC ( 5 , kDebugLevelMain | kDebugLevelSavegame , " Writing save game version (%d) " , SAVEGAME_VERSION ) ;
2006-05-23 23:43:52 +00:00
2008-11-10 19:02:47 +00:00
// Thumbnail
Graphics : : saveThumbnail ( * out ) ;
// Creation date/time
tm curTime ;
_system - > getTimeAndDate ( curTime ) ;
2008-11-29 18:01:16 +00:00
uint32 saveDate = ( ( curTime . tm_mday & 0xFF ) < < 24 ) | ( ( ( curTime . tm_mon + 1 ) & 0xFF ) < < 16 ) | ( ( curTime . tm_year + 1900 ) & 0xFFFF ) ;
uint16 saveTime = ( ( curTime . tm_hour & 0xFF ) < < 8 ) | ( ( curTime . tm_min ) & 0xFF ) ;
2008-11-10 19:02:47 +00:00
out - > writeUint32BE ( saveDate ) ;
debugC ( 5 , kDebugLevelMain | kDebugLevelSavegame , " Writing save date (%d) " , saveDate ) ;
out - > writeUint16BE ( saveTime ) ;
debugC ( 5 , kDebugLevelMain | kDebugLevelSavegame , " Writing save time (%d) " , saveTime ) ;
// TODO: played time
2007-01-16 12:40:51 +00:00
out - > writeByte ( _game . state ) ;
debugC ( 5 , kDebugLevelMain | kDebugLevelSavegame , " Writing game state (%d) " , _game . state ) ;
2007-09-19 08:40:12 +00:00
2007-01-16 12:40:51 +00:00
strcpy ( gameIDstring , _game . id ) ;
2007-01-12 02:29:20 +00:00
out - > write ( gameIDstring , 8 ) ;
2007-01-16 12:40:51 +00:00
debugC ( 5 , kDebugLevelMain | kDebugLevelSavegame , " Writing game id (%s, %s) " , gameIDstring , _game . id ) ;
2006-05-23 23:43:52 +00:00
for ( i = 0 ; i < MAX_FLAGS ; i + + )
2007-01-16 12:40:51 +00:00
out - > writeByte ( _game . flags [ i ] ) ;
2006-05-23 23:43:52 +00:00
for ( i = 0 ; i < MAX_VARS ; i + + )
2007-01-16 12:40:51 +00:00
out - > writeByte ( _game . vars [ i ] ) ;
2006-05-23 23:43:52 +00:00
2007-01-16 12:40:51 +00:00
out - > writeSint16BE ( ( int8 ) _game . horizon ) ;
out - > writeSint16BE ( ( int16 ) _game . lineStatus ) ;
out - > writeSint16BE ( ( int16 ) _game . lineUserInput ) ;
out - > writeSint16BE ( ( int16 ) _game . lineMinPrint ) ;
2007-01-12 02:29:20 +00:00
2007-01-16 12:40:51 +00:00
out - > writeSint16BE ( ( int16 ) _game . inputMode ) ;
out - > writeSint16BE ( ( int16 ) _game . lognum ) ;
2006-05-23 23:43:52 +00:00
2007-01-16 12:40:51 +00:00
out - > writeSint16BE ( ( int16 ) _game . playerControl ) ;
2008-09-30 12:27:38 +00:00
out - > writeSint16BE ( ( int16 ) shouldQuit ( ) ) ;
2007-01-16 12:40:51 +00:00
out - > writeSint16BE ( ( int16 ) _game . statusLine ) ;
out - > writeSint16BE ( ( int16 ) _game . clockEnabled ) ;
out - > writeSint16BE ( ( int16 ) _game . exitAllLogics ) ;
out - > writeSint16BE ( ( int16 ) _game . pictureShown ) ;
out - > writeSint16BE ( ( int16 ) _game . hasPrompt ) ;
out - > writeSint16BE ( ( int16 ) _game . gameFlags ) ;
2006-05-23 23:43:52 +00:00
2007-01-16 12:40:51 +00:00
out - > writeSint16BE ( ( int16 ) _game . inputEnabled ) ;
2007-01-12 02:29:20 +00:00
for ( i = 0 ; i < _HEIGHT ; i + + )
2007-01-16 12:40:51 +00:00
out - > writeByte ( _game . priTable [ i ] ) ;
2007-09-19 08:40:12 +00:00
2007-01-16 12:40:51 +00:00
out - > writeSint16BE ( ( int16 ) _game . gfxMode ) ;
out - > writeByte ( _game . cursorChar ) ;
out - > writeSint16BE ( ( int16 ) _game . colorFg ) ;
out - > writeSint16BE ( ( int16 ) _game . colorBg ) ;
2006-05-23 23:43:52 +00:00
2006-05-24 14:00:08 +00:00
/* game.hires */
2006-05-23 23:43:52 +00:00
/* game.sbuf */
/* game.ego_words */
/* game.num_ego_words */
2007-01-16 12:40:51 +00:00
out - > writeSint16BE ( ( int16 ) _game . numObjects ) ;
for ( i = 0 ; i < ( int16 ) _game . numObjects ; i + + )
out - > writeSint16BE ( ( int16 ) objectGetLocation ( i ) ) ;
2006-05-23 23:43:52 +00:00
/* game.ev_keyp */
for ( i = 0 ; i < MAX_STRINGS ; i + + )
2007-01-16 12:40:51 +00:00
out - > write ( _game . strings [ i ] , MAX_STRINGLEN ) ;
2006-05-23 23:43:52 +00:00
/* record info about loaded resources */
for ( i = 0 ; i < MAX_DIRS ; i + + ) {
2007-01-16 12:40:51 +00:00
out - > writeByte ( _game . dirLogic [ i ] . flags ) ;
out - > writeSint16BE ( ( int16 ) _game . logics [ i ] . sIP ) ;
out - > writeSint16BE ( ( int16 ) _game . logics [ i ] . cIP ) ;
2006-05-23 23:43:52 +00:00
}
for ( i = 0 ; i < MAX_DIRS ; i + + )
2007-01-16 12:40:51 +00:00
out - > writeByte ( _game . dirPic [ i ] . flags ) ;
2006-05-23 23:43:52 +00:00
for ( i = 0 ; i < MAX_DIRS ; i + + )
2007-01-16 12:40:51 +00:00
out - > writeByte ( _game . dirView [ i ] . flags ) ;
2006-05-23 23:43:52 +00:00
for ( i = 0 ; i < MAX_DIRS ; i + + )
2007-01-16 12:40:51 +00:00
out - > writeByte ( _game . dirSound [ i ] . flags ) ;
2006-05-23 23:43:52 +00:00
/* game.pictures */
/* game.logics */
/* game.views */
/* game.sounds */
for ( i = 0 ; i < MAX_VIEWTABLE ; i + + ) {
2007-01-16 12:40:51 +00:00
VtEntry * v = & _game . viewTable [ i ] ;
2006-05-23 23:43:52 +00:00
2007-01-16 12:40:51 +00:00
out - > writeByte ( v - > stepTime ) ;
out - > writeByte ( v - > stepTimeCount ) ;
2007-01-12 02:29:20 +00:00
out - > writeByte ( v - > entry ) ;
2007-01-16 12:40:51 +00:00
out - > writeSint16BE ( v - > xPos ) ;
out - > writeSint16BE ( v - > yPos ) ;
out - > writeByte ( v - > currentView ) ;
2006-05-23 23:43:52 +00:00
/* v->view_data */
2007-01-16 12:40:51 +00:00
out - > writeByte ( v - > currentLoop ) ;
out - > writeByte ( v - > numLoops ) ;
2006-05-23 23:43:52 +00:00
/* v->loop_data */
2007-01-16 12:40:51 +00:00
out - > writeByte ( v - > currentCel ) ;
out - > writeByte ( v - > numCels ) ;
2006-05-23 23:43:52 +00:00
/* v->cel_data */
/* v->cel_data_2 */
2007-01-16 12:40:51 +00:00
out - > writeSint16BE ( v - > xPos2 ) ;
out - > writeSint16BE ( v - > yPos2 ) ;
2006-05-23 23:43:52 +00:00
/* v->s */
2007-01-16 12:40:51 +00:00
out - > writeSint16BE ( v - > xSize ) ;
out - > writeSint16BE ( v - > ySize ) ;
out - > writeByte ( v - > stepSize ) ;
out - > writeByte ( v - > cycleTime ) ;
out - > writeByte ( v - > cycleTimeCount ) ;
2007-01-12 02:29:20 +00:00
out - > writeByte ( v - > direction ) ;
2006-05-23 23:43:52 +00:00
2007-01-12 02:29:20 +00:00
out - > writeByte ( v - > motion ) ;
out - > writeByte ( v - > cycle ) ;
out - > writeByte ( v - > priority ) ;
2006-05-23 23:43:52 +00:00
2007-01-12 02:29:20 +00:00
out - > writeUint16BE ( v - > flags ) ;
2006-05-23 23:43:52 +00:00
2007-01-12 02:29:20 +00:00
out - > writeByte ( v - > parm1 ) ;
out - > writeByte ( v - > parm2 ) ;
out - > writeByte ( v - > parm3 ) ;
out - > writeByte ( v - > parm4 ) ;
2006-05-23 23:43:52 +00:00
}
/* Save image stack */
2007-11-22 10:32:36 +00:00
for ( i = 0 ; i < _imageStack . size ( ) ; i + + ) {
ImageStackElement ise = _imageStack [ i ] ;
out - > writeByte ( ise . type ) ;
out - > writeSint16BE ( ise . parm1 ) ;
out - > writeSint16BE ( ise . parm2 ) ;
out - > writeSint16BE ( ise . parm3 ) ;
out - > writeSint16BE ( ise . parm4 ) ;
out - > writeSint16BE ( ise . parm5 ) ;
out - > writeSint16BE ( ise . parm6 ) ;
out - > writeSint16BE ( ise . parm7 ) ;
2006-05-23 23:43:52 +00:00
}
2007-01-12 02:29:20 +00:00
out - > writeByte ( 0 ) ;
2007-03-22 22:03:21 +00:00
//Write which file number AGIPAL is using (0 if not being used)
2007-03-22 22:29:00 +00:00
out - > writeSint16BE ( _gfx - > getAGIPalFileNum ( ) ) ;
2007-03-22 22:03:21 +00:00
2007-02-17 18:55:51 +00:00
out - > finalize ( ) ;
2007-08-04 06:18:28 +00:00
if ( out - > ioFailed ( ) ) {
2007-01-12 02:29:20 +00:00
warning ( " Can't write file '%s'. (Disk full?) " , fileName ) ;
2007-08-04 06:18:28 +00:00
result = errIOError ;
} else
2007-01-12 02:29:20 +00:00
debugC ( 1 , kDebugLevelMain | kDebugLevelSavegame , " Saved game %s in file %s " , description , fileName ) ;
2007-09-19 08:40:12 +00:00
2007-01-12 02:29:20 +00:00
delete out ;
debugC ( 3 , kDebugLevelMain | kDebugLevelSavegame , " Closed %s " , fileName ) ;
2008-08-10 22:53:43 +00:00
_lastSaveTime = _system - > getMillis ( ) ;
2007-08-04 06:18:28 +00:00
return result ;
2006-05-23 23:43:52 +00:00
}
2007-04-22 16:06:00 +00:00
int AgiEngine : : loadGame ( const char * fileName , bool checkId ) {
2007-01-12 02:29:20 +00:00
char description [ 31 ] , saveVersion , loadId [ 8 ] ;
2007-01-16 12:40:51 +00:00
int i , vtEntries = MAX_VIEWTABLE ;
2006-05-23 23:43:52 +00:00
uint8 t ;
int16 parm [ 7 ] ;
2007-01-12 02:29:20 +00:00
Common : : InSaveFile * in ;
2006-05-23 23:43:52 +00:00
2007-01-12 02:29:20 +00:00
debugC ( 3 , kDebugLevelMain | kDebugLevelSavegame , " AgiEngine::loadGame(%s) " , fileName ) ;
2006-05-23 23:43:52 +00:00
2007-01-12 02:29:20 +00:00
if ( ! ( in = _saveFileMan - > openForLoading ( fileName ) ) ) {
warning ( " Can't open file '%s', game not loaded " , fileName ) ;
2007-01-16 12:40:51 +00:00
return errBadFileOpen ;
2007-01-12 02:29:20 +00:00
} else {
debugC ( 3 , kDebugLevelMain | kDebugLevelSavegame , " Successfully opened %s for reading " , fileName ) ;
2006-05-23 23:43:52 +00:00
}
2007-01-12 02:29:20 +00:00
uint32 typea = in - > readUint32BE ( ) ;
if ( typea = = AGIflag ) {
debugC ( 6 , kDebugLevelMain | kDebugLevelSavegame , " Has AGI flag, good start " ) ;
} else {
warning ( " This doesn't appear to be an AGI savegame, game not restored " ) ;
2007-09-19 08:40:12 +00:00
delete in ;
2007-01-16 12:40:51 +00:00
return errOK ;
2007-09-19 08:40:12 +00:00
}
2007-01-12 02:29:20 +00:00
in - > read ( description , 31 ) ;
2007-09-19 08:40:12 +00:00
2007-01-12 02:29:20 +00:00
debugC ( 6 , kDebugLevelMain | kDebugLevelSavegame , " Description is: %s " , description ) ;
2007-09-19 08:40:12 +00:00
2007-01-12 02:29:20 +00:00
saveVersion = in - > readByte ( ) ;
2008-11-10 19:02:47 +00:00
if ( saveVersion < 2 ) // is the save game pre-ScummVM?
2007-01-12 02:29:20 +00:00
warning ( " Old save game version (%d, current version is %d). Will try and read anyway, but don't be surprised if bad things happen " , saveVersion , SAVEGAME_VERSION ) ;
2008-11-10 19:02:47 +00:00
if ( saveVersion < 3 )
warning ( " This save game contains no AGIPAL data, if the game is using the AGIPAL hack, it won't work correctly " ) ;
if ( saveVersion > = 4 ) {
// We don't need the thumbnail here, so just read it and discard it
Graphics : : Surface * thumbnail = new Graphics : : Surface ( ) ;
assert ( thumbnail ) ;
Graphics : : loadThumbnail ( * in , * thumbnail ) ;
delete thumbnail ;
thumbnail = 0 ;
in - > readUint32BE ( ) ; // save date
in - > readUint16BE ( ) ; // save time
// TODO: played time
}
2007-01-16 12:40:51 +00:00
_game . state = in - > readByte ( ) ;
2007-09-19 08:40:12 +00:00
2007-01-12 02:29:20 +00:00
in - > read ( loadId , 8 ) ;
2007-04-22 16:06:00 +00:00
if ( strcmp ( loadId , _game . id ) & & checkId ) {
2007-09-19 08:40:12 +00:00
delete in ;
2007-01-16 12:40:51 +00:00
warning ( " This save seems to be from a different AGI game (save from %s, running %s), not loaded " , loadId , _game . id ) ;
return errBadFileOpen ;
2006-05-23 23:43:52 +00:00
}
2009-01-07 20:18:38 +00:00
strncpy ( _game . id , loadId , 8 ) ;
2006-05-23 23:43:52 +00:00
for ( i = 0 ; i < MAX_FLAGS ; i + + )
2007-01-16 12:40:51 +00:00
_game . flags [ i ] = in - > readByte ( ) ;
2006-05-23 23:43:52 +00:00
for ( i = 0 ; i < MAX_VARS ; i + + )
2007-01-16 12:40:51 +00:00
_game . vars [ i ] = in - > readByte ( ) ;
2006-05-23 23:43:52 +00:00
2008-01-02 00:35:32 +00:00
setvar ( vFreePages , 255 ) ; // Set amount of free memory to the maximum value (Overwriting the just loaded value)
2007-01-16 12:40:51 +00:00
_game . horizon = in - > readSint16BE ( ) ;
_game . lineStatus = in - > readSint16BE ( ) ;
_game . lineUserInput = in - > readSint16BE ( ) ;
_game . lineMinPrint = in - > readSint16BE ( ) ;
2007-09-19 08:40:12 +00:00
2006-05-23 23:43:52 +00:00
/* These are never saved */
2007-01-16 12:40:51 +00:00
_game . cursorPos = 0 ;
_game . inputBuffer [ 0 ] = 0 ;
_game . echoBuffer [ 0 ] = 0 ;
_game . keypress = 0 ;
_game . inputMode = in - > readSint16BE ( ) ;
_game . lognum = in - > readSint16BE ( ) ;
_game . playerControl = in - > readSint16BE ( ) ;
2008-07-07 23:24:12 +00:00
if ( in - > readSint16BE ( ) )
2008-07-09 02:27:05 +00:00
quitGame ( ) ;
2007-01-16 12:40:51 +00:00
_game . statusLine = in - > readSint16BE ( ) ;
_game . clockEnabled = in - > readSint16BE ( ) ;
_game . exitAllLogics = in - > readSint16BE ( ) ;
_game . pictureShown = in - > readSint16BE ( ) ;
_game . hasPrompt = in - > readSint16BE ( ) ;
_game . gameFlags = in - > readSint16BE ( ) ;
_game . inputEnabled = in - > readSint16BE ( ) ;
2006-05-23 23:43:52 +00:00
for ( i = 0 ; i < _HEIGHT ; i + + )
2007-01-16 12:40:51 +00:00
_game . priTable [ i ] = in - > readByte ( ) ;
2006-12-06 19:27:02 +00:00
2007-01-16 12:40:51 +00:00
if ( _game . hasWindow )
closeWindow ( ) ;
2006-05-23 23:43:52 +00:00
2007-01-16 12:40:51 +00:00
_game . msgBoxTicks = 0 ;
_game . block . active = false ;
2006-05-23 23:43:52 +00:00
/* game.window - fixed by close_window() */
/* game.has_window - fixed by close_window() */
2007-01-16 12:40:51 +00:00
_game . gfxMode = in - > readSint16BE ( ) ;
_game . cursorChar = in - > readByte ( ) ;
_game . colorFg = in - > readSint16BE ( ) ;
_game . colorBg = in - > readSint16BE ( ) ;
2006-05-23 23:43:52 +00:00
2006-05-24 14:00:08 +00:00
/* game.hires - rebuilt from image stack */
2006-05-23 23:43:52 +00:00
/* game.sbuf - rebuilt from image stack */
/* game.ego_words - fixed by clean_input */
/* game.num_ego_words - fixed by clean_input */
2007-01-16 12:40:51 +00:00
_game . numObjects = in - > readSint16BE ( ) ;
for ( i = 0 ; i < ( int16 ) _game . numObjects ; i + + )
objectSetLocation ( i , in - > readSint16BE ( ) ) ;
2006-05-23 23:43:52 +00:00
/* Those are not serialized */
for ( i = 0 ; i < MAX_DIRS ; i + + ) {
2007-01-16 12:40:51 +00:00
_game . evKeyp [ i ] . occured = false ;
2006-05-23 23:43:52 +00:00
}
for ( i = 0 ; i < MAX_STRINGS ; i + + )
2007-01-16 12:40:51 +00:00
in - > read ( _game . strings [ i ] , MAX_STRINGLEN ) ;
2006-05-23 23:43:52 +00:00
for ( i = 0 ; i < MAX_DIRS ; i + + ) {
2007-01-12 02:29:20 +00:00
if ( in - > readByte ( ) & RES_LOADED )
agiLoadResource ( rLOGIC , i ) ;
2006-05-23 23:43:52 +00:00
else
2007-01-12 02:29:20 +00:00
agiUnloadResource ( rLOGIC , i ) ;
2007-01-16 12:40:51 +00:00
_game . logics [ i ] . sIP = in - > readSint16BE ( ) ;
_game . logics [ i ] . cIP = in - > readSint16BE ( ) ;
2006-05-23 23:43:52 +00:00
}
for ( i = 0 ; i < MAX_DIRS ; i + + ) {
2007-01-12 02:29:20 +00:00
if ( in - > readByte ( ) & RES_LOADED )
agiLoadResource ( rPICTURE , i ) ;
2006-05-23 23:43:52 +00:00
else
2007-01-12 02:29:20 +00:00
agiUnloadResource ( rPICTURE , i ) ;
2006-05-23 23:43:52 +00:00
}
for ( i = 0 ; i < MAX_DIRS ; i + + ) {
2007-01-12 02:29:20 +00:00
if ( in - > readByte ( ) & RES_LOADED )
agiLoadResource ( rVIEW , i ) ;
2006-05-23 23:43:52 +00:00
else
2007-01-12 02:29:20 +00:00
agiUnloadResource ( rVIEW , i ) ;
2006-05-23 23:43:52 +00:00
}
for ( i = 0 ; i < MAX_DIRS ; i + + ) {
2007-01-12 02:29:20 +00:00
if ( in - > readByte ( ) & RES_LOADED )
agiLoadResource ( rSOUND , i ) ;
2006-05-23 23:43:52 +00:00
else
2007-01-12 02:29:20 +00:00
agiUnloadResource ( rSOUND , i ) ;
2006-05-23 23:43:52 +00:00
}
/* game.pictures - loaded above */
/* game.logics - loaded above */
/* game.views - loaded above */
/* game.sounds - loaded above */
2007-01-16 12:40:51 +00:00
for ( i = 0 ; i < vtEntries ; i + + ) {
2007-02-03 21:37:52 +00:00
VtEntry * v = & _game . viewTable [ i ] ;
2006-05-23 23:43:52 +00:00
2007-01-16 12:40:51 +00:00
v - > stepTime = in - > readByte ( ) ;
v - > stepTimeCount = in - > readByte ( ) ;
2007-01-12 02:29:20 +00:00
v - > entry = in - > readByte ( ) ;
2007-01-16 12:40:51 +00:00
v - > xPos = in - > readSint16BE ( ) ;
v - > yPos = in - > readSint16BE ( ) ;
v - > currentView = in - > readByte ( ) ;
2006-05-23 23:43:52 +00:00
/* v->view_data - fixed below */
2007-01-16 12:40:51 +00:00
v - > currentLoop = in - > readByte ( ) ;
v - > numLoops = in - > readByte ( ) ;
2006-05-23 23:43:52 +00:00
/* v->loop_data - fixed below */
2007-01-16 12:40:51 +00:00
v - > currentCel = in - > readByte ( ) ;
v - > numCels = in - > readByte ( ) ;
2006-05-23 23:43:52 +00:00
/* v->cel_data - fixed below */
/* v->cel_data_2 - fixed below */
2007-01-16 12:40:51 +00:00
v - > xPos2 = in - > readSint16BE ( ) ;
v - > yPos2 = in - > readSint16BE ( ) ;
2006-05-23 23:43:52 +00:00
/* v->s - fixed below */
2007-01-16 12:40:51 +00:00
v - > xSize = in - > readSint16BE ( ) ;
v - > ySize = in - > readSint16BE ( ) ;
v - > stepSize = in - > readByte ( ) ;
v - > cycleTime = in - > readByte ( ) ;
v - > cycleTimeCount = in - > readByte ( ) ;
2007-01-12 02:29:20 +00:00
v - > direction = in - > readByte ( ) ;
2006-05-23 23:43:52 +00:00
2007-01-12 02:29:20 +00:00
v - > motion = in - > readByte ( ) ;
v - > cycle = in - > readByte ( ) ;
v - > priority = in - > readByte ( ) ;
2006-05-23 23:43:52 +00:00
2007-01-12 02:29:20 +00:00
v - > flags = in - > readUint16BE ( ) ;
2006-05-23 23:43:52 +00:00
2007-01-12 02:29:20 +00:00
v - > parm1 = in - > readByte ( ) ;
v - > parm2 = in - > readByte ( ) ;
v - > parm3 = in - > readByte ( ) ;
v - > parm4 = in - > readByte ( ) ;
2006-05-23 23:43:52 +00:00
}
2007-01-16 12:40:51 +00:00
for ( i = vtEntries ; i < MAX_VIEWTABLE ; i + + ) {
2007-02-03 21:37:52 +00:00
memset ( & _game . viewTable [ i ] , 0 , sizeof ( VtEntry ) ) ;
2006-05-23 23:43:52 +00:00
}
/* Fix some pointers in viewtable */
for ( i = 0 ; i < MAX_VIEWTABLE ; i + + ) {
2007-02-03 21:37:52 +00:00
VtEntry * v = & _game . viewTable [ i ] ;
2006-05-23 23:43:52 +00:00
2007-01-16 12:40:51 +00:00
if ( _game . dirView [ v - > currentView ] . offset = = _EMPTY )
2006-05-23 23:43:52 +00:00
continue ;
2007-01-16 12:40:51 +00:00
if ( ! ( _game . dirView [ v - > currentView ] . flags & RES_LOADED ) )
agiLoadResource ( rVIEW , v - > currentView ) ;
2006-05-23 23:43:52 +00:00
2007-01-16 12:40:51 +00:00
setView ( v , v - > currentView ) ; /* Fix v->view_data */
setLoop ( v , v - > currentLoop ) ; /* Fix v->loop_data */
setCel ( v , v - > currentCel ) ; /* Fix v->cel_data */
v - > celData2 = v - > celData ;
2006-05-23 23:43:52 +00:00
v - > s = NULL ; /* not sure if it is used... */
}
2007-01-16 12:40:51 +00:00
_sprites - > eraseBoth ( ) ;
2006-05-23 23:43:52 +00:00
/* Clear input line */
2006-12-06 19:27:02 +00:00
_gfx - > clearScreen ( 0 ) ;
2007-01-16 12:40:51 +00:00
writeStatus ( ) ;
2006-05-23 23:43:52 +00:00
/* Recreate background from saved image stack */
2007-01-16 12:40:51 +00:00
clearImageStack ( ) ;
2007-01-12 02:29:20 +00:00
while ( ( t = in - > readByte ( ) ) ! = 0 ) {
2006-05-23 23:43:52 +00:00
for ( i = 0 ; i < 7 ; i + + )
2007-01-12 02:29:20 +00:00
parm [ i ] = in - > readSint16BE ( ) ;
2007-01-16 12:40:51 +00:00
replayImageStackCall ( t , parm [ 0 ] , parm [ 1 ] , parm [ 2 ] ,
2006-05-23 23:43:52 +00:00
parm [ 3 ] , parm [ 4 ] , parm [ 5 ] , parm [ 6 ] ) ;
}
2007-09-19 08:40:12 +00:00
//Load AGIPAL Data
2007-03-22 22:29:00 +00:00
if ( saveVersion > = 3 )
2007-03-22 22:03:21 +00:00
_gfx - > setAGIPal ( in - > readSint16BE ( ) ) ;
2007-09-19 08:40:12 +00:00
delete in ;
2007-01-12 02:29:20 +00:00
debugC ( 3 , kDebugLevelMain | kDebugLevelSavegame , " Closed %s " , fileName ) ;
2006-05-23 23:43:52 +00:00
2007-01-16 12:40:51 +00:00
setflag ( fRestoreJustRan , true ) ;
2006-05-23 23:43:52 +00:00
2007-01-16 12:40:51 +00:00
_game . hasPrompt = 0 ; /* force input line repaint if necessary */
cleanInput ( ) ;
2006-05-23 23:43:52 +00:00
2007-01-16 12:40:51 +00:00
_sprites - > eraseBoth ( ) ;
_sprites - > blitBoth ( ) ;
_sprites - > commitBoth ( ) ;
_picture - > showPic ( ) ;
2006-12-06 19:27:02 +00:00
_gfx - > doUpdate ( ) ;
2006-05-23 23:43:52 +00:00
2007-01-16 12:40:51 +00:00
return errOK ;
2006-05-23 23:43:52 +00:00
}
2007-03-12 08:43:13 +00:00
# define NUM_SLOTS 100
# define NUM_VISIBLE_SLOTS 12
2006-05-23 23:43:52 +00:00
2007-01-12 02:29:20 +00:00
const char * AgiEngine : : getSavegameFilename ( int num ) {
static char saveLoadSlot [ 12 ] ;
2007-03-12 08:43:13 +00:00
sprintf ( saveLoadSlot , " %s.%.3d " , _targetName . c_str ( ) , num + _firstSlot ) ;
2007-01-12 02:29:20 +00:00
return saveLoadSlot ;
}
2007-03-12 08:43:13 +00:00
2007-03-12 19:19:30 +00:00
void AgiEngine : : getSavegameDescription ( int num , char * buf , bool showEmpty ) {
2007-03-12 08:43:13 +00:00
char fileName [ MAX_PATH ] ;
Common : : InSaveFile * in ;
2007-09-19 08:40:12 +00:00
2007-03-12 08:43:13 +00:00
debugC ( 4 , kDebugLevelMain | kDebugLevelSavegame , " Current game id is %s " , _targetName . c_str ( ) ) ;
sprintf ( fileName , " %s " , getSavegameFilename ( num ) ) ;
if ( ! ( in = _saveFileMan - > openForLoading ( fileName ) ) ) {
debugC ( 4 , kDebugLevelMain | kDebugLevelSavegame , " File %s does not exist " , fileName ) ;
2007-03-12 19:19:30 +00:00
if ( showEmpty )
strcpy ( buf , " (empty slot) " ) ;
else
* buf = 0 ;
2007-03-12 08:43:13 +00:00
} else {
debugC ( 4 , kDebugLevelMain | kDebugLevelSavegame , " Successfully opened %s for reading " , fileName ) ;
uint32 type = in - > readUint32BE ( ) ;
if ( type = = AGIflag ) {
debugC ( 6 , kDebugLevelMain | kDebugLevelSavegame , " Has AGI flag, good start " ) ;
in - > read ( buf , 31 ) ;
} else {
warning ( " This doesn't appear to be an AGI savegame " ) ;
strcpy ( buf , " (corrupt file) " ) ;
2007-09-19 08:40:12 +00:00
}
2007-03-12 08:43:13 +00:00
delete in ;
}
}
2007-09-19 08:40:12 +00:00
2007-01-12 02:29:20 +00:00
int AgiEngine : : selectSlot ( ) {
2006-05-23 23:43:52 +00:00
int i , key , active = 0 ;
int rc = - 1 ;
2007-03-12 08:43:13 +00:00
int hm = 1 , vm = 3 ; /* box margins */
2007-02-10 16:34:45 +00:00
int xmin , xmax , slotClicked ;
2007-03-12 08:43:13 +00:00
char desc [ NUM_VISIBLE_SLOTS ] [ 40 ] ;
2007-02-10 16:34:45 +00:00
int textCentre , buttonLength , buttonX [ 2 ] , buttonY ;
const char * buttonText [ ] = { " OK " , " Cancel " , NULL } ;
2006-05-23 23:43:52 +00:00
2007-03-12 08:43:13 +00:00
for ( i = 0 ; i < NUM_VISIBLE_SLOTS ; i + + ) {
getSavegameDescription ( i , desc [ i ] ) ;
2006-05-23 23:43:52 +00:00
}
2007-02-10 16:34:45 +00:00
textCentre = GFX_WIDTH / CHAR_LINES / 2 ;
buttonLength = 6 ;
buttonX [ 0 ] = ( textCentre - 3 * buttonLength / 2 ) * CHAR_COLS ;
buttonX [ 1 ] = ( textCentre + buttonLength / 2 ) * CHAR_COLS ;
buttonY = ( vm + 17 ) * CHAR_LINES ;
2007-09-19 08:40:12 +00:00
2007-02-10 16:34:45 +00:00
for ( i = 0 ; i < 2 ; i + + )
2007-07-10 18:32:24 +00:00
_gfx - > drawCurrentStyleButton ( buttonX [ i ] , buttonY , buttonText [ i ] , false , false , i = = 0 ) ;
2007-02-10 16:34:45 +00:00
2007-03-17 16:08:29 +00:00
AllowSyntheticEvents on ( this ) ;
2007-07-06 17:50:27 +00:00
int oldFirstSlot = _firstSlot + 1 ;
int oldActive = active + 1 ;
2007-03-17 16:08:29 +00:00
2008-12-19 17:31:14 +00:00
while ( ! shouldQuit ( ) ) {
2007-09-08 11:17:13 +00:00
int sbPos = 0 ;
2007-03-12 08:43:13 +00:00
2008-12-19 17:21:55 +00:00
// Use the extreme scrollbar positions only if the extreme
// slots are in sight. (We have to calculate this even if we
// don't redraw the save slots, because it's also used for
// clicking in the scrollbar.
if ( _firstSlot = = 0 )
sbPos = 1 ;
else if ( _firstSlot = = NUM_SLOTS - NUM_VISIBLE_SLOTS )
sbPos = NUM_VISIBLE_SLOTS - 2 ;
else {
sbPos = 2 + ( _firstSlot * ( NUM_VISIBLE_SLOTS - 4 ) ) / ( NUM_SLOTS - NUM_VISIBLE_SLOTS - 1 ) ;
if ( sbPos > = NUM_VISIBLE_SLOTS - 3 )
sbPos = NUM_VISIBLE_SLOTS - 3 ;
}
2007-07-06 17:50:27 +00:00
if ( oldFirstSlot ! = _firstSlot | | oldActive ! = active ) {
char dstr [ 64 ] ;
for ( i = 0 ; i < NUM_VISIBLE_SLOTS ; i + + ) {
sprintf ( dstr , " [%2d. %-28.28s] " , i + _firstSlot , desc [ i ] ) ;
printText ( dstr , 0 , hm + 1 , vm + 4 + i ,
( 40 - 2 * hm ) - 1 , i = = active ? MSG_BOX_COLOUR : MSG_BOX_TEXT ,
i = = active ? MSG_BOX_TEXT : MSG_BOX_COLOUR ) ;
}
2007-03-12 08:43:13 +00:00
2007-07-06 17:50:27 +00:00
char upArrow [ ] = " ^ " ;
char downArrow [ ] = " v " ;
char scrollBar [ ] = " " ;
for ( i = 1 ; i < NUM_VISIBLE_SLOTS - 1 ; i + + )
printText ( scrollBar , 35 , hm + 1 , vm + 4 + i , 1 , MSG_BOX_COLOUR , 7 , true ) ;
2007-03-12 08:43:13 +00:00
2007-07-06 17:50:27 +00:00
printText ( upArrow , 35 , hm + 1 , vm + 4 , 1 , 8 , 7 ) ;
printText ( downArrow , 35 , hm + 1 , vm + 4 + NUM_VISIBLE_SLOTS - 1 , 1 , 8 , 7 ) ;
printText ( scrollBar , 35 , hm + 1 , vm + 4 + sbPos , 1 , MSG_BOX_COLOUR , MSG_BOX_TEXT ) ;
2007-03-12 08:43:13 +00:00
2007-07-06 17:50:27 +00:00
oldActive = active ;
oldFirstSlot = _firstSlot ;
}
2007-09-19 08:40:12 +00:00
2006-12-06 19:27:02 +00:00
_gfx - > pollTimer ( ) ; /* msdos driver -> does nothing */
2007-01-16 12:40:51 +00:00
key = doPollKeyboard ( ) ;
2006-05-24 21:40:24 +00:00
switch ( key ) {
case KEY_ENTER :
rc = active ;
2007-01-16 12:40:51 +00:00
strncpy ( _game . strings [ MAX_STRINGS ] , desc [ i ] , MAX_STRINGLEN ) ;
2006-05-24 21:40:24 +00:00
goto press ;
case KEY_ESCAPE :
rc = - 1 ;
goto getout ;
case BUTTON_LEFT :
2007-02-10 16:34:45 +00:00
if ( _gfx - > testButton ( buttonX [ 0 ] , buttonY , buttonText [ 0 ] ) ) {
rc = active ;
strncpy ( _game . strings [ MAX_STRINGS ] , desc [ i ] , MAX_STRINGLEN ) ;
goto press ;
}
if ( _gfx - > testButton ( buttonX [ 1 ] , buttonY , buttonText [ 1 ] ) ) {
rc = - 1 ;
goto getout ;
}
2007-03-12 08:43:13 +00:00
slotClicked = ( ( int ) g_mouse . y - 1 ) / CHAR_COLS - ( vm + 4 ) ;
2007-02-10 16:34:45 +00:00
xmin = ( hm + 1 ) * CHAR_COLS ;
xmax = xmin + CHAR_COLS * 34 ;
if ( ( int ) g_mouse . x > = xmin & & ( int ) g_mouse . x < = xmax ) {
2007-09-19 08:40:12 +00:00
if ( slotClicked > = 0 & & slotClicked < NUM_VISIBLE_SLOTS )
2007-02-10 16:34:45 +00:00
active = slotClicked ;
}
2007-03-12 08:43:13 +00:00
xmin = ( hm + 36 ) * CHAR_COLS ;
xmax = xmin + CHAR_COLS ;
if ( ( int ) g_mouse . x > = xmin & & ( int ) g_mouse . x < = xmax ) {
if ( slotClicked > = 0 & & slotClicked < NUM_VISIBLE_SLOTS ) {
if ( slotClicked = = 0 )
keyEnqueue ( KEY_UP ) ;
else if ( slotClicked = = NUM_VISIBLE_SLOTS - 1 )
keyEnqueue ( KEY_DOWN ) ;
else if ( slotClicked < sbPos )
keyEnqueue ( KEY_UP_RIGHT ) ;
else if ( slotClicked > sbPos )
keyEnqueue ( KEY_DOWN_RIGHT ) ;
}
}
2006-05-24 21:40:24 +00:00
break ;
case KEY_DOWN :
active + + ;
2007-03-12 08:43:13 +00:00
if ( active > = NUM_VISIBLE_SLOTS ) {
if ( _firstSlot + NUM_VISIBLE_SLOTS < NUM_SLOTS ) {
_firstSlot + + ;
for ( i = 1 ; i < NUM_VISIBLE_SLOTS ; i + + )
memcpy ( desc [ i - 1 ] , desc [ i ] , sizeof ( desc [ 0 ] ) ) ;
getSavegameDescription ( NUM_VISIBLE_SLOTS - 1 , desc [ NUM_VISIBLE_SLOTS - 1 ] ) ;
}
active = NUM_VISIBLE_SLOTS - 1 ;
}
2006-05-24 21:40:24 +00:00
break ;
case KEY_UP :
active - - ;
2007-03-12 08:43:13 +00:00
if ( active < 0 ) {
active = 0 ;
if ( _firstSlot > 0 ) {
_firstSlot - - ;
for ( i = NUM_VISIBLE_SLOTS - 1 ; i > 0 ; i - - )
memcpy ( desc [ i ] , desc [ i - 1 ] , sizeof ( desc [ 0 ] ) ) ;
getSavegameDescription ( 0 , desc [ 0 ] ) ;
}
}
break ;
2007-09-19 08:40:12 +00:00
2007-03-12 08:43:13 +00:00
// Page Up/Down and mouse wheel scrolling all leave 'active'
// unchanged so that a visible slot will remain selected.
case WHEEL_DOWN :
if ( _firstSlot < NUM_SLOTS - NUM_VISIBLE_SLOTS ) {
_firstSlot + + ;
for ( i = 1 ; i < NUM_VISIBLE_SLOTS ; i + + )
memcpy ( desc [ i - 1 ] , desc [ i ] , sizeof ( desc [ 0 ] ) ) ;
getSavegameDescription ( NUM_VISIBLE_SLOTS - 1 , desc [ NUM_VISIBLE_SLOTS - 1 ] ) ;
}
break ;
case WHEEL_UP :
if ( _firstSlot > 0 ) {
_firstSlot - - ;
for ( i = NUM_VISIBLE_SLOTS - 1 ; i > 0 ; i - - )
memcpy ( desc [ i ] , desc [ i - 1 ] , sizeof ( desc [ 0 ] ) ) ;
getSavegameDescription ( 0 , desc [ 0 ] ) ;
}
break ;
case KEY_DOWN_RIGHT :
// This is probably triggered by Page Down.
_firstSlot + = NUM_VISIBLE_SLOTS ;
if ( _firstSlot > NUM_SLOTS - NUM_VISIBLE_SLOTS ) {
_firstSlot = NUM_SLOTS - NUM_VISIBLE_SLOTS ;
}
for ( i = 0 ; i < NUM_VISIBLE_SLOTS ; i + + )
getSavegameDescription ( i , desc [ i ] ) ;
break ;
case KEY_UP_RIGHT :
// This is probably triggered by Page Up.
_firstSlot - = NUM_VISIBLE_SLOTS ;
if ( _firstSlot < 0 ) {
_firstSlot = 0 ;
}
for ( i = 0 ; i < NUM_VISIBLE_SLOTS ; i + + )
getSavegameDescription ( i , desc [ i ] ) ;
2006-05-24 21:40:24 +00:00
break ;
2006-05-23 23:43:52 +00:00
}
2006-12-06 19:27:02 +00:00
_gfx - > doUpdate ( ) ;
2006-05-23 23:43:52 +00:00
}
press :
debugC ( 8 , kDebugLevelMain | kDebugLevelInput , " Button pressed: %d " , rc ) ;
getout :
2007-01-16 12:40:51 +00:00
closeWindow ( ) ;
2006-05-23 23:43:52 +00:00
return rc ;
}
2007-01-12 02:29:20 +00:00
int AgiEngine : : saveGameDialog ( ) {
char fileName [ MAX_PATH ] ;
2006-05-23 23:43:52 +00:00
char * desc ;
2006-05-24 19:51:37 +00:00
const char * buttons [ ] = { " Do as I say! " , " I regret " , NULL } ;
2006-05-23 23:43:52 +00:00
char dstr [ 200 ] ;
int rc , slot = 0 ;
2007-09-19 08:40:12 +00:00
int hm , vm , hp , vp ;
2006-05-23 23:43:52 +00:00
int w ;
2007-03-12 08:43:13 +00:00
hm = 1 ;
2006-05-23 23:43:52 +00:00
vm = 3 ;
hp = hm * CHAR_COLS ;
vp = vm * CHAR_LINES ;
w = ( 40 - 2 * hm ) - 1 ;
2007-01-12 02:29:20 +00:00
sprintf ( fileName , " %s " , getSavegameFilename ( slot ) ) ;
2006-05-23 23:43:52 +00:00
2008-08-10 22:53:43 +00:00
do {
drawWindow ( hp , vp , GFX_WIDTH - hp , GFX_HEIGHT - vp ) ;
printText ( " Select a slot in which you wish to \n save the game: " ,
0 , hm + 1 , vm + 1 , w , MSG_BOX_TEXT , MSG_BOX_COLOUR ) ;
slot = selectSlot ( ) ;
if ( slot = = 0 )
messageBox ( " That slot is for Autosave only. " ) ;
else if ( slot < 0 )
return errOK ;
}
while ( slot = = 0 ) ;
2006-05-23 23:43:52 +00:00
2007-01-16 12:40:51 +00:00
drawWindow ( hp , vp + 5 * CHAR_LINES , GFX_WIDTH - hp ,
2006-05-23 23:43:52 +00:00
GFX_HEIGHT - vp - 9 * CHAR_LINES ) ;
2007-01-16 12:40:51 +00:00
printText ( " Enter a description for this game: " ,
2006-05-23 23:43:52 +00:00
0 , hm + 1 , vm + 6 , w , MSG_BOX_TEXT , MSG_BOX_COLOUR ) ;
2006-12-06 19:27:02 +00:00
_gfx - > drawRectangle ( 3 * CHAR_COLS , 11 * CHAR_LINES - 1 ,
2006-05-23 23:43:52 +00:00
37 * CHAR_COLS , 12 * CHAR_LINES , MSG_BOX_TEXT ) ;
2006-12-06 19:27:02 +00:00
_gfx - > flushBlock ( 3 * CHAR_COLS , 11 * CHAR_LINES - 1 ,
2006-05-23 23:43:52 +00:00
37 * CHAR_COLS , 12 * CHAR_LINES ) ;
2007-03-12 19:19:30 +00:00
// The description field of the save/restore dialog holds 32 characters
// but we use four of them for the slot number. The input field is a
// bit wider than that, so we don't have to worry about leaving space
// for the cursor.
getString ( 2 , 11 , 28 , MAX_STRINGS ) ;
// If we're saving over an old slot, show the old description. We can't
// access that buffer directly, so we have to feed the characters to
// the input handler one at a time.
char name [ 40 ] ;
int numChars ;
getSavegameDescription ( slot , name , false ) ;
for ( numChars = 0 ; numChars < 28 & & name [ numChars ] ; numChars + + )
handleGetstring ( name [ numChars ] ) ;
_gfx - > printCharacter ( numChars + 3 , 11 , _game . cursorChar , MSG_BOX_COLOUR , MSG_BOX_TEXT ) ;
2006-05-23 23:43:52 +00:00
do {
2007-01-16 12:40:51 +00:00
mainCycle ( ) ;
} while ( _game . inputMode = = INPUT_GETSTRING ) ;
closeWindow ( ) ;
2006-05-23 23:43:52 +00:00
2007-01-16 12:40:51 +00:00
desc = _game . strings [ MAX_STRINGS ] ;
2006-05-23 23:43:52 +00:00
sprintf ( dstr , " Are you sure you want to save the game "
2007-03-12 08:43:13 +00:00
" described as: \n \n %s \n \n in slot %d? \n \n \n " , desc , slot + _firstSlot ) ;
2006-05-23 23:43:52 +00:00
2007-01-16 12:40:51 +00:00
rc = selectionBox ( dstr , buttons ) ;
2006-05-23 23:43:52 +00:00
if ( rc ! = 0 ) {
2007-01-16 12:40:51 +00:00
messageBox ( " Game NOT saved. " ) ;
return errOK ;
2006-05-23 23:43:52 +00:00
}
2007-01-12 02:29:20 +00:00
sprintf ( fileName , " %s " , getSavegameFilename ( slot ) ) ;
debugC ( 8 , kDebugLevelMain | kDebugLevelResources , " file is [%s] " , fileName ) ;
2006-05-23 23:43:52 +00:00
2007-08-04 06:18:28 +00:00
int result = saveGame ( fileName , desc ) ;
2006-05-23 23:43:52 +00:00
2007-08-04 06:18:28 +00:00
if ( result = = errOK )
messageBox ( " Game saved. " ) ;
else
messageBox ( " Error saving game. " ) ;
2006-05-23 23:43:52 +00:00
2007-08-04 06:18:28 +00:00
return result ;
2006-05-23 23:43:52 +00:00
}
2007-01-12 02:29:20 +00:00
int AgiEngine : : saveGameSimple ( ) {
char fileName [ MAX_PATH ] ;
2006-05-23 23:43:52 +00:00
2007-01-12 02:29:20 +00:00
sprintf ( fileName , " %s " , getSavegameFilename ( 0 ) ) ;
2007-08-04 06:18:28 +00:00
int result = saveGame ( fileName , " Default savegame " ) ;
if ( result ! = errOK )
messageBox ( " Error saving game. " ) ;
return result ;
2006-05-23 23:43:52 +00:00
}
2007-01-12 02:29:20 +00:00
int AgiEngine : : loadGameDialog ( ) {
char fileName [ MAX_PATH ] ;
2006-05-23 23:43:52 +00:00
int rc , slot = 0 ;
int hm , vm , hp , vp ; /* box margins */
int w ;
2007-03-12 08:43:13 +00:00
hm = 1 ;
2006-05-23 23:43:52 +00:00
vm = 3 ;
hp = hm * CHAR_COLS ;
vp = vm * CHAR_LINES ;
w = ( 40 - 2 * hm ) - 1 ;
2007-01-12 02:29:20 +00:00
sprintf ( fileName , " %s " , getSavegameFilename ( slot ) ) ;
2006-05-23 23:43:52 +00:00
2007-01-16 12:40:51 +00:00
_sprites - > eraseBoth ( ) ;
_sound - > stopSound ( ) ;
2006-05-23 23:43:52 +00:00
2007-01-16 12:40:51 +00:00
drawWindow ( hp , vp , GFX_WIDTH - hp , GFX_HEIGHT - vp ) ;
printText ( " Select a game which you wish to \n restore: " ,
2006-05-23 23:43:52 +00:00
0 , hm + 1 , vm + 1 , w , MSG_BOX_TEXT , MSG_BOX_COLOUR ) ;
2007-01-12 02:29:20 +00:00
slot = selectSlot ( ) ;
2006-05-23 23:43:52 +00:00
if ( slot < 0 ) {
2007-01-16 12:40:51 +00:00
messageBox ( " Game NOT restored. " ) ;
return errOK ;
2006-05-23 23:43:52 +00:00
}
2007-01-12 02:29:20 +00:00
sprintf ( fileName , " %s " , getSavegameFilename ( slot ) ) ;
2007-01-16 12:40:51 +00:00
if ( ( rc = loadGame ( fileName ) ) = = errOK ) {
messageBox ( " Game restored. " ) ;
_game . exitAllLogics = 1 ;
_menu - > enableAll ( ) ;
2007-01-12 02:29:20 +00:00
} else {
2007-01-16 12:40:51 +00:00
messageBox ( " Error restoring game. " ) ;
2007-01-12 02:29:20 +00:00
}
return rc ;
}
int AgiEngine : : loadGameSimple ( ) {
char fileName [ MAX_PATH ] ;
int rc = 0 ;
sprintf ( fileName , " %s " , getSavegameFilename ( 0 ) ) ;
2007-01-16 12:40:51 +00:00
_sprites - > eraseBoth ( ) ;
_sound - > stopSound ( ) ;
closeWindow ( ) ;
2006-05-23 23:43:52 +00:00
2007-01-16 12:40:51 +00:00
if ( ( rc = loadGame ( fileName ) ) = = errOK ) {
messageBox ( " Game restored. " ) ;
_game . exitAllLogics = 1 ;
_menu - > enableAll ( ) ;
2006-05-23 23:43:52 +00:00
} else {
2007-01-16 12:40:51 +00:00
messageBox ( " Error restoring game. " ) ;
2006-05-23 23:43:52 +00:00
}
return rc ;
}
2007-01-16 12:40:51 +00:00
} // End of namespace Agi