Legends-of-Azeroth-Pandaria-5.4.8

Форк
0
390 строк · 12.2 Кб
1
/*
2
 * Copyright (C) 2011-2016 Project SkyFire <http://www.projectskyfire.org/>
3
 * Copyright (C) 2008-2016 TrinityCore <http://www.trinitycore.org/>
4
 * Copyright (C) 2005-2016 MaNGOS <http://getmangos.com/>
5
 *
6
 * This program is free software; you can redistribute it and/or modify it
7
 * under the terms of the GNU General Public License as published by the
8
 * Free Software Foundation; either version 3 of the License, or (at your
9
 * option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful, but WITHOUT
12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14
 * more details.
15
 *
16
 * You should have received a copy of the GNU General Public License along
17
 * with this program. If not, see <http://www.gnu.org/licenses/>.
18
 */
19

20
#include "DBCFileLoader.h"
21
#include "PathCommon.h"
22
#include "MapBuilder.h"
23
#include "Timer.h"
24
#include "Util.h"
25
#include <boost/filesystem.hpp>
26
#include <unordered_map>
27

28
using namespace MMAP;
29

30
namespace
31
{
32
    std::unordered_map<uint32, uint8> _liquidTypes;
33
}
34

35
uint32 GetLiquidFlags(uint32 liquidId)
36
{
37
    auto itr = _liquidTypes.find(liquidId);
38
    return itr != _liquidTypes.end() ? (1 << itr->second) : 0;
39
}
40

41
bool checkDirectories(bool debugOutput)
42
{
43
    std::vector<std::string> dirFiles;
44

45
    if (getDirContents(dirFiles, "maps") == LISTFILE_DIRECTORY_NOT_FOUND || dirFiles.empty())
46
    {
47
        printf("'maps' directory is empty or does not exist\n");
48
        return false;
49
    }
50

51
    dirFiles.clear();
52
    if (getDirContents(dirFiles, "vmaps", "*.vmtree") == LISTFILE_DIRECTORY_NOT_FOUND || dirFiles.empty())
53
    {
54
        printf("'vmaps' directory is empty or does not exist\n");
55
        return false;
56
    }
57

58
    dirFiles.clear();
59
    if (getDirContents(dirFiles, "mmaps") == LISTFILE_DIRECTORY_NOT_FOUND)
60
        return boost::filesystem::create_directory("mmaps");
61

62
    dirFiles.clear();
63
    if (debugOutput)
64
    {
65
        if (getDirContents(dirFiles, "meshes") == LISTFILE_DIRECTORY_NOT_FOUND)
66
        {
67
            printf("'meshes' directory does not exist (no place to put debugOutput files)\n");
68
            return false;
69
        }
70
    }
71

72
    return true;
73
}
74

75
bool handleArgs(int argc, char** argv,
76
               int &mapnum,
77
               int &tileX,
78
               int &tileY,
79
               Optional<float>& maxAngle,
80
               Optional<float>& maxAngleNotSteep,
81
               bool &skipLiquid,
82
               bool &skipContinents,
83
               bool &skipJunkMaps,
84
               bool &skipBattlegrounds,
85
               bool &skipArenas,
86
               bool &skipDungeons,
87
               bool &skipTransports,
88
               bool &debugOutput,
89
               bool &silent,
90
               bool &bigBaseUnit,
91
               char* &offMeshInputPath,
92
               char* &file,
93
               unsigned int& threads)
94
{
95
    char* param = nullptr;
96
    for (int i = 1; i < argc; ++i)
97
    {
98
        if (strcmp(argv[i], "--maxAngle") == 0)
99
        {
100
            param = argv[++i];
101
            if (!param)
102
                return false;
103

104
            float maxangle = atof(param);
105
            if (maxangle <= 90.f && maxangle >= 0.f)
106
                maxAngle = maxangle;
107
            else
108
                printf("invalid option for '--maxAngle', using default\n");
109
        }
110
        else if (strcmp(argv[i], "--maxAngleNotSteep") == 0)
111
        {
112
            param = argv[++i];
113
            if (!param)
114
                return false;
115

116
            float maxangle = atof(param);
117
            if (maxangle <= 90.f && maxangle >= 0.f)
118
                maxAngleNotSteep = maxangle;
119
            else
120
                printf("invalid option for '--maxAngleNotSteep', using default\n");
121
        }
122
        else if (strcmp(argv[i], "--threads") == 0)
123
        {
124
            param = argv[++i];
125
            if (!param)
126
                return false;
127
            threads = atoi(param);
128
            printf("Using %i threads to extract mmaps\n", threads);
129
        }
130
        else if (strcmp(argv[i], "--file") == 0)
131
        {
132
            param = argv[++i];
133
            if (!param)
134
                return false;
135
            file = param;
136
        }
137
        else if (strcmp(argv[i], "--tile") == 0)
138
        {
139
            param = argv[++i];
140
            if (!param)
141
                return false;
142

143
            char* stileX = strtok(param, ",");
144
            char* stileY = strtok(NULL, ",");
145
            int tilex = atoi(stileX);
146
            int tiley = atoi(stileY);
147

148
            if ((tilex > 0 && tilex < 64) || (tilex == 0 && strcmp(stileX, "0") == 0))
149
                tileX = tilex;
150
            if ((tiley > 0 && tiley < 64) || (tiley == 0 && strcmp(stileY, "0") == 0))
151
                tileY = tiley;
152

153
            if (tileX < 0 || tileY < 0)
154
            {
155
                printf("invalid tile coords.\n");
156
                return false;
157
            }
158
        }
159
        else if (strcmp(argv[i], "--skipLiquid") == 0)
160
        {
161
            param = argv[++i];
162
            if (!param)
163
                return false;
164

165
            if (strcmp(param, "true") == 0)
166
                skipLiquid = true;
167
            else if (strcmp(param, "false") == 0)
168
                skipLiquid = false;
169
            else
170
                printf("invalid option for '--skipLiquid', using default\n");
171
        }
172
        else if (strcmp(argv[i], "--skipContinents") == 0)
173
        {
174
            param = argv[++i];
175
            if (!param)
176
                return false;
177

178
            if (strcmp(param, "true") == 0)
179
                skipContinents = true;
180
            else if (strcmp(param, "false") == 0)
181
                skipContinents = false;
182
            else
183
                printf("invalid option for '--skipContinents', using default\n");
184
        }
185
        else if (strcmp(argv[i], "--skipJunkMaps") == 0)
186
        {
187
            param = argv[++i];
188
            if (!param)
189
                return false;
190

191
            if (strcmp(param, "true") == 0)
192
                skipJunkMaps = true;
193
            else if (strcmp(param, "false") == 0)
194
                skipJunkMaps = false;
195
            else
196
                printf("invalid option for '--skipJunkMaps', using default\n");
197
        }
198
        else if (strcmp(argv[i], "--skipBattlegrounds") == 0)
199
        {
200
            param = argv[++i];
201
            if (!param)
202
                return false;
203

204
            if (strcmp(param, "true") == 0)
205
                skipBattlegrounds = true;
206
            else if (strcmp(param, "false") == 0)
207
                skipBattlegrounds = false;
208
            else
209
                printf("invalid option for '--skipBattlegrounds', using default\n");
210
        }
211
        else if (strcmp(argv[i], "--skipArenas") == 0)
212
        {
213
            param = argv[++i];
214
            if (!param)
215
                return false;
216

217
            if (strcmp(param, "true") == 0)
218
                skipArenas = true;
219
            else if (strcmp(param, "false") == 0)
220
                skipArenas = false;
221
            else
222
                printf("invalid option for '--skipArenas', using default\n");
223
        }
224
        else if (strcmp(argv[i], "--skipDungeons") == 0)
225
        {
226
            param = argv[++i];
227
            if (!param)
228
                return false;
229

230
            if (strcmp(param, "true") == 0)
231
                skipDungeons = true;
232
            else if (strcmp(param, "false") == 0)
233
                skipDungeons = false;
234
            else
235
                printf("invalid option for '--skipDungeons', using default\n");
236
        }
237
        else if (strcmp(argv[i], "--skipTransports") == 0)
238
        {
239
            param = argv[++i];
240
            if (!param)
241
                return false;
242

243
            if (strcmp(param, "true") == 0)
244
                skipTransports = true;
245
            else if (strcmp(param, "false") == 0)
246
                skipTransports = false;
247
            else
248
                printf("invalid option for '--skipTransports', using default\n");
249
        }
250
        else if (strcmp(argv[i], "--debugOutput") == 0)
251
        {
252
            param = argv[++i];
253
            if (!param)
254
                return false;
255

256
            if (strcmp(param, "true") == 0)
257
                debugOutput = true;
258
            else if (strcmp(param, "false") == 0)
259
                debugOutput = false;
260
            else
261
                printf("invalid option for '--debugOutput', using default true\n");
262
        }
263
        else if (strcmp(argv[i], "--silent") == 0)
264
        {
265
            silent = true;
266
        }
267
        else if (strcmp(argv[i], "--bigBaseUnit") == 0)
268
        {
269
            param = argv[++i];
270
            if (!param)
271
                return false;
272

273
            if (strcmp(param, "true") == 0)
274
                bigBaseUnit = true;
275
            else if (strcmp(param, "false") == 0)
276
                bigBaseUnit = false;
277
            else
278
                printf("invalid option for '--bigBaseUnit', using default false\n");
279
        }
280
        else if (strcmp(argv[i], "--offMeshInput") == 0)
281
        {
282
            param = argv[++i];
283
            if (!param)
284
                return false;
285

286
            offMeshInputPath = param;
287
        }
288
        else
289
        {
290
            int map = atoi(argv[i]);
291
            if (map > 0 || (map == 0 && (strcmp(argv[i], "0") == 0)))
292
                mapnum = map;
293
            else
294
            {
295
                printf("invalid map id\n");
296
                return false;
297
            }
298
        }
299
    }
300

301
    return true;
302
}
303

304
int finish(const char* message, int returnValue)
305
{
306
    printf("%s", message);
307
    getchar(); // Wait for user input
308
    return returnValue;
309
}
310

311
std::unordered_map<uint32, uint8> LoadLiquid()
312
{
313
    DBCFileLoader liquidDbc;
314
    std::unordered_map<uint32, uint8> liquidData;
315
    // format string doesnt matter as long as it has correct length (only used for mapping to structures in worldserver)
316
    if (liquidDbc.Load((boost::filesystem::path("dbc") / "LiquidType.dbc").string().c_str(), "nxxixixxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"))
317
    {
318
        for (uint32 x = 0; x < liquidDbc.GetNumRows(); ++x)
319
        {
320
            DBCFileLoader::Record record = liquidDbc.getRecord(x);
321
            liquidData[record.getUInt(0)] = record.getUInt(3);
322
        }
323
    }
324

325
    return liquidData;
326
}
327

328
int main(int argc, char** argv)
329
{
330
    unsigned int threads = std::thread::hardware_concurrency();
331
    int mapnum = -1;
332
    int tileX = -1, tileY = -1;
333
    Optional<float> maxAngle, maxAngleNotSteep;    
334
    bool skipLiquid = false,
335
         skipContinents = false,
336
         skipJunkMaps = true,
337
         skipBattlegrounds = false,
338
         skipArenas = false,
339
         skipDungeons = false,
340
         skipTransports = false,
341
         debugOutput = false,
342
         silent = false,
343
         bigBaseUnit = false;
344
    char* offMeshInputPath = nullptr;
345
    char* file = NULL;
346

347
    bool validParam = handleArgs(argc, argv, mapnum,
348
                                 tileX, tileY, maxAngle, maxAngleNotSteep,
349
                                 skipLiquid, skipContinents, skipJunkMaps, skipBattlegrounds, skipArenas, skipDungeons, skipTransports,
350
                                 debugOutput, silent, bigBaseUnit, offMeshInputPath, file, threads);
351

352
    if (!validParam)
353
        return silent ? -1 : finish("You have specified invalid parameters", -1);
354

355
    if (mapnum == -1 && debugOutput)
356
    {
357
        if (silent)
358
            return -2;
359

360
        printf("You have specifed debug output, but didn't specify a map to generate.\n");
361
        printf("This will generate debug output for ALL maps.\n");
362
        printf("Are you sure you want to continue? (y/n) ");
363
        if (getchar() != 'y')
364
            return 0;
365
    }
366

367
    if (!checkDirectories(debugOutput))
368
        return silent ? -3 : finish("Press any key to close...", -3);
369

370
    _liquidTypes = LoadLiquid();
371
    if (_liquidTypes.empty())
372
        return silent ? -5 : finish("Failed to load LiquidType.dbc", -5);    
373

374
    MapBuilder builder(maxAngle, maxAngleNotSteep, skipLiquid, skipContinents, skipJunkMaps,
375
                       skipBattlegrounds, skipArenas, skipDungeons, skipTransports, debugOutput, bigBaseUnit, mapnum, offMeshInputPath, threads);
376

377
    uint32 start = getMSTime();
378
    if (file)
379
        builder.buildMeshFromFile(file);
380
    else if (tileX > -1 && tileY > -1 && mapnum >= 0)
381
        builder.buildSingleTile(mapnum, tileX, tileY);
382
    else if (mapnum >= 0)
383
        builder.buildMaps(uint32(mapnum));
384
    else
385
        builder.buildMaps({});
386

387
    if (!silent)
388
        printf("Finished. MMAPS were built in %u ms!\n", GetMSTimeDiffToNow(start));
389
    return 0;
390
}
391

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.