PsyOps

zBaseLoader

Apr 29th, 2016
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.97 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Drawing;
  6.  
  7. namespace zxvf
  8. {
  9.     public class zBaseLoader
  10.     {
  11.         // Holds tileID using a multi dimensional array m_MapGrid[xCoor][yCoor]
  12.         private byte[][] m_MapTileIDs;
  13.         // Holds tileType
  14.         private byte[][] m_MapTileType;
  15.  
  16.         // 4 different points to check - x and y
  17.         private int[] add_x = { -1, 0, 1, 0 };
  18.         private int[] add_y = { 0, -1, 0, 1 };
  19.  
  20.         // Load variables in
  21.         public void LoadMapVars(byte[][] MapTileIDs, byte[][] MapTileType)
  22.         {
  23.             m_MapTileIDs = MapTileIDs;
  24.             m_MapTileType = MapTileType;
  25.         }
  26.  
  27.         List<ushort[]> Safes = new List<ushort[]>();
  28.  
  29.         public void LoadBases(List<Base> BaseList)
  30.         {
  31.             // Start scanning map
  32.             for (int y = 0; y < 1024; y += 1)
  33.             {
  34.                 for (int x = 0; x < 1024; x += 1)
  35.                 {
  36.                     // var to save the safe in
  37.                     ushort[] safe_found = new ushort[4];
  38.  
  39.                     // Start to store the dimensions by using first point
  40.                     safe_found = new ushort[] { (ushort)x, (ushort)y, (ushort)(x + 1), (ushort)(y + 1) };
  41.  
  42.                     Queue<Point> searchPoints = new Queue<Point>();
  43.                     searchPoints.Enqueue(new Point(x, y));
  44.  
  45.                     while (searchPoints.Count > 0)
  46.                     {
  47.                         // pull the enxt point out of list
  48.                         Point next = searchPoints.Dequeue();
  49.  
  50.                         // update safe dimensions
  51.                         m_UpdateDimension(safe_found, next);
  52.  
  53.                         // 4 point check for fill
  54.                         for (int i = 0; i < 4; i++)
  55.                         {
  56.                             // assign next point to check
  57.                             Point fourPoint = new Point( next.X + add_x[i], next.Y + add_y[i] );
  58.  
  59.                             // Make sure its a safe
  60.                             if (m_MapTileIDs[fourPoint.X][fourPoint.Y] == 171)
  61.                             {
  62.                                 // erase tile to avoid including it in q more than once
  63.                                 m_MapTileIDs[fourPoint.X][fourPoint.Y] = 0;
  64.                                 // add to q
  65.                                 searchPoints.Enqueue(fourPoint);
  66.                             }
  67.                         }
  68.                     }
  69.  
  70.                     // add safe into our list
  71.                     Safes.Add(safe_found);
  72.                 }
  73.             }
  74.         }
  75.  
  76.         private void m_UpdateDimension(ushort[] dim, Point p)
  77.         {
  78.             if (p.X < dim[0]) dim[0] = (ushort)p.X;
  79.             else if (p.X + 1 > dim[2]) dim[2] = (ushort)(p.X + 1);
  80.  
  81.             if (p.Y < dim[1]) dim[1] = (ushort)(p.Y);
  82.             else if (p.Y + 1 > dim[3]) dim[3] = (ushort)(p.Y + 1);
  83.         }
  84.     }
  85. }
Advertisement
Add Comment
Please, Sign In to add comment