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

            PluginBehaviac.Nodes.Condition condition = node as PluginBehaviac.Nodes.Condition;
            Debug.Check(condition != null);

            if (condition.Opl != null)
            {
                RightValueCppExporter.GenerateClassMember(condition.Opl, stream, indent, "opl");
            }

            if (condition.Opr != null)
            {
                VariableCppExporter.GenerateClassMember(condition.Opr, stream, indent, "opr");
            }
        }
        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\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)
            {
                if (assignment.Opl.IsPar)
                {
                    ParInfo par = assignment.Opl.Value as ParInfo;
                    if (par != null)
                    {
                        RightValueCppExporter.GenerateCode(assignment.Opr, stream, indent + "\t\t\t", assignment.Opr.NativeType, "opr", "opr");
                        uint id = Behaviac.Design.CRC32.CalcCRC(par.Name);
                        stream.WriteLine("{0}\t\t\tBEHAVIAC_ASSERT(behaviac::MakeVariableId(\"{1}\") == {2}u);", indent, par.Name, id);
                        stream.WriteLine("{0}\t\t\tpAgent->SetVariable(\"{1}\", opr, {2}u);", indent, par.Name, id);
                    }
                }
                else
                {
                    string opl = VariableCppExporter.GenerateCode(assignment.Opl, stream, indent + "\t\t\t", string.Empty, string.Empty, "opl");
                    RightValueCppExporter.GenerateCode(assignment.Opr, stream, indent + "\t\t\t", assignment.Opr.NativeType, "opr", "opr");
                    stream.WriteLine("{0}\t\t\t{1} = opr;", indent, opl);

                    VariableCppExporter.PostGenerateCode(assignment.Opl, stream, indent + "\t\t\t", assignment.Opl.NativeType, "opl", string.Empty);
                }

                if (assignment.Opr.IsMethod)
                {
                    RightValueCppExporter.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, StreamWriter stream, string indent)
        {
            base.GenerateMethod(node, stream, indent);

            DecoratorCount decoratorCount = node as DecoratorCount;
            Debug.Check(decoratorCount != null);

            if (decoratorCount.Count != null)
            {
                stream.WriteLine("{0}\t\tvirtual int GetCount(Agent* pAgent) const", indent);
                stream.WriteLine("{0}\t\t{{", indent);
                stream.WriteLine("{0}\t\t\tBEHAVIAC_UNUSED_VAR(pAgent);", indent);

                string retStr = VariableCppExporter.GenerateCode(decoratorCount.Count, stream, indent + "\t\t\t", string.Empty, string.Empty, string.Empty);

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

            ExampleNode wait = node as ExampleNode;

            Debug.Check(wait != null);

            if (wait.Time != null)
            {
                stream.WriteLine("{0}\t\tvirtual float GetTime(Agent* pAgent) const", indent);
                stream.WriteLine("{0}\t\t{{", indent);
                stream.WriteLine("{0}\t\t\tBEHAVIAC_UNUSED_VAR(pAgent);", indent);

                string retStr = VariableCppExporter.GenerateCode(wait.Time, stream, indent + "\t\t\t", string.Empty, string.Empty, string.Empty);

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

            DecoratorFrames decoratorFrames = node as DecoratorFrames;

            if (decoratorFrames == null)
            {
                return;
            }

            if (decoratorFrames.Time != null)
            {
                stream.WriteLine("{0}\t\tvirtual int GetFrames(Agent* pAgent) const", indent);
                stream.WriteLine("{0}\t\t{{", indent);
                stream.WriteLine("{0}\t\t\tBEHAVIAC_UNUSED_VAR(pAgent);", indent);

                string retStr = VariableCppExporter.GenerateCode(decoratorFrames.Time, false, stream, indent + "\t\t\t", string.Empty, string.Empty, string.Empty);

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

            PluginBehaviac.Nodes.Condition condition = node as PluginBehaviac.Nodes.Condition;
            Debug.Check(condition != null);

            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);

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

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

            // opr
            VariableCppExporter.GenerateCode(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 = Details::Equal(opl, opr);", indent);
                break;

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

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

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

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

            case OperatorType.LessEqual:
                stream.WriteLine("{0}\t\t\tbool op = Details::LessEqual(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 ? BT_SUCCESS : BT_FAILURE;", indent);
            stream.WriteLine("{0}\t\t}}", indent);
        }
        protected override void GenerateMethod(Behaviac.Design.Attachments.Attachment attachment, StreamWriter stream, string indent)
        {
            base.GenerateMethod(attachment, stream, indent);

            PluginBehaviac.Events.Predicate predicate = attachment as PluginBehaviac.Events.Predicate;
            Debug.Check(predicate != null);

            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_FAILURE;", indent);

            // BinaryOperator
            switch (predicate.BinaryOperator)
            {
            case BinaryOperator.And:
                stream.WriteLine("{0}\t\t\tthis->m_bAnd = true;", indent);
                break;

            case BinaryOperator.Or:
            default:
                stream.WriteLine("{0}\t\t\tthis->m_bAnd = false;", indent);
                break;
            }

            string typeName = Plugin.GetNativeTypeName(predicate.Opl.ValueType);

            // opl
            RightValueCppExporter.GenerateCode(predicate.Opl, stream, indent + "\t\t\t", typeName, "opl", string.Empty);

            // opr
            VariableCppExporter.GenerateCode(predicate.Opr, stream, indent + "\t\t\t", typeName, "opr", string.Empty);

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

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

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

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

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

            case OperatorType.LessEqual:
                stream.WriteLine("{0}\t\t\tbool op = Details::LessEqual(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\tif (op)", indent);
            stream.WriteLine("{0}\t\t\t\tresult = BT_SUCCESS;", indent);

            stream.WriteLine("{0}\t\t\treturn result;", indent);
            stream.WriteLine("{0}\t\t}}", indent);
        }
Example #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\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 (compute.Opl != null && compute.Opr1 != null && compute.Opr2 != null)
            {
                RightValueCppExporter.GenerateCode(compute.Opr1, stream, indent + "\t\t\t", compute.Opr1.NativeType, "opr1", "opr1");
                RightValueCppExporter.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 = DataCppExporter.GetBasicGeneratedNativeType(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\tBEHAVIAC_ASSERT(behaviac::MakeVariableId(\"{1}\") == {2}u);", indent, par.Name, id);
                        stream.WriteLine("{0}\t\t\tpAgent->SetVariable(\"{1}\", opr, {2}u);", indent, par.Name, id);
                    }
                }
                else
                {
                    string opl = VariableCppExporter.GenerateCode(compute.Opl, stream, indent + "\t\t\t", string.Empty, string.Empty, "opl");
                    stream.WriteLine("{0}\t\t\t{1} = opr;", indent, opl);

                    VariableCppExporter.PostGenerateCode(compute.Opl, stream, indent + "\t\t\t", compute.Opl.NativeType, "opl", string.Empty, null, "", "opr");
                }

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

                if (compute.Opr2.IsMethod)
                {
                    RightValueCppExporter.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);
        }