[Scummvm-git-logs] scummvm master -> f1ee97dbd5f17e9308805af3e73fdd37135899f6
dreammaster
paulfgilbert at gmail.com
Sat Jun 27 16:59:52 UTC 2020
This automated email contains information about 2 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
cc2939669c GLK: COMPREHEND: Properly load the word map targets
f1ee97dbd5 GLK: COMPREHEND: Allow for non-contiguous word pairs
Commit: cc2939669c35eace749dc3bc0a4c8f250064bb89
https://github.com/scummvm/scummvm/commit/cc2939669c35eace749dc3bc0a4c8f250064bb89
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2020-06-27T09:59:28-07:00
Commit Message:
GLK: COMPREHEND: Properly load the word map targets
Changed paths:
engines/glk/comprehend/game_data.cpp
engines/glk/comprehend/game_data.h
diff --git a/engines/glk/comprehend/game_data.cpp b/engines/glk/comprehend/game_data.cpp
index 192c9a1595..bbf0ee04e8 100644
--- a/engines/glk/comprehend/game_data.cpp
+++ b/engines/glk/comprehend/game_data.cpp
@@ -574,14 +574,13 @@ void GameData::parse_word_map(FileBuffer *fb) {
_wordMaps.push_back(map);
}
- /* Consume two more null bytes (type and index were also null) */
- fb->skip(2);
-
/*
* Parse the target word table. Each entry has a dictionary
* index/type. The first and second words from above map to the
* target word here. E.g. 'go north' -> 'north'.
*/
+ fb->seek(_header.addr_word_map_target);
+
for (i = 0; i < _wordMaps.size(); i++) {
WordMap &map = _wordMaps[i];
@@ -842,8 +841,7 @@ void GameData::parse_header(FileBuffer *fb) {
parse_header_le16(fb, &header->addr_dictionary);
parse_header_le16(fb, &header->addr_word_map);
- /* FIXME - what is this for? */
- parse_header_le16(fb, &dummy);
+ parse_header_le16(fb, &header->addr_word_map_target);
addr_dictionary_end = header->addr_word_map;
/* Rooms */
diff --git a/engines/glk/comprehend/game_data.h b/engines/glk/comprehend/game_data.h
index eef6de0970..a3b3f5a711 100644
--- a/engines/glk/comprehend/game_data.h
+++ b/engines/glk/comprehend/game_data.h
@@ -319,6 +319,7 @@ struct GameHeader {
uint16 addr_dictionary;
uint16 addr_word_map;
+ uint16 addr_word_map_target;
uint16 addr_strings;
uint16 addr_strings_end;
Commit: f1ee97dbd5f17e9308805af3e73fdd37135899f6
https://github.com/scummvm/scummvm/commit/f1ee97dbd5f17e9308805af3e73fdd37135899f6
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2020-06-27T09:59:28-07:00
Commit Message:
GLK: COMPREHEND: Allow for non-contiguous word pairs
Changed paths:
engines/glk/comprehend/game.cpp
engines/glk/comprehend/game.h
engines/glk/comprehend/game_data.cpp
engines/glk/comprehend/game_data.h
diff --git a/engines/glk/comprehend/game.cpp b/engines/glk/comprehend/game.cpp
index 13cc21fcc2..afa937bf1c 100644
--- a/engines/glk/comprehend/game.cpp
+++ b/engines/glk/comprehend/game.cpp
@@ -289,24 +289,6 @@ bool ComprehendGame::handle_restart() {
}
}
-WordIndex *ComprehendGame::is_word_pair(const Word *word1, const Word *word2) {
- WordMap *map;
- uint i;
-
- /* Check if this is a word pair */
- for (i = 0; i < _wordMaps.size(); i++) {
- map = &_wordMaps[i];
-
- if (map->_word[0]._index == word1->_index &&
- map->_word[0]._type == word1->_type &&
- map->_word[1]._index == word2->_index &&
- map->_word[1]._type == word2->_type)
- return &map->_word[2];
- }
-
- return nullptr;
-}
-
Item *ComprehendGame::get_item_by_noun(const Word *noun) {
uint i;
@@ -1103,9 +1085,7 @@ void ComprehendGame::read_sentence(char **line,
Sentence *sentence) {
bool sentence_end = false;
char *word_string, *p = *line;
- WordIndex *pair;
Word *word;
- int index;
sentence->clear();
while (1) {
@@ -1133,29 +1113,45 @@ void ComprehendGame::read_sentence(char **line,
sentence->_nr_words++;
- if (sentence->_nr_words > 1) {
- index = sentence->_nr_words;
-
- /* See if this word and the previous are a word pair */
- pair = is_word_pair(&sentence->_words[index - 2],
- &sentence->_words[index - 1]);
- if (pair) {
- sentence->_words[index - 2]._index = pair->_index;
- sentence->_words[index - 2]._type = pair->_type;
- strcpy(sentence->_words[index - 2]._word,
- "[PAIR]");
- sentence->_nr_words--;
- }
- }
-
if (sentence->_nr_words >= ARRAY_SIZE(sentence->_words) ||
sentence_end)
break;
}
+ parse_sentence_word_pairs(sentence);
+
*line = p;
}
+void ComprehendGame::parse_sentence_word_pairs(Sentence *sentence) {
+ if (sentence->_nr_words < 2)
+ return;
+
+ // Iterate through the pairs
+ for (uint idx = 0; idx < _wordMaps.size(); ++idx) {
+ for (int firstWord = 0; firstWord < (int)sentence->_nr_words - 1; ++firstWord) {
+ for (int secondWord = firstWord + 1; secondWord < (int)sentence->_nr_words; ) {
+ if (sentence->_words[firstWord] == _wordMaps[idx]._word[0] &&
+ sentence->_words[secondWord] == _wordMaps[idx]._word[1]) {
+ // Found a word pair match
+ // Delete the second word
+ for (; secondWord < (int)sentence->_nr_words - 1; ++secondWord)
+ sentence->_words[secondWord] = sentence->_words[secondWord + 1];
+
+ sentence->_words[sentence->_nr_words - 1].clear();
+ sentence->_nr_words--;
+
+ // Replace the first word with the target
+ sentence->_words[firstWord] = _wordMaps[idx]._word[2];
+ } else {
+ // Move to next word
+ ++secondWord;
+ }
+ }
+ }
+ }
+}
+
void ComprehendGame::doBeforeTurn() {
// Run the game specific before turn bits
beforeTurn();
diff --git a/engines/glk/comprehend/game.h b/engines/glk/comprehend/game.h
index 931a07dc83..4059bfc9e4 100644
--- a/engines/glk/comprehend/game.h
+++ b/engines/glk/comprehend/game.h
@@ -45,7 +45,6 @@ public:
const GameStrings *_gameStrings;
private:
- WordIndex *is_word_pair(const Word *word1, const Word *word2);
Item *get_item_by_noun(const Word *noun);
void describe_objects_in_current_room();
void update();
@@ -57,6 +56,7 @@ private:
void skip_non_whitespace(char **p);
bool handle_sentence(Sentence *sentence);
void read_sentence(char **line, Sentence *sentence);
+ void parse_sentence_word_pairs(Sentence *sentence);
void doBeforeTurn();
void doAfterTurn();
void read_input();
diff --git a/engines/glk/comprehend/game_data.cpp b/engines/glk/comprehend/game_data.cpp
index bbf0ee04e8..c8b0cc6681 100644
--- a/engines/glk/comprehend/game_data.cpp
+++ b/engines/glk/comprehend/game_data.cpp
@@ -75,9 +75,15 @@ void Item::synchronize(Common::Serializer &s) {
/*-------------------------------------------------------*/
void Word::clear() {
- _index = 0;
- _type = 0;
+ WordIndex::clear();
+ Common::fill(&_word[0], &_word[7], '\0');
+}
+
+Word &Word::operator=(const WordIndex &src) {
+ _index = src._index;
+ _type = src._type;
Common::fill(&_word[0], &_word[7], '\0');
+ return *this;
}
void Word::load(FileBuffer *fb) {
diff --git a/engines/glk/comprehend/game_data.h b/engines/glk/comprehend/game_data.h
index a3b3f5a711..390408810f 100644
--- a/engines/glk/comprehend/game_data.h
+++ b/engines/glk/comprehend/game_data.h
@@ -220,31 +220,35 @@ struct Item {
void synchronize(Common::Serializer &s);
};
-struct Word {
- char _word[7];
+struct WordIndex {
uint8 _index;
uint8 _type;
- Word() {
+ WordIndex() {
clear();
}
- void clear();
+ void clear() {
+ _index = _type = 0;
+ }
- void load(FileBuffer *fb);
+ bool operator==(WordIndex &src) {
+ return _index == src._index && _type == src._type;
+ }
};
-struct WordIndex {
- uint8 _index;
- uint8 _type;
+struct Word : public WordIndex {
+ char _word[7];
- WordIndex() {
- clear();
+ Word() : WordIndex() {
+ Word::clear();
}
- void clear() {
- _index = _type = 0;
- }
+ void clear();
+
+ void load(FileBuffer *fb);
+
+ Word &operator=(const WordIndex &src);
};
struct WordMap {
More information about the Scummvm-git-logs
mailing list