void buildMap(uint mapID) { var tiles = getTileList(mapID); // make sure we process maps which don't have tiles if (tiles.Count == 0) { // convert coord bounds to grid bounds getGridBounds(mapID, out uint minX, out uint minY, out uint maxX, out uint maxY); // add all tiles within bounds to tile list. for (uint i = minX; i <= maxX; ++i) { for (uint j = minY; j <= maxY; ++j) { uint packTileId = StaticMapTree.PackTileID(i, j); if (!tiles.Contains(packTileId)) { tiles.Add(packTileId); ++m_totalTiles; } } } } if (!tiles.Empty()) { // build navMesh dtNavMesh navMesh; buildNavMesh(mapID, out navMesh); if (navMesh == null) { Console.WriteLine($"[Map {mapID:D4}] Failed creating navmesh!"); m_totalTilesProcessed += tiles.Count; return; } // now start building mmtiles for each tile Console.WriteLine($"[Map {mapID:D4}] We have {tiles.Count} tiles. "); foreach (var it in tiles) { // unpack tile coords StaticMapTree.UnpackTileID(it, out uint tileX, out uint tileY); ++m_totalTilesProcessed; if (shouldSkipTile(mapID, tileX, tileY)) { continue; } buildTile(mapID, tileX, tileY, navMesh); } } Console.WriteLine($"[Map {mapID:D4}] Complete!"); }
void discoverTiles() { uint mapID, tileX, tileY, tileID, count = 0; Console.Write("Discovering maps... "); string[] files = Directory.GetFiles("maps").Select(Path.GetFileName).ToArray(); for (uint i = 0; i < files.Length; ++i) { mapID = uint.Parse(files[i].Substring(0, 4)); if (!m_tiles.Any(p => p.m_mapId == mapID)) { m_tiles.Add(new MapTiles(mapID)); count++; } } files = Directory.GetFiles("vmaps", "*.vmtree").Select(Path.GetFileName).ToArray(); for (uint i = 0; i < files.Length; ++i) { mapID = uint.Parse(files[i].Substring(0, 4)); if (!m_tiles.Any(p => p.m_mapId == mapID)) { m_tiles.Add(new MapTiles(mapID)); count++; } } Console.Write($" found {count}\n"); count = 0; Console.Write("Discovering tiles... "); foreach (var mapTile in m_tiles) { var tiles = mapTile.m_tiles; mapID = mapTile.m_mapId; files = Directory.GetFiles("vmaps", $"{mapID:D4}_*.vmtile").Select(Path.GetFileName).ToArray(); for (int i = 0; i < files.Length; ++i) { tileX = uint.Parse(files[i].Substring(8, 2)); tileY = uint.Parse(files[i].Substring(5, 2)); tileID = StaticMapTree.PackTileID(tileY, tileX); tiles.Add(tileID); count++; } files = Directory.GetFiles("maps", $"{mapID:D4}_*").Select(Path.GetFileName).ToArray(); for (uint i = 0; i < files.Length; ++i) { tileY = uint.Parse(files[i].Substring(5, 2)); tileX = uint.Parse(files[i].Substring(8, 2)); tileID = StaticMapTree.PackTileID(tileX, tileY); if (tiles.Add(tileID)) { count++; } } // make sure we process maps which don't have tiles if (tiles.Empty()) { // convert coord bounds to grid bounds getGridBounds(mapID, out uint minX, out uint minY, out uint maxX, out uint maxY); // add all tiles within bounds to tile list. for (uint i = minX; i <= maxX; ++i) { for (uint j = minY; j <= maxY; ++j) { if (tiles.Add(StaticMapTree.PackTileID(i, j))) { count++; } } } } } Console.Write($"found {count}\n"); Console.Write("\n"); }
public void buildMap(uint mapID) { int cursorLeft; int cursorTop; lock (_lock) { cursorLeft = Console.CursorLeft; cursorTop = Console.CursorTop; Console.WriteLine($"[Map: {mapID:D4} - 0%]"); } var tiles = getTileList(mapID); // make sure we process maps which don't have tiles if (tiles.Count == 0) { // convert coord bounds to grid bounds getGridBounds(mapID, out uint minX, out uint minY, out uint maxX, out uint maxY); // add all tiles within bounds to tile list. for (uint i = minX; i <= maxX; ++i) { for (uint j = minY; j <= maxY; ++j) { uint packTileId = StaticMapTree.PackTileID(i, j); if (!tiles.Contains(packTileId)) { tiles.Add(packTileId); } } } } if (!tiles.Empty()) { // build navMesh dtNavMesh navMesh; buildNavMesh(mapID, out navMesh); if (navMesh == null) { lock (_lock) { Console.SetCursorPosition(cursorLeft, cursorTop); Console.Write($"[Map: {mapID:D4}] - Failed creating navmesh!"); } return; } // now start building mmtiles for each tile int i = 0; foreach (var tileId in tiles) { // unpack tile coords StaticMapTree.UnpackTileID(tileId, out uint tileX, out uint tileY); if (!shouldSkipTile(mapID, tileX, tileY)) { lock (_lock) { Console.SetCursorPosition(cursorLeft, cursorTop); Console.Write($"[Map: {mapID:D4} - {i * 100 / tiles.Count}%] - Building tile [{tileX:D2},{tileY:D2}]"); } buildTile(mapID, tileX, tileY, navMesh); } ++i; } } lock (_lock) { Console.SetCursorPosition(cursorLeft, cursorTop); Console.WriteLine($"[Map: {mapID:D4}] - Done!"); } }
void discoverTiles() { uint mapID, tileX, tileY, tileID, count = 0; Console.WriteLine("Discovering maps... "); string[] files = Directory.GetFiles("maps").Select(Path.GetFileName).ToArray(); for (uint i = 0; i < files.Length; ++i) { mapID = uint.Parse(files[i].Substring(0, 4)); if (!m_tiles.Any(p => p.m_mapId == mapID)) { m_tiles.Add(new MapTiles(mapID)); count++; } } files = Directory.GetFiles("vmaps", "*.vmtree").Select(Path.GetFileName).ToArray(); for (uint i = 0; i < files.Length; ++i) { mapID = uint.Parse(files[i].Substring(0, 4)); if (!m_tiles.Any(p => p.m_mapId == mapID)) { m_tiles.Add(new MapTiles(mapID)); count++; } } Console.WriteLine($"found {count}"); count = 0; Console.WriteLine("Discovering tiles... "); foreach (var mapTile in m_tiles) { var tiles = mapTile.m_tiles; mapID = mapTile.m_mapId; files = Directory.GetFiles("vmaps", $"{mapID:D4}_*.vmtile").Select(Path.GetFileName).ToArray(); for (int i = 0; i < files.Length; ++i) { tileX = uint.Parse(files[i].Substring(8, 2)); tileY = uint.Parse(files[i].Substring(5, 2)); tileID = StaticMapTree.PackTileID(tileY, tileX); tiles.Add(tileID); count++; } files = Directory.GetFiles("maps", $"{mapID:D4}*").Select(Path.GetFileName).ToArray(); for (uint i = 0; i < files.Length; ++i) { tileY = uint.Parse(files[i].Substring(5, 2)); tileX = uint.Parse(files[i].Substring(8, 2)); tileID = StaticMapTree.PackTileID(tileX, tileY); if (tiles.Add(tileID)) { count++; } } } Console.WriteLine($"found {count}.\n"); Interlocked.Add(ref m_totalTiles, (int)count); }
public bool convertWorld2() { bool success = readMapSpawns(); if (!success) { return(false); } float invTileSize = 1.0f / 533.33333f; // export Map data foreach (var mapPair in mapData) { var mapSpawn = mapPair.Value; // build global map tree List <ModelSpawn> mapSpawns = new List <ModelSpawn>(); Console.WriteLine($"Calculating model bounds for map {mapPair.Key}..."); foreach (var entry in mapSpawn.UniqueEntries.Values) { // M2 models don't have a bound set in WDT/ADT placement data, i still think they're not used for LoS at all on retail if (Convert.ToBoolean(entry.flags & ModelFlags.M2)) { if (!calculateTransformedBound(entry)) { continue; } } mapSpawns.Add(entry); spawnedModelFiles.Add(entry.name); var tileEntries = Convert.ToBoolean(entry.flags & ModelFlags.ParentSpawn) ? mapSpawn.ParentTileEntries : mapSpawn.TileEntries; AxisAlignedBox bounds = entry.iBound; Vector2 low = new Vector2(bounds.Lo.X * invTileSize, bounds.Lo.Y * invTileSize); Vector2 high = new Vector2(bounds.Hi.X * invTileSize, bounds.Hi.Y * invTileSize); for (uint x = (ushort)low.X; x <= (ushort)high.X; ++x) { for (uint y = (ushort)low.Y; y <= (ushort)high.Y; ++y) { tileEntries.Add(StaticMapTree.PackTileID(x, y), new TileSpawn(entry.ID, entry.flags)); } } } Console.WriteLine($"Creating map tree for map {mapPair.Key}..."); BIH pTree = new BIH(); pTree.build(mapSpawns, BoundsTrait.GetBounds); // ===> possibly move this code to StaticMapTree class // write map tree file string mapfilename = $"{iDestDir}/{mapPair.Key:D4}.vmtree"; using (BinaryWriter writer = new BinaryWriter(File.Open(mapfilename, FileMode.Create, FileAccess.Write))) { //general info writer.WriteString(SharedConst.VMAP_MAGIC); // Nodes writer.WriteString("NODE"); pTree.writeToFile(writer); // spawn id to index map writer.WriteString("SIDX"); writer.Write(mapSpawns.Count); for (int i = 0; i < mapSpawns.Count; ++i) { writer.Write(mapSpawns[i].ID); writer.Write(i); } } // write map tile files, similar to ADT files, only with extra BIH tree node info foreach (var key in mapSpawn.TileEntries.Keys) { var spawnList = mapSpawn.TileEntries[key]; uint x, y; StaticMapTree.UnpackTileID(key, out x, out y); string tilefilename = $"{iDestDir}/{mapPair.Key:D4}_{y:D2}_{x:D2}.vmtile"; using (BinaryWriter writer = new BinaryWriter(File.Open(tilefilename, FileMode.Create, FileAccess.Write))) { var parentTileEntries = mapPair.Value.ParentTileEntries[key]; int nSpawns = spawnList.Count + parentTileEntries.Count; // file header writer.WriteString(SharedConst.VMAP_MAGIC); // write number of tile spawns writer.Write(nSpawns); // write tile spawns foreach (var tileSpawn in spawnList) { ModelSpawn.WriteToFile(writer, mapPair.Value.UniqueEntries[tileSpawn.Id]); } foreach (var spawnItr in parentTileEntries) { ModelSpawn.WriteToFile(writer, mapPair.Value.UniqueEntries[spawnItr.Id]); } } } } // add an object models, listed in temp_gameobject_models file exportGameobjectModels(); // export objects Console.WriteLine("Converting Model Files"); foreach (var mfile in spawnedModelFiles) { Console.WriteLine($"Converting {mfile}"); convertRawFile(mfile); } return(success); }