Пример #1
0
        void FieldsToItem()
        {
            if (!bInvokeItems)
            {
                return;
            }
            if (lv_ents.SelectedItems.Count == 0)
            {
                return;
            }
            if (curr == null)
            {
                return;
            }

            MapEntity me = curr;

            me.Description        = t_desc.Text;
            me.TileX              = (int)n_x.Value;
            me.TileY              = (int)n_y.Value;
            me.Facing             = (int)c_facing.SelectedIndex + 1;
            me.ChrName            = t_chrfile.Text;
            me.ObeyObstruction    = ck_obeyobs.Checked?1:0;
            me.IsObstruction      = ck_isobs.Checked?1:0;
            me.Speed              = (int)n_movespeed.Value;
            me.MoveType           = (int)c_movetype.SelectedIndex;
            me.WanderRectangle.x0 = (int)n_wx0.Value;
            me.WanderRectangle.y0 = (int)n_wy0.Value;
            me.WanderRectangle.x1 = (int)n_wx1.Value;
            me.WanderRectangle.y1 = (int)n_wy1.Value;
            me.MoveScript         = t_movescript.Text;
            me.WanderDelay        = (int)n_wanderdelay.Value;
            me.AutoFace           = chk_autoface.Checked?1:0;
            me.onActivate         = t_onActivate.Text;
        }
Пример #2
0
        public MapEntity Clone()
        {
            MapEntity m = new MapEntity();

            m.TileX           = TileX;
            m.TileY           = TileY;
            m.Facing          = Facing;
            m.Moving          = Moving;
            m.BottomLineFrame = BottomLineFrame;
            m.SpecialFrameSet = this.SpecialFrameSet;
            m.MapChrIndex     = this.MapChrIndex;
            m.Reset           = this.Reset;
            m.ObeyObstruction = this.ObeyObstruction;
            m.IsObstruction   = this.IsObstruction;
            m.Speed           = this.Speed;
            m.AutoFace        = this.AutoFace;
            m.ActivationMode  = this.ActivationMode;
            m.MoveType        = this.MoveType;
            m.WanderDelay     = this.WanderDelay;
            m.WanderSteps     = this.WanderSteps;
            m.Description     = this.Description;
            m.MoveScript      = this.MoveScript;
            m.__movescript    = this.__movescript;
            m.ID                 = this.ID;
            m.Chr                = this.Chr;
            m.ChrName            = this.ChrName;
            m.WanderRectangle.x0 = this.WanderRectangle.x0;
            m.WanderRectangle.y0 = this.WanderRectangle.y0;
            m.WanderRectangle.x1 = this.WanderRectangle.x1;
            m.WanderRectangle.y1 = this.WanderRectangle.y1;

            m.onActivate = this.onActivate;

            return(m);
        }
Пример #3
0
 private void update_IDs()
 {
     for (int i = 0; i < entCopy.Count; i++)
     {
         MapEntity me = (MapEntity)entCopy[i];
         me.ID = i;
     }
     ResetListView();
 }
Пример #4
0
        void UpdateListView()
        {
            if (lv_ents.SelectedItems.Count == 0)
            {
                return;
            }
            ListViewItem lvi = (ListViewItem)lv_ents.SelectedItems[0];
            MapEntity    me  = (MapEntity)lvi.Tag;

            lvi.SubItems[1].Text = me.Description + "; " + me.ChrName;
        }
Пример #5
0
 public void seek(MapEntity me)
 {
     foreach (ListViewItem lvi in lv_ents.Items)
     {
         MapEntity me_ = (MapEntity)lvi.Tag;
         if (me_.ID == me.ID)
         {
             lvi.Selected = true;
             lvi.EnsureVisible();
         }
     }
 }
Пример #6
0
        MapZone get_ent_zone(int entity)
        {
            MapEntity me = (MapEntity)entCopy[entity];

            if (map.Zones.Count == 0)
            {
                return(null);
            }
            MapZone mz = (MapZone)map.Zones[map.ZoneLayer.getTile(me.TileX, me.TileY)];

            return(mz);
        }
Пример #7
0
        private void button1_Click(object sender, System.EventArgs e)
        {
            MapEntity me = new MapEntity();

            me.ID = entCopy.Count;
            entCopy.Add(me);
            ListViewItem lvi = new ListViewItem(new string[] { me.ID.ToString(), me.Description + "; " + me.ChrName });

            lvi.Tag = me;
            lv_ents.Items.Add(lvi);
            lvi.Selected = true;
            lvi.EnsureVisible();
        }
Пример #8
0
        private void m_delent_Click(object sender, System.EventArgs e)
        {
            if (lv_ents.SelectedItems.Count == 0)
            {
                return;
            }
            MapEntity me = (MapEntity)lv_ents.SelectedItems[0].Tag;

            if (MessageBox.Show("Are you sure you want to delete Entity #" + me.ID + "? This action can not be undone. \r\nWARNING: If there are entities in the list with a higher ID than this entity, they will be shifted down and will henceforth have a different ID.", "Warning", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning)
                == DialogResult.Cancel)
            {
                return;
            }
            entCopy.Remove(me);
            update_IDs();
        }
Пример #9
0
        private void lv_ents_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            FieldsToItem();
            if (lv_ents.SelectedIndices.Count == 0)
            {
                EmptyFields();
                DisableEditor();
                b_delent.Enabled = false;
                return;
            }
            ListViewItem lvi = (ListViewItem)lv_ents.SelectedItems[0];
            MapEntity    me  = (MapEntity)lvi.Tag;

            curr = me;
            ItemsToField(me);
            EnableEditor();
            b_delent.Enabled = true;
        }
Пример #10
0
 void ItemsToField(MapEntity me)
 {
     bInvokeItems             = false;
     t_desc.Text              = me.Description;
     n_x.Value                = me.TileX;
     n_y.Value                = me.TileY;
     c_facing.SelectedIndex   = me.Facing - 1;
     t_chrfile.Text           = me.ChrName;
     ck_obeyobs.Checked       = (me.ObeyObstruction == 1);
     ck_isobs.Checked         = (me.IsObstruction == 1);
     n_movespeed.Value        = me.Speed;
     c_movetype.SelectedIndex = me.MoveType;
     n_wx0.Value              = me.WanderRectangle.x0;
     n_wy0.Value              = me.WanderRectangle.y0;
     n_wx1.Value              = me.WanderRectangle.x1;
     n_wy1.Value              = me.WanderRectangle.y1;
     t_movescript.Text        = me.MoveScript;
     n_wanderdelay.Value      = me.WanderDelay;
     chk_autoface.Checked     = (me.AutoFace == 1);
     t_onActivate.Text        = me.onActivate;
     bInvokeItems             = true;
 }
Пример #11
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);
        }
Пример #12
0
        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;
        }
Пример #13
0
        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;
        }
Пример #14
0
 private void lv_ents_SelectedIndexChanged(object sender, System.EventArgs e)
 {
     FieldsToItem();
     if(lv_ents.SelectedIndices.Count==0)
     {
         EmptyFields();
         DisableEditor();
         b_delent.Enabled=false;
         return;
     }
     ListViewItem lvi = (ListViewItem)lv_ents.SelectedItems[0];
     MapEntity me = (MapEntity)lvi.Tag;
     curr = me;
     ItemsToField(me);
     EnableEditor();
     b_delent.Enabled=true;
 }
Пример #15
0
 public void seek(MapEntity me)
 {
     foreach(ListViewItem lvi in lv_ents.Items)
     {
         MapEntity me_ = (MapEntity)lvi.Tag;
         if(me_.ID==me.ID)
         {
             lvi.Selected=true;
             lvi.EnsureVisible();
         }
     }
 }
Пример #16
0
 private void button1_Click(object sender, System.EventArgs e)
 {
     MapEntity me = new MapEntity();
     me.ID = entCopy.Count;
     entCopy.Add(me);
     ListViewItem lvi = new ListViewItem( new string[] { me.ID.ToString(), me.Description + "; "+me.ChrName } );
     lvi.Tag=me;
     lv_ents.Items.Add(lvi);
     lvi.Selected=true;
     lvi.EnsureVisible();
 }
Пример #17
0
 void ItemsToField(MapEntity me)
 {
     bInvokeItems=false;
     t_desc.Text = me.Description;
     n_x.Value = me.TileX;
     n_y.Value = me.TileY;
     c_facing.SelectedIndex = me.Facing -1;
     t_chrfile.Text = me.ChrName;
     ck_obeyobs.Checked = (me.ObeyObstruction==1);
     ck_isobs.Checked = (me.IsObstruction==1);
     n_movespeed.Value = me.Speed;
     c_movetype.SelectedIndex = me.MoveType;
     n_wx0.Value = me.WanderRectangle.x0;
     n_wy0.Value = me.WanderRectangle.y0;
     n_wx1.Value = me.WanderRectangle.x1;
     n_wy1.Value = me.WanderRectangle.y1;
     t_movescript.Text = me.MoveScript;
     n_wanderdelay.Value = me.WanderDelay;
     chk_autoface.Checked = (me.AutoFace==1);
     t_onActivate.Text = me.onActivate;
     bInvokeItems=true;
 }
Пример #18
0
        public int __movescript; //v2 compatibility

        #endregion Fields

        #region Methods

        public MapEntity Clone()
        {
            MapEntity m = new MapEntity();
            m.TileX = TileX;
            m.TileY = TileY;
            m.Facing = Facing;
            m.Moving = Moving;
            m.BottomLineFrame = BottomLineFrame;
            m.SpecialFrameSet = this.SpecialFrameSet;
            m.MapChrIndex = this.MapChrIndex;
            m.Reset = this.Reset;
            m.ObeyObstruction = this.ObeyObstruction;
            m.IsObstruction = this.IsObstruction;
            m.Speed = this.Speed;
            m.AutoFace = this.AutoFace;
            m.ActivationMode = this.ActivationMode;
            m.MoveType = this.MoveType;
            m.WanderDelay = this.WanderDelay;
            m.WanderSteps = this.WanderSteps;
            m.Description = this.Description;
            m.MoveScript = this.MoveScript;
            m.__movescript = this.__movescript;
            m.ID = this.ID;
            m.Chr = this.Chr;
            m.ChrName = this.ChrName;
            m.WanderRectangle.x0 = this.WanderRectangle.x0;
            m.WanderRectangle.y0 = this.WanderRectangle.y0;
            m.WanderRectangle.x1 = this.WanderRectangle.x1;
            m.WanderRectangle.y1 = this.WanderRectangle.y1;

            m.onActivate = this.onActivate;

            return m;
        }