public void SaveIni(Stream stm, int nVersion, string strFileTmap, string strFileTrmap, string strFilePalette, bool fDemoCheckTrigger)
        {
            Ini ini = new Ini();
            Ini.Section sec;

            // [Intro]
            sec = new Ini.Section("Intro");
            sec.Add(new Ini.Property("String", "This is a test level!"));
            ini.Add(sec);

            // [Side1-n]
            int txOrigin = Bounds.X;
            int tyOrigin = Bounds.Y;

            // Hack - there should be a real "neutral" side
            ArrayList alsidiT = (ArrayList)m_alsidi.Clone();
            SideInfo sidiNeutral = new SideInfo(Side.sideNeutral);
            sidiNeutral.Intelligence = Intelligence.ComputerNeutral;
            sidiNeutral.InitialCredits = 0;
            sidiNeutral.InitialView = new Point(0, 0);
            alsidiT.Add(sidiNeutral);

            foreach (SideInfo sidi in alsidiT) {
                sec = new Ini.Section(sidi.Side.ToString());
                sec.Add(new Ini.Property("InitialView", String.Format("{0},{1}",
                    sidi.InitialView.X - txOrigin, sidi.InitialView.Y - tyOrigin)));
                sec.Add(new Ini.Property("InitialCredits", sidi.InitialCredits.ToString()));
                sec.Add(new Ini.Property("Intelligence", "knIntelligence" + sidi.Intelligence.ToString()));

                // How many units for this side?

                int cStructures = 0;
                int cMobileUnits = 0;
                foreach (IMapItem mi in m_alsmi) {
                    if (mi is Unit) {
                        Unit unt = (Unit)mi;
                        if (unt.Side == sidi.Side) {
                            if (mi is MobileUnit) {
                                cMobileUnits++;
                            }
                            if (mi is Structure) {
                                cStructures++;
                            }
                        }
                    }
                }
                sec.Add(new Ini.Property("InitialMobileUnitCount", cMobileUnits.ToString()));
                sec.Add(new Ini.Property("InitialStructureCount", cStructures.ToString()));
                ini.Add(sec);
            }

            // [GameObjects]
            sec = new Ini.Section("GameObjects");
            foreach (IMapItem mi in m_alsmi) {
                if (mi is Galaxite)
                    continue;
                if (mi is Area)
                    continue;
                if (mi is Wall)
                    continue;
                if (mi is Tile)
                    continue;

                Ini.Property prop = mi.GetIniProperty(txOrigin, tyOrigin);
                if (prop == null)
                    continue;

                // Skip Gobs that are out of bounds
                // UNDONE: can't do the right thing to make sure Gob's right/bottom
                // edges aren't out of bounds because M doesn't know the true
                // width and height of Gobs.

                if (!Bounds.Contains(new Rectangle((int)mi.tx, (int)mi.ty, mi.ctx, mi.cty))) {
                    Console.WriteLine("{0} out of bounds", mi);
                    continue;
                }
                sec.Add(prop);
            }
            ini.Add(sec);

            // [Galaxite]
            sec = new Ini.Section("Galaxite");
            foreach (IMapItem mi in m_alsmi) {
                if (!(mi is Galaxite))
                    continue;

                Ini.Property prop = mi.GetIniProperty(txOrigin, tyOrigin);
                if (prop == null)
                    continue;

                // Skip Galaxite that is out of bounds

                if (!Bounds.Contains((int)mi.tx, (int)mi.ty)) {
                    Console.WriteLine("{0} out of bounds", mi);
                    continue;
                }

                sec.Add(prop);
            }
            ini.Add(sec);

            #if false
            // In terrain now
            // [Walls]
            sec = new Ini.Section("Walls");
            foreach (IMapItem mi in m_alsmi) {
                if (!(mi is Wall))
                    continue;

                Ini.Property prop = mi.GetIniProperty(txOrigin, tyOrigin);
                if (prop == null)
                    continue;

                // Skip Walls that are out of bounds

                if (!Bounds.Contains((int)mi.tx, (int)mi.ty)) {
                    Console.WriteLine("{0} out of bounds", mi);
                    continue;
                }

                sec.Add(prop);
            }
            ini.Add(sec);
            #endif

            // [Areas]
            ArrayList alT = new ArrayList();
            foreach (IMapItem mi in m_alsmi) {
                if (!(mi is Area))
                    continue;
                alT.Add(mi);
            }
            alT.Sort();

            sec = new Ini.Section("Areas");
            foreach (IMapItem mi in alT) {
                Ini.Property prop = mi.GetIniProperty(txOrigin, tyOrigin);
                if (prop == null)
                    continue;

                Area area = (Area)mi;
                if (!Bounds.Contains(new Rectangle((int)mi.tx, (int)mi.ty, mi.ctx, mi.cty))) {
                    MessageBox.Show(String.Format("The area \"{0}\" lies outside of the map's bounds", area.Name), "Error Compiling Level");
                }

                sec.Add(prop);
            }
            ini.Add(sec);

            // [Triggers]
            // NOTE: Triggers must be written before UnitGroups because some trigger actions
            // e.g., CreateUnitAtArea will dynamically create UnitGroups and add them to the UnitGroup list
            ini.Add(m_tgrm.GetIniSection(fDemoCheckTrigger));

            // [UnitGroup 0-n]
            m_ugm.SaveIni(ini);

            // [Switches]
            sec = new Ini.Section("Switches");
            foreach (Switch sw in SwitchManager.Items)
                sec.Add(new Ini.Property(sw.Name, ""));
            ini.Add(sec);

            // [General]
            // This section is written last in case any of the values are modified by
            // the process of writing out the prior sections (e.g., CreateUnitAtArea actions add UnitGroups)
            sec = new Ini.Section("General", null);
            sec.Add(new Ini.Property("Title", Title));
            sec.Add(new Ini.Property("TileMap", strFileTmap));
            sec.Add(new Ini.Property("TerrainMap", strFileTrmap));
            sec.Add(new Ini.Property("Palette", strFilePalette));
            sec.Add(new Ini.Property("MinPlayers", m_nPlayersMin.ToString()));
            sec.Add(new Ini.Property("MaxPlayers", m_nPlayersMax.ToString()));
            sec.Add(new Ini.Property("UnitGroupCount", m_ugm.Items.Count.ToString()));

            // < 0 means use the current version, otherwise use the passed version
            // This is the "level file format" version

            if (nVersion < 0)
                nVersion = 1;
            sec.Add(new Ini.Property("Version", nVersion.ToString()));

            // Add a random number for the revision #. This # is used to determine if saved games are
            // based on older versions of a mission.

            if (nVersion > 0) {
                Random rand = new Random();
                uint dwRevision = (uint)rand.Next();
                sec.Add(new Ini.Property("Revision", dwRevision.ToString()));
            }

            ini.Add(sec);

            // Done

            ini.Save(stm);

            // Mostly Done.
            // Clean out the "__cuaa" unit groups created by CreateUnitAtAreaTriggerAction

            ArrayList alsRemove = new ArrayList();
            UnitGroup[] aug = (UnitGroup[])m_ugm.Items.ToArray(typeof(UnitGroup));
            for (int i = 0; i < m_ugm.Items.Count; i++) {
                if (((UnitGroup)m_ugm.Items[i]).Name.StartsWith("__cuaa")) {
                    alsRemove.Add(m_ugm.Items[i]);
                }
            }
            foreach (UnitGroup ug in alsRemove) {
                m_ugm.RemoveUnitGroup(ug);
            }
        }
 public void SaveIni(Ini ini)
 {
     for (int i = 0; i < m_alsUnitGroups.Count; i++) {
         Ini.Section sec = new Ini.Section("UnitGroup " + i);
         ((UnitGroup)m_alsUnitGroups[i]).AddIniProperties(sec);
         ini.Add(sec);
     }
 }
Beispiel #3
0
        void SaveSettings()
        {
            // Save settings in ini.

            Ini ini = new Ini();
            Ini.Section secGeneral = new Ini.Section("General");
            secGeneral.Add(new Ini.Property("SoundsDir", Path.GetFullPath(textBoxSoundsDir.Text)));
            secGeneral.Add(new Ini.Property("Sfx.h", m_strSfxH));
            ini.Add(secGeneral);

            // Place in directory where .exe resides

            ini.Save(Application.ExecutablePath.Replace(".exe", ".ini"));
        }
Beispiel #4
0
        void SaveSettings()
        {
            // Save settings in ini.

            Ini ini = new Ini();
            Ini.Section secGeneral = new Ini.Section("General");
            secGeneral.Add(new Ini.Property("WindowState", WindowState.ToString()));
            secGeneral.Add(new Ini.Property("X", Bounds.X.ToString()));
            secGeneral.Add(new Ini.Property("Y", Bounds.Y.ToString()));
            secGeneral.Add(new Ini.Property("Width", Bounds.Width.ToString()));
            secGeneral.Add(new Ini.Property("Height", Bounds.Height.ToString()));
            secGeneral.Add(new Ini.Property("AuthorKitPath", AuthorKitPath));
            secGeneral.Add(new Ini.Property("Kit", Globals.IsKit().ToString()));
            secGeneral.Add(new Ini.Property("Eula", "1"));

            ini.Add(secGeneral);

            // Place in directory where .exe resides

            try {
                if (m_strFileSettings != null)
                    ini.Save(m_strFileSettings);
            } catch {
            }
        }
        public Ini.Section GetIniSection(bool fDemoCheckTrigger)
        {
            // If asked create a trigger causes mission failure if running on
            // demo version side1

            bool fModifiedSave = m_fModified;
            Trigger tgrDemo = new Trigger();
            if (fDemoCheckTrigger) {
                // condition: persistent variable $demo is exactly 1
                // action: end mission: lose

                // Condition

                tgrDemo.Sides = SideToMask(Side.side1);
                TestPvarCondition cdn = new TestPvarCondition();
                cdn.Active = true;
                CaTypeText catText = (CaTypeText)cdn.GetTypes()[0];
                catText.Text = "$demo";
                CaTypeQualifiedNumber catQualNum = (CaTypeQualifiedNumber)cdn.GetTypes()[1];
                catQualNum.Qualifier = Qualifier.Exactly;
                catQualNum.Value = 1;
                tgrDemo.Conditions.Add(cdn);

                // Action

                EndMissionTriggerAction acn = new EndMissionTriggerAction();
                acn.Active = true;
                CaTypeWinLose catWinLose = (CaTypeWinLose)acn.GetTypes()[0];
                catWinLose.Result = WinLoseType.Lose;
                tgrDemo.Actions.Add(acn);

                // Add this trigger temporarily
                // Move it up to first place

                AddTrigger(tgrDemo);
                while (MoveUpTrigger(Side.side1, tgrDemo) != -1)
                    ;
            }

            // Save triggers

            Ini.Section sec = new Ini.Section("Triggers");
            sec.Add(new Ini.Property("Count", m_alsTriggers.Count.ToString()));
            foreach (Trigger tgr in m_alsTriggers) {
                // Calc per side indexes

                string strT = "";
                for (int n = 0; n < m_aalsSideTriggers.Length; n++) {
                    ArrayList als = (ArrayList)m_aalsSideTriggers[n];
                    int j = als.IndexOf(tgr);
                    if (j != -1) {
                        if (strT != "")
                            strT += ",";
                        string strType = "k" + ((Side)n).ToString();
                        strT += strType + ":" + j.ToString();
                    }
                }
                sec.Add(new Ini.Property("T", strT));

                // Save trigger contents

                tgr.AddIniProperties(sec);
            }

            // Restore order

            if (fDemoCheckTrigger) {
                m_fModified = fModifiedSave;
                RemoveTrigger(tgrDemo);
            }

            return sec;
        }