int SelectHeaviestSequence( CStudioHdr *pstudiohdr, int activity ) { if ( !pstudiohdr ) return 0; VerifySequenceIndex( pstudiohdr ); int maxweight = 0; int seq = ACTIVITY_NOT_AVAILABLE; int weight = 0; for (int i = 0; i < pstudiohdr->GetNumSeq(); i++) { int curActivity = GetSequenceActivity( pstudiohdr, i, &weight ); if (curActivity == activity) { if ( iabs(weight) > maxweight ) { maxweight = iabs(weight); seq = i; } } } return seq; }
int SelectWeightedSequence( CStudioHdr *pstudiohdr, int activity, int curSequence ) { VPROF( "SelectWeightedSequence" ); #ifdef CLIENT_DLL VPROF_INCREMENT_COUNTER( "Client SelectWeightedSequence", 1 ); #else // ifdef GAME_DLL VPROF_INCREMENT_COUNTER( "Server SelectWeightedSequence", 1 ); #endif if (! pstudiohdr) return 0; if (!pstudiohdr->SequencesAvailable()) return 0; VerifySequenceIndex( pstudiohdr ); int numSeq = pstudiohdr->GetNumSeq(); if ( numSeq == 1 ) { return ( GetSequenceActivity( pstudiohdr, 0, NULL ) == activity ) ? 0 : ACTIVITY_NOT_AVAILABLE; } return pstudiohdr->SelectWeightedSequence( activity, curSequence ); }
//----------------------------------------------------------------------------- // Purpose: Static method // Input : *hdr - // sounds - //----------------------------------------------------------------------------- void CModelSoundsCache::BuildAnimationEventSoundList( CStudioHdr *hdr, CUtlVector< unsigned short >& sounds ) { Assert( hdr ); // force animation event resolution!!! VerifySequenceIndex( hdr ); // Find all animation events which fire off sound script entries... for ( int iSeq=0; iSeq < hdr->GetNumSeq(); iSeq++ ) { mstudioseqdesc_t *pSeq = &hdr->pSeqdesc( iSeq ); // Now read out all the sound events with their timing for ( int iEvent=0; iEvent < (int)pSeq->numevents; iEvent++ ) { mstudioevent_t *pEvent = (mstudioevent_for_client_server_t*)pSeq->pEvent( iEvent ); int nEvent = pEvent->Event(); switch ( nEvent ) { default: { if ( pEvent->type & AE_TYPE_NEWEVENTSYSTEM ) { if ( nEvent == AE_SV_PLAYSOUND ) { FindOrAddScriptSound( sounds, pEvent->pszOptions() ); } } } break; // Old-style client .dll animation event case CL_EVENT_SOUND: { FindOrAddScriptSound( sounds, pEvent->pszOptions() ); } break; case CL_EVENT_FOOTSTEP_LEFT: case CL_EVENT_FOOTSTEP_RIGHT: { char soundname[256]; char const *options = pEvent->pszOptions(); if ( !options || !options[0] ) { options = "NPC_CombineS"; } Q_snprintf( soundname, 256, "%s.RunFootstepLeft", options ); FindOrAddScriptSound( sounds, soundname ); Q_snprintf( soundname, 256, "%s.RunFootstepRight", options ); FindOrAddScriptSound( sounds, soundname ); Q_snprintf( soundname, 256, "%s.FootstepLeft", options ); FindOrAddScriptSound( sounds, soundname ); Q_snprintf( soundname, 256, "%s.FootstepRight", options ); FindOrAddScriptSound( sounds, soundname ); } break; case AE_CL_PLAYSOUND: { if ( !( pEvent->type & AE_TYPE_CLIENT ) ) break; if ( pEvent->pszOptions()[0] ) { FindOrAddScriptSound( sounds, pEvent->pszOptions() ); } else { Warning( "-- Error --: empty soundname, .qc error on AE_CL_PLAYSOUND in model %s, sequence %s, animevent # %i\n", hdr->pszName(), pSeq->pszLabel(), iEvent+1 ); } } break; case SCRIPT_EVENT_SOUND: { FindOrAddScriptSound( sounds, pEvent->pszOptions() ); } break; case SCRIPT_EVENT_SOUND_VOICE: { FindOrAddScriptSound( sounds, pEvent->pszOptions() ); } break; } } } }
int CStudioHdr::CActivityToSequenceMapping::SelectWeightedSequenceFromModifiers( CStudioHdr *pstudiohdr, int activity, CUtlSymbol *pActivityModifiers, int iModifierCount ) { if ( !pstudiohdr->SequencesAvailable() ) { return ACTIVITY_NOT_AVAILABLE; } VerifySequenceIndex( pstudiohdr ); if ( pstudiohdr->GetNumSeq() == 1 ) { return ( ::GetSequenceActivity( pstudiohdr, 0, NULL ) == activity ) ? 0 : ACTIVITY_NOT_AVAILABLE; } if (!ValidateAgainst(pstudiohdr)) { AssertMsg1(false, "CStudioHdr %s has changed its vmodel pointer without reinitializing its activity mapping! Now performing emergency reinitialization.", pstudiohdr->pszName()); ExecuteOnce(DebuggerBreakIfDebugging()); Reinitialize(pstudiohdr); } // a null m_pSequenceTuples just means that this studio header has no activities. if (!m_pSequenceTuples) return ACTIVITY_NOT_AVAILABLE; // get the data for the given activity HashValueType dummy( activity, 0, 0, 0 ); UtlHashHandle_t handle = m_ActToSeqHash.Find(dummy); if (!m_ActToSeqHash.IsValidHandle(handle)) { return ACTIVITY_NOT_AVAILABLE; } const HashValueType * __restrict actData = &m_ActToSeqHash[handle]; // go through each sequence and give it a score int top_score = -1; CUtlVector<int> topScoring( actData->count, actData->count ); for ( int i = 0; i < actData->count; i++ ) { SequenceTuple * __restrict sequenceInfo = m_pSequenceTuples + actData->startingIdx + i; int score = 0; // count matching activity modifiers for ( int m = 0; m < iModifierCount; m++ ) { int num_modifiers = sequenceInfo->iNumActivityModifiers; for ( int k = 0; k < num_modifiers; k++ ) { if ( sequenceInfo->pActivityModifiers[ k ] == pActivityModifiers[ m ] ) { score++; break; } } } if ( score > top_score ) { topScoring.RemoveAll(); topScoring.AddToTail( sequenceInfo->seqnum ); top_score = score; } } // randomly pick between the highest scoring sequences ( NOTE: this method of selecting a sequence ignores activity weights ) if ( IsInPrediction() ) { return topScoring[ SharedRandomInt( "SelectWeightedSequence", 0, topScoring.Count() - 1 ) ]; } return topScoring[ RandomInt( 0, topScoring.Count() - 1 ) ]; }
int SelectWeightedSequence( CStudioHdr *pstudiohdr, int activity, int curSequence ) { VPROF( "SelectWeightedSequence" ); if (! pstudiohdr) return 0; if (!pstudiohdr->SequencesAvailable()) return 0; VerifySequenceIndex( pstudiohdr ); #if STUDIO_SEQUENCE_ACTIVITY_LOOKUPS_ARE_SLOW int weighttotal = 0; int seq = ACTIVITY_NOT_AVAILABLE; int weight = 0; for (int i = 0; i < pstudiohdr->GetNumSeq(); i++) { int curActivity = GetSequenceActivity( pstudiohdr, i, &weight ); if (curActivity == activity) { if ( curSequence == i && weight < 0 ) { seq = i; break; } weighttotal += iabs(weight); int randomValue; if ( IsInPrediction() ) randomValue = SharedRandomInt( "SelectWeightedSequence", 0, weighttotal - 1, i ); else randomValue = RandomInt( 0, weighttotal - 1 ); if (!weighttotal || randomValue < iabs(weight)) seq = i; } } return seq; #else return pstudiohdr->SelectWeightedSequence( activity, curSequence ); #endif }