aboutsummaryrefslogtreecommitdiff
path: root/engines/titanic
diff options
context:
space:
mode:
authorPaul Gilbert2016-05-08 20:57:03 -0400
committerPaul Gilbert2016-07-10 16:38:53 -0400
commit9ce6391a94db959f3dde54ed3d0153e000aa3d5a (patch)
tree60cba99e447b562502d4b66815c94fa6bc44b7e6 /engines/titanic
parent71179e376363c1c59b9c7819bfbe89196c7bbc23 (diff)
downloadscummvm-rg350-9ce6391a94db959f3dde54ed3d0153e000aa3d5a.tar.gz
scummvm-rg350-9ce6391a94db959f3dde54ed3d0153e000aa3d5a.tar.bz2
scummvm-rg350-9ce6391a94db959f3dde54ed3d0153e000aa3d5a.zip
TITANIC: Beginnings of TTWord hierarchy
Diffstat (limited to 'engines/titanic')
-rw-r--r--engines/titanic/module.mk3
-rw-r--r--engines/titanic/support/file_reader.cpp9
-rw-r--r--engines/titanic/support/file_reader.h13
-rw-r--r--engines/titanic/support/simple_file.cpp23
-rw-r--r--engines/titanic/support/simple_file.h13
-rw-r--r--engines/titanic/true_talk/script_handler.cpp6
-rw-r--r--engines/titanic/true_talk/script_handler.h5
-rw-r--r--engines/titanic/true_talk/st_vocab.cpp20
-rw-r--r--engines/titanic/true_talk/st_vocab.h4
-rw-r--r--engines/titanic/true_talk/title_engine.cpp15
-rw-r--r--engines/titanic/true_talk/title_engine.h21
-rw-r--r--engines/titanic/true_talk/tt_string.cpp38
-rw-r--r--engines/titanic/true_talk/tt_string.h39
-rw-r--r--engines/titanic/true_talk/tt_word.cpp75
-rw-r--r--engines/titanic/true_talk/tt_word.h88
15 files changed, 333 insertions, 39 deletions
diff --git a/engines/titanic/module.mk b/engines/titanic/module.mk
index d808f77928..a3d60e7fdb 100644
--- a/engines/titanic/module.mk
+++ b/engines/titanic/module.mk
@@ -467,7 +467,8 @@ MODULE_OBJS := \
true_talk/tt_scripts.o \
true_talk/tt_string.o \
true_talk/tt_talker.o \
- true_talk/tt_title_script.o
+ true_talk/tt_title_script.o \
+ true_talk/tt_word.o
# This module can be built as a plugin
ifeq ($(ENABLE_TITANIC), DYNAMIC_PLUGIN)
diff --git a/engines/titanic/support/file_reader.cpp b/engines/titanic/support/file_reader.cpp
index 308d748704..f31d72bda5 100644
--- a/engines/titanic/support/file_reader.cpp
+++ b/engines/titanic/support/file_reader.cpp
@@ -24,10 +24,13 @@
namespace Titanic {
-void CFileReader::reset() {
- _file.close();
- _field18 = 0;
+CFileReader::CFileReader() : _owner(nullptr), _field4(0), _field8(0),
+ _fieldC(0), _field10(0), _field14(0), _field18(0) {
}
+void CFileReader::reset(CScriptHandler *owner, int val1, int val2) {
+ _owner = owner;
+ _field18 = val2;
+}
} // End of namespace Titanic
diff --git a/engines/titanic/support/file_reader.h b/engines/titanic/support/file_reader.h
index 23ab0a6fce..7d00ebd80d 100644
--- a/engines/titanic/support/file_reader.h
+++ b/engines/titanic/support/file_reader.h
@@ -27,12 +27,21 @@
namespace Titanic {
+class CScriptHandler;
+
class CFileReader {
public:
- Common::File _file;
+ CScriptHandler *_owner;
+ int _field4;
+ int _field8;
+ int _fieldC;
+ int _field10;
+ int _field14;
int _field18;
public:
- void reset();
+ CFileReader();
+
+ void reset(CScriptHandler *owner, int val1, int val2);
};
} // End of namespace Titanic
diff --git a/engines/titanic/support/simple_file.cpp b/engines/titanic/support/simple_file.cpp
index 88d74a9f47..b7f666a1ef 100644
--- a/engines/titanic/support/simple_file.cpp
+++ b/engines/titanic/support/simple_file.cpp
@@ -354,6 +354,29 @@ void SimpleFile::writeClassEnd(int indent) {
write("}\n", 2);
}
+bool SimpleFile::scanf(const char *format, ...) {
+ va_list va;
+ va_start(va, format);
+ char c;
+
+ CString formatStr(format);
+ while (!formatStr.empty()) {
+ if (formatStr.hasPrefix(" ")) {
+ formatStr.deleteChar(0);
+ safeRead(&c, 1);
+
+ if (!Common::isSpace(c))
+ return false;
+ } else if (formatStr.hasPrefix("%d")) {
+ formatStr = CString(formatStr.c_str() + 2);
+ int *param = (int *)va_arg(va, int *);
+ *param = readNumber();
+ }
+ }
+
+ va_end(va);
+}
+
/*------------------------------------------------------------------------*/
void StdCWadFile::open(const CString &name) {
diff --git a/engines/titanic/support/simple_file.h b/engines/titanic/support/simple_file.h
index 115e3805da..431df016ad 100644
--- a/engines/titanic/support/simple_file.h
+++ b/engines/titanic/support/simple_file.h
@@ -122,6 +122,11 @@ public:
void readBuffer(char *buffer = nullptr, size_t count = 0);
/**
+ * Scan in values from the file
+ */
+ bool scanf(const char *format, ...);
+
+ /**
* Write a string line
*/
void writeLine(const CString &str);
@@ -197,6 +202,14 @@ public:
* Write out the ending footer for a class definition
*/
void writeClassEnd(int indent);
+
+ /**
+ * Return true if the stream has finished being read
+ */
+ bool eos() const {
+ assert(_inStream);
+ return _inStream->eos();
+ }
};
/**
diff --git a/engines/titanic/true_talk/script_handler.cpp b/engines/titanic/true_talk/script_handler.cpp
index bd98aad15f..09110a3f19 100644
--- a/engines/titanic/true_talk/script_handler.cpp
+++ b/engines/titanic/true_talk/script_handler.cpp
@@ -53,10 +53,14 @@ ScriptChangedResult CScriptHandler::scriptChanged(TTRoomScript *roomScript, TTNp
void CScriptHandler::processInput(TTRoomScript *roomScript, TTNpcScript *npcScript,
const TTString &line) {
- if (!roomScript || line.empty())
+ if (!roomScript || !line.isValid())
return;
// TODO
}
+SimpleFile *CScriptHandler::openResource(const CString &name) {
+ return _owner->open(name);
+}
+
} // End of namespace Titanic
diff --git a/engines/titanic/true_talk/script_handler.h b/engines/titanic/true_talk/script_handler.h
index 16dff1bf36..38da259021 100644
--- a/engines/titanic/true_talk/script_handler.h
+++ b/engines/titanic/true_talk/script_handler.h
@@ -85,6 +85,11 @@ public:
void processInput(TTRoomScript *roomScript, TTNpcScript *npcScript,
const TTString &line);
+
+ /**
+ * Open a resource for access
+ */
+ SimpleFile *openResource(const CString &name);
};
} // End of namespace Titanic
diff --git a/engines/titanic/true_talk/st_vocab.cpp b/engines/titanic/true_talk/st_vocab.cpp
index ed41a4a61b..b725101214 100644
--- a/engines/titanic/true_talk/st_vocab.cpp
+++ b/engines/titanic/true_talk/st_vocab.cpp
@@ -20,18 +20,32 @@
*
*/
+#include "common/file.h"
#include "titanic/true_talk/st_vocab.h"
+#include "titanic/titanic.h"
namespace Titanic {
-STVocab::STVocab(int val): _field0(0), _field4(0), _field8(0),
+STVocab::STVocab(int val): _field0(0), _field4(0), _vocab(nullptr),
_fieldC(0), _field10(0), _field18(val) {
_field14 = load("STvocab.txt");
}
int STVocab::load(const CString &name) {
- // TODO
- return 0;
+ SimpleFile *file = g_vm->_fileReader._owner->openResource(name);
+ int result = 0;
+
+ while (!file->eos()) {
+ int mode = file->readNumber();
+
+ switch (mode) {
+ case 0:
+ break;
+ }
+ }
+
+ delete file;
+ return result;
}
} // End of namespace Titanic
diff --git a/engines/titanic/true_talk/st_vocab.h b/engines/titanic/true_talk/st_vocab.h
index 2b4ebb8d72..090dc74237 100644
--- a/engines/titanic/true_talk/st_vocab.h
+++ b/engines/titanic/true_talk/st_vocab.h
@@ -24,6 +24,8 @@
#define TITANIC_ST_VOCAB_H
#include "titanic/support/string.h"
+#include "titanic/true_talk/tt_string.h"
+#include "titanic/true_talk/tt_word.h"
namespace Titanic {
@@ -31,7 +33,7 @@ class STVocab {
private:
int _field0;
int _field4;
- int _field8;
+ TTString *_vocab;
int _fieldC;
int _field10;
int _field14;
diff --git a/engines/titanic/true_talk/title_engine.cpp b/engines/titanic/true_talk/title_engine.cpp
index 3908ea0986..24cc4216ee 100644
--- a/engines/titanic/true_talk/title_engine.cpp
+++ b/engines/titanic/true_talk/title_engine.cpp
@@ -64,14 +64,13 @@ void STtitleEngine::dump(int val1, int val2) {
// TODO
}
-void STtitleEngine::open(const CString &name) {
- _stream = _resources.getResource(Common::WinResourceID("Text"),
- name);
-}
-
-void STtitleEngine::close() {
- delete _stream;
- _stream = nullptr;
+SimpleFile *STtitleEngine::open(const CString &name) {
+ Common::SeekableReadStream *stream = _resources.getResource(
+ Common::WinResourceID("Text"), name);
+
+ SimpleFile *file = new SimpleFile();
+ file->open(stream);
+ return file;
}
} // End of namespace Titanic
diff --git a/engines/titanic/true_talk/title_engine.h b/engines/titanic/true_talk/title_engine.h
index 12a02e2b81..fda35ac7bf 100644
--- a/engines/titanic/true_talk/title_engine.h
+++ b/engines/titanic/true_talk/title_engine.h
@@ -32,6 +32,13 @@
namespace Titanic {
+class CTitleEngine;
+
+class CTitleStream : public SimpleFile {
+public:
+ CTitleStream() : SimpleFile() {}
+};
+
class CTitleEngine {
public:
CScriptHandler *_scriptHandler;
@@ -56,12 +63,7 @@ public:
/**
* Open a designated file
*/
- virtual void open(const CString &name) = 0;
-
- /**
- * Close the file
- */
- virtual void close() = 0;
+ virtual SimpleFile *open(const CString &name) = 0;
};
class STtitleEngine : public CTitleEngine {
@@ -96,12 +98,7 @@ public:
/**
* Open a designated file
*/
- virtual void open(const CString &name);
-
- /**
- * Close the file
- */
- virtual void close();
+ virtual SimpleFile *open(const CString &name);
};
} // End of namespace Titanic
diff --git a/engines/titanic/true_talk/tt_string.cpp b/engines/titanic/true_talk/tt_string.cpp
index f9ae5d6e11..ffe6509e07 100644
--- a/engines/titanic/true_talk/tt_string.cpp
+++ b/engines/titanic/true_talk/tt_string.cpp
@@ -24,4 +24,42 @@
namespace Titanic {
+TTString::TTString() : _status(SS_VALID) {
+ _data = new TTStringData();
+}
+
+TTString::TTString(const char *str) : _status(SS_VALID) {
+ _data = new TTStringData(str);
+}
+
+TTString::TTString(const CString &str) {
+ if (_status != SS_VALID) {
+ _status = SS_5;
+ _data = nullptr;
+ } else {
+ _status = SS_VALID;
+ _data = new TTStringData(str);
+ }
+}
+
+TTString::TTString(TTString &str) {
+ if (_status != SS_VALID) {
+ _status = SS_5;
+ _data = nullptr;
+ } else {
+ _status = SS_VALID;
+ _data = str._data;
+ _data->_referenceCount++;
+ }
+}
+
+TTString::~TTString() {
+ if (--_data->_referenceCount == 0)
+ delete _data;
+}
+
+bool TTString::isValid() const {
+ return _status == SS_VALID;
+}
+
} // End of namespace Titanic
diff --git a/engines/titanic/true_talk/tt_string.h b/engines/titanic/true_talk/tt_string.h
index d593553f5c..947007f1ff 100644
--- a/engines/titanic/true_talk/tt_string.h
+++ b/engines/titanic/true_talk/tt_string.h
@@ -27,18 +27,41 @@
namespace Titanic {
-class TTString: public CString {
+class TTStringData {
+private:
+ CString _string;
public:
- int _status;
+ int _referenceCount;
public:
- TTString() : CString(), _status(0) {}
- TTString(const char *str) : CString(str), _status(0) {}
- TTString(const CString &str) : CString(str), _status(0) {}
- virtual ~TTString() {}
+ TTStringData() : _referenceCount(1) {}
+ TTStringData(const char *str) : _string(str), _referenceCount(1) {}
+ TTStringData(const CString &str) : _string(str), _referenceCount(1) {}
+};
+
+enum TTStringStatus { SS_VALID = 0, SS_5 = 5, SS_7 = 7 };
+
+class TTString {
+private:
+ TTStringData *_data;
+ TTStringStatus _status;
+public:
+ TTString();
+ TTString(const char *str);
+ TTString(const CString &str);
+ TTString(TTString &str);
+ virtual ~TTString();
+
+ /**
+ * Returns true if the string is valid
+ */
+ bool isValid() const;
- bool isValid() const { return !_status; }
+ /**
+ * Get the status of the string
+ */
+ TTStringStatus getStatus() const { return _status; }
};
} // End of namespace Titanic
-#endif /* TITANIC_TT_OBJ8_H */
+#endif /* TITANIC_TT_STRING_H */
diff --git a/engines/titanic/true_talk/tt_word.cpp b/engines/titanic/true_talk/tt_word.cpp
new file mode 100644
index 0000000000..4405f72555
--- /dev/null
+++ b/engines/titanic/true_talk/tt_word.cpp
@@ -0,0 +1,75 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include "titanic/true_talk/tt_word.h"
+
+namespace Titanic {
+
+TTWord::TTWord(TTString &str, int val1, int val2) : _string(str),
+ _field18(val1), _field1C(val2), _fieldC(0), _field10(0),
+ _field20(0), _field24(0), _field28(0) {
+ _status = str.getStatus() == SS_VALID ? SS_VALID : SS_5;
+}
+
+/*------------------------------------------------------------------------*/
+
+void TTWord::readSyn(SimpleFile *file) {
+}
+
+/*------------------------------------------------------------------------*/
+
+TTWord1::TTWord1(TTString &str, int val1, int val2, int val3) :
+ TTWord(str, val1, val2), _field2C(val3) {
+}
+
+/*------------------------------------------------------------------------*/
+
+TTWord2::TTWord2(TTString &str, int val1, int val2, int val3, int val4) :
+ TTWord1(str, val1, val2, val3), _field30(val4) {
+}
+
+/*------------------------------------------------------------------------*/
+
+TTWord3::TTWord3(TTString &str, int val1, int val2, int val3, int val4, int val5, int val6) :
+ TTWord1(str, val1, val2, val4), _field34(val3), _field30(val5), _field3C(val6),
+ _field38(0) {
+}
+
+/*------------------------------------------------------------------------*/
+
+TTWord4::TTWord4(TTString &str, int val1, int val2, int val3, int val4) :
+ TTWord1(str, val1, val2, val3) {
+ if (val4 >= 0 && val4 <= 9) {
+ _field30 = val4;
+ } else {
+ _field30 = 0;
+ _status = SS_5;
+ }
+}
+
+/*------------------------------------------------------------------------*/
+
+TTWord5::TTWord5(TTString &str, int val1, int val2, int val3, int val4) :
+ TTWord1(str, val1, val2, val3), _field30(val4) {
+}
+
+} // End of namespace Titanic
diff --git a/engines/titanic/true_talk/tt_word.h b/engines/titanic/true_talk/tt_word.h
new file mode 100644
index 0000000000..d8b34ed04e
--- /dev/null
+++ b/engines/titanic/true_talk/tt_word.h
@@ -0,0 +1,88 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#ifndef TITANIC_TT_WORD_H
+#define TITANIC_TT_WORD_H
+
+#include "titanic/support/simple_file.h"
+#include "titanic/true_talk/tt_string.h"
+
+namespace Titanic {
+
+class TTWord {
+protected:
+ TTString _string;
+ int _fieldC;
+ int _field10;
+ TTStringStatus _status;
+ int _field18;
+ int _field1C;
+ int _field20;
+ int _field24;
+ int _field28;
+public:
+ TTWord(TTString &str, int val1, int val2);
+
+ void readSyn(SimpleFile *file);
+};
+
+class TTWord1 : public TTWord {
+protected:
+ int _field2C;
+public:
+ TTWord1(TTString &str, int val1, int val2, int val3);
+};
+
+class TTWord2 : public TTWord1 {
+protected:
+ int _field30;
+public:
+ TTWord2(TTString &str, int val1, int val2, int val3, int val4);
+};
+
+class TTWord3 : public TTWord1 {
+protected:
+ int _field30;
+ int _field34;
+ int _field38;
+ int _field3C;
+public:
+ TTWord3(TTString &str, int val1, int val2, int val3, int val4, int val5, int val6);
+};
+
+class TTWord4 : public TTWord1 {
+protected:
+ int _field30;
+public:
+ TTWord4(TTString &str, int val1, int val2, int val3, int val4);
+};
+
+class TTWord5 : public TTWord1 {
+protected:
+ int _field30;
+public:
+ TTWord5(TTString &str, int val1, int val2, int val3, int val4);
+};
+
+} // End of namespace Titanic
+
+#endif /* TITANIC_TT_WORD_H */