-
Notifications
You must be signed in to change notification settings - Fork 922
Expand file tree
/
Copy pathtestgen.cpp
More file actions
246 lines (221 loc) · 6.75 KB
/
testgen.cpp
File metadata and controls
246 lines (221 loc) · 6.75 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
#include <stdio.h>
#include <stdlib.h>
#include "all.h"
void write_file(char *path, void *buf, int size);
// drlg_l1.cpp
#define SL_NONE 0
#define Q_INVALID -1
void gen_drlg_l1_tests(void) {
printf("gen_drlg_l1_tests\n");
typedef struct {
// meta.
char *dungeon_name;
// pre.
BYTE dlvl;
BYTE dtype;
BYTE quest_id;
DWORD seed;
BYTE setlvl;
} Golden;
// Golden test cases.
Golden golden[] = {
{
"Cathedral", // dungeon_name
1, // dlvl
DTYPE_CATHEDRAL, // dtype
Q_INVALID, // quest_id
123, // seed
SL_NONE, // setlvl
},
{
"Cathedral (fix corners)", // dungeon_name
1, // dlvl
DTYPE_CATHEDRAL, // dtype
Q_INVALID, // quest_id
35, // seed
SL_NONE, // setlvl
},
{
"The Butcher", // dungeon_name
questlist[Q_BUTCHER]._qdlvl, // dlvl
DTYPE_CATHEDRAL, // dtype
Q_BUTCHER, // quest_id
123, // seed
SL_NONE, // setlvl
},
{
"Poisoned Water Supply", // dungeon_name
questlist[Q_PWATER]._qdlvl, // dlvl
DTYPE_CATHEDRAL, // dtype
Q_PWATER, // quest_id
123, // seed
SL_NONE, // setlvl
},
{
"Ogden's Sign", // dungeon_name
questlist[Q_LTBANNER]._qdlvl, // dlvl
DTYPE_CATHEDRAL, // dtype
Q_LTBANNER, // quest_id
123, // seed
SL_NONE, // setlvl
},
{
"Skeleton King's Lair (entrance)", // dungeon_name
questlist[Q_SKELKING]._qdlvl, // dlvl
DTYPE_CATHEDRAL, // dtype
Q_SKELKING, // quest_id
123, // seed
SL_NONE, // setlvl
},
{
"Skeleton King's Lair", // dungeon_name
questlist[Q_SKELKING]._qdlvl, // dlvl
DTYPE_CATHEDRAL, // dtype
Q_SKELKING, // quest_id
123, // seed
SL_SKELKING, // setlvl
},
// Broken seeds.
{
"Cathedral (broken seed)", // dungeon_name
1, // dlvl
DTYPE_CATHEDRAL, // dtype
Q_INVALID, // quest_id
2588, // seed
SL_NONE, // setlvl
},
{
"Cathedral (broken seed)", // dungeon_name
1, // dlvl
DTYPE_CATHEDRAL, // dtype
Q_INVALID, // quest_id
4743, // seed
SL_NONE, // setlvl
},
{
"Cathedral (broken seed)", // dungeon_name
1, // dlvl
DTYPE_CATHEDRAL, // dtype
Q_INVALID, // quest_id
7281, // seed
SL_NONE, // setlvl
},
{
"Cathedral (broken seed)", // dungeon_name
1, // dlvl
DTYPE_CATHEDRAL, // dtype
Q_INVALID, // quest_id
9345, // seed
SL_NONE, // setlvl
},
{
"Cathedral (broken seed)", // dungeon_name
1, // dlvl
DTYPE_CATHEDRAL, // dtype
Q_INVALID, // quest_id
15236, // seed
SL_NONE, // setlvl
},
// extra
{
"Cathedral (666)", // dungeon_name
1, // dlvl
DTYPE_CATHEDRAL, // dtype
Q_INVALID, // quest_id
1666, // seed
SL_NONE, // setlvl
},
};
// extra.
int in_entry = 0;
BYTE in_max_players = 1; // single
// Load MPQ archives.
init_archives();
// Load level graphics.
//diablo.LoadLevelGraphics();
leveltype = DTYPE_CATHEDRAL;
LoadLvlGFX(); // TODO: only load level graphics once per dtype.
for (int i = 0; i < sizeof(golden) / sizeof(Golden); i++) {
Golden g = golden[i];
// Reset globals (not needed).
memset(pdungeon, 0, sizeof(pdungeon));
memset(dungeon, 0, sizeof(dungeon));
memset(dPiece, 0, sizeof(dPiece));
memset(dSpecial, 0, sizeof(dSpecial));
memset(dTransVal, 0, sizeof(dTransVal));
//*gendung.DType = g.dtype;
leveltype = g.dtype;
// Establish pre-conditions.
//*gendung.DLvl = g.dlvl;
currlevel = g.dlvl;
//*multi.MaxPlayers = 1;
gbMaxPlayers = in_max_players;
//for i := range quests.Quests {
// quests.Quests[i].ID = quests.QuestID(i);
// quests.Quests[i].Active = false;
//}
for (int quest_id = 0; quest_id < MAXQUESTS; quest_id++) {
quests[quest_id]._qtype = quest_id;
quests[quest_id]._qactive = false;
}
//*gendung.IsQuestLevel = false;
if (g.setlvl != SL_NONE) {
setlevel = true;
setlvlnum = g.setlvl;
} else {
setlevel = false;
setlvlnum = SL_NONE;
}
//if g.questID != quests.Invalid {
// quests.Quests[g.questID].Active = true;
// quests.Quests[g.questID].DLvl = g.dlvl;
//}
if (g.quest_id != Q_INVALID) {
quests[g.quest_id]._qlevel = g.dlvl;
quests[g.quest_id]._qactive = true;
}
// Generate dungeon based on the given seed.
//l1.CreateDungeon(g.seed, 0);
if (g.setlvl != SL_NONE) {
LoadSetMap();
} else {
CreateL5Dungeon(g.seed, in_entry);
}
// Dump pre-dungeon tiles.
char output_path[MAX_PATH];
//sprintf(output_path, "testdata/pre-tiles_%d.bin", g.seed);
//write_file(output_path, pdungeon, sizeof(pdungeon));
// Dump tiles.
sprintf(output_path, "testdata/dlvl=%d,quest_id=%d,seed=%d,setlvl=%d_tiles.bin", g.dlvl, g.quest_id, g.seed, g.setlvl);
printf("creating '%s'\n", output_path);
write_file(output_path, dungeon, sizeof(dungeon));
// Dungeon dungeon pieces.
sprintf(output_path, "testdata/dlvl=%d,quest_id=%d,seed=%d,setlvl=%d_dpieces.bin", g.dlvl, g.quest_id, g.seed, g.setlvl);
printf("creating '%s'\n", output_path);
write_file(output_path, dPiece, sizeof(dPiece));
// Dungeon arches.
sprintf(output_path, "testdata/dlvl=%d,quest_id=%d,seed=%d,setlvl=%d_arches.bin", g.dlvl, g.quest_id, g.seed, g.setlvl);
printf("creating '%s'\n", output_path);
write_file(output_path, dSpecial, sizeof(dSpecial));
// Dungeon transparency.
sprintf(output_path, "testdata/dlvl=%d,quest_id=%d,seed=%d,setlvl=%d_transparency.bin", g.dlvl, g.quest_id, g.seed, g.setlvl);
printf("creating '%s'\n", output_path);
write_file(output_path, dTransVal, sizeof(dTransVal));
}
}
void testgen() {
printf("testgen\n");
gen_drlg_l1_tests();
}
void write_file(char *path, void *buf, int size) {
FILE *f = fopen(path, "wb");
if (f == NULL) {
fprintf(stderr, "unable to create file %s", path);
exit(1);
}
if (fwrite(buf, 1, size, f) != size) {
fprintf(stderr, "unable to write to file %s", path);
exit(1);
}
fclose(f);
}