コード例 #1
0
ファイル: tile.cs プロジェクト: vikas100/hostile-takeover
        public Tile(SerializationInfo info, StreamingContext ctx) : base(info, ctx)
        {
            m_strName = null;
            try {
                m_strName = info.GetString("Name");
            } catch {
                m_strName = info.GetInt32("Cookie").ToString();
            }

            m_afVisible = (bool[, ])info.GetValue("Visibility", typeof(bool[, ]));

            try {
                m_afOccupancy = (bool[, ])info.GetValue("Occupancy", typeof(bool[, ]));
            } catch {
                TemplateDoc tmpd = (TemplateDoc)DocManager.GetActiveDocument(typeof(TemplateDoc));
                Template    tmpl = tmpd.FindTemplate(m_strName);
                if (tmpl != null)
                {
                    m_afOccupancy = tmpl.OccupancyMap;
                }
                else
                {
                    m_afOccupancy = new bool[1, 1];
                }
            }

            InitCommon();
        }
コード例 #2
0
        private void buttonModify_Click(object sender, System.EventArgs e)
        {
            string str = (string)listBox1.SelectedItem;

            if (str == null)
            {
                return;
            }
            SwitchManager swm    = ((LevelDoc)DocManager.GetActiveDocument(typeof(LevelDoc))).SwitchManager;
            Switch        sw     = swm[str];
            string        strNew = EditStringForm.DoModal("Modify Switch", "New switch name:", str);

            if (strNew == null)
            {
                return;
            }
            if (strNew != str)
            {
                sw.Name = strNew;
                listBox1.Items.Remove(str);
                int i = listBox1.Items.Add(strNew);
                listBox1.SelectedIndex = i;
                // UNDONE: doc is modified
            }
        }
コード例 #3
0
        private void comboDocs_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e)
        {
            if (e.Index < 0 || e.Index >= comboDocs.Items.Count)
            {
                return;
            }
            string strName;

            if (e.Index == 0)
            {
                Document docActive = DocManager.GetActiveDocument(typeof(TemplateDoc));
                if (docActive == null)
                {
                    strName = "None";
                }
                else
                {
                    strName = "Active (" + docActive.GetName() + ")";
                }
                m_tmpdCurrent = null;
            }
            else
            {
                Document doc = (Document)comboDocs.Items[e.Index];
                m_tmpdCurrent = (TemplateDoc)doc;
                strName       = doc.GetName();
            }
            e.DrawBackground();
            e.Graphics.DrawString(strName, e.Font, new SolidBrush(e.ForeColor), e.Bounds.X, e.Bounds.Y);
            e.DrawFocusRectangle();
        }
コード例 #4
0
        public Switch GetSelectedSwitch()
        {
            if (listBox1.SelectedIndex == -1)
            {
                return(null);
            }
            SwitchManager swm = ((LevelDoc)DocManager.GetActiveDocument(typeof(LevelDoc))).SwitchManager;

            return(swm[(string)listBox1.SelectedItem]);
        }
コード例 #5
0
        public Counter GetSelectedCounter()
        {
            if (listBox1.SelectedIndex == -1)
            {
                return(null);
            }
            CounterManager ctrm = ((LevelDoc)DocManager.GetActiveDocument(typeof(LevelDoc))).CounterManager;

            return(ctrm[(string)listBox1.SelectedItem]);
        }
コード例 #6
0
        public LevelFrame(Form frmParent, Document doc, Type typeView)
        {
            InitializeComponent();

            LevelDocTemplate doct = (LevelDocTemplate)DocManager.FindDocTemplate(typeof(LevelDoc));

            doct.DocActive += new LevelDocTemplate.DocActiveHandler(LevelDocTemplate_DocActive);

            m_doc = doc;

            doc.PathChanged             += new Document.PathChangedHandler(Document_PathChanged);
            doc.ModifiedChanged         += new Document.ModifiedChangedHandler(Document_ModifiedChanged);
            doc.OpenCountChanged        += new Document.OpenCountChangedHandler(Document_OpenCountChanged);
            ((LevelDoc)doc).NameChanged += new LevelDoc.NameChangedHandler(LevelDoc_NameChanged);

            // Parent this and create panes

            MdiParent = frmParent;
            ChangePanes(2);

            // See if the top most mdi frame is maximized. If so, maximize this too
            // If no window around, maximize

            bool fMaximize = true;

            if (frmParent.ActiveMdiChild != null)
            {
                if (frmParent.ActiveMdiChild.WindowState != FormWindowState.Maximized)
                {
                    fMaximize = false;
                }
            }
            if (fMaximize)
            {
                WindowState = FormWindowState.Maximized;
            }

            // Set Title

            s_alsFrames.Add(this);
            SetTitle();

            // If this doc is active, this is the new command target

            if (m_doc == DocManager.GetActiveDocument(typeof(LevelDoc)))
            {
                DocManager.SetCommandTarget(this);
            }

            // Show

            Show();
        }
コード例 #7
0
        private void buttonDelete_Click(object sender, System.EventArgs e)
        {
            string str = (string)listBox1.SelectedItem;

            if (str == null)
            {
                return;
            }
            SwitchManager swm = ((LevelDoc)DocManager.GetActiveDocument(typeof(LevelDoc))).SwitchManager;
            Switch        sw  = swm[str];

            swm.RemoveSwitch(sw);
            listBox1.Items.Remove(str);
            // UNDONE: doc is modified
        }
コード例 #8
0
        private void buttonDelete_Click(object sender, System.EventArgs e)
        {
            string str = (string)listBox1.SelectedItem;

            if (str == null)
            {
                return;
            }
            CounterManager ctrm = ((LevelDoc)DocManager.GetActiveDocument(typeof(LevelDoc))).CounterManager;
            Counter        ctr  = ctrm[str];

            ctrm.RemoveCounter(ctr);
            listBox1.Items.Remove(str);
            // UNDONE: doc is modified
        }
コード例 #9
0
        private void buttonNew_Click(object sender, System.EventArgs e)
        {
            string str = EditStringForm.DoModal("New Switch", "New switch name:", null);

            if (str != null)
            {
                SwitchManager swm = ((LevelDoc)DocManager.GetActiveDocument(typeof(LevelDoc))).SwitchManager;
                if (swm[str] == null)
                {
                    swm.AddSwitch(new Switch(str));
                    int i = listBox1.Items.Add(str);
                    listBox1.SelectedIndex = i;
                    // UNDONE: doc is modified
                }
            }
        }
コード例 #10
0
        private void buttonNew_Click(object sender, System.EventArgs e)
        {
            string str = EditStringForm.DoModal("New Counter", "New Counter name:", null);

            if (str != null)
            {
                CounterManager ctrm = ((LevelDoc)DocManager.GetActiveDocument(typeof(LevelDoc))).CounterManager;
                if (ctrm[str] == null)
                {
                    ctrm.AddCounter(new Counter(str));
                    int i = listBox1.Items.Add(str);
                    listBox1.SelectedIndex = i;
                    // UNDONE: doc is modified
                }
            }
        }
コード例 #11
0
        private void tbcOutput_DoubleClick(object sender, System.EventArgs e)
        {
            LevelDoc lvld = (LevelDoc)DocManager.GetActiveDocument(typeof(LevelDoc));

            if (lvld == null)
            {
                return;
            }

            // scan backwards from the insertion point to the beginning of the line

            string strT = tbcOutput.Text;
            int    i    = tbcOutput.SelectionStart;

            while (i > 0 && strT[i] != '\n')
            {
                i--;
            }
            if (i != 0)
            {
                i++;
            }
            strT = strT.Substring(i, strT.IndexOf('>', i) - i);

            // Select the item with the error

            i = int.Parse(strT);
            LevelError lvle = (LevelError)m_alLevelErrors[i];

            if (lvle.Object is IMapItem)
            {
                ArrayList al = new ArrayList();
                al.Add(lvle.Object);
                lvle.LevelDoc.Selection = al;
            }
            else if (lvle.Object is SideInfo)
            {
                Globals.PropertyGrid.SelectedObject = lvle.Object;
            }
        }
コード例 #12
0
        public static void ImportExpansionPdb(string strFile)
        {
            PdbPacker pdbp = new PdbPacker(strFile);

            ArrayList alsTileSets = new ArrayList();

            for (int i = 0; i < pdbp.Count; i++)
            {
                PdbPacker.File file = pdbp[i];
                if (!file.str.EndsWith(".lvl"))
                {
                    continue;
                }

                // Load up the pieces

                Ini     ini = Ini.LoadBinary(new MemoryStream(file.ab));
                string  strTileMapFilename = ini["General"]["TileMap"].Value;
                TileMap tmap = TileMap.Load(new MemoryStream(pdbp[strTileMapFilename].ab));


                // First, tell the active LevelDoc not to switch its templates based on the following
                // template load

                LevelDoc lvldActive = (LevelDoc)DocManager.GetActiveDocument(typeof(LevelDoc));
                if (lvldActive != null)
                {
                    lvldActive.SwitchTemplatesEnabled = false;
                }

                // If the TileSet for this level is not yet available, load it now

                TemplateDoc tmpd = (TemplateDoc)DocManager.OpenDocument(tmap.Filename.Replace(".tset", ".tc"));
                TileSet     tset = null;
                foreach (TileSet tsetT in alsTileSets)
                {
                    if (tsetT.FileName == tmap.Filename)
                    {
                        tset = tsetT;
                        break;
                    }
                }
                if (tset == null)
                {
                    tset = new TileSet(tmpd, tmap.Filename);
                    alsTileSets.Add(tset);
                }

                // Re-enable template switching

                if (lvldActive != null)
                {
                    lvldActive.SwitchTemplatesEnabled = true;
                }

                // Create a new level description, and deduce which templates are in it, with what visibility

                LevelDoc lvld = (LevelDoc)DocManager.NewDocument(typeof(LevelDoc), null);
                lvld.OutputFilename = file.str;
                ImportTileMap(tmap, tset, tmpd, lvld);

                // Walls are stored in the terrain map. Load them.
                string     strTrmapFilename = ini["General"]["TerrainMap"].Value;
                TerrainMap trmap            = TerrainMap.Load(new MemoryStream(pdbp[strTrmapFilename].ab));
                ImportWalls(trmap, lvld);

                // Load everything else
                lvld.LoadIni(ini);
            }
        }
コード例 #13
0
        public static void SaveExpansionPdb(string strFile, Document[] adoc, string strVersion)
        {
            // First save all level docs

            //annoying
            //DocManager.SaveAllModified(typeof(LevelDoc));

            // Remember active document

            LevelDoc lvldActive = (LevelDoc)DocManager.GetActiveDocument(typeof(LevelDoc));

            // Save documents adoc in an expansion .pdb. Expansion .pdbs need:
            // - .lvl, .tmap, .trmap, but not .tsets since these come from game .pdbs
            // - need a version.txt
            // - need an if demo trigger check "inserted" at save time
            // - .pdb needs WARI creator, ADD1 type
            // - data should be compressed for obfuscation purposes

            PdbPacker pdbp = new PdbPacker();

            // Add version.txt

            byte[] abT = new byte[strVersion.Length + 1];
            for (int n = 0; n < strVersion.Length; n++)
            {
                abT[n] = (byte)strVersion[n];
            }
            abT[abT.Length - 1] = 0;
            pdbp.Add(new PdbPacker.File("version.txt", abT));

            // Load res.h from embedded resource in prep for pre-process

            System.Reflection.Assembly ass = typeof(GobImage).Module.Assembly;
            Stream stmResDotH = ass.GetManifestResourceStream("m.EmbeddedResources." + "res.h");

            if (stmResDotH == null)
            {
                throw new Exception("Cannot load res.h");
            }

            // Compile levels

            Random    rand        = new Random();
            ArrayList alsTileSets = new ArrayList();

            foreach (LevelDoc lvld in adoc)
            {
                // Need to do this unfortunately; some of the "saving" code relies on what the "active" document
                // is!!

                DocManager.SetActiveDocument(typeof(LevelDoc), lvld);

                TemplateDoc tmpd = lvld.GetTemplateDoc();

                // Get appropriate TileSet, or make one if this map
                // uses a new tile collection

                TileSet tset = null;
                foreach (TileSet tsetT in alsTileSets)
                {
                    if (tsetT.TemplateDoc == tmpd)
                    {
                        tset = tsetT;
                        break;
                    }
                }

                // Create new tile set if none found

                if (tset == null)
                {
                    tset = new TileSet(tmpd, tmpd.GetName() + ".tset");
                    alsTileSets.Add(tset);
                }

#if false
                // Generate base file name for this level (this is never user-visible, but it should be
                // as unique as possible

                char[] achBase = new char[16];
                for (int n = 0; n < achBase.Length; n++)
                {
                    int nT = rand.Next() % (26 + 10);
                    if (nT < 26)
                    {
                        achBase[n] = (char)(nT + 97);
                    }
                    else
                    {
                        achBase[n] = (char)(nT + 48 - 26);
                    }
                }
                if (lvld.MaxPlayers > 1)
                {
                    achBase[0] = 'm';
                    achBase[1] = '_';
                }
                string strBase = new String(achBase);
#else
                // This isn't unique which can cause problems due to how packfiles work.
                // Could change packfile api to accept .pdb parameter.
                // Note1: set next mission action requires predictable filename
                // Note2: mission sorting is based on filename, not title
                // Could put lots of "support" in to fix these problems, or just ship
                // it like this.
                //
                // Hack: filename length 29
                // Maximum extension on filename: 7

                string strBase = lvld.Title;
                if (strBase.Length > 29 - 7)
                {
                    strBase = strBase.Substring(0, 29 - 7);
                }

                // If multiplayer, add "m_" to the name by losing the last two characters
                // so sort order is preserved

                if (lvld.MaxPlayers > 1)
                {
                    strBase = "m_" + strBase.Substring(0, strBase.Length - 2);
                }
#endif

                // Get tile map file for this level

                MemoryStream stmTmap = new MemoryStream();
                TileMap      tmap    = TileMap.CreateFromImage(tset, lvld.GetMapBitmap(tmpd.TileSize, tmpd, true), tmpd.TileSize);
                tmap.Save(stmTmap);
                string strTmap = strBase + ".tmap";
                pdbp.Add(new PdbPacker.File(strTmap, stmTmap.ToArray()));
                stmTmap.Close();

                // Get the terrain map file for this level

                MemoryStream stmTRmap = new MemoryStream();
                TerrainMap   trmap    = new TerrainMap(lvld.GetTerrainMap(tmpd.TileSize, tmpd, false));
                trmap.Save(stmTRmap);
                string strTRmap = strBase + ".trmap";
                pdbp.Add(new PdbPacker.File(strTRmap, stmTRmap.ToArray()));
                stmTRmap.Close();

                // Save .ini file for this level doc

                MemoryStream stmLvld = new MemoryStream();
                lvld.SaveIni(stmLvld, -1, strTmap, strTRmap, tmpd.GetName() + ".palbin", true);

                // Pre-process

                stmLvld.Seek(0, SeekOrigin.Begin);
                MemoryStream stmPreprocessed = Misc.PreprocessStream(stmLvld, stmResDotH);
                stmPreprocessed.Seek(0, SeekOrigin.Begin);
                Ini iniPreProcessed = new Ini(stmPreprocessed);

                MemoryStream stmLvldPreProcessedBinary = new MemoryStream();
                iniPreProcessed.SaveBinary(stmLvldPreProcessedBinary);
                stmLvldPreProcessedBinary.Close();

                string strLvlName = lvld.OutputFilename;
                if (strLvlName == null)
                {
                    strLvlName = strBase + ".lvl";
                }
                pdbp.Add(new PdbPacker.File(strLvlName, stmLvldPreProcessedBinary.ToArray()));
                stmLvldPreProcessedBinary.Close();
            }
            stmResDotH.Close();

            // Restore active document

            if (lvldActive != null)
            {
                DocManager.SetActiveDocument(typeof(LevelDoc), lvldActive);
            }

            // Now save out pdb

            pdbp.Save(strFile, "WARI", "ADD2");
        }