diff options
Diffstat (limited to 'engines/sci')
-rw-r--r-- | engines/sci/engine/kparse.cpp | 1 | ||||
-rw-r--r-- | engines/sci/engine/state.cpp | 12 | ||||
-rw-r--r-- | engines/sci/parser/vocabulary.cpp | 53 | ||||
-rw-r--r-- | engines/sci/parser/vocabulary.h | 7 | ||||
-rw-r--r-- | engines/sci/sci.cpp | 3 | ||||
-rw-r--r-- | engines/sci/sci.h | 4 |
6 files changed, 48 insertions, 32 deletions
diff --git a/engines/sci/engine/kparse.cpp b/engines/sci/engine/kparse.cpp index 4287e7c96b..8714981034 100644 --- a/engines/sci/engine/kparse.cpp +++ b/engines/sci/engine/kparse.cpp @@ -93,6 +93,7 @@ reg_t kParse(EngineState *s, int argc, reg_t *argv) { char *error; ResultWordList words; reg_t event = argv[1]; + g_sci->checkVocabularySwitch(); Vocabulary *voc = g_sci->getVocabulary(); voc->parser_event = event; reg_t params[2] = { voc->parser_base, stringpos }; diff --git a/engines/sci/engine/state.cpp b/engines/sci/engine/state.cpp index 36b03c0ad9..e07373b466 100644 --- a/engines/sci/engine/state.cpp +++ b/engines/sci/engine/state.cpp @@ -324,4 +324,16 @@ Common::String SciEngine::strSplit(const char *str, const char *sep) { return retval; } +void SciEngine::checkVocabularySwitch() { + uint16 parserLanguage = 1; + if (SELECTOR(parseLang) != -1) + parserLanguage = readSelectorValue(_gamestate->_segMan, _gameObj, SELECTOR(parseLang)); + + if (parserLanguage != _vocabularyLanguage) { + delete _vocabulary; + _vocabulary = new Vocabulary(_resMan, parserLanguage > 1 ? true : false); + _vocabularyLanguage = parserLanguage; + } +} + } // End of namespace Sci diff --git a/engines/sci/parser/vocabulary.cpp b/engines/sci/parser/vocabulary.cpp index 22827a6327..cb580017c4 100644 --- a/engines/sci/parser/vocabulary.cpp +++ b/engines/sci/parser/vocabulary.cpp @@ -33,9 +33,8 @@ namespace Sci { -Vocabulary::Vocabulary(ResourceManager *resMan) : _resMan(resMan) { +Vocabulary::Vocabulary(ResourceManager *resMan, bool foreign) : _resMan(resMan), _foreign(foreign) { _parserRules = NULL; - _vocabVersion = kVocabularySCI0; memset(_parserNodes, 0, sizeof(_parserNodes)); // Mark parse tree as unused @@ -45,6 +44,23 @@ Vocabulary::Vocabulary(ResourceManager *resMan) : _resMan(resMan) { _synonyms.clear(); // No synonyms debug(2, "Initializing vocabulary"); + if (_resMan->testResource(ResourceId(kResourceTypeVocab, VOCAB_RESOURCE_SCI0_MAIN_VOCAB))) { + _vocabVersion = kVocabularySCI0; + _resourceIdWords = VOCAB_RESOURCE_SCI0_MAIN_VOCAB; + _resourceIdSuffixes = VOCAB_RESOURCE_SCI0_SUFFIX_VOCAB; + _resourceIdBranches = VOCAB_RESOURCE_SCI0_PARSE_TREE_BRANCHES; + } else { + warning("Could not find a main vocabulary, trying SCI01"); + _vocabVersion = kVocabularySCI1; + _resourceIdWords = VOCAB_RESOURCE_SCI1_MAIN_VOCAB; + _resourceIdSuffixes = VOCAB_RESOURCE_SCI1_SUFFIX_VOCAB; + _resourceIdBranches = VOCAB_RESOURCE_SCI1_PARSE_TREE_BRANCHES; + if (_foreign) { + _resourceIdWords += 10; + _resourceIdSuffixes += 10; + _resourceIdBranches += 10; + } + } if (getSciVersion() <= SCI_VERSION_1_EGA && loadParserWords()) { loadSuffixes(); @@ -72,16 +88,10 @@ bool Vocabulary::loadParserWords() { int currentwordpos = 0; // First try to load the SCI0 vocab resource. - Resource *resource = _resMan->findResource(ResourceId(kResourceTypeVocab, VOCAB_RESOURCE_SCI0_MAIN_VOCAB), 0); - - if (!resource) { - warning("SCI0: Could not find a main vocabulary, trying SCI01"); - resource = _resMan->findResource(ResourceId(kResourceTypeVocab, VOCAB_RESOURCE_SCI1_MAIN_VOCAB), 0); - _vocabVersion = kVocabularySCI1; - } + Resource *resource = _resMan->findResource(ResourceId(kResourceTypeVocab, _resourceIdWords), 0); if (!resource) { - warning("SCI1: Could not find a main vocabulary"); + warning("Could not find a main vocabulary"); return false; // NOT critical: SCI1 games and some demos don't have one! } @@ -175,13 +185,7 @@ const char *Vocabulary::getAnyWordFromGroup(int group) { bool Vocabulary::loadSuffixes() { // Determine if we can find a SCI1 suffix vocabulary first - Resource* resource = NULL; - - if (_vocabVersion == kVocabularySCI0) - resource = _resMan->findResource(ResourceId(kResourceTypeVocab, VOCAB_RESOURCE_SCI0_SUFFIX_VOCAB), 1); - else - resource = _resMan->findResource(ResourceId(kResourceTypeVocab, VOCAB_RESOURCE_SCI1_SUFFIX_VOCAB), 1); - + Resource* resource = _resMan->findResource(ResourceId(kResourceTypeVocab, _resourceIdSuffixes), 1); if (!resource) return false; // No vocabulary found @@ -214,13 +218,7 @@ bool Vocabulary::loadSuffixes() { } void Vocabulary::freeSuffixes() { - Resource* resource = NULL; - - if (_vocabVersion == kVocabularySCI0) - resource = _resMan->findResource(ResourceId(kResourceTypeVocab, VOCAB_RESOURCE_SCI0_SUFFIX_VOCAB), 0); - else - resource = _resMan->findResource(ResourceId(kResourceTypeVocab, VOCAB_RESOURCE_SCI1_SUFFIX_VOCAB), 0); - + Resource* resource = _resMan->findResource(ResourceId(kResourceTypeVocab, _resourceIdSuffixes), 0); if (resource) _resMan->unlockResource(resource); @@ -228,12 +226,7 @@ void Vocabulary::freeSuffixes() { } bool Vocabulary::loadBranches() { - Resource *resource = NULL; - - if (_vocabVersion == kVocabularySCI0) - resource = _resMan->findResource(ResourceId(kResourceTypeVocab, VOCAB_RESOURCE_SCI0_PARSE_TREE_BRANCHES), 0); - else - resource = _resMan->findResource(ResourceId(kResourceTypeVocab, VOCAB_RESOURCE_SCI1_PARSE_TREE_BRANCHES), 0); + Resource *resource = _resMan->findResource(ResourceId(kResourceTypeVocab, _resourceIdBranches), 0); _parserBranches.clear(); diff --git a/engines/sci/parser/vocabulary.h b/engines/sci/parser/vocabulary.h index 3317b6dfba..e637d8088a 100644 --- a/engines/sci/parser/vocabulary.h +++ b/engines/sci/parser/vocabulary.h @@ -169,7 +169,7 @@ enum VocabularyVersions { class Vocabulary { public: - Vocabulary(ResourceManager *resMan); + Vocabulary(ResourceManager *resMan, bool foreign); ~Vocabulary(); /** @@ -302,6 +302,11 @@ private: ResourceManager *_resMan; VocabularyVersions _vocabVersion; + bool _foreign; + uint16 _resourceIdWords; + uint16 _resourceIdSuffixes; + uint16 _resourceIdBranches; + // Parser-related lists SuffixList _parserSuffixes; ParseRuleList *_parserRules; /**< GNF rules used in the parser algorithm */ diff --git a/engines/sci/sci.cpp b/engines/sci/sci.cpp index 4601092af8..11d1057fff 100644 --- a/engines/sci/sci.cpp +++ b/engines/sci/sci.cpp @@ -85,6 +85,7 @@ SciEngine::SciEngine(OSystem *syst, const ADGameDescription *desc, SciGameId gam _gamestate = 0; _kernel = 0; _vocabulary = 0; + _vocabularyLanguage = -1; _eventMan = 0; _console = 0; @@ -202,7 +203,7 @@ Common::Error SciEngine::run() { _kernel = new Kernel(_resMan, segMan); _features = new GameFeatures(segMan, _kernel); // Only SCI0 and SCI01 games used a parser - _vocabulary = (getSciVersion() <= SCI_VERSION_1_EGA) ? new Vocabulary(_resMan) : NULL; + _vocabulary = (getSciVersion() <= SCI_VERSION_1_EGA) ? new Vocabulary(_resMan, false) : NULL; _audio = new AudioPlayer(_resMan); _gamestate = new EngineState(segMan); _eventMan = new EventManager(_resMan->detectFontExtended()); diff --git a/engines/sci/sci.h b/engines/sci/sci.h index 4768ca11b9..c497460334 100644 --- a/engines/sci/sci.h +++ b/engines/sci/sci.h @@ -267,6 +267,9 @@ public: Common::String getSciLanguageString(const char *str, kLanguage lang, kLanguage *lang2 = NULL) const; + // Check if vocabulary needs to get switched (in multilingual parser games) + void checkVocabularySwitch(); + // Initializes ports and paint16 for non-sci32 games, also sets default palette void initGraphics(); @@ -332,6 +335,7 @@ private: EngineState *_gamestate; Kernel *_kernel; Vocabulary *_vocabulary; + int16 _vocabularyLanguage; EventManager *_eventMan; reg_t _gameObj; /**< Pointer to the game object */ Console *_console; |