public void Load(TileMatrixClient tileData, Map map) { // get data from the tile Matrix byte[] groundData = tileData.GetLandBlock(BlockX, BlockY); int staticLength; byte[] staticsData = tileData.GetStaticBlock(BlockX, BlockY, out staticLength); // load the ground data into the tiles. int groundDataIndex = 0; for (int i = 0; i < 64; i++) { int iTileID = groundData[groundDataIndex++] + (groundData[groundDataIndex++] << 8); int iTileZ = (sbyte)groundData[groundDataIndex++]; Ground ground = new Ground(iTileID, map); ground.Position.Set((int)BlockX * 8 + i % 8, (int)BlockY * 8 + (i / 8), iTileZ); } // load the statics data into the tiles int countStatics = staticLength / 7; int staticDataIndex = 0; for (int i = 0; i < countStatics; i++) { int iTileID = staticsData[staticDataIndex++] + (staticsData[staticDataIndex++] << 8); int iX = staticsData[staticDataIndex++]; int iY = staticsData[staticDataIndex++]; int iTileZ = (sbyte)staticsData[staticDataIndex++]; int hue = staticsData[staticDataIndex++] + (staticsData[staticDataIndex++] * 256); StaticItem item = new StaticItem(iTileID, hue, i, map); item.Position.Set((int)BlockX * 8 + iX, (int)BlockY * 8 + iY, iTileZ); } }
public void CreateSeasonalTileInfo() { m_StaticCounts = new Dictionary<int, int>(); TileMatrixClient tileData = new TileMatrixClient(0); Map map = new Map(0); for (uint y = 0; y < tileData.BlockHeight; y++) { Tracer.Info("Map Parser: row {0}.", y); for (uint x = 0; x < tileData.BlockWidth; x++) { ParseMapBlock(tileData, x, y); } } var items = from pair in m_StaticCounts orderby pair.Value descending select pair; using (FileStream file = new FileStream(@"AllTiles.txt", FileMode.Create)) { StreamWriter stream = new StreamWriter(file); foreach (KeyValuePair<int, int> pair in items) { ItemData itemData = TileData.ItemData[pair.Key]; if ((itemData.IsBackground || itemData.IsFoliage) && !itemData.IsWet && !itemData.IsSurface) stream.WriteLine(string.Format("{0},{1} ; {2}", pair.Key, pair.Value, itemData.Name)); } stream.Flush(); file.Flush(); } }
public TileMatrixClientPatch(TileMatrixClient matrix, uint index) { if (!m_Enabled) { return; } LoadLandPatches(matrix, String.Format("mapdif{0}.mul", index), String.Format("mapdifl{0}.mul", index)); LoadStaticPatches(matrix, String.Format("stadif{0}.mul", index), String.Format("stadifl{0}.mul", index), String.Format("stadifi{0}.mul", index)); }
public Map(uint index) { Index = index; MapData = new TileMatrixClient(Index); TileHeight = MapData.BlockHeight * 8; TileWidth = MapData.BlockWidth * 8; m_Blocks = new MapBlock[c_CellsInMemorySpan * c_CellsInMemorySpan]; }
private static sbyte[] m_Zs = new sbyte[64]; // shared between all instances of MiniMapBlock. #endregion Fields #region Constructors public MiniMapBlock(uint x, uint y, TileMatrixClient tileData) { X = x; Y = y; Colors = new uint[64]; // get data from the tile Matrix byte[] groundData = tileData.GetLandBlock(x, y); int staticLength; byte[] staticsData = tileData.GetStaticBlock(x, y, out staticLength); // get the ground colors int groundDataIndex = 0; for (int i = 0; i < 64; i++) { Colors[i] = IO.RadarColorData.Colors[groundData[groundDataIndex++] + (groundData[groundDataIndex++] << 8)]; m_Zs[i]= (sbyte)groundData[groundDataIndex++]; } // get the static colors int countStatics = staticLength / 7; int staticDataIndex = 0; for (int i = 0; i < countStatics; i++) { int itemID = staticsData[staticDataIndex++] + (staticsData[staticDataIndex++] << 8); int tile = staticsData[staticDataIndex++] + staticsData[staticDataIndex++] * 8; sbyte z = (sbyte)staticsData[staticDataIndex++]; int hue = staticsData[staticDataIndex++] + (staticsData[staticDataIndex++] * 256); // is this used? ItemData data = TileData.ItemData[itemID]; int iz = z + data.Height + (data.IsRoof || data.IsSurface ? 1 : 0); if ((x * 8 + (tile % 8) == 1480) && (y * 8 + (tile / 8) == 1608)) { if (iz > m_Zs[tile]) { Colors[tile] = IO.RadarColorData.Colors[itemID + 0x4000]; m_Zs[tile] = (sbyte)iz; } } if (iz > m_Zs[tile]) { Colors[tile] = IO.RadarColorData.Colors[itemID + 0x4000]; m_Zs[tile] = (sbyte)iz; } } }
private void ParseMapBlock(TileMatrixClient tileData, uint x, uint y) { byte[] groundData = tileData.GetLandBlock(x, y); int staticLength; byte[] staticsData = tileData.GetStaticBlock(x, y, out staticLength); // load the statics data int countStatics = staticLength / 7; int staticDataIndex = 0; for (int i = 0; i < countStatics; i++) { int iTileID = staticsData[staticDataIndex++] + (staticsData[staticDataIndex++] << 8); int iX = staticsData[staticDataIndex++]; int iY = staticsData[staticDataIndex++]; int iTileZ = (sbyte)staticsData[staticDataIndex++]; int hue = staticsData[staticDataIndex++] + (staticsData[staticDataIndex++] * 256); if (m_StaticCounts.ContainsKey(iTileID)) m_StaticCounts[iTileID]++; else m_StaticCounts.Add(iTileID, 1); } }
private unsafe int LoadStaticPatches(TileMatrixClient tileMatrix, string dataPath, string indexPath, string lookupPath) { m_StaticPatchPtrs = new Dictionary<uint, Tuple<int, int>>(); m_StaticPatchStream = FileManager.GetFile(dataPath); using (FileStream fsIndex = FileManager.GetFile(indexPath)) { using (FileStream fsLookup = FileManager.GetFile(lookupPath)) { BinaryReader indexReader = new BinaryReader(fsIndex); BinaryReader lookupReader = new BinaryReader(fsLookup); int count = (int)(indexReader.BaseStream.Length / 4); for (int i = 0; i < count; ++i) { uint blockID = indexReader.ReadUInt32(); uint blockX = blockID / tileMatrix.BlockHeight; uint blockY = blockID % tileMatrix.BlockHeight; uint key = MakeBlockKey(blockX, blockY); int offset = lookupReader.ReadInt32(); int length = lookupReader.ReadInt32(); lookupReader.ReadInt32(); if (m_StaticPatchPtrs.ContainsKey(key)) { // Tuple<int, int> old = m_StaticPatchPtrs[key]; m_StaticPatchPtrs[key] = new Tuple<int, int>(offset, length); } else { m_StaticPatchPtrs.Add(key, new Tuple<int, int>(offset, length)); } } indexReader.Close(); lookupReader.Close(); return count; } } }
private unsafe int LoadLandPatches(TileMatrixClient tileMatrix, string landPath, string indexPath) { m_LandPatchPtrs = new Dictionary<uint, uint>(); m_LandPatchStream = FileManager.GetFile(landPath); using (FileStream fsIndex = FileManager.GetFile(indexPath)) { BinaryReader indexReader = new BinaryReader(fsIndex); int count = (int)(indexReader.BaseStream.Length / 4); uint ptr = 0; for (int i = 0; i < count; ++i) { uint blockID = indexReader.ReadUInt32(); uint x = blockID / tileMatrix.BlockHeight; uint y = blockID % tileMatrix.BlockHeight; uint key = MakeBlockKey(x, y); ptr += 4; m_LandPatchPtrs.Add(key, ptr); ptr += 192; } indexReader.Close(); return count; } }