Ejemplo n.º 1
0
        public static void doBorders(GameMap map, Tile tile)
        {
            //Console.WriteLine("------------------------------");
            GroundBrush border_brush = tile.getGroundBrush();

            int x = tile.Position.X;
            int y = tile.Position.Y;
            int z = tile.Position.Z;

            Pair <Boolean, GroundBrush>[] neighbours = new Pair <bool, GroundBrush> [8];

            if (x == 0)
            {
                if (y == 0)
                {
                    neighbours[0] = new Pair <bool, GroundBrush>(false, null);
                    neighbours[1] = new Pair <bool, GroundBrush>(false, null);
                    neighbours[2] = new Pair <bool, GroundBrush>(false, null);
                    neighbours[3] = new Pair <bool, GroundBrush>(false, null);
                    neighbours[4] = new Pair <bool, GroundBrush>(false, extractGroundBrushFromTile(map, x + 1, y, z));
                    neighbours[5] = new Pair <bool, GroundBrush>(false, null);
                    neighbours[6] = new Pair <bool, GroundBrush>(false, extractGroundBrushFromTile(map, x, y + 1, z));
                    neighbours[7] = new Pair <bool, GroundBrush>(false, extractGroundBrushFromTile(map, x + 1, y + 1, z));
                }
                else
                {
                    neighbours[0] = new Pair <bool, GroundBrush>(false, null);
                    neighbours[1] = new Pair <bool, GroundBrush>(false, extractGroundBrushFromTile(map, x, y - 1, z));
                    neighbours[2] = new Pair <bool, GroundBrush>(false, extractGroundBrushFromTile(map, x + 1, y - 1, z));
                    neighbours[3] = new Pair <bool, GroundBrush>(false, null);
                    neighbours[4] = new Pair <bool, GroundBrush>(false, extractGroundBrushFromTile(map, x + 1, y, z));
                    neighbours[5] = new Pair <bool, GroundBrush>(false, null);
                    neighbours[6] = new Pair <bool, GroundBrush>(false, extractGroundBrushFromTile(map, x, y + 1, z));
                    neighbours[7] = new Pair <bool, GroundBrush>(false, extractGroundBrushFromTile(map, x + 1, y + 1, z));
                }
            }
            else if (y == 0)
            {
                neighbours[0] = new Pair <bool, GroundBrush>(false, null);
                neighbours[1] = new Pair <bool, GroundBrush>(false, null);
                neighbours[2] = new Pair <bool, GroundBrush>(false, null);
                neighbours[3] = new Pair <bool, GroundBrush>(false, extractGroundBrushFromTile(map, x - 1, y, z));
                neighbours[4] = new Pair <bool, GroundBrush>(false, extractGroundBrushFromTile(map, x + 1, y, z));
                neighbours[5] = new Pair <bool, GroundBrush>(false, extractGroundBrushFromTile(map, x - 1, y + 1, z));
                neighbours[6] = new Pair <bool, GroundBrush>(false, extractGroundBrushFromTile(map, x, y + 1, z));
                neighbours[7] = new Pair <bool, GroundBrush>(false, extractGroundBrushFromTile(map, x + 1, y + 1, z));
            }
            else
            {
                neighbours[0] = new Pair <bool, GroundBrush>(false, extractGroundBrushFromTile(map, x - 1, y - 1, z));
                neighbours[1] = new Pair <bool, GroundBrush>(false, extractGroundBrushFromTile(map, x, y - 1, z));
                neighbours[2] = new Pair <bool, GroundBrush>(false, extractGroundBrushFromTile(map, x + 1, y - 1, z));
                neighbours[3] = new Pair <bool, GroundBrush>(false, extractGroundBrushFromTile(map, x - 1, y, z));
                neighbours[4] = new Pair <bool, GroundBrush>(false, extractGroundBrushFromTile(map, x + 1, y, z));
                neighbours[5] = new Pair <bool, GroundBrush>(false, extractGroundBrushFromTile(map, x - 1, y + 1, z));
                neighbours[6] = new Pair <bool, GroundBrush>(false, extractGroundBrushFromTile(map, x, y + 1, z));
                neighbours[7] = new Pair <bool, GroundBrush>(false, extractGroundBrushFromTile(map, x + 1, y + 1, z));
            }

            List <BorderCluster> border_list = new List <BorderCluster>();

            specific_list.Clear();

            for (int i = 0; i < 8; i++)
            {
                if (neighbours[i].first)
                {
                    continue;
                }
                GroundBrush other = neighbours[i].second;
                if (border_brush != null)
                {
                    if (other != null)
                    {
                        if (other.getID() == border_brush.getID())
                        {
                            continue;
                        }
                        if (other.hasOuterBorder() || border_brush.hasInnerBorder())
                        {
                            bool only_mountain = false;
                            if ((other.friendOf(border_brush) || border_brush.friendOf(other)))
                            {
                                if (other.hasOptionalBorder())
                                {
                                    only_mountain = true;
                                }
                                else
                                {
                                    continue;
                                }
                            }

                            UInt32 tiledata = 0;
                            for (int j = i; j < 8; j++)
                            {
                                if (!neighbours[j].first && (neighbours[j].second != null) && neighbours[j].second.getID() == other.getID())
                                {
                                    neighbours[j].first = true;
                                    tiledata           |= Convert.ToUInt32(1) << j;
                                }
                            }

                            if (tiledata != 0)
                            {
                                if (other.hasOptionalBorder() && tile.hasOptionalBorder())
                                {
                                    BorderCluster cluster = new BorderCluster();
                                    cluster.alignment = tiledata;
                                    cluster.z         = 0x7FFFFFFF; // Above all other borders
                                    //cluster.z = 0;

                                    cluster.border = other.optional_border;
                                    //Console.WriteLine("Aqui 01");
                                    border_list.Add(cluster);
                                    if (other.useSoloOptionalBorder())
                                    {
                                        only_mountain = true;
                                    }
                                }
                                if (!only_mountain)
                                {
                                    BorderBlock bb = getBrushTo(border_brush, other);
                                    if (bb != null)
                                    {
                                        bool found = false;

                                        foreach (BorderCluster bc in border_list)
                                        {
                                            if (bc.border.Equals(bb.autoborder))
                                            {
                                                bc.alignment |= tiledata;
                                                if (bc.z < other.getZ())
                                                {
                                                    bc.z = other.getZ();
                                                }
                                                if (bb.specific_cases.Count() > 0)
                                                {
                                                    if (!specific_list.Contains(bb))
                                                    {
                                                        specific_list.Add(bb);
                                                    }
                                                }
                                                found = true;
                                                break;
                                            }
                                        }
                                        if (!found)
                                        {
                                            BorderCluster bc = new BorderCluster();
                                            bc.alignment = tiledata;
                                            bc.z         = other.getZ();
                                            bc.border    = bb.autoborder;
                                            //Console.WriteLine("Aqui 02");
                                            border_list.Add(bc);
                                            if (bb.specific_cases.Count() > 0)
                                            {
                                                if (!specific_list.Contains(bb))
                                                {
                                                    specific_list.Add(bb);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    else if (border_brush.hasInnerZilchBorder())
                    {
                        UInt32 tiledata = 0;
                        for (int j = i; j < 8; j++)
                        {
                            if (neighbours[j].first == false && neighbours[j].second == null)
                            {
                                neighbours[j].first = true;
                                tiledata           |= Convert.ToUInt32(1) << j;
                            }
                        }
                        if (tiledata != 0)
                        {
                            BorderCluster cluster = new BorderCluster();
                            cluster.alignment = tiledata;
                            cluster.z         = 5000;
                            BorderBlock bb = getBrushTo(border_brush, null);
                            if (bb == null)
                            {
                                continue;
                            }
                            cluster.border = bb.autoborder;
                            if (cluster.border != null)
                            {
                                //Console.WriteLine("Aqui 03");
                                border_list.Add(cluster);
                            }
                            if (bb.specific_cases.Count() > 0)
                            {
                                if (!specific_list.Contains(bb))
                                {
                                    specific_list.Add(bb);
                                }
                            }
                        }
                        continue;
                    }
                }
                else if (other != null && other.hasOuterZilchBorder())
                {
                    UInt32 tiledata = 0;
                    for (int j = i; j < 8; j++)
                    {
                        if (neighbours[j].first == false && (neighbours[j].second != null) && neighbours[j].second.getID() == other.getID())
                        {
                            neighbours[j].first = true;
                            tiledata           |= Convert.ToUInt32(1) << j;
                        }
                    }
                    if (tiledata != 0)
                    {
                        BorderCluster cluster = new BorderCluster();
                        cluster.alignment = tiledata;
                        cluster.z         = other.getZ();
                        BorderBlock bb = getBrushTo(null, other);
                        if (bb != null)
                        {
                            cluster.border = bb.autoborder;
                            if (cluster.border != null)
                            {
                                //Console.WriteLine("where 04 - " + i);
                                border_list.Add(cluster);
                            }
                            if (bb.specific_cases.Count() > 0)
                            {
                                if (!specific_list.Contains(bb))
                                {
                                    specific_list.Add(bb);
                                }
                            }
                        }
                        if (other.hasOptionalBorder() && tile.hasOptionalBorder())
                        {
                            BorderCluster _cluster = new BorderCluster();
                            _cluster.alignment = tiledata;
                            _cluster.z         = 0x7FFFFFFF; // Above other zilch borders
                            // _cluster.z = 0;
                            _cluster.border = other.optional_border;
                            //Console.WriteLine("Aqui 05");
                            border_list.Add(_cluster);
                        }
                        else
                        {
                            tile.setOptionalBorder(false);
                        }
                    }
                }
                neighbours[i].first = true;
            }
            tile.clearBorders();
            //Messages.AddLogMessage("Quantidade de border list: " + border_list.Count);

            //people.OrderBy(x => x.LastName).ToList();

            border_list = border_list.OrderByDescending(item => item.z).ToList();

            while (border_list.Count > 0)
            {
                //BorderCluster cluster = border_list.Last();

                BorderCluster cluster = border_list.First();

                if (cluster.border == null)
                {
                    border_list.Remove(cluster);
                    continue;
                }

                //Console.WriteLine("id: " + cluster.border.Id + " alignment: " + cluster.alignment);
                long[] i = new long[4];
                i[0] = ((Border_Types.border_types[cluster.alignment] & 0x000000FF) >> 0);
                i[1] = ((Border_Types.border_types[cluster.alignment] & 0x0000FF00) >> 8);
                i[2] = ((Border_Types.border_types[cluster.alignment] & 0x00FF0000) >> 16);
                i[3] = ((Border_Types.border_types[cluster.alignment] & 0xFF000000) >> 24);

                for (int iter = 0; iter < 4; ++iter)
                {
                    if (i[iter] != 0)
                    {
                        if (cluster.border.tiles[i[iter]] != 0)
                        {
                            tile.addBorderItem(Item.Create(cluster.border.tiles[i[iter]]));
                        }
                        else
                        {
                            if (i[iter] == BorderType.NORTHWEST_DIAGONAL)
                            {
                                tile.addBorderItem(Item.Create(cluster.border.tiles[BorderType.WEST_HORIZONTAL]));
                                tile.addBorderItem(Item.Create(cluster.border.tiles[BorderType.NORTH_HORIZONTAL]));
                            }
                            else if (i[iter] == BorderType.NORTHEAST_DIAGONAL)
                            {
                                tile.addBorderItem(Item.Create(cluster.border.tiles[BorderType.EAST_HORIZONTAL]));
                                tile.addBorderItem(Item.Create(cluster.border.tiles[BorderType.NORTH_HORIZONTAL]));
                            }
                            else if (i[iter] == BorderType.SOUTHWEST_DIAGONAL)
                            {
                                tile.addBorderItem(Item.Create(cluster.border.tiles[BorderType.SOUTH_HORIZONTAL]));
                                tile.addBorderItem(Item.Create(cluster.border.tiles[BorderType.WEST_HORIZONTAL]));
                            }
                            else if (i[iter] == BorderType.SOUTHEAST_DIAGONAL)
                            {
                                tile.addBorderItem(Item.Create(cluster.border.tiles[BorderType.SOUTH_HORIZONTAL]));
                                tile.addBorderItem(Item.Create(cluster.border.tiles[BorderType.EAST_HORIZONTAL]));
                            }
                        }
                    }
                    else
                    {
                        break;
                    }
                }
                border_list.Remove(cluster);
            }
            if (specific_list.Count > 1)
            {
                // Global.mapCanvas.drawing = false;
                //  MessageBox.Show("Tem especifico");
            }
        }
Ejemplo n.º 2
0
 public static BorderBlock getBrushTo(GroundBrush first, GroundBrush second)
 {
     if (first != null)
     {
         if (second != null)
         {
             //Console.WriteLine("Aqui ninguem é nulo");
             if (first.getZ() < second.getZ() && second.hasOuterBorder())
             {
                 //Console.WriteLine("getBrushTo 01");
                 if (first.hasInnerBorder())
                 {
                     //Console.WriteLine("getBrushTo 02");
                     foreach (BorderBlock bb in first.borders)
                     {
                         //Console.WriteLine("getBrushTo 03");
                         if (bb.outer == true)
                         {
                             continue;
                         }
                         else if (bb.to == second.getID() || bb.to == 0xFFFFFFFF)
                         {
                             return(bb);
                         }
                     }
                 }
                 //Console.WriteLine("getBrushTo 04");
                 foreach (BorderBlock bb in second.borders)
                 {
                     //Console.WriteLine("getBrushTo 05");
                     if (!bb.outer)
                     {
                         continue;
                     }
                     else if (bb.to == first.getID())
                     {
                         //Console.WriteLine("getBrushTo 05 1");
                         return(bb);
                     }
                     else if (bb.to == 0xFFFFFFFF)
                     {
                         //Console.WriteLine("getBrushTo 05 2");
                         return(bb);
                     }
                 }
             }
             else if (first.hasInnerBorder())
             {
                 //Console.WriteLine("getBrushTo 06");
                 foreach (BorderBlock bb in first.borders)
                 {
                     //Console.WriteLine("getBrushTo 07");
                     if (bb.outer == true)
                     {
                         continue;
                     }
                     else if (bb.to == second.getID())
                     {
                         return(bb);
                     }
                     else if (bb.to == 0xFFFFFFFF)
                     {
                         return(bb);
                     }
                 }
             }
         }
         else if (first.hasInnerZilchBorder())
         {
             {
                 foreach (BorderBlock bb in first.borders)
                 {
                     if (bb.outer == true)
                     {
                         continue;
                     }
                     else if (bb.to == 0)
                     {
                         return(bb);
                     }
                 }
             }
         }
     }
     else if (second != null && second.hasOuterZilchBorder())
     {
         foreach (BorderBlock bb in second.borders)
         {
             if (bb.outer == false)
             {
                 continue;
             }
             else if (bb.to == 0)
             {
                 return(bb);
             }
         }
     }
     return(null);
 }