示例#1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="fi"></param>
        /// <param name="map"></param>
        public static Map ReadMap2(FileInfo fi)
        {
            FileStream   fs = fi.OpenRead();
            BinaryReader br = new BinaryReader(fs);

            byte[] Buffer = br.ReadBytes((int)fi.Length);

            br.Close();

            Map map = new Map();

            map.FileOnDisk = fi;

            MemoryStream ms = new MemoryStream(Buffer);

            br = new BinaryReader(ms);

            if (Buffer[0] != 77 || Buffer[1] != 65 || Buffer[2] != 80 || Buffer[3] != 249 || Buffer[4] != 53 || Buffer[5] != 0)
            {
                Errors.Error("InputOutput", "File is not a VERGE2 Map");
                return(null);
            }


            // 6 bytes signature
            // 4 bytes unknown??
            // ---
            // advance 10 bytes
            br.ReadBytes(10);


            // 60 bytes VSP FileName
            FileInfo vspfile = new FileInfo(Helper.BytesToString(br.ReadBytes(60)));

            if (!vspfile.Exists)
            {
                // TODO:  give the option to create a vsp in this case
                Errors.Error("InputOutput", "VSP was not found. New VSP created.");
                map.vsp = new Vsp24();
            }
            else
            {
                map.vsp = ReadVsp(vspfile.FullName);
            }

            // 60 bytes music filename
            map.MusicFileName = Helper.BytesToString(br.ReadBytes(60));

            // 20 bytes render string
            string dontcare = Helper.BytesToString(br.ReadBytes(20));


            // 4 bytes, start position
            map.PlayerStartX = (int)br.ReadInt16();
            map.PlayerStartY = (int)br.ReadInt16();

            // 51 bytes, unknown
            br.ReadBytes(51);

            // 1 byte, number of layers
            int layerCount = (int)br.ReadByte();


            for (int i = 0; i < layerCount; i++)
            {
                // 12 bytes per layer discriptor
                MapLayer ml = new MapLayer(map);
                ml.type = LayerType.Tile;
                ml.name = "Layer " + i.ToString();


                int mx, dx, my, dy;
                mx = (int)br.ReadByte();
                dx = (int)br.ReadByte();
                my = (int)br.ReadByte();
                dy = (int)br.ReadByte();

                double dmx, dmy;

                dmx = 1.0 * mx / dx;
                dmy = 1.0 * my / dy;
                ml.parallaxInfo.MultipleX = dmx;
                ml.parallaxInfo.MultipleY = dmy;

                /*
                 *                              ml.parallaxInfo.MultiplyX = (int)br.ReadByte();
                 *                              ml.parallaxInfo.DivideX = (int)br.ReadByte();
                 *                              ml.parallaxInfo.MultiplyY = (int)br.ReadByte();
                 *                              ml.parallaxInfo.DivideY = (int)br.ReadByte(); */

                int w = (int)br.ReadInt16();
                int h = (int)br.ReadInt16();
                ml.size(w, h);

                ml.Translucency = (int)br.ReadByte();
                ml.HLine        = (int)br.ReadByte();

                // padding
                br.ReadInt16();

                map.Layers.Add(ml);
            }

            for (int i = 0; i < layerCount; i++)
            {
                int rleLength = br.ReadInt32();

                ushort[] layerdata = InputOutput.DecompressData16(Helper.BytesToWords(br.ReadBytes(rleLength)));
                MapLayer ml        = (MapLayer)map.Layers[i];
                ml.Data = new short[ml.Width * ml.Height];
                for (int j = 0; j < ml.Width * ml.Height; j++)
                {
                    ml.Data[j] = (short)layerdata[j];
                }
            }

            int obsDataLength = br.ReadInt32();

            byte[] obsdata = InputOutput.DecompressData8(br.ReadBytes(obsDataLength));
            map.ObsLayer      = new MapLayer(map);
            map.ObsLayer.type = LayerType.Obs;
            map.ObsLayer.size(((MapLayer)map.Layers[0]).Width, ((MapLayer)map.Layers[0]).Height);
            map.ObsLayer.name = "Obstructions";
            map.ObsLayer.Data = new short[map.ObsLayer.Width * map.ObsLayer.Height];
            for (int i = 0; i < map.ObsLayer.Width * map.ObsLayer.Height; i++)
            {
                map.ObsLayer.Data[i] = obsdata[i];
            }


            int zoneDataLength = br.ReadInt32();

            byte[] zonedata = InputOutput.DecompressData8(br.ReadBytes(zoneDataLength));
            map.ZoneLayer      = new MapLayer(map);
            map.ZoneLayer.type = LayerType.Zone;
            map.ZoneLayer.size(((MapLayer)map.Layers[0]).Width, ((MapLayer)map.Layers[0]).Height);
            map.ZoneLayer.name = "Zones";
            map.ZoneLayer.Data = new short[map.ZoneLayer.Width * map.ZoneLayer.Height];
            for (int i = 0; i < map.ZoneLayer.Width * map.ZoneLayer.Height; i++)
                map.ZoneLayer.Data[i] = zonedata[i]; }
示例#2
0
 public void Write()
 {
     InputOutput.WriteVsp(this.FileOnDisk, this);
 }
示例#3
0
        public Map CreateMap()
        {
            Map  m       = new Map();
            int  l_count = (int)n_layers.Value;
            int  l_w     = (int)n_w.Value;
            int  l_h     = (int)n_h.Value;
            bool bNewvsp = rb_new.Checked;

            for (int i = 0; i < l_count; i++)
            {
                MapLayer ml = new MapLayer(m);
                ml.size(l_w, l_h);
                ml.name         = "Layer " + i;
                ml.type         = LayerType.Tile;
                ml.parallaxInfo = new ParallaxInfo();
                m.Layers.Add(ml);
            }
            MapLayer zl = new MapLayer(m);

            zl.type = LayerType.Zone;
            zl.name = "Zones";
            zl.size(l_w, l_h);

            m.ZoneLayer = zl;

            MapLayer ol = new MapLayer(m);

            ol.type = LayerType.Obs;
            ol.name = "Obstructions";
            ol.size(l_w, l_h);
            m.ObsLayer = ol;



            MapLayer el = new MapLayer(m);

            el.type = LayerType.Entity;
            el.name = "Entities";
            MapLayerSpecial rl = new MapLayerSpecial(m);

            rl.type = LayerType.Special_Retrace;


            m.Layers.Add(rl);
            m.Layers.Add(el);
            m.Layers.Add(ol);
            m.Layers.Add(zl);

            m.EntLayer = el;
            if (bNewvsp)
            {
                Vsp24 v = new Vsp24();

                //v.AddTiles(100);
                v.Tiles.AddRange(v.GetTiles(100));
                m.vsp = v;
            }
            else
            {
                Vsp24 v = InputOutput.ReadVsp(t_vspfile.Text);
                if (v == null)
                {
                    Errors.Error("Warning", "An error occured when attempting to load the vsp file.  A blank VSP has been created.");
                    v = new Vsp24();

                    v.Tiles.Add(v.GetTiles(100));
                    m.vsp = v;
                }
                else
                {
                    m.vsp = v;
                }
            }

            MapZone mz = new MapZone();

            mz.ID   = 0;
            mz.Name = "NULL_ZONE";
            m.Zones.Add(mz);


            m.Init();
            m.RenderString = "";
            return(m);
        }