Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- /*-------------------------------
- * TileID
- * ------------------------------
- * 0 = No tile
- * 1-19 = Normal tiles
- * 20 = Border
- * 21-161 = Normal tiles
- * 162-165 = Vertical doors
- * 166-169 = Horizontal doors
- * 170 = Flag
- * 171 = Safe zone
- * 172 = Goal area
- * 173-175 = Fly over tiles
- * 176-191 = Fly under tiles
- --------------------------------
- * TileType
- *-------------------------------
- * 0 solid
- * 1 passable - or no tile
- * 2 door
- * 3 warp/wormhole
- * 4 brick
- ---------------------------------*/
- namespace zxvf
- {
- public class MapInfo
- {
- private byte[][] m_MapGrid;
- public MapInfo(Byte[] mapData)
- {
- m_MapGrid = new byte[1024][];
- for (int i = 0; i < 1024; i += 1)
- {
- m_MapGrid[i] = new byte[1024];
- for (int j = 0; j < 1024; j += 1)
- {
- m_MapGrid[i][j] = 0;
- }
- }
- int remainingBytes = mapData.Length;
- for (Int32 i = 0; i < mapData.Length; i += 4)
- {
- // Gathering the next 4 bytes and converting to Int32
- byte[] nextFour = new byte[4] { mapData[i], mapData[i + 1], mapData[i + 2], mapData[i + 3] };
- int mi = BitConverter.ToInt32(nextFour, 0);
- int tile = mi >> 24 & 0x00ff;
- int y = (mi >> 12) & 0x03FF;
- int x = mi & 0x03FF;
- m_MapGrid[x][y] = (byte)tile;
- }
- }
- public void MyMapFunction()
- {
- // do stuffs here
- }
- public byte GetTileID(ushort x, ushort y)
- {
- return m_GetTileID(x, y);
- }
- private byte getTileType(ushort x, ushort y)
- {
- byte id = m_GetTileID(x, y);
- if (id == 0) return 1;
- if (id < 162)
- return 0;
- else if (id < 170)
- return 2;
- else if (id < 192)
- return 1;
- else if (id < 220)
- return 0;
- else if (id == 220)
- return 3;
- else if (id < 241)
- return 0;
- else if (id == 241)
- return 1;
- else if (id == 242)
- return 3;
- else if (id < 252)
- return 0;
- else if (id == 252)
- return 3;
- return 1;
- }
- /// <summary>
- /// Return TileId and also check surrounding area
- /// to make sure coords arent inside one of the larger tile types:
- /// Station\Wormhole\Large Asteroid
- /// </summary>
- /// <param name="x">x coord</param>
- /// <param name="y">y coord</param>
- /// <returns>Returns ID of tile</returns>
- private byte m_GetTileID(ushort x, ushort y)
- {
- if (m_MapGrid[x][y] != 0) return m_MapGrid[x][y];
- int startXIndex = x - 5 < 0 ? 0 : x - 5; // Using largest dimension for check
- int startYIndex = y - 5 < 0 ? 0 : y - 5; // The station, its 6x6 - then work down
- for (int i = startXIndex; i < x; i += 1)
- {
- for (int j = startYIndex; j < y; j += 1)
- {
- if (m_MapGrid[i][j] == 219) // Check for station first
- return 219;
- if ((x - i <= 4 || y - j <= 4) && m_MapGrid[i][j] == 220)// Check for wormhole if within region (5 tiles)
- return 220;
- if ((x - i <= 1 || y - j <= 1) && m_MapGrid[i][j] == 217)// Last Check - Large Asteroid (2x2 tiles)
- return 217;
- }
- }
- return 0; // No tile found
- }
- public string[] MapPrintOut()
- {
- string[] reply = new string[12];
- int norm = 0;
- int door_v = 0;
- int door_h = 0;
- int flags = 0;
- int safe = 0;
- int goal = 0;
- int flyOver = 0;
- int flyUnder = 0;
- int total = 0;
- for (int i = 0; i < 1024; i += 1)
- {
- for (int j = 0; j < 1024; j += 1)
- {
- byte id = m_MapGrid[i][j];
- if (id > 0)
- {
- total++;
- if (id < 162)
- norm++;
- else if (id < 166)
- door_v++;
- else if (id < 170)
- door_h++;
- else if (id == 170)
- flags++;
- else if (id == 171)
- safe++;
- else if (id == 172)
- goal++;
- else if (id < 176)
- flyOver++;
- else if (id < 192)
- flyUnder++;
- }
- }
- }
- reply[0] = "+---------------------------------------+";
- reply[1] = "+ Map Information +";
- reply[2] = "+---------------------------------------+";
- reply[3] = "Normal Tiles".PadRight(30) + norm;
- reply[4] = "Door Tiles (V)".PadRight(30) + door_v;
- reply[5] = "Door Tiles (H)".PadRight(30) + door_h;
- reply[6] = "Total Flags".PadRight(30) + flags;
- reply[7] = "Safe Tiles".PadRight(30) + safe;
- reply[8] = "Goal Tiles".PadRight(30) + goal;
- reply[9] = "Fly Over".PadRight(30) + flyOver;
- reply[10] = "Fly Under".PadRight(30) + flyUnder;
- reply[11] = "Total Tiles".PadRight(30) + total;
- return reply;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment