コード例 #1
0
ファイル: NewMapWnd.cs プロジェクト: zeromus/maped3
        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;
        }
コード例 #2
0
        public unsafe static Map ReadMap3(FileInfo fi)
        {
            byte[] m3s = new byte[] { (byte)'V', (byte)'3', (byte)'M', (byte)'A', (byte)'P', (byte)0 };

            FileStream   fs = fi.OpenRead();
            BinaryReader br = new BinaryReader(fs);

            Map map = new Map();

            map.FileOnDisk = fi;

            //			Directory.SetCurrentDirectory(map.FileOnDisk.Directory.FullName);


            byte[] sig = br.ReadBytes(m3s.Length);
            for (int i = 0; i < m3s.Length; i++)
            {
                if (sig[i] != m3s[i])
                {
                    return(null);
                }
            }

            int version = br.ReadInt32();
            int vcofs   = br.ReadInt32();

            byte[] formal       = br.ReadBytes(256);
            byte[] vspname      = br.ReadBytes(256);
            byte[] musicname    = br.ReadBytes(256);
            byte[] renderstring = br.ReadBytes(256);
            byte[] aexec        = br.ReadBytes(256);

            string   vspf = Helper.BytesToString(vspname);
            FileInfo vspfile;

            try {
                vspfile = new FileInfo(vspf);
            } catch (ArgumentException) {
                throw new Exception("VSP file is inaccessible. Requested file was '" + vspf + "'");
            }
            if (!vspfile.Exists)
            {
                System.Windows.Forms.DialogResult dr = System.Windows.Forms.MessageBox.Show("Unable to load requested VSP file.  Create a blank vsp?", "Load Error", System.Windows.Forms.MessageBoxButtons.YesNoCancel, System.Windows.Forms.MessageBoxIcon.Information);
                if (dr == System.Windows.Forms.DialogResult.OK)
                {
                    map.vsp = new Vsp24();
                }
                else if (dr == System.Windows.Forms.DialogResult.Cancel)
                {
                    return(null);
                }
                else
                {
                    return(null);
                }
            }
            else
            {
                map.vsp = ReadVsp(vspfile.FullName);
            }

            map.FormalName    = Helper.BytesToString(formal);
            map.MusicFileName = Helper.BytesToString(musicname);
            //map.RenderString = Helper.BytesToString(renderstring);
            string rs = Helper.BytesToString(renderstring);

            map.AutoExecEvent = Helper.BytesToString(aexec);

            map.PlayerStartX = br.ReadInt16();
            map.PlayerStartY = br.ReadInt16();

            int layercount = br.ReadInt32();

            for (int i = 0; i < layercount; i++)
            {
                MapLayer ml = new MapLayer(map);
                ml.name                   = Helper.BytesToString(br.ReadBytes(256));
                ml.type                   = LayerType.Tile;
                ml.parallaxInfo           = new ParallaxInfo();
                ml.parallaxInfo.MultipleX = br.ReadDouble();
                ml.parallaxInfo.MultipleY = br.ReadDouble();
                int w = br.ReadInt16();
                int h = br.ReadInt16();
                ml.size(w, h);
                ml.Translucency = br.ReadByte();
                int len  = br.ReadInt32();
                int zlen = br.ReadInt32();
                ml.Data = ZLIB.DecodeShorts(br.ReadBytes(zlen), len);

                map.Layers.Add(ml);
            }

            MapLayer ol = new MapLayer(map);

            ol.type = LayerType.Obs;
            ol.name = "Obstructions";
            ol.size(((MapLayer)map.Layers[0]).Width, ((MapLayer)map.Layers[0]).Height);
            int ol_lenn = br.ReadInt32();
            int ol_len  = br.ReadInt32();

            byte[] obsdata = ZLIB.Decode(br.ReadBytes(ol_len), ol_lenn);
            for (int i = 0; i < obsdata.Length; i++)
            {
                ol.Data[i] = obsdata[i];
            }
            map.ObsLayer = ol;


            int      zl_lenn = br.ReadInt32();
            int      zl_len  = br.ReadInt32();
            MapLayer zl      = new MapLayer(map);

            zl.type = LayerType.Zone;
            zl.name = "Zones";
            zl.size(((MapLayer)map.Layers[0]).Width, ((MapLayer)map.Layers[0]).Height);
            zl.Data       = ZLIB.DecodeShorts(br.ReadBytes(zl_len), zl_lenn);
            map.ZoneLayer = zl;


            MapLayer el = new MapLayer(map);

            el.type      = LayerType.Entity;
            el.name      = "Entities";
            map.EntLayer = el;
            map.Layers.Add(el);

            MapLayerSpecial rl = new MapLayerSpecial(map);

            rl.type = LayerType.Special_Retrace;


            map.Layers.Add(rl);
            map.Layers.Add(ol);
            map.Layers.Add(zl);


            int zonecount = br.ReadInt32();

            for (int i = 0; i < zonecount; i++)
            {
                MapZone mz      = new MapZone();
                byte[]  zname   = br.ReadBytes(256);
                byte[]  pscript = br.ReadBytes(256);
                //				byte[] escript = br.ReadBytes(256);
                mz.Name         = Helper.BytesToString(zname);
                mz.PlayerScript = Helper.BytesToString(pscript);
                //				mz.EntityScript = Helper.BytesToString(escript);
                mz.Rate   = br.ReadByte();
                mz.Delay  = br.ReadByte();
                mz.AdjAct = br.ReadByte();
                mz.ID     = i;
                map.Zones.Add(mz);
            }
            if (zonecount == 0)
            {
                MapZone mz = new MapZone();
                mz.ID   = 0;
                mz.Name = "NULL_ZONE";
                map.Zones.Add(mz);
            }

            int entcount = br.ReadInt32();

            for (int i = 0; i < entcount; i++)
            {
                MapEntity me = new MapEntity();
                me.TileX  = br.ReadInt16();
                me.TileY  = br.ReadInt16();
                me.Facing = br.ReadByte();

                me.ObeyObstruction = br.ReadByte();
                me.IsObstruction   = br.ReadByte();
                me.AutoFace        = br.ReadByte();
                me.Speed           = br.ReadInt16();
                me.ActivationMode  = br.ReadByte();

                me.MoveType           = br.ReadByte();
                me.WanderRectangle.x0 = br.ReadInt16();
                me.WanderRectangle.y0 = br.ReadInt16();
                me.WanderRectangle.x1 = br.ReadInt16();
                me.WanderRectangle.y1 = br.ReadInt16();
                me.WanderDelay        = br.ReadInt16();

                int expand = br.ReadInt32();

                me.MoveScript  = Helper.BytesToString(br.ReadBytes(256));
                me.ChrName     = Helper.BytesToString(br.ReadBytes(256));
                me.Description = Helper.BytesToString(br.ReadBytes(256));
                me.onActivate  = Helper.BytesToString(br.ReadBytes(256));
                me.ID          = map.Entities.Add(me);
            }
            br.Close();
            string rs2 = "";

            if (version == 1)
            {
                foreach (char c in rs)
                {
                    if (rs2.Length != 0)
                    {
                        rs2 += ",";
                    }
                    rs2 += c;
                }
                map.RenderString = rs2;
            }
            else
            {
                map.RenderString = rs;
            }
            return(map);
        }
コード例 #3
0
ファイル: InputOutput.cs プロジェクト: zeromus/maped3
        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];

            MapLayer el = new MapLayer(map);
            el.type = LayerType.Entity;
            el.name = "Entities";
            map.Layers.Add(el);
            map.EntLayer = el;

            MapLayerSpecial rl = new MapLayerSpecial(map);
            rl.type = LayerType.Special_Retrace;

            map.Layers.Add(rl);
            map.Layers.Add(map.ObsLayer);
            map.Layers.Add(map.ZoneLayer);
            int zoneCount = br.ReadInt32();

            // 50 bytes per zone
            for (int i = 0; i < zoneCount; i++)
            {
                MapZone mz = new MapZone();

                mz.ID = i;

                mz.Name = Helper.CharsToString(br.ReadChars(40));
                //Errors.Error(mz.Name);

                mz.PlayerScript = "";
                br.ReadInt16();
                mz.Rate = (int)br.ReadInt16();
                mz.Delay = (int)br.ReadInt16();

                mz.Flags = (int)br.ReadInt16();
                mz.EntityScript = "";
                br.ReadInt16();

                map.Zones.Add(mz);
            }
            if (zoneCount == 0)
            {
                MapZone mz = new MapZone();
                mz.ID = 0;
                mz.Name = "NULL_ZONE";
                map.Zones.Add(mz);
            }

            int chrCount = (int)br.ReadByte();
            ArrayList al_chrs = new ArrayList();

            for (int i = 0; i < chrCount; i++)
            {
                MapChr mc = new MapChr();

                try
                {
                    mc.Name = Helper.BytesToFileString(br.ReadBytes(60));
                }
                catch (Exception e)
                {
                    mc.Name = "";

                    /// there's no error log in maped3 yet.  I'll discuss this with the boys.  For now, ANNOYING MESSAGE BOX!
                    /// -gru

                    Errors.Error("I/O", "Bad filename for MapChr(" + i + "): " + e.Message + "\nDefaulting to empty string for file name.");
                }

                mc.ID = i;

                if (mc.Name.Length > 0)
                {
                    FileInfo mcfi = new FileInfo(mc.Name);
                    if (ReadCHR(mcfi, mc) == 0) mc.bImageAvailable = true;
                }
                al_chrs.Add(mc);
            }

            int entCount = (int)br.ReadByte();
            //Errors.Error(entCount.ToString() + ", "+br.BaseStream.Position.ToString());

            for (int i = 0; i < entCount; i++)
            {
                MapEntity me = new MapEntity();

                me.TileX = (int)br.ReadInt32();
                me.TileY = (int)br.ReadInt32();

                int xx = (int)br.ReadInt16();
                int xy = (int)br.ReadInt16();

                //Errors.Error(""+ me.TileX+","+me.TileY+":"+xx+","+xy);
                // ignore
                //br.ReadBytes(4);

                me.Facing = (int)br.ReadByte();
                if (me.Facing == 0)
                    me.Facing = 2;
                me.Moving = (int)br.ReadByte();

                // ignore
                br.ReadByte();

                me.BottomLineFrame = (int)br.ReadByte();
                me.SpecialFrameSet = (int)br.ReadByte();
                int cidx = (int)br.ReadByte();
                // assign chr
                // dont do this
                //me.Chr = ((MapChr)al_chrs[cidx]).Clone();
                me.ChrName = string.Copy(((MapChr)al_chrs[cidx]).Name);

                me.Reset = (int)br.ReadByte();
                me.ObeyObstruction = (int)br.ReadByte();
                me.IsObstruction = (int)br.ReadByte();
                me.Speed = (int)br.ReadByte();
                switch (me.Speed)
                {
                    case 1: me.Speed = 25; break;
                    case 2: me.Speed = 33; break;
                    case 3: me.Speed = 50; break;
                    case 4: me.Speed = 100; break;
                    case 5: me.Speed = 200; break;
                    case 6: me.Speed = 300; break;
                    case 7: me.Speed = 400; break;
                }

                // ignore
                br.ReadBytes(10); // entspeedcnt(1), anim frame delay(1), anim script(4), move script(4)

                //32

                me.AutoFace = (int)br.ReadByte();
                me.ActivationMode = (int)br.ReadByte();
                me.MoveType = (int)br.ReadByte();
                if (me.MoveType > 1) me.MoveType--;
                me.__movescript = (int)br.ReadByte();

                // ignore
                br.ReadBytes(2); // subtile move ctr, mode flag

                me.WanderSteps = (int)br.ReadInt16();
                me.WanderDelay = (int)br.ReadInt16();

                // ignore
                br.ReadBytes(4); // step ctr, delay ctr

                me.ID = i;

                br.ReadBytes(2); // WTF IS THIS!!

                for (int j = 0; j < 6; j++)
                {
                    me.UserData[j] = br.ReadInt16();
                }

                me.WanderRectangle.x0 = me.UserData[1];
                me.WanderRectangle.y0 = me.UserData[2];
                me.WanderRectangle.x1 = me.UserData[4];
                me.WanderRectangle.y1 = me.UserData[5];

                // ignore
                br.ReadBytes(20); // a lot of shiznit

                me.Description = Helper.BytesToString(br.ReadBytes(20));

                //Errors.Error(me.Description);

                //br.ReadBytes(2); // WTF IS THIS!!

                me.ID = i;
                map.Entities.Add(me);
            }

            int movescriptCount = (int)br.ReadByte();
            int movescriptBuffersize = (int)br.ReadInt32();

            ArrayList al_scripts = new ArrayList();
            // ignore
            br.ReadBytes(4 * movescriptCount);

            string script = "";
            while (movescriptBuffersize > 0)
            {
                char c = br.ReadChar();

                if (c == (char)0)
                {
                    al_scripts.Add(string.Copy(script));
                    script = "";
                }
                else script += c;
                movescriptBuffersize--;
            }
            // add all the scripts to their respective entities and trash the movescript array

            foreach (MapEntity me in map.Entities)
            {
                me.MoveScript = (string)al_scripts[me.__movescript];
            }

            br.Close();

            string rs2 = "";
            foreach (char c in dontcare)
            {
                if (rs2.Length != 0)
                    rs2 += ",";
                rs2 += c;
            }
            map.RenderString = rs2;
            return map;
        }
コード例 #4
0
ファイル: InputOutput.cs プロジェクト: zeromus/maped3
        public static unsafe Map ReadMap3(FileInfo fi)
        {
            byte[] m3s = new byte[] { (byte)'V', (byte)'3', (byte)'M', (byte)'A', (byte)'P', (byte)0 };

            FileStream fs = fi.OpenRead();
            BinaryReader br = new BinaryReader(fs);

            Map map = new Map();

            map.FileOnDisk = fi;

            //			Directory.SetCurrentDirectory(map.FileOnDisk.Directory.FullName);

            byte[] sig = br.ReadBytes(m3s.Length);
            for (int i = 0; i < m3s.Length; i++)
                if (sig[i] != m3s[i]) return null;

            int version = br.ReadInt32();

            int vcofs = br.ReadInt32();

            if (version >= 3)
            {
                int numNotes = br.ReadInt32();
                for (int i = 0; i < numNotes; i++)
                {
                    Map.Note note = new Map.Note();
                    note.x = br.ReadInt32();
                    note.y = br.ReadInt32();
                    int strlen = br.ReadInt32();
                    byte[] bytes = br.ReadBytes(strlen);
                    note.note = System.Text.Encoding.ASCII.GetString(bytes);
                    map.Notes.Add(note);
                }
            }

            byte[] formal = br.ReadBytes(256);
            byte[] vspname = br.ReadBytes(256);
            byte[] musicname = br.ReadBytes(256);
            byte[] renderstring = br.ReadBytes(256);
            byte[] aexec = br.ReadBytes(256);

            string vspf = Helper.BytesToString(vspname);
            FileInfo vspfile;
            try
            {

                vspfile = new FileInfo(vspf);
            }
            catch (ArgumentException)
            {
                throw new Exception("VSP file is inaccessible. Requested file was '" + vspf + "'");
            }
            if (!vspfile.Exists)
            {
                System.Windows.Forms.DialogResult dr = System.Windows.Forms.MessageBox.Show("Unable to load requested VSP file.  Create a blank vsp?", "Load Error", System.Windows.Forms.MessageBoxButtons.YesNoCancel, System.Windows.Forms.MessageBoxIcon.Information);
                if (dr == System.Windows.Forms.DialogResult.OK)
                    map.vsp = new Vsp24();
                else if (dr == System.Windows.Forms.DialogResult.Cancel)
                    return null;
                else return null;
            }
            else
            {
                map.vsp = ReadVsp(vspfile.FullName);
            }

            map.FormalName = Helper.BytesToString(formal);
            map.MusicFileName = Helper.BytesToString(musicname);
            //map.RenderString = Helper.BytesToString(renderstring);
            string rs = Helper.BytesToString(renderstring);
            map.AutoExecEvent = Helper.BytesToString(aexec);

            map.PlayerStartX = br.ReadInt16();
            map.PlayerStartY = br.ReadInt16();

            int layercount = br.ReadInt32();

            for (int i = 0; i < layercount; i++)
            {
                MapLayer ml = new MapLayer(map);
                ml.name = Helper.BytesToString(br.ReadBytes(256));
                ml.type = LayerType.Tile;
                ml.parallaxInfo = new ParallaxInfo();
                ml.parallaxInfo.MultipleX = br.ReadDouble();
                ml.parallaxInfo.MultipleY = br.ReadDouble();
                int w = br.ReadInt16();
                int h = br.ReadInt16();
                ml.size(w, h);
                ml.Translucency = br.ReadByte();
                int len = br.ReadInt32();
                int zlen = br.ReadInt32();
                ml.Data = ZLIB.DecodeShorts(br.ReadBytes(zlen), len);

                map.Layers.Add(ml);
            }

            MapLayer ol = new MapLayer(map);
            ol.type = LayerType.Obs;
            ol.name = "Obstructions";
            ol.size(((MapLayer)map.Layers[0]).Width, ((MapLayer)map.Layers[0]).Height);
            int ol_lenn = br.ReadInt32();
            int ol_len = br.ReadInt32();
            byte[] obsdata = ZLIB.Decode(br.ReadBytes(ol_len), ol_lenn);
            //patch up total garbage obstruction data
            for (int i = 0; i < obsdata.Length; i++)
            {
                ol.Data[i] = obsdata[i];
            #if ASTRAL
                if (ol.Data[i] >= 16) //NUM_OBS
                    ol.Data[i] = 15;
            #endif
            }
            map.ObsLayer = ol;

            int zl_lenn = br.ReadInt32();
            int zl_len = br.ReadInt32();
            MapLayer zl = new MapLayer(map);
            zl.type = LayerType.Zone;
            zl.name = "Zones";
            zl.size(((MapLayer)map.Layers[0]).Width, ((MapLayer)map.Layers[0]).Height);
            zl.Data = ZLIB.DecodeShorts(br.ReadBytes(zl_len), zl_lenn);
            map.ZoneLayer = zl;

            MapLayer el = new MapLayer(map);
            el.type = LayerType.Entity;
            el.name = "Entities";
            map.EntLayer = el;
            map.Layers.Add(el);

            MapLayerSpecial rl = new MapLayerSpecial(map);
            rl.type = LayerType.Special_Retrace;

            map.Layers.Add(rl);
            map.Layers.Add(ol);
            map.Layers.Add(zl);

            int zonecount = br.ReadInt32();
            for (int i = 0; i < zonecount; i++)
            {
                MapZone mz = new MapZone();
                byte[] zname = br.ReadBytes(256);
                byte[] pscript = br.ReadBytes(256);
                //				byte[] escript = br.ReadBytes(256);
                mz.Name = Helper.BytesToString(zname);
                mz.PlayerScript = Helper.BytesToString(pscript);
                //				mz.EntityScript = Helper.BytesToString(escript);
                mz.Rate = br.ReadByte();
                mz.Delay = br.ReadByte();
                mz.Flags = br.ReadByte();
                mz.ID = i;
                map.Zones.Add(mz);
            }
            if (zonecount == 0)
            {
                MapZone mz = new MapZone();
                mz.ID = 0;
                mz.Name = "NULL_ZONE";
                map.Zones.Add(mz);
            }

            int entcount = br.ReadInt32();
            for (int i = 0; i < entcount; i++)
            {
                MapEntity me = new MapEntity();
                me.TileX = br.ReadInt16();
                me.TileY = br.ReadInt16();
                me.Facing = br.ReadByte();

                me.ObeyObstruction = br.ReadByte();
                me.IsObstruction = br.ReadByte();
                me.AutoFace = br.ReadByte();
                me.Speed = br.ReadInt16();
                me.ActivationMode = br.ReadByte();

                me.MoveType = br.ReadByte();
                me.WanderRectangle.x0 = br.ReadInt16();
                me.WanderRectangle.y0 = br.ReadInt16();
                me.WanderRectangle.x1 = br.ReadInt16();
                me.WanderRectangle.y1 = br.ReadInt16();
                me.WanderDelay = br.ReadInt16();

                int expand = br.ReadInt32();

                me.MoveScript = Helper.BytesToString(br.ReadBytes(256));
                me.ChrName = Helper.BytesToString(br.ReadBytes(256));
                me.Description = Helper.BytesToString(br.ReadBytes(256));
                me.onActivate = Helper.BytesToString(br.ReadBytes(256));
                map.Entities.Add(me);
                me.ID = map.Entities.Count-1;
            }
            br.Close();
            string rs2 = "";
            if (version == 1)
            {
                foreach (char c in rs)
                {
                    if (rs2.Length != 0)
                        rs2 += ",";
                    rs2 += c;
                }
                map.RenderString = rs2;
            }
            else
                map.RenderString = rs;
            return map;
        }
コード例 #5
0
ファイル: NewMapWnd.cs プロジェクト: salviati/verge3
        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);
        }