PsyOps

Base Class

Apr 24th, 2016
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.05 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. /*-------------------------------
  6.  * TileID
  7.  * ------------------------------
  8.  * 0        = No tile
  9.  * 1-19     = Normal tiles
  10.  * 20       = Border
  11.  * 21-161   = Normal tiles
  12.  * 162-165  = Vertical doors
  13.  * 166-169  = Horizontal doors
  14.  * 170      = Flag
  15.  * 171      = Safe zone
  16.  * 172      = Goal area
  17.  * 173-175  = Fly over tiles
  18.  * 176-191  = Fly under tiles
  19.  --------------------------------
  20.  *  TileType
  21.  *-------------------------------
  22.  * 0    solid
  23.  * 1    passable - or no tile
  24.  * 2    door
  25.  * 3    warp/wormhole
  26.  * 4    brick
  27.  ---------------------------------*/
  28. namespace zxvf
  29. {
  30.     public class MapInfo
  31.     {
  32.         private byte[][] m_MapGrid;
  33.  
  34.         public MapInfo(Byte[] mapData)
  35.         {
  36.             m_MapGrid = new byte[1024][];
  37.  
  38.             for (int i = 0; i < 1024; i += 1)
  39.             {
  40.                 m_MapGrid[i] = new byte[1024];
  41.                 for (int j = 0; j < 1024; j += 1)
  42.                 {
  43.                     m_MapGrid[i][j] = 0;
  44.                 }
  45.             }
  46.  
  47.             int remainingBytes = mapData.Length;
  48.             for (Int32 i = 0; i < mapData.Length; i += 4)
  49.             {
  50.                 // Gathering the next 4 bytes and converting to Int32
  51.                 byte[] nextFour = new byte[4] { mapData[i], mapData[i + 1], mapData[i + 2], mapData[i + 3] };
  52.                 int mi = BitConverter.ToInt32(nextFour, 0);
  53.  
  54.                 int tile = mi >> 24 & 0x00ff;
  55.                 int y = (mi >> 12) & 0x03FF;
  56.                 int x = mi & 0x03FF;
  57.  
  58.                 m_MapGrid[x][y] = (byte)tile;
  59.             }
  60.         }
  61.        
  62.         public void MyMapFunction()
  63.         {
  64.             // do stuffs here
  65.         }
  66.         public byte GetTileID(ushort x, ushort y)
  67.         {
  68.             return m_GetTileID(x, y);
  69.         }
  70.  
  71.         private byte getTileType(ushort x, ushort y)
  72.         {
  73.             byte id = m_GetTileID(x, y);
  74.             if (id == 0) return 1;
  75.  
  76.             if (id < 162)
  77.                 return 0;
  78.             else if (id < 170)
  79.                 return 2;
  80.             else if (id < 192)
  81.                 return 1;
  82.             else if (id < 220)
  83.                 return 0;
  84.             else if (id == 220)
  85.                 return 3;
  86.             else if (id < 241)
  87.                 return 0;
  88.             else if (id == 241)
  89.                 return 1;
  90.             else if (id == 242)
  91.                 return 3;
  92.             else if (id < 252)
  93.                 return 0;
  94.             else if (id == 252)
  95.                 return 3;
  96.  
  97.             return 1;
  98.         }
  99.         /// <summary>
  100.         /// Return TileId and also check surrounding area
  101.         ///  to make sure coords arent inside one of the larger tile types:
  102.         /// Station\Wormhole\Large Asteroid
  103.         /// </summary>
  104.         /// <param name="x">x coord</param>
  105.         /// <param name="y">y coord</param>
  106.         /// <returns>Returns ID of tile</returns>
  107.         private byte m_GetTileID(ushort x, ushort y)
  108.         {
  109.             if (m_MapGrid[x][y] != 0) return m_MapGrid[x][y];
  110.  
  111.             int startXIndex = x - 5 < 0 ? 0 : x - 5;    // Using largest dimension for check
  112.             int startYIndex = y - 5 < 0 ? 0 : y - 5;    // The station, its 6x6 - then work down
  113.  
  114.             for (int i = startXIndex; i < x; i += 1)
  115.             {
  116.                 for (int j = startYIndex; j < y; j += 1)
  117.                 {
  118.                     if (m_MapGrid[i][j] == 219) // Check for station first
  119.                         return 219;
  120.                     if ((x - i <= 4 || y - j <= 4) && m_MapGrid[i][j] == 220)// Check for wormhole if within region (5 tiles)
  121.                         return 220;
  122.                     if ((x - i <= 1 || y - j <= 1) && m_MapGrid[i][j] == 217)// Last Check - Large Asteroid (2x2 tiles)
  123.                         return 217;
  124.                 }
  125.             }
  126.             return 0;   // No tile found
  127.         }
  128.  
  129.         public string[] MapPrintOut()
  130.         {
  131.             string[] reply = new string[12];
  132.             int norm = 0;
  133.             int door_v = 0;
  134.             int door_h = 0;
  135.             int flags = 0;
  136.             int safe = 0;
  137.             int goal = 0;
  138.             int flyOver = 0;
  139.             int flyUnder = 0;
  140.             int total = 0;
  141.  
  142.             for (int i = 0; i < 1024; i += 1)
  143.             {
  144.                 for (int j = 0; j < 1024; j += 1)
  145.                 {
  146.                     byte id = m_MapGrid[i][j];
  147.                     if (id > 0)
  148.                     {
  149.                         total++;
  150.                         if (id < 162)
  151.                             norm++;
  152.                         else if (id < 166)
  153.                             door_v++;
  154.                         else if (id < 170)
  155.                             door_h++;
  156.                         else if (id == 170)
  157.                             flags++;
  158.                         else if (id == 171)
  159.                             safe++;
  160.                         else if (id == 172)
  161.                             goal++;
  162.                         else if (id < 176)
  163.                             flyOver++;
  164.                         else if (id < 192)
  165.                             flyUnder++;
  166.                     }
  167.                 }
  168.             }
  169.  
  170.             reply[0] = "+---------------------------------------+";
  171.             reply[1] = "+            Map Information            +";
  172.             reply[2] = "+---------------------------------------+";
  173.             reply[3] = "Normal Tiles".PadRight(30) + norm;
  174.             reply[4] = "Door Tiles (V)".PadRight(30) + door_v;
  175.             reply[5] = "Door Tiles (H)".PadRight(30) + door_h;
  176.             reply[6] = "Total Flags".PadRight(30) + flags;
  177.             reply[7] = "Safe Tiles".PadRight(30) + safe;
  178.             reply[8] = "Goal Tiles".PadRight(30) + goal;
  179.             reply[9] = "Fly Over".PadRight(30) + flyOver;
  180.             reply[10] = "Fly Under".PadRight(30) + flyUnder;
  181.             reply[11] = "Total Tiles".PadRight(30) + total;
  182.  
  183.             return reply;
  184.         }
  185.     }
  186. }
Advertisement
Add Comment
Please, Sign In to add comment