summaryrefslogtreecommitdiff
path: root/src/T2DLL/T2WordDefArray.cpp
diff options
context:
space:
mode:
authorAsh Wolf <ninji@wuffs.org>2023-06-14 00:50:34 +0100
committerAsh Wolf <ninji@wuffs.org>2023-06-14 00:50:34 +0100
commit37e364b2c6cc7487a1c888d256a73e5337bb7189 (patch)
treeeaf6e857382eef16c2dd940eb4125536fbe068bd /src/T2DLL/T2WordDefArray.cpp
downloadt2win-37e364b2c6cc7487a1c888d256a73e5337bb7189.tar.gz
t2win-37e364b2c6cc7487a1c888d256a73e5337bb7189.zip
initial commit
Diffstat (limited to '')
-rw-r--r--src/T2DLL/T2WordDefArray.cpp49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/T2DLL/T2WordDefArray.cpp b/src/T2DLL/T2WordDefArray.cpp
new file mode 100644
index 0000000..76b3248
--- /dev/null
+++ b/src/T2DLL/T2WordDefArray.cpp
@@ -0,0 +1,49 @@
+#include "CResFile.h"
+#include "T2WordDef.h"
+#include "T2WordDefArray.h"
+#include "UT2Utils.h"
+
+T2WordDefArray::T2WordDefArray(HINSTANCE instance) {
+ mInstance = instance;
+}
+
+/*virtual*/ T2WordDefArray::~T2WordDefArray() {
+}
+
+void T2WordDefArray::GetWords(unsigned int sex, unsigned int age, unsigned int flags, unsigned int level, CString& outStr) const {
+ outStr = "";
+
+ CResFile resFile;
+ if (resFile.OpenResource(mInstance, 1, 'WoDf')) {
+ unsigned int numOfWordDef;
+ resFile >> numOfWordDef;
+
+ T2WordDef *wordDef = new T2WordDef[numOfWordDef];
+
+ for (unsigned int i = 0; i < numOfWordDef; i++)
+ wordDef[i].Read(resFile);
+
+ if (numOfWordDef > 0) {
+ unsigned char *seen = (unsigned char *) malloc(numOfWordDef);
+ memset(seen, 0, numOfWordDef);
+
+ unsigned int i = 0;
+ while ((outStr == "") && i < numOfWordDef) {
+ int rnd = UT2Utils::Randomize(numOfWordDef);
+ if (!seen[rnd]) {
+ seen[rnd] = true;
+ wordDef[rnd].GetWords(sex, age, flags, level, outStr);
+ } else {
+ for (i = 0; i < numOfWordDef; i++) {
+ if (!seen[i])
+ break;
+ }
+ }
+ }
+
+ free(seen);
+ }
+
+ delete[] wordDef;
+ }
+}