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.

1406 lines
36 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.
*
****/
/*
===== doors.cpp ========================================================
*/
#include "extdll.h"
#include "util.h"
#include "cbase.h"
#include "doors.h"
#include "movewith.h"
#include "game.h"
#include "weapons.h"
7 years ago
8 years ago
extern void SetMovedir( entvars_t *ev );
7 years ago
#define noiseMoving noise1
#define noiseArrived noise2
class CBaseDoor : public CBaseToggle
{
public:
void Spawn( void );
void Precache( void );
virtual void PostSpawn( void );
virtual void KeyValue( KeyValueData *pkvd );
virtual void Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value );
virtual void Blocked( CBaseEntity *pOther );
8 years ago
virtual int ObjectCaps( void )
7 years ago
{
8 years ago
if( pev->spawnflags & SF_ITEM_USE_ONLY )
7 years ago
{
return (CBaseToggle::ObjectCaps() & ~FCAP_ACROSS_TRANSITION) | FCAP_IMPULSE_USE |
(m_iDirectUse ? FCAP_ONLYDIRECT_USE : 0);
}
else
return (CBaseToggle::ObjectCaps() & ~FCAP_ACROSS_TRANSITION);
};
8 years ago
virtual int Save( CSave &save );
virtual int Restore( CRestore &restore );
static TYPEDESCRIPTION m_SaveData[];
7 years ago
virtual void SetToggleState( int state );
// used to selectivly override defaults
void EXPORT DoorTouch( CBaseEntity *pOther );
// local functions
8 years ago
int DoorActivate();
7 years ago
void EXPORT DoorGoUp( void );
void EXPORT DoorGoDown( void );
void EXPORT DoorHitTop( void );
void EXPORT DoorHitBottom( void );
8 years ago
BYTE m_bHealthValue;// some doors are medi-kit doors, they give players health
BYTE m_bMoveSnd; // sound a door makes while moving
BYTE m_bStopSnd; // sound a door makes when it stops
7 years ago
locksound_t m_ls; // door lock sounds
8 years ago
BYTE m_bLockedSound; // ordinals from entity selection
BYTE m_bLockedSentence;
BYTE m_bUnlockedSound;
BYTE m_bUnlockedSentence;
7 years ago
BOOL m_iOnOffMode;
BOOL m_iImmediateMode;
BOOL m_iDirectUse;
};
TYPEDESCRIPTION CBaseDoor::m_SaveData[] =
7 years ago
{
DEFINE_FIELD( CBaseDoor, m_bHealthValue, FIELD_CHARACTER ),
DEFINE_FIELD( CBaseDoor, m_bMoveSnd, FIELD_CHARACTER ),
DEFINE_FIELD( CBaseDoor, m_bStopSnd, FIELD_CHARACTER ),
8 years ago
7 years ago
DEFINE_FIELD( CBaseDoor, m_bLockedSound, FIELD_CHARACTER ),
DEFINE_FIELD( CBaseDoor, m_bLockedSentence, FIELD_CHARACTER ),
8 years ago
DEFINE_FIELD( CBaseDoor, m_bUnlockedSound, FIELD_CHARACTER ),
DEFINE_FIELD( CBaseDoor, m_bUnlockedSentence, FIELD_CHARACTER ),
7 years ago
DEFINE_FIELD( CBaseDoor, m_iOnOffMode, FIELD_BOOLEAN ),
DEFINE_FIELD( CBaseDoor, m_iImmediateMode, FIELD_BOOLEAN ),
DEFINE_FIELD( CBaseDoor, m_iDirectUse, FIELD_BOOLEAN ),
};
IMPLEMENT_SAVERESTORE( CBaseDoor, CBaseToggle )
7 years ago
#define DOOR_SENTENCEWAIT 6.0f
#define DOOR_SOUNDWAIT 3.0f
#define BUTTON_SOUNDWAIT 0.5f
7 years ago
// play door or button locked or unlocked sounds.
// pass in pointer to valid locksound struct.
// if flocked is true, play 'door is locked' sound,
// otherwise play 'door is unlocked' sound
// NOTE: this routine is shared by doors and buttons
8 years ago
void PlayLockSounds( entvars_t *pev, locksound_t *pls, int flocked, int fbutton )
7 years ago
{
// LOCKED SOUND
8 years ago
7 years ago
// CONSIDER: consolidate the locksound_t struct (all entries are duplicates for lock/unlock)
// CONSIDER: and condense this code.
float flsoundwait;
8 years ago
if( fbutton )
7 years ago
flsoundwait = BUTTON_SOUNDWAIT;
else
flsoundwait = DOOR_SOUNDWAIT;
8 years ago
if( flocked )
7 years ago
{
8 years ago
int fplaysound = ( pls->sLockedSound && gpGlobals->time > pls->flwaitSound );
int fplaysentence = ( pls->sLockedSentence && !pls->bEOFLocked && gpGlobals->time > pls->flwaitSentence );
7 years ago
float fvol;
8 years ago
if( fplaysound && fplaysentence )
fvol = 0.25f;
7 years ago
else
fvol = 1.0f;
7 years ago
// if there is a locked sound, and we've debounced, play sound
8 years ago
if( fplaysound )
7 years ago
{
// play 'door locked' sound
EMIT_SOUND( ENT( pev ), CHAN_ITEM, STRING( pls->sLockedSound ), fvol, ATTN_NORM );
7 years ago
pls->flwaitSound = gpGlobals->time + flsoundwait;
}
// if there is a sentence, we've not played all in list, and we've debounced, play sound
8 years ago
if( fplaysentence )
7 years ago
{
// play next 'door locked' sentence in group
int iprev = pls->iLockedSentence;
8 years ago
pls->iLockedSentence = SENTENCEG_PlaySequentialSz( ENT( pev ), STRING( pls->sLockedSentence ),
0.85f, ATTN_NORM, 0, 100, pls->iLockedSentence, FALSE );
7 years ago
pls->iUnlockedSentence = 0;
// make sure we don't keep calling last sentence in list
8 years ago
pls->bEOFLocked = ( iprev == pls->iLockedSentence );
7 years ago
pls->flwaitSentence = gpGlobals->time + DOOR_SENTENCEWAIT;
}
}
else
{
// UNLOCKED SOUND
8 years ago
int fplaysound = ( pls->sUnlockedSound && gpGlobals->time > pls->flwaitSound );
int fplaysentence = ( pls->sUnlockedSentence && !pls->bEOFUnlocked && gpGlobals->time > pls->flwaitSentence );
7 years ago
float fvol;
// if playing both sentence and sound, lower sound volume so we hear sentence
8 years ago
if( fplaysound && fplaysentence )
fvol = 0.25f;
7 years ago
else
fvol = 1.0f;
7 years ago
// play 'door unlocked' sound if set
8 years ago
if( fplaysound )
7 years ago
{
EMIT_SOUND( ENT( pev ), CHAN_ITEM, STRING( pls->sUnlockedSound ), fvol, ATTN_NORM );
7 years ago
pls->flwaitSound = gpGlobals->time + flsoundwait;
}
// play next 'door unlocked' sentence in group
8 years ago
if( fplaysentence )
7 years ago
{
int iprev = pls->iUnlockedSentence;
8 years ago
pls->iUnlockedSentence = SENTENCEG_PlaySequentialSz( ENT( pev ), STRING( pls->sUnlockedSentence ),
0.85f, ATTN_NORM, 0, 100, pls->iUnlockedSentence, FALSE );
7 years ago
pls->iLockedSentence = 0;
// make sure we don't keep calling last sentence in list
8 years ago
pls->bEOFUnlocked = ( iprev == pls->iUnlockedSentence );
7 years ago
pls->flwaitSentence = gpGlobals->time + DOOR_SENTENCEWAIT;
}
}
}
//
// Cache user-entity-field values until spawn is called.
//
void CBaseDoor::KeyValue( KeyValueData *pkvd )
{
8 years ago
if( FStrEq( pkvd->szKeyName, "skin" ) )//skin is used for content type
7 years ago
{
pev->skin = atoi( pkvd->szValue );
7 years ago
pkvd->fHandled = TRUE;
}
8 years ago
else if( FStrEq( pkvd->szKeyName, "movesnd" ) )
7 years ago
{
m_bMoveSnd = atoi( pkvd->szValue );
7 years ago
pkvd->fHandled = TRUE;
}
8 years ago
else if( FStrEq( pkvd->szKeyName, "stopsnd" ) )
7 years ago
{
m_bStopSnd = atoi( pkvd->szValue );
7 years ago
pkvd->fHandled = TRUE;
}
8 years ago
else if( FStrEq( pkvd->szKeyName, "healthvalue" ) )
7 years ago
{
m_bHealthValue = atoi( pkvd->szValue );
7 years ago
pkvd->fHandled = TRUE;
}
8 years ago
else if( FStrEq( pkvd->szKeyName, "locked_sound" ) )
7 years ago
{
m_bLockedSound = atoi( pkvd->szValue );
7 years ago
pkvd->fHandled = TRUE;
}
8 years ago
else if( FStrEq( pkvd->szKeyName, "locked_sentence" ) )
7 years ago
{
m_bLockedSentence = atoi( pkvd->szValue );
7 years ago
pkvd->fHandled = TRUE;
}
8 years ago
else if( FStrEq( pkvd->szKeyName, "unlocked_sound" ) )
7 years ago
{
m_bUnlockedSound = atoi( pkvd->szValue );
7 years ago
pkvd->fHandled = TRUE;
}
8 years ago
else if( FStrEq( pkvd->szKeyName, "unlocked_sentence" ) )
7 years ago
{
m_bUnlockedSentence = atoi(pkvd->szValue);
7 years ago
pkvd->fHandled = TRUE;
}
else if (FStrEq(pkvd->szKeyName, "immediatemode"))
{
m_iImmediateMode = atoi(pkvd->szValue);
pkvd->fHandled = TRUE;
}
else if (FStrEq(pkvd->szKeyName, "onoffmode"))
{
m_iOnOffMode = atoi(pkvd->szValue);
pkvd->fHandled = TRUE;
}
else if (FStrEq(pkvd->szKeyName, "directuse"))
{
m_iDirectUse = atoi(pkvd->szValue);
pkvd->fHandled = TRUE;
}
8 years ago
else if( FStrEq( pkvd->szKeyName, "WaveHeight" ) )
7 years ago
{
pev->scale = atof( pkvd->szValue ) * ( 1.0f / 8.0f );
7 years ago
pkvd->fHandled = TRUE;
}
else
CBaseToggle::KeyValue( pkvd );
}
/*QUAKED func_door (0 .5 .8) ? START_OPEN x DOOR_DONT_LINK TOGGLE
if two doors touch, they are assumed to be connected and operate as a unit.
TOGGLE causes the door to wait in both the start and end states for a trigger event.
START_OPEN causes the door to move to its destination when spawned, and operate in reverse.
It is used to temporarily or permanently close off an area when triggered (not usefull for
touch or takedamage doors).
"angle" determines the opening direction
"targetname" if set, no touch field will be spawned and a remote button or trigger
field activates the door.
"health" if set, door must be shot open
"speed" movement speed (100 default)
"wait" wait before returning (3 default, -1 = never return)
"lip" lip remaining at end of move (8 default)
"dmg" damage to inflict when blocked (2 default)
"sounds"
0) no sound
1) stone
2) base
3) stone chain
4) screechy metal
*/
LINK_ENTITY_TO_CLASS( func_door, CBaseDoor )
7 years ago
//
// func_water - same as a door.
//
LINK_ENTITY_TO_CLASS( func_water, CBaseDoor )
7 years ago
//MH this new spawn function messes up SF_DOOR_START_OPEN
// so replace it with the old one (below)
/*
8 years ago
void CBaseDoor::Spawn()
7 years ago
{
Precache();
8 years ago
SetMovedir( pev );
7 years ago
8 years ago
if( pev->skin == 0 )
{
//normal door
8 years ago
if( FBitSet( pev->spawnflags, SF_DOOR_PASSABLE ) )
pev->solid = SOLID_NOT;
7 years ago
else
8 years ago
pev->solid = SOLID_BSP;
7 years ago
}
else
{
// special contents
8 years ago
pev->solid = SOLID_NOT;
7 years ago
SetBits( pev->spawnflags, SF_DOOR_SILENT ); // water is silent for now
}
8 years ago
pev->movetype = MOVETYPE_PUSH;
SET_MODEL( ENT( pev ), STRING( pev->model ) );
7 years ago
UTIL_SetOrigin(this, pev->origin);
8 years ago
if( pev->speed == 0.0f )
pev->speed = 100.0f;
8 years ago
m_vecPosition1 = pev->origin;
7 years ago
// Subtract 2 from size because the engine expands bboxes by 1 in all directions making the size too big
m_vecPosition2 = m_vecPosition1 + ( pev->movedir * ( fabs( pev->movedir.x * ( pev->size.x - 2.0f ) ) + fabs( pev->movedir.y * ( pev->size.y - 2.0f ) ) + fabs( pev->movedir.z * ( pev->size.z - 2.0f ) ) - m_flLip ) );
8 years ago
ASSERTSZ( m_vecPosition1 != m_vecPosition2, "door start/end positions are equal" );
if( FBitSet( pev->spawnflags, SF_DOOR_START_OPEN ) )
{
// swap pos1 and pos2, put door at pos2
8 years ago
UTIL_SetOrigin( pev, m_vecPosition2 );
7 years ago
m_vecPosition2 = m_vecPosition1;
m_vecPosition1 = pev->origin;
}
m_toggle_state = TS_AT_BOTTOM;
8 years ago
7 years ago
// if the door is flagged for USE button activation only, use NULL touch function
// (unless it's overridden, of course- LRC)
if ( FBitSet ( pev->spawnflags, SF_DOOR_USE_ONLY ) &&
!FBitSet ( pev->spawnflags, SF_DOOR_FORCETOUCHABLE ))
{
SetTouch ( NULL );
}
else // touchable button
SetTouch(&CBaseDoor:: DoorTouch );
}
*/
//standard Spirit 1.0 spawn function
void CBaseDoor::Spawn( )
{
Precache();
SetMovedir (pev);
if ( pev->skin == 0 )
{//normal door
if ( FBitSet (pev->spawnflags, SF_DOOR_PASSABLE) )
pev->solid = SOLID_NOT;
else
pev->solid = SOLID_BSP;
}
else
{// special contents
pev->solid = SOLID_NOT;
SetBits( pev->spawnflags, SF_DOOR_SILENT ); // water is silent for now
}
pev->movetype = MOVETYPE_PUSH;
SET_MODEL( ENT(pev), STRING(pev->model) );
UTIL_SetOrigin(this, pev->origin);
if (pev->speed == 0)
pev->speed = 100;
m_toggle_state = TS_AT_BOTTOM;
// if the door is flagged for USE button activation only, use NULL touch function
// (unless it's overridden, of course- LRC)
if ( FBitSet ( pev->spawnflags, SF_DOOR_USE_ONLY ) &&
!FBitSet ( pev->spawnflags, SF_DOOR_FORCETOUCHABLE ))
{
9 years ago
SetTouch( NULL );
7 years ago
}
else // touchable button
SetTouch( &CBaseDoor::DoorTouch );
}
//END
//LRC
void CBaseDoor :: PostSpawn( void )
{
if (m_pMoveWith)
m_vecPosition1 = pev->origin - m_pMoveWith->pev->origin;
else
m_vecPosition1 = pev->origin;
// Subtract 2 from size because the engine expands bboxes by 1 in all directions
m_vecPosition2 = m_vecPosition1 + (pev->movedir * (fabs( pev->movedir.x * (pev->size.x-2) ) + fabs( pev->movedir.y * (pev->size.y-2) ) + fabs( pev->movedir.z * (pev->size.z-2) ) - m_flLip));
ASSERTSZ(m_vecPosition1 != m_vecPosition2, "door start/end positions are equal");
if ( FBitSet (pev->spawnflags, SF_DOOR_START_OPEN) )
{ // swap pos1 and pos2, put door at pos2
if (m_pMoveWith)
{
m_vecSpawnOffset = m_vecSpawnOffset + (m_vecPosition2 + m_pMoveWith->pev->origin) - pev->origin;
UTIL_AssignOrigin(this, m_vecPosition2 + m_pMoveWith->pev->origin);
}
else
{
m_vecSpawnOffset = m_vecSpawnOffset + m_vecPosition2 - pev->origin;
UTIL_AssignOrigin(this, m_vecPosition2);
}
Vector vecTemp = m_vecPosition2;
m_vecPosition2 = m_vecPosition1;
m_vecPosition1 = vecTemp;
// ALERT(at_console, "func_door postspawn: origin %f %f %f\n", pev->origin.x, pev->origin.y, pev->origin.z);
}
}
//void CBaseDoor :: PostMoveWith( void )
//{
// Vector vecTemp = m_vecPosition1 - m_pMoveWith->m_vecSpawnOffset;
// ALERT(at_console, "door %s pmw: pos1 changes from (%f %f %f) to (%f %f %f)\n", STRING(pev->targetname), m_vecPosition1.x, m_vecPosition1.y, m_vecPosition1.z, vecTemp.x, vecTemp.y, vecTemp.z);
// m_vecPosition1 = m_vecPosition1 - m_pMoveWith->m_vecSpawnOffset;
// m_vecPosition2 = m_vecPosition2 - m_pMoveWith->m_vecSpawnOffset;
//}
9 years ago
8 years ago
void CBaseDoor::SetToggleState( int state )
7 years ago
{
8 years ago
if( state == TS_AT_TOP )
7 years ago
{
if (m_pMoveWith)
UTIL_AssignOrigin( this, m_vecPosition2 + m_pMoveWith->pev->origin);
else
UTIL_AssignOrigin( this, m_vecPosition2 );
}
else
{
if (m_pMoveWith)
UTIL_AssignOrigin( this, m_vecPosition1 + m_pMoveWith->pev->origin);
9 years ago
else
7 years ago
UTIL_AssignOrigin( this, m_vecPosition1 );
}
}
void CBaseDoor::Precache( void )
{
const char *pszSound;
BOOL NullSound = FALSE;
7 years ago
// set the door's "in-motion" sound
8 years ago
switch( m_bMoveSnd )
7 years ago
{
8 years ago
case 1:
pszSound = "doors/doormove1.wav";
8 years ago
break;
case 2:
pszSound = "doors/doormove2.wav";
8 years ago
break;
case 3:
pszSound = "doors/doormove3.wav";
8 years ago
break;
case 4:
pszSound = "doors/doormove4.wav";
8 years ago
break;
case 5:
pszSound = "doors/doormove5.wav";
8 years ago
break;
case 6:
pszSound = "doors/doormove6.wav";
8 years ago
break;
case 7:
pszSound = "doors/doormove7.wav";
8 years ago
break;
case 8:
pszSound = "doors/doormove8.wav";
8 years ago
break;
case 9:
pszSound = "doors/doormove9.wav";
8 years ago
break;
case 10:
pszSound = "doors/doormove10.wav";
8 years ago
break;
case 0:
8 years ago
default:
pszSound = "common/null.wav";
NullSound = TRUE;
8 years ago
break;
7 years ago
}
if( !NullSound )
PRECACHE_SOUND( pszSound );
pev->noiseMoving = MAKE_STRING( pszSound );
NullSound = FALSE;
// set the door's 'reached destination' stop sound
8 years ago
switch( m_bStopSnd )
7 years ago
{
8 years ago
case 1:
pszSound = "doors/doorstop1.wav";
8 years ago
break;
case 2:
pszSound = "doors/doorstop2.wav";
8 years ago
break;
case 3:
pszSound = "doors/doorstop3.wav";
8 years ago
break;
case 4:
pszSound = "doors/doorstop4.wav";
8 years ago
break;
case 5:
pszSound = "doors/doorstop5.wav";
8 years ago
break;
case 6:
pszSound = "doors/doorstop6.wav";
8 years ago
break;
case 7:
pszSound = "doors/doorstop7.wav";
8 years ago
break;
case 8:
pszSound = "doors/doorstop8.wav";
8 years ago
break;
case 0:
8 years ago
default:
pszSound = "common/null.wav";
NullSound = TRUE;
8 years ago
break;
7 years ago
}
if( !NullSound )
PRECACHE_SOUND( pszSound );
pev->noiseArrived = MAKE_STRING( pszSound );
7 years ago
9 years ago
// get door button sounds, for doors which are directly 'touched' to open
8 years ago
if( m_bLockedSound )
7 years ago
{
pszSound = ButtonSound( (int)m_bLockedSound );
8 years ago
PRECACHE_SOUND( pszSound );
m_ls.sLockedSound = MAKE_STRING( pszSound );
7 years ago
}
8 years ago
if( m_bUnlockedSound )
7 years ago
{
pszSound = ButtonSound( (int)m_bUnlockedSound );
8 years ago
PRECACHE_SOUND( pszSound );
m_ls.sUnlockedSound = MAKE_STRING( pszSound );
7 years ago
}
// get sentence group names, for doors which are directly 'touched' to open
8 years ago
switch( m_bLockedSentence )
7 years ago
{
8 years ago
case 1:
// access denied
m_ls.sLockedSentence = MAKE_STRING( "NA" );
8 years ago
break;
case 2:
// security lockout
m_ls.sLockedSentence = MAKE_STRING( "ND" );
8 years ago
break;
case 3:
// blast door
m_ls.sLockedSentence = MAKE_STRING( "NF" );
8 years ago
break;
case 4:
// fire door
m_ls.sLockedSentence = MAKE_STRING( "NFIRE" );
8 years ago
break;
case 5:
// chemical door
m_ls.sLockedSentence = MAKE_STRING( "NCHEM" );
8 years ago
break;
case 6:
// radiation door
m_ls.sLockedSentence = MAKE_STRING( "NRAD" );
8 years ago
break;
case 7:
// gen containment
m_ls.sLockedSentence = MAKE_STRING( "NCON" );
8 years ago
break;
case 8:
// maintenance door
m_ls.sLockedSentence = MAKE_STRING( "NH" );
8 years ago
break;
case 9:
// broken door
m_ls.sLockedSentence = MAKE_STRING( "NG" );
8 years ago
break;
default:
m_ls.sLockedSentence = 0;
break;
7 years ago
}
8 years ago
switch( m_bUnlockedSentence )
7 years ago
{
8 years ago
case 1:
// access granted
m_ls.sUnlockedSentence = MAKE_STRING( "EA" );
8 years ago
break;
case 2:
// security door
m_ls.sUnlockedSentence = MAKE_STRING( "ED" );
8 years ago
break;
case 3:
// blast door
m_ls.sUnlockedSentence = MAKE_STRING( "EF" );
8 years ago
break;
case 4:
// fire door
m_ls.sUnlockedSentence = MAKE_STRING( "EFIRE" );
8 years ago
break;
case 5:
// chemical door
m_ls.sUnlockedSentence = MAKE_STRING( "ECHEM" );
8 years ago
break;
case 6:
// radiation door
m_ls.sUnlockedSentence = MAKE_STRING( "ERAD" );
8 years ago
break;
case 7:
// gen containment
m_ls.sUnlockedSentence = MAKE_STRING( "ECON" );
8 years ago
break;
case 8:
// maintenance door
m_ls.sUnlockedSentence = MAKE_STRING( "EH" );
8 years ago
break;
default:
m_ls.sUnlockedSentence = 0;
break;
7 years ago
}
}
//
// Doors not tied to anything (e.g. button, another door) can be touched, to make them activate.
//
void CBaseDoor::DoorTouch( CBaseEntity *pOther )
{
// Ignore touches by anything but players
if( !pOther->IsPlayer() )
7 years ago
return;
// If door has master, and it's not ready to trigger,
// play 'locked' sound
8 years ago
if( m_sMaster && !UTIL_IsMasterTriggered( m_sMaster, pOther ) )
PlayLockSounds( pev, &m_ls, TRUE, FALSE );
7 years ago
// If door is somebody's target, then touching does nothing.
// You have to activate the owner (e.g. button).
//LRC- allow flags to override this
if (!FStringNull(pev->targetname) && !FBitSet(pev->spawnflags,SF_DOOR_FORCETOUCHABLE))
{
// play locked sound
8 years ago
PlayLockSounds( pev, &m_ls, TRUE, FALSE );
7 years ago
return;
}
8 years ago
7 years ago
m_hActivator = pOther;// remember who activated the door
if( DoorActivate() )
7 years ago
SetTouch( NULL ); // Temporarily disable the touch function, until movement is finished.
}
//
// Used by SUB_UseTargets, when a door is the target of a button.
//
void CBaseDoor::Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value )
{
m_hActivator = pActivator;
if (!UTIL_IsMasterTriggered(m_sMaster, pActivator))
return;
//LRC:
if (m_iOnOffMode)
{
if (useType == USE_ON)
{
if (m_toggle_state == TS_AT_BOTTOM)
{
PlayLockSounds(pev, &m_ls, FALSE, FALSE);
DoorGoUp();
}
return;
}
else if (useType == USE_OFF)
{
if (m_toggle_state == TS_AT_TOP)
{
DoorGoDown();
}
return;
}
}
// if not ready to be used, ignore "use" command.
if (m_toggle_state == TS_AT_TOP)
{
if (!FBitSet(pev->spawnflags, SF_DOOR_NO_AUTO_RETURN))
return;
}
else if (m_toggle_state != TS_AT_BOTTOM)
return;
DoorActivate();
}
//
// Causes the door to "do its thing", i.e. start moving, and cascade activation.
//
8 years ago
int CBaseDoor::DoorActivate()
7 years ago
{
8 years ago
if( !UTIL_IsMasterTriggered( m_sMaster, m_hActivator ) )
7 years ago
return 0;
8 years ago
if( FBitSet( pev->spawnflags, SF_DOOR_NO_AUTO_RETURN ) && m_toggle_state == TS_AT_TOP )
{
// door should close
7 years ago
DoorGoDown();
}
else
{
// door should open
if( m_hActivator != 0 && m_hActivator->IsPlayer() )
{
// give health if player opened the door (medikit)
//VARS( m_eoActivator )->health += m_bHealthValue;
7 years ago
m_hActivator->TakeHealth( m_bHealthValue, DMG_GENERIC );
}
// play door unlock sounds
8 years ago
PlayLockSounds( pev, &m_ls, FALSE, FALSE );
7 years ago
DoorGoUp();
}
return 1;
}
extern Vector VecBModelOrigin( entvars_t* pevBModel );
//
// Starts the door going to its "up" position (simply ToggleData->vecPosition2).
//
void CBaseDoor::DoorGoUp( void )
{
8 years ago
entvars_t *pevActivator;
7 years ago
// It could be going-down, if blocked.
8 years ago
ASSERT( m_toggle_state == TS_AT_BOTTOM || m_toggle_state == TS_GOING_DOWN );
7 years ago
// emit door moving and stop sounds on CHAN_STATIC so that the multicast doesn't
// filter them out and leave a client stuck with looping door sounds!
8 years ago
if( !FBitSet( pev->spawnflags, SF_DOOR_SILENT ) )
if( m_toggle_state != TS_GOING_UP && m_toggle_state != TS_GOING_DOWN )
EMIT_SOUND( ENT( pev ), CHAN_STATIC, STRING( pev->noiseMoving ), 1, ATTN_NORM );
7 years ago
m_toggle_state = TS_GOING_UP;
8 years ago
9 years ago
SetMoveDone( &CBaseDoor::DoorHitTop );
7 years ago
// LRC- if synched, we fire as soon as we start to go up
if (m_iImmediateMode)
{
if (m_iOnOffMode)
SUB_UseTargets( m_hActivator, USE_ON, 0 );
else
SUB_UseTargets( m_hActivator, USE_TOGGLE, 0 );
}
8 years ago
if( FClassnameIs( pev, "func_door_rotating" ) ) // !!! BUGBUG Triggered doors don't work with this yet
7 years ago
{
float sign = 1.0f;
7 years ago
if( m_hActivator != 0 )
7 years ago
{
pevActivator = m_hActivator->pev;
8 years ago
if( !FBitSet( pev->spawnflags, SF_DOOR_ONEWAY ) && pev->movedir.y ) // Y axis rotation, move away from the player
7 years ago
{
Vector vec = pevActivator->origin - pev->origin;
Vector angles = pevActivator->angles;
angles.x = 0.0f;
angles.z = 0.0f;
8 years ago
UTIL_MakeVectors( angles );
//Vector vnext = ( pevToucher->origin + ( pevToucher->velocity * 10.f ) ) - pev->origin;
8 years ago
UTIL_MakeVectors( pevActivator->angles );
Vector vnext = ( pevActivator->origin + ( gpGlobals->v_forward * 10.f ) ) - pev->origin;
if( ( vec.x * vnext.y - vec.y * vnext.x ) < 0.0f )
sign = -1.0f;
7 years ago
}
}
8 years ago
AngularMove( m_vecAngle2*sign, pev->speed );
7 years ago
}
else
8 years ago
LinearMove( m_vecPosition2, pev->speed );
7 years ago
}
//
// The door has reached the "up" position. Either go back down, or wait for another activation.
//
void CBaseDoor::DoorHitTop( void )
{
8 years ago
if( !FBitSet( pev->spawnflags, SF_DOOR_SILENT ) )
7 years ago
{
STOP_SOUND( ENT( pev ), CHAN_STATIC, STRING( pev->noiseMoving ) );
EMIT_SOUND( ENT( pev ), CHAN_STATIC, STRING( pev->noiseArrived ), 1.0f, ATTN_NORM );
7 years ago
}
8 years ago
ASSERT( m_toggle_state == TS_GOING_UP );
7 years ago
m_toggle_state = TS_AT_TOP;
8 years ago
7 years ago
// toggle-doors don't come down automatically, they wait for refire.
8 years ago
if( FBitSet( pev->spawnflags, SF_DOOR_NO_AUTO_RETURN ) )
7 years ago
{
// Re-instate touch method, movement is complete
if ( !FBitSet ( pev->spawnflags, SF_DOOR_USE_ONLY ) ||
FBitSet ( pev->spawnflags, SF_DOOR_FORCETOUCHABLE ) )
9 years ago
SetTouch( &CBaseDoor::DoorTouch );
7 years ago
}
else
{
// In flWait seconds, DoorGoDown will fire, unless wait is -1, then door stays open
SetNextThink( m_flWait );
9 years ago
SetThink( &CBaseDoor::DoorGoDown );
7 years ago
if( m_flWait == -1.0f )
7 years ago
{
DontThink();
}
}
// Fire the close target (if startopen is set, then "top" is closed) - netname is the close target
if (pev->spawnflags & SF_DOOR_START_OPEN)
{
if (pev->netname)
8 years ago
FireTargets( STRING( pev->netname ), m_hActivator, this, USE_TOGGLE, 0 );
7 years ago
}
else
{
if (pev->message)
FireTargets( STRING(pev->message), m_hActivator, this, USE_TOGGLE, 0 );
}
// LRC
if (!m_iImmediateMode)
{
if (m_iOnOffMode)
SUB_UseTargets( m_hActivator, USE_OFF, 0 );
else
SUB_UseTargets( m_hActivator, USE_TOGGLE, 0 );
}
}
//
// Starts the door going to its "down" position (simply ToggleData->vecPosition1).
//
void CBaseDoor::DoorGoDown( void )
{
8 years ago
if( !FBitSet( pev->spawnflags, SF_DOOR_SILENT ) )
7 years ago
if( m_toggle_state != TS_GOING_UP && m_toggle_state != TS_GOING_DOWN )
EMIT_SOUND( ENT( pev ), CHAN_STATIC, STRING( pev->noiseMoving ), 1.0f, ATTN_NORM );
4 years ago
#if DOOR_ASSERT
8 years ago
ASSERT( m_toggle_state == TS_AT_TOP );
7 years ago
#endif // DOOR_ASSERT
m_toggle_state = TS_GOING_DOWN;
9 years ago
SetMoveDone( &CBaseDoor::DoorHitBottom );
8 years ago
if( FClassnameIs( pev, "func_door_rotating" ) )//rotating door
7 years ago
{
// LRC- if synched, we fire as soon as we start to go down
if (m_iImmediateMode)
{
if (m_iOnOffMode)
SUB_UseTargets( m_hActivator, USE_OFF, 0 );
else
SUB_UseTargets( m_hActivator, USE_TOGGLE, 0 );
}
8 years ago
AngularMove( m_vecAngle1, pev->speed );
7 years ago
}
else
{
// LRC- if synched, we fire as soon as we start to go down
if (m_iImmediateMode)
{
SUB_UseTargets( m_hActivator, USE_OFF, 0 );
}
8 years ago
LinearMove( m_vecPosition1, pev->speed );
9 years ago
}
7 years ago
}
//
// The door has reached the "down" position. Back to quiescence.
//
void CBaseDoor::DoorHitBottom( void )
{
8 years ago
if( !FBitSet( pev->spawnflags, SF_DOOR_SILENT ) )
7 years ago
{
STOP_SOUND( ENT( pev ), CHAN_STATIC, STRING( pev->noiseMoving ) );
EMIT_SOUND( ENT( pev ), CHAN_STATIC, STRING( pev->noiseArrived ), 1.0f, ATTN_NORM );
7 years ago
}
8 years ago
ASSERT( m_toggle_state == TS_GOING_DOWN );
7 years ago
m_toggle_state = TS_AT_BOTTOM;
// Re-instate touch method, cycle is complete
if ( FBitSet ( pev->spawnflags, SF_DOOR_USE_ONLY ) &&
!FBitSet ( pev->spawnflags, SF_DOOR_FORCETOUCHABLE ) )
{// use only door
9 years ago
SetTouch( NULL );
7 years ago
}
else // touchable door
9 years ago
SetTouch( &CBaseDoor::DoorTouch );
7 years ago
// Fire the close target (if startopen is set, then "top" is closed) - netname is the close target
// LRC- 'message' is the open target
if (pev->spawnflags & SF_DOOR_START_OPEN)
{
if (pev->message)
FireTargets( STRING(pev->message), m_hActivator, this, USE_TOGGLE, 0 );
}
else
{
if (pev->netname)
8 years ago
FireTargets( STRING( pev->netname ), m_hActivator, this, USE_TOGGLE, 0 );
9 years ago
}
7 years ago
// else
// {
// ALERT(at_console,"didn't fire closetarget because ");
// if (!(pev->netname))
// ALERT(at_console,"no netname\n");
// else if (pev->spawnflags & SF_DOOR_START_OPEN)
// ALERT(at_console,"startopen\n");
// else
// ALERT(at_console,"!!?!\n");
// }
// LRC- if synched, don't fire now
if (!m_iImmediateMode)
{
if (m_iOnOffMode)
SUB_UseTargets( m_hActivator, USE_ON, 0 );
else
SUB_UseTargets( m_hActivator, USE_TOGGLE, 0 );
}
}
void CBaseDoor::Blocked( CBaseEntity *pOther )
{
CBaseEntity *pTarget = NULL;
CBaseDoor *pDoor = NULL;
7 years ago
// Hurt the blocker a little.
8 years ago
if( pev->dmg )
7 years ago
pOther->TakeDamage( pev, pev, pev->dmg, DMG_CRUSH );
if( satchelfix.value )
{
// Detonate satchels
if( !strcmp( "monster_satchel", STRING( pOther->pev->classname ) ) )
( (CSatchel*)pOther )->Use( this, this, USE_ON, 0 );
}
7 years ago
// if a door has a negative wait, it would never come back if blocked,
// so let it just squash the object to death real fast
if( m_flWait >= 0.0f )
7 years ago
{
//LRC - thanks to [insert name here] for this
if( !FBitSet( pev->spawnflags, SF_DOOR_SILENT ) )
STOP_SOUND( ENT( pev ), CHAN_STATIC, STRING( pev->noiseMoving ) ); // BMod End
8 years ago
if( m_toggle_state == TS_GOING_DOWN )
7 years ago
{
DoorGoUp();
}
else
{
DoorGoDown();
}
}
// Block all door pieces with the same targetname here.
//LRC - in immediate mode don't do this, doors are expected to do it themselves.
if ( !m_iImmediateMode && !FStringNull ( pev->targetname ) )
{
for( ; ; )
7 years ago
{
pTarget = UTIL_FindEntityByTargetname(pTarget, STRING(pev->targetname));
if ( !pTarget )
9 years ago
break;
7 years ago
if ( ( VARS( pTarget->pev ) != pev && FClassnameIs( pTarget->pev, "func_door" ) ) ||
FClassnameIs( pTarget->pev, "func_door_rotating" ) )
{
pDoor = GetClassPtr( (CBaseDoor *)VARS( pTarget->pev ) );
if( pDoor->m_flWait >= 0.0f )
7 years ago
{
// avelocity == velocity!? LRC
8 years ago
if( pDoor->pev->velocity == pev->velocity && pDoor->pev->avelocity == pev->velocity )
9 years ago
{
// this is the most hacked, evil, bastardized thing I've ever seen. kjb
7 years ago
if ( FClassnameIs ( pTarget->pev, "func_door" ) )
{// set origin to realign normal doors
9 years ago
pDoor->pev->origin = pev->origin;
7 years ago
UTIL_SetVelocity(pDoor, g_vecZero);// stop!
9 years ago
}
else
8 years ago
{
// set angles to realign rotating doors
9 years ago
pDoor->pev->angles = pev->angles;
7 years ago
UTIL_SetAvelocity(pDoor, g_vecZero);
9 years ago
}
7 years ago
}
8 years ago
if( !FBitSet( pev->spawnflags, SF_DOOR_SILENT ) )
STOP_SOUND( ENT( pev ), CHAN_STATIC, STRING( pev->noiseMoving ) );
7 years ago
8 years ago
if( pDoor->m_toggle_state == TS_GOING_DOWN )
9 years ago
pDoor->DoorGoUp();
else
pDoor->DoorGoDown();
}
7 years ago
}
}
}
}
/*QUAKED FuncRotDoorSpawn (0 .5 .8) ? START_OPEN REVERSE
DOOR_DONT_LINK TOGGLE X_AXIS Y_AXIS
if two doors touch, they are assumed to be connected and operate as
a unit.
TOGGLE causes the door to wait in both the start and end states for
a trigger event.
START_OPEN causes the door to move to its destination when spawned,
and operate in reverse. It is used to temporarily or permanently
close off an area when triggered (not usefull for touch or
takedamage doors).
You need to have an origin brush as part of this entity. The
center of that brush will be
the point around which it is rotated. It will rotate around the Z
axis by default. You can
check either the X_AXIS or Y_AXIS box to change that.
"distance" is how many degrees the door will be rotated.
"speed" determines how fast the door moves; default value is 100.
REVERSE will cause the door to rotate in the opposite direction.
"angle" determines the opening direction
"targetname" if set, no touch field will be spawned and a remote
button or trigger field activates the door.
"health" if set, door must be shot open
"speed" movement speed (100 default)
"wait" wait before returning (3 default, -1 = never return)
"dmg" damage to inflict when blocked (2 default)
"sounds"
0) no sound
1) stone
2) base
3) stone chain
4) screechy metal
*/
7 years ago
class CRotDoor : public CBaseDoor
{
public:
void Spawn( void );
void KeyValue( KeyValueData *pkvd );
virtual void PostSpawn( void ) {} // don't use the moveWith fix from CBaseDoor
virtual void SetToggleState( int state );
};
LINK_ENTITY_TO_CLASS( func_door_rotating, CRotDoor )
7 years ago
void CRotDoor::Spawn( void )
{
Precache();
// set the axis of rotation
CBaseToggle::AxisDir( pev );
// check for clockwise rotation
8 years ago
if( FBitSet( pev->spawnflags, SF_DOOR_ROTATE_BACKWARDS ) )
pev->movedir = pev->movedir * -1.0f;
8 years ago
//m_flWait = 2; who the hell did this? (sjb)
m_vecAngle1 = pev->angles;
m_vecAngle2 = pev->angles + pev->movedir * m_flMoveDistance;
7 years ago
8 years ago
ASSERTSZ( m_vecAngle1 != m_vecAngle2, "rotating door start/end positions are equal" );
if( FBitSet( pev->spawnflags, SF_DOOR_PASSABLE ) )
pev->solid = SOLID_NOT;
7 years ago
else
8 years ago
pev->solid = SOLID_BSP;
7 years ago
8 years ago
pev->movetype = MOVETYPE_PUSH;
7 years ago
UTIL_SetOrigin(this, pev->origin);
8 years ago
SET_MODEL( ENT( pev ), STRING( pev->model ) );
7 years ago
if( pev->speed == 0.0f )
pev->speed = 100.0f;
8 years ago
// DOOR_START_OPEN is to allow an entity to be lighted in the closed position
// but spawn in the open position
8 years ago
if( FBitSet( pev->spawnflags, SF_DOOR_START_OPEN ) )
{
// swap pos1 and pos2, put door at pos2, invert movement direction
7 years ago
pev->angles = m_vecAngle2;
Vector vecSav = m_vecAngle1;
m_vecAngle2 = m_vecAngle1;
m_vecAngle1 = vecSav;
pev->movedir = pev->movedir * -1.0f;
7 years ago
}
m_toggle_state = TS_AT_BOTTOM;
if ( FBitSet ( pev->spawnflags, SF_DOOR_USE_ONLY ) && !FBitSet(pev->spawnflags, SF_DOOR_FORCETOUCHABLE) )
{
9 years ago
SetTouch( NULL );
7 years ago
}
else // touchable button
SetTouch(&CRotDoor:: DoorTouch );
}
void CRotDoor::KeyValue( KeyValueData *pkvd )
{
if (FStrEq(pkvd->szKeyName, "axes"))
{
UTIL_StringToVector( (float*)(pev->movedir), pkvd->szValue );
pkvd->fHandled = TRUE;
}
else
CBaseDoor::KeyValue( pkvd );
}
8 years ago
void CRotDoor::SetToggleState( int state )
7 years ago
{
8 years ago
if( state == TS_AT_TOP )
7 years ago
pev->angles = m_vecAngle2;
else
pev->angles = m_vecAngle1;
UTIL_SetOrigin( this, pev->origin );
}
#define SF_MOMDOOR_MOVESTART = 0x80000000
class CMomentaryDoor : public CBaseToggle
{
public:
8 years ago
void Spawn( void );
7 years ago
void Precache( void );
void EXPORT MomentaryMoveDone( void );
void EXPORT StopMoveSound( void );
7 years ago
8 years ago
void KeyValue( KeyValueData *pkvd );
void Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value );
virtual int ObjectCaps( void ) { return CBaseToggle::ObjectCaps() & ~FCAP_ACROSS_TRANSITION; }
7 years ago
8 years ago
virtual int Save( CSave &save );
virtual int Restore( CRestore &restore );
static TYPEDESCRIPTION m_SaveData[];
7 years ago
8 years ago
BYTE m_bMoveSnd; // sound a door makes while moving
BYTE m_bStopSnd; // sound a door makes when it stops
7 years ago
STATE m_iState;
float m_fLastPos;
STATE GetState( void ) { return m_iState; }
float CalcRatio( CBaseEntity *pLocus ) { return m_fLastPos; }
};
LINK_ENTITY_TO_CLASS( momentary_door, CMomentaryDoor )
7 years ago
8 years ago
TYPEDESCRIPTION CMomentaryDoor::m_SaveData[] =
7 years ago
{
DEFINE_FIELD( CMomentaryDoor, m_bMoveSnd, FIELD_CHARACTER ),
DEFINE_FIELD( CMomentaryDoor, m_iState, FIELD_INTEGER ),
DEFINE_FIELD( CMomentaryDoor, m_fLastPos, FIELD_FLOAT ),
9 years ago
DEFINE_FIELD( CMomentaryDoor, m_bStopSnd, FIELD_CHARACTER ),
7 years ago
};
IMPLEMENT_SAVERESTORE( CMomentaryDoor, CBaseToggle )
7 years ago
void CMomentaryDoor::Spawn( void )
{
8 years ago
SetMovedir( pev );
7 years ago
8 years ago
pev->solid = SOLID_BSP;
pev->movetype = MOVETYPE_PUSH;
7 years ago
UTIL_SetOrigin(this, pev->origin);
8 years ago
SET_MODEL( ENT( pev ), STRING( pev->model ) );
// if( pev->speed == 0.0f )
// pev->speed = 100.0f;
if( pev->dmg == 0.0f )
pev->dmg = 2.0f;
7 years ago
m_iState = STATE_OFF;
8 years ago
m_vecPosition1 = pev->origin;
7 years ago
// Subtract 2 from size because the engine expands bboxes by 1 in all directions making the size too big
m_vecPosition2 = m_vecPosition1 + ( pev->movedir * ( fabs( pev->movedir.x * ( pev->size.x - 2.0f ) ) + fabs( pev->movedir.y * ( pev->size.y - 2.0f ) ) + fabs( pev->movedir.z * ( pev->size.z - 2.0f ) ) - m_flLip ) );
8 years ago
ASSERTSZ( m_vecPosition1 != m_vecPosition2, "door start/end positions are equal" );
7 years ago
//LRC: FIXME, move to PostSpawn
8 years ago
if( FBitSet( pev->spawnflags, SF_DOOR_START_OPEN ) )
7 years ago
{ // swap pos1 and pos2, put door at pos2
UTIL_AssignOrigin(this, m_vecPosition2);
Vector vecTemp = m_vecPosition2;
m_vecPosition2 = m_vecPosition1;
m_vecPosition1 = vecTemp;
}
if (m_pMoveWith)
{
m_vecPosition1 = m_vecPosition1 - m_pMoveWith->pev->origin;
m_vecPosition2 = m_vecPosition2 - m_pMoveWith->pev->origin;
}
SetTouch( NULL );
8 years ago
7 years ago
Precache();
}
7 years ago
void CMomentaryDoor::Precache( void )
{
const char *pszSound;
BOOL NullSound = FALSE;
7 years ago
// set the door's "in-motion" sound
8 years ago
switch( m_bMoveSnd )
7 years ago
{
8 years ago
case 1:
pszSound = "doors/doormove1.wav";
7 years ago
break;
8 years ago
case 2:
pszSound = "doors/doormove2.wav";
7 years ago
break;
8 years ago
case 3:
pszSound = "doors/doormove3.wav";
7 years ago
break;
8 years ago
case 4:
pszSound = "doors/doormove4.wav";
7 years ago
break;
8 years ago
case 5:
pszSound = "doors/doormove5.wav";
7 years ago
break;
8 years ago
case 6:
pszSound = "doors/doormove6.wav";
7 years ago
break;
8 years ago
case 7:
pszSound = "doors/doormove7.wav";
7 years ago
break;
8 years ago
case 8:
pszSound = "doors/doormove8.wav";
7 years ago
break;
case 0:
9 years ago
default:
pszSound = "common/null.wav";
NullSound = TRUE;
7 years ago
break;
9 years ago
}
if( !NullSound )
PRECACHE_SOUND( pszSound );
pev->noiseMoving = MAKE_STRING( pszSound );
NullSound = FALSE;
// set the door's 'reached destination' stop sound
8 years ago
switch( m_bStopSnd )
9 years ago
{
8 years ago
case 1:
pszSound = "doors/doorstop1.wav";
9 years ago
break;
8 years ago
case 2:
pszSound = "doors/doorstop2.wav";
9 years ago
break;
8 years ago
case 3:
pszSound = "doors/doorstop3.wav";
9 years ago
break;
8 years ago
case 4:
pszSound = "doors/doorstop4.wav";
9 years ago
break;
8 years ago
case 5:
pszSound = "doors/doorstop5.wav";
9 years ago
break;
8 years ago
case 6:
pszSound = "doors/doorstop6.wav";
9 years ago
break;
8 years ago
case 7:
pszSound = "doors/doorstop7.wav";
9 years ago
break;
8 years ago
case 8:
pszSound = "doors/doorstop8.wav";
9 years ago
break;
case 0:
7 years ago
default:
pszSound = "common/null.wav";
NullSound = TRUE;
7 years ago
break;
}
if( !NullSound )
PRECACHE_SOUND( pszSound );
pev->noiseArrived = MAKE_STRING( pszSound );
7 years ago
}
void CMomentaryDoor::KeyValue( KeyValueData *pkvd )
{
8 years ago
if( FStrEq( pkvd->szKeyName, "movesnd" ) )
7 years ago
{
m_bMoveSnd = atoi( pkvd->szValue );
7 years ago
pkvd->fHandled = TRUE;
}
8 years ago
else if( FStrEq( pkvd->szKeyName, "stopsnd" ) )
7 years ago
{
8 years ago
m_bStopSnd = atof( pkvd->szValue );
7 years ago
pkvd->fHandled = TRUE;
}
8 years ago
else if( FStrEq( pkvd->szKeyName, "healthvalue" ) )
7 years ago
{
8 years ago
//m_bHealthValue = atof( pkvd->szValue );
7 years ago
pkvd->fHandled = TRUE;
}
else
CBaseToggle::KeyValue( pkvd );
}
void CMomentaryDoor::Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value )
{
8 years ago
if( useType != USE_SET ) // Momentary buttons will pass down a float in here
7 years ago
return;
if( value > 1.0f )
value = 1.0f;
if( value < 0.0f )
value = 0.0f;
7 years ago
if (IsLockedByMaster()) return;
8 years ago
Vector move = m_vecPosition1 + ( value * ( m_vecPosition2 - m_vecPosition1 ) );
7 years ago
float speed = 0;
if( pev->speed )
7 years ago
{
//LRC- move at the given speed, if any.
speed = pev->speed;
}
else
{
// default: get there in 0.1 secs
Vector delta;
delta = move - pev->origin;
speed = delta.Length() * 0.1f;
7 years ago
}
//FIXME: allow for it being told to move at the same speed in the _opposite_ direction!
8 years ago
if( speed != 0 )
7 years ago
{
// This entity only thinks when it moves
//LRC- nope, in a MoveWith world you can't rely on that. Check the state instead.
if ( m_iState == STATE_OFF )
{
//ALERT(at_console,"USE: start moving to %f %f %f.\n", move.x, move.y, move.z);
m_iState = STATE_ON;
EMIT_SOUND(ENT(pev), CHAN_STATIC, STRING(pev->noiseMoving), 1, ATTN_NORM);
7 years ago
}
m_fLastPos = value;
LinearMove( move, speed );
9 years ago
SetMoveDone( &CMomentaryDoor::MomentaryMoveDone );
7 years ago
}
}
void CMomentaryDoor::MomentaryMoveDone( void )
{
m_iState = STATE_OFF;
SetThink(&CMomentaryDoor::StopMoveSound);
pev->nextthink = pev->ltime + 0.1f;
}
void CMomentaryDoor::StopMoveSound()
9 years ago
{
STOP_SOUND( ENT( pev ), CHAN_STATIC, STRING( pev->noiseMoving ) );
EMIT_SOUND( ENT( pev ), CHAN_STATIC, STRING( pev->noiseArrived ), 1.0f, ATTN_NORM );
pev->nextthink = -1.0f;
ResetThink();
7 years ago
}