Example #1
0
        public static CaBase LoadIni(string strValue)
        {
            CaBase cab = null;
            switch (int.Parse(strValue.Split(',')[0])) {
            case 0: // knMissionLoadedCondition
                cab = new MissionLoadedCondition();
                break;

            case 1: // knCreditsCondition
                cab = new CreditsCondition();
                break;

            case 2: // knAreaContainsUnitsCondition
                cab = new AreaContainsUnitsCondition();
                break;

            case 3: // knGalaxiteCapacityReachedCondition
                cab = new GalaxiteCapacityReachedCondition();
                break;

            case 4: // knMobileHQDeployedCondition
            #if false
                cab = new MobileHQDeployedCondition();
            #endif
                break;

            case 5: // knPlaceStructureModeCondition
                cab = new PlaceStructureModeCondition();
                break;

            case 6: // knElapsedTimeCondition
                cab = new ElapsedTimeCondition();
                break;

            case 7: // knOwnsUnitsCondition
                cab = new OwnsUnitsCondition();
                break;

            case 8: // knMinerCantFindGalaxiteCondition
                cab = new MinerCantFindGalaxiteCondition();
                break;

            case 9: // knUnitSeesUnitCondition
            #if false
                cab = new UnitSeesUnitCondition();
            #endif
                break;

            case 10: // knUnitDestroyedCondition
            #if false
                cab = new UnitDestroyedCondition();
            #endif
                break;

            case 11: // knSwitchCondition
                cab = new SwitchCondition();
                break;

            case 12: // knPeriodicTimerCondition
                cab = new PeriodicTimerCondition();
                break;

            case 13: // knDiscoversSideCondition
                cab = new DiscoversSideCondition();
                break;

            case 14: // knCountdownTimerCondition
                cab = new CountdownTimerCondition();
                break;

            case 15: // knCounterCondition
            #if false
                cab = new CounterCondition();
            #endif
                break;

            case 16: // knTestPvarCondition
                cab = new TestPvarCondition();
                break;

            case 17: // knHasUpgradesCondition
                cab = new HasUpgradesCondition();
                break;
            }
            if (cab != null) {
                cab.FromSaveString(strValue);
            }
            return cab;
        }
        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;
        }