示例#1
0
        public static void GenerateOperand(DefaultObject defaultObj, StringWriter stream, string indent, RightValueDef operand, string operandName, string nodeName)
        {
            if (operand != null)
            {
                string typeName = DataCsExporter.GetGeneratedNativeType(operand.ValueType);
                typeName = typeName.Replace("::", ".");

                if (operand.IsMethod) // method
                {
                    RightValueCsExporter.GenerateCode(defaultObj, operand, stream, indent, typeName, operandName, string.Empty);
                    RightValueCsExporter.PostGenerateCode(operand, stream, indent, typeName, operandName, string.Empty);
                }
                else
                {
                    VariableDef var = operand.Var;

                    if (var != null)
                    {
                        if (var.IsProperty) // property
                        {
                            PropertyDef prop = var.Property;

                            if (prop != null)
                            {
                                string property = PropertyCsExporter.GetProperty(defaultObj, prop, var.ArrayIndexElement, stream, indent, operandName, nodeName);
                                string propName = prop.BasicName.Replace("[]", "");

                                if (prop.IsArrayElement && var.ArrayIndexElement != null)
                                {
                                    ParameterCsExporter.GenerateCode(defaultObj, var.ArrayIndexElement, stream, indent, "int", operandName + "_index", nodeName + "_opl");
                                    property = string.Format("({0})[{1}_index]", property, operandName);
                                }

                                stream.WriteLine("{0}{1} {2} = {3};", indent, typeName, operandName, property);
                            }
                        }
                        else if (var.IsConst) // const
                        {
                            RightValueCsExporter.GenerateCode(defaultObj, operand, stream, indent, typeName, operandName, string.Empty);
                        }
                    }
                }
            }
        }
示例#2
0
        protected override void GenerateMethod(Node node, StreamWriter stream, string indent)
        {
            base.GenerateMethod(node, stream, indent);

            Assignment assignment = node as Assignment;

            Debug.Check(assignment != null);

            stream.WriteLine("{0}\t\tprotected override EBTStatus update_impl(behaviac.Agent pAgent, behaviac.EBTStatus childStatus)", indent);
            stream.WriteLine("{0}\t\t{{", indent);
            stream.WriteLine("{0}\t\t\tEBTStatus result = EBTStatus.BT_SUCCESS;", indent);

            if (assignment.Opl != null && assignment.Opr != null)
            {
                if (assignment.Opl.IsPar)
                {
                    ParInfo par = assignment.Opl.Value as ParInfo;
                    if (par != null)
                    {
                        RightValueCsExporter.GenerateCode(assignment.Opr, stream, indent + "\t\t\t", assignment.Opr.NativeType.Replace("::", "."), "opr", "opr");
                        uint   id       = Behaviac.Design.CRC32.CalcCRC(par.Name);
                        string typename = DataCsExporter.GetGeneratedNativeType(par.NativeType);
                        stream.WriteLine("{0}\t\t\tDebug.Check(behaviac.Utils.MakeVariableId(\"{1}\") == {2}u);", indent, par.Name, id);
                        stream.WriteLine("{0}\t\t\tpAgent.SetVariable<{1}>(\"{2}\", opr, {3}u);", indent, typename, par.Name, id);
                    }
                }
                else
                {
                    Debug.Check(assignment.Opl.IsProperty);
                    RightValueCsExporter.GenerateCode(assignment.Opr, stream, indent + "\t\t\t", assignment.Opr.NativeType.Replace("::", "."), "opr", "opr");
                    //VariableCsExporter.GenerateCode(assignment.Opl, stream, indent + "\t\t\t", string.Empty, string.Empty, "opl", "opr");
                    VariableCsExporter.PostGenerateCode(assignment.Opl, stream, indent + "\t\t\t", assignment.Opl.NativeType.Replace("::", "."), "opl", string.Empty, null, "", "opr");
                }

                if (assignment.Opr.IsMethod)
                {
                    RightValueCsExporter.PostGenerateCode(assignment.Opr, stream, indent + "\t\t\t", assignment.Opr.NativeType.Replace("::", "."), "opr", string.Empty);
                }
            }

            stream.WriteLine("{0}\t\t\treturn result;", indent);
            stream.WriteLine("{0}\t\t}}", indent);
        }
示例#3
0
        protected override void GenerateMethod(Behaviac.Design.Attachments.Attachment attachment, StreamWriter stream, string indent)
        {
            base.GenerateMethod(attachment, stream, indent);

            TransitionCondition transition = attachment as TransitionCondition;

            if (transition == null)
            {
                return;
            }

            stream.WriteLine("{0}\t\tprotected override EBTStatus update_impl(behaviac.Agent pAgent, behaviac.EBTStatus childStatus)", indent);
            stream.WriteLine("{0}\t\t{{", indent);
            stream.WriteLine("{0}\t\t\tEBTStatus result = EBTStatus.BT_SUCCESS;", indent);

            {
                string typeName = Plugin.GetNativeTypeName(transition.Opl.ValueType);
                typeName = typeName.Replace("::", ".");

                RightValueCsExporter.GenerateCode(attachment, transition.Opl, stream, indent + "\t\t\t", typeName, "opl", "");
                RightValueCsExporter.GenerateCode(attachment, transition.Opr2, stream, indent + "\t\t\t", typeName, "opr2", "");

                if (transition.Opl != null && transition.Opl.IsMethod)
                {
                    RightValueCsExporter.PostGenerateCode(transition.Opl, stream, indent + "\t\t\t", typeName, "opl", "");
                }

                if (transition.Opr2 != null && transition.Opr2.IsMethod)
                {
                    RightValueCsExporter.PostGenerateCode(transition.Opr2, stream, indent + "\t\t\t", typeName, "opr2", "");
                }

                switch (transition.Operator)
                {
                case OperatorTypes.Equal:
                    stream.WriteLine("{0}\t\t\tbool op = (opl == opr2);", indent);
                    break;

                case OperatorTypes.NotEqual:
                    stream.WriteLine("{0}\t\t\tbool op = (opl != opr2);", indent);
                    break;

                case OperatorTypes.Greater:
                    stream.WriteLine("{0}\t\t\tbool op = (opl > opr2);", indent);
                    break;

                case OperatorTypes.GreaterEqual:
                    stream.WriteLine("{0}\t\t\tbool op = (opl >= opr2);", indent);
                    break;

                case OperatorTypes.Less:
                    stream.WriteLine("{0}\t\t\tbool op = (opl < opr2);", indent);
                    break;

                case OperatorTypes.LessEqual:
                    stream.WriteLine("{0}\t\t\tbool op = (opl <= opr2);", indent);
                    break;

                default:
                    stream.WriteLine("{0}\t\t\tbool op = false;", indent);
                    break;
                }
            }

            stream.WriteLine("{0}\t\t\tif (!op)", indent);
            stream.WriteLine("{0}\t\t\t\tresult = EBTStatus.BT_FAILURE;", indent);

            stream.WriteLine("{0}\t\t\treturn result;", indent);
            stream.WriteLine("{0}\t\t}}", indent);
        }
        protected override void GenerateMethod(Node node, StreamWriter stream, string indent)
        {
            base.GenerateMethod(node, stream, indent);

            Assignment assignment = node as Assignment;

            if (assignment == null)
            {
                return;
            }

            stream.WriteLine("{0}\t\tvirtual EBTStatus update_impl(Agent* pAgent, EBTStatus childStatus)", indent);
            stream.WriteLine("{0}\t\t{{", indent);
            stream.WriteLine("{0}\t\t\tBEHAVIAC_UNUSED_VAR(pAgent);", indent);
            stream.WriteLine("{0}\t\t\tBEHAVIAC_UNUSED_VAR(childStatus);", indent);
            stream.WriteLine("{0}\t\t\tEBTStatus result = BT_SUCCESS;", indent);

            if (assignment.Opl != null && assignment.Opr != null)
            {
                PropertyDef prop = assignment.Opl.Property;

                if (prop != null)
                {
                    RightValueCppExporter.GenerateCode(assignment.Opr, stream, indent + "\t\t\t", assignment.Opr.NativeType, "opr", "opr");

                    string property = PropertyCppExporter.GetProperty(prop, assignment.Opl.ArrayIndexElement, stream, indent + "\t\t\t", "opl", "assignment");
                    string propName = prop.BasicName.Replace("[]", "");

                    if (prop.IsArrayElement && assignment.Opl.ArrayIndexElement != null)
                    {
                        ParameterCppExporter.GenerateCode(assignment.Opl.ArrayIndexElement, stream, indent + "\t\t\t", "int", "opl_index", "assignment_opl");
                        property = string.Format("({0})[opl_index]", property);
                    }

                    string opr = "opr";
                    if (!Plugin.IsArrayType(prop.Type))
                    {
                        if (assignment.Opr.Var != null && assignment.Opr.Var.ArrayIndexElement != null)
                        {
                            ParameterCppExporter.GenerateCode(assignment.Opr.Var.ArrayIndexElement, stream, indent + "\t\t\t", "int", "opr_index", "assignment_opr");
                            opr = string.Format("({0})[opr_index]", opr);
                        }
                    }

                    if (!prop.IsArrayElement && (prop.IsPar || prop.IsCustomized))
                    {
                        string propBasicName = prop.BasicName.Replace("[]", "");
                        uint   id            = Behaviac.Design.CRC32.CalcCRC(propBasicName);

                        stream.WriteLine("{0}\t\t\tBEHAVIAC_ASSERT(behaviac::MakeVariableId(\"{1}\") == {2}u);", indent, propBasicName, id);
                        stream.WriteLine("{0}\t\t\tpAgent->SetVariable(\"{1}\", {2}, {3}u);", indent, propBasicName, opr, id);
                    }
                    else
                    {
                        stream.WriteLine("{0}\t\t\t{1} = {2};", indent, property, opr);
                    }
                }

                if (assignment.Opr.IsMethod)
                {
                    RightValueCsExporter.PostGenerateCode(assignment.Opr, stream, indent + "\t\t\t", assignment.Opr.NativeType, "opr", string.Empty);
                }
            }

            stream.WriteLine("{0}\t\t\treturn result;", indent);
            stream.WriteLine("{0}\t\t}}", indent);
        }
        protected override void GenerateMethod(Node node, StringWriter stream, string indent)
        {
            base.GenerateMethod(node, stream, indent);

            Assignment assignment = node as Assignment;

            if (assignment == null)
            {
                return;
            }

            stream.WriteLine("{0}\t\tprotected override EBTStatus update_impl(behaviac.Agent pAgent, behaviac.EBTStatus childStatus)", indent);
            stream.WriteLine("{0}\t\t{{", indent);
            stream.WriteLine("{0}\t\t\tEBTStatus result = EBTStatus.BT_SUCCESS;", indent);

            if (assignment.Opl != null && assignment.Opr != null)
            {
                PropertyDef prop = assignment.Opl.Property;

                if (prop != null)
                {
                    RightValueCsExporter.GenerateCode(node, assignment.Opr, stream, indent + "\t\t\t", assignment.Opr.NativeType.Replace("::", "."), "opr", "opr");

                    string property = PropertyCsExporter.GetProperty(node, prop, assignment.Opl.ArrayIndexElement, stream, indent + "\t\t\t", "opl", "assignment");
                    string propName = prop.BasicName.Replace("[]", "");

                    if (prop.IsArrayElement && assignment.Opl.ArrayIndexElement != null)
                    {
                        ParameterCsExporter.GenerateCode(node, assignment.Opl.ArrayIndexElement, stream, indent + "\t\t\t", "int", "opl_index", "assignment_opl");
                        property = string.Format("({0})[opl_index]", property);
                    }

                    string oprStr = "opr";

                    if (!Plugin.IsArrayType(prop.Type))
                    {
                        if (assignment.Opr.Var != null && assignment.Opr.Var.ArrayIndexElement != null)
                        {
                            ParameterCsExporter.GenerateCode(node, assignment.Opr.Var.ArrayIndexElement, stream, indent + "\t\t\t", "int", "opr_index", "assignment_opr");
                            oprStr = string.Format("({0})[opr_index]", oprStr);
                        }
                    }

                    if (!prop.IsArrayElement && (!prop.IsPublic || prop.IsPar || prop.IsCustomized))
                    {
                        string propBasicName = prop.BasicName.Replace("[]", "");
                        uint   id            = Behaviac.Design.CRC32.CalcCRC(propBasicName);
                        string agentName     = PropertyCsExporter.GetGenerateAgentName(prop, "opl", "assignment");
                        string typename      = DataCsExporter.GetGeneratedNativeType(prop.NativeType);

                        stream.WriteLine("{0}\t\t\t{1}.SetVariable<{2}>(\"{3}\", {4}u, {5});", indent, agentName, typename, propBasicName, id, oprStr);
                    }
                    else
                    {
                        if (assignment.IsCasting)
                        {
                            stream.WriteLine("{0}\t\t\t{1} = ({2}){3};", indent, property, DataCsExporter.GetGeneratedNativeType(assignment.Opl.ValueType), oprStr);
                        }
                        else
                        {
                            stream.WriteLine("{0}\t\t\t{1} = {2};", indent, property, oprStr);
                        }
                    }
                }

                if (assignment.Opr.IsMethod)
                {
                    RightValueCsExporter.PostGenerateCode(assignment.Opr, stream, indent + "\t\t\t", assignment.Opr.NativeType.Replace("::", "."), "opr", string.Empty);
                }
            }

            stream.WriteLine("{0}\t\t\treturn result;", indent);
            stream.WriteLine("{0}\t\t}}", indent);
        }
示例#6
0
        protected override void GenerateMethod(Behaviac.Design.Attachments.Attachment attachment, StreamWriter stream, string indent)
        {
            base.GenerateMethod(attachment, stream, indent);

            AttachAction attach = attachment as AttachAction;

            if (attach == null)
            {
                return;
            }

            stream.WriteLine("{0}\t\tprotected override EBTStatus update_impl(behaviac.Agent pAgent, behaviac.EBTStatus childStatus)", indent);
            stream.WriteLine("{0}\t\t{{", indent);
            stream.WriteLine("{0}\t\t\tEBTStatus result = EBTStatus.BT_SUCCESS;", indent);

            if (attach.IsAction())
            {
                string method = MethodCsExporter.GenerateCode(attachment, attach.Opl.Method, stream, indent + "\t\t\t", string.Empty, string.Empty, "opl");

                stream.WriteLine("{0}\t\t\t{1};", indent, method);
                MethodCsExporter.PostGenerateCode(attach.Opl.Method, stream, indent + "\t\t\t", string.Empty, string.Empty, "opl");
            }
            else if (attach.IsAssign())
            {
                if (attach.Opl != null && !attach.Opl.IsMethod && attach.Opl.Var != null && attach.Opr2 != null)
                {
                    PropertyDef prop = attach.Opl.Var.Property;
                    if (prop != null)
                    {
                        RightValueCsExporter.GenerateCode(attachment, attach.Opr2, stream, indent + "\t\t\t", attach.Opr2.NativeType.Replace("::", "."), "opr2", "opr2");

                        string property = PropertyCsExporter.GetProperty(attachment, prop, attach.Opl.Var.ArrayIndexElement, stream, indent + "\t\t\t", "opl", "attach");
                        string propName = prop.BasicName.Replace("[]", "");

                        if (prop.IsArrayElement && attach.Opl.Var.ArrayIndexElement != null)
                        {
                            ParameterCsExporter.GenerateCode(attachment, attach.Opl.Var.ArrayIndexElement, stream, indent + "\t\t\t", "int", "opl_index", "attach_opl");
                            property = string.Format("({0})[opl_index]", property);
                        }

                        string propBasicName = prop.BasicName.Replace("[]", "");

                        if (!prop.IsArrayElement && (prop.IsPar || prop.IsCustomized))
                        {
                            uint   id           = Behaviac.Design.CRC32.CalcCRC(propBasicName);
                            string oplAgentName = PropertyCsExporter.GetGenerateAgentName(prop, "opl", "attach");

                            stream.WriteLine("{0}\t\t\t{1}.SetVariable(\"{2}\", {3}u, opr2);", indent, oplAgentName, propBasicName, id);
                        }
                        else
                        {
                            if (prop.IsPublic)
                            {
                                stream.WriteLine("{0}\t\t\t{1} = opr2;", indent, property);
                            }
                            else
                            {
                                string agentName = PropertyCsExporter.GetGenerateAgentName(prop, "opr2", "opr2");
                                stream.WriteLine("{0}\t\t\tAgentExtra_Generated.SetProperty({1}, \"{2}\", opr2);", indent, agentName, propBasicName);
                            }
                        }

                        if (attach.Opr2.IsMethod)
                        {
                            RightValueCsExporter.PostGenerateCode(attach.Opr2, stream, indent + "\t\t\t", attach.Opr2.NativeType.Replace("::", "."), "opr2", string.Empty);
                        }
                    }
                }
            }
            else if (attach.IsCompare())
            {
                ConditionCsExporter.GenerateOperand(attachment, stream, indent + "\t\t\t", attach.Opl, "opl", "");
                ConditionCsExporter.GenerateOperand(attachment, stream, indent + "\t\t\t", attach.Opr2, "opr2", "");

                switch (attach.Operator)
                {
                case OperatorTypes.Equal:
                    stream.WriteLine("{0}\t\t\tbool op = (opl == opr2);", indent);
                    break;

                case OperatorTypes.NotEqual:
                    stream.WriteLine("{0}\t\t\tbool op = (opl != opr2);", indent);
                    break;

                case OperatorTypes.Greater:
                    stream.WriteLine("{0}\t\t\tbool op = (opl > opr2);", indent);
                    break;

                case OperatorTypes.GreaterEqual:
                    stream.WriteLine("{0}\t\t\tbool op = (opl >= opr2);", indent);
                    break;

                case OperatorTypes.Less:
                    stream.WriteLine("{0}\t\t\tbool op = (opl < opr2);", indent);
                    break;

                case OperatorTypes.LessEqual:
                    stream.WriteLine("{0}\t\t\tbool op = (opl <= opr2);", indent);
                    break;

                default:
                    stream.WriteLine("{0}\t\t\tbool op = false;", indent);
                    break;
                }
                stream.WriteLine("{0}\t\t\tif (!op)", indent);
                stream.WriteLine("{0}\t\t\t\tresult = EBTStatus.BT_FAILURE;", indent);
            }
            else if (attach.IsCompute())
            {
                if (attach.Opl != null && !attach.Opl.IsMethod && attach.Opl.Var != null && attach.Opr1 != null && attach.Opr2 != null)
                {
                    PropertyDef prop = attach.Opl.Var.Property;
                    if (prop != null)
                    {
                        string typeName = Plugin.GetNativeTypeName(attach.Opr1.ValueType);
                        typeName = typeName.Replace("::", ".");

                        RightValueCsExporter.GenerateCode(attachment, attach.Opr1, stream, indent + "\t\t\t", typeName, "opr1", "opr1");
                        RightValueCsExporter.GenerateCode(attachment, attach.Opr2, stream, indent + "\t\t\t", typeName, "opr2", "opr2");

                        string oprStr = string.Empty;
                        switch (attach.Operator)
                        {
                        case OperatorTypes.Add:
                            oprStr = "opr1 + opr2";
                            break;

                        case OperatorTypes.Sub:
                            oprStr = "opr1 - opr2";
                            break;

                        case OperatorTypes.Mul:
                            oprStr = "opr1 * opr2";
                            break;

                        case OperatorTypes.Div:
                            oprStr = "opr1 / opr2";
                            break;

                        default:
                            Debug.Check(false, "The operator is wrong!");
                            break;
                        }

                        oprStr = string.Format("({0})({1})", typeName, oprStr);

                        string property = PropertyCsExporter.GetProperty(attachment, prop, attach.Opl.Var.ArrayIndexElement, stream, indent + "\t\t\t", "opl", "attach");
                        string propName = prop.BasicName.Replace("[]", "");

                        if (prop.IsArrayElement && attach.Opl.Var.ArrayIndexElement != null)
                        {
                            ParameterCsExporter.GenerateCode(attachment, attach.Opl.Var.ArrayIndexElement, stream, indent + "\t\t\t", "int", "opl_index", "attach_opl");
                            property = string.Format("({0})[opl_index]", property);
                        }

                        string propBasicName = prop.BasicName.Replace("[]", "");
                        string agentName     = PropertyCsExporter.GetGenerateAgentName(prop, "opl", "attach");

                        if (!prop.IsArrayElement && (prop.IsPar || prop.IsCustomized))
                        {
                            uint id = Behaviac.Design.CRC32.CalcCRC(propBasicName);

                            stream.WriteLine("{0}\t\t\t{1}.SetVariable(\"{2}\", {3}u, {4});", indent, agentName, propBasicName, id, oprStr);
                        }
                        else if (prop.IsPublic)
                        {
                            stream.WriteLine("{0}\t\t\t{1} = {2};", indent, property, oprStr);
                        }
                        else
                        {
                            stream.WriteLine("{0}\t\t\tAgentExtra_Generated.SetProperty({1}, \"{2}\", {3});", indent, agentName, propBasicName, oprStr);
                        }

                        if (attach.Opr1.IsMethod)
                        {
                            RightValueCsExporter.PostGenerateCode(attach.Opr1, stream, indent + "\t\t\t", typeName, "opr1", string.Empty);
                        }

                        if (attach.Opr2.IsMethod)
                        {
                            RightValueCsExporter.PostGenerateCode(attach.Opr2, stream, indent + "\t\t\t", typeName, "opr2", string.Empty);
                        }
                    }
                }
            }

            stream.WriteLine("{0}\t\t\treturn result;", indent);
            stream.WriteLine("{0}\t\t}}", indent);
        }
示例#7
0
        protected override void GenerateMethod(Node node, StreamWriter stream, string indent)
        {
            base.GenerateMethod(node, stream, indent);

            Compute compute = node as Compute;

            if (compute == null)
            {
                return;
            }

            stream.WriteLine("{0}\t\tprotected override EBTStatus update_impl(behaviac.Agent pAgent, behaviac.EBTStatus childStatus)", indent);
            stream.WriteLine("{0}\t\t{{", indent);
            stream.WriteLine("{0}\t\t\tEBTStatus result = EBTStatus.BT_SUCCESS;", indent);

            if (compute.Opl != null && compute.Opr1 != null && compute.Opr2 != null)
            {
                string typeName = Plugin.GetNativeTypeName(compute.Opr1.ValueType);
                typeName = typeName.Replace("::", ".");

                RightValueCsExporter.GenerateCode(compute.Opr1, stream, indent + "\t\t\t", typeName, "opr1", "opr1");
                RightValueCsExporter.GenerateCode(compute.Opr2, stream, indent + "\t\t\t", typeName, "opr2", "opr2");

                string oprStr = string.Empty;
                switch (compute.Operator)
                {
                case ComputeOperator.Add:
                    oprStr = "opr1 + opr2";
                    break;

                case ComputeOperator.Sub:
                    oprStr = "opr1 - opr2";
                    break;

                case ComputeOperator.Mul:
                    oprStr = "opr1 * opr2";
                    break;

                case ComputeOperator.Div:
                    oprStr = "opr1 / opr2";
                    break;

                default:
                    Debug.Check(false, "The operator is wrong!");
                    break;
                }

                oprStr = string.Format("({0})({1})", typeName, oprStr);

                PropertyDef prop = compute.Opl.Property;
                if (prop != null)
                {
                    string property = PropertyCsExporter.GetProperty(prop, compute.Opl.ArrayIndexElement, stream, indent + "\t\t\t", "opl", "compute");
                    string propName = prop.BasicName.Replace("[]", "");

                    if (prop.IsArrayElement && compute.Opl.ArrayIndexElement != null)
                    {
                        ParameterCsExporter.GenerateCode(compute.Opl.ArrayIndexElement, stream, indent + "\t\t\t", "int", "opl_index", "compute_opl");
                        property = string.Format("({0})[opl_index]", property);
                    }

                    if (!prop.IsArrayElement && (prop.IsPar || prop.IsCustomized))
                    {
                        string propBasicName = prop.BasicName.Replace("[]", "");
                        uint   id            = Behaviac.Design.CRC32.CalcCRC(propBasicName);

                        string typename = DataCsExporter.GetGeneratedNativeType(prop.NativeType);
                        stream.WriteLine("{0}\t\t\tDebug.Check(behaviac.Utils.MakeVariableId(\"{1}\") == {2}u);", indent, propBasicName, id);
                        stream.WriteLine("{0}\t\t\tpAgent.SetVariable<{1}>(\"{2}\", {3}, {4}u);", indent, typename, propBasicName, oprStr, id);
                    }
                    else
                    {
                        stream.WriteLine("{0}\t\t\t{1} = {2};", indent, property, oprStr);
                    }
                }

                if (compute.Opr1.IsMethod)
                {
                    RightValueCsExporter.PostGenerateCode(compute.Opr1, stream, indent + "\t\t\t", typeName, "opr1", string.Empty);
                }

                if (compute.Opr2.IsMethod)
                {
                    RightValueCsExporter.PostGenerateCode(compute.Opr2, stream, indent + "\t\t\t", typeName, "opr2", string.Empty);
                }
            }

            stream.WriteLine("{0}\t\t\treturn result;", indent);
            stream.WriteLine("{0}\t\t}}", indent);
        }
示例#8
0
        protected override void GenerateMethod(Node node, StreamWriter stream, string indent)
        {
            base.GenerateMethod(node, stream, indent);

            Compute compute = node as Compute;

            Debug.Check(compute != null);

            stream.WriteLine("{0}\t\tprotected override EBTStatus update_impl(behaviac.Agent pAgent, behaviac.EBTStatus childStatus)", indent);
            stream.WriteLine("{0}\t\t{{", indent);
            stream.WriteLine("{0}\t\t\tEBTStatus result = EBTStatus.BT_SUCCESS;", indent);

            if (compute.Opl != null && compute.Opr1 != null && compute.Opr2 != null)
            {
                RightValueCsExporter.GenerateCode(compute.Opr1, stream, indent + "\t\t\t", compute.Opr1.NativeType, "opr1", "opr1");
                RightValueCsExporter.GenerateCode(compute.Opr2, stream, indent + "\t\t\t", compute.Opr2.NativeType, "opr2", "opr2");

                string oprStr = string.Empty;
                switch (compute.Operator)
                {
                case ComputeOperator.Add:
                    oprStr = "opr1 + opr2";
                    break;

                case ComputeOperator.Sub:
                    oprStr = "opr1 - opr2";
                    break;

                case ComputeOperator.Mul:
                    oprStr = "opr1 * opr2";
                    break;

                case ComputeOperator.Div:
                    oprStr = "opr1 / opr2";
                    break;

                default:
                    Debug.Check(false, "The operator is wrong!");
                    break;
                }

                string basicType = DataCsExporter.GetGeneratedNativeType(compute.Opl.NativeType);
                stream.WriteLine("{0}\t\t\t{1} opr = ({1})({2});", indent, basicType, oprStr);

                if (compute.Opl.IsPar)
                {
                    ParInfo par = compute.Opl.Value as ParInfo;
                    if (par != null)
                    {
                        uint id = Behaviac.Design.CRC32.CalcCRC(par.Name);
                        stream.WriteLine("{0}\t\t\tDebug.Check(behaviac.Utils.MakeVariableId(\"{1}\") == {2}u);", indent, par.Name, id);
                        stream.WriteLine("{0}\t\t\tpAgent.SetVariable(\"{1}\", opr, {2}u);", indent, par.Name, id);
                    }
                }
                else
                {
                    //VariableCsExporter.GenerateCode(compute.Opl, stream, indent + "\t\t\t", string.Empty, string.Empty, "opl", "opr");
                    VariableCsExporter.PostGenerateCode(compute.Opl, stream, indent + "\t\t\t", compute.Opl.NativeType, "opl", string.Empty, null, "", "opr");
                }

                if (compute.Opr1.IsMethod)
                {
                    RightValueCsExporter.PostGenerateCode(compute.Opr1, stream, indent + "\t\t\t", compute.Opr1.NativeType, "opr1", string.Empty);
                }

                if (compute.Opr2.IsMethod)
                {
                    RightValueCsExporter.PostGenerateCode(compute.Opr2, stream, indent + "\t\t\t", compute.Opr2.NativeType, "opr2", string.Empty);
                }
            }

            stream.WriteLine("{0}\t\t\treturn result;", indent);
            stream.WriteLine("{0}\t\t}}", indent);
        }
示例#9
0
        protected override void GenerateMethod(Node node, StreamWriter stream, string indent)
        {
            base.GenerateMethod(node, stream, indent);

            PluginBehaviac.Nodes.Condition condition = node as PluginBehaviac.Nodes.Condition;
            if (condition == null)
            {
                return;
            }

            stream.WriteLine("{0}\t\tprotected override EBTStatus update_impl(behaviac.Agent pAgent, behaviac.EBTStatus childStatus)", indent);
            stream.WriteLine("{0}\t\t{{", indent);

            string typeName = DataCsExporter.GetGeneratedNativeType(condition.Opl.ValueType);

            // opl
            if (condition.Opl != null)
            {
                RightValueCsExporter.GenerateCode(condition.Opl, stream, indent + "\t\t\t", typeName, "opl", string.Empty);
                if (condition.Opl.IsMethod)
                {
                    RightValueCsExporter.PostGenerateCode(condition.Opl, stream, indent + "\t\t\t", typeName, "opl", string.Empty);
                }
            }

            // opr
            if (condition.Opr != null)
            {
                RightValueCsExporter.GenerateCode(condition.Opr, stream, indent + "\t\t\t", typeName, "opr", string.Empty);
                if (condition.Opr != null)
                {
                    RightValueCsExporter.PostGenerateCode(condition.Opr, stream, indent + "\t\t\t", typeName, "opr", string.Empty);
                }
            }

            // Operator
            switch (condition.Operator)
            {
            case OperatorType.Equal:
                stream.WriteLine("{0}\t\t\tbool op = opl == opr;", indent);
                break;

            case OperatorType.NotEqual:
                stream.WriteLine("{0}\t\t\tbool op = opl != opr;", indent);
                break;

            case OperatorType.Greater:
                stream.WriteLine("{0}\t\t\tbool op = opl > opr;", indent);
                break;

            case OperatorType.GreaterEqual:
                stream.WriteLine("{0}\t\t\tbool op = opl >= opr;", indent);
                break;

            case OperatorType.Less:
                stream.WriteLine("{0}\t\t\tbool op = opl < opr;", indent);
                break;

            case OperatorType.LessEqual:
                stream.WriteLine("{0}\t\t\tbool op = opl <= opr;", indent);
                break;

            case OperatorType.And:
                stream.WriteLine("{0}\t\t\tbool op = opl && opr;", indent);
                break;

            case OperatorType.Or:
                stream.WriteLine("{0}\t\t\tbool op = opl || opr;", indent);
                break;

            default:
                stream.WriteLine("{0}\t\t\tbool op = false;", indent);
                break;
            }

            stream.WriteLine("{0}\t\t\treturn op ? EBTStatus.BT_SUCCESS : EBTStatus.BT_FAILURE;", indent);
            stream.WriteLine("{0}\t\t}}", indent);
        }