aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--engines/glk/advsys/game.cpp8
-rw-r--r--engines/glk/advsys/vm.cpp17
2 files changed, 12 insertions, 13 deletions
diff --git a/engines/glk/advsys/game.cpp b/engines/glk/advsys/game.cpp
index ea8bac93bb..3b6133d6ef 100644
--- a/engines/glk/advsys/game.cpp
+++ b/engines/glk/advsys/game.cpp
@@ -243,7 +243,7 @@ int Game::getObjectLocation(int obj) const {
}
int Game::getActionLocation(int action) const {
- if (action < 1 || action >= _actionCount)
+ if (action < 1 || action > _actionCount)
error("Invalid action number %d", action);
return READ_LE_UINT16(_actionTable + action * 2);
@@ -297,18 +297,16 @@ bool Game::hasVerb(int act, const Common::Array<int> &verbs) const {
Common::Array<int>::const_iterator verb = verbs.begin();
int word = readWord(link + L_DATA);
- for (; verb < verbs.end() && word; link = readWord(link + L_NEXT)) {
+ for (; verb < verbs.end() && word; ++verb, word = readWord(word + L_NEXT)) {
if (*verb != readWord(word + L_DATA))
break;
-
- ++verb;
}
if (verb == verbs.end() && !word)
return true;
}
- return true;
+ return false;
}
bool Game::inList(int link, int word) const {
diff --git a/engines/glk/advsys/vm.cpp b/engines/glk/advsys/vm.cpp
index a2ce0f2832..8c6072c73e 100644
--- a/engines/glk/advsys/vm.cpp
+++ b/engines/glk/advsys/vm.cpp
@@ -444,8 +444,9 @@ bool VM::parseInput() {
// Initialize the parser result fields
_actor = _action = _dObject = _iObject = 0;
_ndObjects = 0;
- _adjectiveList.clear();
_nouns.clear();
+ _adjectiveList.clear();
+ _adjectiveList.reserve(20);
// Get the input line
if (!getLine())
@@ -460,7 +461,7 @@ bool VM::parseInput() {
}
// Check for a verb
- if (getVerb())
+ if (!getVerb())
return false;
// Get direct object, preposition, and/or indirect object
@@ -517,8 +518,7 @@ bool VM::parseInput() {
_dObject = noun1;
_ndObjects = cnt1;
_iObject = noun2;
- }
- else if (noun2) {
+ } else if (noun2) {
if (cnt1 > 1) {
parseError();
return false;
@@ -540,7 +540,7 @@ bool VM::parseInput() {
flags |= A_IOBJECT;
// Find the action
- if (!(_action == findAction(_verbs, preposition, flags))) {
+ if (!(_action = findAction(_verbs, preposition, flags))) {
parseError();
return false;
}
@@ -612,6 +612,7 @@ uint VM::getNoun() {
_adjectiveList.push_back(ae);
}
_adjectiveList.push_back(AdjectiveEntry());
+ assert(_adjectiveList.size() <= 20);
// Add a noun entry to the list
Noun n;
@@ -626,7 +627,7 @@ uint VM::getNoun() {
bool VM::getVerb() {
_verbs.clear();
- if (*_wordPtr == NIL || getWordType(*_wordPtr) != WT_VERB) {
+ if (_wordPtr == _words.end() || getWordType(*_wordPtr) != WT_VERB) {
parseError();
return false;
}
@@ -634,8 +635,8 @@ bool VM::getVerb() {
_verbs.push_back(*_wordPtr++);
// Check for a word following the verb
- if (!_words.empty()) {
- _verbs.push_back(_words.front());
+ if (_wordPtr < _words.end()) {
+ _verbs.push_back(*_wordPtr);
if (checkVerb(_verbs)) {
++_wordPtr;