diff options
Diffstat (limited to '')
-rw-r--r-- | src/T2DLL/T2WordDefArray.cpp | 49 |
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; + } +} |