Exemplo n.º 1
0
    void BehaviorTask::reset(Agent* pAgent)
    {
#if BEHAVIAC_ENABLE_PROFILING
        BEHAVIAC_PROFILE("BehaviorTask::reset");
#endif
        this->traverse(&reset_handler, pAgent, 0);
    }
Exemplo n.º 2
0
behaviac::EBTStatus CPerformanceAgent::RunAway()
{
    BEHAVIAC_PROFILE("FunctionCall");

    Hungry += 0.015f;
    DistanceToEnemy += 0.5f;

    TEST_LOGINFO("RunAway HP=%f DistanceToEnemy=%f Hungry=%f Food=%f\n", HP, DistanceToEnemy, Hungry, Food);
    FakeSleep(1);
    return behaviac::BT_RUNNING;
}
Exemplo n.º 3
0
behaviac::EBTStatus CPerformanceAgent::Fidget()
{
    BEHAVIAC_PROFILE("FunctionCall");

    float smallDistance = this->GetVariable<float>("par_SmallDisance");

    if (DistanceToEnemy > smallDistance) {
        DistanceToEnemy -= smallDistance;
    }

    TEST_LOGINFO("Fidget HP=%f DistanceToEnemy=%f Hungry=%f Food=%f\n", HP, DistanceToEnemy, Hungry, Food);
    return behaviac::BT_SUCCESS;
}
Exemplo n.º 4
0
void CPerformanceAgent::Fire()
{
    BEHAVIAC_PROFILE("FunctionCall");

    HP *= 0.3f;

    if (DistanceToEnemy > 3.0f) {
        DistanceToEnemy -= 0.01f;
    }

    TEST_LOGINFO("Fire HP=%f DistanceToEnemy=%f Hungry=%f Food=%f\n", HP, DistanceToEnemy, Hungry, Food);
    FakeSleep(1);
}
Exemplo n.º 5
0
behaviac::EBTStatus CPerformanceAgent::SearchForFood()
{
    BEHAVIAC_PROFILE("FunctionCall");

    Food += 0.002f;

    TEST_LOGINFO("SearchForFood HP=%f DistanceToEnemy=%f Hungry=%f Food=%f\n", HP, DistanceToEnemy, Hungry, Food);
    FakeSleep(1);

    if (Food >= 3.0f) {
        return behaviac::BT_SUCCESS;
    }

    return behaviac::BT_RUNNING;
}
Exemplo n.º 6
0
behaviac::EBTStatus CPerformanceAgent::Wander()
{
    BEHAVIAC_PROFILE("FunctionCall");

    m_internal += 0.03f;
    DistanceToEnemy -= 0.01f;
    HP -= 0.02f;

    TEST_LOGINFO("Wander HP=%f DistanceToEnemy=%f Hungry=%f Food=%f\n", HP, DistanceToEnemy, Hungry, Food);
    FakeSleep(1);

    if (m_internal > 21.0f) {
        Hungry += m_internal;
        m_internal = 0.0f;
        return behaviac::BT_SUCCESS;
    }

    return behaviac::BT_RUNNING;
}
Exemplo n.º 7
0
behaviac::EBTStatus CPerformanceAgent::Eat()
{
    BEHAVIAC_PROFILE("FunctionCall");

    Hungry -= 0.04f;
    HP += 0.01f;

    TEST_LOGINFO("Eat HP=%f DistanceToEnemy=%f Hungry=%f Food=%f\n", HP, DistanceToEnemy, Hungry, Food);
    FakeSleep(1);

    if (Hungry <= 0.0f) {
        Hungry = 0.0f;
        Food--;

        return behaviac::BT_SUCCESS;
    }

    return behaviac::BT_RUNNING;
}
Exemplo n.º 8
0
    bool Workspace::CheckBreakpoint(const behaviac::Agent* pAgent, const behaviac::BehaviorNode* b, const char* action, EActionResult actionResult)
    {
        BEHAVIAC_UNUSED_VAR(pAgent);
        BEHAVIAC_UNUSED_VAR(b);
        BEHAVIAC_UNUSED_VAR(action);
        BEHAVIAC_UNUSED_VAR(actionResult);
#if !BEHAVIAC_RELEASE

        if (Config::IsSocketing())
        {
#if BEHAVIAC_ENABLE_PROFILING
            BEHAVIAC_PROFILE("Workspace::CheckBreakpoint");
#endif
            behaviac::string bpStr = BehaviorTask::GetTickInfo(pAgent, b, action);

            uint32_t bpid = MakeVariableId(bpStr.c_str());

            BreakpointInfos_t::const_iterator it = m_breakpoints.find(bpid);

            if (it != m_breakpoints.end())
            {
                const BreakpointInfo_t& bp = it->second;

                if (bp.action_result & actionResult)
                {
                    int count = GetActionCount(bpStr.c_str());
                    BEHAVIAC_ASSERT(count > 0);

                    if (bp.hit_config == 0 || bp.hit_config == count)
                    {
                        return true;
                    }
                }
            }
        }

#endif//#if !BEHAVIAC_RELEASE
        return false;
    }
Exemplo n.º 9
0
    EBTStatus BehaviorTask::exec(Agent* pAgent, EBTStatus childStatus)
    {
#if BEHAVIAC_ENABLE_PROFILING
#if 1
        const char* classStr = (this->m_node ? this->m_node->GetClassNameString().c_str() : "BT");
        int nodeId = (this->m_node ? this->m_node->GetId() : -1);
        behaviac::string taskClassid = FormatString("%s[%i]", classStr, nodeId);

        AutoProfileBlockSend profiler_block(Profiler::GetInstance(), taskClassid, pAgent);
#else
        const char* classStr = (this->m_node ? this->m_node->GetClassNameString().c_str() : "BT");
        BEHAVIAC_PROFILE(classStr);
#endif
#endif//#if BEHAVIAC_ENABLE_PROFILING

        BEHAVIAC_ASSERT(!this->m_node || this->m_node->IsValid(pAgent, this),
                        FormatString("Agent In BT:%s while the Agent used for: %s", this->m_node->m_agentType.c_str(), pAgent->GetClassTypeName()));

        bool bEnterResult = false;

        if (this->m_status == BT_RUNNING)
        {
            bEnterResult = true;

        }
        else
        {
            //reset it to invalid when it was success/failure
            this->m_status = BT_INVALID;

            bEnterResult = this->onenter_action(pAgent);
        }

        if (bEnterResult)
        {
#if !BEHAVIAC_RELEASE

            if (Config::IsLoggingOrSocketing())
            {
                string btStr = BehaviorTask::GetTickInfo(pAgent, this, "update");

                //empty btStr is for internal BehaviorTreeTask
                if (!StringUtils::IsNullOrEmpty(btStr.c_str()))
                {
                    LogManager::GetInstance()->Log(pAgent, btStr.c_str(), EAR_none, ELM_tick);
                }
            }

#endif
            bool bValid = true;
            int _tempPrecndCount = this->m_node != 0 ? this->m_node->PreconditionsCount() : 0;

            if (_tempPrecndCount > 0)
            {
                bValid = this->m_node->CheckPreconditions(pAgent, true);
            }

            if (bValid)
            {
                this->m_status = this->update_current(pAgent, childStatus);
            }
            else
            {
                this->m_status = BT_FAILURE;
            }

            if (this->m_status != BT_RUNNING)
            {
                //clear it

                this->onexit_action(pAgent, this->m_status);

                //this node is possibly ticked by its parent or by the topBranch who records it as currrent node
                //so, we can't here reset the topBranch's current node

            }
            else
            {
                BranchTask* tree = this->GetTopManageBranchTask();

                if (tree != 0)
                {
                    tree->SetCurrentTask(this);
                }
            }

        }
        else
        {
            this->m_status = BT_FAILURE;
        }

        return this->m_status;
    }