2
0
mirror of https://github.com/FWGS/hlsdk-xash3d synced 2024-11-22 09:57:21 +01:00
hlsdk-xash3d/dlls/h_cycler.cpp

454 lines
10 KiB
C++
Raw Normal View History

2016-06-04 15:24:23 +02:00
/***
*
* 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.
*
****/
/*
===== h_cycler.cpp ========================================================
The Halflife Cycler Monsters
*/
#include "extdll.h"
#include "util.h"
#include "cbase.h"
#include "monsters.h"
#include "animation.h"
#include "weapons.h"
#include "player.h"
2021-06-20 00:53:07 +02:00
#define TEMP_FOR_SCREEN_SHOTS 1
#if TEMP_FOR_SCREEN_SHOTS //===================================================
2016-06-04 15:24:23 +02:00
class CCycler : public CBaseMonster
{
public:
2017-06-29 15:56:03 +02:00
void GenericCyclerSpawn( const char *szModel, Vector vecMin, Vector vecMax );
2016-07-31 15:48:50 +02:00
virtual int ObjectCaps( void ) { return ( CBaseEntity::ObjectCaps() | FCAP_IMPULSE_USE ); }
2016-06-04 15:24:23 +02:00
int TakeDamage( entvars_t* pevInflictor, entvars_t* pevAttacker, float flDamage, int bitsDamageType );
void Spawn( void );
void Think( void );
//void Pain( float flDamage );
void Use ( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value );
// Don't treat as a live target
virtual BOOL IsAlive( void ) { return FALSE; }
2016-07-31 15:48:50 +02:00
virtual int Save( CSave &save );
virtual int Restore( CRestore &restore );
static TYPEDESCRIPTION m_SaveData[];
2016-06-04 15:24:23 +02:00
BOOL IsAllowedToSpeak( void ) { return TRUE; }
2016-07-31 15:48:50 +02:00
int m_animate;
2016-06-04 15:24:23 +02:00
};
2016-07-31 15:48:50 +02:00
TYPEDESCRIPTION CCycler::m_SaveData[] =
2016-06-04 15:24:23 +02:00
{
DEFINE_FIELD( CCycler, m_animate, FIELD_INTEGER ),
};
IMPLEMENT_SAVERESTORE( CCycler, CBaseMonster )
2016-06-04 15:24:23 +02:00
//
// we should get rid of all the other cyclers and replace them with this.
//
class CGenericCycler : public CCycler
{
public:
2016-07-31 15:48:50 +02:00
void Spawn( void )
{
2017-07-23 23:24:55 +02:00
GenericCyclerSpawn( STRING( pev->model ), Vector( -16, -16, 0 ), Vector( 16, 16, 72 ) );
2016-07-31 15:48:50 +02:00
}
2016-06-04 15:24:23 +02:00
};
LINK_ENTITY_TO_CLASS( cycler, CGenericCycler )
2016-06-04 15:24:23 +02:00
// Probe droid imported for tech demo compatibility
//
// PROBE DROID
//
class CCyclerProbe : public CCycler
{
public:
void Spawn( void );
};
LINK_ENTITY_TO_CLASS( cycler_prdroid, CCyclerProbe )
2016-07-31 15:48:50 +02:00
void CCyclerProbe::Spawn( void )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
pev->origin = pev->origin + Vector( 0, 0, 16 );
GenericCyclerSpawn( "models/prdroid.mdl", Vector( -16, -16, -16 ), Vector( 16, 16, 16 ) );
2016-06-04 15:24:23 +02:00
}
// Cycler member functions
2017-06-29 15:56:03 +02:00
void CCycler::GenericCyclerSpawn( const char *szModel, Vector vecMin, Vector vecMax )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
if( !szModel || !*szModel )
2016-06-04 15:24:23 +02:00
{
2019-10-13 13:49:25 +02:00
ALERT( at_error, "cycler at %.0f %.0f %0.f missing modelname", (double)pev->origin.x, (double)pev->origin.y, (double)pev->origin.z );
2016-07-31 15:48:50 +02:00
REMOVE_ENTITY( ENT( pev ) );
2016-06-04 15:24:23 +02:00
return;
}
2016-07-31 15:48:50 +02:00
pev->classname = MAKE_STRING( "cycler" );
2016-06-04 15:24:23 +02:00
PRECACHE_MODEL( szModel );
2016-07-31 15:48:50 +02:00
SET_MODEL( ENT( pev ), szModel );
2016-06-04 15:24:23 +02:00
2016-07-31 15:48:50 +02:00
CCycler::Spawn();
2016-06-04 15:24:23 +02:00
2016-07-31 15:48:50 +02:00
UTIL_SetSize( pev, vecMin, vecMax );
2016-06-04 15:24:23 +02:00
}
2016-07-31 15:48:50 +02:00
void CCycler::Spawn()
2016-06-04 15:24:23 +02:00
{
InitBoneControllers();
2016-07-31 15:48:50 +02:00
pev->solid = SOLID_SLIDEBOX;
2016-06-04 15:24:23 +02:00
pev->movetype = MOVETYPE_NONE;
pev->takedamage = DAMAGE_YES;
pev->effects = 0;
2016-07-31 15:48:50 +02:00
pev->health = 80000;// no cycler should die
2016-06-04 15:24:23 +02:00
pev->yaw_speed = 5;
pev->ideal_yaw = pev->angles.y;
ChangeYaw( 360 );
2016-07-31 15:48:50 +02:00
2016-06-04 15:24:23 +02:00
m_flFrameRate = 75;
m_flGroundSpeed = 0;
2019-10-13 13:49:25 +02:00
pev->nextthink += 1.0f;
2016-06-04 15:24:23 +02:00
2016-07-31 15:48:50 +02:00
ResetSequenceInfo();
2016-06-04 15:24:23 +02:00
2016-07-31 15:48:50 +02:00
if( pev->sequence != 0 || pev->frame != 0 )
2016-06-04 15:24:23 +02:00
{
m_animate = 0;
pev->framerate = 0;
}
else
{
m_animate = 1;
}
}
//
// cycler think
//
2016-07-31 15:48:50 +02:00
void CCycler::Think( void )
2016-06-04 15:24:23 +02:00
{
2019-10-13 13:49:25 +02:00
pev->nextthink = gpGlobals->time + 0.1f;
2016-06-04 15:24:23 +02:00
2016-07-31 15:48:50 +02:00
if( m_animate )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
StudioFrameAdvance();
2016-06-04 15:24:23 +02:00
}
2016-07-31 15:48:50 +02:00
if( m_fSequenceFinished && !m_fSequenceLoops )
2016-06-04 15:24:23 +02:00
{
// ResetSequenceInfo();
// hack to avoid reloading model every frame
pev->animtime = gpGlobals->time;
pev->framerate = 1.0;
m_fSequenceFinished = FALSE;
m_flLastEventCheck = gpGlobals->time;
pev->frame = 0;
2016-07-31 15:48:50 +02:00
if( !m_animate )
2019-10-13 13:49:25 +02:00
pev->framerate = 0.0f; // FIX: don't reset framerate
2016-06-04 15:24:23 +02:00
}
}
//
// CyclerUse - starts a rotation trend
//
2016-07-31 15:48:50 +02:00
void CCycler::Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value )
2016-06-04 15:24:23 +02:00
{
m_animate = !m_animate;
2016-07-31 15:48:50 +02:00
if( m_animate )
2019-10-13 13:49:25 +02:00
pev->framerate = 1.0f;
2016-06-04 15:24:23 +02:00
else
2019-10-13 13:49:25 +02:00
pev->framerate = 0.0f;
2016-06-04 15:24:23 +02:00
}
//
// CyclerPain , changes sequences when shot
//
2016-07-31 15:48:50 +02:00
//void CCycler::Pain( float flDamage )
int CCycler::TakeDamage( entvars_t *pevInflictor, entvars_t *pevAttacker, float flDamage, int bitsDamageType )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
if( m_animate )
2016-06-04 15:24:23 +02:00
{
pev->sequence++;
2016-07-31 15:48:50 +02:00
ResetSequenceInfo();
2016-06-04 15:24:23 +02:00
2019-10-13 13:49:25 +02:00
if( m_flFrameRate == 0.0f )
2016-06-04 15:24:23 +02:00
{
pev->sequence = 0;
2016-07-31 15:48:50 +02:00
ResetSequenceInfo();
2016-06-04 15:24:23 +02:00
}
pev->frame = 0;
}
else
{
2019-10-13 13:49:25 +02:00
pev->framerate = 1.0f;
StudioFrameAdvance( 0.1f );
2016-06-04 15:24:23 +02:00
pev->framerate = 0;
2019-10-13 13:49:25 +02:00
ALERT( at_console, "sequence: %d, frame %.0f\n", pev->sequence, (double)pev->frame );
2016-06-04 15:24:23 +02:00
}
return 0;
}
#endif
class CCyclerSprite : public CBaseEntity
{
public:
void Spawn( void );
void Think( void );
void Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value );
2016-07-31 15:48:50 +02:00
virtual int ObjectCaps( void ) { return ( CBaseEntity :: ObjectCaps() | FCAP_DONT_SAVE | FCAP_IMPULSE_USE ); }
virtual int TakeDamage( entvars_t *pevInflictor, entvars_t *pevAttacker, float flDamage, int bitsDamageType );
void Animate( float frames );
virtual int Save( CSave &save );
virtual int Restore( CRestore &restore );
static TYPEDESCRIPTION m_SaveData[];
inline int ShouldAnimate( void )
{
2019-10-13 13:49:25 +02:00
return m_animate && m_maxFrame > 1.0f;
2016-07-31 15:48:50 +02:00
}
int m_animate;
float m_lastTime;
float m_maxFrame;
2016-06-04 15:24:23 +02:00
};
LINK_ENTITY_TO_CLASS( cycler_sprite, CCyclerSprite )
2016-06-04 15:24:23 +02:00
2016-07-31 15:48:50 +02:00
TYPEDESCRIPTION CCyclerSprite::m_SaveData[] =
2016-06-04 15:24:23 +02:00
{
DEFINE_FIELD( CCyclerSprite, m_animate, FIELD_INTEGER ),
DEFINE_FIELD( CCyclerSprite, m_lastTime, FIELD_TIME ),
DEFINE_FIELD( CCyclerSprite, m_maxFrame, FIELD_FLOAT ),
};
IMPLEMENT_SAVERESTORE( CCyclerSprite, CBaseEntity )
2016-06-04 15:24:23 +02:00
void CCyclerSprite::Spawn( void )
{
2016-07-31 15:48:50 +02:00
pev->solid = SOLID_SLIDEBOX;
2016-06-04 15:24:23 +02:00
pev->movetype = MOVETYPE_NONE;
pev->takedamage = DAMAGE_YES;
pev->effects = 0;
2016-07-31 15:48:50 +02:00
pev->frame = 0;
2019-10-13 13:49:25 +02:00
pev->nextthink = gpGlobals->time + 0.1f;
2016-07-31 15:48:50 +02:00
m_animate = 1;
m_lastTime = gpGlobals->time;
2016-06-04 15:24:23 +02:00
2017-07-23 23:24:55 +02:00
PRECACHE_MODEL( STRING( pev->model ) );
2016-07-31 15:48:50 +02:00
SET_MODEL( ENT( pev ), STRING( pev->model ) );
2016-06-04 15:24:23 +02:00
2016-07-31 15:48:50 +02:00
m_maxFrame = (float)MODEL_FRAMES( pev->modelindex ) - 1;
2016-06-04 15:24:23 +02:00
}
void CCyclerSprite::Think( void )
{
2016-07-31 15:48:50 +02:00
if( ShouldAnimate() )
Animate( pev->framerate * ( gpGlobals->time - m_lastTime ) );
2016-06-04 15:24:23 +02:00
2019-10-13 13:49:25 +02:00
pev->nextthink = gpGlobals->time + 0.1f;
2016-06-04 15:24:23 +02:00
m_lastTime = gpGlobals->time;
}
void CCyclerSprite::Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value )
{
m_animate = !m_animate;
2016-07-31 15:48:50 +02:00
ALERT( at_console, "Sprite: %s\n", STRING( pev->model ) );
2016-06-04 15:24:23 +02:00
}
2016-07-31 15:48:50 +02:00
int CCyclerSprite::TakeDamage( entvars_t *pevInflictor, entvars_t *pevAttacker, float flDamage, int bitsDamageType )
2016-06-04 15:24:23 +02:00
{
2019-10-13 13:49:25 +02:00
if( m_maxFrame > 1.0f )
2016-06-04 15:24:23 +02:00
{
2019-10-13 13:49:25 +02:00
Animate( 1.0f );
2016-06-04 15:24:23 +02:00
}
return 1;
}
void CCyclerSprite::Animate( float frames )
{
pev->frame += frames;
2016-07-31 15:48:50 +02:00
if( m_maxFrame > 0 )
2016-06-04 15:24:23 +02:00
pev->frame = fmod( pev->frame, m_maxFrame );
}
class CWeaponCycler : public CBasePlayerWeapon
{
public:
void Spawn( void );
int iItemSlot( void ) { return 1; }
int GetItemInfo(ItemInfo *p) {return 0; }
void PrimaryAttack( void );
void SecondaryAttack( void );
BOOL Deploy( void );
void Holster( int skiplocal = 0 );
int m_iszModel;
int m_iModel;
};
LINK_ENTITY_TO_CLASS( cycler_weapon, CWeaponCycler )
2016-06-04 15:24:23 +02:00
2016-07-31 15:48:50 +02:00
void CWeaponCycler::Spawn()
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
pev->solid = SOLID_SLIDEBOX;
pev->movetype = MOVETYPE_NONE;
2016-06-04 15:24:23 +02:00
2017-07-23 23:24:55 +02:00
PRECACHE_MODEL( STRING( pev->model ) );
2016-07-31 15:48:50 +02:00
SET_MODEL( ENT( pev ), STRING( pev->model ) );
2016-06-04 15:24:23 +02:00
m_iszModel = pev->model;
m_iModel = pev->modelindex;
UTIL_SetOrigin( pev, pev->origin );
2016-07-31 15:48:50 +02:00
UTIL_SetSize( pev, Vector( -16, -16, 0 ), Vector( 16, 16, 16 ) );
2016-06-04 15:24:23 +02:00
SetTouch( &CBasePlayerItem::DefaultTouch );
}
2016-07-31 15:48:50 +02:00
BOOL CWeaponCycler::Deploy()
2016-06-04 15:24:23 +02:00
{
m_pPlayer->pev->viewmodel = m_iszModel;
2019-10-13 13:49:25 +02:00
m_pPlayer->m_flNextAttack = UTIL_WeaponTimeBase() + 1.0f;
2016-06-04 15:24:23 +02:00
SendWeaponAnim( 0 );
m_iClip = 0;
return TRUE;
}
void CWeaponCycler::Holster( int skiplocal /* = 0 */ )
{
2019-10-13 13:49:25 +02:00
m_pPlayer->m_flNextAttack = UTIL_WeaponTimeBase() + 0.5f;
2016-06-04 15:24:23 +02:00
}
void CWeaponCycler::PrimaryAttack()
{
SendWeaponAnim( pev->sequence );
2019-10-13 13:49:25 +02:00
m_flNextPrimaryAttack = gpGlobals->time + 0.3f;
2016-06-04 15:24:23 +02:00
}
void CWeaponCycler::SecondaryAttack( void )
{
float flFrameRate, flGroundSpeed;
2016-07-31 15:48:50 +02:00
pev->sequence = ( pev->sequence + 1 ) % 8;
2016-06-04 15:24:23 +02:00
pev->modelindex = m_iModel;
2016-07-31 15:48:50 +02:00
void *pmodel = GET_MODEL_PTR( ENT( pev ) );
2016-06-04 15:24:23 +02:00
GetSequenceInfo( pmodel, pev, &flFrameRate, &flGroundSpeed );
pev->modelindex = 0;
2019-10-13 13:49:25 +02:00
if( flFrameRate == 0.0f )
2016-06-04 15:24:23 +02:00
{
pev->sequence = 0;
}
SendWeaponAnim( pev->sequence );
2019-10-13 13:49:25 +02:00
m_flNextSecondaryAttack = gpGlobals->time + 0.3f;
2016-06-04 15:24:23 +02:00
}
// Flaming Wreakage
class CWreckage : public CBaseMonster
{
2016-07-31 15:48:50 +02:00
int Save( CSave &save );
int Restore( CRestore &restore );
static TYPEDESCRIPTION m_SaveData[];
2016-06-04 15:24:23 +02:00
void Spawn( void );
void Precache( void );
void Think( void );
int m_flStartTime;
};
2016-07-31 15:48:50 +02:00
TYPEDESCRIPTION CWreckage::m_SaveData[] =
2016-06-04 15:24:23 +02:00
{
DEFINE_FIELD( CWreckage, m_flStartTime, FIELD_TIME ),
};
IMPLEMENT_SAVERESTORE( CWreckage, CBaseMonster )
2016-06-04 15:24:23 +02:00
LINK_ENTITY_TO_CLASS( cycler_wreckage, CWreckage )
2016-06-04 15:24:23 +02:00
void CWreckage::Spawn( void )
{
2016-07-31 15:48:50 +02:00
pev->solid = SOLID_NOT;
pev->movetype = MOVETYPE_NONE;
pev->takedamage = 0;
pev->effects = 0;
2016-06-04 15:24:23 +02:00
2016-07-31 15:48:50 +02:00
pev->frame = 0;
2019-10-13 13:49:25 +02:00
pev->nextthink = gpGlobals->time + 0.1f;
2016-06-04 15:24:23 +02:00
2016-07-31 15:48:50 +02:00
if( pev->model )
2016-06-04 15:24:23 +02:00
{
2017-07-23 23:24:55 +02:00
PRECACHE_MODEL( STRING( pev->model ) );
2016-07-31 15:48:50 +02:00
SET_MODEL( ENT( pev ), STRING( pev->model ) );
2016-06-04 15:24:23 +02:00
}
// pev->scale = 5.0;
2017-06-29 15:56:03 +02:00
m_flStartTime = (int)gpGlobals->time;
2016-06-04 15:24:23 +02:00
}
2016-07-31 15:48:50 +02:00
void CWreckage::Precache()
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
if( pev->model )
2017-07-23 23:24:55 +02:00
PRECACHE_MODEL( STRING( pev->model ) );
2016-06-04 15:24:23 +02:00
}
void CWreckage::Think( void )
{
2016-07-31 15:48:50 +02:00
StudioFrameAdvance();
2019-10-13 13:49:25 +02:00
pev->nextthink = gpGlobals->time + 0.2f;
2016-06-04 15:24:23 +02:00
2016-07-31 15:48:50 +02:00
if( pev->dmgtime )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
if( pev->dmgtime < gpGlobals->time )
2016-06-04 15:24:23 +02:00
{
UTIL_Remove( this );
return;
}
2016-07-31 15:48:50 +02:00
else if( RANDOM_FLOAT( 0, pev->dmgtime - m_flStartTime ) > pev->dmgtime - gpGlobals->time )
2016-06-04 15:24:23 +02:00
{
return;
}
}
2016-07-31 15:48:50 +02:00
2016-06-04 15:24:23 +02:00
Vector VecSrc;
2016-07-31 15:48:50 +02:00
2016-06-04 15:24:23 +02:00
VecSrc.x = RANDOM_FLOAT( pev->absmin.x, pev->absmax.x );
VecSrc.y = RANDOM_FLOAT( pev->absmin.y, pev->absmax.y );
VecSrc.z = RANDOM_FLOAT( pev->absmin.z, pev->absmax.z );
MESSAGE_BEGIN( MSG_PVS, SVC_TEMPENTITY, VecSrc );
WRITE_BYTE( TE_SMOKE );
WRITE_COORD( VecSrc.x );
WRITE_COORD( VecSrc.y );
WRITE_COORD( VecSrc.z );
WRITE_SHORT( g_sModelIndexSmoke );
2016-07-31 15:48:50 +02:00
WRITE_BYTE( RANDOM_LONG( 0,49 ) + 50 ); // scale * 10
WRITE_BYTE( RANDOM_LONG( 0, 3 ) + 8 ); // framerate
2016-06-04 15:24:23 +02:00
MESSAGE_END();
}