aboutsummaryrefslogtreecommitdiff
path: root/engines/titanic
diff options
context:
space:
mode:
Diffstat (limited to 'engines/titanic')
-rw-r--r--engines/titanic/true_talk/tt_input.cpp4
-rw-r--r--engines/titanic/true_talk/tt_input.h2
-rw-r--r--engines/titanic/true_talk/tt_parser.cpp132
-rw-r--r--engines/titanic/true_talk/tt_parser.h14
-rw-r--r--engines/titanic/true_talk/tt_string.cpp8
-rw-r--r--engines/titanic/true_talk/tt_string.h2
6 files changed, 153 insertions, 9 deletions
diff --git a/engines/titanic/true_talk/tt_input.cpp b/engines/titanic/true_talk/tt_input.cpp
index 20fe86319b..5d480425bd 100644
--- a/engines/titanic/true_talk/tt_input.cpp
+++ b/engines/titanic/true_talk/tt_input.cpp
@@ -40,4 +40,8 @@ TTinput::TTinput(int inputCtr, const TTstring &line, CScriptHandler *owner,
_status = _line.isValid() && _string2.isValid() ? SS_11: SS_VALID;
}
+void TTinput::set38(int val) {
+ _field38 = val;
+}
+
} // End of namespace Titanic
diff --git a/engines/titanic/true_talk/tt_input.h b/engines/titanic/true_talk/tt_input.h
index 7e6fd92f12..e4d91d7a58 100644
--- a/engines/titanic/true_talk/tt_input.h
+++ b/engines/titanic/true_talk/tt_input.h
@@ -71,6 +71,8 @@ public:
public:
TTinput(int inputCtr, const TTstring &line, CScriptHandler *owner,
TTroomScript *roomScript, TTnpcScript *npcScript);
+
+ void set38(int v);
};
} // End of namespace Titanic
diff --git a/engines/titanic/true_talk/tt_parser.cpp b/engines/titanic/true_talk/tt_parser.cpp
index a48fcaea0e..2d958f8d7a 100644
--- a/engines/titanic/true_talk/tt_parser.cpp
+++ b/engines/titanic/true_talk/tt_parser.cpp
@@ -36,24 +36,138 @@ int TTparser::processInput(TTinput *input) {
}
int TTparser::normalize(TTinput *input) {
- TTstring *line = new TTstring();
+ TTstring *destLine = new TTstring();
+ const TTstring &srcLine = input->_line;
+ int srcSize = srcLine.size();
+ int savedIndex = 0;
+ int counter1 = 0;
+ int commandVal;
- for (const char *lineP = input->_line.c_str(); lineP; ++lineP) {
- char c = *lineP;
+ for (int index = 0; index < srcSize; ++index) {
+ char c = srcLine[index];
if (Common::isLower(c)) {
- (*line) += c;
+ (*destLine) += c;
} else if (Common::isSpace(c)) {
- if (!line->empty() && line->lastChar() != ' ')
- (*line) += ' ';
+ if (!destLine->empty() && destLine->lastChar() != ' ')
+ (*destLine) += ' ';
} else if (Common::isUpper(c)) {
- (*line) += toupper(c);
+ (*destLine) += toupper(c);
} else if (Common::isDigit(c)) {
- // TODO: num handling
+ if (c == '0' && isSpecialCommand(srcLine, index)) {
+ input->set38(10);
+ } else {
+ // Iterate through all the digits of the number
+ (*destLine) += c;
+ while (Common::isDigit(srcLine[index + 1]))
+ (*destLine) += srcLine[++index];
+ }
+ } else if (Common::isPunct(c)) {
+ bool flag = false;
+ switch (c) {
+ case '!':
+ input->set38(3);
+ break;
+
+ case '\'':
+ if (!normalizeQuotedString(srcLine, index, *destLine))
+ flag = true;
+ break;
+
+ case '.':
+ input->set38(1);
+ break;
+
+ case ':':
+ commandVal = isSpecialCommand(srcLine, index);
+ if (commandVal) {
+ input->set38(commandVal);
+ index += 2;
+ } else {
+ flag = true;
+ }
+ break;
+
+ case ';':
+ commandVal = isSpecialCommand(srcLine, index);
+ if (commandVal == 6) {
+ input->set38(7);
+ index += 2;
+ } else if (commandVal != 0) {
+ input->set38(commandVal);
+ index += 2;
+ }
+ break;
+
+ case '<':
+ ++index;
+ commandVal = isSpecialCommand(srcLine, index);
+ if (commandVal == 6) {
+ input->set38(12);
+ } else {
+ --index;
+ flag = true;
+ }
+ break;
+
+ case '>':
+ ++index;
+ commandVal = isSpecialCommand(srcLine, index);
+ if (commandVal == 6 || commandVal == 9) {
+ input->set38(11);
+ } else {
+ --index;
+ flag = true;
+ }
+ break;
+
+ case '?':
+ input->set38(2);
+ break;
+
+ default:
+ flag = true;
+ break;
+ }
+
+ if (flag && (!savedIndex || (index - savedIndex) == 1))
+ ++counter1;
+
+ savedIndex = index;
}
- // TODO other cases
}
return 0;
}
+int TTparser::isSpecialCommand(const TTstring &str, int &index) {
+ if (str[index] != ':' && str[index] != ';')
+ return 0;
+
+ if (str[index + 1] != '-')
+ return 0;
+
+ index += 2;
+ switch (str[index]) {
+ case '(':
+ case '<':
+ return 8;
+
+ case ')':
+ case '>':
+ return 6;
+
+ case 'P':
+ case 'p':
+ return 9;
+
+ default:
+ return 5;
+ }
+}
+
+bool TTparser::normalizeQuotedString(const TTstring &srcLine, int srcIndex, TTstring &destLine) {
+ // TODO
+ return false;
+}
+
} // End of namespace Titanic
diff --git a/engines/titanic/true_talk/tt_parser.h b/engines/titanic/true_talk/tt_parser.h
index 7df82b0b5b..d05835dd4c 100644
--- a/engines/titanic/true_talk/tt_parser.h
+++ b/engines/titanic/true_talk/tt_parser.h
@@ -31,7 +31,21 @@ class CScriptHandler;
class TTparser {
private:
+ /**
+ * Normalizes a passed input, taking care of things like removing extra
+ * spaces and lowercasing everything
+ */
int normalize(TTinput *input);
+
+ /**
+ * Submethod called by normalize to handle text following single quote chracters
+ */
+ bool normalizeQuotedString(const TTstring &srcLine, int srcIndex, TTstring &destLine);
+
+ /**
+ * Checks for what is likely special developer cheat codes
+ */
+ static int isSpecialCommand(const TTstring &str, int &index);
public:
CScriptHandler *_owner;
int _field4;
diff --git a/engines/titanic/true_talk/tt_string.cpp b/engines/titanic/true_talk/tt_string.cpp
index 338b7b50ae..5574cffb48 100644
--- a/engines/titanic/true_talk/tt_string.cpp
+++ b/engines/titanic/true_talk/tt_string.cpp
@@ -95,6 +95,10 @@ TTstring &TTstring::operator+=(char c) {
return *this;
}
+const char &TTstring::operator[](uint index) {
+ return *(c_str() + index);
+}
+
bool TTstring::empty() const {
return _data->_string.empty();
}
@@ -107,6 +111,10 @@ char TTstring::lastChar() const {
return _data->_string.lastChar();
}
+int TTstring::size() const {
+ return _data->_string.size();
+}
+
TTstring *TTstring::copy() const {
return new TTstring(c_str());
}
diff --git a/engines/titanic/true_talk/tt_string.h b/engines/titanic/true_talk/tt_string.h
index 8fe7127ac7..3b2b6a2245 100644
--- a/engines/titanic/true_talk/tt_string.h
+++ b/engines/titanic/true_talk/tt_string.h
@@ -57,9 +57,11 @@ public:
TTstring &operator+=(const char *str);
TTstring &operator+=(const TTstring &str);
TTstring &operator+=(char c);
+ const char &operator[](uint index);
bool empty() const;
char firstChar() const;
char lastChar() const;
+ int size() const;
/**
* Create a new copy of the string