123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204 |
- #include "../idlib/precompiled.h"
- #pragma hdrstop
- #include "Game_local.h"
- #define HEIGHT_MAX 32
- #define FLYRADIUS 45
- const idEventDef EV_TremblerReset( "tremblerreset" );
- const idEventDef EV_TremblerArm( "<TremblerArm>" );
- CLASS_DECLARATION( idAnimatedEntity, idTrembler )
-
- EVENT( EV_Touch, idTrembler::Event_Touch )
- EVENT( EV_TremblerReset, idTrembler::Reset)
- EVENT( EV_TremblerArm, idTrembler::Arm)
- END_CLASS
- void idTrembler::Save( idSaveGame *savefile ) const
- {
- savefile->WriteInt(state);
- savefile->WriteVec3(itemOriginalPosition);
- itemEnt.Save(savefile);
- savefile->WriteInt(ticksoundTime);
- }
- void idTrembler::Restore( idRestoreGame *savefile )
- {
- savefile->ReadInt(state);
- savefile->ReadVec3(itemOriginalPosition);
- itemEnt.Restore(savefile);
- savefile->ReadInt(ticksoundTime);
- }
- //state
- //-1 = waiting for item to settle.
- // 0 = armed.
- // 1 = alarm tripped.
- void idTrembler::Spawn( void )
- {
- itemEnt = NULL;
- itemOriginalPosition = idVec3(0,0,0);
- state = -1;
- ticksoundTime = 0;
-
- Reset();
- BecomeActive( TH_THINK );
- }
- void idTrembler::Reset( void )
- {
- StopSound( SND_CHANNEL_ANY, false );
- renderEntity.shaderParms[ SHADERPARM_RED ] = 0;
- renderEntity.shaderParms[ SHADERPARM_GREEN ] = 0.7f;
- renderEntity.shaderParms[ SHADERPARM_BLUE ] = 1;
- UpdateVisuals();
- state = -1;
- int resettime = spawnArgs.GetInt("armtime");
- Event_PlayAnim("idle", 1);
- PostEventMS( &EV_TremblerArm, resettime ); //give a little delay to let physics settle the objects down.
- }
- void idTrembler::Arm( void )
- {
- if ( !itemEnt.IsValid() )
- {
- idStr itemName = spawnArgs.GetString( "itemname", "" );
- if ( itemName.Length() )
- {
- itemEnt = gameLocal.FindEntity( itemName );
- if (!itemEnt.IsValid())
- {
- common->Warning("idTrembler %s couldn't find item '%s'.", name.c_str(), itemName.c_str());
- }
- }
- else
- {
- common->Warning("idTrembler %s has no 'itemname' value.", name.c_str());
- }
- }
- if (itemEnt.IsValid())
- {
- itemOriginalPosition = itemEnt.GetEntity()->GetPhysics()->GetOrigin();
- }
- state = 0;
- renderEntity.shaderParms[ SHADERPARM_RED ] = 1;
- renderEntity.shaderParms[ SHADERPARM_GREEN ] = 1;
- renderEntity.shaderParms[ SHADERPARM_BLUE ] = 0;
- UpdateVisuals();
- }
- void idTrembler::Think( void )
- {
- if (state == 0 && itemEnt.IsValid())
- {
- idVec3 currentPosition = itemEnt.GetEntity()->GetPhysics()->GetOrigin();
- if (currentPosition.x != itemOriginalPosition.x || currentPosition.y != itemOriginalPosition.y
- || currentPosition.z != itemOriginalPosition.z || itemEnt.GetEntity()->IsHidden())
- {
- Event_Touch(NULL,NULL);
- }
- }
- if (state == 1)
- {
- if (gameLocal.time > ticksoundTime)
- {
- StopSound( SND_CHANNEL_BODY2, false );
- ticksoundTime = gameLocal.time + 1000000;
- }
- }
- //Render the polys.
- idAnimatedEntity::Present();
- }
- void idTrembler::Event_Touch( idEntity *other, trace_t *trace )
- {
-
- if (state == 0)
- {
- idEntity *entityList[ MAX_GENTITIES ];
- int i;
- int flyforce;
- state = 1;
- Event_PlayAnim("bounce", 1);
- StartSound( "snd_trigger", SND_CHANNEL_BODY, 0, false, NULL );
- StartSound( "snd_trigger_idle", SND_CHANNEL_BODY2, 0, false, NULL );
- ticksoundTime = gameLocal.time + (spawnArgs.GetInt("ticktime", "10") * 1000);
- if (g_skill.GetInteger() > 0)
- {
- ActivateTargets(this); //activate alarm.
- }
- int listedEntities = gameLocal.EntitiesWithinRadius( GetPhysics()->GetOrigin(), FLYRADIUS, entityList, MAX_GENTITIES );
- flyforce = spawnArgs.GetInt("force", "256");
- renderEntity.shaderParms[ SHADERPARM_RED ] = 1;
- renderEntity.shaderParms[ SHADERPARM_GREEN ] = 0;
- renderEntity.shaderParms[ SHADERPARM_BLUE ] = 0;
- UpdateVisuals();
- //KA BOIIIIINNNGGGGGG
- for (i = 0; i < listedEntities; i++)
- {
- idEntity *ent = entityList[ i ];
- if (!ent)
- {
- continue;
- }
- float ent_zpos = ent->GetPhysics()->GetOrigin().z;
- float trembler_zpos = this->GetPhysics()->GetOrigin().z;
- //only affect things above the trembler.
- if (ent_zpos < trembler_zpos)
- continue;
- //only affect things within X height of trembler.
- if (ent_zpos > trembler_zpos + HEIGHT_MAX)
- continue;
- if ( !ent->IsType( idMoveableItem::Type ) && !ent->IsType( idMoveable::Type ) )
- continue;
- ent->GetPhysics()->SetLinearVelocity(idVec3(0,0,1) * flyforce);
- }
- }
- }
|