blob: 46f05d279fdaa0c0973d7ffd75f4161c0fb2d7f8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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 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;
}
}
|