public void AddIniProperties(Ini.Section sec) { // Save conditions & actions foreach (CaBase cab in m_alsConditions) { if (!(cab is CommentCondition)) sec.Add(new Ini.Property("C", cab.ToSaveString())); } foreach (CaBase cab in m_alsActions) { if (!(cab is CommentTriggerAction)) sec.Add(new Ini.Property("A", cab.ToSaveString())); } }
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 AddIniProperties(Ini.Section sec) { // Save Name sec.Add(new Ini.Property("Name", Name)); // Save Side sec.Add(new Ini.Property("Side", "k" + m_side.ToString())); // Save Aggressiveness sec.Add(new Ini.Property("Aggressiveness", "knAggressiveness" + m_aggr.ToString())); // Save flags sec.Add(new Ini.Property("LoopForever", m_fLoopForever ? "1" : "0")); sec.Add(new Ini.Property("CreateAtLevelLoad", m_fCreateAtLevelLoad ? "1" : "0")); sec.Add(new Ini.Property("RandomGroup", m_fRandomGroup ? "1" : "0")); sec.Add(new Ini.Property("Spawn", m_fSpawn ? "1" : "0")); sec.Add(new Ini.Property("ReplaceGroup", m_fReplaceDestroyedGroup ? "1" : "0")); // Save SpawnArea int nSpawnArea = CaTypeArea.GetArea(m_strSpawnArea); if (nSpawnArea != -1) sec.Add(new Ini.Property("SpawnArea", nSpawnArea.ToString())); // Save Health sec.Add(new Ini.Property("Health", Health.ToString())); // Save unit list if (m_alsUnitTypeAndCounts.Count > 0) { // Write total # of units int cTotalUnits = 0; foreach (UnitTypeAndCount utc in m_alsUnitTypeAndCounts) cTotalUnits += utc.c; string str = cTotalUnits.ToString(); // Write unit/count pairs foreach (UnitTypeAndCount utc in m_alsUnitTypeAndCounts) str += "," + utc.ToSaveString(); sec.Add(new Ini.Property("Units", str)); } // Save actions foreach (CaBase cab in m_alsActions) { if (!(cab is CommentUnitGroupAction)) sec.Add(new Ini.Property("A", cab.ToSaveString())); } }
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); } }
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 { } }
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")); }