Skip to content

Commit

Permalink
SCUMM: keep track of the number of nested script calls for a sentence
Browse files Browse the repository at this point in the history
command in v0

If for instance an object necessary for the sentence command is not reachable or pickupable (try to use faucet (object 55) with jar with water in microwave (object 50), the pick-up script of the jar will tell the actor to pickup object 99 (jar not in microwave)) the actor will try to pick-up the jar infinitely.
This is fixed by counting the amount of nested scripts the sentence command has called (directly or indirectly) so far and aborts it if there have been too many.
  • Loading branch information
tobigun committed Feb 11, 2012
1 parent fb68456 commit e3f9a09
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
17 changes: 14 additions & 3 deletions engines/scumm/script.cpp
Expand Up @@ -1209,8 +1209,7 @@ void ScummEngine_v0::checkAndRunSentenceScript() {
return;
}

// FIXME: should this be executed?
//_currentScript = 0xFF;
_currentScript = 0xFF;

assert(st.objectA);

Expand All @@ -1233,7 +1232,19 @@ void ScummEngine_v0::checkAndRunSentenceScript() {
_cmdObject2 = st.objectB;
_sentenceNum--;

// TODO: check sentenceNum
// abort sentence execution if the number of nested scripts is too high.
// This might happen for instance if the sentence command depends on an
// object that the actor has to pick-up in a nested doSentence() call.
// If the actor is not able to pick-up the object (e.g. because it is not
// reachable or pickupable) a nested pick-up command is triggered again
// and again, so the actual sentence command will never be executed.
// In this case the sentence command has to be aborted.
_sentenceNestedCount++;
if (_sentenceNestedCount > 6) {
_sentenceNestedCount = 0;
_sentenceNum = 0;
return;
}

if (whereIsObject(st.objectA) != WIO_INVENTORY) {
if (_currentMode != kModeKeypad) {
Expand Down
3 changes: 3 additions & 0 deletions engines/scumm/script_v0.cpp
Expand Up @@ -979,6 +979,9 @@ void ScummEngine_v0::resetSentence() {

_walkToObjectState = kWalkToObjectStateDone;
_redrawSentenceLine = true;

_sentenceNum = 0;
_sentenceNestedCount = 0;
}

} // End of namespace Scumm
1 change: 1 addition & 0 deletions engines/scumm/scumm_v0.h
Expand Up @@ -55,6 +55,7 @@ class ScummEngine_v0 : public ScummEngine_v2 {
int _cmdVerb; // script verb
int _cmdObject; // 1st script object (see OBJECT_V0())
int _cmdObject2; // 2nd script object or actor (see OBJECT_V0())
int _sentenceNestedCount;

int _walkToObject;
int _walkToObjectState;
Expand Down
3 changes: 3 additions & 0 deletions engines/scumm/verbs.cpp
Expand Up @@ -689,6 +689,9 @@ int ScummEngine_v0::activeVerbPrep() {
}

void ScummEngine_v0::verbExec() {
_sentenceNum = 0;
_sentenceNestedCount = 0;

if (_activeVerb == kVerbWhatIs)
return;

Expand Down

0 comments on commit e3f9a09

Please sign in to comment.