Example #1
0
bool Maker::CreateDependencyTree()
{
    if (goals.size() == 0)
    {
        Variable *dg = VariableContainer::Instance()->Lookup(".DEFAULT_GOAL");
        std::string value;
        if (dg && dg->GetValue().size() != 0)
        {
            value = dg->GetValue();
            if (dg->GetFlavor() == Variable::f_recursive)
            {
                Eval r(value, false);
                value = r.Evaluate();
            }
        }
        else
        {
            value = firstGoal;
        }
        if (value.size() == 0)
            return true; // nothing to do
        AddGoal(value);
    }
    EnterSuffixTerminals();
    std::string intermediate;
    Variable *v = VariableContainer::Instance()->Lookup(".INTERMEDIATE");
    if (v)
    {
        intermediate = v->GetValue();
    }
    for (std::deque<std::string>::iterator it = goals.begin(); it != goals.end(); ++it)
    {
        Time tv1, tv2;
        Depends *t = Dependencies(*it, "", tv1);
        if (t || OnList(*it,".PHONY"))
        {
            depends.push_back(t);
        }
        else if (t)
            delete t;
    }
    v = VariableContainer::Instance()->Lookup(".INTERMEDIATE");
    if (v)
    {
        v->SetValue(intermediate);
    }
    return !missingTarget;
}
Example #2
0
void CAIGoalMgr::SetGoalSet(uint32 iGoalSet, const char* szName, bool bClearGoals)
{
	if( iGoalSet == -1 )
	{
		return;
	}
	
	AIDB_GoalSetRecord* pGoalSet = g_pAIDB->GetAIGoalSetRecord( iGoalSet );

	// Check if GoalSet requires a specific AIType.

	if( !pGoalSet->lstRequiredAITypes.empty() )
	{
		if( m_pAI->GetAIAttributes() )
		{
			ENUM_AIAttributesID eAttributesID = m_pAI->GetAIAttributes()->eAIAttributesID;

			AIATTRIBUTES_LIST::iterator it_AIType;
			for( it_AIType = pGoalSet->lstRequiredAITypes.begin(); it_AIType != pGoalSet->lstRequiredAITypes.end(); ++it_AIType )
			{
				// Found a matching AIType.

				if( eAttributesID == *it_AIType )
				{
					break;
				}
			}

			// No matching AIType was found. Bail!

			if( it_AIType == pGoalSet->lstRequiredAITypes.end() )
			{
				AIDB_AttributesRecord* pRecord = g_pAIDB->GetAIAttributesRecord( eAttributesID );
				if( pRecord )
				{
					AIASSERT3( 0, m_pAI->m_hObject, "%s : GoalSet '%s' invalid for AIType '%s'.", szName, pGoalSet->strName.c_str(), pRecord->strName.c_str() );
				}
				else {
					AIASSERT2( 0, m_pAI->m_hObject, "%s : GoalSet '%s' invalid for AIType.", szName, pGoalSet->strName.c_str() );
				}
				return;
			}
		}
	}

	// Delete existing goals if flag is set.

	if( bClearGoals )
	{
		Term( false );
		Init( m_pAI );
		
		// Allow transitions to finish.  Stomp anything else.

		if( !m_pAI->GetAnimationContext()->IsTransitioning() )
		{
			m_pAI->GetAnimationContext()->ClearSpecial();
		}

		// Clear memory of characters.

		CAIWMFact factQuery;
		factQuery.SetFactType( kFact_Character );
		m_pAI->GetAIWorkingMemory()->ClearWMFacts( factQuery );

		// Clear memory of disturbances.

		factQuery.SetFactType( kFact_Disturbance );
		m_pAI->GetAIWorkingMemory()->ClearWMFacts( factQuery );

		// Clear anything we are targeting.

		m_pAI->GetAIBlackBoard()->SetBBInvalidateTarget( true );
	}

	m_iGoalSet = iGoalSet;
	m_fGoalSetTime = g_pLTServer->GetTime();

	// Create goals for every entry in map.

	CAIGoalAbstract* pGoal;
	double fTime = g_pLTServer->GetTime();
	AIGOAL_TYPE_LIST::iterator itGoal;
	for( itGoal = pGoalSet->lstGoalSet.begin(); itGoal != pGoalSet->lstGoalSet.end(); ++itGoal )
	{
		pGoal = AddGoal( *itGoal, fTime );

//		pGoal->SetPermanentGoal( bPermanent );
	}
}