2004-01-06 13:44:17 +00:00
|
|
|
/* Copyright (C) 1994-2004 Revolution Software Ltd
|
2003-07-28 01:44:38 +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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*
|
|
|
|
* $Header$
|
|
|
|
*/
|
|
|
|
|
2003-11-16 14:18:29 +00:00
|
|
|
#include "common/stdafx.h"
|
2003-11-18 08:17:36 +00:00
|
|
|
#include "common/file.h"
|
2003-11-16 14:18:29 +00:00
|
|
|
#include "sword2/sword2.h"
|
2004-02-05 14:19:07 +00:00
|
|
|
#include "sword2/console.h"
|
|
|
|
#include "sword2/logic.h"
|
|
|
|
#include "sword2/maketext.h"
|
|
|
|
#include "sword2/resman.h"
|
|
|
|
#include "sword2/driver/d_sound.h"
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-11-19 18:40:53 +00:00
|
|
|
#define Debug_Printf _vm->_debugger->DebugPrintf
|
|
|
|
|
2003-10-04 00:52:27 +00:00
|
|
|
namespace Sword2 {
|
|
|
|
|
2003-11-04 18:02:49 +00:00
|
|
|
uint32 Logic::initStartMenu(void) {
|
2003-09-20 17:00:14 +00:00
|
|
|
// 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
|
|
|
|
// objects that are screen managers.
|
|
|
|
// We query each in turn and setup an array of start structures.
|
|
|
|
// If the file doesn't exist then we say so and return a 0.
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-11-18 08:17:36 +00:00
|
|
|
File fp;
|
|
|
|
|
2003-09-20 17:00:14 +00:00
|
|
|
uint32 pos = 0;
|
|
|
|
char *raw_script;
|
|
|
|
uint32 null_pc;
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-09-20 17:00:14 +00:00
|
|
|
char ascii_start_ids[MAX_starts][7];
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-09-20 17:00:14 +00:00
|
|
|
// ok, load in the master screen manager file
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-11-04 18:02:49 +00:00
|
|
|
_totalStartups = 0; // no starts
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-09-27 11:02:58 +00:00
|
|
|
debug(5, "initialising start menu");
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-11-18 08:17:36 +00:00
|
|
|
if (!fp.open("startup.inf")) {
|
|
|
|
warning("initStartMenu: cannot open startup.inf - the debugger won't have a start menu");
|
|
|
|
return 0;
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
|
|
|
|
2003-11-18 08:17:36 +00:00
|
|
|
// The startup.inf file which contains a list of all the files. Now
|
|
|
|
// extract the filenames
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
bool done = false;
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
byte b = fp.readByte();
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-11-18 08:17:36 +00:00
|
|
|
if (fp.ioFailed()) {
|
|
|
|
done = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Each item ends with CRLF
|
|
|
|
if (b == 13) {
|
|
|
|
fp.readByte();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pos < 7)
|
|
|
|
ascii_start_ids[_totalScreenManagers][pos] = b;
|
2003-07-28 01:44:38 +00:00
|
|
|
pos++;
|
2003-09-20 17:00:14 +00:00
|
|
|
}
|
|
|
|
|
2003-11-18 08:17:36 +00:00
|
|
|
if (done)
|
|
|
|
break;
|
|
|
|
|
2003-09-20 17:00:14 +00:00
|
|
|
// NULL terminate our extracted string
|
2003-11-04 18:02:49 +00:00
|
|
|
ascii_start_ids[_totalScreenManagers][pos] = 0;
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-09-20 17:00:14 +00:00
|
|
|
// reset position in current slot between entries
|
|
|
|
pos = 0;
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-09-20 17:00:14 +00:00
|
|
|
// done another
|
2003-11-04 18:02:49 +00:00
|
|
|
_totalScreenManagers++;
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-11-04 18:02:49 +00:00
|
|
|
if (_totalScreenManagers == MAX_starts) {
|
2003-09-27 11:02:58 +00:00
|
|
|
debug(5, "WARNING MAX_starts exceeded!");
|
2003-07-28 01:44:38 +00:00
|
|
|
break;
|
|
|
|
}
|
2003-11-18 08:17:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fp.close();
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-09-20 17:00:14 +00:00
|
|
|
// using this method the Gode generated resource.inf must have #0d0a
|
|
|
|
// on the last entry
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-11-04 18:02:49 +00:00
|
|
|
debug(5, "%d screen manager objects", _totalScreenManagers);
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-09-20 17:00:14 +00:00
|
|
|
// 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
|
|
|
|
// instance a startup could be set for later in the game where
|
|
|
|
// specific vars are set
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-11-18 08:17:36 +00:00
|
|
|
for (uint i = 0; i < _totalScreenManagers; i++) {
|
|
|
|
_startRes = atoi(ascii_start_ids[i]);
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-11-04 18:02:49 +00:00
|
|
|
debug(5, "+querying screen manager %d", _startRes);
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-09-20 17:00:14 +00:00
|
|
|
// resopen each one and run through the interpretter
|
|
|
|
// script 0 is the query request script
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-09-20 17:00:14 +00:00
|
|
|
// if the resource number is within range & it's not a null
|
2003-11-04 18:02:49 +00:00
|
|
|
// resource
|
2003-09-20 17:00:14 +00:00
|
|
|
// - need to check in case un-built sections included in
|
|
|
|
// start list
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-11-16 14:18:29 +00:00
|
|
|
if (_vm->_resman->checkValid(_startRes)) {
|
2003-11-04 18:02:49 +00:00
|
|
|
debug(5, "- resource %d ok", _startRes);
|
2003-11-16 14:18:29 +00:00
|
|
|
raw_script = (char *) _vm->_resman->openResource(_startRes);
|
2003-09-20 17:00:14 +00:00
|
|
|
null_pc = 0;
|
2003-11-04 18:02:49 +00:00
|
|
|
runScript(raw_script, raw_script, &null_pc);
|
2003-11-16 14:18:29 +00:00
|
|
|
_vm->_resman->closeResource(_startRes);
|
2003-09-20 17:00:14 +00:00
|
|
|
} else
|
2003-11-04 18:02:49 +00:00
|
|
|
debug(5, "- resource %d invalid", _startRes);
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
|
|
|
|
2003-09-20 17:00:14 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-10-18 08:11:50 +00:00
|
|
|
int32 Logic::fnRegisterStartPoint(int32 *params) {
|
2003-09-20 17:00:14 +00:00
|
|
|
// params: 0 id of startup script to call - key
|
|
|
|
// 1 pointer to ascii message
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-09-20 17:00:14 +00:00
|
|
|
#ifdef _SWORD2_DEBUG
|
2003-11-04 18:02:49 +00:00
|
|
|
if (_totalStartups == MAX_starts)
|
|
|
|
error("ERROR: _startList full");
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-09-20 17:00:14 +00:00
|
|
|
// +1 to allow for NULL terminator
|
2003-11-16 14:18:29 +00:00
|
|
|
if (strlen((const char *) _vm->_memory->intToPtr(params[1])) + 1 > MAX_description)
|
2003-10-26 15:42:49 +00:00
|
|
|
error("ERROR: startup description too long");
|
2003-09-20 17:00:14 +00:00
|
|
|
#endif
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-09-20 17:00:14 +00:00
|
|
|
// this objects id
|
2003-11-04 18:02:49 +00:00
|
|
|
_startList[_totalStartups].start_res_id = _startRes;
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-09-20 17:00:14 +00:00
|
|
|
// a key code to be passed to a script via a script var to SWITCH in
|
|
|
|
// the correct start
|
2003-11-04 18:02:49 +00:00
|
|
|
_startList[_totalStartups].key = params[0];
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-11-16 14:18:29 +00:00
|
|
|
strcpy(_startList[_totalStartups].description, (const char *) _vm->_memory->intToPtr(params[1]));
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-10-26 15:42:49 +00:00
|
|
|
// point to next
|
2003-11-04 18:02:49 +00:00
|
|
|
_totalStartups++;
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-09-20 17:00:14 +00:00
|
|
|
return 1;
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
|
|
|
|
2003-11-04 18:02:49 +00:00
|
|
|
void Logic::conPrintStartMenu(void) {
|
2003-09-20 17:00:14 +00:00
|
|
|
// the console 'starts' (or 's') command which lists out all the
|
|
|
|
// registered start points in the game
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-11-04 18:02:49 +00:00
|
|
|
if (!_totalStartups) {
|
2003-10-26 15:42:49 +00:00
|
|
|
Debug_Printf("Sorry - no startup positions registered?\n");
|
2003-09-20 17:00:14 +00:00
|
|
|
|
2003-11-04 18:02:49 +00:00
|
|
|
if (!_totalScreenManagers)
|
2003-10-26 15:42:49 +00:00
|
|
|
Debug_Printf("There is a problem with startup.inf\n");
|
2003-07-28 01:44:38 +00:00
|
|
|
else
|
2003-11-04 18:02:49 +00:00
|
|
|
Debug_Printf(" (%d screen managers found in startup.inf)\n", _totalScreenManagers);
|
2003-09-20 17:00:14 +00:00
|
|
|
} else {
|
2003-11-04 18:02:49 +00:00
|
|
|
for (uint i = 0; i < _totalStartups; i++)
|
|
|
|
Debug_Printf("%d (%s)\n", i, _startList[i].description);
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-11-04 18:02:49 +00:00
|
|
|
void Logic::conStart(int start) {
|
2003-09-20 17:00:14 +00:00
|
|
|
char *raw_script;
|
|
|
|
char *raw_data_ad;
|
|
|
|
uint32 null_pc;
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-11-04 18:02:49 +00:00
|
|
|
if (!_totalStartups)
|
2003-10-26 15:42:49 +00:00
|
|
|
Debug_Printf("Sorry - there are no startups!\n");
|
2003-11-04 18:02:49 +00:00
|
|
|
else if (start >= 0 && start < (int) _totalStartups) {
|
2003-10-26 15:42:49 +00:00
|
|
|
// do the startup as we've specified a legal start
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-10-26 15:42:49 +00:00
|
|
|
// restarting - stop sfx, music & speech!
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-11-08 15:47:51 +00:00
|
|
|
_vm->clearFxQueue();
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-10-26 15:42:49 +00:00
|
|
|
// fade out any music that is currently playing
|
2003-11-04 18:02:49 +00:00
|
|
|
fnStopMusic(NULL);
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-10-26 15:42:49 +00:00
|
|
|
// halt the sample prematurely
|
2003-11-16 14:18:29 +00:00
|
|
|
_vm->_sound->unpauseSpeech();
|
|
|
|
_vm->_sound->stopSpeech();
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-10-26 15:42:49 +00:00
|
|
|
// clean out all resources & flags, ready for a total
|
2003-11-04 18:02:49 +00:00
|
|
|
// restart
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-10-26 15:42:49 +00:00
|
|
|
// remove all resources from memory, including player
|
|
|
|
// object & global variables
|
2003-09-20 17:00:14 +00:00
|
|
|
|
2003-11-16 14:18:29 +00:00
|
|
|
_vm->_resman->removeAll();
|
2003-09-20 17:00:14 +00:00
|
|
|
|
2003-10-26 15:42:49 +00:00
|
|
|
// reopen global variables resource & send address to
|
|
|
|
// interpreter - it won't be moving
|
2003-12-28 15:08:12 +00:00
|
|
|
setGlobalInterpreterVariables((int32 *) (_vm->_resman->openResource(1) + sizeof(StandardHeader)));
|
2003-11-16 14:18:29 +00:00
|
|
|
_vm->_resman->closeResource(1);
|
2003-09-20 17:00:14 +00:00
|
|
|
|
2003-10-26 15:42:49 +00:00
|
|
|
// free all the route memory blocks from previous game
|
2003-11-15 09:38:00 +00:00
|
|
|
_router->freeAllRouteMem();
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-10-26 15:42:49 +00:00
|
|
|
// if there was speech text, kill the text block
|
2003-11-04 18:02:49 +00:00
|
|
|
if (_speechTextBlocNo) {
|
2003-11-16 14:18:29 +00:00
|
|
|
_vm->_fontRenderer->killTextBloc(_speechTextBlocNo);
|
2003-11-04 18:02:49 +00:00
|
|
|
_speechTextBlocNo = 0;
|
2003-10-26 15:42:49 +00:00
|
|
|
}
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-10-26 15:42:49 +00:00
|
|
|
// set the key
|
2003-09-20 17:00:14 +00:00
|
|
|
|
2003-10-26 15:42:49 +00:00
|
|
|
// Open George
|
2003-11-16 14:18:29 +00:00
|
|
|
raw_data_ad = (char *) _vm->_resman->openResource(8);
|
|
|
|
raw_script = (char *) _vm->_resman->openResource(_startList[start].start_res_id);
|
2003-09-20 17:00:14 +00:00
|
|
|
|
2003-10-26 15:42:49 +00:00
|
|
|
// denotes script to run
|
2003-11-04 18:02:49 +00:00
|
|
|
null_pc = _startList[start].key & 0xffff;
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-10-26 15:42:49 +00:00
|
|
|
Debug_Printf("Running start %d\n", start);
|
2003-11-04 18:02:49 +00:00
|
|
|
runScript(raw_script, raw_data_ad, &null_pc);
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-11-16 14:18:29 +00:00
|
|
|
_vm->_resman->closeResource(_startList[start].start_res_id);
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-10-26 15:42:49 +00:00
|
|
|
// Close George
|
2003-11-16 14:18:29 +00:00
|
|
|
_vm->_resman->closeResource(8);
|
2003-09-20 17:00:14 +00:00
|
|
|
|
2003-10-26 15:42:49 +00:00
|
|
|
// make sure thre's a mouse, in case restarting while
|
|
|
|
// mouse not available
|
2003-11-04 18:02:49 +00:00
|
|
|
fnAddHuman(NULL);
|
2003-10-26 15:42:49 +00:00
|
|
|
} else
|
|
|
|
Debug_Printf("Not a legal start position\n");
|
2003-09-20 17:00:14 +00:00
|
|
|
}
|
2003-10-04 00:52:27 +00:00
|
|
|
|
|
|
|
} // End of namespace Sword2
|