Example #1
0
 private static List<Vector2> GetBlockPoints(Block block, int layer)
 {
     var obstacles = GetBlockLines(block, layer);
     var blockPoints = new List<Vector2>();
     foreach (var lineObstacle in obstacles)
     {
         if (!blockPoints.Contains(lineObstacle.Start))
             blockPoints.Add(lineObstacle.Start);
         if (!blockPoints.Contains(lineObstacle.End))
             blockPoints.Add(lineObstacle.End);
     }
     return blockPoints;
 }
Example #2
0
        private static bool CheckBlocksAbove(Block block, Map.Map map, int layer, Dictionary<int, List<IObstacle>> layerObstacles, Dictionary<Block, List<Vector2>> blockPointsDictionary)
        {
            List<Vector2> blockPoints;
            if (!blockPointsDictionary.TryGetValue(block, out blockPoints))
            {
                blockPoints = GetBlockPoints(block, layer);
                blockPointsDictionary.Add(block, blockPoints);
            }
            for (var z = (int)block.Position.Z + 1; z < 8; z++)
            {
                if (map.GetBlock(new Vector3(block.Position.X, block.Position.Y, z)).Lid)
                    return true;

                var blockFilled = false;
                foreach (var layerObstacle in layerObstacles[z])
                {
                    var containAll = false;

                    var polygonObstacle = layerObstacle as PolygonObstacle;
                    if (polygonObstacle != null)
                        containAll = blockPoints.All(polygonObstacle.Contains);

                    var rectangleObstacle = layerObstacle as RectangleObstacle;
                    if (rectangleObstacle != null)
                        containAll = blockPoints.All(rectangleObstacle.Contains);

                    if (!containAll)
                        continue;
                    //all points are within the polygon, block is ok
                    blockFilled = true;
                    break;
                }
                if (blockFilled)
                    return true;
            }
            return false;
        }
Example #3
0
 public static List<ILineObstacle> GetBlockLines(Block block, int layer)
 {
     var obstacles = new List<ILineObstacle>();
     block.GetCollision(obstacles, false);
     if (obstacles.Count == 0)
     {
         obstacles.Add(LineObstacle.DefaultLeft((int)block.Position.X, (int)block.Position.Y, layer));
         obstacles.Add(LineObstacle.DefaultTop((int)block.Position.X, (int)block.Position.Y, layer));
         obstacles.Add(LineObstacle.DefaultRight((int)block.Position.X, (int)block.Position.Y, layer));
         obstacles.Add(LineObstacle.DefaultBottom((int)block.Position.X, (int)block.Position.Y, layer));
     }
     return obstacles;
 }
Example #4
0
        private void GetNeighborBlocks(LineSegment line, IEnumerable<Block> blocks, out Block blockX, out Block blockY, out Orientation orientation)
        {
            blockX = null;
            blockY = null;
            orientation = Orientation.Other;
            foreach (var block in blocks)
            {
                var found = false;
                var blockLines = Polygon.GetBlockLines(block, Layer).Where(item => item.IsSlope);
                foreach (var lineObstacle in blockLines)
                {

                    if (line.Start == lineObstacle.Start && line.End == lineObstacle.End)
                        found = true;
                    else if (line.End == lineObstacle.Start && line.Start == lineObstacle.End)
                        found = true;
                    if (found)
                        break;
                }
                if (!found)
                    continue;
                if (blockX == null)
                    blockX = block;
                else
                {
                    blockY = block;
                    //ok, we have both blocks
                    var isVertical = line.Direction == Direction.Down || line.Direction == Direction.Up;
                    var isHorizontal = line.Direction == Direction.Left || line.Direction == Direction.Right;

                    if (isVertical)
                    {
                        orientation = Orientation.Vertical;
                        if (blockX.Position.X < blockY.Position.X)
                            return;
                    }
                    if (isHorizontal)
                    {
                        orientation = Orientation.Horizontal;
                        if (blockX.Position.Y < blockY.Position.Y)
                            return;
                    }
                    var blockTemp = blockX;
                    blockX = blockY;
                    blockY = blockTemp;
                    return;
                }
            }
        }
Example #5
0
        private static bool BlocksMatch(Block blockX, Block blockY, Orientation orientation)
        {
            //well, I should do it more dynamically...
            if (blockX == null || blockY == null)
                return true;

            if (blockX.SlopeDirection == blockY.SlopeDirection && blockX.SlopeSubTyp == blockY.SlopeSubTyp)
            {
                if ((blockX.SlopeDirection == SlopeDirection.Up || blockX.SlopeDirection == SlopeDirection.Down) && orientation == Orientation.Vertical)
                    return true;
                if ((blockX.SlopeDirection == SlopeDirection.Right || blockX.SlopeDirection == SlopeDirection.Left) && orientation == Orientation.Horizontal)
                    return true;
            }

            if (blockX.SlopeType == SlopeType.Up26High && blockY.SlopeType == SlopeType.Up26Low && orientation == Orientation.Horizontal)
                return true;
            if (blockX.SlopeType == SlopeType.Down26Low && blockY.SlopeType == SlopeType.Down26High && orientation == Orientation.Horizontal)
                return true;
            if (blockX.SlopeType == SlopeType.Left26High && blockY.SlopeType == SlopeType.Left26Low && orientation == Orientation.Vertical)
                return true;
            if (blockX.SlopeType == SlopeType.Right26Low && blockY.SlopeType == SlopeType.Right26High && orientation == Orientation.Vertical)
                return true;

            //Up
            if (blockX.SlopeType == SlopeType.Up7High0 && blockY.SlopeType == SlopeType.Up7Low && orientation == Orientation.Horizontal)
                return true;
            if (blockX.SlopeType == SlopeType.Up7High1 && blockY.SlopeType == SlopeType.Up7High0 && orientation == Orientation.Horizontal)
                return true;
            if (blockX.SlopeType == SlopeType.Up7High2 && blockY.SlopeType == SlopeType.Up7High1 && orientation == Orientation.Horizontal)
                return true;
            if (blockX.SlopeType == SlopeType.Up7High3 && blockY.SlopeType == SlopeType.Up7High2 && orientation == Orientation.Horizontal)
                return true;
            if (blockX.SlopeType == SlopeType.Up7High4 && blockY.SlopeType == SlopeType.Up7High3 && orientation == Orientation.Horizontal)
                return true;
            if (blockX.SlopeType == SlopeType.Up7High5 && blockY.SlopeType == SlopeType.Up7High4 && orientation == Orientation.Horizontal)
                return true;
            if (blockX.SlopeType == SlopeType.Up7High6 && blockY.SlopeType == SlopeType.Up7High5 && orientation == Orientation.Horizontal)
                return true;

            //Down
            if (blockX.SlopeType == SlopeType.Down7Low && blockY.SlopeType == SlopeType.Down7High0 && orientation == Orientation.Horizontal)
                return true;
            if (blockX.SlopeType == SlopeType.Down7High0 && blockY.SlopeType == SlopeType.Down7High1 && orientation == Orientation.Horizontal)
                return true;
            if (blockX.SlopeType == SlopeType.Down7High1 && blockY.SlopeType == SlopeType.Down7High2 && orientation == Orientation.Horizontal)
                return true;
            if (blockX.SlopeType == SlopeType.Down7High2 && blockY.SlopeType == SlopeType.Down7High3 && orientation == Orientation.Horizontal)
                return true;
            if (blockX.SlopeType == SlopeType.Down7High3 && blockY.SlopeType == SlopeType.Down7High4 && orientation == Orientation.Horizontal)
                return true;
            if (blockX.SlopeType == SlopeType.Down7High4 && blockY.SlopeType == SlopeType.Down7High5 && orientation == Orientation.Horizontal)
                return true;
            if (blockX.SlopeType == SlopeType.Down7High5 && blockY.SlopeType == SlopeType.Down7High6 && orientation == Orientation.Horizontal)
                return true;

            //Left
            if (blockX.SlopeType == SlopeType.Left7High0 && blockY.SlopeType == SlopeType.Left7Low && orientation == Orientation.Vertical)
                return true;
            if (blockX.SlopeType == SlopeType.Left7High1 && blockY.SlopeType == SlopeType.Left7High0 && orientation == Orientation.Vertical)
                return true;
            if (blockX.SlopeType == SlopeType.Left7High2 && blockY.SlopeType == SlopeType.Left7High1 && orientation == Orientation.Vertical)
                return true;
            if (blockX.SlopeType == SlopeType.Left7High3 && blockY.SlopeType == SlopeType.Left7High2 && orientation == Orientation.Vertical)
                return true;
            if (blockX.SlopeType == SlopeType.Left7High4 && blockY.SlopeType == SlopeType.Left7High3 && orientation == Orientation.Vertical)
                return true;
            if (blockX.SlopeType == SlopeType.Left7High5 && blockY.SlopeType == SlopeType.Left7High4 && orientation == Orientation.Vertical)
                return true;
            if (blockX.SlopeType == SlopeType.Left7High6 && blockY.SlopeType == SlopeType.Left7High5 && orientation == Orientation.Vertical)
                return true;

            //Right
            if (blockX.SlopeType == SlopeType.Right7Low && blockY.SlopeType == SlopeType.Right7High0 && orientation == Orientation.Vertical)
                return true;
            if (blockX.SlopeType == SlopeType.Right7High0 && blockY.SlopeType == SlopeType.Right7High1 && orientation == Orientation.Vertical)
                return true;
            if (blockX.SlopeType == SlopeType.Right7High1 && blockY.SlopeType == SlopeType.Right7High2 && orientation == Orientation.Vertical)
                return true;
            if (blockX.SlopeType == SlopeType.Right7High2 && blockY.SlopeType == SlopeType.Right7High3 && orientation == Orientation.Vertical)
                return true;
            if (blockX.SlopeType == SlopeType.Right7High3 && blockY.SlopeType == SlopeType.Right7High4 && orientation == Orientation.Vertical)
                return true;
            if (blockX.SlopeType == SlopeType.Right7High4 && blockY.SlopeType == SlopeType.Right7High5 && orientation == Orientation.Vertical)
                return true;
            if (blockX.SlopeType == SlopeType.Right7High5 && blockY.SlopeType == SlopeType.Right7High6 && orientation == Orientation.Vertical)
                return true;

            if (blockX.SlopeType == SlopeType.Up45 && blockY.SlopeType == SlopeType.Down45 && orientation == Orientation.Horizontal)
                return true;
            if (blockX.SlopeType == SlopeType.Down45 && blockY.SlopeType == SlopeType.Up45 && orientation == Orientation.Horizontal)
                return true;

            if (blockX.SlopeType == SlopeType.Left45 && blockY.SlopeType == SlopeType.Right45 && orientation == Orientation.Vertical)
                return true;
            if (blockX.SlopeType == SlopeType.Right45 && blockY.SlopeType == SlopeType.Left45 && orientation == Orientation.Vertical)
                return true;

            return false;
        }
Example #6
0
 private static void AddBlockLines(IDictionary<Block, List<LineSegment>> blockLines, Block block, LineSegment intersectionLine)
 {
     if (block == null)
         return;
     List<LineSegment> blockLineSegments;
     if (blockLines.TryGetValue(block, out blockLineSegments))
     {
         blockLineSegments.Add(intersectionLine);
     }
     else
     {
         blockLineSegments = new List<LineSegment> {intersectionLine};
         blockLines.Add(block, blockLineSegments);
     }
 }
Example #7
0
 private void CreateUncompressedMap(uint[,] baseOffsets, uint[] columns, Block[] blocks)
 {
     for (var i = 0; i < 256; i++)
     {
         for (var j = 0; j < 256; j++)
         {
             var columnIndex = baseOffsets[j,i];
             var height = columns[columnIndex] & 0xFF;
             var offset = (columns[columnIndex] & 0xFF00) >> 8;
             for (var k = 0; k < height; k++)
             {
                 if (k >= offset)
                 {
                     cityBlocks[i, j, k] = blocks[columns[columnIndex + k - offset + 1]].DeepCopy();
                     cityBlocks[i, j, k].Position = new Vector3(i, j, k);
                 }
             }
         }
     }
 }
Example #8
0
 private void ReadDMAP(BinaryReader reader)
 {
     var baseOffsets = new uint[256, 256];
     for (var i = 0; i < 256; i++)
     {
         for (var j = 0; j < 256; j++)
             baseOffsets[i,j] = reader.ReadUInt32();
     }
     var columnCount = reader.ReadUInt32();
     var columns = new uint[columnCount];
     for (var i = 0; i < columnCount; i++)
         columns[i] = reader.ReadUInt32();
     var blockCount = reader.ReadUInt32();
     var blocks = new Block[blockCount];
     for (var i = 0; i < blockCount; i++)
     {
         BlockStructure blockStructure;
         blockStructure.Left = reader.ReadUInt16();
         blockStructure.Right = reader.ReadUInt16();
         blockStructure.Top = reader.ReadUInt16();
         blockStructure.Bottom = reader.ReadUInt16();
         blockStructure.Lid = reader.ReadUInt16();
         blockStructure.Arrows = reader.ReadByte();
         blockStructure.SlopeType = reader.ReadByte();
         Block block = BlockFactory.Build(blockStructure, Vector3.One);
         blocks[i] = block;
     }
     CreateUncompressedMap(baseOffsets, columns, blocks);
 }