behaviac::string BehaviorTask::GetTickInfo(const behaviac::Agent* pAgent, const behaviac::BehaviorNode* n, const char* action)
    {
        if (pAgent && pAgent->IsMasked())
        {
            //BEHAVIAC_PROFILE("GetTickInfo", true);

            const behaviac::string& bClassName = n->GetClassNameString();

            //filter out intermediate bt, whose class name is empty
            if (!bClassName.empty())
            {
				const behaviac::string& btName = GetParentTreeName(pAgent, n);

                int nodeId = n->GetId();
                //TestBehaviorGroup\scratch.xml->EventetTask[0]:enter
                behaviac::string bpstr;

				if (!StringUtils::IsNullOrEmpty(btName.c_str()))
                {
                    bpstr = FormatString("%s.xml->", btName.c_str());
                }

                bpstr += FormatString("%s[%i]", bClassName.c_str(), nodeId);

				if (!StringUtils::IsNullOrEmpty(action))
                {
                    bpstr += FormatString(":%s", action);
                }

                return bpstr;
            }
        }

        return behaviac::string();
    }
Example #2
0
	EBTStatus FSMTask::UpdateFSM(Agent* pAgent, EBTStatus childStatus)
	{
		BEHAVIAC_ASSERT(this->m_node != 0);
		BEHAVIAC_ASSERT(this->m_currentNodeId != -1);

		EBTStatus status = childStatus;
		bool bLoop = true;

#if !BEHAVIAC_RELEASE
		const int kMaxCount = 10;
		behaviac::map<int, int> state_update_count;
#endif//#if !BEHAVIAC_RELEASE

		while (bLoop)
		{
			BehaviorTask* currentState = this->GetChildById(this->m_currentNodeId);
            //BEHAVIAC_ASSERT(currentState->GetNextStateId() == -1, "m_nextStateId is not reset to -1 in onenter");
			currentState->exec(pAgent);

			if (StateTask::DynamicCast(currentState) != 0)
			{
				StateTask* pStateTask = (StateTask*)currentState;

				if (pStateTask->IsEndState())
				{
					return BT_SUCCESS;
				}
			}

			int nextStateId = currentState->GetNextStateId();

			if (nextStateId < 0) // don't know why, the nextStateID might be -2147483648, so change the condition
			{
				//if not transitioned, don't go on next state, to exit
				bLoop = false;
			}
			else
			{
#if !BEHAVIAC_RELEASE
				state_update_count[this->m_currentNodeId]++;
				if (state_update_count[this->m_currentNodeId] > kMaxCount) {
					behaviac::string treeName = GetParentTreeName(pAgent, this->GetNode());
					BEHAVIAC_LOGERROR("%s might be updating an FSM('%s') endlessly, possibly a dead loop, please redesign it!", pAgent->GetName().c_str(), treeName.c_str());
					BEHAVIAC_ASSERT(false);
				}
#endif

				//if transitioned, go on next state
				this->m_currentNodeId = nextStateId;
			}
		}

		return status;
	}