123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187 |
- #include "../idlib/precompiled.h"
- #pragma hdrstop
- #include "Game_local.h"
- const idEventDef EV_frobscript( "<frobscript>" );
- CLASS_DECLARATION( idAnimated, idLever )
- EVENT( EV_frobscript, idLever::OnFrobScript)
- END_CLASS
- void idLever::Save( idSaveGame *savefile ) const
- {
- savefile->WriteBool(toggleable);
- savefile->WriteInt(toggleState);
- savefile->WriteInt(state);
- savefile->WriteInt(nextStateTime);
- }
- void idLever::Restore( idRestoreGame *savefile )
- {
- savefile->ReadBool(toggleable);
- savefile->ReadInt(toggleState);
- savefile->ReadInt(state);
- savefile->ReadInt(nextStateTime);
- }
- void idLever::Spawn( void )
- {
- //make frobbable and no collision.
- //this->GetPhysics()->SetContents(CONTENTS_CORPSE);
- GetPhysics()->SetContents( CONTENTS_RENDERMODEL );
- GetPhysics()->SetClipMask( MASK_SOLID | CONTENTS_MOVEABLECLIP );
- this->isFrobbable = true;
- this->noGrab = true;
- renderEntity.shaderParms[ SHADERPARM_RED ] = 0;
- renderEntity.shaderParms[ SHADERPARM_GREEN ] = 1;
- renderEntity.shaderParms[ SHADERPARM_BLUE ] = 0;
- nextStateTime = 0;
- toggleable = spawnArgs.GetBool("toggleable", "0");
- toggleState = 0;
- state = IDLE;
- if (spawnArgs.GetBool("start_on", "0"))
- {
- toggleState = !toggleState;
- }
- BecomeActive(TH_THINK);
- }
- void idLever::Reset( void )
- {
- if (spawnArgs.GetBool("start_on", "0"))
- {
- toggleState = 1;
- }
- else
- {
- toggleState = 0;
- }
- }
- void idLever::UpdateStates( void )
- {
- if (state == PRESSED)
- {
- if (gameLocal.time > nextStateTime)
- {
- renderEntity.shaderParms[ SHADERPARM_RED ] = 0;
- renderEntity.shaderParms[ SHADERPARM_GREEN ] = 1;
- renderEntity.shaderParms[ SHADERPARM_BLUE ] = 0;
- this->isFrobbable = true;
- state = IDLE;
- }
- }
- }
- void idLever::OnFrobScript( void )
- {
- idStr scriptName = spawnArgs.GetString( "call", "" );
- if (scriptName.Length() <= 0)
- return;
- if (toggleable)
- {
- if (toggleState > 0)
- {
- scriptName = scriptName + "_on";
- }
- else
- {
- scriptName = scriptName + "_off";
- }
- }
- const function_t *scriptFunction;
- scriptFunction = gameLocal.program.FindFunction( scriptName );
- if ( scriptFunction )
- {
- idThread *thread;
- thread = new idThread( scriptFunction );
- thread->DelayedStart( 0 );
- }
-
- }
- void idLever::OnFrob( idEntity* activator )
- {
- float waitTime;
- if (state == PRESSED)
- {
- return;
- }
- state = PRESSED;
- StartSound( "snd_press", SND_CHANNEL_BODY, 0, false, NULL );
- if (!toggleable)
- {
- Event_PlayAnim( spawnArgs.GetString("pushanim", "push"), 4 );
- }
- else
- {
- if (toggleState)
- {
- Event_PlayAnim( spawnArgs.GetString("pullanim", "pull"), 4 );
- }
- else
- {
- Event_PlayAnim( spawnArgs.GetString("pushanim", "push"), 4 );
-
- }
- toggleState = !toggleState;
- }
- renderEntity.shaderParms[ SHADERPARM_RED ] = 1;
- renderEntity.shaderParms[ SHADERPARM_GREEN ] = .75f;
- renderEntity.shaderParms[ SHADERPARM_BLUE ] = 0;
- waitTime = spawnArgs.GetFloat("animtime", "0.3");
- if (waitTime <= 0)
- {
- waitTime = 0.1f;
- }
- nextStateTime = gameLocal.time + (waitTime * 1000);
- ActivateTargets(this);
- this->isFrobbable = false;
- float delay = spawnArgs.GetFloat("delay", "0");
- PostEventSec( &EV_frobscript, delay );
- }
- void idLever::Think( void )
- {
- UpdateStates();
-
- idAnimatedEntity::Think();
- idAnimatedEntity::Present();
- }
|