PsyOps

MapInfo.cs

Dec 24th, 2015
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.83 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace DevaBot
  7. {
  8.     class MapData
  9.     {
  10.         // Holds tileID using a multi dimensional array m_MapGrid[xCoor][yCoor]
  11.         private byte[][] m_MapTileIDs;
  12.         public byte[][] TileIDs
  13.         {
  14.             get { return m_MapTileIDs; }
  15.         }
  16.  
  17.         // Holds tileType
  18.         private byte[][] m_MapTileType;
  19.         public byte[][] TileTypes
  20.         {
  21.             get { return m_MapTileType; }
  22.         }
  23.         // Saves a linear array of tile info into a multi dimensional array
  24.         public MapData(Byte[] mapData)
  25.         {
  26.             // temp array to make sure we dont double check tiles > 1x1
  27.             byte[][] m_MapTileIDs_temp;
  28.  
  29.             // Create arrays and initialize them
  30.             m_MapTileIDs_temp = new byte[1024][];
  31.             m_MapTileIDs = new byte[1024][];
  32.             m_MapTileType = new byte[1024][];
  33.             for (int i = 0; i < 1024; i += 1)
  34.             {
  35.                 m_MapTileIDs_temp[i] = new byte[1024];
  36.  
  37.                 m_MapTileIDs[i] = new byte[1024];
  38.                 m_MapTileType[i] = new byte[1024];
  39.  
  40.                 for (int j = 0; j < 1024; j += 1)
  41.                 {
  42.                     m_MapTileIDs_temp[i][j] = 0;
  43.  
  44.                     m_MapTileIDs[i][j] = 0;
  45.                     m_MapTileType[i][j] = 1;
  46.                 }
  47.             }
  48.  
  49.             // Convert from bit info into our array
  50.             int remainingBytes = mapData.Length;
  51.             for (Int32 i = 0; i < mapData.Length; i += 4)
  52.             {
  53.                 // Gathering the next 4 bytes and converting to Int32
  54.                 byte[] nextFour = new byte[4] { mapData[i], mapData[i + 1], mapData[i + 2], mapData[i + 3] };
  55.                 int mi = BitConverter.ToInt32(nextFour, 0);
  56.  
  57.                 int tile = mi >> 24 & 0x00ff;
  58.                 int y = (mi >> 12) & 0x03FF;
  59.                 int x = mi & 0x03FF;
  60.  
  61.                 // Sort Type here
  62.                 byte type = 1;
  63.  
  64.                 if (tile == 0) type = 1;
  65.                 else if (tile < 162) type = 0;
  66.                 else if (tile < 170) type = 2;
  67.                 else if (tile < 192) type = 1;
  68.                 else if (tile < 220) type = 0;
  69.                 else if (tile == 220) type = 3;
  70.                 else if (tile < 241) type = 0;
  71.                 else if (tile == 241) type = 1;
  72.                 else if (tile == 242) type = 3;
  73.                 else if (tile < 252) type = 0;
  74.                 else if (tile == 252) type = 3;
  75.  
  76.                 m_MapTileIDs[x][y] = (byte)tile;
  77.                 m_MapTileType[x][y] = type;
  78.  
  79.                 // Fill main array with missing tile info- see m_fillTile description
  80.                 switch (tile)
  81.                 {
  82.                     case 217:
  83.                         m_fillTile(x, y, 217, 2, type);
  84.                         break;
  85.                     case 219:
  86.                         m_fillTile(x, y, 219, 6, type);
  87.                         break;
  88.                     case 220:
  89.                         m_fillTile(x, y, 220, 5, type);
  90.                         break;
  91.                 }
  92.             }
  93.         }
  94.  
  95.         /*  The map info saved in a lvl file stores a tile bigger than 1x1
  96.          *  by only recording the top left tile coord. This will fill in the
  97.          *  empty tile locations that weren't recorded on the initial save.
  98.          *  Tiles: Station, Wormhole, and Large Ateroid       */
  99.         private void m_fillTile(int x, int y, byte ID, int places, byte type)
  100.         {
  101.             for (int i = 1; i < places; i++)
  102.             {
  103.                 for (int j = 1; j < places; j++)
  104.                 {
  105.                     m_MapTileIDs[x + i][y + j] = ID;
  106.                     m_MapTileType[x + i][y + j] = type;
  107.                 }
  108.             }
  109.         }
  110.     }
  111. }
Advertisement
Add Comment
Please, Sign In to add comment