Refactored ScummEngine*::checkExecVerbs method

svn-id: r29284
This commit is contained in:
Max Horn 2007-10-28 12:57:25 +00:00
parent 61c96353cf
commit 3f958711a2
6 changed files with 73 additions and 18 deletions

View File

@ -279,6 +279,7 @@ protected:
virtual void readMAXS(int blockSize);
virtual void redrawBGAreas();
virtual void checkExecVerbs();
byte *defineArray(int array, int type, int dim2start, int dim2end, int dim1start, int dim1end);
virtual int readArray(int array, int idx2, int idx1);
@ -359,6 +360,8 @@ protected:
byte VAR_NUM_CHARSETS;
byte VAR_POLYGONS_ONLY;
byte VAR_MOUSE_STATE; // Used in checkExecVerbs();
};
class ScummEngine_v80he : public ScummEngine_v72he {

View File

@ -90,6 +90,8 @@ void ScummEngine::parseEvents() {
}
if (_game.heversion >= 80) {
// FIXME: Move this code & VAR_KEY_STATE to class ScummEngine_v80he
// Keyboard is controlled via variable
int keyState = 0;

View File

@ -332,6 +332,7 @@ protected:
void setUserState(byte state);
virtual void handleMouseOver(bool updateInventory);
virtual void checkExecVerbs();
void initV2MouseOver();
void initNESMouseOver();

View File

@ -443,7 +443,6 @@ ScummEngine::ScummEngine(OSystem *syst, const DetectorResult &dr)
VAR_NUM_GLOBAL_OBJS = 0xFF;
VAR_KEY_STATE = 0xFF;
VAR_MOUSE_STATE = 0xFF;
// Use g_scumm from error() ONLY
g_scumm = this;
@ -780,6 +779,7 @@ ScummEngine_v72he::ScummEngine_v72he(OSystem *syst, const DetectorResult &dr)
VAR_NUM_IMAGES = 0xFF;
VAR_NUM_CHARSETS = 0xFF;
VAR_POLYGONS_ONLY = 0xFF;
VAR_MOUSE_STATE = 0xFF;
}
ScummEngine_v80he::ScummEngine_v80he(OSystem *syst, const DetectorResult &dr)

View File

@ -1342,7 +1342,6 @@ public:
byte VAR_NUM_SCRIPT_CYCLES; // Used in runAllScripts()
byte VAR_KEY_STATE; // Used in parseEvents()
byte VAR_MOUSE_STATE; // Used in checkExecVerbs();
// Exists both in V7 and in V72HE:
byte VAR_NUM_GLOBAL_OBJS;

View File

@ -26,6 +26,7 @@
#include "scumm/actor.h"
#include "scumm/charset.h"
#include "scumm/he/intern_he.h"
#include "scumm/intern.h"
#include "scumm/object.h"
#include "scumm/resource.h"
@ -513,18 +514,25 @@ void ScummEngine_v0::handleMouseOver(bool updateInventory) {
drawSentence();
}
void ScummEngine::checkExecVerbs() {
int i, over;
VerbSlot *vs;
if (VAR_MOUSE_STATE != 0xFF)
VAR(VAR_MOUSE_STATE) = 0;
#ifndef DISABLE_HE
void ScummEngine_v72he::checkExecVerbs() {
VAR(VAR_MOUSE_STATE) = 0;
if (_userPut <= 0 || _mouseAndKeyboardStat == 0)
return;
if (VAR_MOUSE_STATE != 0xFF)
VAR(VAR_MOUSE_STATE) = _mouseAndKeyboardStat;
VAR(VAR_MOUSE_STATE) = _mouseAndKeyboardStat;
ScummEngine::checkExecVerbs();
}
#endif
void ScummEngine::checkExecVerbs() {
int i, over;
VerbSlot *vs;
if (_userPut <= 0 || _mouseAndKeyboardStat == 0)
return;
if (_mouseAndKeyboardStat < MBS_MAX_KEY) {
/* Check keypresses */
@ -572,7 +580,7 @@ void ScummEngine::checkExecVerbs() {
if ((_game.platform == Common::kPlatformFMTowns && _game.id == GID_ZAK) &&
(_mouseAndKeyboardStat >= 315 && _mouseAndKeyboardStat <= 318)) {
// Hack: Handle switching to a person via F1-F4 keys.
// This feature isn't available in the scripts of the FM-TOWNS verison.
// This feature isn't available in the scripts of the FM-TOWNS version.
int fKey = _mouseAndKeyboardStat - 314;
int switchSlot = getVerbSlot(36, 0);
// check if switch-verb is enabled
@ -590,25 +598,67 @@ void ScummEngine::checkExecVerbs() {
runInputScript(kKeyClickArea, _mouseAndKeyboardStat, 1);
} else if (_mouseAndKeyboardStat & MBS_MOUSE_MASK) {
VirtScreen *zone = findVirtScreen(_mouse.y);
byte code = _mouseAndKeyboardStat & MBS_LEFT_CLICK ? 1 : 2;
int inventoryArea = (_game.platform == Common::kPlatformNES) ? 48: 32;
const byte code = _mouseAndKeyboardStat & MBS_LEFT_CLICK ? 1 : 2;
// This could be kUnkVirtScreen.
// Fixes bug #1536932: "MANIACNES: Crash on click in speechtext-area"
if (!zone)
return;
if (_game.version <= 2 && zone->number == kVerbVirtScreen && _mouse.y <= zone->topline + 8) {
over = findVerbAtPos(_mouse.x, _mouse.y);
if (over != 0) {
// Verb was clicked
runInputScript(kVerbClickArea, _verbs[over].verbid, code);
} else {
// Scene was clicked
runInputScript((zone->number == kMainVirtScreen) ? kSceneClickArea : kVerbClickArea, 0, code);
}
}
}
void ScummEngine_v2::checkExecVerbs() {
int i, over;
VerbSlot *vs;
if (_userPut <= 0 || _mouseAndKeyboardStat == 0)
return;
if (_mouseAndKeyboardStat < MBS_MAX_KEY) {
/* Check keypresses */
vs = &_verbs[1];
for (i = 1; i < _numVerbs; i++, vs++) {
if (vs->verbid && vs->saveid == 0 && vs->curmode == 1) {
if (_mouseAndKeyboardStat == vs->key) {
// Trigger verb as if the user clicked it
runInputScript(1, vs->verbid, 1);
return;
}
}
}
// Generic keyboard input
runInputScript(4, _mouseAndKeyboardStat, 1);
} else if (_mouseAndKeyboardStat & MBS_MOUSE_MASK) {
VirtScreen *zone = findVirtScreen(_mouse.y);
const byte code = _mouseAndKeyboardStat & MBS_LEFT_CLICK ? 1 : 2;
const int inventoryArea = (_game.platform == Common::kPlatformNES) ? 48: 32;
// This could be kUnkVirtScreen.
// Fixes bug #1536932: "MANIACNES: Crash on click in speechtext-area"
if (!zone)
return;
if (zone->number == kVerbVirtScreen && _mouse.y <= zone->topline + 8) {
// Click into V2 sentence line
runInputScript(kSentenceClickArea, 0, 0);
} else if (_game.version <= 2 && zone->number == kVerbVirtScreen && _mouse.y > zone->topline + inventoryArea) {
runInputScript(5, 0, 0);
} else if (zone->number == kVerbVirtScreen && _mouse.y > zone->topline + inventoryArea) {
// Click into V2 inventory
((ScummEngine_v2 *)this)->checkV2Inventory(_mouse.x, _mouse.y);
checkV2Inventory(_mouse.x, _mouse.y);
} else {
over = findVerbAtPos(_mouse.x, _mouse.y);
if (over != 0) {
// Verb was clicked
runInputScript(kVerbClickArea, _verbs[over].verbid, code);
runInputScript(1, _verbs[over].verbid, code);
} else {
// Scene was clicked
runInputScript((zone->number == kMainVirtScreen) ? kSceneClickArea : kVerbClickArea, 0, code);