diff options
| author | Jørgen P. Tjernø <[email protected]> | 2013-12-02 19:31:46 -0800 |
|---|---|---|
| committer | Jørgen P. Tjernø <[email protected]> | 2013-12-02 19:46:31 -0800 |
| commit | f56bb35301836e56582a575a75864392a0177875 (patch) | |
| tree | de61ddd39de3e7df52759711950b4c288592f0dc /mp/src/game/server/sdk/sdk_modelentity.cpp | |
| parent | Mark some more files as text. (diff) | |
| download | source-sdk-2013-f56bb35301836e56582a575a75864392a0177875.tar.xz source-sdk-2013-f56bb35301836e56582a575a75864392a0177875.zip | |
Fix line endings. WHAMMY.
Diffstat (limited to 'mp/src/game/server/sdk/sdk_modelentity.cpp')
| -rw-r--r-- | mp/src/game/server/sdk/sdk_modelentity.cpp | 256 |
1 files changed, 128 insertions, 128 deletions
diff --git a/mp/src/game/server/sdk/sdk_modelentity.cpp b/mp/src/game/server/sdk/sdk_modelentity.cpp index e3dca5b6..aad6aead 100644 --- a/mp/src/game/server/sdk/sdk_modelentity.cpp +++ b/mp/src/game/server/sdk/sdk_modelentity.cpp @@ -1,128 +1,128 @@ -//========= Copyright Valve Corporation, All rights reserved. ============//
-//
-// Purpose: Simple model entity that randomly moves and changes direction
-// when activated.
-//
-//=============================================================================//
-
-#include "cbase.h"
-
-class CMyModelEntity : public CBaseAnimating
-{
-public:
- DECLARE_CLASS( CMyModelEntity, CBaseAnimating );
- DECLARE_DATADESC();
-
- void Spawn( void );
- void Precache( void );
-
- void MoveThink( void );
-
- // Input function
- void InputToggle( inputdata_t &inputData );
-
-private:
-
- bool m_bActive;
- float m_flNextChangeTime;
-};
-
-LINK_ENTITY_TO_CLASS( my_model_entity, CMyModelEntity );
-
-// Start of our data description for the class
-BEGIN_DATADESC( CMyModelEntity )
-
- // Save/restore our active state
- DEFINE_FIELD( m_bActive, FIELD_BOOLEAN ),
- DEFINE_FIELD( m_flNextChangeTime, FIELD_TIME ),
-
- // Links our input name from Hammer to our input member function
- DEFINE_INPUTFUNC( FIELD_VOID, "Toggle", InputToggle ),
-
- // Declare our think function
- DEFINE_THINKFUNC( MoveThink ),
-
-END_DATADESC()
-
-// Name of our entity's model
-#define ENTITY_MODEL "models/gibs/airboat_broken_engine.mdl"
-
-//-----------------------------------------------------------------------------
-// Purpose: Precache assets used by the entity
-//-----------------------------------------------------------------------------
-void CMyModelEntity::Precache( void )
-{
- PrecacheModel( ENTITY_MODEL );
-}
-
-//-----------------------------------------------------------------------------
-// Purpose: Sets up the entity's initial state
-//-----------------------------------------------------------------------------
-void CMyModelEntity::Spawn( void )
-{
- Precache();
-
- SetModel( ENTITY_MODEL );
- SetSolid( SOLID_BBOX );
- UTIL_SetSize( this, -Vector(20,20,20), Vector(20,20,20) );
-
- m_bActive = false;
-}
-
-//-----------------------------------------------------------------------------
-// Purpose: Think function to randomly move the entity
-//-----------------------------------------------------------------------------
-void CMyModelEntity::MoveThink( void )
-{
- // See if we should change direction again
- if ( m_flNextChangeTime < gpGlobals->curtime )
- {
- // Randomly take a new direction and speed
- Vector vecNewVelocity = RandomVector( -64.0f, 64.0f );
- SetAbsVelocity( vecNewVelocity );
-
- // Randomly change it again within one to three seconds
- m_flNextChangeTime = gpGlobals->curtime + random->RandomFloat( 1.0f, 3.0f );
- }
-
- // Snap our facing to where we're heading
- Vector velFacing = GetAbsVelocity();
- QAngle angFacing;
- VectorAngles( velFacing, angFacing );
- SetAbsAngles( angFacing );
-
- // Think every 20Hz
- SetNextThink( gpGlobals->curtime + 0.05f );
-}
-
-//-----------------------------------------------------------------------------
-// Purpose: Toggle the movement of the entity
-//-----------------------------------------------------------------------------
-void CMyModelEntity::InputToggle( inputdata_t &inputData )
-{
- // Toggle our active state
- if ( !m_bActive )
- {
- // Start thinking
- SetThink( &CMyModelEntity::MoveThink );
- SetNextThink( gpGlobals->curtime + 0.05f );
-
- // Start flying
- SetMoveType( MOVETYPE_FLY );
-
- // Set our next time for changing our speed and direction
- m_flNextChangeTime = gpGlobals->curtime;
- m_bActive = true;
- }
- else
- {
- // Stop thinking
- SetThink( NULL );
-
- // Stop moving
- SetAbsVelocity( vec3_origin );
- SetMoveType( MOVETYPE_NONE );
-
- m_bActive = false;
- }
-}
+//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: Simple model entity that randomly moves and changes direction +// when activated. +// +//=============================================================================// + +#include "cbase.h" + +class CMyModelEntity : public CBaseAnimating +{ +public: + DECLARE_CLASS( CMyModelEntity, CBaseAnimating ); + DECLARE_DATADESC(); + + void Spawn( void ); + void Precache( void ); + + void MoveThink( void ); + + // Input function + void InputToggle( inputdata_t &inputData ); + +private: + + bool m_bActive; + float m_flNextChangeTime; +}; + +LINK_ENTITY_TO_CLASS( my_model_entity, CMyModelEntity ); + +// Start of our data description for the class +BEGIN_DATADESC( CMyModelEntity ) + + // Save/restore our active state + DEFINE_FIELD( m_bActive, FIELD_BOOLEAN ), + DEFINE_FIELD( m_flNextChangeTime, FIELD_TIME ), + + // Links our input name from Hammer to our input member function + DEFINE_INPUTFUNC( FIELD_VOID, "Toggle", InputToggle ), + + // Declare our think function + DEFINE_THINKFUNC( MoveThink ), + +END_DATADESC() + +// Name of our entity's model +#define ENTITY_MODEL "models/gibs/airboat_broken_engine.mdl" + +//----------------------------------------------------------------------------- +// Purpose: Precache assets used by the entity +//----------------------------------------------------------------------------- +void CMyModelEntity::Precache( void ) +{ + PrecacheModel( ENTITY_MODEL ); +} + +//----------------------------------------------------------------------------- +// Purpose: Sets up the entity's initial state +//----------------------------------------------------------------------------- +void CMyModelEntity::Spawn( void ) +{ + Precache(); + + SetModel( ENTITY_MODEL ); + SetSolid( SOLID_BBOX ); + UTIL_SetSize( this, -Vector(20,20,20), Vector(20,20,20) ); + + m_bActive = false; +} + +//----------------------------------------------------------------------------- +// Purpose: Think function to randomly move the entity +//----------------------------------------------------------------------------- +void CMyModelEntity::MoveThink( void ) +{ + // See if we should change direction again + if ( m_flNextChangeTime < gpGlobals->curtime ) + { + // Randomly take a new direction and speed + Vector vecNewVelocity = RandomVector( -64.0f, 64.0f ); + SetAbsVelocity( vecNewVelocity ); + + // Randomly change it again within one to three seconds + m_flNextChangeTime = gpGlobals->curtime + random->RandomFloat( 1.0f, 3.0f ); + } + + // Snap our facing to where we're heading + Vector velFacing = GetAbsVelocity(); + QAngle angFacing; + VectorAngles( velFacing, angFacing ); + SetAbsAngles( angFacing ); + + // Think every 20Hz + SetNextThink( gpGlobals->curtime + 0.05f ); +} + +//----------------------------------------------------------------------------- +// Purpose: Toggle the movement of the entity +//----------------------------------------------------------------------------- +void CMyModelEntity::InputToggle( inputdata_t &inputData ) +{ + // Toggle our active state + if ( !m_bActive ) + { + // Start thinking + SetThink( &CMyModelEntity::MoveThink ); + SetNextThink( gpGlobals->curtime + 0.05f ); + + // Start flying + SetMoveType( MOVETYPE_FLY ); + + // Set our next time for changing our speed and direction + m_flNextChangeTime = gpGlobals->curtime; + m_bActive = true; + } + else + { + // Stop thinking + SetThink( NULL ); + + // Stop moving + SetAbsVelocity( vec3_origin ); + SetMoveType( MOVETYPE_NONE ); + + m_bActive = false; + } +} |