protected override void GenerateConstructor(Node node, StreamWriter stream, string indent, string className)
        {
            base.GenerateConstructor(node, stream, indent, className);

            DecoratorIterator iterator = node as DecoratorIterator;
            if (iterator == null)
                return;

            if (iterator.Opl != null || iterator.Opr != null)
            {
                if (iterator.Opl != null)
                {
                    stream.WriteLine("{0}\t\t\tthis.m_opl = Condition.LoadLeft(\"{1}\");", indent, iterator.Opl.GetExportValue());
                    stream.WriteLine("{0}\t\t\tDebug.Check(this.m_opl != null);", indent);
                }

                stream.WriteLine("{0}\t\t\tstring typeName = null;", indent);

                if (iterator.Opr != null)
                {
                    stream.WriteLine("{0}\t\t\tthis.m_opr = Condition.LoadRight(\"{1}\", ref typeName);", indent, iterator.Opr.GetExportValue());
                    stream.WriteLine("{0}\t\t\tDebug.Check(this.m_opr != null);", indent);
                }
            }
        }
        protected override void GenerateConstructor(Node node, StreamWriter stream, string indent, string className)
        {
            base.GenerateConstructor(node, stream, indent, className);

            DecoratorIterator iterator = node as DecoratorIterator;
            if (iterator == null)
                return;

            if (iterator.Opl != null || iterator.Opr != null)
            {
                if (iterator.Opl != null)
                {
                    stream.WriteLine("{0}\t\t\tthis->m_opl = Condition::LoadLeft(\"{1}\");", indent, iterator.Opl.GetExportValue());
                    stream.WriteLine("{0}\t\t\tBEHAVIAC_ASSERT(this->m_opl != NULL);", indent);
                }

                stream.WriteLine("{0}\t\t\tbehaviac::string typeName;", indent);

                if (iterator.Opr != null)
                {
                    stream.WriteLine("{0}\t\t\tthis->m_opr = Condition::LoadRight(\"{1}\", typeName);", indent, iterator.Opr.GetExportValue());
                    stream.WriteLine("{0}\t\t\tBEHAVIAC_ASSERT(this->m_opr != NULL);", indent);
                }
            }
        }
        protected override void CloneProperties(Node newnode)
        {
            base.CloneProperties(newnode);

            DecoratorLoopUntil node = (DecoratorLoopUntil)newnode;
            node._until = this._until;
        }
Beispiel #4
0
        private void ExportAttachment(StreamWriter file, string btClassName, string agentType, string parentName, Node node, string indent)
        {
            if (node.Attachments.Count > 0)
            {
                file.WriteLine("{0}// attachments", indent);
                foreach (Behaviac.Design.Attachments.Attachment attach in node.Attachments)
                {
                    file.WriteLine("{0}{{", indent);

                    string nodeName = string.Format("attach{0}", attach.Id);

                    // export its instance and the properties
                    AttachmentCsExporter attachmentExporter = AttachmentCsExporter.CreateInstance(attach);
                    attachmentExporter.GenerateInstance(attach, file, indent, nodeName, agentType, btClassName);

                    ExportPars(file, nodeName, attach, indent);

                    file.WriteLine("{0}\t{1}.Attach({2});", indent, parentName, nodeName);
                    if (attach is Behaviac.Design.Attachments.Event)
                    {
                        file.WriteLine("{0}\t{1}.SetHasEvents({1}.HasEvents() | ({2} is Event));", indent, parentName, nodeName);
                    }
                    file.WriteLine("{0}}}", indent);
                }
            }
        }
Beispiel #5
0
        public void SetPar(ParInfo par, Nodes.Node rootNode, bool isNewPar)
        {
            Debug.Check(par != null && rootNode != null);

            _isNewPar = isNewPar;
            _initialized = false;

            this.Text = isNewPar ? Resources.NewPar : Resources.EditPar;

            _par = par;
            _parTemp = par.Clone();
            _rootNode = rootNode;

            setParTypes();

            if (par != null) {
                _isArray = Plugin.IsArrayType(par.Type);
                Type type = _isArray ? par.Type.GetGenericArguments()[0] : par.Type;

                nameTextBox.Text = par.Name;
                arrayCheckBox.Checked = _isArray;
                typeComboBox.Text = Plugin.GetMemberValueTypeName(type);
                descTextBox.Text = par.BasicDescription;

                setValue(type);
            }

            enableOkButton();

            _initialized = true;
        }
        protected override void GenerateMethod(Node node, StreamWriter stream, string indent)
        {
            base.GenerateMethod(node, stream, indent);

            ReferencedBehavior referencedBehavior = node as ReferencedBehavior;
            if (referencedBehavior == null)
                return;

            stream.WriteLine("{0}\t\tvirtual const char* GetReferencedTree(const Agent* pAgent) const", indent);
            stream.WriteLine("{0}\t\t{{", indent);
            stream.WriteLine("{0}\t\t\tBEHAVIAC_UNUSED_VAR(pAgent);", indent);

            string retStr = RightValueCppExporter.GenerateCode(referencedBehavior.ReferenceBehavior, stream, indent + "\t\t\t", "const char*", string.Empty, "_referencedBehavior");

            bool bConst = false;
            if (referencedBehavior.ReferenceBehavior.Var != null && referencedBehavior.ReferenceBehavior.Var.IsConst)
            {
                bConst = true;
            }

            if (!bConst)
            {
                stream.WriteLine("{0}\t\t\tif (pAgent) {{", indent);
            }

            stream.WriteLine("{0}\t\t\treturn {1};", indent, retStr);

            if (!bConst)
            {
                stream.WriteLine("{0}\t\t\t}}", indent);
                stream.WriteLine("{0}\t\t\treturn 0;", indent);
            }

            stream.WriteLine("{0}\t\t}}", indent);
        }
 /// <summary>
 /// Creates a new subitem which can show a property on the node.
 /// </summary>
 /// <param name="owner">The node whose property we want to show. MUST be the same as the one the subitem belongs to.</param>
 /// <param name="property">The property we want to show.</param>
 /// <param name="att">The attribute associated with the property.</param>
 public SubItemProperty(Node owner, PropertyInfo property, DesignerProperty att)
     : base(null, null, __font, Brushes.White, Alignment.Center, false)
 {
     _owner = owner;
     _property = property;
     _attribute = att;
 }
Beispiel #8
0
        public static NodeCppExporter CreateInstance(Node node)
        {
            if (node != null)
            {
                string nodeExporter = "PluginBehaviac.NodeExporters." + node.ExportClass + "CppExporter";
                Type exporterType = Type.GetType(nodeExporter);
                if (exporterType == null)
                {
                    foreach (Assembly assembly in Plugin.GetLoadedPlugins())
                    {
                        string filename = Path.GetFileNameWithoutExtension(assembly.Location);
                        nodeExporter = filename + ".NodeExporters." + node.ExportClass + "CppExporter";
                        exporterType = assembly.GetType(nodeExporter);
                        if (exporterType != null)
                        {
                            break;
                        }
                    }
                }

                if (exporterType != null)
                {
                    return (NodeCppExporter)Activator.CreateInstance(exporterType);
                }
            }

            return new NodeCppExporter();
        }
Beispiel #9
0
        protected override void CloneProperties(Node newnode)
        {
            base.CloneProperties(newnode);

            DecoratorLog dec = (DecoratorLog)newnode;
            dec._logMessage = _logMessage;
        }
Beispiel #10
0
        protected override void CloneProperties(Node newnode)
        {
            base.CloneProperties(newnode);

            State state = (State)newnode;

            state._method = this._method;
        }
        /// <summary>
        /// Branches the list for a node.
        /// </summary>
        /// <param name="node">The node we are branching for.</param>
        /// <returns>A new list which contains the previously processed behaviours for referenced behaviours. For other nodes it returns the same list.</returns>
        public ProcessedBehaviors Branch(Node node)
        {
            ReferencedBehaviorNode refnode= node as ReferencedBehaviorNode;
            if(refnode !=null)
                return new ProcessedBehaviors(this);

            return this;
        }
Beispiel #12
0
        protected override void CloneProperties(Node newnode)
        {
            base.CloneProperties(newnode);

            WaitFrames dec = (WaitFrames)newnode;
            if (_frames != null)
                dec._frames = (RightValueDef)_frames.Clone();
        }
Beispiel #13
0
        protected override void CloneProperties(Node newnode)
        {
            base.CloneProperties(newnode);

            DecoratorTime dec = (DecoratorTime)newnode;
            if (_time != null)
                dec._time = (VariableDef)_time.Clone();
        }
Beispiel #14
0
        protected override void CloneProperties(Node newnode)
        {
            base.CloneProperties(newnode);

            Wait dec = (Wait)newnode;
            if (_time != null)
                dec._time = (RightValueDef)_time.Clone();
        }
Beispiel #15
0
        protected override void CloneProperties(Node newnode)
        {
            base.CloneProperties(newnode);

            ExampleNode dec = (ExampleNode)newnode;
            if (_time != null)
                dec._time = (VariableDef)_time.Clone();
        }
Beispiel #16
0
        /// <summary>
        /// Checks if a node may be processed without running into circular references. The node is not added to the list.
        /// </summary>
        /// <param name="node">The node we want to process.</param>
        /// <returns>Returns true when the node may be processed, if not the calling function has to stop.</returns>
        public bool MayProcessCheckOnly(Node node) {
            ReferencedBehavior refnode = node as ReferencedBehavior;

            if (refnode != null)
            { return !_processedBehaviors.Contains(refnode); }

            return true;
        }
Beispiel #17
0
		protected override void CloneProperties(Node newnode)
		{
			base.CloneProperties(newnode);

            DecoratorCount dec = (DecoratorCount)newnode;
            if (_count != null)
                dec._count = (VariableDef)_count.Clone();
		}
        protected override void GenerateConstructor(Node node, StreamWriter stream, string indent, string className)
        {
            base.GenerateConstructor(node, stream, indent, className);

            DecoratorLoopUntil decoratorLoopUntil = node as DecoratorLoopUntil;
            Debug.Check(decoratorLoopUntil != null);

            stream.WriteLine("{0}\t\t\tm_until = {1};", indent, decoratorLoopUntil.Until ? "true" : "false");
        }
        protected override void GenerateConstructor(Node node, StreamWriter stream, string indent, string className)
        {
            base.GenerateConstructor(node, stream, indent, className);

            DecoratorLog decoratorLog = node as DecoratorLog;
            Debug.Check(decoratorLog != null);

            stream.WriteLine("{0}\t\t\tm_message = \"{1}\";", indent, decoratorLog.Log);
        }
        protected override void GenerateConstructor(Node node, StreamWriter stream, string indent, string className)
        {
            base.GenerateConstructor(node, stream, indent, className);

            Decorator decorator = node as Decorator;
            Debug.Check(decorator != null);

            stream.WriteLine("{0}\t\t\tm_bDecorateWhenChildEnds = {1};", indent, decorator.DecorateWhenChildEnds ? "true" : "false");
        }
Beispiel #21
0
        protected override void GenerateConstructor(Node node, StreamWriter stream, string indent, string className)
        {
            base.GenerateConstructor(node, stream, indent, className);

            Wait wait = node as Wait;
            Debug.Check(wait != null);

            stream.WriteLine("{0}\t\t\tm_ignoreTimeScale = {1};", indent, wait.IgnoreTimeScale ? "true" : "false");
        }
Beispiel #22
0
        protected override void GenerateConstructor(Node node, StreamWriter stream, string indent, string className)
        {
            base.GenerateConstructor(node, stream, indent, className);

            Query query = node as Query;
            Debug.Check(query != null);

            stream.WriteLine("{0}\t\t\tthis->Initialize(\"{1}\", \"{2}\");",
                indent, query.Domain, DesignerPropertyUtility.RetrieveExportValue(query.Descriptors));
        }
Beispiel #23
0
        protected override void GenerateConstructor(Node node, StreamWriter stream, string indent, string className)
        {
            base.GenerateConstructor(node, stream, indent, className);

            WaitState waitState = node as WaitState;
            if (waitState == null)
                return;

            stream.WriteLine("{0}\t\t\tm_ignoreTimeScale = {1};", indent, waitState.IgnoreTimeScale ? "true" : "false");
        }
        protected override void GenerateMethod(Node node, StreamWriter stream, string indent)
        {
            SequenceStochastic sequenceStochastic = node as SequenceStochastic;
            Debug.Check(sequenceStochastic != null);

            stream.WriteLine("{0}\t\tpublic void Initialize(string method)", indent);
            stream.WriteLine("{0}\t\t{{", indent);
            stream.WriteLine("{0}\t\t\tthis.m_method = Action.LoadMethod(method);", indent);
            stream.WriteLine("{0}\t\t}}", indent);
        }
        protected override void GenerateConstructor(Node node, StreamWriter stream, string indent, string className)
        {
            base.GenerateConstructor(node, stream, indent, className);

            DecoratorLoop decoratorLoop = node as DecoratorLoop;
            if (decoratorLoop == null)
                return;

            stream.WriteLine("{0}\t\t\tm_bDoneWithinFrame = {1};", indent, decoratorLoop.DoneWithinFrame ? "true" : "false");
        }
Beispiel #26
0
        protected override void CloneProperties(Node newnode)
        {
            base.CloneProperties(newnode);

            if (_weight != null)
            {
                DecoratorWeight dec = (DecoratorWeight)newnode;
                dec._weight = (VariableDef)_weight.Clone();
            }
        }
Beispiel #27
0
        protected override void CloneProperties(Node newnode)
        {
            base.CloneProperties(newnode);

            Wait dec = (Wait)newnode;
            if (_time != null)
                dec._time = (VariableDef)_time.Clone();

            dec._ignoreTimeScale = this._ignoreTimeScale;
        }
        protected override void GenerateMethod(Node node, StreamWriter stream, string indent)
        {
            SelectorProbability selectorProbability = node as SelectorProbability;
            Debug.Check(selectorProbability != null);

            stream.WriteLine("{0}\t\tpublic void Initialize(string method)", indent);
            stream.WriteLine("{0}\t\t{{", indent);
            stream.WriteLine("{0}\t\t\tthis.m_method = Action.LoadMethod(method);", indent);
            stream.WriteLine("{0}\t\t}}", indent);
        }
Beispiel #29
0
        public static NodeCsExporter CreateInstance(Node node)
        {
            if (node != null)
            {
                Type exporterType = getExporterType(node.GetType());
                if (exporterType != null)
                    return (NodeCsExporter)Activator.CreateInstance(exporterType);
            }

            return new NodeCsExporter();
        }
        protected override void CloneProperties(Node newnode)
        {
            base.CloneProperties(newnode);

            SelectorProbability prec = (SelectorProbability)newnode;

            if (_method != null)
            {
                prec._method = (MethodDef)_method.Clone();
            }
        }
Beispiel #31
0
        protected override void CloneProperties(Behaviac.Design.Nodes.Node newattach)
        {
            base.CloneProperties(newattach);

            DecoratorIterator prec = (DecoratorIterator)newattach;

            if (_opl != null)
            {
                prec._opl = (VariableDef)_opl.Clone();
            }

            if (_opr != null)
            {
                prec._opr = (RightValueDef)_opr.Clone();
            }
        }
Beispiel #32
0
        private static void AddAfterConditions(Node node, Behaviac.Design.Attachments.BinaryOperator binaryOpr, Behaviac.Design.Nodes.Node newNode, Behaviac.Design.Nodes.Node.Connector connector, Node oldOne)
        {
            node.RemoveChild(connector, oldOne);

            Type seqType = Plugin.GetType("PluginBehaviac.Nodes.And");

            if (binaryOpr == Behaviac.Design.Attachments.BinaryOperator.Or)
            {
                seqType = Plugin.GetType("PluginBehaviac.Nodes.Or");
            }

            Behaviac.Design.Nodes.Node seq = Behaviac.Design.Nodes.Node.Create(seqType);
            seq.AddChild(BaseNode.Connector.kGeneric, newNode);
            seq.AddChild(BaseNode.Connector.kGeneric, oldOne);

            node.AddChild(BaseNode.Connector.kInterupt, seq);
        }
Beispiel #33
0
 public Event(Behaviac.Design.Nodes.Node node)
     : base(node, Resources.Event, Resources.EventDesc)
 {
 }
Beispiel #34
0
 protected override void CloneProperties(Behaviac.Design.Nodes.Node newnode)
 {
     base.CloneProperties(newnode);
 }
Beispiel #35
0
 public override void PostCreate(List <Node.ErrorCheck> result, int version, Behaviac.Design.Nodes.Node node, System.Xml.XmlNode xmlNode)
 {
     AutoRestruct(result, version, this, node);
 }
Beispiel #36
0
        //if there is a 'Predicate' attachment, convert it to a Condition node and attach it to the '_custom_condition' connector.
        private void AutoRestruct(List <Node.ErrorCheck> result, int version, Behaviac.Design.Attachments.Attachment a, Node node)
        {
            if (version <= 1)
            {
                string attachClass = a.GetType().FullName;
                if (attachClass.IndexOf("PluginBehaviac.Events.Predicate") >= 0)
                {
                    DesignerPropertyInfo propInfo = DesignerProperty.GetDesignerProperty(a.GetType(), "Opl");
                    RightValueDef        opl      = propInfo.GetValue(a) as RightValueDef;
                    propInfo = DesignerProperty.GetDesignerProperty(a.GetType(), "Opr");
                    RightValueDef opr = propInfo.GetValue(a) as RightValueDef;
                    propInfo = DesignerProperty.GetDesignerProperty(a.GetType(), "Operator");
                    OperatorType  oprr    = (OperatorType)propInfo.GetValue(a);
                    OperatorTypes oprType = (OperatorTypes)((int)OperatorTypes.Equal - (int)OperatorType.Equal + (int)oprr);
                    propInfo = DesignerProperty.GetDesignerProperty(a.GetType(), "BinaryOperator");
                    Behaviac.Design.Attachments.BinaryOperator binaryOpr = (Behaviac.Design.Attachments.BinaryOperator)propInfo.GetValue(a);

                    string clss      = node.GetType().FullName;
                    bool   bIsSeqSel = (node.GetType().IsSubclassOf(typeof(Sequence)) ||
                                        node.GetType().IsSubclassOf(typeof(Selector)));

                    bool bCare = (bIsSeqSel ||
                                  node.GetType().IsSubclassOf(typeof(Impulse))
                                  );

                    if (bCare ||
                        clss == "PluginBehaviac.Nodes.Query" ||
                        clss == "PluginBehaviac.Nodes.DecoratorCountLimit")
                    {
                        node.RemoveAttachment(a);
                        node.Behavior.TriggerWasModified(node);

                        Type newType = Plugin.GetType("PluginBehaviac.Nodes.Condition");

                        Behaviac.Design.Nodes.Node           newNode   = Behaviac.Design.Nodes.Node.Create(newType);
                        Behaviac.Design.Nodes.Node.Connector connector = node.GetConnector(Node.Connector.kInterupt);

                        if (connector != null && connector.Identifier == Node.Connector.kInterupt && connector.ChildCount > 0)
                        {
                            //it has multiple Predicates, so insert all of them to a newly created Sequence
                            Node oldOne = (Node)connector.GetChild(0);
                            if (oldOne.GetType().IsSubclassOf(typeof(Condition)))
                            {
                                AddAfterConditions(node, binaryOpr, newNode, connector, oldOne);
                            }
                            else
                            {
                                if (bIsSeqSel)
                                {
                                    Debug.Check(oldOne.GetType().IsSubclassOf(typeof(Decorator)));
                                    Decorator d = oldOne as Decorator;
                                    node      = oldOne;
                                    connector = node.GetConnector(BaseNode.Connector.kGeneric);
                                    oldOne    = (Node)d.Children[0];
                                }

                                if (oldOne.GetType() == typeof(PluginBehaviac.Nodes.And))
                                {
                                    if (binaryOpr == Behaviac.Design.Attachments.BinaryOperator.Or)
                                    {
                                        node.RemoveChild(connector, oldOne);
                                        Type selType1 = Plugin.GetType("PluginBehaviac.Nodes.Or");

                                        Behaviac.Design.Nodes.Node sel = Behaviac.Design.Nodes.Node.Create(selType1);
                                        sel.AddChild(BaseNode.Connector.kGeneric, oldOne);
                                        sel.AddChild(BaseNode.Connector.kGeneric, newNode);

                                        node.AddChild(BaseNode.Connector.kInterupt, sel);
                                    }
                                    else
                                    {
                                        oldOne.AddChild(BaseNode.Connector.kGeneric, newNode);
                                    }
                                }
                                else if (oldOne.GetType() == typeof(PluginBehaviac.Nodes.Or))
                                {
                                    if (binaryOpr == Behaviac.Design.Attachments.BinaryOperator.And)
                                    {
                                        node.RemoveChild(connector, oldOne);
                                        Type selType1 = Plugin.GetType("PluginBehaviac.Nodes.And");

                                        Behaviac.Design.Nodes.Node sel = Behaviac.Design.Nodes.Node.Create(selType1);
                                        sel.AddChild(BaseNode.Connector.kGeneric, oldOne);
                                        sel.AddChild(BaseNode.Connector.kGeneric, newNode);

                                        node.AddChild(BaseNode.Connector.kInterupt, sel);
                                    }
                                    else
                                    {
                                        oldOne.AddChild(BaseNode.Connector.kGeneric, newNode);
                                    }
                                }
                                else if (oldOne.GetType().IsSubclassOf(typeof(Condition)))
                                {
                                    AddAfterConditions(node, binaryOpr, newNode, connector, oldOne);
                                }
                                else
                                {
                                    Debug.Check(false);
                                }
                            }
                        }
                        else
                        {
                            //the first condition
                            Behaviac.Design.Nodes.Node notNode = null;
                            if (bIsSeqSel)
                            {
                                //for sequence/selector, it is reverted
                                Type notType = Plugin.GetType("PluginBehaviac.Nodes.DecoratorNot");

                                notNode = Behaviac.Design.Nodes.Node.Create(notType);
                                node.AddChild(BaseNode.Connector.kInterupt, notNode);
                                notNode.AddChild(BaseNode.Connector.kGeneric, newNode);
                            }
                            else
                            {
                                node.AddChild(BaseNode.Connector.kInterupt, newNode);
                            }
                        }

                        // initialise the attachments properties
                        IList <DesignerPropertyInfo> lp = newNode.GetDesignerProperties();
                        for (int p = 0; p < lp.Count; ++p)
                        {
                            if (lp[p].Property.Name == "Opl")
                            {
                                lp[p].Property.SetValue(newNode, opl, null);
                            }
                            else if (lp[p].Property.Name == "Opr")
                            {
                                lp[p].Property.SetValue(newNode, opr, null);
                            }
                            else if (lp[p].Property.Name == "Operator")
                            {
                                lp[p].Property.SetValue(newNode, oprr, null);
                            }
                        }

                        // update attacheent with attributes
                        newNode.OnPropertyValueChanged(false);
                    }
                    else if (clss == "PluginBehaviac.Nodes.Action")
                    {
                        Type newType = Plugin.GetType("PluginBehaviac.Events.Precondition");

                        Behaviac.Design.Attachments.Attachment newNode = Behaviac.Design.Attachments.Attachment.Create(newType, node);
                        node.AddAttachment(newNode);
                        node.RemoveAttachment(a);
                        node.Behavior.TriggerWasModified(node);

                        // initialise the attachments properties
                        IList <DesignerPropertyInfo> lp = newNode.GetDesignerProperties();
                        for (int p = 0; p < lp.Count; ++p)
                        {
                            if (lp[p].Property.Name == "BinaryOperator")
                            {
                                lp[p].Property.SetValue(newNode, binaryOpr, null);
                            }
                            else if (lp[p].Property.Name == "Opl")
                            {
                                lp[p].Property.SetValue(newNode, opl, null);
                            }
                            else if (lp[p].Property.Name == "Opr2")
                            {
                                lp[p].Property.SetValue(newNode, opr, null);
                            }
                            else if (lp[p].Property.Name == "Operator")
                            {
                                lp[p].Property.SetValue(newNode, oprType, null);
                            }
                            else if (lp[p].Property.Name == "IsAlive")
                            {
                                lp[p].SetValueFromString(result, newNode, "true");
                            }
                        }

                        // update attacheent with attributes
                        newNode.OnPropertyValueChanged(false);
                    }
                    else
                    {
                        Debug.Check(false);
                    }
                }
            } // if (version <= 1)
        }