From 37e364b2c6cc7487a1c888d256a73e5337bb7189 Mon Sep 17 00:00:00 2001 From: Ash Wolf Date: Wed, 14 Jun 2023 00:50:34 +0100 Subject: initial commit --- src/T2DLL/T2WordDefArray.cpp | 49 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 src/T2DLL/T2WordDefArray.cpp (limited to 'src/T2DLL/T2WordDefArray.cpp') 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; + } +} -- cgit v1.2.3