Exemplo n.º 1
0
    void BehaviorNode::ApplyEffects(Agent* pAgent, BehaviorNode::EPhase  phase) const
    {
        if (this->m_effectors.size() == 0)
        {
            return;
        }

        if (this->m_both_effectors == 0)
        {
            if (phase == Effector::E_SUCCESS && this->m_success_effectors == 0)
            {
                return;
            }

            if (phase == Effector::E_FAILURE && this->m_failure_effectors == 0)
            {
                return;
            }
        }

        for (uint32_t i = 0; i < this->m_effectors.size(); ++i)
        {
            Effector* pEffector = (Effector*)this->m_effectors[i];

            if (pEffector != NULL)
            {
                Effector::EPhase ph = pEffector->GetPhase();

                if (phase == Effector::E_BOTH || ph == Effector::E_BOTH || ph == phase)
                {
                    pEffector->Evaluate((Agent*)pAgent);
                }
            }
        }
    }
Exemplo n.º 2
0
    void BehaviorNode::Attach(BehaviorNode* pAttachment, bool bIsPrecondition, bool bIsEffector, bool bIsTransition)
    {
        BEHAVIAC_UNUSED_VAR(bIsTransition);
        BEHAVIAC_ASSERT(bIsTransition == false);

        if (bIsPrecondition)
        {
            BEHAVIAC_ASSERT(!bIsEffector);

            Precondition* predicate = (Precondition*)pAttachment;
            BEHAVIAC_ASSERT(predicate != NULL);
            this->m_preconditions.push_back(predicate);

            Precondition::EPhase phase = predicate->GetPhase();

            if (phase == Precondition::E_ENTER)
            {
                this->m_enter_precond++;

            }
            else if (phase == Precondition::E_UPDATE)
            {
                this->m_update_precond++;

            }
            else if (phase == Precondition::E_BOTH)
            {
                this->m_both_precond++;

            }
            else
            {
                BEHAVIAC_ASSERT(false);
            }
        }
        else if (bIsEffector)
        {
            BEHAVIAC_ASSERT(!bIsPrecondition);

            Effector* effector = (Effector*)pAttachment;
            BEHAVIAC_ASSERT(effector != NULL);
            this->m_effectors.push_back(effector);

            Effector::EPhase phase = effector->GetPhase();

            if (phase == Effector::E_SUCCESS)
            {
                this->m_success_effectors++;

            }
            else if (phase == Effector::E_FAILURE)
            {
                this->m_failure_effectors++;

            }
            else if (phase == Effector::E_BOTH)
            {
                this->m_both_effectors++;

            }
            else
            {
                BEHAVIAC_ASSERT(false);
            }
        }
        else
        {
            this->m_events.push_back(pAttachment);
        }
    }