aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--engines/agi/words.cpp5
1 files changed, 3 insertions, 2 deletions
diff --git a/engines/agi/words.cpp b/engines/agi/words.cpp
index f6e399245a..1001c66b20 100644
--- a/engines/agi/words.cpp
+++ b/engines/agi/words.cpp
@@ -134,8 +134,9 @@ int AgiEngine::findWord(const char *word, int *flen) {
for (int i = 0; i < (int)a.size(); i++) {
int wlen = strlen(a[i]->word);
- // Keep looking till we find the word itself, or the whole phrase
- if (!strncmp(a[i]->word, word, wlen) && (word[wlen] == 0 || word[wlen] == 0x20)) {
+ // Keep looking till we find the word itself, or the whole phrase.
+ // Try to find the best match (i.e. the longest matching phrase).
+ if (!strncmp(a[i]->word, word, wlen) && (word[wlen] == 0 || word[wlen] == 0x20) && wlen >= *flen) {
*flen = wlen;
result = a[i]->id;
}