Example #1
0
        public void LoadIni(Ini ini)
        {
            Hashtable map        = new Hashtable();
            Trigger   tgrCurrent = null;

            Ini.Section sec = ini["Triggers"];
            foreach (Ini.Property prop in sec.Properties)
            {
                if (prop.Name == "Count")
                {
                    continue;
                }
                if (prop.Name == "T")
                {
                    tgrCurrent = new Trigger();
                    int nfSides = 0;
                    foreach (string key in prop.Value.Split(','))
                    {
                        Side side = (Side)int.Parse(key.Split(':')[0]);
                        nfSides |= SideToMask(side);
                        map.Add(key, tgrCurrent);
                    }
                    tgrCurrent.Sides = nfSides;
                    m_alsTriggers.Add(tgrCurrent);
                    continue;
                }
                if (prop.Name == "C")
                {
                    tgrCurrent.Conditions.Add(TriggerConditionLoader.LoadIni(prop.Value));
                    continue;
                }
                if (prop.Name == "A")
                {
                    tgrCurrent.Actions.Add(TriggerActionLoader.LoadIni(prop.Value));
                    continue;
                }
            }

            // Add the triggers for each side in proper order

            for (int side = 0; side < m_aalsSideTriggers.Length; side++)
            {
                int index = 0;
                while (true)
                {
                    bool fFound = false;
                    foreach (string key in map.Keys)
                    {
                        int sideT = int.Parse(key.Split(':')[0]);
                        if (sideT != side)
                        {
                            continue;
                        }
                        int indexT = int.Parse(key.Split(':')[1]);
                        if (indexT != index)
                        {
                            continue;
                        }
                        fFound = true;
                        m_aalsSideTriggers[side].Add(map[key]);
                    }
                    if (!fFound)
                    {
                        break;
                    }
                    index = index + 1;
                }
            }

            // Go through all the triggers and search for demo check trigger.
            // There should be only one, but check them all.

            ArrayList alsRemove = new ArrayList();

            foreach (Trigger tgr in m_alsTriggers)
            {
                foreach (CaBase cab in tgr.Conditions)
                {
                    if (cab.GetType() == typeof(TestPvarCondition))
                    {
                        TestPvarCondition cdn = (TestPvarCondition)cab;
                        if (cdn.GetVariableString() == "$demo")
                        {
                            alsRemove.Add(tgr);
                            break;
                        }
                    }
                }
            }
            foreach (Trigger tgr in alsRemove)
            {
                RemoveTrigger(tgr);
            }

            // Triggers have been modified

            SetModified();
        }
Example #2
0
        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);
        }