#include "StdAfx.h" #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 numOfWordDefs; resFile >> numOfWordDefs; T2WordDef *theWordDef = new T2WordDef[numOfWordDefs]; for (unsigned int i = 0; i < numOfWordDefs; i++) theWordDef[i].Read(resFile); if (numOfWordDefs > 0) { unsigned char *seenArray = (unsigned char *) malloc(numOfWordDefs); memset(seenArray, 0, numOfWordDefs); unsigned int i = 0, wordInd; while ((outStr == "") && i < numOfWordDefs) { wordInd = UT2Utils::Randomize(numOfWordDefs); if (!seenArray[wordInd]) { seenArray[wordInd] = true; theWordDef[wordInd].GetWords(sex, age, flags, level, outStr); } else { for (i = 0; i < numOfWordDefs; i++) { if (!seenArray[i]) break; } } } free(seenArray); } delete[] theWordDef; } }