Beispiel #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);
            }
        }
Beispiel #2
0
        public static void AddMeta(CForestRoomMeta meta)
        {
            if (m_dict.ContainsKey(meta.sId))
            {
                Debug.LogError(string.Format("CForestRoomMetaManager ALREADY CONTAIN the meta with id -- {0} ", meta.sId));
            }

            m_dict[meta.sId] = meta;
        }
Beispiel #3
0
        public static CForestRoomMeta GetMeta(string id)
        {
            CForestRoomMeta meta = null;
            bool            v    = m_dict.TryGetValue(id, out meta);

            if (!v)
            {
                Debug.LogError(string.Format("CForestRoomMetaManager DO NOT CONTAIN the meta with id -- {0} ", id));
            }
            return(meta);
        }
        private void PlaceRoom(int sx, int sy, CForestRoomMeta meta)
        {
            for (int x = 0; x < meta.Size.x; x++)
            {
                for (int y = 0; y < meta.Size.y; y++)
                {
                    SetTileData(sx + x, sy + y, meta.sId, meta.GetSpot(x, y));
                }
            }

            var room = new CForestRoomData(meta.sId, sx, sy);

            m_roomList.Add(room);
        }
        private void TryRoomAllocInRange(CForestRoomMeta meta, Vector2Int bottomLeft, Vector2Int topRight)
        {
            int tryNum = 20;

            while (tryNum > 0)
            {
                int  sx = Random.Range(bottomLeft.x, topRight.x - meta.Size.x);
                int  sy = Random.Range(bottomLeft.y, topRight.y - meta.Size.y);
                int  ex = sx + meta.Size.x;
                int  ey = sy + meta.Size.y;
                bool b  = CanPlaceRoom(sx, sy, ex, ey);
                if (b)
                {
                    PlaceRoom(sx, sy, meta);
                }

                tryNum--;
            }
        }