[Scummvm-cvs-logs] CVS: scummvm/sword2 anims.cpp,1.56,1.57 build_display.cpp,1.54,1.55 console.cpp,1.40,1.41 controls.cpp,1.65,1.66 debug.cpp,1.35,1.36 defs.h,1.11,1.12 events.cpp,1.26,1.27 function.cpp,1.57,1.58 icons.cpp,1.33,1.34 interpreter.cpp,1.40,1.41 logic.cpp,1.41,1.42 logic.h,1.27,1.28 maketext.cpp,1.38,1.39 memory.cpp,1.23,1.24 mouse.cpp,1.53,1.54 resman.cpp,1.88,1.89 router.cpp,1.40,1.41 save_rest.cpp,1.49,1.50 scroll.cpp,1.17,1.18 sound.cpp,1.40,1.41 speech.cpp,1.58,1.59 startup.cpp,1.39,1.40 sword2.cpp,1.105,1.106 sync.cpp,1.18,1.19 walker.cpp,1.35,1.36

Torbj?rn Andersson eriktorbjorn at users.sourceforge.net
Wed Mar 17 01:13:06 CET 2004


Update of /cvsroot/scummvm/scummvm/sword2
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17744

Modified Files:
	anims.cpp build_display.cpp console.cpp controls.cpp debug.cpp 
	defs.h events.cpp function.cpp icons.cpp interpreter.cpp 
	logic.cpp logic.h maketext.cpp memory.cpp mouse.cpp resman.cpp 
	router.cpp save_rest.cpp scroll.cpp sound.cpp speech.cpp 
	startup.cpp sword2.cpp sync.cpp walker.cpp 
Log Message:
Use the same syntax for accessing script variables as BS1 does, i.e. now
it's Logic::_scriptVars[ID] instead of just ID. Apart from looking cool, it
makes it much easier to tell the difference between variables and constants
when looking at the code.

Of course, this sort of sweeping changes is jolly good for introducing
truly weird regressions, which is why I waited until after 0.6.0.


Index: anims.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/anims.cpp,v
retrieving revision 1.56
retrieving revision 1.57
diff -u -d -r1.56 -r1.57
--- anims.cpp	2 Mar 2004 07:02:31 -0000	1.56
+++ anims.cpp	17 Mar 2004 09:03:14 -0000	1.57
@@ -107,7 +107,7 @@
 		// 'testing_routines' object in George's Player Character
 		// section of linc
 
-		if (SYSTEM_TESTING_ANIMS) {
+		if (_scriptVars[SYSTEM_TESTING_ANIMS]) {
 			// if the resource number is within range & it's not
 			// a null resource
 
@@ -141,7 +141,7 @@
 #ifdef _SWORD2_DEBUG
 		// check that we haven't been passed a zero resource number
 		if (res == 0)
-			error("animate: %s (id %d) passed zero anim resource", _vm->fetchObjectName(ID), ID);
+			error("animate: %s (id %d) passed zero anim resource", _vm->fetchObjectName(_scriptVars[ID]), _scriptVars[ID]);
 #endif
 
 		// open anim file
@@ -173,7 +173,7 @@
 			ob_graphic->anim_pc = 0;
  	} else if (getSync()) {
 		// We've received a sync - return to script immediately
-		debug(5, "**sync stopped %d**", ID);
+		debug(5, "**sync stopped %d**", _scriptVars[ID]);
 
 		// If sync received, anim finishes right now (remaining on
 		// last frame). Quit animation, but continue script.
@@ -263,7 +263,7 @@
 #ifdef _SWORD2_DEBUG
 	// check that we haven't been passed a zero resource number
 	if (res == 0)
-		error("fnSetFrame: %s (id %d) passed zero anim resource", _vm->fetchObjectName(ID), ID);
+		error("fnSetFrame: %s (id %d) passed zero anim resource", _vm->fetchObjectName(_scriptsVars[ID]), _scriptsVars[ID]);
 #endif
 
 	// open the resource (& check it's valid)
@@ -679,7 +679,7 @@
 
 	MoviePlayer player(_vm);
 
-	if (_sequenceTextLines && !DEMO)
+	if (_sequenceTextLines && !_scriptVars[DEMO])
 		rv = player.play(filename, sequenceSpeechArray, leadOut);
 	else
 		rv = player.play(filename, NULL, leadOut);

Index: build_display.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/build_display.cpp,v
retrieving revision 1.54
retrieving revision 1.55
diff -u -d -r1.54 -r1.55
--- build_display.cpp	5 Feb 2004 14:19:03 -0000	1.54
+++ build_display.cpp	17 Mar 2004 09:03:14 -0000	1.55
@@ -465,7 +465,7 @@
 			frame_head->height);
 	}
 
-	if (SYSTEM_TESTING_ANIMS) {	// see anims.cpp
+	if (Logic::_scriptVars[SYSTEM_TESTING_ANIMS]) { // see anims.cpp
 		// bring the anim into the visible screen
 		// but leave extra pixel at edge for box
 		if (spriteInfo.x + spriteInfo.scaledWidth >= 639)
@@ -569,7 +569,7 @@
 	frame_head = fetchFrameHeader(file, ob_graph->anim_pc);
 
 	// update player graphic details for on-screen debug info
-	if (ID == CUR_PLAYER_ID) {
+	if (Logic::_scriptVars[ID] == CUR_PLAYER_ID) {
 		_debugger->_playerGraphic.type = ob_graph->type;
 		_debugger->_playerGraphic.anim_resource = ob_graph->anim_resource;
 		// counting 1st frame as 'frame 1'
@@ -659,10 +659,10 @@
 			// isn't same is current id
 			// then we don't want this "left over" pointer text
 
-			if (_mouseList[_curMouse].pointer_text && _mouseList[_curMouse].id != (int32) ID)
+			if (_mouseList[_curMouse].pointer_text && _mouseList[_curMouse].id != (int32) Logic::_scriptVars[ID])
 				_mouseList[_curMouse].pointer_text=0;
 
-			_mouseList[_curMouse].id = ID;
+			_mouseList[_curMouse].id = Logic::_scriptVars[ID];
 			// not using sprite as detection mask
 			_mouseList[_curMouse].anim_resource = 0;
 			_mouseList[_curMouse].anim_pc = 0;
@@ -776,11 +776,11 @@
 	_vm->_thisScreen.player_feet_y = ob_mega->feet_y;
 
 	// for the script
-	PLAYER_FEET_X = ob_mega->feet_x;
-	PLAYER_FEET_Y = ob_mega->feet_y;
-	PLAYER_CUR_DIR = ob_mega->current_dir;
+	_scriptVars[PLAYER_FEET_X] = ob_mega->feet_x;
+	_scriptVars[PLAYER_FEET_Y] = ob_mega->feet_y;
+	_scriptVars[PLAYER_CUR_DIR] = ob_mega->current_dir;
 
-	SCROLL_OFFSET_X = _vm->_thisScreen.scroll_offset_x;
+	_scriptVars[SCROLL_OFFSET_X] = _vm->_thisScreen.scroll_offset_x;
 
 	debug(5, "fnUpdatePlayerStats: %d %d", ob_mega->feet_x, ob_mega->feet_y);
 
@@ -829,7 +829,7 @@
 	// now work properly too!
 
 	// hut interior
-	if (LOCATION == 13) {
+	if (Logic::_scriptVars[LOCATION] == 13) {
 		// unpausing
 		if (palRes == -1) {
 			// restore whatever palette was last set (screen

Index: console.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/console.cpp,v
retrieving revision 1.40
retrieving revision 1.41
diff -u -d -r1.40 -r1.41
--- console.cpp	5 Feb 2004 14:19:03 -0000	1.40
+++ console.cpp	17 Mar 2004 09:03:14 -0000	1.41
@@ -118,13 +118,13 @@
 }
 
 void Debugger::varGet(int var) {
-	DebugPrintf("%d\n", VAR(var));
+	DebugPrintf("%d\n", Logic::_scriptVars[var]);
 }
 
 void Debugger::varSet(int var, int val) {
-	DebugPrintf("was %d, ", VAR(var));
-	VAR(var) = val;
-	DebugPrintf("now %d\n", VAR(var));
+	DebugPrintf("was %d, ", Logic::_scriptVars[var]);
+	Logic::_scriptVars[var] = val;
+	DebugPrintf("now %d\n", Logic::_scriptVars[var]);
 }
 
 void Debugger::preEnter() {

Index: controls.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/controls.cpp,v
retrieving revision 1.65
retrieving revision 1.66
diff -u -d -r1.65 -r1.66
--- controls.cpp	4 Mar 2004 08:03:32 -0000	1.65
+++ controls.cpp	17 Mar 2004 09:03:14 -0000	1.66
@@ -1617,10 +1617,10 @@
 	_vm->killMusic();
 
 	// In case we were dead - well we're not anymore!
-	DEAD = 0;
+	Logic::_scriptVars[DEAD] = 0;
 
 	// Restart the game. Clear all memory and reset the globals
-	temp_demo_flag = DEMO;
+	temp_demo_flag = Logic::_scriptVars[DEMO];
 
 	// Remove all resources from memory, including player object and
 	// global variables
@@ -1628,12 +1628,11 @@
 
 	// Reopen global variables resource & send address to interpreter -
 	// it won't be moving
-	_vm->_logic->setGlobalInterpreterVariables((int32 *) (_vm->_resman->openResource(1) + sizeof(StandardHeader)));
-	_vm->_resman->closeResource(1);
+	_vm->_logic->resetScriptVars();
 
-	DEMO = temp_demo_flag;
+	Logic::_scriptVars[DEMO] = temp_demo_flag;
 
-	// Rree all the route memory blocks from previous game
+	// Free all the route memory blocks from previous game
 	_vm->_logic->_router->freeAllRouteMem();
 
 	// Call the same function that first started us up

Index: debug.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/debug.cpp,v
retrieving revision 1.35
retrieving revision 1.36
diff -u -d -r1.35 -r1.36
--- debug.cpp	5 Feb 2004 14:19:03 -0000	1.35
+++ debug.cpp	17 Mar 2004 09:03:14 -0000	1.36
@@ -59,7 +59,6 @@
 	int32 showVarNo;		// for variable watching
 	int32 showVarPos;
 	int32 varNo;
-	int32 *varTable;
 
 	// clear the array of text block numbers for the debug text
 	clearDebugTextBlocks();
@@ -79,7 +78,7 @@
 	// mouse area coords
 
 	// defining a mouse area the easy way, by creating a box on-screen
-	if (_draggingRectangle || SYSTEM_TESTING_ANIMS) {
+	if (_draggingRectangle || Logic::_scriptVars[SYSTEM_TESTING_ANIMS]) {
 		// so we can see what's behind the lines
 		_rectFlicker = !_rectFlicker;
 
@@ -129,8 +128,8 @@
 
 	if (_displayTextNumbers) {
 		if (_textNumber) {
-			if (SYSTEM_TESTING_TEXT) {
-				if (SYSTEM_WANT_PREVIOUS_LINE)
+			if (Logic::_scriptVars[SYSTEM_TESTING_TEXT]) {
+				if (Logic::_scriptVars[SYSTEM_WANT_PREVIOUS_LINE])
 					sprintf(buf, "backwards");
 				else
  					sprintf(buf, "forwards");
@@ -151,8 +150,8 @@
 
 	// resource number currently being checking for animation
 
-	if (SYSTEM_TESTING_ANIMS) {
-		sprintf(buf, "trying resource %d", SYSTEM_TESTING_ANIMS);
+	if (Logic::_scriptVars[SYSTEM_TESTING_ANIMS]) {
+		sprintf(buf, "trying resource %d", Logic::_scriptVars[SYSTEM_TESTING_ANIMS]);
 		makeDebugTextBlock(buf, 0, 90);
 	}
 
@@ -167,13 +166,16 @@
 
 		// mouse coords & object pointed to
 
-		if (CLICKED_ID)
+		if (Logic::_scriptVars[CLICKED_ID])
 			sprintf(buf, "last click at %d,%d (id %d: %s)",
-				MOUSE_X, MOUSE_Y, CLICKED_ID,
-				_vm->fetchObjectName(CLICKED_ID));
+				Logic::_scriptVars[MOUSE_X],
+				Logic::_scriptVars[MOUSE_Y],
+				Logic::_scriptVars[CLICKED_ID],
+				_vm->fetchObjectName(Logic::_scriptVars[CLICKED_ID]));
 		else
 			sprintf(buf, "last click at %d,%d (---)",
-				MOUSE_X, MOUSE_Y);
+				Logic::_scriptVars[MOUSE_X],
+				Logic::_scriptVars[MOUSE_Y]);
 
  		makeDebugTextBlock(buf, 0, 15);
 
@@ -216,12 +218,12 @@
 
  		// location number
 
-		sprintf(buf, "location=%d", LOCATION);
+		sprintf(buf, "location=%d", Logic::_scriptVars[LOCATION]);
 		makeDebugTextBlock(buf, 440, 15);
 
  		// "result" variable
 
-		sprintf(buf, "result=%d", RESULT);
+		sprintf(buf, "result=%d", Logic::_scriptVars[RESULT]);
 		makeDebugTextBlock(buf, 440, 30);
 
  		// no. of events in event list
@@ -272,9 +274,6 @@
 
 		showVarPos = 115;	// y-coord for first showVar
 
-		// res 1 is the global variables resource
-		varTable = (int32 *) (_vm->_resman->openResource(1) + sizeof(StandardHeader));
-
 		for (showVarNo = 0; showVarNo < MAX_SHOWVARS; showVarNo++) {
 			varNo = _showVar[showVarNo];	// get variable number
 
@@ -282,14 +281,12 @@
 			// anyway because it changes throughout the logic loop
 
 			if (varNo) {
-				sprintf(buf, "var(%d) = %d", varNo, varTable[varNo]);
+				sprintf(buf, "var(%d) = %d", varNo, Logic::_scriptVars[varNo]);
 				makeDebugTextBlock(buf, 530, showVarPos);
 				showVarPos += 15;	// next line down
 			}
 		}
 
-		_vm->_resman->closeResource(1);	// close global variables resource
-
 		// memory indicator - this should come last, to show all the
 		// sprite blocks above!
 
@@ -316,7 +313,7 @@
 
    	// mouse area rectangle / sprite box rectangle when testing anims
 
-	if (SYSTEM_TESTING_ANIMS) {
+	if (Logic::_scriptVars[SYSTEM_TESTING_ANIMS]) {
 		// draw box around current frame
 		drawRect(_rectX1, _rectY1, _rectX2, _rectY2, 184);
 	} else if (_draggingRectangle) {

Index: defs.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/defs.h,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- defs.h	6 Jan 2004 13:44:17 -0000	1.11
+++ defs.h	17 Mar 2004 09:03:14 -0000	1.12
@@ -23,119 +23,123 @@
 #define	SIZE	0x10000			// 65536 items per section
 #define	NuSIZE	0xffff			// & with this
 
-// global variable references
-// NB. 4 * <number from linc's Global Variables list>
-
-#define VAR(n)				(*(uint32 *) (g_sword2->_resman->_resList[1]->ad + sizeof(StandardHeader) + 4 * (n)))
-
-#define ID				VAR(0)
-#define RESULT				VAR(1)
-#define PLAYER_ACTION			VAR(2)
-// #define CUR_PLAYER_ID		VAR(3)
 // always 8 (George object used for Nico player character as well)
-#define	CUR_PLAYER_ID			8
-#define PLAYER_ID			VAR(305)
-#define TALK_FLAG			VAR(13)
+#define CUR_PLAYER_ID 8
 
-#define MOUSE_X				VAR(4)
-#define MOUSE_Y				VAR(5)
-#define LEFT_BUTTON			VAR(109)
-#define RIGHT_BUTTON			VAR(110)
-#define CLICKED_ID			VAR(178)
+// global variable references
 
-#define IN_SUBJECT			VAR(6)
-#define COMBINE_BASE			VAR(7)
-#define OBJECT_HELD			VAR(14)
+enum {
+	ID				= 0,
+	RESULT				= 1,
+	PLAYER_ACTION			= 2,
+	// CUR_PLAYER_ID		= 3,
+	PLAYER_ID			= 305,
+	TALK_FLAG			= 13,
 
-#define SPEECH_ID			VAR(9)
-#define INS1				VAR(10)
-#define INS2				VAR(11)
-#define INS3				VAR(12)
-#define INS4				VAR(60)
-#define INS5				VAR(61)
-#define INS_COMMAND			VAR(59)
+	MOUSE_X				= 4,
+	MOUSE_Y				= 5,
+	LEFT_BUTTON			= 109,
+	RIGHT_BUTTON			= 110,
+	CLICKED_ID			= 178,
 
-#define PLAYER_FEET_X			VAR(141)
-#define PLAYER_FEET_Y			VAR(142)
-#define PLAYER_CUR_DIR			VAR(937)
+	IN_SUBJECT			= 6,
+	COMBINE_BASE			= 7,
+	OBJECT_HELD			= 14,
 
-// for debug.cpp
-#define LOCATION			VAR(62)
+	SPEECH_ID			= 9,
+	INS1				= 10,
+	INS2				= 11,
+	INS3				= 12,
+	INS4				= 60,
+	INS5				= 61,
+	INS_COMMAND			= 59,
 
-// so scripts can force scroll offsets
-#define SCROLL_X			VAR(345)
-#define SCROLL_Y			VAR(346)
+	PLAYER_FEET_X			= 141,
+	PLAYER_FEET_Y			= 142,
+	PLAYER_CUR_DIR			= 937,
 
-#define EXIT_CLICK_ID			VAR(710)
-#define EXIT_FADING			VAR(713)
+	// for debug.cpp
+	LOCATION			= 62,
 
-#define SYSTEM_TESTING_ANIMS		VAR(912)
-#define SYSTEM_TESTING_TEXT		VAR(1230)
-#define SYSTEM_WANT_PREVIOUS_LINE	VAR(1245)
+	// so scripts can force scroll offsets
+	SCROLL_X			= 345,
+	SCROLL_Y			= 346,
 
-// 1=on 0=off (set in fnAddHuman and fnNoHuman)
-#define MOUSE_AVAILABLE			VAR(686)
+	EXIT_CLICK_ID			= 710,
+	EXIT_FADING			= 713,
 
-// used in fnChoose
-#define AUTO_SELECTED			VAR(1115)
+	SYSTEM_TESTING_ANIMS		= 912,
+	SYSTEM_TESTING_TEXT		= 1230,
+	SYSTEM_WANT_PREVIOUS_LINE	= 1245,
 
-// see fnStartConversation and fnChooser
-#define CHOOSER_COUNT_FLAG		VAR(15)
+	// 1=on 0=off (set in fnAddHuman and fnNoHuman)
+	MOUSE_AVAILABLE			= 686,
 
-// signifies a demo mode
-#define DEMO				VAR(1153)
+	// used in fnChoose
+	AUTO_SELECTED			= 1115,
 
-// Indicates to script whether this is the Playstation version.
-// #define PSXFLAG			VAR(1173)
+	// see fnStartConversation and fnChooser
+	CHOOSER_COUNT_FLAG		= 15,
 
-// 1 = dead
-#define DEAD				VAR(1256)
+	// signifies a demo mode
+	DEMO				= 1153,
 
- // If set indicates that the speech anim is to run through only once.
-#define SPEECHANIMFLAG			VAR(1278)
+	// Indicates to script whether this is the Playstation version.
+	// PSXFLAG			= 1173,
 
-// for the engine
-#define SCROLL_OFFSET_X			VAR(1314)
+	// for the poor PSX so it knows what language is running.
+	// GAME_LANGUAGE		= 111,
 
-// for the poor PSX so it knows what language is running.
-// #define GAME_LANGUAGE		VAR(111)
+	// 1 = dead
+	DEAD				= 1256,
 
-// resource id's of pouse mointers. It's pretty much safe to do it like this
+	// If set indicates that the speech anim is to run through only once.
+	SPEECHANIMFLAG			= 1278,
 
-#define NORMAL_MOUSE_ID			17
-#define SCROLL_LEFT_MOUSE_ID		1440
-#define SCROLL_RIGHT_MOUSE_ID		1441
+	// for the engine
+	SCROLL_OFFSET_X			= 1314
+};
 
-// Console Font - does not use game text - only English required
-#define CONSOLE_FONT_ID			340		// ConsFont
+// Resource IDs
 
-// Speech Font
-#define ENGLISH_SPEECH_FONT_ID		341		// SpchFont
-#define FINNISH_SPEECH_FONT_ID		956		// FinSpcFn
-#define POLISH_SPEECH_FONT_ID		955		// PolSpcFn
+enum {
+	// mouse mointers - It's pretty much safe to do it like this
+	NORMAL_MOUSE_ID			= 17,
+	SCROLL_LEFT_MOUSE_ID		= 1440,
+	SCROLL_RIGHT_MOUSE_ID		= 1441,
 
-// Control Panel Font (and un-selected savegame descriptions)
-#define ENGLISH_CONTROLS_FONT_ID	2005		// Sfont
-#define FINNISH_CONTROLS_FONT_ID	959		// FinSavFn
-#define POLISH_CONTROLS_FONT_ID		3686		// PolSavFn
+	// Console Font - does not use game text - only English required
+	CONSOLE_FONT_ID			= 340,
 
-// Red Font (for selected savegame descriptions)
-#define ENGLISH_RED_FONT_ID		2005		// 1998	// Redfont
-#define FINNISH_RED_FONT_ID		959		// 960	// FinRedFn
-#define POLISH_RED_FONT_ID		3686		// 3688	// PolRedFn
+	// Speech Font
+	ENGLISH_SPEECH_FONT_ID		= 341,
+	FINNISH_SPEECH_FONT_ID		= 956,
+	POLISH_SPEECH_FONT_ID		= 955,
 
-// Control panel palette resource id
+	// Control Panel Font (and un-selected savegame descriptions)
+	ENGLISH_CONTROLS_FONT_ID	= 2005,
+	FINNISH_CONTROLS_FONT_ID	= 959,
+	POLISH_CONTROLS_FONT_ID		= 3686,
 
-#define CONTROL_PANEL_PALETTE		261
+	// Red Font (for selected savegame descriptions)
+	// BS2 doesn't draw selected savegames in red, so I guess this is a
+	// left-over from BS1
+	ENGLISH_RED_FONT_ID		= 2005,		// 1998	// Redfont
+	FINNISH_RED_FONT_ID		= 959,		// 960	// FinRedFn
+	POLISH_RED_FONT_ID		= 3686,		// 3688	// PolRedFn
 
-// res id's of the system menu icons
-#define OPTIONS_ICON			344
-#define QUIT_ICON			335
-#define SAVE_ICON			366
-#define RESTORE_ICON			364
-#define RESTART_ICON			342
+	// Control panel palette resource id
+	CONTROL_PANEL_PALETTE		= 261,
 
-// res id of conversation exit icon, 'EXIT' menu icon (used in fnChoose)
-#define EXIT_ICON			65
+	// res id's of the system menu icons
+	OPTIONS_ICON			= 344,
+	QUIT_ICON			= 335,
+	SAVE_ICON			= 366,
+	RESTORE_ICON			= 364,
+	RESTART_ICON			= 342,
+
+	// conversation exit icon, 'EXIT' menu icon (used in fnChoose)
+	EXIT_ICON			= 65
+};
 
 #endif

Index: events.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/events.cpp,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -d -r1.26 -r1.27
--- events.cpp	5 Feb 2004 14:19:03 -0000	1.26
+++ events.cpp	17 Mar 2004 09:03:14 -0000	1.27
@@ -66,7 +66,7 @@
 
 bool Logic::checkEventWaiting(void) {
 	for (int i = 0; i < MAX_events; i++) {
-		if (_eventList[i].id == ID)
+		if (_eventList[i].id == _scriptVars[ID])
 			return true;
 	}
 
@@ -78,7 +78,7 @@
 	// you must follow with a return IR_TERMINATE
 
 	for (int i = 0; i < MAX_events; i++) {
-		if (_eventList[i].id == ID) {
+		if (_eventList[i].id == _scriptVars[ID]) {
 			// run 3rd script of target object on level 1
 			logicOne(_eventList[i].interact_id);
 
@@ -89,7 +89,7 @@
 	}
 
 	// oh dear - stop the system
-	error("Start_event can't find event for id %d", ID);
+	error("Start_event can't find event for id %d", _scriptVars[ID]);
 }
 
 void Logic::clearEvent(uint32 id) {
@@ -149,14 +149,14 @@
 }
 
 int32 Logic::fnCheckEventWaiting(int32 *params) {
-	// returns yes/no in RESULT
+	// returns yes/no in _scriptVars[RESULT]
 
 	// params:	none
 
 	if (checkEventWaiting())
-		RESULT = 1;
+		_scriptVars[RESULT] = 1;
 	else
-		RESULT = 0;
+		_scriptVars[RESULT] = 0;
 
 	return IR_CONT;
 }
@@ -219,7 +219,7 @@
 int32 Logic::fnClearEvent(int32 *params) {
 	// params:	none
 
-	clearEvent(ID);
+	clearEvent(_scriptVars[ID]);
 	return IR_CONT;
 }
 

Index: function.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/function.cpp,v
retrieving revision 1.57
retrieving revision 1.58
diff -u -d -r1.57 -r1.58
--- function.cpp	1 Mar 2004 00:32:47 -0000	1.57
+++ function.cpp	17 Mar 2004 09:03:14 -0000	1.58
@@ -58,7 +58,7 @@
 	// params:	0 id of script
 
 	// must clear this
-	PLAYER_ACTION = 0;
+	_scriptVars[PLAYER_ACTION] = 0;
 
 	logicReplace(params[0]);
 	return IR_TERMINATE;
@@ -72,7 +72,7 @@
 	//		  reference
 
 	// must clear this
-	PLAYER_ACTION = 0;
+	_scriptVars[PLAYER_ACTION] = 0;
 
 	// 3rd script of clicked on id
 	logicUp((params[0] < 16) + 2);
@@ -127,12 +127,12 @@
 
 int32 Logic::fnRandom(int32 *params) {
 	// Generates a random number between 'min' & 'max' inclusive, and
-	// sticks it in the script flag 'result'
+	// sticks it in _scriptVars[RESULT]
 
 	// params:	0 min
 	//		1 max
 
-	RESULT = _vm->_rnd.getRandomNumberRng(params[0], params[1]);
+	_scriptVars[RESULT] = _vm->_rnd.getRandomNumberRng(params[0], params[1]);
 	return IR_CONT;
 }
 
@@ -176,7 +176,7 @@
 		pars[1] = params[2];
 
 		fnRandom(pars);
-		pars[1] = RESULT;
+		pars[1] = _scriptVars[RESULT];
 	}
 
 	pars[0] = params[0];
@@ -396,7 +396,7 @@
 
 	// params:	none
 
-	if (DEMO) {
+	if (_scriptVars[DEMO]) {
 		_vm->closeGame();
 		return IR_STOP;
 	}
@@ -619,7 +619,7 @@
 	// credits. Note that musicTimeRemaining() will return 0 if the music
 	// is muted, so we need a sensible fallback for that case.
 
-	uint32 musicLength = MAX((int32)(1000 * (_vm->_sound->musicTimeRemaining() - 3)), 25 * (int32)scrollSteps);
+	uint32 musicLength = MAX((int32) (1000 * (_vm->_sound->musicTimeRemaining() - 3)), 25 * (int32) scrollSteps);
 
 	while (scrollPos < scrollSteps && !_vm->_quit) {
 		bool foundStartLine = false;
@@ -734,7 +734,7 @@
 	if (!_vm->_mouseStatus || _choosing)
 		_vm->setMouse(NORMAL_MOUSE_ID);
 
-	if (DEAD)
+	if (_scriptVars[DEAD])
 		_vm->buildSystemMenu();
 
 	return IR_CONT;

Index: icons.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/icons.cpp,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -d -r1.33 -r1.34
--- icons.cpp	5 Feb 2004 14:19:04 -0000	1.33
+++ icons.cpp	17 Mar 2004 09:03:14 -0000	1.34
@@ -48,7 +48,7 @@
 	// params:	none
 
 	// can reset this now
-	COMBINE_BASE = 0;
+	_scriptVars[COMBINE_BASE] = 0;
 
 	// so that the icon in 'object_held' is coloured while the rest are
 	// grey
@@ -159,11 +159,11 @@
 				// If this is the icon being examined, make
 				// it coloured. If not, grey this one out.
 
-				if (res == OBJECT_HELD)
+				if (res == Logic::_scriptVars[OBJECT_HELD])
 					icon_coloured = true;
 				else
 					icon_coloured = false;
-			} else if (COMBINE_BASE) {
+			} else if (Logic::_scriptVars[COMBINE_BASE]) {
 				// WHEN ONE MENU OBJECT IS BEING USED WITH
 				// ANOTHER - BOTH TO BE COLOURED, THE REST
 				// GREYED OUT
@@ -171,7 +171,7 @@
 				// if this if either of the icons being
 				// combined...
 
-				if (res == OBJECT_HELD || res == COMBINE_BASE)
+				if (res == Logic::_scriptVars[OBJECT_HELD] || res == Logic::_scriptVars[COMBINE_BASE])
 					icon_coloured = true;
 				else
 					icon_coloured = false;
@@ -182,7 +182,7 @@
 				// If this is the selction, grey it out. If
 				// not, make it coloured.
 
-  				if (res == OBJECT_HELD)
+  				if (res == Logic::_scriptVars[OBJECT_HELD])
 					icon_coloured = false;
 				else
 					icon_coloured = true;
@@ -230,7 +230,7 @@
 		// The only case when an icon is grayed is when the player
 		// is dead. Then SAVE is not available.
 
-		if (!DEAD || icon_list[i] != SAVE_ICON)
+		if (!Logic::_scriptVars[DEAD] || icon_list[i] != SAVE_ICON)
 			icon += (RDMENU_ICONWIDE * RDMENU_ICONDEEP);
 
 		_graphics->setMenuIcon(RDMENU_TOP, i, icon);

Index: interpreter.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/interpreter.cpp,v
retrieving revision 1.40
retrieving revision 1.41
diff -u -d -r1.40 -r1.41
--- interpreter.cpp	5 Feb 2004 14:19:04 -0000	1.40
+++ interpreter.cpp	17 Mar 2004 09:03:14 -0000	1.41
@@ -25,6 +25,8 @@
 
 namespace Sword2 {
 
+#define STACK_SIZE 10
+
 // The machine code table
 
 #define OPCODE(x)	{ &Logic::x, #x }
@@ -194,9 +196,7 @@
 
 #define pop() (assert(stackPtr < ARRAYSIZE(stack)), stack[--stackPtr])
 
-void Logic::setGlobalInterpreterVariables(int32 *vars) {
-	_globals = vars;
-}
+uint32 *Logic::_scriptVars = NULL;
 
 int Logic::runScript(char *scriptData, char *objectData, uint32 *offset) {
 	// Interestingly, unlike our BASS engine the stack is a local variable.
@@ -315,9 +315,9 @@
 
 			// WORKAROUND: Pyramid Bug. See explanation above.
 
-			if (checkPyramidBug && _globals[913] == 1) {
+			if (checkPyramidBug && _scriptVars[913] == 1) {
 				warning("Working around Titipoco script bug (the \"Pyramid Bug\")");
-				_globals[913] = 0;
+				_scriptVars[913] = 0;
 			}
 
 			break;
@@ -355,9 +355,9 @@
 		case CP_PUSH_GLOBAL_VAR32:
 			// Push a global variable
 			Read16ip(parameter);
-			assert(_globals);
-			debug(5, "Push global var %d (%d)", parameter, _globals[parameter]);
-			push(_globals[parameter]);
+			assert(_scriptVars);
+			debug(5, "Push global var %d (%d)", parameter, _scriptVars[parameter]);
+			push(_scriptVars[parameter]);
 			break;
 		case CP_PUSH_LOCAL_ADDR:
 			// push the address of a local variable
@@ -398,7 +398,7 @@
 			Read16ip(parameter);
 			value = pop();
 			debug(5, "Pop %d into global var %d", value, parameter);
-			_globals[parameter] = value;
+			_scriptVars[parameter] = value;
 			break;
 		case CP_ADDNPOP_LOCAL_VAR32:
 			Read16ip(parameter);
@@ -418,15 +418,15 @@
 			// Add and pop a global variable
 			Read16ip(parameter);
 			value = pop();
-			_globals[parameter] += value;
-			debug(5, "+= %d into global var %d -> %d", value, parameter, _globals[parameter]);
+			_scriptVars[parameter] += value;
+			debug(5, "+= %d into global var %d -> %d", value, parameter, _scriptVars[parameter]);
 			break;
 		case CP_SUBNPOP_GLOBAL_VAR32:
 			// Sub and pop a global variable
 			Read16ip(parameter);
 			value = pop();
-			_globals[parameter] -= value;
-			debug(5, "-= %d into global var %d -> %d", value, parameter, _globals[parameter]);
+			_scriptVars[parameter] -= value;
+			debug(5, "-= %d into global var %d -> %d", value, parameter, _scriptVars[parameter]);
 			break;
 
 		// Jump opcodes

Index: logic.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/logic.cpp,v
retrieving revision 1.41
retrieving revision 1.42
diff -u -d -r1.41 -r1.42
--- logic.cpp	5 Feb 2004 14:19:04 -0000	1.41
+++ logic.cpp	17 Mar 2004 09:03:14 -0000	1.42
@@ -32,6 +32,16 @@
 namespace Sword2 {
 
 /**
+ * Reset the script variables. If the resource is already open, this won't do
+ * anything, I beleive.
+ */
+
+void Logic::resetScriptVars(void) {
+	_scriptVars = (uint32 *) (_vm->_resman->openResource(1) + sizeof(StandardHeader));
+	_vm->_resman->closeResource(1);
+}
+    
+/**
  * Do one cycle of the current session.
  */
 
@@ -64,26 +74,26 @@
 		game_object_list = (uint32 *) (head + 1);
 
 		// read the next id
-		ID = game_object_list[_pc++];
-		id = ID;
+		_scriptVars[ID] = game_object_list[_pc++];
+		id = _scriptVars[ID];
 
 		// release the list again so it can float in memory - at this
 		// point not one thing should be locked
 
 		_vm->_resman->closeResource(run_list);
 
-		debug(5, "%d", ID);
+		debug(5, "%d", _scriptVars[ID]);
 
 		// null terminated
-		if (!ID) {
+		if (!_scriptVars[ID]) {
 			// end the session naturally
 			return 0;
 		}
 
-		head = (StandardHeader *) _vm->_resman->openResource(ID);
+		head = (StandardHeader *) _vm->_resman->openResource(_scriptVars[ID]);
 
 		if (head->fileType != GAME_OBJECT)
-			error("processSession: %d not an object", ID);
+			error("processSession: %d not an object", _scriptVars[ID]);
 
 		_curObjectHub = (ObjectHub *) (head + 1);
 
@@ -104,7 +114,7 @@
 
 			// there is a distinction between running one of our
 			// own scripts and that of another object
-			if (script / SIZE == ID) {
+			if (script / SIZE == _scriptVars[ID]) {
 				// its our script
 
 				debug(5, "run script %d pc%d",
@@ -181,7 +191,7 @@
 		// clear any syncs that were waiting for this character - it
 		// has used them or now looses them
 
-		clearSyncs(ID);
+		clearSyncs(_scriptVars[ID]);
 
 		if (_pc != 0xffffffff) {
 			// the session is still valid so run the service script
@@ -197,7 +207,7 @@
 
 		// and that's it so close the object resource
 
-		_vm->_resman->closeResource(ID);
+		_vm->_resman->closeResource(_scriptVars[ID]);
 	}
 
 	// leaving a room so remove all ids that must reboot correctly
@@ -222,7 +232,7 @@
 	_pc = 0xffffffff;
 
 	// reset now in case we double-clicked an exit prior to changing screen
-	EXIT_FADING = 0;
+	_scriptVars[EXIT_FADING] = 0;
 
 	// we're trashing the list - presumably to change room
 	// in theory sync waiting in the list could be left behind and never
@@ -296,7 +306,7 @@
 
 	// can be 0, 1, 2
 	if (LEVEL == 3)
-		error("logicUp id %d has run off script tree! :-O", ID);
+		error("logicUp id %d has run off script tree! :-O", _scriptVars[ID]);
 
 	// setup new script on next level (not the current level)
 
@@ -387,11 +397,11 @@
 	uint32 entry;
 
 	// DON'T EVER KILL GEORGE!
-	if (ID != 8) {
+	if (_scriptVars[ID] != 8) {
 		// first, scan list to see if this object is already included
 
 		entry = 0;
-		while (entry < _kills && _objectKillList[entry] != ID)
+		while (entry < _kills && _objectKillList[entry] != _scriptVars[ID])
 			entry++;
 
 		// if this ID isn't already in the list, then add it,
@@ -402,7 +412,7 @@
 			assert(_kills < OBJECT_KILL_LIST_SIZE);
 
 			// add this 'ID' to the kill list
-			_objectKillList[_kills] = ID;
+			_objectKillList[_kills] = _scriptVars[ID];
 			_kills++;
 
 			// "another one bites the dust"

Index: logic.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/logic.h,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -d -r1.27 -r1.28
--- logic.h	7 Jan 2004 07:42:00 -0000	1.27
+++ logic.h	17 Mar 2004 09:03:14 -0000	1.28
@@ -30,14 +30,12 @@
 
 namespace Sword2 {
 
-#define STACK_SIZE 10
-
-#define	MAX_events 10
+#define MAX_events 10
 
 // There won't be many, will there? Probably 2 at most i reckon
-#define	MAX_syncs 10
+#define MAX_syncs 10
 
-#define	TREE_SIZE 3
+#define TREE_SIZE 3
 
 // This must allow for the largest number of objects in a screen
 #define OBJECT_KILL_LIST_SIZE 50
@@ -50,9 +48,6 @@
 private:
 	Sword2Engine *_vm;
 
-	// Point to the global variable data
-	int32 *_globals;
-
 	uint32 _objectKillList[OBJECT_KILL_LIST_SIZE];
 
 	// keeps note of no. of objects in the kill list
@@ -162,13 +157,14 @@
 
 public:
 	Logic(Sword2Engine *vm) :
-		  _vm(vm), _globals(NULL), _kills(0), _debugFlag(false),
-		  _smackerLeadOut(0), _sequenceTextLines(0), _speechTime(0),
-		  _animId(0), _speechAnimType(0), _leftClickDelay(0),
-		  _rightClickDelay(0), _defaultResponseId(0),
-		  _totalStartups(0), _totalScreenManagers(0),
-		  _officialTextNumber(0), _speechScriptWaiting(0),
-		  _speechTextBlocNo(0), _choosing(false), _unpauseZone(0) {
+		  _vm(vm), _kills(0), _debugFlag(false), _smackerLeadOut(0),
+		  _sequenceTextLines(0), _speechTime(0), _animId(0),
+		  _speechAnimType(0), _leftClickDelay(0), _rightClickDelay(0),
+		  _defaultResponseId(0), _totalStartups(0),
+		  _totalScreenManagers(0), _officialTextNumber(0),
+		  _speechScriptWaiting(0), _speechTextBlocNo(0),
+		  _choosing(false), _unpauseZone(0) {
+		_scriptVars = NULL;
 		memset(_subjectList, 0, sizeof(_subjectList));
 		memset(_eventList, 0, sizeof(_eventList));
 		memset(_syncList, 0, sizeof(_syncList));
@@ -180,6 +176,9 @@
 		delete _router;
 	}
 
+	// Point to the global variable data
+	static uint32 *_scriptVars;
+
 	// "TEXT" - current official text line number - will match the wav
 	// filenames
 
@@ -200,10 +199,11 @@
 
 	uint32 _unpauseZone;
 
+	void resetScriptVars(void);
+
 	void conPrintStartMenu(void);
 	void conStart(int start);
 
-	void setGlobalInterpreterVariables(int32 *vars);
 	int runScript(char *scriptData, char *objectData, uint32 *offset);
 
 	struct EventUnit {

Index: maketext.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/maketext.cpp,v
retrieving revision 1.38
retrieving revision 1.39
diff -u -d -r1.38 -r1.39
--- maketext.cpp	5 Feb 2004 14:19:04 -0000	1.38
+++ maketext.cpp	17 Mar 2004 09:03:14 -0000	1.39
@@ -49,6 +49,7 @@
 #include "common/stdafx.h"
 #include "sword2/sword2.h"
 #include "sword2/defs.h"
+#include "sword2/logic.h"
 #include "sword2/maketext.h"
 #include "sword2/resman.h"
 #include "sword2/driver/d_draw.h"
@@ -87,7 +88,7 @@
 
 	// allocate memory for array of lineInfo structures
 
-	line = _vm->_memory->allocMemory(MAX_LINES * sizeof(LineInfo), MEM_locked, (uint32)UID_temp);
+	line = _vm->_memory->allocMemory(MAX_LINES * sizeof(LineInfo), MEM_locked, (uint32) UID_temp);
 
 	// get details of sentence breakdown into array of LineInfo structures
 	// and get the no of lines involved
@@ -213,7 +214,7 @@
 
 	// allocate memory for sprite, and lock it ready for use
 	// NB. 'textSprite' is the given pointer to the handle to be used
-	textSprite = _vm->_memory->allocMemory(sizeof(FrameHeader) + sizeOfSprite, MEM_locked, (uint32)UID_text_sprite);
+	textSprite = _vm->_memory->allocMemory(sizeof(FrameHeader) + sizeOfSprite, MEM_locked, (uint32) UID_text_sprite);
 
 	// the handle (*textSprite) now points to UNMOVABLE memory block
 	// set up the frame header
@@ -579,7 +580,7 @@
 
 	// Get the text line - skip the 2 chars containing the wavId
 
-	if (DEMO)
+	if (Logic::_scriptVars[DEMO])
 		textLine = fetchTextLine(textFile, 451) + 2;
 	else
 		textLine = fetchTextLine(textFile, 54) + 2;

Index: memory.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/memory.cpp,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -d -r1.23 -r1.24
--- memory.cpp	5 Feb 2004 14:19:04 -0000	1.23
+++ memory.cpp	17 Mar 2004 09:03:14 -0000	1.24
@@ -73,7 +73,7 @@
 	_memList[0].size = _totalFreeMemory;
 	_memList[0].parent = -1;		// we are base - for now
 	_memList[0].child = -1;			// we are the end as well
-	_memList[0].uid = (uint32)UID_memman;		// init id
+	_memList[0].uid = (uint32) UID_memman;		// init id
 
 	_baseMemBlock = 0;			// for now
 }
@@ -206,7 +206,7 @@
 	}
 
 	_memList[spawn].state = MEM_free;	// new block is free
-	_memList[spawn].uid = (uint32)UID_memman;	// a memman created bloc
+	_memList[spawn].uid = (uint32) UID_memman;	// a memman created bloc
 
 	// size of the existing parent free block minus the size of the new
 	// space Talloc'ed.
@@ -253,7 +253,7 @@
 	// once you've done this the memory may be recycled
 
 	block->state = MEM_free;
-	block->uid = (uint32)UID_memman;	// belongs to the memory manager again
+	block->uid = (uint32) UID_memman;	// belongs to the memory manager again
 
 #ifdef	MEMDEBUG
 	debugMemory();

Index: mouse.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/mouse.cpp,v
retrieving revision 1.53
retrieving revision 1.54
diff -u -d -r1.53 -r1.54
--- mouse.cpp	5 Feb 2004 14:19:04 -0000	1.53
+++ mouse.cpp	17 Mar 2004 09:03:14 -0000	1.54
@@ -72,7 +72,7 @@
 	// If George is dead, the system menu is visible all the time, and is
 	// the only thing that can be used.
 
-	if (DEAD) {
+	if (Logic::_scriptVars[DEAD]) {
 		if (_mouseMode != MOUSE_system_menu) {
 			_mouseMode = MOUSE_system_menu;
 
@@ -144,7 +144,7 @@
 	// If the mouse is moved off the menu, close it. Unless the player is
 	// dead, in which case the menu should always be visible.
 
-	if (_input->_mouseY > 0 && !DEAD) {
+	if (_input->_mouseY > 0 && !Logic::_scriptVars[DEAD]) {
 		_mouseMode = MOUSE_normal;
 		_graphics->hideMenu(RDMENU_TOP);
 		return;
@@ -167,7 +167,7 @@
 
 	// No save when dead
 
-	if (icon_list[hit] == SAVE_ICON && DEAD)
+	if (icon_list[hit] == SAVE_ICON && Logic::_scriptVars[DEAD])
 		return;
 
 	// Gray out all he icons, except the one that was clicked
@@ -219,7 +219,7 @@
 
 	// Menu stays open on death screen. Otherwise it's closed.
 
-	if (!DEAD) {
+	if (!Logic::_scriptVars[DEAD]) {
 		_mouseMode = MOUSE_normal;
 		_graphics->hideMenu(RDMENU_TOP);
 	} else {
@@ -292,7 +292,7 @@
 	// not do this, but it feels natural to me.
 
 	if (me->buttons & RD_RIGHTBUTTONDOWN) {
-		OBJECT_HELD = 0;
+		Logic::_scriptVars[OBJECT_HELD] = 0;
 		_menuSelectedPos = 0;
 		_mouseMode = MOUSE_menu;
 		setLuggage(0);
@@ -318,22 +318,24 @@
 		// Set global script variable 'button'. We know that it was the
 		// left button, not the right one.
 
-		LEFT_BUTTON = 1;
-		RIGHT_BUTTON = 0;
+		Logic::_scriptVars[LEFT_BUTTON]  = 1;
+		Logic::_scriptVars[RIGHT_BUTTON] = 0;
 
 		// These might be required by the action script about to be run
 
-		MOUSE_X = _input->_mouseX + _thisScreen.scroll_offset_x;
-		MOUSE_Y = _input->_mouseY + _thisScreen.scroll_offset_y;
+		Logic::_scriptVars[MOUSE_X] = _input->_mouseX + _thisScreen.scroll_offset_x;
+		Logic::_scriptVars[MOUSE_Y] = _input->_mouseY + _thisScreen.scroll_offset_y;
 
 		// For scripts to know what's been clicked. First used for
 		// 'room_13_turning_script' in object 'biscuits_13'
 
-		CLICKED_ID = _mouseTouching;
+		Logic::_scriptVars[CLICKED_ID] = _mouseTouching;
 
 		_logic->setPlayerActionEvent(CUR_PLAYER_ID, _mouseTouching);
 
-		debug(2, "Used \"%s\" on \"%s\"", fetchObjectName(OBJECT_HELD), fetchObjectName(CLICKED_ID));
+		debug(2, "Used \"%s\" on \"%s\"",
+			fetchObjectName(Logic::_scriptVars[OBJECT_HELD]),
+			fetchObjectName(Logic::_scriptVars[CLICKED_ID]));
 
 		// Hide menu - back to normal menu mode
 
@@ -359,12 +361,12 @@
 	if ((uint) hit == _menuSelectedPos) {
 		// If we clicked on the same icon again, reset the first icon
 
-		OBJECT_HELD = 0;
+		Logic::_scriptVars[OBJECT_HELD] = 0;
 		_menuSelectedPos = 0;
 	} else {
 		// Otherwise, combine the two icons
 
-		COMBINE_BASE = _masterMenuList[hit].icon_resource;
+		Logic::_scriptVars[COMBINE_BASE] = _masterMenuList[hit].icon_resource;
 		_logic->setPlayerActionEvent(CUR_PLAYER_ID, MENU_MASTER_OBJECT);
 
 		// Turn off mouse now, to prevent player trying to click
@@ -372,7 +374,9 @@
 
 		noHuman();
 
-		debug(2, "Used \"%s\" on \"%s\"", fetchObjectName(OBJECT_HELD), fetchObjectName(COMBINE_BASE));
+		debug(2, "Used \"%s\" on \"%s\"",
+			fetchObjectName(Logic::_scriptVars[OBJECT_HELD]),
+			fetchObjectName(Logic::_scriptVars[COMBINE_BASE]));
 	}
 
 	// Refresh the menu
@@ -409,12 +413,12 @@
 		// resource id.
 
 		_examiningMenuIcon = true;
-		OBJECT_HELD = _masterMenuList[hit].icon_resource;
+		Logic::_scriptVars[OBJECT_HELD] = _masterMenuList[hit].icon_resource;
 
 		// Must clear this so next click on exit becomes 1st click
 		// again
 
-		EXIT_CLICK_ID = 0;
+		Logic::_scriptVars[EXIT_CLICK_ID] = 0;
 
 		_logic->setPlayerActionEvent(CUR_PLAYER_ID, MENU_MASTER_OBJECT);
 
@@ -428,7 +432,7 @@
 		noHuman();
 
 		debug(2, "Right-click on \"%s\" icon",
-			fetchObjectName(OBJECT_HELD));
+			fetchObjectName(Logic::_scriptVars[OBJECT_HELD]));
 
 		return;
 	}
@@ -441,13 +445,13 @@
 		_mouseMode = MOUSE_drag;
 
 		_menuSelectedPos = hit;
-		OBJECT_HELD = _masterMenuList[hit].icon_resource;
+		Logic::_scriptVars[OBJECT_HELD] = _masterMenuList[hit].icon_resource;
 		_currentLuggageResource = _masterMenuList[hit].luggage_resource;
 
 		// Must clear this so next click on exit becomes 1st click
 		// again
 
-		EXIT_CLICK_ID = 0;
+		Logic::_scriptVars[EXIT_CLICK_ID] = 0;
 
 		// Refresh the menu
 
@@ -456,7 +460,7 @@
 		setLuggage(_masterMenuList[hit].luggage_resource);
 
 		debug(2, "Left-clicked on \"%s\" icon - switch to drag mode",
-			fetchObjectName(OBJECT_HELD));
+			fetchObjectName(Logic::_scriptVars[OBJECT_HELD]));
 	}
 }
 
@@ -470,7 +474,7 @@
 	// big-object menu lock situation, of if the player is dragging an
 	// object.
 
-	if (_input->_mouseY < 0 && !_mouseModeLocked && !OBJECT_HELD) {
+	if (_input->_mouseY < 0 && !_mouseModeLocked && !Logic::_scriptVars[OBJECT_HELD]) {
 		_mouseMode = MOUSE_system_menu;
 
 		if (_mouseTouching) {
@@ -498,7 +502,7 @@
 		// object, even if the inventory menu was closed after the
 		// first object was selected.
 
-		if (!OBJECT_HELD)
+		if (!Logic::_scriptVars[OBJECT_HELD])
 			_mouseMode = MOUSE_menu;
 		else
 			_mouseMode = MOUSE_drag;
@@ -571,8 +575,8 @@
 	// If user right-clicks while holding an object, release it. The
 	// original code did not do this, but it feels natural to me.
 
-	if (OBJECT_HELD && (me->buttons & RD_RIGHTBUTTONDOWN)) {
-		OBJECT_HELD = 0;
+	if (Logic::_scriptVars[OBJECT_HELD] && (me->buttons & RD_RIGHTBUTTONDOWN)) {
+		Logic::_scriptVars[OBJECT_HELD] = 0;
 		_menuSelectedPos = 0;
 		setLuggage(0);
 		return;
@@ -599,28 +603,28 @@
 
 	// PLAYER_ACTION script variable - whatever catches this must reset to
 	// 0 again
-	// PLAYER_ACTION = _mouseTouching;
+	// Logic::_scriptVars[PLAYER_ACTION] = _mouseTouching;
 
 	// Idle or router-anim will catch it
 
 	// Set global script variable 'button'
 
 	if (me->buttons & RD_LEFTBUTTONDOWN) {
-		LEFT_BUTTON  = 1;
-		RIGHT_BUTTON = 0;
+		Logic::_scriptVars[LEFT_BUTTON]  = 1;
+		Logic::_scriptVars[RIGHT_BUTTON] = 0;
 		_buttonClick = 0;	// for re-click
 	} else {
-		LEFT_BUTTON  = 0;
-		RIGHT_BUTTON = 1;
+		Logic::_scriptVars[LEFT_BUTTON]  = 0;
+		Logic::_scriptVars[RIGHT_BUTTON] = 1;
 		_buttonClick = 1;	// for re-click
 	}
 
 	// These might be required by the action script about to be run
 
-	MOUSE_X = _input->_mouseX + _thisScreen.scroll_offset_x;
-	MOUSE_Y = _input->_mouseY + _thisScreen.scroll_offset_y;
+	Logic::_scriptVars[MOUSE_X] = _input->_mouseX + _thisScreen.scroll_offset_x;
+	Logic::_scriptVars[MOUSE_Y] = _input->_mouseY + _thisScreen.scroll_offset_y;
 
-	if (_mouseTouching == EXIT_CLICK_ID && (me->buttons & RD_LEFTBUTTONDOWN)) {
+	if (_mouseTouching == Logic::_scriptVars[EXIT_CLICK_ID] && (me->buttons & RD_LEFTBUTTONDOWN)) {
 		// It's the exit double click situation. Let the existing
 		// interaction continue and start fading down. Switch the human
 		// off too
@@ -630,8 +634,8 @@
 
 		// Tell the walker
 
-		EXIT_FADING = 1;
-	} else if (_oldButton == _buttonClick && _mouseTouching == CLICKED_ID && _mousePointerRes != NORMAL_MOUSE_ID) {
+		Logic::_scriptVars[EXIT_FADING] = 1;
+	} else if (_oldButton == _buttonClick && _mouseTouching == Logic::_scriptVars[CLICKED_ID] && _mousePointerRes != NORMAL_MOUSE_ID) {
 		// Re-click. Do nothing, except on floors
 	} else {
 		// For re-click
@@ -641,13 +645,13 @@
 		// For scripts to know what's been clicked. First used for
 		// 'room_13_turning_script' in object 'biscuits_13'
 
-		CLICKED_ID = _mouseTouching;
+		Logic::_scriptVars[CLICKED_ID] = _mouseTouching;
 
 		// Must clear these two double-click control flags - do it here
 		// so reclicks after exit clicks are cleared up
 
-		EXIT_CLICK_ID = 0;
-		EXIT_FADING = 0;
+		Logic::_scriptVars[EXIT_CLICK_ID] = 0;
+		Logic::_scriptVars[EXIT_FADING] = 0;
 
 		// WORKAROUND: Examining the lift while at the top of the
 		// pyramid causes the game to hang.
@@ -660,17 +664,21 @@
 		// If the user didn't click the left button, the script will
 		// terminate. With the mouse cursor still disabled. Ouch!
 
-		if (_mouseTouching == 2773 && !LEFT_BUTTON) {
+		if (_mouseTouching == 2773 && !Logic::_scriptVars[LEFT_BUTTON]) {
 			warning("Working around elevator script bug");
 		} else
 			_logic->setPlayerActionEvent(CUR_PLAYER_ID, _mouseTouching);
 
-		if (OBJECT_HELD)
-			debug(2, "Used \"%s\" on \"%s\"", fetchObjectName(OBJECT_HELD), fetchObjectName(CLICKED_ID));
-		else if (LEFT_BUTTON)
-			debug(2, "Left-clicked on \"%s\"", fetchObjectName(CLICKED_ID));
+		if (Logic::_scriptVars[OBJECT_HELD])
+			debug(2, "Used \"%s\" on \"%s\"",
+				fetchObjectName(Logic::_scriptVars[OBJECT_HELD]),
+				fetchObjectName(Logic::_scriptVars[CLICKED_ID]));
+		else if (Logic::_scriptVars[LEFT_BUTTON])
+			debug(2, "Left-clicked on \"%s\"",
+				fetchObjectName(Logic::_scriptVars[CLICKED_ID]));
 		else	// RIGHT BUTTON
-			debug(2, "Right-clicked on \"%s\"", fetchObjectName(CLICKED_ID));
+			debug(2, "Right-clicked on \"%s\"",
+				fetchObjectName(Logic::_scriptVars[CLICKED_ID]));
 	}
 }
 
@@ -725,7 +733,7 @@
 			setMouse(pointer_type);
 
 			// setup luggage icon
-			if (OBJECT_HELD) {
+			if (Logic::_scriptVars[OBJECT_HELD]) {
 				setLuggage(_currentLuggageResource);
 			}
 		} else
@@ -1014,7 +1022,7 @@
 	// it and when combining objects
 
 	// for logic scripts
-	MOUSE_AVAILABLE = 0;
+	Logic::_scriptVars[MOUSE_AVAILABLE] = 0;
 
 	// human/mouse off
 	_mouseStatus = true;
@@ -1045,12 +1053,12 @@
 	// If 'pointer_text' field is set, but the 'id' field isn't same is
 	// current id, then we don't want this "left over" pointer text
 
-	if (_mouseList[_curMouse].pointer_text && _mouseList[_curMouse].id != (int32) ID)
+	if (_mouseList[_curMouse].pointer_text && _mouseList[_curMouse].id != (int32) Logic::_scriptVars[ID])
 		_mouseList[_curMouse].pointer_text = 0;
 
 	// Get id from system variable 'id' which is correct for current object
 
-	_mouseList[_curMouse].id = ID;
+	_mouseList[_curMouse].id = Logic::_scriptVars[ID];
 
 	// Not using sprite as mask - this is only done from fnRegisterFrame()
 
@@ -1082,7 +1090,7 @@
 	// special menus use noHuman
 
 	// dont hide menu in conversations
-	if (TALK_FLAG == 0)
+	if (_scriptVars[TALK_FLAG] == 0)
 		_vm->_graphics->hideMenu(RDMENU_BOTTOM);
 
 	if (_vm->_mouseMode == MOUSE_system_menu) {
@@ -1098,7 +1106,7 @@
 	// params:	none
 
 	// for logic scripts
-	MOUSE_AVAILABLE = 1;
+	_scriptVars[MOUSE_AVAILABLE] = 1;
 
 	// off
 	if (_vm->_mouseStatus) {
@@ -1106,8 +1114,8 @@
 		_vm->_mouseTouching = 1;	// forces engine to choose a cursor
 	}
 
-	//clear this to reset no-second-click system
-	CLICKED_ID = 0;
+	// clear this to reset no-second-click system
+	_scriptVars[CLICKED_ID] = 0;
 
 	// this is now done outside the OBJECT_HELD check in case it's set to
 	// zero before now!
@@ -1117,14 +1125,14 @@
 
 	_vm->_mouseModeLocked = false;
 
-	if (OBJECT_HELD) {
+	if (_scriptVars[OBJECT_HELD]) {
 		// was dragging something around
 		// need to clear this again
-		OBJECT_HELD = 0;
+		_scriptVars[OBJECT_HELD] = 0;
 
 		// and these may also need clearing, just in case
 		_vm->_examiningMenuIcon = false;
-		COMBINE_BASE = 0;
+		Logic::_scriptVars[COMBINE_BASE] = 0;
 
 		_vm->setLuggage(0);
 	}
@@ -1192,7 +1200,7 @@
 	// current object id - used for checking pointer_text when mouse area
 	// registered (in fnRegisterMouse and fnRegisterFrame)
 
-	_vm->_mouseList[_vm->_curMouse].id = ID;
+	_vm->_mouseList[_vm->_curMouse].id = _scriptVars[ID];
 	_vm->_mouseList[_vm->_curMouse].pointer_text = params[0];
 	return IR_CONT;
 }
@@ -1268,7 +1276,7 @@
 
 	_vm->setLuggage(params[0]);
 
-	OBJECT_HELD = params[0];
+	_scriptVars[OBJECT_HELD] = params[0];
 	_vm->_currentLuggageResource = params[0];
 
 	// mode locked - no menu available
@@ -1301,9 +1309,9 @@
 		// positive check
 
 		_vm->_playerActivityDelay = 0;
-		RESULT = 1;
+		_scriptVars[RESULT] = 1;
 	} else
-		RESULT = 0;
+		_scriptVars[RESULT] = 0;
 
 	return IR_CONT;
 }

Index: resman.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/resman.cpp,v
retrieving revision 1.88
retrieving revision 1.89
diff -u -d -r1.88 -r1.89
--- resman.cpp	4 Mar 2004 08:03:32 -0000	1.88
+++ resman.cpp	17 Mar 2004 09:03:14 -0000	1.89
@@ -90,7 +90,7 @@
 	end = file.size();
 
 	//get some space for the incoming resource file - soon to be trashed
-	temp = _vm->_memory->allocMemory(end, MEM_locked, (uint32)UID_temp);
+	temp = _vm->_memory->allocMemory(end, MEM_locked, (uint32) UID_temp);
 
 	if (file.read(temp->ad, end) != end) {
 		file.close();

Index: router.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/router.cpp,v
retrieving revision 1.40
retrieving revision 1.41
diff -u -d -r1.40 -r1.41
--- router.cpp	5 Feb 2004 14:19:04 -0000	1.40
+++ router.cpp	17 Mar 2004 09:03:15 -0000	1.41
@@ -76,6 +76,7 @@
 #include "common/stdafx.h"
 #include "sword2/sword2.h"
 #include "sword2/defs.h"
+#include "sword2/logic.h"
 #include "sword2/resman.h"
 #include "sword2/router.h"
 #include "sword2/driver/d_draw.h"
@@ -83,7 +84,7 @@
 namespace Sword2 {
 
 uint8 Router::returnSlotNo(uint32 megaId) {
-	if (ID == CUR_PLAYER_ID) {
+	if (Logic::_scriptVars[ID] == CUR_PLAYER_ID) {
 		// George (8)
 		return 0;
 	} else {
@@ -101,7 +102,7 @@
 	// in middle of route, the old route will be safely cleared from
 	// memory just before they create a new one
 
-	slotNo = returnSlotNo(ID); 
+	slotNo = returnSlotNo(Logic::_scriptVars[ID]); 
 
 	// if this slot is already used, then it can't be needed any more
 	// because this id is creating a new route!
@@ -109,7 +110,7 @@
 	if (_routeSlots[slotNo])
 		freeRouteMem();
 
-	_routeSlots[slotNo] = _vm->_memory->allocMemory(sizeof(WalkData) * O_WALKANIM_SIZE, MEM_locked, (uint32)UID_walk_anim);
+	_routeSlots[slotNo] = _vm->_memory->allocMemory(sizeof(WalkData) * O_WALKANIM_SIZE, MEM_locked, (uint32) UID_walk_anim);
 
 	// 12000 bytes were used for this in Sword1 mega compacts, based on
 	// 20 bytes per 'WalkData' frame
@@ -125,20 +126,20 @@
 }
 
 WalkData *Router::lockRouteMem(void) {
-	uint8 slotNo = returnSlotNo(ID);
+	uint8 slotNo = returnSlotNo(Logic::_scriptVars[ID]);
 	
 	_vm->_memory->lockMemory(_routeSlots[slotNo]);
 	return (WalkData *) _routeSlots[slotNo]->ad;
 }
 
 void Router::floatRouteMem(void) {
-	uint8 slotNo = returnSlotNo(ID); 
+	uint8 slotNo = returnSlotNo(Logic::_scriptVars[ID]); 
 
 	_vm->_memory->floatMemory(_routeSlots[slotNo]);
 }
 
 void Router::freeRouteMem(void) {
-	uint8 slotNo = returnSlotNo(ID); 
+	uint8 slotNo = returnSlotNo(Logic::_scriptVars[ID]); 
 
 	// free the mem block pointed to from this entry of _routeSlots[]
 
@@ -1447,13 +1448,13 @@
 		while (lastDir != _currentDir) {
 			lastDir += turnDir;
 
-			// new frames for turn frames	29oct95jps
+			// new frames for turn frames
 			if (turnDir < 0) {
 				if (lastDir < 0)
 					lastDir += NO_DIRECTIONS;
 				module = _firstStandingTurnLeftFrame + lastDir;
 			} else {
-				if ( lastDir > 7)
+				if (lastDir > 7)
 					lastDir -= NO_DIRECTIONS;
 				module = _firstStandingTurnRightFrame + lastDir;
 			}

Index: save_rest.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/save_rest.cpp,v
retrieving revision 1.49
retrieving revision 1.50
diff -u -d -r1.49 -r1.50
--- save_rest.cpp	4 Mar 2004 08:03:32 -0000	1.49
+++ save_rest.cpp	17 Mar 2004 09:03:15 -0000	1.50
@@ -96,7 +96,7 @@
 	// allocate the savegame buffer
 
 	bufferSize = findBufferSize();
-	saveBufferMem = _memory->allocMemory(bufferSize, MEM_locked, (uint32)UID_savegame_buffer);
+	saveBufferMem = _memory->allocMemory(bufferSize, MEM_locked, (uint32) UID_savegame_buffer);
 
 	fillSaveBuffer(saveBufferMem, bufferSize, desc);
 
@@ -226,7 +226,7 @@
 	// allocate the savegame buffer
 
 	bufferSize = findBufferSize();
-	saveBufferMem = _memory->allocMemory(bufferSize, MEM_locked, (uint32)UID_savegame_buffer);
+	saveBufferMem = _memory->allocMemory(bufferSize, MEM_locked, (uint32) UID_savegame_buffer);
 
 	// read the savegame file into our buffer
 

Index: scroll.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/scroll.cpp,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -d -r1.17 -r1.18
--- scroll.cpp	5 Feb 2004 14:19:05 -0000	1.17
+++ scroll.cpp	17 Mar 2004 09:03:15 -0000	1.18
@@ -44,18 +44,10 @@
 	uint16 scroll_distance_y;
 
 	// if the scroll offsets are being forced in script
-	if (SCROLL_X || SCROLL_Y) {
-		// ensure not too far right
-		if (_thisScreen.max_scroll_offset_x > SCROLL_X)
-			_thisScreen.scroll_offset_x = SCROLL_X;
-		else
-			_thisScreen.scroll_offset_x = _thisScreen.max_scroll_offset_x;
-
-		// ensure not too far down
-		if (_thisScreen.max_scroll_offset_y > SCROLL_Y)
-			_thisScreen.scroll_offset_y = SCROLL_Y;
-		else
-			_thisScreen.scroll_offset_y = _thisScreen.max_scroll_offset_y;
+	if (Logic::_scriptVars[SCROLL_X] || Logic::_scriptVars[SCROLL_Y]) {
+		// ensure not too far right or too far down
+		_thisScreen.scroll_offset_x = MIN((uint16) Logic::_scriptVars[SCROLL_X], _thisScreen.max_scroll_offset_x);
+		_thisScreen.scroll_offset_y = MIN((uint16) Logic::_scriptVars[SCROLL_Y], _thisScreen.max_scroll_offset_y);
 	} else {
 		// George's offset from the centre - the desired position
 		// for him

Index: sound.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/sound.cpp,v
retrieving revision 1.40
retrieving revision 1.41
diff -u -d -r1.40 -r1.41
--- sound.cpp	5 Feb 2004 14:19:05 -0000	1.40
+++ sound.cpp	17 Mar 2004 09:03:15 -0000	1.41
@@ -258,7 +258,7 @@
 	// in case we want to call fnStopFx() later, to kill this fx
 	// (mainly for FX_LOOP & FX_RANDOM)
 
-	RESULT = j;
+	_scriptVars[RESULT] = j;
 	return IR_CONT;
 }
 
@@ -367,7 +367,7 @@
 
 	// add the appropriate file extension & play it
 
-	if (DEMO) {
+	if (_scriptVars[DEMO]) {
 		// The demo I found didn't come with any music file, but you
 		// could use the music from the first CD of the complete game,
 		// I suppose...
@@ -407,7 +407,7 @@
 	// or 0 if no music playing
 
 	// in seconds, rounded up to the nearest second
-	RESULT = _vm->_sound->musicTimeRemaining();
+	_scriptVars[RESULT] = _vm->_sound->musicTimeRemaining();
 
 	return IR_CONT;
 }

Index: speech.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/speech.cpp,v
retrieving revision 1.58
retrieving revision 1.59
diff -u -d -r1.58 -r1.59
--- speech.cpp	5 Feb 2004 14:19:05 -0000	1.58
+++ speech.cpp	17 Mar 2004 09:03:15 -0000	1.59
@@ -56,7 +56,7 @@
 	// params:	0 id
 	//		1 daves reference number
 
-	if (IN_SUBJECT == 0) {
+	if (_scriptVars[IN_SUBJECT] == 0) {
 		// This is the start of the new subject list
 		// Set the default repsonse id to zero in case we're never
 		// passed one
@@ -77,12 +77,12 @@
 		// a luggage icon is clicked on someone when it wouldn't have
 		// been in the chooser list (see fnChoose below)
 	} else {
-		_subjectList[IN_SUBJECT].res = params[0];
-		_subjectList[IN_SUBJECT].ref = params[1];
+		_subjectList[_scriptVars[IN_SUBJECT]].res = params[0];
+		_subjectList[_scriptVars[IN_SUBJECT]].ref = params[1];
 
 		debug(5, "fnAddSubject res %d, uid %d", params[0], params[1]);
 
-		IN_SUBJECT++;
+		_scriptVars[IN_SUBJECT]++;
 	}
 
 	return IR_CONT;
@@ -98,11 +98,11 @@
 	int hit;
 	uint8 *icon;
 
-	AUTO_SELECTED = 0;	// see below
+	_scriptVars[AUTO_SELECTED] = 0;	// see below
 
 	// new thing to intercept objects held at time of clicking on a person
 
-	if (OBJECT_HELD) {
+	if (_scriptVars[OBJECT_HELD]) {
 		// So that, if there is no match, the speech script uses the
 		// default text for objects that are not accounted for
 
@@ -121,8 +121,8 @@
 
 		// scan the subject list for a match with our 'object_held'
 
-		for (i = 0; i < IN_SUBJECT; i++) {
-			if (_subjectList[i].res == OBJECT_HELD) {
+		for (i = 0; i < _scriptVars[IN_SUBJECT]; i++) {
+			if (_subjectList[i].res == _scriptVars[OBJECT_HELD]) {
 				// Return special subject chosen code (same
 				// as in normal chooser routine below)
 				response = _subjectList[i].ref;
@@ -130,8 +130,8 @@
 			}
 		}
 
-		OBJECT_HELD = 0; // clear it so it doesn't keep happening!
-		IN_SUBJECT = 0;	 // clear the subject list
+		_scriptVars[OBJECT_HELD] = 0;	// clear it so it doesn't keep happening!
+		_scriptVars[IN_SUBJECT] = 0;	// clear the subject list
 
 		return IR_CONT | (response << 3);
 	}
@@ -141,9 +141,9 @@
 	// If this is the 1st time the chooser is coming up in this
 	// conversation, AND there's only 1 subject, AND it's the EXIT icon
 
-	if (CHOOSER_COUNT_FLAG == 0 && IN_SUBJECT == 1 && _subjectList[0].res == EXIT_ICON) {
-		AUTO_SELECTED = 1;	// for speech script
-		IN_SUBJECT = 0;		// clear the subject list
+	if (_scriptVars[CHOOSER_COUNT_FLAG] == 0 && _scriptVars[IN_SUBJECT] == 1 && _subjectList[0].res == EXIT_ICON) {
+		_scriptVars[AUTO_SELECTED] = 1;	// for speech script
+		_scriptVars[IN_SUBJECT] = 0;	// clear the subject list
 
 		// return special subject chosen code (same as in normal
 		// chooser routine below)
@@ -154,14 +154,14 @@
 		// new choose session
 		// build menus from subject_list
 
-		if (!IN_SUBJECT)
+		if (!_scriptVars[IN_SUBJECT])
 			error("fnChoose with no subjects :-O");
 
 		// init top menu from master list
 		// all icons are highlighted / full colour
 
 		for (i = 0; i < 15; i++) {
-			if (i < IN_SUBJECT) {
+			if (i < _scriptVars[IN_SUBJECT]) {
 				debug(5, " ICON res %d for %d", _subjectList[i].res, i);
 				icon = _vm->_resman->openResource(_subjectList[i].res) + sizeof(StandardHeader) + RDMENU_ICONWIDE * RDMENU_ICONDEEP;
 				_vm->_graphics->setMenuIcon(RDMENU_BOTTOM, (uint8) i, icon);
@@ -199,7 +199,7 @@
 	// Check for click on a menu. If so then end the choose, highlight only
 	// the chosen, blank the mouse and return the ref code * 8
 
-	hit = _vm->menuClick(IN_SUBJECT);
+	hit = _vm->menuClick(_scriptVars[IN_SUBJECT]);
 
 	if (hit < 0) {
 		debug(5, "end choose");
@@ -209,7 +209,7 @@
 	debug(5, "Icons available:");
 
 	// change icons
-	for (i = 0; i < IN_SUBJECT; i++) {
+	for (i = 0; i < _scriptVars[IN_SUBJECT]; i++) {
 		debug(5, "%s", _vm->fetchObjectName(_subjectList[i].res));
 
 		// change all others to grey
@@ -225,7 +225,7 @@
 	// this is our looping flag
 	_choosing = false;
 
-	IN_SUBJECT = 0;
+	_scriptVars[IN_SUBJECT] = 0;
 
 	// blank mouse again
 	_vm->setMouse(0);
@@ -234,7 +234,7 @@
 
 	// for non-speech scripts that manually
 	// call the chooser
-	RESULT = _subjectList[hit].res;
+	_scriptVars[RESULT] = _subjectList[hit].res;
 
 	// return special subject chosen code
 	return IR_CONT | (_subjectList[hit].ref << 3);
@@ -252,8 +252,8 @@
 
 	// params:	none
 
-	if (TALK_FLAG == 0)
-		CHOOSER_COUNT_FLAG = 0;	// see fnChooser & speech scripts
+	if (_scriptVars[TALK_FLAG] == 0)
+		_scriptVars[CHOOSER_COUNT_FLAG] = 0;	// see fnChooser & speech scripts
 
 	fnNoHuman(params);
 	return IR_CONT;
@@ -272,7 +272,7 @@
 		debug(5, "   holding");
 	}
 
-	TALK_FLAG = 0;	// in-case DC forgets
+	_scriptVars[TALK_FLAG] = 0;	// in-case DC forgets
 
 	// restart george's base script
 	// totalRestart();
@@ -311,20 +311,20 @@
 
 	// result is 1 for waiting, 0 for busy
 
-	if (RESULT == 1 && !INS_COMMAND) {
+	if (_scriptVars[RESULT] == 1 && !_scriptVars[INS_COMMAND]) {
 		// its waiting and no other command is queueing
 		// reset debug flag now that we're no longer waiting - see
 		// debug.cpp
 
 		_speechScriptWaiting = 0;
 
-		SPEECH_ID = params[0];
-		INS_COMMAND = params[1];
-		INS1 = params[2];
-		INS2 = params[3];
-		INS3 = params[4];
-		INS4 = params[5];
-		INS5 = params[6];
+		_scriptVars[SPEECH_ID] = params[0];
+		_scriptVars[INS_COMMAND] = params[1];
+		_scriptVars[INS1] = params[2];
+		_scriptVars[INS2] = params[3];
+		_scriptVars[INS3] = params[4];
+		_scriptVars[INS4] = params[5];
+		_scriptVars[INS5] = params[6];
 
 		return IR_CONT;
 	}
@@ -373,18 +373,18 @@
 
 	ob_logic = (ObjectLogic *) _vm->_memory->intToPtr(params[0]);
 
-	if (!INS_COMMAND && RESULT == 1 && ob_logic->looping == 0) {
+	if (!_scriptVars[INS_COMMAND] && _scriptVars[RESULT] == 1 && ob_logic->looping == 0) {
 		// first time so set up targets command if target is waiting
 
 		debug(5, "fnTheyDoWeWait sending command to %d", target);
 
-		SPEECH_ID = params[1];
-		INS_COMMAND = params[2];
-		INS1 = params[3];
-		INS2 = params[4];
-		INS3 = params[5];
-		INS4 = params[6];
-		INS5 = params[7];
+		_scriptVars[SPEECH_ID] = params[1];
+		_scriptVars[INS_COMMAND] = params[2];
+		_scriptVars[INS1] = params[3];
+		_scriptVars[INS2] = params[4];
+		_scriptVars[INS3] = params[5];
+		_scriptVars[INS4] = params[6];
+		_scriptVars[INS5] = params[7];
 
 		ob_logic->looping = 1;
 
@@ -407,7 +407,7 @@
 
 	// result is 1 for waiting, 0 for busy
 
-	if (RESULT == 1) {
+	if (_scriptVars[RESULT] == 1) {
 		// its waiting now so we can be finished with all this
 		debug(5, "fnTheyDoWeWait finished");
 
@@ -451,7 +451,7 @@
 
 	// result is 1 for waiting, 0 for busy
 
-	if (RESULT == 1) {
+	if (_scriptVars[RESULT] == 1) {
 		// reset debug flag now that we're no longer waiting - see
 		// debug.cpp
 		_speechScriptWaiting = 0;
@@ -499,12 +499,12 @@
 
 	// result is 1 for waiting, 0 for busy
 
-	if (RESULT == 1) {
+	if (_scriptVars[RESULT] == 1) {
 		// reset because counter is likely to be still high
 		ob_logic->looping = 0;
 
 		//means ok
-		RESULT = 0;
+		_scriptVars[RESULT] = 0;
 
 		// reset debug flag now that we're no longer waiting - see
 		// debug.cpp
@@ -517,7 +517,7 @@
 
 	if (!ob_logic->looping) {	// time up - caller must check RESULT
 		// not ok
-		RESULT = 1;
+		_scriptVars[RESULT] = 1;
 
 		// clear the event that hasn't been picked up - in theory,
 		// none of this should ever happen
@@ -774,31 +774,31 @@
 			break;
 		}
 
-		if (SPEECH_ID == ID) {
+		if (_scriptVars[SPEECH_ID] == _scriptVars[ID]) {
 			// new command for us!
 			// clear this or it could trigger next go
-			SPEECH_ID = 0;
+			_scriptVars[SPEECH_ID] = 0;
 
 			// grab the command - potentially, we only have this
 			// cycle to do this
 
-			ob_speech->command = INS_COMMAND;
-			ob_speech->ins1 = INS1;
-			ob_speech->ins2 = INS2;
-			ob_speech->ins3 = INS3;
-			ob_speech->ins4 = INS4;
-			ob_speech->ins5 = INS5;
+			ob_speech->command = _scriptVars[INS_COMMAND];
+			ob_speech->ins1 = _scriptVars[INS1];
+			ob_speech->ins2 = _scriptVars[INS2];
+			ob_speech->ins3 = _scriptVars[INS3];
+			ob_speech->ins4 = _scriptVars[INS4];
+			ob_speech->ins5 = _scriptVars[INS5];
+
+			debug(5, "received new command %d", _scriptVars[INS_COMMAND]);
 
 			// the current send has been received - i.e. separate
 			// multiple they-do's
 
-			INS_COMMAND = 0;
+			_scriptVars[INS_COMMAND] = 0;
 
 			// now busy
 			ob_speech->wait_state = 0;
 
-			debug(5, "received new command %d", INS_COMMAND);
-
 			// we'll drop off and be caught by the while(1), so
 			// kicking in the new command straight away
 		} else {
@@ -906,8 +906,8 @@
 		// See 'testing_routines' object in George's Player Character
 		// section of linc
 
-		if (SYSTEM_TESTING_TEXT) {
-			RESULT = 0;
+		if (_scriptVars[SYSTEM_TESTING_TEXT]) {
+			_scriptVars[RESULT] = 0;
 
 			text_res = params[S_TEXT] / SIZE;
 			local_text = params[S_TEXT] & 0xffff;
@@ -924,22 +924,22 @@
 					// if line number is out of range
 					if (!_vm->checkTextLine((uint8 *) head, local_text)) {
 						// line number out of range
-						RESULT = 2;
+						_scriptVars[RESULT] = 2;
 					}
 				} else {
 					// invalid (not a text resource)
-					RESULT = 1;
+					_scriptVars[RESULT] = 1;
 				}
 
 				// close the resource
 				_vm->_resman->closeResource(text_res);
 
-				if (RESULT)
+				if (_scriptVars[RESULT])
 					return IR_CONT;
 			} else {
 				// not a valid resource number - invalid (null
 				// resource)
-				RESULT = 1;
+				_scriptVars[RESULT] = 1;
 				return IR_CONT;
 			}
 		}
@@ -961,12 +961,12 @@
 		// prevent dud lines from appearing while testing text & speech
 		// since these will not occur in the game anyway
 
-		if (SYSTEM_TESTING_TEXT) {	// if testing text & speech
+		if (_scriptVars[SYSTEM_TESTING_TEXT]) {	// if testing text & speech
 			// if actor number is 0 and text line is just a 'dash'
 			// character
 			if (_officialTextNumber == 0 && text[2] == '-' && text[3] == 0) {
 				// dud line - return & continue script
-				RESULT = 3;
+				_scriptVars[RESULT] = 3;
 				return IR_CONT;
 			}
 		}
@@ -984,10 +984,10 @@
 		// Write to walkthrough file (zebug0.txt)
 		// if (player_id != george), then player is controlling Nico
 
-		if (PLAYER_ID != CUR_PLAYER_ID)
+		if (_scriptVars[PLAYER_ID] != CUR_PLAYER_ID)
 			debug(5, "(%d) Nico: %s", _officialTextNumber, text + 2);
 		else
-			debug(5, "(%d) %s: %s", _officialTextNumber, _vm->fetchObjectName(ID), text + 2);
+			debug(5, "(%d) %s: %s", _officialTextNumber, _vm->fetchObjectName(_scriptVars[ID]), text + 2);
 
 		// Set up the speech animation
 
@@ -996,7 +996,7 @@
 			_animId = params[S_ANIM];
 
 			// anim type
-			_speechAnimType = SPEECHANIMFLAG;
+			_speechAnimType = _scriptVars[SPEECHANIMFLAG];
 
 			// set the talker's graphic to this speech anim now
 			ob_graphic->anim_resource = _animId;
@@ -1016,7 +1016,7 @@
 			_animId = anim_table[ob_mega->current_dir];
 
 			// anim type
-			_speechAnimType = SPEECHANIMFLAG;
+			_speechAnimType = _scriptVars[SPEECHANIMFLAG];
 
 			// set the talker's graphic to this speech anim now
 			ob_graphic->anim_resource = _animId;
@@ -1029,7 +1029,7 @@
 		}
 
 		// Default back to looped lip synced anims.
-		SPEECHANIMFLAG = 0;
+		_scriptVars[SPEECHANIMFLAG] = 0;
 
 		// set up '_textX' & '_textY' for speech-pan and/or
 		// text-sprite position
@@ -1180,7 +1180,7 @@
 
 	// so that we can go to the options panel while text & speech is
 	// being tested
-	if (SYSTEM_TESTING_TEXT == 0 || _vm->_input->_mouseY > 0) {
+	if (_scriptVars[SYSTEM_TESTING_TEXT] == 0 || _vm->_input->_mouseY > 0) {
 		me = _vm->_input->mouseEvent();
 
 		// Note that we now have TWO click-delays - one for LEFT
@@ -1192,14 +1192,14 @@
 			// the speech we ignore mouse releases
 
 			// if testing text & speech
-			if (SYSTEM_TESTING_TEXT) {
+			if (_scriptVars[SYSTEM_TESTING_TEXT]) {
 				// and RB used to click past text
 				if (me->buttons & RD_RIGHTBUTTONDOWN) {
 					// then we want the previous line again
-					SYSTEM_WANT_PREVIOUS_LINE = 1;
+					_scriptVars[SYSTEM_WANT_PREVIOUS_LINE] = 1;
 				} else {
 					// LB just want next line again
-					SYSTEM_WANT_PREVIOUS_LINE = 0;
+					_scriptVars[SYSTEM_WANT_PREVIOUS_LINE] = 0;
 				}
 			}
 
@@ -1249,7 +1249,7 @@
 		// this number comes from the text line)
 		_officialTextNumber = 0;
 
-		RESULT = 0;	// ok
+		_scriptVars[RESULT] = 0;	// ok
 		return IR_CONT;
 	}
 

Index: startup.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/startup.cpp,v
retrieving revision 1.39
retrieving revision 1.40
diff -u -d -r1.39 -r1.40
--- startup.cpp	5 Feb 2004 14:19:05 -0000	1.39
+++ startup.cpp	17 Mar 2004 09:03:15 -0000	1.40
@@ -214,8 +214,7 @@
 
 		// reopen global variables resource & send address to
 		// interpreter - it won't be moving
-		setGlobalInterpreterVariables((int32 *) (_vm->_resman->openResource(1) + sizeof(StandardHeader)));
-		_vm->_resman->closeResource(1);
+		_vm->_logic->resetScriptVars();
 
 		// free all the route memory blocks from previous game
 		_router->freeAllRouteMem();

Index: sword2.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/sword2.cpp,v
retrieving revision 1.105
retrieving revision 1.106
diff -u -d -r1.105 -r1.106
--- sword2.cpp	4 Mar 2004 08:03:32 -0000	1.105
+++ sword2.cpp	17 Mar 2004 09:03:15 -0000	1.106
@@ -224,13 +224,9 @@
 int32 Sword2Engine::initialiseGame(void) {
 	// init engine drivers
 
-	uint8 *file;
-
 	// initialise global script variables
 	// res 1 is the globals list
-	file = _resman->openResource(1);
-	debug(5, "CALLING: SetGlobalInterpreterVariables");
-	_logic->setGlobalInterpreterVariables((int32 *) (file + sizeof(StandardHeader)));
+	Logic::_scriptVars = (uint32 *) (_resman->openResource(1) + sizeof(StandardHeader));
 
 	// DON'T CLOSE VARIABLES RESOURCE - KEEP IT OPEN AT VERY START OF
 	// MEMORY SO IT CAN'T MOVE!
@@ -238,7 +234,7 @@
 	// DON'T CLOSE PLAYER OBJECT RESOURCE - KEEP IT OPEN IN MEMORY SO IT
 	// CAN'T MOVE!
 
-	file = _resman->openResource(8);
+	_resman->openResource(8);
 
 	// Set up font resource variables for this language version
 
@@ -252,9 +248,9 @@
 
 	// all demos (not just web)
 	if (_features & GF_DEMO)
-		DEMO = 1;
+		Logic::_scriptVars[DEMO] = 1;
 	else
-		DEMO = 0;
+		Logic::_scriptVars[DEMO] = 0;
 
 	return 0;
 }
@@ -380,7 +376,7 @@
 						pauseGame();
 					break;
 				case 'c':
-					if (!DEMO && !_logic->_choosing)
+					if (!Logic::_scriptVars[DEMO] && !_logic->_choosing)
 						_logic->fnPlayCredits(NULL);
 					break;
 #ifdef _SWORD2_DEBUG
@@ -440,7 +436,7 @@
 	debug(5, "startGame() STARTING:");
 
 	// all demos not just web
-	if (DEMO)
+	if (Logic::_scriptVars[DEMO])
 		screen_manager_id = 19;		// DOCKS SECTION START
 	else
 		screen_manager_id = 949;	// INTRO & PARIS START
@@ -526,7 +522,7 @@
 }
 
 void Sword2Engine::unpauseGame(void) {
-	if (OBJECT_HELD && _realLuggageItem)
+	if (Logic::_scriptVars[OBJECT_HELD] && _realLuggageItem)
 		setLuggage(_realLuggageItem);
 
 	unpauseAllSound();

Index: sync.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/sync.cpp,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -d -r1.18 -r1.19
--- sync.cpp	5 Feb 2004 14:19:05 -0000	1.18
+++ sync.cpp	17 Mar 2004 09:03:15 -0000	1.19
@@ -32,7 +32,7 @@
 
 	for (int i = 0; i < MAX_syncs; i++) {
 		if (_syncList[i].id == 0) {
-			debug(5, " %d sending sync %d to %d", ID, params[1], params[0]);
+			debug(5, " %d sending sync %d to %d", _scriptVars[ID], params[1], params[0]);
 			_syncList[i].id = params[0];
 			_syncList[i].sync = params[1];
 			return IR_CONT;
@@ -66,7 +66,7 @@
 	// animation to be quit
 
 	for (int i = 0; i < MAX_syncs; i++) {
-		if (_syncList[i].id == ID) {
+		if (_syncList[i].id == _scriptVars[ID]) {
 			// means sync found
 			return true;
 		}
@@ -83,15 +83,15 @@
 	// params:	none
 
 	for (int i = 0; i < MAX_syncs; i++) {
-		if (_syncList[i].id == ID) {
+		if (_syncList[i].id == _scriptVars[ID]) {
 			// return sync value waiting
-			RESULT = _syncList[i].sync;
+			_scriptVars[RESULT] = _syncList[i].sync;
 			return IR_CONT;
 		}
 	}
 
 	// no sync found
-	RESULT = 0;
+	_scriptVars[RESULT] = 0;
 	return IR_CONT;
 }
 
@@ -100,13 +100,13 @@
 
 	// params:	none
 
-	debug(5, "fnWaitSync: %d waits", ID);
+	debug(5, "fnWaitSync: %d waits", _scriptVars[ID]);
 
 	for (int i = 0; i < MAX_syncs; i++) {
-		if (_syncList[i].id == ID) {
+		if (_syncList[i].id == _scriptVars[ID]) {
 			// return sync value waiting
 			debug(5, "fnWaitSync: go");
-			RESULT = _syncList[i].sync;
+			_scriptVars[RESULT] = _syncList[i].sync;
 			return IR_CONT;
 		}
 	}

Index: walker.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/walker.cpp,v
retrieving revision 1.35
retrieving revision 1.36
diff -u -d -r1.35 -r1.36
--- walker.cpp	5 Feb 2004 14:19:05 -0000	1.35
+++ walker.cpp	17 Mar 2004 09:03:15 -0000	1.36
@@ -78,7 +78,8 @@
 		// anim.
 		
 		if (ob_mega->feet_x == target_x && ob_mega->feet_y == target_y && ob_mega->current_dir == target_dir) {
-			RESULT = 0;	// 0 means ok - finished walk
+			// 0 means ok - finished walk
+			_scriptVars[RESULT] = 0;
 			return IR_CONT;	// may as well continue the script
 		}
 
@@ -119,7 +120,7 @@
 			_router->freeRouteMem();
 
 			// 1 means error, no walk created
-			RESULT = 1;
+			_scriptVars[RESULT] = 1;
 
 			// may as well continue the script
 			return IR_CONT;
@@ -129,7 +130,7 @@
 		// resource
 
 		ob_graph->anim_resource = ob_mega->megaset_res;
-	} else if (EXIT_FADING && _vm->_graphics->getFadeStatus() == RDFADE_BLACK) {
+	} else if (_scriptVars[EXIT_FADING] && _vm->_graphics->getFadeStatus() == RDFADE_BLACK) {
 		// double clicked an exit so quit the walk when screen is black
 
 		// ok, thats it - back to script and change screen
@@ -139,18 +140,18 @@
 
 		// must clear in-case on the new screen there's a walk
 		// instruction (which would get cut short)
-		EXIT_CLICK_ID = 0;
+		_scriptVars[EXIT_CLICK_ID] = 0;
 
 		// this will be reset when we change screens, so we can use
 		// it in script to check if a 2nd-click came along
-		// EXIT_FADING = 0;
+		// _scriptVars[EXIT_FADING] = 0;
 
 		// finished walk
 		ob_mega->currently_walking = 0;
 
 		// (see fnGetPlayerSaveData() in save_rest.cpp
 
-		RESULT = 0;		// 0 means ok
+		_scriptVars[RESULT] = 0;		// 0 means ok
 
 		// continue the script so that RESULT can be checked!
 		return IR_CONT;
@@ -206,10 +207,12 @@
 
 		if (checkEventWaiting()) {
 			startEvent();
-			RESULT = 1;		// 1 means didn't finish walk
+			// 1 means didn't finish walk
+			_scriptVars[RESULT] = 1;
 			return IR_TERMINATE;
 		} else {
-			RESULT = 0;		// 0 means ok - finished walk
+			// 0 means ok - finished walk
+			_scriptVars[RESULT] = 0;
 
 			// CONTINUE the script so that RESULT can be checked!
 			// Also, if an anim command follows the fnWalk command,
@@ -724,7 +727,7 @@
 	// re-enter a location
 
 	// DON'T EVER KILL GEORGE!
-	if (ID != 8) {
+	if (_scriptVars[ID] != 8) {
 		// need to call this in case it wasn't called in script!
 		// ('params' just used as dummy param)
 		fnAddToKillList(params);





More information about the Scummvm-git-logs mailing list