Exemplo n.º 1
0
        public static VariableComparator Create(string comparionOperator, Property lhs, CMethodBase lhs_m, Property rhs, CMethodBase rhs_m)
        {
            E_VariableComparisonType comparisonType = VariableComparator.ParseComparisonType(comparionOperator);

            VariableComparator pComparator = VariableComparator.Create(lhs, lhs_m, rhs, rhs_m);
            pComparator.SetComparisonType(comparisonType);

            return pComparator;
        }
Exemplo n.º 2
0
        public static bool EvaluteCompute(Agent pAgent, Property opl, Property opr1, CMethodBase opr1_m, EComputeOperator opr, Property opr2, CMethodBase opr2_m)
        {
            bool bValid = false;
            object value1 = null;

            if (opl != null)
            {
            if (opr1_m != null)
            {
                bValid = true;
                value1 = opr1_m.Invoke(pAgent);
            }
            else if (opr1 != null)
            {
                bValid = true;
                Agent pParentR = opr1.GetParentAgent(pAgent);

                value1 = opr1.GetValue(pParentR);
            }

            Debug.Check(value1 != null, "weird, have you modified your meta? please reexport your trees");

            if (opr2_m != null)
            {
                bValid = true;
                object value2 = opr2_m.Invoke(pAgent);

                Agent pParentOpl = opl.GetParentAgent(pAgent);
                object returnValue = Details.ComputeValue(value1, value2, opr);

                opl.SetValue(pParentOpl, returnValue);
            }
            else if (opr2 != null)
            {
                bValid = true;
                Agent pParentL = opl.GetParentAgent(pAgent);
                Agent pParentR = opr2.GetParentAgent(pAgent);

                object value2 = opr2.GetValue(pParentR);

                object returnValue = Details.ComputeValue(value1, value2, opr);

                opl.SetValue(pParentL, returnValue);
            }
            }

            return bValid;
        }
Exemplo n.º 3
0
            //generate a random float value between 0 and 1.
            public static float GetRandomValue(CMethodBase method, Agent pAgent)
            {
                float value = 0;

                if (method != null)
                {
                    value = (float)method.Invoke(pAgent);
                }
                else
                {
                    value = RandomGenerator.GetInstance().GetRandom();
                }

                Debug.Check(value >= 0.0f && value < 1.0f);
                return value;
            }
Exemplo n.º 4
0
        public static bool EvaluteCompute(Agent pAgent, Property opl, Property opr1, CMethodBase opr1_m, EComputeOperator opr, Property opr2, CMethodBase opr2_m)
        {
            bool bValid = false;
            object value1 = null;

            if (opl != null)
            {
            if (opr1_m != null)
            {
                bValid = true;
                value1 = opr1_m.Invoke(pAgent);
            }
            else if (opr1 != null)
            {
                bValid = true;
                Agent pParentR = opr1.GetParentAgent(pAgent);

                value1 = opr1.GetValue(pParentR);
            }

            if (opr2_m != null)
            {
                bValid = true;
                object value2 = opr2_m.Invoke(pAgent);

                Agent pParentOpl = opl.GetParentAgent(pAgent);
                object returnValue = Details.ComputeValue(value1, value2, opr);

                opl.SetValue(pParentOpl, returnValue);
            }
            else if (opr2 != null)
            {
                bValid = true;
                Agent pParentL = opl.GetParentAgent(pAgent);
                Agent pParentR = opr2.GetParentAgent(pAgent);

                object value2 = opr2.GetValue(pParentR);

                object returnValue = Details.ComputeValue(value1, value2, opr);

                opl.SetValue(pParentL, returnValue);
            }
            }

            return bValid;
        }
        protected override void load(int version, string agentType, List<property_t> properties)
        {
            base.load(version, agentType, properties);

            foreach (property_t p in properties)
            {
                if (p.name == "RandomGenerator")
                {
                    if (p.value[0] != '\0')
                    {
                        this.m_method = Action.LoadMethod(p.value);
                    }//if (p.value[0] != '\0')
                }
                else
                {
                    //Debug.Check(0, "unrecognised property %s", p.name);
                }
            }
        }
        protected override void load(int version, string agentType, List<property_t> properties)
        {
            base.load(version, agentType, properties);

            foreach (property_t p in properties)
            {
                if (p.name == "EventName")
                {
                    //method
                    this.m_event = Action.LoadMethod(p.value);
                }
                else if (p.name == "ReferenceFilename")
                {
                    this.m_referencedBehaviorPath = p.value;
                }
                else if (p.name == "TriggeredOnce")
                {
                    if (p.value == "true")
                    {
                        this.m_bTriggeredOnce = true;
                    }
                }
                else if (p.name == "TriggerMode")
                {
                    if (p.value == "Transfer")
                    {
                        this.m_triggerMode = TriggerMode.TM_Transfer;
                    }
                    else if (p.value == "Return")
                    {
                        this.m_triggerMode = TriggerMode.TM_Return;
                    }
                    else
                    {
                        Debug.Check(false, string.Format("unrecognised trigger mode {0}", p.value));
                    }
                }
                else
                {
                    //Debug.Check(0, "unrecognised property %s", p.name);
                }
            }
        }
        protected override void load(int version, string agentType, List<property_t> properties)
        {
            base.load(version, agentType, properties);
            foreach (property_t p in properties)
            {
                if (p.name == "Frames")
                {
                    string propertyName = null;

                    int pParenthesis = p.value.IndexOf('(');
                    if (pParenthesis == -1)
                    {
                        string typeName = null;
                        this.m_frames_var = Condition.LoadRight(p.value, propertyName, ref typeName);
                    }
                    else
                    {
                        //method
                        this.m_frames_method = Action.LoadMethod(p.value);
                    }
                }
            }
        }
        public static bool DoCompare(Agent pAgent, VariableComparator comparator, Property opl, CMethodBase opl_m, Property opr, CMethodBase opr_m)
        {
            bool bResult = false;
            if (opl != null)
            {
                Agent agent_left = opl.GetParentAgent(pAgent);
                Agent agent_right = opr != null ? opr.GetParentAgent(pAgent) : opr_m.GetParentAgent(pAgent);

                bResult = comparator.Execute(agent_left, agent_right);
            }
            else if (opl_m != null)
            {
                Agent agent_left = opl_m.GetParentAgent(pAgent);

                object returnValue = opl_m.Invoke(agent_left, pAgent);

                Agent agent_right = opr != null ? opr.GetParentAgent(pAgent) : opr_m.GetParentAgent(pAgent);

                bResult = comparator.Execute(returnValue, agent_left, agent_right);
            }

            return bResult;
        }
Exemplo n.º 9
0
        protected override void load(int version, string agentType, List<property_t> properties)
        {
            base.load(version, agentType, properties);

            for (int i = 0; i < properties.Count; ++i)
            {
                property_t p = properties[i];
                if (p.name == "Time")
                {
                    int pParenthesis = p.value.IndexOf('(');

                    if (pParenthesis == -1)
                    {
                        string typeName = null;
                        this.m_time_var = Condition.LoadRight(p.value, ref typeName);
                    }
                    else
                    {
                        //method
                        this.m_time_m = Action.LoadMethod(p.value);
                    }
                }
            }
        }
Exemplo n.º 10
0
 public WaitState()
 {
     this.m_time_var = null;
     this.m_time_m = null;
 }
Exemplo n.º 11
0
        protected override void load(int version, string agentType, List<property_t> properties)
        {
            base.load(version, agentType, properties);

            for (int i = 0; i < properties.Count; ++i)
            {
                property_t p = properties[i];

                if (p.name == "ReferenceBehavior")
                {
                    int pParenthesis = p.value.IndexOf('(');

                    if (pParenthesis == -1)
                    {
                        string typeName = null;
                        this.m_referencedBehaviorPath_var = Condition.LoadRight(p.value, ref typeName);
                    }
                    else
                    {
                        //method
                        this.m_referencedBehaviorPath_m = Action.LoadMethod(p.value);
                    }

                    string szTreePath = this.GetReferencedTree(null);

                    //conservatively make it true
                    bool bHasEvents = true;
                    if (!string.IsNullOrEmpty(szTreePath))
                    {
                        BehaviorTree behaviorTree = Workspace.Instance.LoadBehaviorTree(szTreePath);
                        Debug.Check(behaviorTree != null);

                        if (behaviorTree != null)
                        {
                            bHasEvents = behaviorTree.HasEvents();
                        }

                        this.m_bHasEvents |= bHasEvents;
                    }
                }
                else if (p.name == "Task")
                {
                    Debug.Check(!string.IsNullOrEmpty(p.value));
                    CMethodBase m = Action.LoadMethod(p.value);
                    Debug.Check(m is CTaskMethod);

                    this.m_taskMethod = m as CTaskMethod;
                }
                else
                {
                    //Debug.Check(0, "unrecognised property %s", p.name);
                }
            }
        }
Exemplo n.º 12
0
 public ReferencedBehavior()
 {
     this.m_referencedBehaviorPath_var = null;
     this.m_referencedBehaviorPath_m = null;
 }
Exemplo n.º 13
0
        protected override void load(int version, string agentType, List<property_t> properties)
        {
            base.load(version, agentType, properties);

            string typeName = null;
            string propertyName = null;
            string comparatorName = null;

            foreach (property_t p in properties)
            {
                if (p.name == "Operator")
                {
                    comparatorName = p.value;
                }
                else if (p.name == "Opl")
                {
                    int pParenthesis = p.value.IndexOf('(');
                    if (pParenthesis == -1)
                    {
                        this.m_opl = Condition.LoadLeft(p.value, ref propertyName, null);
                    }
                    else
                    {
                        //method
                        this.m_opl_m = Action.LoadMethod(p.value);
                    }
                }
                else if (p.name == "Opr")
                {
                    this.m_opr = Condition.LoadRight(p.value, propertyName, ref typeName);
                }
                else if (p.name == "BinaryOperator")
                {
                    if (p.value == "Or")
                    {
                        this.m_bAnd = false;
                    }
                    else if (p.value == "And")
                    {
                        this.m_bAnd = true;
                    }
                    else
                    {
                        Debug.Check(false);
                    }
                }
                else
                {
                    //Debug.Check(0, "unrecognised property %s", p.name);
                }
            }

            if (!string.IsNullOrEmpty(comparatorName) && (this.m_opl != null || this.m_opl_m != null) && this.m_opr != null)
            {
                this.m_comparator = Condition.Create(typeName, comparatorName, this.m_opl, this.m_opr);
            }
        }
Exemplo n.º 14
0
        protected override void load(int version, string agentType, List<property_t> properties)
        {
            base.load(version, agentType, properties);

            for (int i = 0; i < properties.Count; ++i)
            {
            property_t p = properties[i];
            if (p.name == "Opl")
            {
                this.m_opl = Condition.LoadLeft(p.value);
            }
            else if (p.name == "Operator")
            {
                if (p.value == "Add")
                {
                    this.m_operator = EComputeOperator.E_ADD;
                }
                else if (p.value == "Sub")
                {
                    this.m_operator = EComputeOperator.E_SUB;
                }
                else if (p.value == "Mul")
                {
                    this.m_operator = EComputeOperator.E_MUL;
                }
                else if (p.value == "Div")
                {
                    this.m_operator = EComputeOperator.E_DIV;
                }
                else
                {
                    Debug.Check(false);
                }
            }
            else if (p.name == "Opr1")
            {
                int pParenthesis = p.value.IndexOf('(');

                if (pParenthesis == -1)
                {
                    string typeName = null;
                    this.m_opr1 = Condition.LoadRight(p.value, ref typeName);
                }
                else
                {
                    //method
                    this.m_opr1_m = Action.LoadMethod(p.value);
                }
            }
            else if (p.name == "Opr2")
            {
                int pParenthesis = p.value.IndexOf('(');

                if (pParenthesis == -1)
                {
                    string typeName = null;
                    this.m_opr2 = Condition.LoadRight(p.value, ref typeName);
                }
                else
                {
                    //method
                    this.m_opr2_m = Action.LoadMethod(p.value);
                }
            }
            else
            {
                //Debug.Check(0, "unrecognised property %s", p.name);
            }
            }
        }
Exemplo n.º 15
0
 public DecoratorTime()
 {
     this.m_time_var = null;
     this.m_time_m = null;
 }
Exemplo n.º 16
0
        public virtual bool load(List<property_t> properties)
        {
            string opr2TypeName = null;
            string comparatorName = null;

            foreach(property_t p in properties)
            {
                if (p.name == "Mode")
                {
                    switch (p.value)
                    {
                        case "Condition":
                            this.m_mode = TransitionMode.Condition;
                            break;

                        case "Success":
                            this.m_mode = TransitionMode.Success;
                            break;

                        case "Failure":
                            this.m_mode = TransitionMode.Failure;
                            break;

                        case "End":
                            this.m_mode = TransitionMode.End;
                            break;
                    }
                }
                else if (p.name == "Opl")
                {
                    if (StringUtils.IsValidString(p.value))
                    {
                        int pParenthesis = p.value.IndexOf('(');

                        if (pParenthesis == -1)
                        {
                            string typeName = null;
                            this.m_opl = Condition.LoadRight(p.value, ref typeName);
                        }
                        else
                        {
                            //method
                            this.m_opl_m = Action.LoadMethod(p.value);
                        }
                    }
                }
                else if (p.name == "Opr1")
                {
                    if (StringUtils.IsValidString(p.value))
                    {
                        int pParenthesis = p.value.IndexOf('(');

                        if (pParenthesis == -1)
                        {
                            string typeName = null;
                            this.m_opr1 = Condition.LoadRight(p.value, ref typeName);
                        }
                        else
                        {
                            //method
                            this.m_opr1_m = Action.LoadMethod(p.value);
                        }
                    }
                }
                else if (p.name == "Operator")
                {
                    comparatorName = p.value;

                    switch (p.value)
                    {
                        case "Invalid":
                            this.m_operator = EOperatorType.E_INVALID;
                            break;

                        case "Assign":
                            this.m_operator = EOperatorType.E_ASSIGN;
                            break;

                        case "Add":
                            this.m_operator = EOperatorType.E_ADD;
                            break;

                        case "Sub":
                            this.m_operator = EOperatorType.E_SUB;
                            break;

                        case "Mul":
                            this.m_operator = EOperatorType.E_MUL;
                            break;

                        case "Div":
                            this.m_operator = EOperatorType.E_DIV;
                            break;

                        case "Equal":
                            this.m_operator = EOperatorType.E_EQUAL;
                            break;

                        case "NotEqual":
                            this.m_operator = EOperatorType.E_NOTEQUAL;
                            break;

                        case "Greater":
                            this.m_operator = EOperatorType.E_GREATER;
                            break;

                        case "Less":
                            this.m_operator = EOperatorType.E_LESS;
                            break;

                        case "GreaterEqual":
                            this.m_operator = EOperatorType.E_GREATEREQUAL;
                            break;

                        case "LessEqual":
                            this.m_operator = EOperatorType.E_LESSEQUAL;
                            break;
                    }
                }
                else if (p.name == "Opr2")
                {
                    if (StringUtils.IsValidString(p.value))
                    {
                        int pParenthesis = p.value.IndexOf('(');

                        if (pParenthesis == -1)
                        {
                            this.m_opr2 = Condition.LoadRight(p.value, ref opr2TypeName);
                        }
                        else
                        {
                            //method
                            this.m_opr2_m = Action.LoadMethod(p.value);
                        }
                    }
                }
                else
                {
                    //Debug.Check(0, "unrecognised property %s", p.name);
                }
            }

            // compare
            if (this.m_operator >= EOperatorType.E_EQUAL && this.m_operator <= EOperatorType.E_LESSEQUAL)
            {
                if (!string.IsNullOrEmpty(comparatorName) && (this.m_opl != null || this.m_opl_m != null) &&
                    (this.m_opr2 != null || this.m_opr2_m != null))
                {
                    this.m_comparator = Condition.Create(comparatorName, this.m_opl, this.m_opl_m, this.m_opr2, this.m_opr2_m);
                }
            }

            return this.m_opl != null;
        }
Exemplo n.º 17
0
        private void RegisterType(Type type, bool bExpandMembers)
        {
            bool bReferendAgentType = false;
            Attribute[] attributes = (Attribute[])type.GetCustomAttributes(typeof(behaviac.TypeMetaInfoAttribute), false);

            if (!bExpandMembers && attributes.Length == 0)
            {
                //type is a referenced agent type which is not decorated by TypeMetaInfoAttribute
                if (Utils.IsAgentType(type) && !IsRegisterd_Referenced(type) && !IsRegisterd(type))
                {
                    TypeInfo_t typeInfo = new TypeInfo_t();
                    typeInfo.type = type;

                    m_agentTypes_Referenced.Add(typeInfo);

                    bReferendAgentType = true;
                }
            }

            //agent type must have behaviac.AgentTypeAttribute
            if (!bExpandMembers || attributes.Length > 0 || bReferendAgentType)
            {
                behaviac.TypeMetaInfoAttribute cda = attributes.Length > 0 ? (behaviac.TypeMetaInfoAttribute)attributes[0] : null;

                string typeFullName = type.FullName.Replace('+', '.');
                Agent.CTagObjectDescriptor objectDesc = Agent.GetDescriptorByName(typeFullName);

                if (type.BaseType != null && Utils.IsAgentType(type.BaseType))
                {
                    string baseTypeFullName = type.BaseType.FullName.Replace('+', '.');
                    Agent.CTagObjectDescriptor baseObjectDesc = Agent.GetDescriptorByName(baseTypeFullName);
                    objectDesc.m_parent = baseObjectDesc;
                }

                objectDesc.type = type;
                objectDesc.displayName = ((cda == null || string.IsNullOrEmpty(cda.DisplayName)) ? typeFullName : cda.DisplayName);
                objectDesc.desc = ((cda == null || string.IsNullOrEmpty(cda.Description)) ? objectDesc.displayName : cda.Description);

                if (Utils.IsEnumType(type))
                {
                    return;
                }

                BindingFlags bindingFlags = BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static | BindingFlags.DeclaredOnly;

                FieldInfo[] fields = type.GetFields(bindingFlags);
                foreach (FieldInfo f in fields)
                {
                    //for agent type, only register members with MemberDescAttribute
                    behaviac.MemberMetaInfoAttribute memberDesc;
                    bool bToRegister = IfToRegister(bExpandMembers, f, out memberDesc);

                    if (bToRegister)
                    {
                        CMemberBase m = new CFieldInfo(f, memberDesc);

                        RegisterMember(type, objectDesc, f.FieldType, m);
                    }
                }

                PropertyInfo[] properties = type.GetProperties(bindingFlags);
                foreach (PropertyInfo p in properties)
                {
                    //for agent type, only register members with MemberDescAttribute
                    behaviac.MemberMetaInfoAttribute memberDesc;
                    bool bToRegister = IfToRegister(bExpandMembers, p, out memberDesc);

                    if (bToRegister)
                    {
                        CMemberBase m = new CProperyInfo(p, memberDesc);

                        RegisterMember(type, objectDesc, p.PropertyType, m);
                    }
                }

                if (bExpandMembers)
                {
                    MethodInfo[] methods = type.GetMethods(bindingFlags);
                    foreach (MethodInfo m in methods)
                    {
                        Attribute[] attributes2 = (Attribute[])m.GetCustomAttributes(typeof(behaviac.MethodMetaInfoAttribute), false);

                        if (attributes2.Length > 0)
                        {
                            behaviac.MethodMetaInfoAttribute methodDesc = (behaviac.MethodMetaInfoAttribute)attributes2[0];

                            CMethodBase method = new CMethodBase(m, methodDesc, null);
                            objectDesc.ms_methods.Add(method);

                            ParameterInfo[] parameters = m.GetParameters();

                            foreach (ParameterInfo para in parameters)
                            {
                                if ((Utils.IsCustomClassType(para.ParameterType) || Utils.IsEnumType(para.ParameterType)) &&
                                    !Agent.IsTypeRegisterd(para.ParameterType.FullName))
                                {
                                    RegisterType(para.ParameterType, false);
                                }
                            }

                            if ((Utils.IsCustomClassType(m.ReturnType) || Utils.IsEnumType(m.ReturnType)) &&
                                !Agent.IsTypeRegisterd(m.ReturnType.FullName))
                            {
                                RegisterType(m.ReturnType, false);
                            }
                        }
                    }//end of foreach

                    //Type[] delegates = type.GetNestedTypes(bindingFlags);
                    //foreach (Type d in delegates)
                    //{
                    //    Attribute[] attributes0 = (Attribute[])d.GetCustomAttributes(typeof(behaviac.EventMetaInfoAttribute), false);
                    //    if (attributes0.Length > 0)
                    //    {
                    //        behaviac.EventMetaInfoAttribute eventDesc = (behaviac.EventMetaInfoAttribute)attributes0[0];

                    //        MethodInfo m = d.GetMethod("Invoke");

                    //        CNamedEvent method = new CNamedEvent(m, eventDesc, d.Name);
                    //        objectDesc.m_methods.Add(method);
                    //    }
                    //}
                }//if (bIsAgentType)
            }
        }
Exemplo n.º 18
0
        protected override void load(int version, string agentType, List<property_t> properties)
        {
            base.load(version, agentType, properties);

            for (int i = 0; i < properties.Count; ++i)
            {
                property_t p = properties[i];
                if (p.name == "Method")
                {
                    if (!string.IsNullOrEmpty(p.value))
                    {
                        this.m_method = Action.LoadMethod(p.value);
                    }//if (p.value[0] != '\0')
                }
                else if (p.name == "IsEndState")
                {
                    if (!string.IsNullOrEmpty(p.value))
                    {
                        if (p.value == "true")
                        {
                            this.m_bIsEndState = true;
                        }
                    }
                }
            }
        }
Exemplo n.º 19
0
        private static void RegisterType(Type type, bool bIsAgentType)
        {
            Attribute[] attributes = (Attribute[])type.GetCustomAttributes(typeof(behaviac.TypeMetaInfoAttribute), false);

            //agent type must have behaviac.AgentTypeAttribute
            if (!bIsAgentType || attributes.Length > 0)
            {
                behaviac.TypeMetaInfoAttribute cda = attributes.Length > 0 ? (behaviac.TypeMetaInfoAttribute)attributes[0] : null;

                Agent.CTagObjectDescriptor objectDesc = Agent.GetDescriptorByName(type.FullName);

                if (Utils.IsAgentType(type.BaseType))
                {
                    Agent.CTagObjectDescriptor baseObjectDesc = Agent.GetDescriptorByName(type.BaseType.FullName);
                    objectDesc.m_parent = baseObjectDesc;
                }

                objectDesc.type = type;
                objectDesc.displayName = ((cda == null || string.IsNullOrEmpty(cda.DisplayName)) ? type.FullName : cda.DisplayName);
                objectDesc.desc = ((cda == null || string.IsNullOrEmpty(cda.Description)) ? objectDesc.displayName : cda.Description);

                if (Utils.IsEnumType(type))
                {
                    return;
                }

                BindingFlags bindingFlags = BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static | BindingFlags.DeclaredOnly;

                FieldInfo[] fields = type.GetFields(bindingFlags);
                foreach (FieldInfo f in fields)
                {
                    //for agent type, only register members with MemberDescAttribute
                    bool bToRegister = false;

                    behaviac.MemberMetaInfoAttribute memberDesc = null;
                    if (bIsAgentType)
                    {
                        Attribute[] attributes1 = (Attribute[])f.GetCustomAttributes(typeof(behaviac.MemberMetaInfoAttribute), false);
                        if (attributes1.Length > 0)
                        {
                            memberDesc = (behaviac.MemberMetaInfoAttribute)attributes1[0];
                            bToRegister = true;
                        }
                    }
                    else
                    {
                        bToRegister = true;
                    }

                    if (bToRegister)
                    {
                        CMemberBase m = new CMemberBase(f, memberDesc);

						CMemberBase pMember = objectDesc.ms_members.Find(delegate(CMemberBase m1) { return m1.GetId() == m.GetId(); });
						Debug.Check(pMember == null, "RegisterMetas is called more than once!");

                        objectDesc.ms_members.Add(m);

                        if ((Utils.IsCustomClassType(f.FieldType) || Utils.IsEnumType(f.FieldType)) &&
                            !Agent.IsTypeRegisterd(f.FieldType.FullName))
                        {
                            RegisterType(f.FieldType, false);
                        }
                    }
                }

                if (bIsAgentType)
                {
                    MethodInfo[] methods = type.GetMethods(bindingFlags);
                    foreach (MethodInfo m in methods)
                    {
                        Attribute[] attributes2 = (Attribute[])m.GetCustomAttributes(typeof(behaviac.MethodMetaInfoAttribute), false);
                        if (attributes2.Length > 0)
                        {
                            behaviac.MethodMetaInfoAttribute methodDesc = (behaviac.MethodMetaInfoAttribute)attributes2[0];

                            CMethodBase method = new CMethodBase(m, methodDesc, null);
                            objectDesc.ms_methods.Add(method);

                            ParameterInfo[] parameters = m.GetParameters();

                            foreach (ParameterInfo para in parameters)
                            {
                                if ((Utils.IsCustomClassType(para.ParameterType) || Utils.IsEnumType(para.ParameterType)) &&
                                    !Agent.IsTypeRegisterd(para.ParameterType.FullName))
                                {
                                    RegisterType(para.ParameterType, false);
                                }
                            }

                            if ((Utils.IsCustomClassType(m.ReturnType) || Utils.IsEnumType(m.ReturnType)) &&
                                !Agent.IsTypeRegisterd(m.ReturnType.FullName))
                            {
                                RegisterType(m.ReturnType, false);
                            }
                        }
                    }//end of foreach

                    Type[] delegates = type.GetNestedTypes(bindingFlags);
                    foreach (Type d in delegates)
                    {
                        Attribute[] attributes0 = (Attribute[])d.GetCustomAttributes(typeof(behaviac.EventMetaInfoAttribute), false);
                        if (attributes0.Length > 0)
                        {
                            behaviac.EventMetaInfoAttribute eventDesc = (behaviac.EventMetaInfoAttribute)attributes0[0];

                            MethodInfo m = d.GetMethod("Invoke");

                            CNamedEvent method = new CNamedEvent(m, eventDesc, d.Name);
                            objectDesc.ms_methods.Add(method);
                        }
                    }
                }//if (bIsAgentType)
            }
        }
Exemplo n.º 20
0
        protected override void load(int version, string agentType, List<property_t> properties)
        {
            base.load(version, agentType, properties);

            string typeName = null;
            string comparatorName = null;

            for (int i = 0; i < properties.Count; ++i)
            {
                property_t p = properties[i];
                if (p.name == "Operator")
                {
                    comparatorName = p.value;
                }
                else if (p.name == "Opl")
                {
                    int pParenthesis = p.value.IndexOf('(');

                    if (pParenthesis == -1)
                    {
                        this.m_opl = LoadLeft(p.value);
                    }
                    else
                    {
                        this.m_opl_m = Action.LoadMethod(p.value);
                    }
                }
                else if (p.name == "Opr")
                {
                    int pParenthesis = p.value.IndexOf('(');

                    if (pParenthesis == -1)
                    {
                        this.m_opr = LoadRight(p.value, ref typeName);
                    }
                    else
                    {
                        this.m_opr_m = Action.LoadMethod(p.value);
                    }
                }
                else
                {
                    //Debug.Check(0, "unrecognised property %s", p.name);
                }
            }

            if (!string.IsNullOrEmpty(comparatorName) && (this.m_opl != null || this.m_opl_m != null) && (this.m_opr != null || this.m_opr_m != null))
            {
                this.m_comparator = Condition.Create(comparatorName, this.m_opl, this.m_opl_m, this.m_opr, this.m_opr_m);
            }
        }
Exemplo n.º 21
0
            //generate a random float value between 0 and 1.
            public static float GetRandomValue(CMethodBase method, Agent pAgent)
            {
                float value = 0;
                if (method != null)
                {
                    ParentType pt = method.GetParentType();
                    Agent pParent = pAgent;
                    if (pt == ParentType.PT_INSTANCE)
                    {
                        pParent = Agent.GetInstance(method.GetInstanceNameString(), pParent.GetContextId());
                        Debug.Check(pParent != null || Utils.IsStaticClass(method.GetInstanceNameString()));
                    }

                    value = (float)method.run(pParent, pAgent);
                }
                else
                {
                    value = RandomGenerator.GetInstance().GetRandom();
                }

                Debug.Check(value >= 0.0f && value < 1.0f);
                return value;
            }
Exemplo n.º 22
0
 public State()
 {
     m_bIsEndState = false;
     m_method = null;
 }
Exemplo n.º 23
0
        protected override void load(int version, string agentType, List<property_t> properties)
        {
            base.load(version, agentType, properties);

            foreach (property_t p in properties)
            {
                if (p.name == "Method")
                {
                    if (!string.IsNullOrEmpty(p.value))
                    {
                        this.m_method = Action.LoadMethod(p.value);
                    }//if (p.value[0] != '\0')
                }
                else if (p.name == "ResultOption")
                {
                    if (p.value == "BT_INVALID")
                    {
                        m_resultOption = EBTStatus.BT_INVALID;
                    }
                    else if (p.value == "BT_FAILURE")
                    {
                        m_resultOption = EBTStatus.BT_FAILURE;
                    }
                    else if (p.value == "BT_RUNNING")
                    {
                        m_resultOption = EBTStatus.BT_RUNNING;
                    }
                    else
                    {
                        m_resultOption = EBTStatus.BT_SUCCESS;
                    }
                }
                else if (p.name == "ResultFunctor")
                {
                    if (p.value[0] != '\0')
                    {
                        this.m_resultFunctor = Action.LoadMethod(p.value);
                    }
                }
                else if (p.name == "PreconditionFailResult")
                {
                    if (p.value == "BT_FAILURE")
                    {
                        m_resultPreconditionFail = EBTStatus.BT_FAILURE;
                    }
                    else if (p.value == "BT_BT_SUCCESS")
                    {
                        m_resultPreconditionFail = EBTStatus.BT_SUCCESS;
                    }
                    else
                    {
                        Debug.Check(false);
                    }
                }
                else
                {
                    //Debug.Check(0, "unrecognised property %s", p.name);
                }
            }
        }
        protected override void load(int version, string agentType, List<property_t> properties)
        {
            base.load(version, agentType, properties);

            string propertyName = null;

            foreach (property_t p in properties)
            {
                if (p.name == "Opl")
                {
                    this.m_opl = Condition.LoadLeft(p.value, ref propertyName, null);
                }
                else if (p.name == "Opr")
                {
                    int pParenthesis = p.value.IndexOf('(');
                    if (pParenthesis == -1)
                    {
                        string typeName = null;
                        this.m_opr = Condition.LoadRight(p.value, propertyName, ref typeName);
                    }
                    else
                    {
                        //method
                        this.m_opr_m = Action.LoadMethod(p.value);
                    }
                }
                else
                {
                    //Debug.Check(0, "unrecognised property %s", p.name);
                }
            }
        }