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;
- using System.Drawing;
- namespace zxvf
- {
- public class zBaseLoader
- {
- // Holds tileID using a multi dimensional array m_MapGrid[xCoor][yCoor]
- private byte[][] m_MapTileIDs;
- // Holds tileType
- private byte[][] m_MapTileType;
- // 4 different points to check - x and y
- private int[] add_x = { -1, 0, 1, 0 };
- private int[] add_y = { 0, -1, 0, 1 };
- // Load variables in
- public void LoadMapVars(byte[][] MapTileIDs, byte[][] MapTileType)
- {
- m_MapTileIDs = MapTileIDs;
- m_MapTileType = MapTileType;
- }
- List<ushort[]> Safes = new List<ushort[]>();
- public void LoadBases(List<Base> BaseList)
- {
- // Start scanning map
- for (int y = 0; y < 1024; y += 1)
- {
- for (int x = 0; x < 1024; x += 1)
- {
- // var to save the safe in
- ushort[] safe_found = new ushort[4];
- // Start to store the dimensions by using first point
- safe_found = new ushort[] { (ushort)x, (ushort)y, (ushort)(x + 1), (ushort)(y + 1) };
- Queue<Point> searchPoints = new Queue<Point>();
- searchPoints.Enqueue(new Point(x, y));
- while (searchPoints.Count > 0)
- {
- // pull the enxt point out of list
- Point next = searchPoints.Dequeue();
- // update safe dimensions
- m_UpdateDimension(safe_found, next);
- // 4 point check for fill
- for (int i = 0; i < 4; i++)
- {
- // assign next point to check
- Point fourPoint = new Point( next.X + add_x[i], next.Y + add_y[i] );
- // Make sure its a safe
- if (m_MapTileIDs[fourPoint.X][fourPoint.Y] == 171)
- {
- // erase tile to avoid including it in q more than once
- m_MapTileIDs[fourPoint.X][fourPoint.Y] = 0;
- // add to q
- searchPoints.Enqueue(fourPoint);
- }
- }
- }
- // add safe into our list
- Safes.Add(safe_found);
- }
- }
- }
- private void m_UpdateDimension(ushort[] dim, Point p)
- {
- if (p.X < dim[0]) dim[0] = (ushort)p.X;
- else if (p.X + 1 > dim[2]) dim[2] = (ushort)(p.X + 1);
- if (p.Y < dim[1]) dim[1] = (ushort)(p.Y);
- else if (p.Y + 1 > dim[3]) dim[3] = (ushort)(p.Y + 1);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment