Skip to content

Commit

Permalink
Added env_model from Day of Defeat & Spirit SDK mods
Browse files Browse the repository at this point in the history
  • Loading branch information
SmileyAG committed Nov 6, 2022
1 parent 90e7e35 commit 8451ba7
Showing 1 changed file with 180 additions and 0 deletions.
180 changes: 180 additions & 0 deletions dlls/effects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1343,6 +1343,186 @@ void CSprite::Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useTy
}
}

//=================================================================
// env_model: like env_sprite, except you can specify a sequence.
//=================================================================
#define SF_ENVMODEL_OFF 1
#define SF_ENVMODEL_DROPTOFLOOR 2
#define SF_ENVMODEL_SOLID 4

class CEnvModel : public CBaseAnimating
{
void Spawn( void );
void Precache( void );
void EXPORT Think( void );
void KeyValue( KeyValueData *pkvd );
void Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value );
virtual int ObjectCaps( void ) { return CBaseEntity :: ObjectCaps() & ~FCAP_ACROSS_TRANSITION; }

virtual int Save( CSave &save );
virtual int Restore( CRestore &restore );
static TYPEDESCRIPTION m_SaveData[];

void SetSequence( void );

string_t m_iszSequence_On;
string_t m_iszSequence_Off;
int m_iAction_On;
int m_iAction_Off;
};

TYPEDESCRIPTION CEnvModel::m_SaveData[] =
{
DEFINE_FIELD( CEnvModel, m_iszSequence_On, FIELD_STRING ),
DEFINE_FIELD( CEnvModel, m_iszSequence_Off, FIELD_STRING ),
DEFINE_FIELD( CEnvModel, m_iAction_On, FIELD_INTEGER ),
DEFINE_FIELD( CEnvModel, m_iAction_Off, FIELD_INTEGER ),
};

IMPLEMENT_SAVERESTORE( CEnvModel, CBaseAnimating );
LINK_ENTITY_TO_CLASS( env_model, CEnvModel );

void CEnvModel::KeyValue( KeyValueData *pkvd )
{
if (FStrEq(pkvd->szKeyName, "m_iszSequence_On"))
{
m_iszSequence_On = ALLOC_STRING(pkvd->szValue);
pkvd->fHandled = TRUE;
}
else if (FStrEq(pkvd->szKeyName, "m_iszSequence_Off"))
{
m_iszSequence_Off = ALLOC_STRING(pkvd->szValue);
pkvd->fHandled = TRUE;
}
else if (FStrEq(pkvd->szKeyName, "m_iAction_On"))
{
m_iAction_On = atoi(pkvd->szValue);
pkvd->fHandled = TRUE;
}
else if (FStrEq(pkvd->szKeyName, "m_iAction_Off"))
{
m_iAction_Off = atoi(pkvd->szValue);
pkvd->fHandled = TRUE;
}
else
{
CBaseAnimating::KeyValue( pkvd );
}
}

void CEnvModel :: Spawn( void )
{
Precache();
SET_MODEL( ENT(pev), STRING(pev->model) );
UTIL_SetOrigin(pev, pev->origin);

if (pev->spawnflags & SF_ENVMODEL_SOLID)
{
pev->solid = SOLID_SLIDEBOX;
UTIL_SetSize(pev, Vector(-10, -10, -10), Vector(10, 10, 10)); //LRCT
}

if (pev->spawnflags & SF_ENVMODEL_DROPTOFLOOR)
{
pev->origin.z += 1;
DROP_TO_FLOOR ( ENT(pev) );
}
SetBoneController( 0, 0 );
SetBoneController( 1, 0 );

SetSequence();

pev->nextthink = gpGlobals->time + 0.1;
}

void CEnvModel::Precache( void )
{
PRECACHE_MODEL( (char *)STRING(pev->model) );
}

void CEnvModel::Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value )
{
if (ShouldToggle(useType, !(pev->spawnflags & SF_ENVMODEL_OFF)))
{
if (pev->spawnflags & SF_ENVMODEL_OFF)
pev->spawnflags &= ~SF_ENVMODEL_OFF;
else
pev->spawnflags |= SF_ENVMODEL_OFF;

SetSequence();
pev->nextthink = gpGlobals->time + 0.1;
}
}

void CEnvModel::Think( void )
{
int iTemp;

StudioFrameAdvance ( ); // set m_fSequenceFinished if necessary

if (m_fSequenceFinished && !m_fSequenceLoops)
{
if (pev->spawnflags & SF_ENVMODEL_OFF)
iTemp = m_iAction_Off;
else
iTemp = m_iAction_On;

switch (iTemp)
{
case 2: // change state
if (pev->spawnflags & SF_ENVMODEL_OFF)
pev->spawnflags &= ~SF_ENVMODEL_OFF;
else
pev->spawnflags |= SF_ENVMODEL_OFF;
SetSequence();
break;
default: //remain frozen
return;
}
}
pev->nextthink = gpGlobals->time + 0.1;
}

void CEnvModel :: SetSequence( void )
{
int iszSeq;

if (pev->spawnflags & SF_ENVMODEL_OFF)
iszSeq = m_iszSequence_Off;
else
iszSeq = m_iszSequence_On;

if (!iszSeq)
return;
pev->sequence = LookupSequence( STRING( iszSeq ));

if (pev->sequence == -1)
{
if (pev->targetname)
ALERT( at_error, "env_model %s: unknown sequence \"%s\"\n", STRING( pev->targetname ), STRING( iszSeq ));
else
ALERT( at_error, "env_model: unknown sequence \"%s\"\n", STRING( pev->targetname ), STRING( iszSeq ));
pev->sequence = 0;
}

pev->frame = 0;
ResetSequenceInfo( );

if (pev->spawnflags & SF_ENVMODEL_OFF)
{
if (m_iAction_Off == 1)
m_fSequenceLoops = 1;
else
m_fSequenceLoops = 0;
}
else
{
if (m_iAction_On == 1)
m_fSequenceLoops = 1;
else
m_fSequenceLoops = 0;
}
}

class CGibShooter : public CBaseDelay
{
Expand Down

0 comments on commit 8451ba7

Please sign in to comment.