コード例 #1
0
ファイル: AINodeGuard.cpp プロジェクト: Arc0re/lithtech
void AINodeGuard::Init()
{
	super::Init();

	// Get the guarded nodes.
	// Guarded nodes will be owned by this guard node.  Nodes that are
	// owned may only be used by the AI assigned to this guard node.

	HSTRING hstrNodeName;
	HSTRING_LIST::iterator it;
	for ( it = m_lstGuardedNodeNames.begin(); it != m_lstGuardedNodeNames.end(); ++it )
	{
		hstrNodeName = *it;
		AINode* pNode = g_pAINodeMgr->GetNode( hstrNodeName );

		if ( pNode )
		{
			m_lstGuardedNodes.push_back( pNode->m_hObject );
			pNode->SetNodeOwner( m_hObject );
		}
		else
		{
			AIASSERT1( 0, m_hObject, "AINodeGuard::Init: Cannot find guarded node \"%s\"", ::ToString( hstrNodeName ));
		}

		FREE_HSTRING( hstrNodeName );
	}
	
	m_lstGuardedNodeNames.clear();
}
コード例 #2
0
//----------------------------------------------------------------------------
//
//	ROUTINE:	ConvertAlignmentNameToEnum()
//
//	PURPOSE:	Converts the name of a Alignment to a alignment.
//
//----------------------------------------------------------------------------
CharacterAlignment ConvertAlignmentNameToEnum(const char* const szName)
{
    if ( szName != NULL )
    {
        if ( 0 == strcmp(szName, "LIKE") )
        {
            return LIKE;
        }
        else if ( 0 == strcmp(szName, "HATE") )
        {
            return HATE;
        }
        else if ( 0 == strcmp(szName, "TOLERATE") )
        {
            return TOLERATE;
        }
        else if ( 0 == strcmp(szName, "UNDETERMINED") )
        {
            return UNDETERMINED;
        }
        else
        {
            AIASSERT1( 0, NULL, "Invalid Alignment Name: %s", szName );
        }
    }

    return INVALID;
}
コード例 #3
0
ファイル: AIGoalPatrol.cpp プロジェクト: rickyharis39/nolf2
LTBOOL CAIGoalPatrol::HandleNameValuePair(const char *szName, const char *szValue)
{
	ASSERT(szName && szValue);

	if ( !_stricmp(szName, "NODE") )
	{
		AINode* pNode = g_pAINodeMgr->GetNode(szValue);
		AIASSERT1( pNode && (pNode->GetType() == kNode_Patrol), m_pAI->m_hObject, "CAIGoalPatrol::HandleNameValuePair: Could not find patrol node: %s", szValue );
		if( pNode )
		{
			SetPatrolNode( (AINodePatrol*)pNode );
		}
		return LTTRUE;
	}

	else if ( !_stricmp(szName, "AWARENESS") )
	{
		m_eAwareness = CAnimationMgrList::GetPropFromName( szValue );
		AIASSERT( m_eAwareness != kAP_Invalid, m_pAI->m_hObject, "CAIGoalPatrol::HandleNameValuePair: Awareness is None" );

		if( m_pAI->GetState()->GetStateType() == kState_HumanPatrol )
		{
			CAIHumanStatePatrol* pStatePatrol = (CAIHumanStatePatrol*)(m_pAI->GetState());
			pStatePatrol->SetAwareness( m_eAwareness );
		}
	}

	return LTFALSE;
}
コード例 #4
0
bool CAIActionDeathOnVehicleUnanimated::ValidateContextPreconditions( CAI* pAI, CAIWorldState& wsWorldStateGoal, bool bIsPlanning )
{
	// Action is only valid if AI is riding a Vehicle.

	SAIWORLDSTATE_PROP* pProp = pAI->GetAIWorldState()->GetWSProp( kWSK_RidingVehicle, pAI->m_hObject );
	if( ( !pProp ) ||
		( pProp->eAnimPropWSValue == kAP_None ) )
	{
		return false;
	}
	EnumAnimProp eVehicle = pProp->eAnimPropWSValue;

	// Action is only valid if AI is dead!

	if( !pAI->GetDestructible()->IsDead() )
	{
		return false;
	}

	// Assert if the AI does not have the required weightset.

#if !defined(_FINAL) && !defined(_DEMO)
	HPHYSICSWEIGHTSET hSet;
	if ( g_pModelLT->FindPhysicsWeightSet( pAI->GetHOBJECT(), g_szPhysicsWeightSet, hSet) != LT_OK )
	{
		AIASSERT1( 0, pAI->GetHOBJECT(), "Failed to find the required physics weightset.  To die while on a vehicle, AIs must have a physics weightset named %s.", g_szPhysicsWeightSet );
		return false;
	}
#endif

	// Do not die.

	return true;
}
コード例 #5
0
void CAIGoalDisappearReappear::UpdateGoal()
{
	CAIState* pState = m_pAI->GetState();

	switch(pState->GetStateType())
	{
		case kState_HumanDisappearReappear:
			HandleStateDisappearReappear();
			break;

		// Unexpected State.
		default: AIASSERT1(0, m_pAI->m_hObject, "CAIGoalDisappearReappear::UpdateGoal: Unexpected State: %s.", s_aszStateTypes[pState->GetStateType()] );
	}
}
コード例 #6
0
ファイル: AIGoalMgr.cpp プロジェクト: Arc0re/lithtech
CAIGoalAbstract* CAIGoalMgr::AddGoal(EnumAIGoalType eGoalType, double fTime)
{
	CAIGoalAbstract* pGoal = NULL;
	AIDB_GoalRecord* pRecord;

	ASSERT(eGoalType != kGoal_InvalidType && eGoalType < kGoal_Count);
	if( eGoalType != kGoal_InvalidType && eGoalType < kGoal_Count)
	{
		// Check if AI already has this goal.
		AIGOAL_LIST::iterator it;
		for(it = m_lstGoals.begin(); it != m_lstGoals.end(); ++it)
		{
			pGoal = *it;

			// If AI has the goal, return it.
			if(pGoal->GetGoalType() == eGoalType)
			{
				break;
			}
		}

		if( it == m_lstGoals.end() )
		{
			pRecord = g_pAIDB->GetAIGoalRecord( eGoalType );
			if( pRecord && ( pRecord->eGoalClass != kGoal_InvalidType ) )
			{
				// Add goal to list of goals.
				pGoal = NULL;
				pGoal = AI_FACTORY_NEW_Goal( pRecord->eGoalClass );
				if( pGoal == NULL )
				{
					AIASSERT( 0, m_pAI->m_hObject, "CAIGoalMgr::AddGoal: Failed to create goal.");
					return NULL;
				}

				m_lstGoals.push_back(pGoal);


				// Initialize goal.

				pGoal->InitGoal( m_pAI, eGoalType, pRecord );
			}
			else {
				AIASSERT1( 0, m_pAI->m_hObject, "CAIGoalMgr::AddGoal: Unable to create goal '%s'", s_aszGoalTypes[eGoalType] );
			}
		}
	}

	return pGoal;
}
コード例 #7
0
ファイル: AIGoalButeMgr.cpp プロジェクト: emoose/lithtech
void CAIGoalButeMgr::ReadGoalTemplate(uint32 iTemplate)
{
	sprintf(s_aTagName, "Goal%d", iTemplate);
	char szName[128];
	CButeTools::GetValidatedString(m_buteMgr, s_aTagName, "Name",szName,sizeof(szName));

	uint32 iGoal = ConvertToGoalTypeEnum(szName);

	// Make sure that the selected goal is in range before we access it!
	if ( iGoal == kGoal_InvalidType || iGoal == kGoal_Count )
	{
		AIASSERT1( 0, NULL, "Goal name and enumerations out of sync for goal: %s", szName );
		return;
	}

	AIGBM_GoalTemplate& Template = m_aTemplates[iGoal];

	// Get values.

	Template.fImportance			= (LTFLOAT)CButeTools::GetValidatedDouble(m_buteMgr, s_aTagName, "Importance");
	Template.fDecayTime				= (LTFLOAT)CButeTools::GetValidatedDouble(m_buteMgr, s_aTagName, "DecayTime");
	Template.bFreezeDecay			= CButeTools::GetValidatedBool(m_buteMgr, s_aTagName, "FreezeDecay", LTFALSE);
	Template.bLockedAnimIsInterruptable= CButeTools::GetValidatedBool(m_buteMgr, s_aTagName, "LockedAnimIsInterruptable", LTTRUE);
	Template.bForceAnimInterrupt	= CButeTools::GetValidatedBool(m_buteMgr, s_aTagName, "ForceAnimInterrupt", LTFALSE);
	Template.fUpdateRate			= (LTFLOAT)CButeTools::GetValidatedDouble(m_buteMgr, s_aTagName, "UpdateRate");
	Template.bDeleteOnDeactivation	= CButeTools::GetValidatedBool(m_buteMgr, s_aTagName, "DeleteWhenDone", LTFALSE);
	Template.fChanceToActivate		= (LTFLOAT)CButeTools::GetValidatedDouble(m_buteMgr, s_aTagName, "ChanceToActivate", 1.f);
	Template.fFrequencyMin			= (LTFLOAT)CButeTools::GetValidatedRange(m_buteMgr, s_aTagName, "Frequency", CARange(0.f, 0.f)).GetMin();
	Template.fFrequencyMax			= (LTFLOAT)CButeTools::GetValidatedRange(m_buteMgr, s_aTagName, "Frequency", CARange(0.f, 0.f)).GetMax();
	Template.nDamagePriority		= CButeTools::GetValidatedInt(m_buteMgr, s_aTagName, "DamagePriority", 0);

	// Get SenseTriggers. (SenseTypes are bitflags)

	GetBitFlagItems( &(Template.flagSenseTriggers), "SenseTrigger", 
					 kSense_Count, s_aszSenseTypes);

	// Get Attractors. (AttractorTypes are enums)
	Template.cAttractors = 0;
	Template.aAttractors = LTNULL;
	GetEnumItems( (uint32*&)(Template.aAttractors), Template.cAttractors, 
					"Attractor", kNode_Count, s_aszAINodeTypes);

	// Get AttractorDist, if there are attractors.
	if(Template.aAttractors != LTNULL)
	{
		Template.fAttractorDistSqr = (LTFLOAT)CButeTools::GetValidatedDouble(m_buteMgr, s_aTagName, "AttractorDist");
		Template.fAttractorDistSqr *= Template.fAttractorDistSqr;
	}
}
コード例 #8
0
ファイル: AIGoalGoto.cpp プロジェクト: Arc0re/lithtech
LTBOOL CAIGoalGoto::HandleNameValuePair(const char *szName, const char *szValue)
{
	ASSERT(szName && szValue);

	if ( !_stricmp(szName, "NODE") )
	{
		AITRACE( AIShowGoals, ( m_pAI->m_hObject, "GOTO setting node=%s", szValue ) );
		AINode* pNode = g_pAINodeMgr->GetNode( szValue );
		if( pNode )
		{
			m_hDestNode = pNode->m_hObject;

			// If Goal was already active (walking to previous goto node)
			// Reset the goal.

			if( m_pGoalMgr->IsCurGoal( this ) && ( m_pAI->GetState()->GetStateType() == kState_HumanGoto ) )
			{
				CAIHumanStateGoto* pGoto = (CAIHumanStateGoto*)m_pAI->GetState();
				pGoto->SetDestNode( m_hDestNode );
			}
		}
		else
		{
			AIASSERT1( 0, m_pAI->m_hObject, "CAIGoalGoto::HandleNameValuePair: Cannot find node '%s'", szValue );
		}
		return LTTRUE;
	}

	else if ( !_stricmp(szName, "MOVEMENT") )
	{
		m_eMovement = CAnimationMgrList::GetPropFromName( szValue );
		return LTTRUE;
	}

	else if ( !_stricmp(szName, "AWARENESS") )
	{
		m_eAwareness = CAnimationMgrList::GetPropFromName( szValue );
		return LTTRUE;
	}

	return LTFALSE;
}
コード例 #9
0
bool CAIActionDeathAnimated::ValidateContextPreconditions( CAI* pAI, CAIWorldState& wsWorldStateGoal, bool bIsPlanning )
{
	if ( !super::ValidateContextPreconditions( pAI, wsWorldStateGoal, bIsPlanning ) )
	{
		return false;
	}

	// Verify we have a smartobject.  If we don't, this action cannot be used.

	if ( NULL == GetActionSmartObject(this) )
	{
		AIASSERT1( 0, pAI->GetHOBJECT(), 
			"CAIActionDeathAnimated::ValidateContextPreconditions: AI action '%s' requires a SmartObject to specify animations.  No SmartObject was specified.", 
			s_aszActionTypes[GetActionRecord()->eActionType] );
		return false;
	}

	// AI must actually be dead

	if( !pAI->GetDestructible()->IsDead() )
	{
		return false;
	}

	// Death animation does not exist.

	CAnimationProps	animProps;
	GetAnimationProps( pAI, GetActionSmartObject(this), &animProps );
	uint32 cAnimations = pAI->GetAnimationContext()->CountAnimations( animProps );
	if( 0 == cAnimations )
	{
		return false;
	}

	return true;
}
コード例 #10
0
ファイル: AIGoalButeMgr.cpp プロジェクト: emoose/lithtech
LTBOOL CAIGoalButeMgr::Init(const char* szAttributeFile)
{
    if (g_pAIGoalButeMgr || !szAttributeFile) return LTFALSE;
    if (!Parse(szAttributeFile))
	{
		AIASSERT1( 0, NULL, "CAIGoalButeMgr::Init: Failed to parse %s", szAttributeFile );
		return LTFALSE;
	}

	// Set up global pointer

	g_pAIGoalButeMgr = this;

	// Read Goal Sets.
	
	uint32 iGoalSet = 0;
	sprintf(s_aTagName, "%s%d", "GoalSet", iGoalSet);
	
	while (m_buteMgr.Exist(s_aTagName))
	{
		ReadGoalSet();
		++iGoalSet;
		sprintf(s_aTagName, "%s%d", "GoalSet", iGoalSet);
	}


	// Create an array as big as the goal type enum list.
	
	m_aTemplates = debug_newa(AIGBM_GoalTemplate, kGoal_Count);

	// See how many goal templates there are

	uint32 cTemplates = 0;
	sprintf(s_aTagName, "%s%d", "Goal", cTemplates);

	while (m_buteMgr.Exist(s_aTagName))
	{
		++cTemplates;
		sprintf(s_aTagName, "%s%d", "Goal", cTemplates);
	}

	
	// Read the goal templates.

	for ( uint32 iTemplate = 0 ; iTemplate < cTemplates ; ++iTemplate )
	{
		ReadGoalTemplate(iTemplate);
	}

	// Read SmartObject templates.
	
	uint32 iSmartObject = 0;
	sprintf(s_aTagName, "%s%d", "SmartObject", iSmartObject);
	
	while (m_buteMgr.Exist(s_aTagName))
	{
		ReadSmartObjectTemplate(iSmartObject);
		++iSmartObject;
		sprintf(s_aTagName, "%s%d", "SmartObject", iSmartObject);
	}


	m_buteMgr.Term();

    return LTTRUE;
}
コード例 #11
0
ファイル: AIGoalButeMgr.cpp プロジェクト: emoose/lithtech
void CAIGoalButeMgr::ReadGoalSet()
{
	// Create new goal set and add it to list.

	AIGBM_GoalSet* pGoalSet = debug_new(AIGBM_GoalSet);
	m_lstGoalSets.push_back(pGoalSet);

	// Read name.
	CButeTools::GetValidatedString(m_buteMgr, s_aTagName, "Name", pGoalSet->szName, sizeof(pGoalSet->szName) );

	char szGoalString[64];

	// Read included goalsets.

	uint32 iGoalSet = 0;

	while ( true )
	{
		szGoalString[0] = '\0';
		sprintf(s_aAttName, "IncludeGoalSet%d", iGoalSet);
		m_buteMgr.GetString(s_aTagName, s_aAttName, "", szGoalString, sizeof(szGoalString) );
		if( !m_buteMgr.Success( ))
		{
			break;
		}

		// Find a goalset with a matching name, and add it to the list of
		// included goalsets.  Included goalsets must be listed first.

		if( szGoalString[0] )
		{
			AIGOAL_SET_LIST::iterator it;
			for( it = m_lstGoalSets.begin(); it != m_lstGoalSets.end(); ++it )
			{
				if( stricmp( szGoalString, (*it)->szName ) == 0 )
				{
					pGoalSet->lstIncludeGoalSets.push_back( *it );
					break;
				}
			}

			if( it == m_lstGoalSets.end() )
			{
				AIASSERT1( 0, NULL, "CAIGoalButeMgr::ReadGoalSet: Failed to find included goalset named %s", szGoalString );
			}
		}

		++iGoalSet;
	}

	// Read required brains.

	uint32 iBrain = 0;
	int nBrainID;

	while ( true )
	{
		szGoalString[0] = '\0';
		sprintf(s_aAttName, "RequiredBrain%d", iBrain);
		m_buteMgr.GetString(s_aTagName, s_aAttName, "", szGoalString, sizeof(szGoalString) );
		if( !m_buteMgr.Success( ))
		{
			break;
		}

		// Find a brain with a matching name, and add it to the list of
		// required brains.  

		if( szGoalString[0] )
		{
			nBrainID = g_pAIButeMgr->GetBrainIDByName( szGoalString );
			if( nBrainID != -1 )
			{
				pGoalSet->lstRequiredBrains.push_back( nBrainID );
			}
			else {
				AIASSERT1( 0, NULL, "CAIGoalButeMgr::ReadGoalSet: Failed to find Brain named %s", szGoalString );
			}
		}

		++iBrain;
	}


	// Read flags.

	if( CButeTools::GetValidatedBool( m_buteMgr, s_aTagName, "Permanent", LTFALSE ) )
	{
		pGoalSet->dwGoalSetFlags |= AIGBM_GoalSet::kGS_Permanent;
	}

	if( CButeTools::GetValidatedBool( m_buteMgr, s_aTagName, "Hidden", LTFALSE ) )
	{
		pGoalSet->dwGoalSetFlags |= AIGBM_GoalSet::kGS_Hidden;
	}

	// Read goal importances.

	uint32 iGoal = 0;
	
	char* tok;
	EnumAIGoalType eGoalType;
	SGoalSetData gsd;
	while ( true )
	{
		// Read entire goal string.
		sprintf(s_aAttName, "Goal%d", iGoal);
		m_buteMgr.GetString(s_aTagName, s_aAttName, "", szGoalString, sizeof(szGoalString) );
		if( !m_buteMgr.Success( ))
		{
			break;
		}

		// First token is AIGoalType.
		tok = strtok(szGoalString, " ");
		eGoalType = ConvertToGoalTypeEnum(tok);

		// All following tokens are parameters.
		gsd.hstrParams = LTNULL;
		if( g_pLTServer != LTNULL )
		{
			tok = strtok(LTNULL, "");
			if(tok != LTNULL)
			{
				gsd.hstrParams = g_pLTServer->CreateString( tok );
			}
		}

		// Add goal to map.
		pGoalSet->mapGoalSet.insert( AIGOAL_DATA_MAP::value_type(eGoalType, gsd) );

		++iGoal;
	}
}