private void CheckTileTexture(Tile tile, out List<Texture2D> decorativeTextures)
        {
            decorativeTextures = null;
            TerrainDetail terrainDetailByPositionNoCheck = this.screen.Scenario.GetTerrainDetailByPositionNoCheck(tile.Position);
            if (terrainDetailByPositionNoCheck.Textures != null && terrainDetailByPositionNoCheck.Textures.BasicTextures.Count != 0)
            {
                int i;
                List<int> list;
                int num12;
                for (i = 0; i < this.TerrainList.Count; i++)
                {
                    this.TerrainList[i] = 0;
                }
                TerrainDirection direction = TerrainDirection.None;
                int num2 = 0;

                Point position = new Point(tile.Position.X - 1, tile.Position.Y);
                int leftId = 0;
                TerrainDetail leftDetail = null;
                if (!this.screen.Scenario.PositionOutOfRange(position))
                {
                    leftDetail = this.screen.Scenario.GetTerrainDetailByPositionNoCheck(position);
                    leftId = leftDetail.ID;
                    //(list = this.TerrainList)[num12 = this.mainMap.MapData[position.X, position.Y]] = list[num12] + 1;
                }
                Point point2 = new Point(tile.Position.X - 1, tile.Position.Y - 1);
                int topLeftId = 0;
                if (!this.screen.Scenario.PositionOutOfRange(point2))
                {
                    topLeftId = this.screen.Scenario.GetTerrainDetailByPositionNoCheck(point2).ID;
                    //(list = this.TerrainList)[num12 = this.mainMap.MapData[point2.X, point2.Y]] = list[num12] + 1;
                }
                Point point3 = new Point(tile.Position.X, tile.Position.Y - 1);
                int topId = 0;
                TerrainDetail top = null;
                if (!this.screen.Scenario.PositionOutOfRange(point3))
                {
                    top = this.screen.Scenario.GetTerrainDetailByPositionNoCheck(point3);
                    topId = top.ID;
                }
                Point point4 = new Point(tile.Position.X + 1, tile.Position.Y - 1);
                int topRightId = 0;
                if (!this.screen.Scenario.PositionOutOfRange(point4))
                {
                    topRightId = this.screen.Scenario.GetTerrainDetailByPositionNoCheck(point4).ID;
                }
                Point point5 = new Point(tile.Position.X + 1, tile.Position.Y);
                int rightId = 0;
                TerrainDetail right = null;
                if (!this.screen.Scenario.PositionOutOfRange(point5))
                {
                    right = this.screen.Scenario.GetTerrainDetailByPositionNoCheck(point5);
                    rightId = right.ID;
                }
                Point point6 = new Point(tile.Position.X + 1, tile.Position.Y + 1);
                int bottomRightId = 0;
                if (!this.screen.Scenario.PositionOutOfRange(point6))
                {
                    bottomRightId = this.screen.Scenario.GetTerrainDetailByPositionNoCheck(point6).ID;
                }
                Point point7 = new Point(tile.Position.X, tile.Position.Y + 1);
                int bottomId = 0;
                TerrainDetail bottom = null;
                if (!this.screen.Scenario.PositionOutOfRange(point7))
                {
                    bottom = this.screen.Scenario.GetTerrainDetailByPositionNoCheck(point7);
                    bottomId = bottom.ID;
                }
                Point point8 = new Point(tile.Position.X - 1, tile.Position.Y + 1);
                int bottomLeftId = 0;
                if (!this.screen.Scenario.PositionOutOfRange(point8))
                {
                    bottomLeftId = this.screen.Scenario.GetTerrainDetailByPositionNoCheck(point8).ID;
                }

                int equalTerrainCnt = 0;
                if ((leftId > 0) && (leftId == terrainDetailByPositionNoCheck.ID))
                {
                    equalTerrainCnt++;
                }
                if ((topId > 0) && (topId == terrainDetailByPositionNoCheck.ID))
                {
                    equalTerrainCnt++;
                }
                if ((rightId > 0) && (rightId == terrainDetailByPositionNoCheck.ID))
                {
                    equalTerrainCnt++;
                }
                if ((bottomId > 0) && (bottomId == terrainDetailByPositionNoCheck.ID))
                {
                    equalTerrainCnt++;
                }

                if (equalTerrainCnt < 4)
                {
                    if (top != null)
                    {
                        (list = this.TerrainList)[num12 = this.mainMap.MapData[point3.X, point3.Y]] = list[num12] + 1;
                        for (i = 0; i < this.TerrainList.Count; i++)
                        {
                            if ((i != terrainDetailByPositionNoCheck.ID) && ((((this.TerrainList[i] >= 2) && (leftId == i)) && (topLeftId != terrainDetailByPositionNoCheck.ID)) && (topId == i)))
                            {
                                direction = TerrainDirection.TopLeft;
                                num2 = i;
                                break;
                            }
                        }
                    }
                    if (topRightId > 0)
                    {
                        (list = this.TerrainList)[num12 = this.mainMap.MapData[point4.X, point4.Y]] = list[num12] + 1;
                    }
                    if (rightId > 0)
                    {
                        (list = this.TerrainList)[num12 = this.mainMap.MapData[point5.X, point5.Y]] = list[num12] + 1;
                        for (i = 0; i < this.TerrainList.Count; i++)
                        {
                            if (i != terrainDetailByPositionNoCheck.ID)
                            {
                                if (((direction == TerrainDirection.None) && (this.TerrainList[i] >= 2)) && (((topId == i) && (topRightId != terrainDetailByPositionNoCheck.ID)) && (rightId == i)))
                                {
                                    direction = TerrainDirection.TopRight;
                                    num2 = i;
                                }
                                if (this.TerrainList[i] >= 3)
                                {
                                    if ((((leftId == i) && (topId == i)) && ((rightId == i) && (topRightId != terrainDetailByPositionNoCheck.ID))) && (topLeftId != terrainDetailByPositionNoCheck.ID))
                                    {
                                        direction = TerrainDirection.Top;
                                        num2 = i;
                                    }
                                    break;
                                }
                            }
                        }
                    }
                    if (bottomRightId > 0)
                    {
                        (list = this.TerrainList)[num12 = this.mainMap.MapData[point6.X, point6.Y]] = list[num12] + 1;
                    }
                    if (bottomId > 0)
                    {
                        (list = this.TerrainList)[num12 = this.mainMap.MapData[point7.X, point7.Y]] = list[num12] + 1;
                        for (i = 0; i < this.TerrainList.Count; i++)
                        {
                            if (i != terrainDetailByPositionNoCheck.ID)
                            {
                                if (((direction == TerrainDirection.None) && (this.TerrainList[i] >= 2)) && (((rightId == i) && (bottomRightId != terrainDetailByPositionNoCheck.ID)) && (bottomId == i)))
                                {
                                    direction = TerrainDirection.BottomRight;
                                    num2 = i;
                                }
                                if ((this.TerrainList[i] >= 3) && ((((topId == i) && (rightId == i)) && ((bottomId == i) && (topRightId != terrainDetailByPositionNoCheck.ID))) && (bottomRightId != terrainDetailByPositionNoCheck.ID)))
                                {
                                    direction = TerrainDirection.Right;
                                    num2 = i;
                                }
                            }
                        }
                    }
                    if (bottomLeftId > 0)
                    {
                        (list = this.TerrainList)[num12 = this.mainMap.MapData[point8.X, point8.Y]] = list[num12] + 1;
                    }
                    if (leftId > 0)
                    {
                        for (i = 0; i < this.TerrainList.Count; i++)
                        {
                            if (i != terrainDetailByPositionNoCheck.ID)
                            {
                                if (((direction == TerrainDirection.None) && (this.TerrainList[i] >= 2)) && (((bottomId == i) && (bottomLeftId != terrainDetailByPositionNoCheck.ID)) && (leftId == i)))
                                {
                                    direction = TerrainDirection.BottomLeft;
                                    num2 = i;
                                }
                                if ((this.TerrainList[i] >= 3) && ((((rightId == i) && (bottomId == i)) && ((leftId == i) && (bottomRightId != terrainDetailByPositionNoCheck.ID))) && (bottomLeftId != terrainDetailByPositionNoCheck.ID)))
                                {
                                    direction = TerrainDirection.Bottom;
                                    num2 = i;
                                }
                                if (((((this.TerrainList[i] >= 4) && (leftId == i)) && ((topId == i) && (rightId == i))) && (bottomId == i)) && ((((topLeftId != terrainDetailByPositionNoCheck.ID) && (topRightId != terrainDetailByPositionNoCheck.ID)) && ((bottomRightId != terrainDetailByPositionNoCheck.ID) && (bottomLeftId != terrainDetailByPositionNoCheck.ID))) || (this.TerrainList[i] >= 7)))
                                {
                                    direction = TerrainDirection.Centre;
                                    num2 = i;
                                    break;
                                }
                            }
                        }
                    }
                    if ((((direction != TerrainDirection.Centre) && (direction != TerrainDirection.Top)) && ((direction != TerrainDirection.Right) && (direction != TerrainDirection.Bottom))) && (topId > 0))
                    {
                        for (i = 0; i < this.TerrainList.Count; i++)
                        {
                            if (((i != terrainDetailByPositionNoCheck.ID) && (this.TerrainList[i] >= 3)) && ((((bottomId == i) && (leftId == i)) && ((topId == i) && (bottomLeftId != terrainDetailByPositionNoCheck.ID))) && (topLeftId != terrainDetailByPositionNoCheck.ID)))
                            {
                                direction = TerrainDirection.Left;
                                num2 = i;
                            }
                        }
                    }
                    decorativeTextures = new List<Texture2D>();
                    switch (direction)
                    {
                        case TerrainDirection.Top:
                            decorativeTextures.Add(top.Textures.TopTextures[((tile.Position.X * 7) + (tile.Position.Y * 11)) % top.Textures.TopTextures.Count]);
                            if ((((bottom != null) && (bottom.ID != terrainDetailByPositionNoCheck.ID)) && ((bottomRightId != terrainDetailByPositionNoCheck.ID) && (bottomLeftId != terrainDetailByPositionNoCheck.ID))) && (bottom.GraphicLayer < terrainDetailByPositionNoCheck.GraphicLayer))
                            {
                                decorativeTextures.Add(bottom.Textures.BottomEdgeTextures[((tile.Position.X * 7) + (tile.Position.Y * 11)) % bottom.Textures.BottomEdgeTextures.Count]);
                            }
                            return;

                        case TerrainDirection.Left:
                            decorativeTextures.Add(leftDetail.Textures.LeftTextures[((tile.Position.X * 7) + (tile.Position.Y * 11)) % leftDetail.Textures.LeftTextures.Count]);
                            if ((((right != null) && (right.ID != terrainDetailByPositionNoCheck.ID)) && ((topRightId != terrainDetailByPositionNoCheck.ID) && (bottomRightId != terrainDetailByPositionNoCheck.ID))) && (right.GraphicLayer < terrainDetailByPositionNoCheck.GraphicLayer))
                            {
                                decorativeTextures.Add(right.Textures.RightEdgeTextures[((tile.Position.X * 7) + (tile.Position.Y * 11)) % right.Textures.RightEdgeTextures.Count]);
                            }
                            return;

                        case TerrainDirection.Right:
                            decorativeTextures.Add(right.Textures.RightTextures[((tile.Position.X * 7) + (tile.Position.Y * 11)) % right.Textures.RightTextures.Count]);
                            if ((((leftDetail != null) && (leftDetail.ID != terrainDetailByPositionNoCheck.ID)) && ((bottomLeftId != terrainDetailByPositionNoCheck.ID) && (topLeftId != terrainDetailByPositionNoCheck.ID))) && (leftDetail.GraphicLayer < terrainDetailByPositionNoCheck.GraphicLayer))
                            {
                                decorativeTextures.Add(leftDetail.Textures.LeftEdgeTextures[((tile.Position.X * 7) + (tile.Position.Y * 11)) % leftDetail.Textures.LeftEdgeTextures.Count]);
                            }
                            return;

                        case TerrainDirection.Bottom:
                            decorativeTextures.Add(bottom.Textures.BottomTextures[((tile.Position.X * 7) + (tile.Position.Y * 11)) % bottom.Textures.BottomTextures.Count]);
                            if ((((top != null) && (top.ID != terrainDetailByPositionNoCheck.ID)) && ((topLeftId != terrainDetailByPositionNoCheck.ID) && (topRightId != terrainDetailByPositionNoCheck.ID))) && (top.GraphicLayer < terrainDetailByPositionNoCheck.GraphicLayer))
                            {
                                decorativeTextures.Add(top.Textures.TopEdgeTextures[((tile.Position.X * 7) + (tile.Position.Y * 11)) % top.Textures.TopEdgeTextures.Count]);
                            }
                            return;

                        case TerrainDirection.TopLeft:
                            decorativeTextures.Add(leftDetail.Textures.TopLeftCornerTextures[((tile.Position.X * 7) + (tile.Position.Y * 11)) % leftDetail.Textures.TopLeftCornerTextures.Count]);
                            if ((((right == null) || (terrainDetailByPositionNoCheck.ID == bottomRightId)) || (rightId != bottomId)) || (terrainDetailByPositionNoCheck.ID == rightId))
                            {
                                if ((((right != null) && (right.ID != terrainDetailByPositionNoCheck.ID)) && ((topRightId != terrainDetailByPositionNoCheck.ID) && (bottomRightId != terrainDetailByPositionNoCheck.ID))) && (right.GraphicLayer < terrainDetailByPositionNoCheck.GraphicLayer))
                                {
                                    decorativeTextures.Add(right.Textures.RightEdgeTextures[((tile.Position.X * 7) + (tile.Position.Y * 11)) % right.Textures.RightEdgeTextures.Count]);
                                }
                                if ((((bottom != null) && (bottom.ID != terrainDetailByPositionNoCheck.ID)) && ((bottomRightId != terrainDetailByPositionNoCheck.ID) && (bottomLeftId != terrainDetailByPositionNoCheck.ID))) && (bottom.GraphicLayer < terrainDetailByPositionNoCheck.GraphicLayer))
                                {
                                    decorativeTextures.Add(bottom.Textures.BottomEdgeTextures[((tile.Position.X * 7) + (tile.Position.Y * 11)) % bottom.Textures.BottomEdgeTextures.Count]);
                                }
                                return;
                            }
                            decorativeTextures.Add(right.Textures.BottomRightCornerTextures[((tile.Position.X * 7) + (tile.Position.Y * 11)) % right.Textures.BottomRightCornerTextures.Count]);
                            return;

                        case TerrainDirection.TopRight:
                            decorativeTextures.Add(top.Textures.TopRightCornerTextures[((tile.Position.X * 7) + (tile.Position.Y * 11)) % top.Textures.TopRightCornerTextures.Count]);
                            if ((((bottom == null) || (terrainDetailByPositionNoCheck.ID == bottomLeftId)) || (bottomId != leftId)) || (terrainDetailByPositionNoCheck.ID == bottomId))
                            {
                                if ((((leftDetail != null) && (leftDetail.ID != terrainDetailByPositionNoCheck.ID)) && ((bottomLeftId != terrainDetailByPositionNoCheck.ID) && (topLeftId != terrainDetailByPositionNoCheck.ID))) && (leftDetail.GraphicLayer < terrainDetailByPositionNoCheck.GraphicLayer))
                                {
                                    decorativeTextures.Add(leftDetail.Textures.LeftEdgeTextures[((tile.Position.X * 7) + (tile.Position.Y * 11)) % leftDetail.Textures.LeftEdgeTextures.Count]);
                                }
                                if ((((bottom != null) && (bottom.ID != terrainDetailByPositionNoCheck.ID)) && ((bottomRightId != terrainDetailByPositionNoCheck.ID) && (bottomLeftId != terrainDetailByPositionNoCheck.ID))) && (bottom.GraphicLayer < terrainDetailByPositionNoCheck.GraphicLayer))
                                {
                                    decorativeTextures.Add(bottom.Textures.BottomEdgeTextures[((tile.Position.X * 7) + (tile.Position.Y * 11)) % bottom.Textures.BottomEdgeTextures.Count]);
                                }
                                return;
                            }
                            decorativeTextures.Add(bottom.Textures.BottomLeftCornerTextures[((tile.Position.X * 7) + (tile.Position.Y * 11)) % bottom.Textures.BottomLeftCornerTextures.Count]);
                            return;

                        case TerrainDirection.BottomLeft:
                            decorativeTextures.Add(bottom.Textures.BottomLeftCornerTextures[((tile.Position.X * 7) + (tile.Position.Y * 11)) % bottom.Textures.BottomLeftCornerTextures.Count]);
                            if ((((top == null) || (terrainDetailByPositionNoCheck.ID == topRightId)) || (topId != rightId)) || (terrainDetailByPositionNoCheck.ID == topId))
                            {
                                if ((((top != null) && (top.ID != terrainDetailByPositionNoCheck.ID)) && ((topLeftId != terrainDetailByPositionNoCheck.ID) && (topRightId != terrainDetailByPositionNoCheck.ID))) && (top.GraphicLayer < terrainDetailByPositionNoCheck.GraphicLayer))
                                {
                                    decorativeTextures.Add(top.Textures.TopEdgeTextures[((tile.Position.X * 7) + (tile.Position.Y * 11)) % top.Textures.TopEdgeTextures.Count]);
                                }
                                if ((((right != null) && (right.ID != terrainDetailByPositionNoCheck.ID)) && ((topRightId != terrainDetailByPositionNoCheck.ID) && (bottomRightId != terrainDetailByPositionNoCheck.ID))) && (right.GraphicLayer < terrainDetailByPositionNoCheck.GraphicLayer))
                                {
                                    decorativeTextures.Add(right.Textures.RightEdgeTextures[((tile.Position.X * 7) + (tile.Position.Y * 11)) % right.Textures.RightEdgeTextures.Count]);
                                }
                                return;
                            }
                            decorativeTextures.Add(top.Textures.TopRightCornerTextures[((tile.Position.X * 7) + (tile.Position.Y * 11)) % top.Textures.TopRightCornerTextures.Count]);
                            return;

                        case TerrainDirection.BottomRight:
                            decorativeTextures.Add(right.Textures.BottomRightCornerTextures[((tile.Position.X * 7) + (tile.Position.Y * 11)) % right.Textures.BottomRightCornerTextures.Count]);
                            if ((((leftDetail == null) || (terrainDetailByPositionNoCheck.ID == topLeftId)) || (leftId != topId)) || (terrainDetailByPositionNoCheck.ID == leftId))
                            {
                                if ((((leftDetail != null) && (leftDetail.ID != terrainDetailByPositionNoCheck.ID)) && ((bottomLeftId != terrainDetailByPositionNoCheck.ID) && (topLeftId != terrainDetailByPositionNoCheck.ID))) && (leftDetail.GraphicLayer < terrainDetailByPositionNoCheck.GraphicLayer))
                                {
                                    decorativeTextures.Add(leftDetail.Textures.LeftEdgeTextures[((tile.Position.X * 7) + (tile.Position.Y * 11)) % leftDetail.Textures.LeftEdgeTextures.Count]);
                                }
                                if ((((top != null) && (top.ID != terrainDetailByPositionNoCheck.ID)) && ((topLeftId != terrainDetailByPositionNoCheck.ID) && (topRightId != terrainDetailByPositionNoCheck.ID))) && (top.GraphicLayer < terrainDetailByPositionNoCheck.GraphicLayer))
                                {
                                    decorativeTextures.Add(top.Textures.TopEdgeTextures[((tile.Position.X * 7) + (tile.Position.Y * 11)) % top.Textures.TopEdgeTextures.Count]);
                                }
                                return;
                            }
                            decorativeTextures.Add(leftDetail.Textures.TopLeftCornerTextures[((tile.Position.X * 7) + (tile.Position.Y * 11)) % leftDetail.Textures.TopLeftCornerTextures.Count]);
                            return;

                        case TerrainDirection.Centre:
                            decorativeTextures.Add(leftDetail.Textures.CentreTextures[((tile.Position.X * 7) + (tile.Position.Y * 11)) % leftDetail.Textures.CentreTextures.Count]);
                            return;

                        case TerrainDirection.None:
                            if ((((leftDetail != null) && (leftDetail.ID != terrainDetailByPositionNoCheck.ID)) && ((bottomLeftId != terrainDetailByPositionNoCheck.ID) && (topLeftId != terrainDetailByPositionNoCheck.ID))) && (leftDetail.GraphicLayer < terrainDetailByPositionNoCheck.GraphicLayer))
                            {
                                decorativeTextures.Add(leftDetail.Textures.LeftEdgeTextures[((tile.Position.X * 7) + (tile.Position.Y * 11)) % leftDetail.Textures.LeftEdgeTextures.Count]);
                            }
                            if ((((top != null) && (top.ID != terrainDetailByPositionNoCheck.ID)) && ((topLeftId != terrainDetailByPositionNoCheck.ID) && (topRightId != terrainDetailByPositionNoCheck.ID))) && (top.GraphicLayer < terrainDetailByPositionNoCheck.GraphicLayer))
                            {
                                decorativeTextures.Add(top.Textures.TopEdgeTextures[((tile.Position.X * 7) + (tile.Position.Y * 11)) % top.Textures.TopEdgeTextures.Count]);
                            }
                            if ((((right != null) && (right.ID != terrainDetailByPositionNoCheck.ID)) && ((topRightId != terrainDetailByPositionNoCheck.ID) && (bottomRightId != terrainDetailByPositionNoCheck.ID))) && (right.GraphicLayer < terrainDetailByPositionNoCheck.GraphicLayer))
                            {
                                decorativeTextures.Add(right.Textures.RightEdgeTextures[((tile.Position.X * 7) + (tile.Position.Y * 11)) % right.Textures.RightEdgeTextures.Count]);
                            }
                            if ((((bottom != null) && (bottom.ID != terrainDetailByPositionNoCheck.ID)) && ((bottomRightId != terrainDetailByPositionNoCheck.ID) && (bottomLeftId != terrainDetailByPositionNoCheck.ID))) && (bottom.GraphicLayer < terrainDetailByPositionNoCheck.GraphicLayer))
                            {
                                decorativeTextures.Add(bottom.Textures.BottomEdgeTextures[((tile.Position.X * 7) + (tile.Position.Y * 11)) % bottom.Textures.BottomEdgeTextures.Count]);
                            }
                            return;
                    }
                }
            }
        }
        private void CheckTileTexture(Tile tile, out List<Texture2D> decorativeTextures)  //用大地图时没有使用
        {
            decorativeTextures = null;
            TerrainDetail terrainDetailByPositionNoCheck = this.screen.Scenario.GetTerrainDetailByPositionNoCheck(tile.Position);
            if (terrainDetailByPositionNoCheck.Textures.BasicTextures.Count != 0)
            {
                int num;
                List<int> list;
                int num12;
                for (num = 0; num < this.TerrainList.Count; num++)
                {
                    this.TerrainList[num] = 0;
                }
                TerrainDirection none = TerrainDirection.None;
                int num2 = 0;
                Point position = new Point(tile.Position.X - 1, tile.Position.Y);
                int iD = 0;
                TerrainDetail detail2 = null;
                if (!this.screen.Scenario.PositionOutOfRange(position))
                {
                    detail2 = this.screen.Scenario.GetTerrainDetailByPositionNoCheck(position);
                    iD = detail2.ID;
                    (list = this.TerrainList)[num12 = this.mainMap.MapData[position.X, position.Y]] = list[num12] + 1;
                }
                Point point2 = new Point(tile.Position.X - 1, tile.Position.Y - 1);
                int num4 = 0;
                if (!this.screen.Scenario.PositionOutOfRange(point2))
                {
                    num4 = this.screen.Scenario.GetTerrainDetailByPositionNoCheck(point2).ID;
                    (list = this.TerrainList)[num12 = this.mainMap.MapData[point2.X, point2.Y]] = list[num12] + 1;
                }
                Point point3 = new Point(tile.Position.X, tile.Position.Y - 1);
                int num5 = 0;
                TerrainDetail detail4 = null;
                if (!this.screen.Scenario.PositionOutOfRange(point3))
                {
                    detail4 = this.screen.Scenario.GetTerrainDetailByPositionNoCheck(point3);
                    num5 = detail4.ID;
                }
                Point point4 = new Point(tile.Position.X + 1, tile.Position.Y - 1);
                int num6 = 0;
                if (!this.screen.Scenario.PositionOutOfRange(point4))
                {
                    num6 = this.screen.Scenario.GetTerrainDetailByPositionNoCheck(point4).ID;
                }
                Point point5 = new Point(tile.Position.X + 1, tile.Position.Y);
                int num7 = 0;
                TerrainDetail detail6 = null;
                if (!this.screen.Scenario.PositionOutOfRange(point5))
                {
                    detail6 = this.screen.Scenario.GetTerrainDetailByPositionNoCheck(point5);
                    num7 = detail6.ID;
                }
                Point point6 = new Point(tile.Position.X + 1, tile.Position.Y + 1);
                int num8 = 0;
                if (!this.screen.Scenario.PositionOutOfRange(point6))
                {
                    num8 = this.screen.Scenario.GetTerrainDetailByPositionNoCheck(point6).ID;
                }
                Point point7 = new Point(tile.Position.X, tile.Position.Y + 1);
                int num9 = 0;
                TerrainDetail detail8 = null;
                if (!this.screen.Scenario.PositionOutOfRange(point7))
                {
                    detail8 = this.screen.Scenario.GetTerrainDetailByPositionNoCheck(point7);
                    num9 = detail8.ID;
                }
                Point point8 = new Point(tile.Position.X - 1, tile.Position.Y + 1);
                int num10 = 0;
                if (!this.screen.Scenario.PositionOutOfRange(point8))
                {
                    num10 = this.screen.Scenario.GetTerrainDetailByPositionNoCheck(point8).ID;
                }
                int num11 = 0;
                if ((iD > 0) && (iD == terrainDetailByPositionNoCheck.ID))
                {
                    num11++;
                }
                if ((num5 > 0) && (num5 == terrainDetailByPositionNoCheck.ID))
                {
                    num11++;
                }
                if ((num7 > 0) && (num7 == terrainDetailByPositionNoCheck.ID))
                {
                    num11++;
                }
                if ((num9 > 0) && (num9 == terrainDetailByPositionNoCheck.ID))
                {
                    num11++;
                }
                if (num11 < 4)
                {
                    if (detail4 != null)
                    {
                        (list = this.TerrainList)[num12 = this.mainMap.MapData[point3.X, point3.Y]] = list[num12] + 1;
                        for (num = 0; num < this.TerrainList.Count; num++)
                        {
                            if ((num != terrainDetailByPositionNoCheck.ID) && ((((this.TerrainList[num] >= 2) && (iD == num)) && (num4 != terrainDetailByPositionNoCheck.ID)) && (num5 == num)))
                            {
                                none = TerrainDirection.TopLeft;
                                num2 = num;
                                break;
                            }
                        }
                    }
                    if (num6 > 0)
                    {
                        (list = this.TerrainList)[num12 = this.mainMap.MapData[point4.X, point4.Y]] = list[num12] + 1;
                    }
                    if (num7 > 0)
                    {
                        (list = this.TerrainList)[num12 = this.mainMap.MapData[point5.X, point5.Y]] = list[num12] + 1;
                        for (num = 0; num < this.TerrainList.Count; num++)
                        {
                            if (num != terrainDetailByPositionNoCheck.ID)
                            {
                                if (((none == TerrainDirection.None) && (this.TerrainList[num] >= 2)) && (((num5 == num) && (num6 != terrainDetailByPositionNoCheck.ID)) && (num7 == num)))
                                {
                                    none = TerrainDirection.TopRight;
                                    num2 = num;
                                }
                                if (this.TerrainList[num] >= 3)
                                {
                                    if ((((iD == num) && (num5 == num)) && ((num7 == num) && (num6 != terrainDetailByPositionNoCheck.ID))) && (num4 != terrainDetailByPositionNoCheck.ID))
                                    {
                                        none = TerrainDirection.Top;
                                        num2 = num;
                                    }
                                    break;
                                }
                            }
                        }
                    }
                    if (num8 > 0)
                    {
                        (list = this.TerrainList)[num12 = this.mainMap.MapData[point6.X, point6.Y]] = list[num12] + 1;
                    }
                    if (num9 > 0)
                    {
                        (list = this.TerrainList)[num12 = this.mainMap.MapData[point7.X, point7.Y]] = list[num12] + 1;
                        for (num = 0; num < this.TerrainList.Count; num++)
                        {
                            if (num != terrainDetailByPositionNoCheck.ID)
                            {
                                if (((none == TerrainDirection.None) && (this.TerrainList[num] >= 2)) && (((num7 == num) && (num8 != terrainDetailByPositionNoCheck.ID)) && (num9 == num)))
                                {
                                    none = TerrainDirection.BottomRight;
                                    num2 = num;
                                }
                                if ((this.TerrainList[num] >= 3) && ((((num5 == num) && (num7 == num)) && ((num9 == num) && (num6 != terrainDetailByPositionNoCheck.ID))) && (num8 != terrainDetailByPositionNoCheck.ID)))
                                {
                                    none = TerrainDirection.Right;
                                    num2 = num;
                                }
                            }
                        }
                    }
                    if (num10 > 0)
                    {
                        (list = this.TerrainList)[num12 = this.mainMap.MapData[point8.X, point8.Y]] = list[num12] + 1;
                    }
                    if (iD > 0)
                    {
                        for (num = 0; num < this.TerrainList.Count; num++)
                        {
                            if (num != terrainDetailByPositionNoCheck.ID)
                            {
                                if (((none == TerrainDirection.None) && (this.TerrainList[num] >= 2)) && (((num9 == num) && (num10 != terrainDetailByPositionNoCheck.ID)) && (iD == num)))
                                {
                                    none = TerrainDirection.BottomLeft;
                                    num2 = num;
                                }
                                if ((this.TerrainList[num] >= 3) && ((((num7 == num) && (num9 == num)) && ((iD == num) && (num8 != terrainDetailByPositionNoCheck.ID))) && (num10 != terrainDetailByPositionNoCheck.ID)))
                                {
                                    none = TerrainDirection.Bottom;
                                    num2 = num;
                                }
                                if (((((this.TerrainList[num] >= 4) && (iD == num)) && ((num5 == num) && (num7 == num))) && (num9 == num)) && ((((num4 != terrainDetailByPositionNoCheck.ID) && (num6 != terrainDetailByPositionNoCheck.ID)) && ((num8 != terrainDetailByPositionNoCheck.ID) && (num10 != terrainDetailByPositionNoCheck.ID))) || (this.TerrainList[num] >= 7)))
                                {
                                    none = TerrainDirection.Centre;
                                    num2 = num;
                                    break;
                                }
                            }
                        }
                    }
                    if ((((none != TerrainDirection.Centre) && (none != TerrainDirection.Top)) && ((none != TerrainDirection.Right) && (none != TerrainDirection.Bottom))) && (num5 > 0))
                    {
                        for (num = 0; num < this.TerrainList.Count; num++)
                        {
                            if (((num != terrainDetailByPositionNoCheck.ID) && (this.TerrainList[num] >= 3)) && ((((num9 == num) && (iD == num)) && ((num5 == num) && (num10 != terrainDetailByPositionNoCheck.ID))) && (num4 != terrainDetailByPositionNoCheck.ID)))
                            {
                                none = TerrainDirection.Left;
                                num2 = num;
                            }
                        }
                    }
                    decorativeTextures = new List<Texture2D>();
                    switch (none)
                    {
                        case TerrainDirection.Top:
                            decorativeTextures.Add(detail4.Textures.TopTextures[((tile.Position.X * 7) + (tile.Position.Y * 11)) % detail4.Textures.TopTextures.Count]);
                            if ((((detail8 != null) && (detail8.ID != terrainDetailByPositionNoCheck.ID)) && ((num8 != terrainDetailByPositionNoCheck.ID) && (num10 != terrainDetailByPositionNoCheck.ID))) && (detail8.GraphicLayer < terrainDetailByPositionNoCheck.GraphicLayer))
                            {
                                decorativeTextures.Add(detail8.Textures.BottomEdgeTextures[((tile.Position.X * 7) + (tile.Position.Y * 11)) % detail8.Textures.BottomEdgeTextures.Count]);
                            }
                            return;

                        case TerrainDirection.Left:
                            decorativeTextures.Add(detail2.Textures.LeftTextures[((tile.Position.X * 7) + (tile.Position.Y * 11)) % detail2.Textures.LeftTextures.Count]);
                            if ((((detail6 != null) && (detail6.ID != terrainDetailByPositionNoCheck.ID)) && ((num6 != terrainDetailByPositionNoCheck.ID) && (num8 != terrainDetailByPositionNoCheck.ID))) && (detail6.GraphicLayer < terrainDetailByPositionNoCheck.GraphicLayer))
                            {
                                decorativeTextures.Add(detail6.Textures.RightEdgeTextures[((tile.Position.X * 7) + (tile.Position.Y * 11)) % detail6.Textures.RightEdgeTextures.Count]);
                            }
                            return;

                        case TerrainDirection.Right:
                            decorativeTextures.Add(detail6.Textures.RightTextures[((tile.Position.X * 7) + (tile.Position.Y * 11)) % detail6.Textures.RightTextures.Count]);
                            if ((((detail2 != null) && (detail2.ID != terrainDetailByPositionNoCheck.ID)) && ((num10 != terrainDetailByPositionNoCheck.ID) && (num4 != terrainDetailByPositionNoCheck.ID))) && (detail2.GraphicLayer < terrainDetailByPositionNoCheck.GraphicLayer))
                            {
                                decorativeTextures.Add(detail2.Textures.LeftEdgeTextures[((tile.Position.X * 7) + (tile.Position.Y * 11)) % detail2.Textures.LeftEdgeTextures.Count]);
                            }
                            return;

                        case TerrainDirection.Bottom:
                            decorativeTextures.Add(detail8.Textures.BottomTextures[((tile.Position.X * 7) + (tile.Position.Y * 11)) % detail8.Textures.BottomTextures.Count]);
                            if ((((detail4 != null) && (detail4.ID != terrainDetailByPositionNoCheck.ID)) && ((num4 != terrainDetailByPositionNoCheck.ID) && (num6 != terrainDetailByPositionNoCheck.ID))) && (detail4.GraphicLayer < terrainDetailByPositionNoCheck.GraphicLayer))
                            {
                                decorativeTextures.Add(detail4.Textures.TopEdgeTextures[((tile.Position.X * 7) + (tile.Position.Y * 11)) % detail4.Textures.TopEdgeTextures.Count]);
                            }
                            return;

                        case TerrainDirection.TopLeft:
                            decorativeTextures.Add(detail2.Textures.TopLeftCornerTextures[((tile.Position.X * 7) + (tile.Position.Y * 11)) % detail2.Textures.TopLeftCornerTextures.Count]);
                            if ((((detail6 == null) || (terrainDetailByPositionNoCheck.ID == num8)) || (num7 != num9)) || (terrainDetailByPositionNoCheck.ID == num7))
                            {
                                if ((((detail6 != null) && (detail6.ID != terrainDetailByPositionNoCheck.ID)) && ((num6 != terrainDetailByPositionNoCheck.ID) && (num8 != terrainDetailByPositionNoCheck.ID))) && (detail6.GraphicLayer < terrainDetailByPositionNoCheck.GraphicLayer))
                                {
                                    decorativeTextures.Add(detail6.Textures.RightEdgeTextures[((tile.Position.X * 7) + (tile.Position.Y * 11)) % detail6.Textures.RightEdgeTextures.Count]);
                                }
                                if ((((detail8 != null) && (detail8.ID != terrainDetailByPositionNoCheck.ID)) && ((num8 != terrainDetailByPositionNoCheck.ID) && (num10 != terrainDetailByPositionNoCheck.ID))) && (detail8.GraphicLayer < terrainDetailByPositionNoCheck.GraphicLayer))
                                {
                                    decorativeTextures.Add(detail8.Textures.BottomEdgeTextures[((tile.Position.X * 7) + (tile.Position.Y * 11)) % detail8.Textures.BottomEdgeTextures.Count]);
                                }
                                return;
                            }
                            decorativeTextures.Add(detail6.Textures.BottomRightCornerTextures[((tile.Position.X * 7) + (tile.Position.Y * 11)) % detail6.Textures.BottomRightCornerTextures.Count]);
                            return;

                        case TerrainDirection.TopRight:
                            decorativeTextures.Add(detail4.Textures.TopRightCornerTextures[((tile.Position.X * 7) + (tile.Position.Y * 11)) % detail4.Textures.TopRightCornerTextures.Count]);
                            if ((((detail8 == null) || (terrainDetailByPositionNoCheck.ID == num10)) || (num9 != iD)) || (terrainDetailByPositionNoCheck.ID == num9))
                            {
                                if ((((detail2 != null) && (detail2.ID != terrainDetailByPositionNoCheck.ID)) && ((num10 != terrainDetailByPositionNoCheck.ID) && (num4 != terrainDetailByPositionNoCheck.ID))) && (detail2.GraphicLayer < terrainDetailByPositionNoCheck.GraphicLayer))
                                {
                                    decorativeTextures.Add(detail2.Textures.LeftEdgeTextures[((tile.Position.X * 7) + (tile.Position.Y * 11)) % detail2.Textures.LeftEdgeTextures.Count]);
                                }
                                if ((((detail8 != null) && (detail8.ID != terrainDetailByPositionNoCheck.ID)) && ((num8 != terrainDetailByPositionNoCheck.ID) && (num10 != terrainDetailByPositionNoCheck.ID))) && (detail8.GraphicLayer < terrainDetailByPositionNoCheck.GraphicLayer))
                                {
                                    decorativeTextures.Add(detail8.Textures.BottomEdgeTextures[((tile.Position.X * 7) + (tile.Position.Y * 11)) % detail8.Textures.BottomEdgeTextures.Count]);
                                }
                                return;
                            }
                            decorativeTextures.Add(detail8.Textures.BottomLeftCornerTextures[((tile.Position.X * 7) + (tile.Position.Y * 11)) % detail8.Textures.BottomLeftCornerTextures.Count]);
                            return;

                        case TerrainDirection.BottomLeft:
                            decorativeTextures.Add(detail8.Textures.BottomLeftCornerTextures[((tile.Position.X * 7) + (tile.Position.Y * 11)) % detail8.Textures.BottomLeftCornerTextures.Count]);
                            if ((((detail4 == null) || (terrainDetailByPositionNoCheck.ID == num6)) || (num5 != num7)) || (terrainDetailByPositionNoCheck.ID == num5))
                            {
                                if ((((detail4 != null) && (detail4.ID != terrainDetailByPositionNoCheck.ID)) && ((num4 != terrainDetailByPositionNoCheck.ID) && (num6 != terrainDetailByPositionNoCheck.ID))) && (detail4.GraphicLayer < terrainDetailByPositionNoCheck.GraphicLayer))
                                {
                                    decorativeTextures.Add(detail4.Textures.TopEdgeTextures[((tile.Position.X * 7) + (tile.Position.Y * 11)) % detail4.Textures.TopEdgeTextures.Count]);
                                }
                                if ((((detail6 != null) && (detail6.ID != terrainDetailByPositionNoCheck.ID)) && ((num6 != terrainDetailByPositionNoCheck.ID) && (num8 != terrainDetailByPositionNoCheck.ID))) && (detail6.GraphicLayer < terrainDetailByPositionNoCheck.GraphicLayer))
                                {
                                    decorativeTextures.Add(detail6.Textures.RightEdgeTextures[((tile.Position.X * 7) + (tile.Position.Y * 11)) % detail6.Textures.RightEdgeTextures.Count]);
                                }
                                return;
                            }
                            decorativeTextures.Add(detail4.Textures.TopRightCornerTextures[((tile.Position.X * 7) + (tile.Position.Y * 11)) % detail4.Textures.TopRightCornerTextures.Count]);
                            return;

                        case TerrainDirection.BottomRight:
                            decorativeTextures.Add(detail6.Textures.BottomRightCornerTextures[((tile.Position.X * 7) + (tile.Position.Y * 11)) % detail6.Textures.BottomRightCornerTextures.Count]);
                            if ((((detail2 == null) || (terrainDetailByPositionNoCheck.ID == num4)) || (iD != num5)) || (terrainDetailByPositionNoCheck.ID == iD))
                            {
                                if ((((detail2 != null) && (detail2.ID != terrainDetailByPositionNoCheck.ID)) && ((num10 != terrainDetailByPositionNoCheck.ID) && (num4 != terrainDetailByPositionNoCheck.ID))) && (detail2.GraphicLayer < terrainDetailByPositionNoCheck.GraphicLayer))
                                {
                                    decorativeTextures.Add(detail2.Textures.LeftEdgeTextures[((tile.Position.X * 7) + (tile.Position.Y * 11)) % detail2.Textures.LeftEdgeTextures.Count]);
                                }
                                if ((((detail4 != null) && (detail4.ID != terrainDetailByPositionNoCheck.ID)) && ((num4 != terrainDetailByPositionNoCheck.ID) && (num6 != terrainDetailByPositionNoCheck.ID))) && (detail4.GraphicLayer < terrainDetailByPositionNoCheck.GraphicLayer))
                                {
                                    decorativeTextures.Add(detail4.Textures.TopEdgeTextures[((tile.Position.X * 7) + (tile.Position.Y * 11)) % detail4.Textures.TopEdgeTextures.Count]);
                                }
                                return;
                            }
                            decorativeTextures.Add(detail2.Textures.TopLeftCornerTextures[((tile.Position.X * 7) + (tile.Position.Y * 11)) % detail2.Textures.TopLeftCornerTextures.Count]);
                            return;

                        case TerrainDirection.Centre:
                            decorativeTextures.Add(detail2.Textures.CentreTextures[((tile.Position.X * 7) + (tile.Position.Y * 11)) % detail2.Textures.CentreTextures.Count]);
                            return;

                        case TerrainDirection.None:
                            if ((((detail2 != null) && (detail2.ID != terrainDetailByPositionNoCheck.ID)) && ((num10 != terrainDetailByPositionNoCheck.ID) && (num4 != terrainDetailByPositionNoCheck.ID))) && (detail2.GraphicLayer < terrainDetailByPositionNoCheck.GraphicLayer))
                            {
                                decorativeTextures.Add(detail2.Textures.LeftEdgeTextures[((tile.Position.X * 7) + (tile.Position.Y * 11)) % detail2.Textures.LeftEdgeTextures.Count]);
                            }
                            if ((((detail4 != null) && (detail4.ID != terrainDetailByPositionNoCheck.ID)) && ((num4 != terrainDetailByPositionNoCheck.ID) && (num6 != terrainDetailByPositionNoCheck.ID))) && (detail4.GraphicLayer < terrainDetailByPositionNoCheck.GraphicLayer))
                            {
                                decorativeTextures.Add(detail4.Textures.TopEdgeTextures[((tile.Position.X * 7) + (tile.Position.Y * 11)) % detail4.Textures.TopEdgeTextures.Count]);
                            }
                            if ((((detail6 != null) && (detail6.ID != terrainDetailByPositionNoCheck.ID)) && ((num6 != terrainDetailByPositionNoCheck.ID) && (num8 != terrainDetailByPositionNoCheck.ID))) && (detail6.GraphicLayer < terrainDetailByPositionNoCheck.GraphicLayer))
                            {
                                decorativeTextures.Add(detail6.Textures.RightEdgeTextures[((tile.Position.X * 7) + (tile.Position.Y * 11)) % detail6.Textures.RightEdgeTextures.Count]);
                            }
                            if ((((detail8 != null) && (detail8.ID != terrainDetailByPositionNoCheck.ID)) && ((num8 != terrainDetailByPositionNoCheck.ID) && (num10 != terrainDetailByPositionNoCheck.ID))) && (detail8.GraphicLayer < terrainDetailByPositionNoCheck.GraphicLayer))
                            {
                                decorativeTextures.Add(detail8.Textures.BottomEdgeTextures[((tile.Position.X * 7) + (tile.Position.Y * 11)) % detail8.Textures.BottomEdgeTextures.Count]);
                            }
                            return;
                    }
                }
            }
        }