diff options
| author | Paul Gilbert | 2016-05-16 23:13:24 -0400 |
|---|---|---|
| committer | Paul Gilbert | 2016-07-15 19:12:39 -0400 |
| commit | 361ac2cfe4c6e778ad5eeafac94bbc6927aeaf1b (patch) | |
| tree | 575b3b4b7ef0caebb831d4f9b80fa3e656bebef1 | |
| parent | 3878f38d8c76f2289be1f53bbecf9cda95e43067 (diff) | |
| download | scummvm-rg350-361ac2cfe4c6e778ad5eeafac94bbc6927aeaf1b.tar.gz scummvm-rg350-361ac2cfe4c6e778ad5eeafac94bbc6927aeaf1b.tar.bz2 scummvm-rg350-361ac2cfe4c6e778ad5eeafac94bbc6927aeaf1b.zip | |
TITANIC: Implemented secondary replaceNumbers method
| -rw-r--r-- | engines/titanic/true_talk/tt_parser.cpp | 54 | ||||
| -rw-r--r-- | engines/titanic/true_talk/tt_parser.h | 14 |
2 files changed, 64 insertions, 4 deletions
diff --git a/engines/titanic/true_talk/tt_parser.cpp b/engines/titanic/true_talk/tt_parser.cpp index 24361f9e03..9787d1cd98 100644 --- a/engines/titanic/true_talk/tt_parser.cpp +++ b/engines/titanic/true_talk/tt_parser.cpp @@ -360,7 +360,57 @@ int TTparser::searchAndReplace(TTstring &line, int startIndex, const StringArray return startIndex; } -const NumberEntry *TTparser::replaceNumbers(TTstring &line, int *startIndex) { +int TTparser::replaceNumbers(TTstring &line, int startIndex) { + int index = startIndex; + const NumberEntry *numEntry = replaceNumbers2(line, &index); + if (!numEntry || !(numEntry->_flags & NF_2)) + return index; + + bool flag1 = false, flag2 = false, flag3 = false; + int total = 0, factor = 0; + + do { + if (numEntry->_flags & NF_1) { + flag2 = true; + if (numEntry->_flags & NF_8) + flag1 = true; + + if (numEntry->_flags & NF_4) { + flag3 = true; + factor *= numEntry->_value; + } + + if (numEntry->_flags & NF_2) { + if (flag3) { + total += factor; + factor = 0; + } + + factor += numEntry->_value; + } + } + } while (replaceNumbers2(line, &index)); + + if (!flag2) + return index; + + if (index >= 0) { + if (line[index - 1] != ' ') + return index; + } + + total += factor; + CTrueTalkManager::_v1 = total; + if (flag1) + total = -total; + + CString numStr = CString::format("%d", total); + line = CString(line.c_str(), line.c_str() + startIndex) + numStr + + CString(line.c_str() + index); + return index; +} + +const NumberEntry *TTparser::replaceNumbers2(TTstring &line, int *startIndex) { int lineSize = line.size(); int index = *startIndex; if (index < 0 || index >= lineSize) { @@ -373,7 +423,7 @@ const NumberEntry *TTparser::replaceNumbers(TTstring &line, int *startIndex) { 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 || + if ((ne._flags & NF_10) || (index + (int)ne._text.size()) >= lineSize || line[index + ne._text.size()] == ' ') { *startIndex += ne._text.size(); numEntry = ≠ diff --git a/engines/titanic/true_talk/tt_parser.h b/engines/titanic/true_talk/tt_parser.h index 7e4e97f1ff..171c91d470 100644 --- a/engines/titanic/true_talk/tt_parser.h +++ b/engines/titanic/true_talk/tt_parser.h @@ -28,7 +28,7 @@ namespace Titanic { -enum NumberFlag { NF_2 = 2, NF_8 = 8, NF_10 = 0x10 }; +enum NumberFlag { NF_1 = 1, NF_2 = 2, NF_4 = 4, NF_8 = 8, NF_10 = 0x10 }; class CScriptHandler; @@ -94,6 +94,16 @@ private: 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 Index of the start of the following word, or -1 if at end of line + */ + int replaceNumbers(TTstring &line, int startIndex); + + /** * 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. @@ -101,7 +111,7 @@ private: * @param startIndex Starting index in the start to check * @returns Pointer to matching number entry, if match occurred */ - const NumberEntry *replaceNumbers(TTstring &line, int *startIndex); + const NumberEntry *replaceNumbers2(TTstring &line, int *startIndex); public: CScriptHandler *_owner; int _field4; |
