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;
        }
Esempio n. 2
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;
        }
Esempio n. 3
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);
            }
        }
Esempio n. 4
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);
            }
        }