Пример #1
0
        protected override void Parse()
        {
            m_xreader.ReadRootNode();

            foreach (XmlElement node in m_xreader.rootChildNodes)
            {
                CForestRoomMeta meta = new CForestRoomMeta(node.GetAttribute("id"));
                meta.NameKey = node.GetAttribute("name");
                m_xreader.TryReadChildNodeAttr(node, "PreferLocation", ref meta.PreferLocation);

                int cols = 0, rows = 0;
                m_xreader.TryReadChildNodeAttr(node, "Shape", "x", ref cols);
                m_xreader.TryReadChildNodeAttr(node, "Shape", "y", ref rows);
                meta.SetSize(cols, rows);

                List <string> lines     = new List <string>();
                var           shapeNode = node.SelectSingleNode("Shape");
                m_xreader.TryReadChildNodesAttr(shapeNode, "Line", lines);
                for (int r = 0; r < lines.Count; r++)
                {
                    var arr = lines[r].ToCharArray();
                    for (int c = 0; c < arr.Length; c++)
                    {
                        meta.SetSpot(c, r, arr[c]);
                    }
                }

                CForestRoomMetaManager.AddMeta(meta);
            }
        }
Пример #2
0
        /// <summary>
        /// 我们期望房子开辟在这里, 所以会覆盖所有的其他数据
        /// </summary>
        private void PreferLocation(int roomId)
        {
            if (roomId < 0)
            {
                return;
            }
            var meta = CForestRoomMetaManager.GetMeta(roomId.ToString());

            if (!meta.HasPreferLocation)
            {
                return;
            }

            int sx = meta.PreferLocation.x;
            int sy = meta.PreferLocation.y;
            int ex = sx + meta.Size.x;
            int ey = sy + meta.Size.y;

            if (sx < 0 || sy < 0)
            {
                Debug.LogError("PreferLocation Must Bigger Than 0!!");
                return;
            }

            if (ex >= m_size.x || ey >= m_size.y)
            {
                Debug.LogError("PreferLocation + RoomSize Must Smaller Than MapSize!!");
                return;
            }

            PlaceRoom(sx, sy, meta);
        }
Пример #3
0
        /// <summary>
        /// 全地图开辟一个房间
        /// 开辟过程中会做20次尝试
        /// 如果开辟失败就不开辟
        /// </summary>
        private void RoomAlloc(int roomId)
        {
            if (roomId < 0)
            {
                return;
            }
            var meta = CForestRoomMetaManager.GetMeta(roomId.ToString());

            if (meta.HasPreferLocation)
            {
                PreferLocation(roomId);
                return;
            }

            TryRoomAllocInRange(meta, new Vector2Int(0, 0), m_size);
        }
Пример #4
0
        /// <summary>
        /// 在地图外围1/3的区域开辟房间
        /// </summary>
        private void RoomAllocInEdge(int roomId)
        {
            if (roomId < 0)
            {
                return;
            }
            var meta = CForestRoomMetaManager.GetMeta(roomId.ToString());

            Vector2Int bottomLeft = new Vector2Int(0, 0);
            Vector2Int topRight   = m_size;

            int edgeCols = Mathf.CeilToInt(m_size.x * 0.33f);
            int edgeRows = Mathf.CeilToInt(m_size.y * 0.33f);

            //45 90 135 在下半区域放房子
            if (EdgeEntrances == 1 || EdgeEntrances == 2 || EdgeEntrances == 3)
            {
                bottomLeft.x = 0;
                bottomLeft.y = 0;
                topRight.x   = m_size.x;
                topRight.y   = edgeRows;
            }
            //225, 270, 315 在上半区域放房子
            else if (EdgeEntrances == 4 || EdgeEntrances == 6 || EdgeEntrances == 7)
            {
                bottomLeft.x = 0;
                bottomLeft.y = m_size.y - edgeRows;
                topRight.x   = m_size.x;
                topRight.y   = m_size.y;
            }
            else if (EdgeEntrances == 0)             //0 在左侧放房子
            {
                bottomLeft.x = 0;
                bottomLeft.y = 0;
                topRight.x   = edgeCols;
                topRight.y   = m_size.y;
            }
            else             //剩余的在右侧放房子
            {
                bottomLeft.x = m_size.x - edgeCols;
                bottomLeft.y = 0;
                topRight.x   = m_size.x;
                topRight.y   = m_size.y;
            }

            TryRoomAllocInRange(meta, bottomLeft, topRight);
        }