using HPJ.Simulation.Enums; using HPJ.Simulation.Utilities; using System.Linq; namespace HPJ.Simulation.Map { /// /// A Flattenned version of a map that changes every tile type into a 1 or 0. Is it traverable or is it not /// [System.Serializable] public class BytePointMap { private byte[,] _tiles; /// /// The Tiles for the Byte Map /// public byte[,] Tiles { get { return _tiles; } } private int _width; /// /// The Width of the Byte Map /// public int Width { get { return _width; } } private int _length; /// /// The Length of the Byte Map /// public int Length { get { return _length; } } private bool _cornerCutting; /// /// Whether corner cuttins is enabled on this map /// public bool CornerCutting { get { return _cornerCutting; } set { _cornerCutting = value; } } private string _traversableKey; /// /// The Key used to flatten the map /// public string TraversableKey { get { return _traversableKey; } } private TileTypes[] _traversable; /// /// The Tiles that are traversable on this map /// public TileTypes[] Traversable { get { return _traversable; } } public BytePointMap(byte[,] TileTypeMap, TileTypes[] TraversableTiles, int TileMapWidth, int TileMapLength, bool CornerCuttingEnabled) { _traversable = TraversableTiles; _traversableKey = TraversableTiles.TilesToString(); _cornerCutting = CornerCuttingEnabled; _tiles = new byte[TileMapWidth, TileMapLength]; _width = TileMapWidth; _length = TileMapLength; for (int x = 0; x < TileMapWidth; x++) { for (int y = 0; y < TileMapLength; y++) { if (_traversable.Contains((TileTypes)TileTypeMap[x, y])) { _tiles[x, y] = 100; } else { _tiles[x, y] = 0; } } } } /// /// Changes the tile of the byte map /// /// /// /// public void ChangeTile(int x, int y, TileTypes newType) { if (_traversable.Contains(newType)) { _tiles[x, y] = 100; } else { _tiles[x, y] = 0; } } /// /// Changes the tile of the byte map /// /// /// public void ChangeTile(IntVector2 TileIndex, TileTypes newType) { if (_traversable.Contains(newType)) { _tiles[TileIndex.x, TileIndex.y] = 100; } else { _tiles[TileIndex.x, TileIndex.y] = 0; } } /// /// Gets the speed of the tile /// /// /// /// public byte GetTileSpeed(int x, int y) { if (x < 0 || x >= _width) { return 0; } if (y < 0 || y >= _length) { return 0; } return _tiles[x, y]; } } }