public static DependencyAction NewFromStatement(MissionStatement item)
        {
            switch (item.Name)
            {
            case "set_variable":
                if (item.GetAttribute("value") == null && (item.GetAttribute("randomIntLow") != null || item.GetAttribute("randomIntHigh") != null))
                {
                    return(new DependencyValueAction(item, item.GetAttribute("name"), null, item.GetAttribute("randomIntLow"), item.GetAttribute("randomIntHigh"), null, null));
                }
                if (item.GetAttribute("value") == null && (item.GetAttribute("randomFloatLow") != null || item.GetAttribute("randomFloatHigh") != null))
                {
                    return(new DependencyValueAction(item, item.GetAttribute("name"), null, null, null, item.GetAttribute("randomFloatLow"), item.GetAttribute("randomFloatHigh")));
                }
                else
                {
                    return(new DependencyValueAction(item, item.GetAttribute("name"), item.GetAttribute("value"), null, null, null, null));
                }

            case "set_timer":
                return(new DependencyTimerAction(item, item.GetAttribute("name"), item.GetAttribute("seconds")));

            default:
                return(new DependencyMiscAction());
            }
        }
 public DependencyValueCondition(MissionStatement statement, string name, string comparator, string value)
 {
     Statement  = statement;
     Name       = name;
     Comparator = comparator;
     Value      = value;
 }
 public MissionSearchResult(int curNode, int curStatement, string text, TreeNode node, MissionStatement statement)
 {
     CurNode = curNode;
     CurStatement = curStatement;
     if (text == null)
     {
         Text = null;
         Valid = false;
     }
     else if (node == null)
     {
         Text =  text;
         NodeText = null;
         Valid = false;
     }
     else
     {
         //string node_text = node.Text.Length > 25 ? node.Text.Substring(0, 25 - 3) + "..." : string.Format("{0,-25}", node.Text);
         NodeText = node.Text;
         //Text = "(" + node_text + ") " + text;
         Text = text;
         Valid = true;
     }
     Node = node;
     Statement = statement;
     Event = null;
 }
 public MissionSearchResult(int curNode, int curStatement, string text, TreeNode node, MissionStatement statement)
 {
     CurNode      = curNode;
     CurStatement = curStatement;
     if (text == null)
     {
         Text  = null;
         Valid = false;
     }
     else if (node == null)
     {
         Text     = text;
         NodeText = null;
         Valid    = false;
     }
     else
     {
         //string node_text = node.Text.Length > 25 ? node.Text.Substring(0, 25 - 3) + "..." : string.Format("{0,-25}", node.Text);
         NodeText = node.Text;
         //Text = "(" + node_text + ") " + text;
         Text  = text;
         Valid = true;
     }
     Node      = node;
     Statement = statement;
     Event     = null;
 }
        private void Conditions_Add(MissionStatement item)
        {
            DependencyCondition dc = DependencyCondition.NewFromStatement(item);

            MiscConditionCount += dc is DependencyMiscCondition ? 1 : 0;

            Conditions.Add(dc);
        }
		public DependencyPrecursor(DependencyEvent _event, int seconds = 0, double probability = 1.0, int count = 0, MissionStatement statement = null)
		{
			Event = _event;
			Seconds = seconds;
			Probability = probability;
			Count = count;
			Statement = statement;
		}
示例#7
0
 public DependencyPrecursor(DependencyEvent _event, int seconds = 0, double probability = 1.0, int count = 0, MissionStatement statement = null)
 {
     Event       = _event;
     Seconds     = seconds;
     Probability = probability;
     Count       = count;
     Statement   = statement;
 }
        private void Conditions_Add(MissionStatement item)
        {
            DependencyCondition dc = DependencyCondition.NewFromStatement(item);

            MiscConditionCount += dc is DependencyMiscCondition ? 1 : 0;

            Conditions.Add(dc);
        }
示例#9
0
        /// <summary>
        /// Read node contents from XmlNode.
        /// </summary>
        /// <param name="item">Source node</param>
        public override void FromXml(XmlNode item)
        {
            SetDefaultName();
            ID       = null;
            ParentID = null;
            Conditions.Clear();
            Actions.Clear();

            List <MissionStatement> commentHolder = new List <MissionStatement>();

            foreach (XmlAttribute att in item.Attributes)
            {
                if (att.Name == "id_arme")
                {
                    ID = Helper.GuidTryRead(att.Value, true);
                }
                // Start node should not have parent id
                //if (att.Name == "parent_id_arme")
                //    ParentID = new Guid(att.Value);
                if (att.Name == "name_arme" || att.Name == "name")
                {
                    Name = att.Value;
                }
            }

            foreach (XmlNode xNode in item.ChildNodes)
            {
                MissionStatement nStatement = MissionStatement.NewFromXML(xNode, this);
                switch (nStatement.Kind)
                {
                case MissionStatementKind.Action:
                {
                    foreach (MissionStatement mS in commentHolder)
                    {
                        Actions.Add(mS);
                    }
                    commentHolder.Clear();
                    Actions.Add(nStatement);
                }
                break;

                case MissionStatementKind.Condition:
                {
                    Log.Add("Found a condition in start block! It was ignored as start nodes are not allowed to have conditions.");
                }
                break;

                case MissionStatementKind.Commentary:
                    commentHolder.Add(nStatement);
                    break;
                }
            }

            foreach (MissionStatement mS in commentHolder)
            {
                Actions.Add(mS);
            }
        }
 public DependencyValueAction(MissionStatement statement, string name, string value, string valueMinInt, string valueMaxInt, string valueMinFloat, string valueMaxFloat)
 {
     Statement     = statement;
     Name          = name;
     ValueExact    = value;
     ValueMinInt   = valueMinInt;
     ValueMaxInt   = valueMaxInt;
     ValueMinFloat = valueMinFloat;
     ValueMaxFloat = valueMaxFloat;
 }
        public static MissionStatement NewFromXML(XmlNode item, MissionNode parent)
        {
            MissionStatement mn = new MissionStatement(parent);

            mn.FromXml(item);

            mn.Update();

            return(mn);
        }
 public MissionSearchResult()
 {
     CurNode      = -1;
     CurStatement = -1;
     Text         = null;
     NodeText     = null;
     Valid        = false;
     Node         = null;
     Statement    = null;
     Event        = null;
 }
        private void Actions_Add(MissionStatement item)
        {
            DependencyAction da = DependencyAction.NewFromStatement(item);

            //Remove duplicate if present
            for (int i = Actions.Count-1;i>=0;i--)
                if (Actions[i].IsDuplicate(da))
                    Actions.RemoveAt(i);

            Actions.Add(da);
        }
 public MissionSearchResult(string prefix, string suffix, TreeNode node)
 {
     CurNode = -1;
     CurStatement = -1;
     //string node_text = node.Text.Length > 25 ? node.Text.Substring(0, 25 - 3) + "..." : string.Format("{0,-25}", node.Text);
     string node_text = node.Text.Length > 25 ? node.Text.Substring(0, 25 - 3) + "..." : string.Format("{0,-25}", node.Text);
     Text = prefix + node_text + suffix;
     Valid = true;
     Node = node;
     Statement = null;
     Event = null;
 }
        public MissionSearchResult(string prefix, string suffix, TreeNode node)
        {
            CurNode      = -1;
            CurStatement = -1;
            //string node_text = node.Text.Length > 25 ? node.Text.Substring(0, 25 - 3) + "..." : string.Format("{0,-25}", node.Text);
            string node_text = node.Text.Length > 25 ? node.Text.Substring(0, 25 - 3) + "..." : string.Format("{0,-25}", node.Text);

            Text      = prefix + node_text + suffix;
            Valid     = true;
            Node      = node;
            Statement = null;
            Event     = null;
        }
        public static DependencyCondition NewFromStatement(MissionStatement item)
        {
            switch (item.Name)
            {
            case "if_variable":
                return(new DependencyValueCondition(item, item.GetAttribute("name"), item.GetAttribute("comparator"), item.GetAttribute("value")));

            case "if_timer_finished":
                return(new DependencyTimerCondition(item, item.GetAttribute("name")));

            default:
                return(new DependencyMiscCondition());
            }
        }
        private void Actions_Add(MissionStatement item)
        {
            DependencyAction da = DependencyAction.NewFromStatement(item);

            //Remove duplicate if present
            for (int i = Actions.Count - 1; i >= 0; i--)
            {
                if (Actions[i].IsDuplicate(da))
                {
                    Actions.RemoveAt(i);
                }
            }

            Actions.Add(da);
        }
 public static DependencyAction NewFromStatement(MissionStatement item)
 {
     switch (item.Name)
     {
         case "set_variable":
             if (item.GetAttribute("value") == null && (item.GetAttribute("randomIntLow") != null || item.GetAttribute("randomIntHigh") != null))
                 return new DependencyValueAction(item, item.GetAttribute("name"), null, item.GetAttribute("randomIntLow"), item.GetAttribute("randomIntHigh"), null, null);
             if (item.GetAttribute("value") == null && (item.GetAttribute("randomFloatLow") != null || item.GetAttribute("randomFloatHigh") != null))
                 return new DependencyValueAction(item, item.GetAttribute("name"), null, null, null, item.GetAttribute("randomFloatLow"), item.GetAttribute("randomFloatHigh"));
             else
                 return new DependencyValueAction(item, item.GetAttribute("name"), item.GetAttribute("value"), null, null, null, null);
         case "set_timer":
             return new DependencyTimerAction(item, item.GetAttribute("name"), item.GetAttribute("seconds"));
         default:
             return new DependencyMiscAction();
     }
 }
示例#19
0
        /// <summary>
        /// Replace according to search command in the specified statement. Returns how many replacements were done.
        /// </summary>
        public int Replace_InStatement(TreeNode node, MissionStatement statement, int curNode, int curStatement, List<MissionSearchResult> list, MissionSearchCommand msc)
        {
            int replacements = 0;

            //Replace in statement
            if (statement!=null)
            {
                //We are interested in comments only if we are especially looking for them
                if (statement.Kind == MissionStatementKind.Commentary)
                {
                    if (msc.Commentaries)
                        if (Find_CheckStringForMatch(statement.Body, msc))
                        {
                            statement.Body = Replace_ReplaceInString(statement.Body, msc);
                            replacements++;
                        }
                }
                else
                    if (msc.XmlAttValue) //Look for xml attribute values
                        foreach (KeyValuePair<string, string> kvp in statement.GetAttributes())
                            if ((string.IsNullOrEmpty(msc.AttName) || kvp.Key == msc.AttName) && Find_CheckStringForMatch(kvp.Value, msc))
                            {
                                statement.SetAttribute(kvp.Key, Replace_ReplaceInString(kvp.Value, msc));
                                replacements++;
                            }
                statement.Update();
                if (replacements>0)
                    list.Add(new MissionSearchResult(curNode, curStatement, statement.Text, node, statement));
            }

            return replacements;
        }
示例#20
0
 /// <summary>
 /// Highlights statement if it's erroneous and returns wether or not it was highlighted
 /// </summary>
 /// <param name="statement"></param>
 /// <returns></returns>
 public bool HighlightErrors_HighlightStatementIfErroneous(MissionStatement statement)
 {
     bool result = !statement.IsGreen();
     if (result)
         TreeViewStatements.HighlightedTagList.Add(statement);
     return result;
 }
 protected DependencyAction()
 {
     Statement = null;
 }
 public DependencyTimerCondition(MissionStatement statement, string name)
 {
     Statement = statement;
     Name      = name;
 }
示例#23
0
        /// <summary>
        /// Process results from "Edit statement on space map" feature. 
        /// </summary>
        /// <param name="curStatement">Statement being edited</param>
        /// <param name="result">Result from space map dialog</param>
        private void ParseSpaceMapStatementResults(MissionStatement curStatement, SpaceMap.Space result)
        {
            if (result == null)
                return;

            curStatement.FromXml(result.SelectionSpecial.ToXml(new XmlDocument()));

            curStatement.Update();

            OutputMissionNodeContentsToStatementTree();
            RegisterChange("Changes to statement via space map");
        }
示例#24
0
        /// <summary>
        /// Select mission statement by tag value. 
        /// Called from FromState and recursively calls iself.
        /// </summary>
        /// <param name="node">Currently visited node</param>
        /// <param name="statement">Target statement</param>
        private void FromState_RecursiveSelectByTag(TreeNode node, MissionStatement statement)
        {
            foreach (TreeNode child in node.Nodes)
                FromState_RecursiveSelectByTag(child, statement);

            if (!(node.Tag is MissionStatement))
                return;

            if (((MissionStatement)node.Tag) == statement)
                TreeViewStatements.SelectedNode = node;
        }
示例#25
0
        /// <summary>
        /// Add condition statement
        /// </summary>
        /// <param name="nodeUnderCursor">Specified when inserting via dropdown menu, unspecified when inserting via hotkey</param>
        public void StatementAddCondition(TreeNode nodeUnderCursor = null)
        {
            MissionStatement newStatement = new MissionStatement((MissionNode)TreeViewNodes.SelectedNode.Tag);
            newStatement.Name = "if_variable";

            if (StatementAddNew(newStatement, nodeUnderCursor))
                RegisterChange("New condition statement");
        }
 protected DependencyAction()
 {
     Statement = null;
 }
 public DependencyValueAction(MissionStatement statement, string name, string value, string valueMinInt, string valueMaxInt, string valueMinFloat, string valueMaxFloat)
 {
     Statement = statement;
     Name = name;
     ValueExact = value;
     ValueMinInt = valueMinInt;
     ValueMaxInt = valueMaxInt;
     ValueMinFloat = valueMinFloat;
     ValueMaxFloat = valueMaxFloat;
 }
示例#28
0
        /// <summary>
        /// Read node contents from XmlNode.
        /// </summary>
        /// <param name="item">Source node</param>
        public override void FromXml(XmlNode item)
        {
            SerialNumber = Mission.Current.EventCount + 1;
            Enabled      = item.Name == "event";
            ID           = null;
            ParentID     = null;
            Conditions.Clear();
            Actions.Clear();

            List <MissionStatement> commentHolder = new List <MissionStatement>();

            foreach (XmlAttribute att in item.Attributes)
            {
                if (att.Name == "id_arme")
                {
                    ID = Helper.GuidTryRead(att.Value, true);
                }
                if (att.Name == "parent_id_arme")
                {
                    ParentID = Helper.GuidTryRead(att.Value, true);
                }
                if (att.Name == "name_arme" || att.Name == "name")
                {
                    Name = att.Value;
                    if (Name.Contains("Event") && Helper.IntTryParse(Name.Substring(5, Name.Length - 5)))
                    {
                        SerialNumber = Helper.StringToInt(Name.Substring(5, Name.Length - 5));
                    }
                }
            }

            if (ID == null)
            {
                ID = Guid.NewGuid();
            }

            foreach (XmlNode xNode in item.ChildNodes)
            {
                MissionStatement nStatement = MissionStatement.NewFromXML(xNode, this);
                switch (nStatement.Kind)
                {
                case MissionStatementKind.Action:
                {
                    foreach (MissionStatement mS in commentHolder)
                    {
                        Actions.Add(mS);
                    }
                    commentHolder.Clear();
                    Actions.Add(nStatement);
                }
                break;

                case MissionStatementKind.Condition:
                {
                    foreach (MissionStatement mS in commentHolder)
                    {
                        Conditions.Add(mS);
                    }
                    commentHolder.Clear();
                    Conditions.Add(nStatement);
                }
                break;

                case MissionStatementKind.Commentary:
                    commentHolder.Add(nStatement);
                    break;
                }
            }

            foreach (MissionStatement mS in commentHolder)
            {
                Actions.Add(mS);
            }
        }
 public DependencyTimerAction(MissionStatement statement, string name, string value)
 {
     Statement = statement;
     Name      = name;
     Value     = value;
 }
示例#30
0
        /// <summary>
        /// Select statement (either forcing it to be single selected statement or allowing it to get added to selection if Shift was pressed)
        /// </summary>
        /// <param name="forbidMultiSelect">If true, will make sure this statement will be the only one selected</param>
        public void SelectStatement(MissionStatement statement, bool forbidMultiSelect = false)
        {
            TreeNode node = GetStatementNode(statement);

            if (node != null)
            {
                if (forbidMultiSelect)
                    TreeViewStatements.SelectedNodes.Clear();
                TreeViewStatements.SelectedNode = node;
                TreeViewStatements.SelectedNode.EnsureVisible();
            }
            else
            {
                TreeViewStatements.SelectedNode = null;
                _E_statementTV_AfterSelect(null, null);
            }
        }
示例#31
0
        /// <summary>
        /// Add commentary statement
        /// </summary>
        /// <param name="nodeUnderCursor">Specified when inserting via dropdown menu, unspecified when inserting via hotkey</param>
        public void StatementAddCommentary(TreeNode nodeUnderCursor = null)
        {
            MissionStatement newStatement = new MissionStatement((MissionNode)TreeViewNodes.SelectedNode.Tag);
            newStatement.IsCommentary = true;
            newStatement.Name = "Commentary";

            if (StatementAddNew(newStatement, nodeUnderCursor))
                RegisterChange("New commentary statement");
        }
 public DependencyTimerAction(MissionStatement statement, string name, string value)
 {
     Statement = statement;
     Name = name;
     Value = value;
 }
示例#33
0
        /// <summary> 
        /// Check if mission statement matches the search criteria, return search result if it does 
        /// </summary>
        private MissionSearchResult Find_CheckStatementForMatch(TreeNode node, MissionStatement statement, int curNode, int curStatement, MissionSearchCommand msc)
        {
            //We are interested in comments only if we are especially looking for them
            if (statement.Kind == MissionStatementKind.Commentary)
            {
                if (msc.Commentaries)
                    if (Find_CheckStringForMatch(statement.Body, msc))
                        return new MissionSearchResult(curNode, curStatement, statement.Body, node, statement);

                return new MissionSearchResult(curNode, curStatement, null, node, statement);
            }

            bool statisfies = false;

            //Look for xml attribute names
            if (msc.XmlAttName)
                foreach (KeyValuePair<string, string> kvp in statement.GetAttributes())
                    statisfies = statisfies | Find_CheckStringForMatch(kvp.Key, msc);

            //Look for xml attribute values
            if (msc.XmlAttValue)
                foreach (KeyValuePair<string, string> kvp in statement.GetAttributes())
                    statisfies = statisfies | ((string.IsNullOrEmpty(msc.AttName) || kvp.Key == msc.AttName) && Find_CheckStringForMatch(kvp.Value, msc));

            //Look for statement text
            if (msc.StatementText)
                statisfies = statisfies | Find_CheckStringForMatch(statement.Text, msc);

            if (statisfies)
                return new MissionSearchResult(curNode, curStatement, statement.Text, node, statement);

            return new MissionSearchResult(curNode, curStatement, null, node, statement);
        }
 public DependencyCondition()
 {
     Precursors = new List <DependencyPrecursor>();
     Statement  = null;
 }
示例#35
0
        /// <summary>
        /// Gets text representation of the difference for specific statement.
        /// Called from GetDifferenceVersusSource.
        /// </summary>
        private void GetDifferenceVersusSource_GetDifference(string caption, MissionStatement statement, ref string output, ref bool first)
        {
            if (statement.Kind == MissionStatementKind.Commentary)
                return;
            if (string.IsNullOrWhiteSpace(statement.SourceXML))
                return;

            XmlDocument xDoc = new XmlDocument();
            xDoc.LoadXml(statement.SourceXML);
            XmlNode xOld = xDoc.ChildNodes[0];
            XmlNode xNew = statement.ToXml(xDoc);
            string diffs = "";

            if (xOld.Name != xNew.Name)
                diffs += "\r\n" + "Name: <" + xOld.Name + "> => <" + xNew.Name + ">";
            foreach (XmlAttribute atto in xOld.Attributes)
            {
                XmlAttribute attn = xNew.Attributes[atto.Name];
                if (attn == null)
                    diffs += "\r\n" + "Attribute: <" + atto.Name + "> removed!";
                else if (attn.Value != atto.Value)
                    diffs += "\r\n" + "Attribute: <" + atto.Name + "> value changed <" + atto.Value + "> => <" + attn.Value + ">";
            }
            foreach (XmlAttribute attn in xNew.Attributes)
            {
                XmlAttribute atto = xOld.Attributes[attn.Name];
                if (atto == null)
                    diffs += "\r\n" + "Attribute: added <" + attn.Name + ">";
            }
            if (!String.IsNullOrEmpty(diffs))
            {
                if (first)
                {
                    first = false;
                    output += caption;
                }
                output += "\r\n" + "\r\n" + xOld.OuterXml + " => " + xNew.OuterXml;
                output += diffs;
            }
        }
示例#36
0
        /// <summary>
        /// Get Node from TreeView for Statements that represents the supplied statement
        /// </summary>
        public TreeNode GetStatementNode(MissionStatement statement)
        {
            if (statement == null)
                return null;

            TreeNode result = null;

            foreach (TreeNode node in TreeViewStatements.Nodes)
                if ((result = GetStatementNode_RecursivelySelect(node, statement)) != null)
                    return result;

            return null;
        }
示例#37
0
        /// <summary>
        /// Inner part of adding new statement, returns whether update (change register) is required
        /// </summary>
        /// <param name="newStatement">Statement to add</param>
        /// <param name="nodeUnderCursor">Specified when inserting via dropdown menu, unspecified when inserting via hotkey</param>
        private bool StatementAddNew(MissionStatement newStatement, TreeNode nodeUnderCursor = null)
        {
            if (TreeViewNodes.SelectedNode == null)
                return false;
            TreeViewStatements.Focus();

            newStatement.Body = "";
            newStatement.Update();

            TreeNode newTNode = new TreeNode();
            newTNode.Text = newStatement.Text;
            newTNode.ImageIndex = newStatement.ImageIndex;
            newTNode.SelectedImageIndex = newStatement.ImageIndex;
            newTNode.Tag = newStatement;

            bool needUpdate = StatementInsertUnderNode(newTNode, nodeUnderCursor ?? TreeViewStatements.SelectedNode);
            TreeViewStatements.SelectedNode = newTNode;

            ImportMissionNodeContentsFromStatementTree();

            return needUpdate;
        }
示例#38
0
        /// <summary>
        /// Try to find node that represents the supplied statement in the child nodes of the current node. 
        /// Called from GetStatementNode and recursively calls itself.
        /// </summary>
        /// <param name="node"></param>
        /// <param name="statement"></param>
        /// <returns></returns>
        public TreeNode GetStatementNode_RecursivelySelect(TreeNode node, MissionStatement statement)
        {
            TreeNode result = null;
            foreach (TreeNode child in node.Nodes)
                if ((result = GetStatementNode_RecursivelySelect(child, statement)) != null)
                    return result;

            if (node.Tag == statement)
                return node;

            return null;
        }
 public MissionSearchResult()
 {
     CurNode = -1;
     CurStatement = -1;
     Text = null;
     NodeText = null;
     Valid = false;
     Node = null;
     Statement = null;
     Event = null;
 }
        public static MissionStatement NewFromXML(XmlNode item, MissionNode parent)
        {
            MissionStatement mn = new MissionStatement(parent);

            mn.FromXml(item);

            mn.Update();

            return mn;
        }