diff options
-rw-r--r-- | engines/titanic/titanic.h | 12 | ||||
-rw-r--r-- | engines/titanic/true_talk/tt_parser.cpp | 34 | ||||
-rw-r--r-- | engines/titanic/true_talk/tt_parser.h | 10 |
3 files changed, 56 insertions, 0 deletions
diff --git a/engines/titanic/titanic.h b/engines/titanic/titanic.h index 95d1abae04..2b08f56f7d 100644 --- a/engines/titanic/titanic.h +++ b/engines/titanic/titanic.h @@ -82,6 +82,17 @@ struct TitanicSavegameHeader { int _totalFrames; }; +enum NumberFlag { NF_2 = 2, NF_8 = 8, NF_10 = 0x10 }; + +struct NumberEntry { + CString _text; + int _value; + int _flags; + NumberEntry(const CString &text, int value, int flags) : + _text(text), _value(value), _flags(flags) {} +}; +typedef Common::Array<NumberEntry> NumberArray; + class TitanicEngine : public Engine { private: /** @@ -137,6 +148,7 @@ public: StringArray _replacements2; StringArray _replacements3; StringArray _phrases; + NumberArray _numbers; public: TitanicEngine(OSystem *syst, const TitanicGameDescription *gameDesc); virtual ~TitanicEngine(); diff --git a/engines/titanic/true_talk/tt_parser.cpp b/engines/titanic/true_talk/tt_parser.cpp index 4fdaf58671..9aa6c2ef7a 100644 --- a/engines/titanic/true_talk/tt_parser.cpp +++ b/engines/titanic/true_talk/tt_parser.cpp @@ -321,4 +321,38 @@ int TTparser::searchAndReplace(TTstring &line, int startIndex, const StringArray return startIndex; } +bool TTparser::replaceNumbers(TTstring &line, int *startIndex) { + int lineSize = line.size(); + int index = *startIndex; + if (index < 0 || index >= lineSize) + return true; + + NumberArray &numbers = g_vm->_numbers; + NumberEntry *numEntry = nullptr; + + for (uint idx = 0; idx < numbers.size(); ++idx) { + NumberEntry &ne = numbers[idx]; + if (!strncmp(line.c_str() + index, ne._text.c_str(), ne._text.size())) { + if ((ne._flags & NF_10) || (index + ne._text.size()) >= lineSize || + line[index + ne._text.size()] == ' ') { + *startIndex += ne._text.size(); + numEntry = ≠ + break; + } + } + } + + if (!numEntry || !(numEntry->_flags & NF_10)) { + // Skip to end of current word + while (*startIndex < lineSize && !Common::isSpace(line[*startIndex])) + ++*startIndex; + } + + // Skip over following spaces until start of following word is reached + while (*startIndex < lineSize && Common::isSpace(line[*startIndex])) + ++*startIndex; + + return *startIndex < lineSize; +} + } // End of namespace Titanic diff --git a/engines/titanic/true_talk/tt_parser.h b/engines/titanic/true_talk/tt_parser.h index 1eed38d515..22a2850516 100644 --- a/engines/titanic/true_talk/tt_parser.h +++ b/engines/titanic/true_talk/tt_parser.h @@ -67,6 +67,16 @@ private: * @returns Index of the start of the following word */ static int searchAndReplace(TTstring &line, int startIndex, const StringArray &strings); + + /** + * Checks the string starting at a given index for a number representation + * such as roman numericals, spelled out numbers, etc. and replaces it with + * a plain decimal representation. + * @param line Line to check + * @param startIndex Starting index in the start to check + * @returns True if end of line hasn't been reached yet + */ + static bool replaceNumbers(TTstring &line, int *startIndex); public: CScriptHandler *_owner; int _field4; |