Portable Half-Life SDK. GoldSource and Xash3D. Crossplatform.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

322 lines
9.0 KiB

7 years ago
/***
*
* Copyright (c) 1996-2002, Valve LLC. All rights reserved.
*
* This product contains software technology licensed from Id
* Software, Inc. ("Id Technology"). Id Technology (c) 1996 Id Software, Inc.
* All Rights Reserved.
*
* Use, distribution, and modification of this source code and/or resulting
* object code is restricted to non-commercial enhancements to products from
* Valve LLC. All other use, distribution, or modification is prohibited
* without written permission from Valve LLC.
*
****/
/*
===== monsters.cpp ========================================================
Monster-related utility code
*/
#include "extdll.h"
#include "util.h"
#include "cbase.h"
#include "animation.h"
#include "saverestore.h"
8 years ago
TYPEDESCRIPTION CBaseAnimating::m_SaveData[] =
7 years ago
{
DEFINE_FIELD( CBaseMonster, m_flFrameRate, FIELD_FLOAT ),
DEFINE_FIELD( CBaseMonster, m_flGroundSpeed, FIELD_FLOAT ),
DEFINE_FIELD( CBaseMonster, m_flLastEventCheck, FIELD_TIME ),
DEFINE_FIELD( CBaseMonster, m_fSequenceFinished, FIELD_BOOLEAN ),
DEFINE_FIELD( CBaseMonster, m_fSequenceLoops, FIELD_BOOLEAN ),
};
IMPLEMENT_SAVERESTORE( CBaseAnimating, CBaseDelay )
7 years ago
//=========================================================
// StudioFrameAdvance - advance the animation frame up to the current time
// if an flInterval is passed in, only advance animation that number of seconds
//=========================================================
8 years ago
float CBaseAnimating::StudioFrameAdvance( float flInterval )
7 years ago
{
if( flInterval == 0.0f )
7 years ago
{
8 years ago
flInterval = gpGlobals->time - pev->animtime;
if( flInterval <= 0.001f )
7 years ago
{
pev->animtime = gpGlobals->time;
return 0.0f;
7 years ago
}
}
8 years ago
if( !pev->animtime )
flInterval = 0.0f;
8 years ago
7 years ago
pev->frame += flInterval * m_flFrameRate * pev->framerate;
pev->animtime = gpGlobals->time;
if( pev->frame < 0.0f || pev->frame >= 256.0f )
7 years ago
{
8 years ago
if( m_fSequenceLoops )
pev->frame -= (int)( pev->frame / 256.0f ) * 256.0f;
7 years ago
else
pev->frame = ( pev->frame < 0.0f ) ? 0.0f : 255.0f;
7 years ago
m_fSequenceFinished = TRUE; // just in case it wasn't caught in GetEvents
}
return flInterval;
}
//=========================================================
// LookupActivity
//=========================================================
8 years ago
int CBaseAnimating::LookupActivity( int activity )
7 years ago
{
ASSERT( activity != 0 );
8 years ago
void *pmodel = GET_MODEL_PTR( ENT( pev ) );
7 years ago
return ::LookupActivity( pmodel, pev, activity );
}
//=========================================================
// LookupActivityHeaviest
//
// Get activity with highest 'weight'
//
//=========================================================
8 years ago
int CBaseAnimating::LookupActivityHeaviest( int activity )
7 years ago
{
8 years ago
void *pmodel = GET_MODEL_PTR( ENT( pev ) );
7 years ago
return ::LookupActivityHeaviest( pmodel, pev, activity );
}
//=========================================================
//=========================================================
8 years ago
int CBaseAnimating::LookupSequence( const char *label )
7 years ago
{
8 years ago
void *pmodel = GET_MODEL_PTR( ENT( pev ) );
7 years ago
return ::LookupSequence( pmodel, label );
}
//=========================================================
//=========================================================
8 years ago
void CBaseAnimating::ResetSequenceInfo()
7 years ago
{
8 years ago
void *pmodel = GET_MODEL_PTR( ENT( pev ) );
7 years ago
GetSequenceInfo( pmodel, pev, &m_flFrameRate, &m_flGroundSpeed );
8 years ago
m_fSequenceLoops = ( ( GetSequenceFlags() & STUDIO_LOOPING ) != 0 );
7 years ago
pev->animtime = gpGlobals->time;
pev->framerate = 1.0;
m_fSequenceFinished = FALSE;
m_flLastEventCheck = gpGlobals->time;
}
//=========================================================
//=========================================================
8 years ago
BOOL CBaseAnimating::GetSequenceFlags()
7 years ago
{
8 years ago
void *pmodel = GET_MODEL_PTR( ENT( pev ) );
7 years ago
return ::GetSequenceFlags( pmodel, pev );
}
//=========================================================
// DispatchAnimEvents
//=========================================================
8 years ago
void CBaseAnimating::DispatchAnimEvents( float flInterval )
7 years ago
{
MonsterEvent_t event;
8 years ago
void *pmodel = GET_MODEL_PTR( ENT( pev ) );
7 years ago
8 years ago
if( !pmodel )
7 years ago
{
ALERT( at_aiconsole, "Gibbed monster is thinking!\n" );
return;
}
// FIXME: I have to do this or some events get missed, and this is probably causing the problem below
flInterval = 0.1f;
7 years ago
// FIX: this still sometimes hits events twice
8 years ago
float flStart = pev->frame + ( m_flLastEventCheck - pev->animtime ) * m_flFrameRate * pev->framerate;
7 years ago
float flEnd = pev->frame + flInterval * m_flFrameRate * pev->framerate;
m_flLastEventCheck = pev->animtime + flInterval;
m_fSequenceFinished = FALSE;
if( flEnd >= 256.0f || flEnd <= 0.0f )
7 years ago
m_fSequenceFinished = TRUE;
int index = 0;
8 years ago
while( ( index = GetAnimationEvent( pmodel, pev, &event, flStart, flEnd, index ) ) != 0 )
7 years ago
{
HandleAnimEvent( &event );
}
}
//=========================================================
//=========================================================
8 years ago
float CBaseAnimating::SetBoneController( int iController, float flValue )
7 years ago
{
8 years ago
void *pmodel = GET_MODEL_PTR( ENT( pev ) );
7 years ago
return SetController( pmodel, pev, iController, flValue );
}
//=========================================================
//=========================================================
8 years ago
void CBaseAnimating::InitBoneControllers( void )
7 years ago
{
8 years ago
void *pmodel = GET_MODEL_PTR( ENT( pev ) );
7 years ago
SetController( pmodel, pev, 0, 0.0 );
SetController( pmodel, pev, 1, 0.0 );
SetController( pmodel, pev, 2, 0.0 );
SetController( pmodel, pev, 3, 0.0 );
}
//=========================================================
//=========================================================
8 years ago
float CBaseAnimating::SetBlending( int iBlender, float flValue )
7 years ago
{
8 years ago
void *pmodel = GET_MODEL_PTR( ENT( pev ) );
7 years ago
return ::SetBlending( pmodel, pev, iBlender, flValue );
}
//=========================================================
//=========================================================
8 years ago
void CBaseAnimating::GetBonePosition( int iBone, Vector &origin, Vector &angles )
7 years ago
{
8 years ago
GET_BONE_POSITION( ENT( pev ), iBone, origin, angles );
7 years ago
}
//=========================================================
//=========================================================
8 years ago
void CBaseAnimating::GetAttachment( int iAttachment, Vector &origin, Vector &angles )
7 years ago
{
8 years ago
GET_ATTACHMENT( ENT( pev ), iAttachment, origin, angles );
7 years ago
}
//=========================================================
//=========================================================
8 years ago
int CBaseAnimating::FindTransition( int iEndingSequence, int iGoalSequence, int *piDir )
7 years ago
{
8 years ago
void *pmodel = GET_MODEL_PTR( ENT( pev ) );
if( piDir == NULL )
7 years ago
{
int iDir;
int sequence = ::FindTransition( pmodel, iEndingSequence, iGoalSequence, &iDir );
8 years ago
if( iDir != 1 )
7 years ago
return -1;
else
return sequence;
}
return ::FindTransition( pmodel, iEndingSequence, iGoalSequence, piDir );
}
//=========================================================
//=========================================================
8 years ago
void CBaseAnimating::GetAutomovement( Vector &origin, Vector &angles, float flInterval )
7 years ago
{
}
8 years ago
void CBaseAnimating::SetBodygroup( int iGroup, int iValue )
7 years ago
{
8 years ago
::SetBodygroup( GET_MODEL_PTR( ENT( pev ) ), pev, iGroup, iValue );
7 years ago
}
8 years ago
int CBaseAnimating::GetBodygroup( int iGroup )
7 years ago
{
8 years ago
return ::GetBodygroup( GET_MODEL_PTR( ENT( pev ) ), pev, iGroup );
7 years ago
}
int CBaseAnimating :: GetBoneCount( void )
{
return ::GetBoneCount( GET_MODEL_PTR(ENT(pev)) );
}
void CBaseAnimating :: SetBones( float (*data)[3], int datasize )
{
::SetBones( GET_MODEL_PTR( ENT(pev) ), data, datasize );
}
8 years ago
int CBaseAnimating::ExtractBbox( int sequence, float *mins, float *maxs )
7 years ago
{
8 years ago
return ::ExtractBbox( GET_MODEL_PTR( ENT( pev ) ), sequence, mins, maxs );
7 years ago
}
//=========================================================
//=========================================================
8 years ago
void CBaseAnimating::SetSequenceBox( void )
7 years ago
{
Vector mins, maxs;
// Get sequence bbox
8 years ago
if( ExtractBbox( pev->sequence, mins, maxs ) )
7 years ago
{
// expand box for rotation
// find min / max for rotations
float yaw = pev->angles.y * ( M_PI_F / 180.0f );
8 years ago
7 years ago
Vector xvector, yvector;
8 years ago
xvector.x = cos( yaw );
xvector.y = sin( yaw );
yvector.x = -sin( yaw );
yvector.y = cos( yaw );
7 years ago
Vector bounds[2];
bounds[0] = mins;
bounds[1] = maxs;
8 years ago
Vector rmin( 9999.0f, 9999.0f, 9999.0f );
Vector rmax( -9999.0f, -9999.0f, -9999.0f );
7 years ago
Vector base, transformed;
8 years ago
for( int i = 0; i <= 1; i++ )
7 years ago
{
base.x = bounds[i].x;
8 years ago
for( int j = 0; j <= 1; j++ )
7 years ago
{
base.y = bounds[j].y;
8 years ago
for( int k = 0; k <= 1; k++ )
7 years ago
{
base.z = bounds[k].z;
8 years ago
// transform the point
transformed.x = xvector.x * base.x + yvector.x * base.y;
transformed.y = xvector.y * base.x + yvector.y * base.y;
7 years ago
transformed.z = base.z;
8 years ago
if( transformed.x < rmin.x )
7 years ago
rmin.x = transformed.x;
8 years ago
if( transformed.x > rmax.x )
7 years ago
rmax.x = transformed.x;
8 years ago
if( transformed.y < rmin.y )
7 years ago
rmin.y = transformed.y;
8 years ago
if( transformed.y > rmax.y )
7 years ago
rmax.y = transformed.y;
8 years ago
if( transformed.z < rmin.z )
7 years ago
rmin.z = transformed.z;
8 years ago
if( transformed.z > rmax.z )
7 years ago
rmax.z = transformed.z;
}
}
}
rmin.z = 0.0f;
rmax.z = rmin.z + 1.0f;
7 years ago
UTIL_SetSize( pev, rmin, rmax );
}
}