Ejemplo n.º 1
0
        private static void WriteRegions(EU2.Map.IDGrid idgrid, EU2.Data.ProvinceList provinces, IDMap idmap, EU2.IO.CSVWriter writer)
        {
            writer.EndRow( "region-index-x;region-index-y;region-offset-x;region-offset-x;region-provinceCount;index;provinceId;name" );

            for(int y=0; y<idgrid.Height; ++y ) {
                for(int x=0; x<idgrid.Width; ++x ) {
                    ushort[] list = idgrid.GetIDs(x,y);
                    if ( list.Length == 0 ) {
                        writer.Write(x);
                        writer.Write(y);
                        writer.Write(x*EU2.Map.IDGrid.RegionWidth);
                        writer.Write(y*EU2.Map.IDGrid.RegionHeight);
                        writer.Write(0);

                        Rectangle rect = Rectangle.Empty;
                        if ( !EU2.Map.IDGrid.CheckAreaForOverflow(idmap, EU2.Map.IDGrid.GetRegionRect(x,y), out rect) ) {
                            writer.Write("Overflow");
                            writer.Write(rect.X);
                            writer.Write(rect.Y);
                            writer.Write(rect.Width);
                            writer.Write(rect.Height);
                        }
                        writer.EndRow();
                    }
                    else {
                        int i=0;
                        for(; i<list.Length; ++i) {
                            if ( list[i] == 0 && i>0 ) break;
                        }
                        int cnt = i;

                        for(i=0; i<list.Length; ++i) {
                            if ( list[i] == 0 && i>0 ) break;
                            writer.Write(x);
                            writer.Write(y);
                            writer.Write(x*EU2.Map.IDGrid.RegionWidth);
                            writer.Write(y*EU2.Map.IDGrid.RegionHeight);
                            writer.Write(cnt);
                            writer.Write(i);
                            writer.Write(list[i]);
                            writer.Write(provinces[list[i]].Name);
                            writer.EndRow();
                        }
                    }
                }
            }
            writer.Flush();
        }
Ejemplo n.º 2
0
        private static void WriteRegions(EU2.Map.IDGrid idgrid, EU2.Data.ProvinceList provinces, IDMap idmap, System.Xml.XmlTextWriter writer)
        {
            writer.WriteStartDocument();
            writer.WriteStartElement("IDGrid");

            for(int y=0; y<idgrid.Height; ++y ) {
                for(int x=0; x<idgrid.Width; ++x ) {
                    writer.WriteStartElement("Region");
                    writer.WriteAttributeString("index-x", x.ToString());
                    writer.WriteAttributeString("index-y", y.ToString());
                    writer.WriteAttributeString("offset-x", (x*EU2.Map.IDGrid.RegionWidth).ToString());
                    writer.WriteAttributeString("offset-y", (y*EU2.Map.IDGrid.RegionHeight).ToString());

                    ushort[] list = idgrid.GetIDs(x,y);
                    int cnt=0;
                    for(; cnt<list.Length; ++cnt) {
                        if ( list[cnt] == 0 && cnt>0 ) break;
                    }

                    if ( cnt <= 1 ) {
                        writer.WriteAttributeString("provinceCount", "0");
                        Rectangle rect = Rectangle.Empty;
                        if ( !EU2.Map.IDGrid.CheckAreaForOverflow(idmap, EU2.Map.IDGrid.GetRegionRect(x,y), out rect) ) {
                            writer.WriteStartElement("Overflow");
                            writer.WriteAttributeString("x", rect.X.ToString());
                            writer.WriteAttributeString("y", rect.Y.ToString());
                            writer.WriteAttributeString("width", rect.Width.ToString());
                            writer.WriteAttributeString("height", rect.Height.ToString());
                            writer.WriteEndElement();
                        }
                    }
                    else {
                        writer.WriteAttributeString("provinceCount", cnt.ToString());
                        for(int i=0; i<list.Length; ++i) {
                            if ( list[i] == 0 && i>0 ) break;
                            writer.WriteStartElement("Province");
                            writer.WriteAttributeString("index", i.ToString());
                            writer.WriteAttributeString("id", list[i].ToString());
                            writer.WriteAttributeString("name", provinces[list[i]].Name);
                            writer.WriteEndElement();
                        }
                    }
                    writer.WriteEndElement();
                }
            }
            writer.WriteEndElement();
            writer.WriteEndDocument();
            writer.Flush();
        }