diff options
author | Torbjörn Andersson | 2004-04-27 08:59:58 +0000 |
---|---|---|
committer | Torbjörn Andersson | 2004-04-27 08:59:58 +0000 |
commit | 49fc62b4d0a3d905195fa70e34dd33b10a49c62f (patch) | |
tree | 8f940da0ae42873a9cf5007967d8c36a4c0b3255 /sword2/startup.cpp | |
parent | aaf508d4da5ac68a4d7d4fdae9b64983a7177654 (diff) | |
download | scummvm-rg350-49fc62b4d0a3d905195fa70e34dd33b10a49c62f.tar.gz scummvm-rg350-49fc62b4d0a3d905195fa70e34dd33b10a49c62f.tar.bz2 scummvm-rg350-49fc62b4d0a3d905195fa70e34dd33b10a49c62f.zip |
Cleanup
svn-id: r13649
Diffstat (limited to 'sword2/startup.cpp')
-rw-r--r-- | sword2/startup.cpp | 191 |
1 files changed, 80 insertions, 111 deletions
diff --git a/sword2/startup.cpp b/sword2/startup.cpp index 661d702b1b..f5899c1dc9 100644 --- a/sword2/startup.cpp +++ b/sword2/startup.cpp @@ -21,6 +21,7 @@ #include "common/file.h" #include "sword2/sword2.h" #include "sword2/console.h" +#include "sword2/interpreter.h" #include "sword2/logic.h" #include "sword2/maketext.h" #include "sword2/resman.h" @@ -30,7 +31,7 @@ namespace Sword2 { -uint32 Logic::initStartMenu(void) { +bool Logic::initStartMenu(void) { // Print out a list of all the start points available. // There should be a linc produced file called startup.txt. // This file should contain ascii numbers of all the resource game @@ -40,72 +41,60 @@ uint32 Logic::initStartMenu(void) { File fp; - uint32 pos = 0; - char *raw_script; - uint32 null_pc; - - char ascii_start_ids[MAX_starts][7]; - // ok, load in the master screen manager file - _totalStartups = 0; // no starts - - debug(5, "initialising start menu"); + _totalStartups = 0; if (!fp.open("startup.inf")) { - warning("initStartMenu: cannot open startup.inf - the debugger won't have a start menu"); - return 0; + warning("Cannot open startup.inf - the debugger won't have a start menu"); + return false; } // The startup.inf file which contains a list of all the files. Now // extract the filenames + int start_ids[MAX_starts]; + while (1) { bool done = false; - while (1) { - byte b = fp.readByte(); + start_ids[_totalScreenManagers] = 0; + + // Scan the string until the LF in CRLF + + int b; + + do { + b = fp.readByte(); if (fp.ioFailed()) { done = true; break; } - // Each item ends with CRLF - if (b == 13) { - fp.readByte(); - break; + if (isdigit(b)) { + start_ids[_totalScreenManagers] *= 10; + start_ids[_totalScreenManagers] += (b - '0'); } - - if (pos < 7) - ascii_start_ids[_totalScreenManagers][pos] = b; - pos++; - } + } while (b != 10); if (done) break; - // NULL terminate our extracted string - ascii_start_ids[_totalScreenManagers][pos] = 0; - - // reset position in current slot between entries - pos = 0; - - // done another _totalScreenManagers++; if (_totalScreenManagers == MAX_starts) { - debug(5, "WARNING MAX_starts exceeded!"); + warning("MAX_starts exceeded"); break; } } fp.close(); - // using this method the Gode generated resource.inf must have #0d0a + // Using this method the Gode generated resource.inf must have #0d0a // on the last entry - debug(5, "%d screen manager objects", _totalScreenManagers); + debug(1, "%d screen manager objects", _totalScreenManagers); // Open each object and make a query call. The object must fill in a // startup structure. It may fill in several if it wishes - for @@ -113,12 +102,12 @@ uint32 Logic::initStartMenu(void) { // specific vars are set for (uint i = 0; i < _totalScreenManagers; i++) { - _startRes = atoi(ascii_start_ids[i]); + _startRes = start_ids[i]; - debug(5, "+querying screen manager %d", _startRes); + debug(2, "Querying screen manager %d", _startRes); - // resopen each one and run through the interpretter - // script 0 is the query request script + // Open each one and run through the interpreter. Script 0 is + // the query request script // if the resource number is within range & it's not a null // resource @@ -126,13 +115,13 @@ uint32 Logic::initStartMenu(void) { // start list if (_vm->_resman->checkValid(_startRes)) { - debug(5, "- resource %d ok", _startRes); - raw_script = (char *) _vm->_resman->openResource(_startRes); - null_pc = 0; + char *raw_script = (char *) _vm->_resman->openResource(_startRes); + uint32 null_pc = 0; + runScript(raw_script, raw_script, &null_pc); _vm->_resman->closeResource(_startRes); } else - debug(5, "- resource %d invalid", _startRes); + warning("Start menu resource %d invalid", _startRes); } return 1; @@ -142,34 +131,26 @@ int32 Logic::fnRegisterStartPoint(int32 *params) { // params: 0 id of startup script to call - key // 1 pointer to ascii message -#ifdef _SWORD2_DEBUG - if (_totalStartups == MAX_starts) - error("ERROR: _startList full"); + assert(_totalStartups < MAX_starts); - // +1 to allow for NULL terminator - if (strlen((const char *) _vm->_memory->decodePtr(params[1])) + 1 > MAX_description) - error("ERROR: startup description too long"); -#endif + char *name = (char *) _vm->_memory->decodePtr(params[1]); - // this objects id _startList[_totalStartups].start_res_id = _startRes; - - // a key code to be passed to a script via a script var to SWITCH in - // the correct start _startList[_totalStartups].key = params[0]; - strcpy(_startList[_totalStartups].description, (const char *) _vm->_memory->decodePtr(params[1])); + strncpy(_startList[_totalStartups].description, name, MAX_description); + _startList[_totalStartups].description[MAX_description - 1] = 0; - // point to next _totalStartups++; - - return 1; + return IR_CONT; } -void Logic::conPrintStartMenu(void) { - // the console 'starts' (or 's') command which lists out all the - // registered start points in the game +/** + * The console 'starts' (or 's') command which lists out all the registered + * start points in the game. + */ +void Logic::conPrintStartMenu(void) { if (!_totalStartups) { Debug_Printf("Sorry - no startup positions registered?\n"); @@ -177,76 +158,64 @@ void Logic::conPrintStartMenu(void) { Debug_Printf("There is a problem with startup.inf\n"); else Debug_Printf(" (%d screen managers found in startup.inf)\n", _totalScreenManagers); - } else { - for (uint i = 0; i < _totalStartups; i++) - Debug_Printf("%d (%s)\n", i, _startList[i].description); + return; } + + for (uint i = 0; i < _totalStartups; i++) + Debug_Printf("%d (%s)\n", i, _startList[i].description); } void Logic::conStart(int start) { - char *raw_script; - char *raw_data_ad; - uint32 null_pc; - - if (!_totalStartups) + if (!_totalStartups) { Debug_Printf("Sorry - there are no startups!\n"); - else if (start >= 0 && start < (int) _totalStartups) { - // do the startup as we've specified a legal start - - // restarting - stop sfx, music & speech! - - _vm->clearFxQueue(); - - // fade out any music that is currently playing - fnStopMusic(NULL); - - // halt the sample prematurely - _vm->_sound->unpauseSpeech(); - _vm->_sound->stopSpeech(); + return; + } - // clean out all resources & flags, ready for a total - // restart + if (start < 0 || start >= (int) _totalStartups) { + Debug_Printf("Not a legal start position\n"); + return; + } - // remove all resources from memory, including player - // object & global variables + // Restarting - stop sfx, music & speech! - _vm->_resman->removeAll(); + _vm->clearFxQueue(); + fnStopMusic(NULL); + _vm->_sound->unpauseSpeech(); + _vm->_sound->stopSpeech(); - // reopen global variables resource & send address to - // interpreter - it won't be moving - _vm->_logic->resetScriptVars(); + // Remove all resources from memory, including player object and global + // variables - // free all the route memory blocks from previous game - _router->freeAllRouteMem(); + _vm->_resman->removeAll(); - // if there was speech text, kill the text block - if (_speechTextBlocNo) { - _vm->_fontRenderer->killTextBloc(_speechTextBlocNo); - _speechTextBlocNo = 0; - } + // Reopen global variables resource and send address to interpreter + _vm->_logic->resetScriptVars(); - // set the key + // Free all the route memory blocks from previous game + _router->freeAllRouteMem(); - // Open George - raw_data_ad = (char *) _vm->_resman->openResource(8); - raw_script = (char *) _vm->_resman->openResource(_startList[start].start_res_id); + // If there was speech text, kill the text block + if (_speechTextBlocNo) { + _vm->_fontRenderer->killTextBloc(_speechTextBlocNo); + _speechTextBlocNo = 0; + } - // denotes script to run - null_pc = _startList[start].key & 0xffff; + // Open George + char *raw_data_ad = (char *) _vm->_resman->openResource(8); + char *raw_script = (char *) _vm->_resman->openResource(_startList[start].start_res_id); - Debug_Printf("Running start %d\n", start); - runScript(raw_script, raw_data_ad, &null_pc); + // Denotes script to run + uint32 null_pc = _startList[start].key & 0xffff; - _vm->_resman->closeResource(_startList[start].start_res_id); + Debug_Printf("Running start %d\n", start); + runScript(raw_script, raw_data_ad, &null_pc); - // Close George - _vm->_resman->closeResource(8); + _vm->_resman->closeResource(_startList[start].start_res_id); + _vm->_resman->closeResource(8); - // make sure thre's a mouse, in case restarting while - // mouse not available - fnAddHuman(NULL); - } else - Debug_Printf("Not a legal start position\n"); + // Make sure there's a mouse, in case restarting while mouse not + // available + fnAddHuman(NULL); } } // End of namespace Sword2 |