forked from mangos/Extractor_projects
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerator.cpp
More file actions
457 lines (418 loc) · 13.2 KB
/
generator.cpp
File metadata and controls
457 lines (418 loc) · 13.2 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
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
/**
* MaNGOS is a full featured server for World of Warcraft, supporting
* the following clients: 1.12.x, 2.4.3, 3.3.5a, 4.3.4a and 5.4.8
*
* Copyright (C) 2005-2022 MaNGOS <https://getmangos.eu>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* World of Warcraft, and all World of Warcraft or Warcraft art, images,
* and lore are copyrighted by Blizzard Entertainment, Inc.
*/
#include "ace/High_Res_Timer.h"
#include "MMapCommon.h"
#include "MapBuilder.h"
#include "ExtractorCommon.h"
using namespace MMAP;
bool checkDirectories(bool debugOutput)
{
vector<string> dirFiles;
if (getDirContents(dirFiles, "maps") == LISTFILE_DIRECTORY_NOT_FOUND || !dirFiles.size())
{
printf(" 'maps' directory is empty or does not exist\n");
return false;
}
dirFiles.clear();
if (getDirContents(dirFiles, "vmaps", "*.vmtree") == LISTFILE_DIRECTORY_NOT_FOUND || !dirFiles.size())
{
printf(" 'vmaps' directory is empty or does not exist\n");
return false;
}
dirFiles.clear();
if (getDirContents(dirFiles, "mmaps") == LISTFILE_DIRECTORY_NOT_FOUND)
{
//printf(" 'mmaps' directory does not exist\n");
CreateDir(std::string("mmaps"));
}
dirFiles.clear();
if (debugOutput)
{
if (getDirContents(dirFiles, "meshes") == LISTFILE_DIRECTORY_NOT_FOUND)
{
printf(" 'meshes' directory does not exist (no place to put debugOutput files)\n");
return false;
}
}
return true;
}
void printUsage(char* prg)
{
printf(" Usage: %s [OPTION]\n\n", prg);
printf(" Generate movement maps from extracted client maps.\n");
printf(" -h, --help show the usage\n");
printf(" -i, --input <path> search path for game client folder\n");
printf(" --threads [#] number of worker threads (default 0).\n");
printf(" --maxAngle [#] max walkable inclination angle.\n");
printf(" --tile [#,#] build the specified tile.\n");
printf(" --skipLiquid [true|false] skip liquid data for maps.\n");
printf(" --skipContinents [true|false] skip continents.\n");
printf(" --skipJunkMaps [true|false] skip unused junk maps.\n");
printf(" --skipBattlegrounds [true|false] skip battleground maps.\n");
printf(" --bigBaseUnit [true|false] generate tile/map using bigger basic unit.\n");
printf(" --offMeshInput [file.*] path to file containing off mesh.\n");
printf(" connections data\n");
printf(" --debugOutput [true|false] create debugging files for use with\n");
printf(" RecastDemo.\n");
printf(" --silent No questions asked.\n");
printf(" [#] Build only the map specified by #.\n");
printf("\n");
printf(" Examples:\n");
printf(" - generate all movement maps:\n");
printf(" %s\n", prg);
printf(" - generate only map 0:\n");
printf(" %s 0\n", prg);
printf(" - build tile 34,46 of map 0:\n");
printf(" %s --tile 34,46\n", prg);
}
bool handleArgs(int argc, char** argv,
char* gameInputPath,
int& mapnum,
int& tileX,
int& tileY,
float& maxAngle,
bool& skipLiquid,
bool& skipContinents,
bool& skipJunkMaps,
bool& skipBattlegrounds,
bool& debugOutput,
bool& silent,
bool& bigBaseUnit,
int& num_threads,
char*& offMeshInputPath)
{
char* param = NULL;
for (int i = 1; i < argc; ++i)
{
if (strcmp(argv[i], "-i") == 0 || strcmp(argv[i], "--input") == 0)
{
param = argv[++i];
if (!param)
{
return false;
}
strcpy(gameInputPath, param);
}
else if (strcmp(argv[i], "--maxAngle") == 0)
{
param = argv[++i];
if (!param)
{
return false;
}
float maxangle = atof(param);
if (maxangle <= 90.f && maxangle >= 45.f)
{
maxAngle = maxangle;
}
else
{
printf("invalid option for '--maxAngle', using default\n");
}
}
else if (strcmp(argv[i], "--threads") == 0)
{
param = argv[++i];
if (!param)
{
return false;
}
int nThreads = atoi(param);
if (nThreads)
{
num_threads = nThreads;
}
else
{
printf("invalid option for '--threads', using single threaded build\n");
}
}
else if (strcmp(argv[i], "--tile") == 0)
{
param = argv[++i];
if (!param)
{
return false;
}
char* stileX = strtok(param, ",");
char* stileY = strtok(NULL, ",");
int tilex = atoi(stileX);
int tiley = atoi(stileY);
if ((tilex > 0 && tilex < 64) || (tilex == 0 && strcmp(stileX, "0") == 0))
{
tileX = tilex;
}
if ((tiley > 0 && tiley < 64) || (tiley == 0 && strcmp(stileY, "0") == 0))
{
tileY = tiley;
}
if (tileX < 0 || tileY < 0)
{
printf("invalid tile coords.\n");
return false;
}
}
else if (strcmp(argv[i], "--skipLiquid") == 0)
{
param = argv[++i];
if (!param)
{
return false;
}
if (strcmp(param, "true") == 0)
{
skipLiquid = true;
}
else if (strcmp(param, "false") == 0)
{
skipLiquid = false;
}
else
{
printf("invalid option for '--skipLiquid', using default\n");
}
}
else if (strcmp(argv[i], "--skipContinents") == 0)
{
param = argv[++i];
if (!param)
{
return false;
}
if (strcmp(param, "true") == 0)
{
skipContinents = true;
}
else if (strcmp(param, "false") == 0)
{
skipContinents = false;
}
else
{
printf("invalid option for '--skipContinents', using default\n");
}
}
else if (strcmp(argv[i], "--skipJunkMaps") == 0)
{
param = argv[++i];
if (!param)
{
return false;
}
if (strcmp(param, "true") == 0)
{
skipJunkMaps = true;
}
else if (strcmp(param, "false") == 0)
{
skipJunkMaps = false;
}
else
{
printf("invalid option for '--skipJunkMaps', using default\n");
}
}
else if (strcmp(argv[i], "--skipBattlegrounds") == 0)
{
param = argv[++i];
if (!param)
{
return false;
}
if (strcmp(param, "true") == 0)
{
skipBattlegrounds = true;
}
else if (strcmp(param, "false") == 0)
{
skipBattlegrounds = false;
}
else
{
printf("invalid option for '--skipBattlegrounds', using default\n");
}
}
else if (strcmp(argv[i], "--debugOutput") == 0)
{
param = argv[++i];
if (!param)
{
return false;
}
if (strcmp(param, "true") == 0)
{
debugOutput = true;
}
else if (strcmp(param, "false") == 0)
{
debugOutput = false;
}
else
{
printf("invalid option for '--debugOutput', using default true\n");
}
}
else if (strcmp(argv[i], "--silent") == 0)
{
silent = true;
}
else if (strcmp(argv[i], "--bigBaseUnit") == 0)
{
param = argv[++i];
if (!param)
{
return false;
}
if (strcmp(param, "true") == 0)
{
bigBaseUnit = true;
}
else if (strcmp(param, "false") == 0)
{
bigBaseUnit = false;
}
else
{
printf("invalid option for '--bigBaseUnit', using default false\n");
}
}
else if (strcmp(argv[i], "--offMeshInput") == 0)
{
param = argv[++i];
if (!param)
{
return false;
}
offMeshInputPath = param;
}
else if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0)
{
printUsage(argv[0]);
exit(1);
}
else
{
int map = atoi(argv[i]);
if (map > 0 || (map == 0 && (strcmp(argv[i], "0") == 0)))
{
mapnum = map;
}
else
{
printf("invalid map id\n");
return false;
}
}
}
return true;
}
int finish(const char* message, int returnValue)
{
printf("%s", message);
(void)getchar();
return returnValue;
}
int main(int argc, char** argv)
{
char map_magic[16];
char input_path[128] = "."; /**< TODO */
int mapnum = -1;
float maxAngle = 60.0f;
int tileX = -1, tileY = -1;
bool skipLiquid = false,
skipContinents = false,
skipJunkMaps = true,
skipBattlegrounds = false,
debugOutput = false,
silent = false,
bigBaseUnit = false;
int num_threads = 0;
char* offMeshInputPath = NULL;
bool validParam = handleArgs(argc, argv, input_path, mapnum,
tileX, tileY, maxAngle,
skipLiquid, skipContinents, skipJunkMaps, skipBattlegrounds,
debugOutput, silent, bigBaseUnit, num_threads, offMeshInputPath);
if (!validParam)
{
return silent ? -1 : finish(" You have specified invalid parameters (use -h for more help)", -1);
}
int thisBuild = getBuildNumber(input_path);
int iCoreNumber = getCoreNumberFromBuild(thisBuild);
showBanner("Movement Map Generator", iCoreNumber);
setMapMagicVersion(iCoreNumber, map_magic);
showWebsiteBanner();
if (mapnum == -1 && debugOutput)
{
if (silent)
{
return -2;
}
printf(" You have specifed debug output, but didn't specify a map to generate.\n");
printf(" This will generate debug output for ALL maps.\n");
printf(" Are you sure you want to continue? (y/n) ");
if (getchar() != 'y')
{
return 0;
}
}
if (!checkDirectories(debugOutput))
{
return silent ? -3 : finish(" Press any key to close...", -3);
}
MapBuilder builder(map_magic, maxAngle, skipLiquid, skipContinents, skipJunkMaps,
skipBattlegrounds, debugOutput, bigBaseUnit, offMeshInputPath);
ACE_Time_Value elapsed;
ACE_High_Res_Timer timer;
timer.start();
if (tileX > -1 && tileY > -1 && mapnum >= 0)
{
builder.buildSingleTile(mapnum, tileX, tileY);
}
else
{
if (num_threads && builder.activate(num_threads)== -1)
{
if (!silent)
{
printf(" Thread initialization was not ok. The build is single threaded\n");
}
}
if (builder.activated())
{
printf(" Using %d thread(s) for building\n", num_threads);
}
if (mapnum >= 0)
{
builder.buildMap(uint32(mapnum), true);
}
else
{
builder.buildAllMaps();
}
}
timer.stop();
timer.elapsed_time(elapsed);
printf(" \n Total build time: %ld seconds\n\n", elapsed.sec());
return silent ? 1 : finish(" Movemap build is complete! Press enter to exit\n", 1);
}