aboutsummaryrefslogtreecommitdiff
path: root/sword2
diff options
context:
space:
mode:
Diffstat (limited to 'sword2')
-rw-r--r--sword2/anims.cpp10
-rw-r--r--sword2/build_display.cpp18
-rw-r--r--sword2/console.cpp8
-rw-r--r--sword2/controls.cpp11
-rw-r--r--sword2/debug.cpp35
-rw-r--r--sword2/defs.h226
-rw-r--r--sword2/events.cpp14
-rw-r--r--sword2/function.cpp16
-rw-r--r--sword2/icons.cpp12
-rw-r--r--sword2/interpreter.cpp26
-rw-r--r--sword2/logic.cpp38
-rw-r--r--sword2/logic.h32
-rw-r--r--sword2/maketext.cpp7
-rw-r--r--sword2/memory.cpp6
-rw-r--r--sword2/mouse.cpp124
-rw-r--r--sword2/resman.cpp2
-rw-r--r--sword2/router.cpp17
-rw-r--r--sword2/save_rest.cpp4
-rw-r--r--sword2/scroll.cpp16
-rw-r--r--sword2/sound.cpp6
-rw-r--r--sword2/speech.cpp144
-rw-r--r--sword2/startup.cpp3
-rw-r--r--sword2/sword2.cpp18
-rw-r--r--sword2/sync.cpp16
-rw-r--r--sword2/walker.cpp21
25 files changed, 420 insertions, 410 deletions
diff --git a/sword2/anims.cpp b/sword2/anims.cpp
index 6614ce6e82..17e90bf036 100644
--- a/sword2/anims.cpp
+++ b/sword2/anims.cpp
@@ -107,7 +107,7 @@ int32 Logic::animate(int32 *params, bool reverse) {
// '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 @@ int32 Logic::animate(int32 *params, bool reverse) {
#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 @@ int32 Logic::animate(int32 *params, bool reverse) {
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 @@ int32 Logic::fnSetFrame(int32 *params) {
#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 @@ int32 Logic::fnPlaySequence(int32 *params) {
MoviePlayer player(_vm);
- if (_sequenceTextLines && !DEMO)
+ if (_sequenceTextLines && !_scriptVars[DEMO])
rv = player.play(filename, sequenceSpeechArray, leadOut);
else
rv = player.play(filename, NULL, leadOut);
diff --git a/sword2/build_display.cpp b/sword2/build_display.cpp
index 3466149f96..b7758a4499 100644
--- a/sword2/build_display.cpp
+++ b/sword2/build_display.cpp
@@ -465,7 +465,7 @@ void Sword2Engine::processImage(BuildUnit *build_unit) {
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 @@ void Sword2Engine::registerFrame(int32 *params, BuildUnit *build_unit) {
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 @@ void Sword2Engine::registerFrame(int32 *params, BuildUnit *build_unit) {
// 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 @@ int32 Logic::fnUpdatePlayerStats(int32 *params) {
_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 @@ void Sword2Engine::setFullPalette(int32 palRes) {
// 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
diff --git a/sword2/console.cpp b/sword2/console.cpp
index 6f1d67f2d0..a9497ae361 100644
--- a/sword2/console.cpp
+++ b/sword2/console.cpp
@@ -118,13 +118,13 @@ Debugger::Debugger(Sword2Engine *vm)
}
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() {
diff --git a/sword2/controls.cpp b/sword2/controls.cpp
index bb1d7bb7e9..755ad1ebad 100644
--- a/sword2/controls.cpp
+++ b/sword2/controls.cpp
@@ -1617,10 +1617,10 @@ void Gui::restartControl(void) {
_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 @@ void Gui::restartControl(void) {
// 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
diff --git a/sword2/debug.cpp b/sword2/debug.cpp
index df8d33f2f4..85a463932a 100644
--- a/sword2/debug.cpp
+++ b/sword2/debug.cpp
@@ -59,7 +59,6 @@ void Debugger::buildDebugText(void) {
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 @@ void Debugger::buildDebugText(void) {
// 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 @@ void Debugger::buildDebugText(void) {
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 @@ void Debugger::buildDebugText(void) {
// 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 @@ void Debugger::buildDebugText(void) {
// 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 @@ void Debugger::buildDebugText(void) {
// 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 @@ void Debugger::buildDebugText(void) {
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 @@ void Debugger::buildDebugText(void) {
// 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 @@ void Debugger::drawDebugGraphics(void) {
// 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) {
diff --git a/sword2/defs.h b/sword2/defs.h
index 3b88134894..0968419372 100644
--- a/sword2/defs.h
+++ b/sword2/defs.h
@@ -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 MOUSE_X VAR(4)
-#define MOUSE_Y VAR(5)
-#define LEFT_BUTTON VAR(109)
-#define RIGHT_BUTTON VAR(110)
-#define CLICKED_ID VAR(178)
-
-#define IN_SUBJECT VAR(6)
-#define COMBINE_BASE VAR(7)
-#define OBJECT_HELD VAR(14)
-
-#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)
-
-#define PLAYER_FEET_X VAR(141)
-#define PLAYER_FEET_Y VAR(142)
-#define PLAYER_CUR_DIR VAR(937)
-
-// for debug.cpp
-#define LOCATION VAR(62)
-
-// so scripts can force scroll offsets
-#define SCROLL_X VAR(345)
-#define SCROLL_Y VAR(346)
-
-#define EXIT_CLICK_ID VAR(710)
-#define EXIT_FADING VAR(713)
-
-#define SYSTEM_TESTING_ANIMS VAR(912)
-#define SYSTEM_TESTING_TEXT VAR(1230)
-#define SYSTEM_WANT_PREVIOUS_LINE VAR(1245)
-
-// 1=on 0=off (set in fnAddHuman and fnNoHuman)
-#define MOUSE_AVAILABLE VAR(686)
-
-// used in fnChoose
-#define AUTO_SELECTED VAR(1115)
-
-// see fnStartConversation and fnChooser
-#define CHOOSER_COUNT_FLAG VAR(15)
-
-// signifies a demo mode
-#define DEMO VAR(1153)
+#define CUR_PLAYER_ID 8
-// Indicates to script whether this is the Playstation version.
-// #define PSXFLAG VAR(1173)
-
-// 1 = dead
-#define DEAD VAR(1256)
-
- // If set indicates that the speech anim is to run through only once.
-#define SPEECHANIMFLAG VAR(1278)
-
-// for the engine
-#define SCROLL_OFFSET_X VAR(1314)
-
-// for the poor PSX so it knows what language is running.
-// #define GAME_LANGUAGE VAR(111)
-
-// resource id's of pouse mointers. It's pretty much safe to do it like this
-
-#define NORMAL_MOUSE_ID 17
-#define SCROLL_LEFT_MOUSE_ID 1440
-#define SCROLL_RIGHT_MOUSE_ID 1441
-
-// Console Font - does not use game text - only English required
-#define CONSOLE_FONT_ID 340 // ConsFont
-
-// Speech Font
-#define ENGLISH_SPEECH_FONT_ID 341 // SpchFont
-#define FINNISH_SPEECH_FONT_ID 956 // FinSpcFn
-#define POLISH_SPEECH_FONT_ID 955 // PolSpcFn
-
-// 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
-
-// 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
-
-// Control panel palette resource id
-
-#define CONTROL_PANEL_PALETTE 261
-
-// 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
+// global variable references
-// res id of conversation exit icon, 'EXIT' menu icon (used in fnChoose)
-#define EXIT_ICON 65
+enum {
+ ID = 0,
+ RESULT = 1,
+ PLAYER_ACTION = 2,
+ // CUR_PLAYER_ID = 3,
+ PLAYER_ID = 305,
+ TALK_FLAG = 13,
+
+ MOUSE_X = 4,
+ MOUSE_Y = 5,
+ LEFT_BUTTON = 109,
+ RIGHT_BUTTON = 110,
+ CLICKED_ID = 178,
+
+ IN_SUBJECT = 6,
+ COMBINE_BASE = 7,
+ OBJECT_HELD = 14,
+
+ SPEECH_ID = 9,
+ INS1 = 10,
+ INS2 = 11,
+ INS3 = 12,
+ INS4 = 60,
+ INS5 = 61,
+ INS_COMMAND = 59,
+
+ PLAYER_FEET_X = 141,
+ PLAYER_FEET_Y = 142,
+ PLAYER_CUR_DIR = 937,
+
+ // for debug.cpp
+ LOCATION = 62,
+
+ // so scripts can force scroll offsets
+ SCROLL_X = 345,
+ SCROLL_Y = 346,
+
+ EXIT_CLICK_ID = 710,
+ EXIT_FADING = 713,
+
+ SYSTEM_TESTING_ANIMS = 912,
+ SYSTEM_TESTING_TEXT = 1230,
+ SYSTEM_WANT_PREVIOUS_LINE = 1245,
+
+ // 1=on 0=off (set in fnAddHuman and fnNoHuman)
+ MOUSE_AVAILABLE = 686,
+
+ // used in fnChoose
+ AUTO_SELECTED = 1115,
+
+ // see fnStartConversation and fnChooser
+ CHOOSER_COUNT_FLAG = 15,
+
+ // signifies a demo mode
+ DEMO = 1153,
+
+ // Indicates to script whether this is the Playstation version.
+ // PSXFLAG = 1173,
+
+ // for the poor PSX so it knows what language is running.
+ // GAME_LANGUAGE = 111,
+
+ // 1 = dead
+ DEAD = 1256,
+
+ // If set indicates that the speech anim is to run through only once.
+ SPEECHANIMFLAG = 1278,
+
+ // for the engine
+ SCROLL_OFFSET_X = 1314
+};
+
+// Resource IDs
+
+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,
+
+ // Console Font - does not use game text - only English required
+ CONSOLE_FONT_ID = 340,
+
+ // Speech Font
+ ENGLISH_SPEECH_FONT_ID = 341,
+ FINNISH_SPEECH_FONT_ID = 956,
+ POLISH_SPEECH_FONT_ID = 955,
+
+ // Control Panel Font (and un-selected savegame descriptions)
+ ENGLISH_CONTROLS_FONT_ID = 2005,
+ FINNISH_CONTROLS_FONT_ID = 959,
+ POLISH_CONTROLS_FONT_ID = 3686,
+
+ // 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
+
+ // Control panel palette resource id
+ CONTROL_PANEL_PALETTE = 261,
+
+ // 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
diff --git a/sword2/events.cpp b/sword2/events.cpp
index ad11bad8e4..e704897ac6 100644
--- a/sword2/events.cpp
+++ b/sword2/events.cpp
@@ -66,7 +66,7 @@ void Logic::setPlayerActionEvent(uint32 id, uint32 interact_id) {
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 @@ void Logic::startEvent(void) {
// 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 @@ void Logic::startEvent(void) {
}
// 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::fnSendEvent(int32 *params) {
}
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::fnPauseForEvent(int32 *params) {
int32 Logic::fnClearEvent(int32 *params) {
// params: none
- clearEvent(ID);
+ clearEvent(_scriptVars[ID]);
return IR_CONT;
}
diff --git a/sword2/function.cpp b/sword2/function.cpp
index 831411691c..2f95fd564b 100644
--- a/sword2/function.cpp
+++ b/sword2/function.cpp
@@ -58,7 +58,7 @@ int32 Logic::fnNewScript(int32 *params) {
// 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 @@ int32 Logic::fnInteract(int32 *params) {
// 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::fnRelease(int32 *params) {
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 @@ int32 Logic::fnRandomPause(int32 *params) {
pars[1] = params[2];
fnRandom(pars);
- pars[1] = RESULT;
+ pars[1] = _scriptVars[RESULT];
}
pars[0] = params[0];
@@ -396,7 +396,7 @@ int32 Logic::fnPlayCredits(int32 *params) {
// params: none
- if (DEMO) {
+ if (_scriptVars[DEMO]) {
_vm->closeGame();
return IR_STOP;
}
@@ -619,7 +619,7 @@ int32 Logic::fnPlayCredits(int32 *params) {
// 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 @@ int32 Logic::fnPlayCredits(int32 *params) {
if (!_vm->_mouseStatus || _choosing)
_vm->setMouse(NORMAL_MOUSE_ID);
- if (DEAD)
+ if (_scriptVars[DEAD])
_vm->buildSystemMenu();
return IR_CONT;
diff --git a/sword2/icons.cpp b/sword2/icons.cpp
index d09043a99e..2771a39cb6 100644
--- a/sword2/icons.cpp
+++ b/sword2/icons.cpp
@@ -48,7 +48,7 @@ int32 Logic::fnRefreshInventory(int32 *params) {
// 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 @@ void Sword2Engine::buildMenu(void) {
// 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 @@ void Sword2Engine::buildMenu(void) {
// 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 @@ void Sword2Engine::buildMenu(void) {
// 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 @@ void Sword2Engine::buildSystemMenu(void) {
// 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);
diff --git a/sword2/interpreter.cpp b/sword2/interpreter.cpp
index 31803c065e..c84360ffdd 100644
--- a/sword2/interpreter.cpp
+++ b/sword2/interpreter.cpp
@@ -25,6 +25,8 @@
namespace Sword2 {
+#define STACK_SIZE 10
+
// The machine code table
#define OPCODE(x) { &Logic::x, #x }
@@ -194,9 +196,7 @@ do { \
#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 @@ int Logic::runScript(char *scriptData, char *objectData, uint32 *offset) {
// 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 @@ int Logic::runScript(char *scriptData, char *objectData, uint32 *offset) {
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 @@ int Logic::runScript(char *scriptData, char *objectData, uint32 *offset) {
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 @@ int Logic::runScript(char *scriptData, char *objectData, uint32 *offset) {
// 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
diff --git a/sword2/logic.cpp b/sword2/logic.cpp
index f7dab314b7..6d9596c874 100644
--- a/sword2/logic.cpp
+++ b/sword2/logic.cpp
@@ -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 @@ int Logic::processSession(void) {
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 @@ int Logic::processSession(void) {
// 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 @@ int Logic::processSession(void) {
// 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 @@ int Logic::processSession(void) {
// 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 @@ void Logic::expressChangeSession(uint32 sesh_id) {
_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 @@ void Logic::logicUp(uint32 new_script) {
// 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 @@ int32 Logic::fnAddToKillList(int32 *params) {
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 @@ int32 Logic::fnAddToKillList(int32 *params) {
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"
diff --git a/sword2/logic.h b/sword2/logic.h
index fc44ce8ac8..ebb8368b03 100644
--- a/sword2/logic.h
+++ b/sword2/logic.h
@@ -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 @@ class Logic {
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 @@ private:
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 @@ public:
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 @@ public:
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 {
diff --git a/sword2/maketext.cpp b/sword2/maketext.cpp
index 3555e46a1a..bc528bba28 100644
--- a/sword2/maketext.cpp
+++ b/sword2/maketext.cpp
@@ -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 @@ Memory *FontRenderer::makeTextSprite(uint8 *sentence, uint16 maxWidth, uint8 pen
// 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 @@ Memory *FontRenderer::buildTextSprite(uint8 *sentence, uint32 fontRes, uint8 pen
// 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 @@ void Sword2Engine::initialiseFontResourceFlags(void) {
// 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;
diff --git a/sword2/memory.cpp b/sword2/memory.cpp
index 4d45e45682..9ae7af92c8 100644
--- a/sword2/memory.cpp
+++ b/sword2/memory.cpp
@@ -73,7 +73,7 @@ MemoryManager::MemoryManager(Sword2Engine *vm) : _vm(vm) {
_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 @@ Memory *MemoryManager::lowLevelAlloc(uint32 size, uint32 type, uint32 unique_id)
}
_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 @@ void MemoryManager::freeMemory(Memory *block) {
// 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();
diff --git a/sword2/mouse.cpp b/sword2/mouse.cpp
index cc25c35244..65f7b43b0e 100644
--- a/sword2/mouse.cpp
+++ b/sword2/mouse.cpp
@@ -72,7 +72,7 @@ void Sword2Engine::mouseEngine(void) {
// 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 @@ void Sword2Engine::systemMenuMouse(void) {
// 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 @@ void Sword2Engine::systemMenuMouse(void) {
// 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 @@ void Sword2Engine::systemMenuMouse(void) {
// 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 @@ void Sword2Engine::dragMouse(void) {
// 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 @@ void Sword2Engine::dragMouse(void) {
// 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 @@ void Sword2Engine::dragMouse(void) {
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 @@ void Sword2Engine::dragMouse(void) {
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 @@ void Sword2Engine::menuMouse(void) {
// 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 @@ void Sword2Engine::menuMouse(void) {
noHuman();
debug(2, "Right-click on \"%s\" icon",
- fetchObjectName(OBJECT_HELD));
+ fetchObjectName(Logic::_scriptVars[OBJECT_HELD]));
return;
}
@@ -441,13 +445,13 @@ void Sword2Engine::menuMouse(void) {
_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 @@ void Sword2Engine::menuMouse(void) {
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 @@ void Sword2Engine::normalMouse(void) {
// 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 @@ void Sword2Engine::normalMouse(void) {
// 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 @@ void Sword2Engine::normalMouse(void) {
// 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 @@ void Sword2Engine::normalMouse(void) {
// 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 @@ void Sword2Engine::normalMouse(void) {
// 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 @@ void Sword2Engine::normalMouse(void) {
// 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 @@ void Sword2Engine::normalMouse(void) {
// 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 @@ void Sword2Engine::mouseOnOff(void) {
setMouse(pointer_type);
// setup luggage icon
- if (OBJECT_HELD) {
+ if (Logic::_scriptVars[OBJECT_HELD]) {
setLuggage(_currentLuggageResource);
}
} else
@@ -1014,7 +1022,7 @@ void Sword2Engine::noHuman(void) {
// 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 @@ void Sword2Engine::registerMouse(ObjectMouse *ob_mouse) {
// 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 @@ int32 Logic::fnNoHuman(int32 *params) {
// 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 @@ int32 Logic::fnAddHuman(int32 *params) {
// params: none
// for logic scripts
- MOUSE_AVAILABLE = 1;
+ _scriptVars[MOUSE_AVAILABLE] = 1;
// off
if (_vm->_mouseStatus) {
@@ -1106,8 +1114,8 @@ int32 Logic::fnAddHuman(int32 *params) {
_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 @@ int32 Logic::fnAddHuman(int32 *params) {
_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 @@ int32 Logic::fnRegisterPointerText(int32 *params) {
// 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 @@ int32 Logic::fnSetObjectHeld(int32 *params) {
_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 @@ int32 Logic::fnCheckPlayerActivity(int32 *params) {
// positive check
_vm->_playerActivityDelay = 0;
- RESULT = 1;
+ _scriptVars[RESULT] = 1;
} else
- RESULT = 0;
+ _scriptVars[RESULT] = 0;
return IR_CONT;
}
diff --git a/sword2/resman.cpp b/sword2/resman.cpp
index 31b5db1eee..4fbf6cfdc5 100644
--- a/sword2/resman.cpp
+++ b/sword2/resman.cpp
@@ -90,7 +90,7 @@ ResourceManager::ResourceManager(Sword2Engine *vm) {
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();
diff --git a/sword2/router.cpp b/sword2/router.cpp
index cf75d75762..59eddd059e 100644
--- a/sword2/router.cpp
+++ b/sword2/router.cpp
@@ -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 @@ void Router::allocateRouteMem(void) {
// 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 @@ void Router::allocateRouteMem(void) {
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 @@ void Router::allocateRouteMem(void) {
}
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 @@ int32 Router::solidWalkAnimator(WalkData *walkAnim) {
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;
}
diff --git a/sword2/save_rest.cpp b/sword2/save_rest.cpp
index 63784aa520..264416abe2 100644
--- a/sword2/save_rest.cpp
+++ b/sword2/save_rest.cpp
@@ -96,7 +96,7 @@ uint32 Sword2Engine::saveGame(uint16 slotNo, uint8 *desc) {
// 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 @@ uint32 Sword2Engine::restoreGame(uint16 slotNo) {
// 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
diff --git a/sword2/scroll.cpp b/sword2/scroll.cpp
index 744073a0a7..45be9a939a 100644
--- a/sword2/scroll.cpp
+++ b/sword2/scroll.cpp
@@ -44,18 +44,10 @@ void Sword2Engine::setScrolling(void) {
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
diff --git a/sword2/sound.cpp b/sword2/sound.cpp
index 90e1356e65..cc8b199cfe 100644
--- a/sword2/sound.cpp
+++ b/sword2/sound.cpp
@@ -258,7 +258,7 @@ int32 Logic::fnPlayFx(int32 *params) {
// 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 @@ int32 Logic::fnPlayMusic(int32 *params) {
// 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 @@ int32 Logic::fnCheckMusicPlaying(int32 *params) {
// 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;
}
diff --git a/sword2/speech.cpp b/sword2/speech.cpp
index 6726856fd3..36bb2a6a2e 100644
--- a/sword2/speech.cpp
+++ b/sword2/speech.cpp
@@ -56,7 +56,7 @@ int32 Logic::fnAddSubject(int32 *params) {
// 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 @@ int32 Logic::fnAddSubject(int32 *params) {
// 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 @@ int32 Logic::fnChoose(int32 *params) {
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 @@ int32 Logic::fnChoose(int32 *params) {
// 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 @@ int32 Logic::fnChoose(int32 *params) {
}
}
- 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 @@ int32 Logic::fnChoose(int32 *params) {
// 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 @@ int32 Logic::fnChoose(int32 *params) {
// 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 @@ int32 Logic::fnChoose(int32 *params) {
// 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 @@ int32 Logic::fnChoose(int32 *params) {
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 @@ int32 Logic::fnChoose(int32 *params) {
// this is our looping flag
_choosing = false;
- IN_SUBJECT = 0;
+ _scriptVars[IN_SUBJECT] = 0;
// blank mouse again
_vm->setMouse(0);
@@ -234,7 +234,7 @@ int32 Logic::fnChoose(int32 *params) {
// 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 @@ int32 Logic::fnStartConversation(int32 *params) {
// 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 @@ int32 Logic::fnEndConversation(int32 *params) {
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 @@ int32 Logic::fnTheyDo(int32 *params) {
// 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 @@ int32 Logic::fnTheyDoWeWait(int32 *params) {
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 @@ int32 Logic::fnTheyDoWeWait(int32 *params) {
// 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 @@ int32 Logic::fnWeWait(int32 *params) {
// 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 @@ int32 Logic::fnTimedWait(int32 *params) {
// 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 @@ int32 Logic::fnTimedWait(int32 *params) {
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 @@ int32 Logic::fnSpeechProcess(int32 *params) {
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 @@ int32 Logic::fnISpeak(int32 *params) {
// 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 @@ int32 Logic::fnISpeak(int32 *params) {
// 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 @@ int32 Logic::fnISpeak(int32 *params) {
// 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 @@ int32 Logic::fnISpeak(int32 *params) {
// 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 @@ int32 Logic::fnISpeak(int32 *params) {
_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 @@ int32 Logic::fnISpeak(int32 *params) {
_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 @@ int32 Logic::fnISpeak(int32 *params) {
}
// 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 @@ int32 Logic::fnISpeak(int32 *params) {
// 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 @@ int32 Logic::fnISpeak(int32 *params) {
// 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 @@ int32 Logic::fnISpeak(int32 *params) {
// this number comes from the text line)
_officialTextNumber = 0;
- RESULT = 0; // ok
+ _scriptVars[RESULT] = 0; // ok
return IR_CONT;
}
diff --git a/sword2/startup.cpp b/sword2/startup.cpp
index 182548fedf..9c0756cee1 100644
--- a/sword2/startup.cpp
+++ b/sword2/startup.cpp
@@ -214,8 +214,7 @@ void Logic::conStart(int start) {
// 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();
diff --git a/sword2/sword2.cpp b/sword2/sword2.cpp
index d24090ec91..cf8af3a606 100644
--- a/sword2/sword2.cpp
+++ b/sword2/sword2.cpp
@@ -224,13 +224,9 @@ void Sword2Engine::errorString(const char *buf1, char *buf2) {
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 @@ int32 Sword2Engine::initialiseGame(void) {
// 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 @@ int32 Sword2Engine::initialiseGame(void) {
// 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 @@ void Sword2Engine::go() {
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 @@ void Sword2Engine::startGame(void) {
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::pauseGame(void) {
}
void Sword2Engine::unpauseGame(void) {
- if (OBJECT_HELD && _realLuggageItem)
+ if (Logic::_scriptVars[OBJECT_HELD] && _realLuggageItem)
setLuggage(_realLuggageItem);
unpauseAllSound();
diff --git a/sword2/sync.cpp b/sword2/sync.cpp
index 0475bbd08b..c7011a185b 100644
--- a/sword2/sync.cpp
+++ b/sword2/sync.cpp
@@ -32,7 +32,7 @@ int32 Logic::fnSendSync(int32 *params) {
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 @@ bool Logic::getSync(void) {
// 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 @@ int32 Logic::fnGetSync(int32 *params) {
// 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 @@ int32 Logic::fnWaitSync(int32 *params) {
// 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;
}
}
diff --git a/sword2/walker.cpp b/sword2/walker.cpp
index df6206b992..13485b5da2 100644
--- a/sword2/walker.cpp
+++ b/sword2/walker.cpp
@@ -78,7 +78,8 @@ int32 Logic::fnWalk(int32 *params) {
// 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 @@ int32 Logic::fnWalk(int32 *params) {
_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 @@ int32 Logic::fnWalk(int32 *params) {
// 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 @@ int32 Logic::fnWalk(int32 *params) {
// 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 @@ int32 Logic::fnWalk(int32 *params) {
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 @@ int32 Logic::fnAddWalkGrid(int32 *params) {
// 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);