I second Captain P advice, the way you are doing it right now will involve a lot of code duplication and that will put a lot of burden when maintaining it.
Sometimes in situations like these, it's best to make methods that solve small but repetitive problems. In your case, one small problem is "how do I convert the
pev->weapons
value to a C string that would match the animations names" and "how do I handle the standing up/crouched difference".
Then you combine both solutions to get the "final answer" to your original problem which was "how do I get the proper value to use in
LookupSequence
". In the end, you have something like this:
/**
* Returns the name of a sequence for this monster based on his stance (standing up or crouched), a specific name and his current weapon's name.
* @param szName The name of the sequence without the stance ("ref_" and "crouch_"), weapon's name ("python"...) and any underscore.
* @return The corresponding sequence name.
*/
const char *CMyMonster::GetSequenceName( const char *szName ) const
{
static char szResult[32];
strncpy( szResult, m_fStanding ? "ref_" : "crouch_", sizeof( szResult ) );
strncat( szResult, szName, sizeof( szResult ) );
strncat( szResult, "_", sizeof( szResult ) );
strncat( szResult, GetWeaponIDAsCStr(), sizeof( szResult ) );
return szResult;
}
/**
* Returns the name of the weapon this monster is currently using as a "C string".
* This is used to select the proper sequence when performing activities.
* @return This monster's current weapon name.
*/
const char *CMyMonster::GetWeaponIDAsCStr() const
{
if ( pev->weapons & HEVSCI_PYTHON )
return "python";
else if ( pev->weapons & HEVSCI_SHOTGUN )
return "shotgun";
else if ( pev->weapons & HEVSCI_MP5 )
return "mp5";
else if ( pev->weapons & HEVSCI_CROSSBOW )
return "bow";
else if ( pev->weapons & HEVSCI_RPG )
return "rpg";
else if ( pev->weapons & HEVSCI_GAUSS )
return "gauss";
else
return "onehanded";
}
Which you can use like this:
void CMyMonster::SetActivity( Activity NewActivity )
{
int iSequence = ACTIVITY_NOT_AVAILABLE;
void *pModel = GET_MODEL_PTR( ENT( pev ) );
switch ( NewActivity )
{
case ACT_IDLE:
iSequence = LookupSequence( GetSequenceName( "aim" ) );
break;
default:
iSequence = LookupActivity( NewActivity );
}
if ( iSequence <= ACTIVITY_NOT_AVAILABLE )
{
// Not available try to get default anim
ALERT( at_console, "%s has no sequence for act:%d\n", STRING( pev->classname ), NewActivity );
pev->sequence = 0; // Set to the reset anim (if it's there)
return;
}
// Set to the desired anim, or default anim if the desired is not present
if ( pev->sequence != iSequence || !m_fSequenceLoops )
pev->frame = 0;
pev->sequence = iSequence; // Set to the reset anim (if it's there)
ResetSequenceInfo();
SetYawSpeed();
}
Assuming your monster is crouched, uses the Python and you want the corresponding
aim
sequence,
GetSequenceName( "aim" )
will return
crouched_aim_python
.