2 ===========================================================================
5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
7 This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
9 Doom 3 Source Code is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
14 Doom 3 Source Code is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
22 In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
24 If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
26 ===========================================================================
29 #include "../idlib/precompiled.h"
32 #include "Game_local.h"
36 ===============================================================================
40 ===============================================================================
43 const idEventDef EV_Enable( "enable", NULL );
44 const idEventDef EV_Disable( "disable", NULL );
46 CLASS_DECLARATION( idEntity, idTrigger )
47 EVENT( EV_Enable, idTrigger::Event_Enable )
48 EVENT( EV_Disable, idTrigger::Event_Disable )
53 idTrigger::DrawDebugInfo
56 void idTrigger::DrawDebugInfo( void ) {
57 idMat3 axis = gameLocal.GetLocalPlayer()->viewAngles.ToMat3();
58 idVec3 up = axis[ 2 ] * 5.0f;
59 idBounds viewTextBounds( gameLocal.GetLocalPlayer()->GetPhysics()->GetOrigin() );
60 idBounds viewBounds( gameLocal.GetLocalPlayer()->GetPhysics()->GetOrigin() );
61 idBounds box( idVec3( -4.0f, -4.0f, -4.0f ), idVec3( 4.0f, 4.0f, 4.0f ) );
66 const function_t *func;
68 viewTextBounds.ExpandSelf( 128.0f );
69 viewBounds.ExpandSelf( 512.0f );
70 for( ent = gameLocal.spawnedEntities.Next(); ent != NULL; ent = ent->spawnNode.Next() ) {
71 if ( ent->GetPhysics()->GetContents() & ( CONTENTS_TRIGGER | CONTENTS_FLASHLIGHT_TRIGGER ) ) {
72 show = viewBounds.IntersectsBounds( ent->GetPhysics()->GetAbsBounds() );
74 for( i = 0; i < ent->targets.Num(); i++ ) {
75 target = ent->targets[ i ].GetEntity();
76 if ( target && viewBounds.IntersectsBounds( target->GetPhysics()->GetAbsBounds() ) ) {
87 gameRenderWorld->DebugBounds( colorOrange, ent->GetPhysics()->GetAbsBounds() );
88 if ( viewTextBounds.IntersectsBounds( ent->GetPhysics()->GetAbsBounds() ) ) {
89 gameRenderWorld->DrawText( ent->name.c_str(), ent->GetPhysics()->GetAbsBounds().GetCenter(), 0.1f, colorWhite, axis, 1 );
90 gameRenderWorld->DrawText( ent->GetEntityDefName(), ent->GetPhysics()->GetAbsBounds().GetCenter() + up, 0.1f, colorWhite, axis, 1 );
91 if ( ent->IsType( idTrigger::Type ) ) {
92 func = static_cast<idTrigger *>( ent )->GetScriptFunction();
98 gameRenderWorld->DrawText( va( "call script '%s'", func->Name() ), ent->GetPhysics()->GetAbsBounds().GetCenter() - up, 0.1f, colorWhite, axis, 1 );
102 for( i = 0; i < ent->targets.Num(); i++ ) {
103 target = ent->targets[ i ].GetEntity();
105 gameRenderWorld->DebugArrow( colorYellow, ent->GetPhysics()->GetAbsBounds().GetCenter(), target->GetPhysics()->GetOrigin(), 10, 0 );
106 gameRenderWorld->DebugBounds( colorGreen, box, target->GetPhysics()->GetOrigin() );
107 if ( viewTextBounds.IntersectsBounds( target->GetPhysics()->GetAbsBounds() ) ) {
108 gameRenderWorld->DrawText( target->name.c_str(), target->GetPhysics()->GetAbsBounds().GetCenter(), 0.1f, colorWhite, axis, 1 );
121 void idTrigger::Enable( void ) {
122 GetPhysics()->SetContents( CONTENTS_TRIGGER );
123 GetPhysics()->EnableClip();
131 void idTrigger::Disable( void ) {
132 // we may be relinked if we're bound to another object, so clear the contents as well
133 GetPhysics()->SetContents( 0 );
134 GetPhysics()->DisableClip();
139 idTrigger::CallScript
142 void idTrigger::CallScript( void ) const {
145 if ( scriptFunction ) {
146 thread = new idThread( scriptFunction );
147 thread->DelayedStart( 0 );
153 idTrigger::GetScriptFunction
156 const function_t *idTrigger::GetScriptFunction( void ) const {
157 return scriptFunction;
165 void idTrigger::Save( idSaveGame *savefile ) const {
166 if ( scriptFunction ) {
167 savefile->WriteString( scriptFunction->Name() );
169 savefile->WriteString( "" );
178 void idTrigger::Restore( idRestoreGame *savefile ) {
180 savefile->ReadString( funcname );
181 if ( funcname.Length() ) {
182 scriptFunction = gameLocal.program.FindFunction( funcname );
183 if ( scriptFunction == NULL ) {
184 gameLocal.Warning( "idTrigger_Multi '%s' at (%s) calls unknown function '%s'", name.c_str(), GetPhysics()->GetOrigin().ToString(0), funcname.c_str() );
187 scriptFunction = NULL;
193 idTrigger::Event_Enable
196 void idTrigger::Event_Enable( void ) {
202 idTrigger::Event_Disable
205 void idTrigger::Event_Disable( void ) {
214 idTrigger::idTrigger() {
215 scriptFunction = NULL;
223 void idTrigger::Spawn( void ) {
224 GetPhysics()->SetContents( CONTENTS_TRIGGER );
226 idStr funcname = spawnArgs.GetString( "call", "" );
227 if ( funcname.Length() ) {
228 scriptFunction = gameLocal.program.FindFunction( funcname );
229 if ( scriptFunction == NULL ) {
230 gameLocal.Warning( "trigger '%s' at (%s) calls unknown function '%s'", name.c_str(), GetPhysics()->GetOrigin().ToString(0), funcname.c_str() );
233 scriptFunction = NULL;
239 ===============================================================================
243 ===============================================================================
246 const idEventDef EV_TriggerAction( "<triggerAction>", "e" );
248 CLASS_DECLARATION( idTrigger, idTrigger_Multi )
249 EVENT( EV_Touch, idTrigger_Multi::Event_Touch )
250 EVENT( EV_Activate, idTrigger_Multi::Event_Trigger )
251 EVENT( EV_TriggerAction, idTrigger_Multi::Event_TriggerAction )
257 idTrigger_Multi::idTrigger_Multi
260 idTrigger_Multi::idTrigger_Multi( void ) {
269 triggerFirst = false;
270 triggerWithSelf = false;
275 idTrigger_Multi::Save
278 void idTrigger_Multi::Save( idSaveGame *savefile ) const {
279 savefile->WriteFloat( wait );
280 savefile->WriteFloat( random );
281 savefile->WriteFloat( delay );
282 savefile->WriteFloat( random_delay );
283 savefile->WriteInt( nextTriggerTime );
284 savefile->WriteString( requires );
285 savefile->WriteInt( removeItem );
286 savefile->WriteBool( touchClient );
287 savefile->WriteBool( touchOther );
288 savefile->WriteBool( triggerFirst );
289 savefile->WriteBool( triggerWithSelf );
294 idTrigger_Multi::Restore
297 void idTrigger_Multi::Restore( idRestoreGame *savefile ) {
298 savefile->ReadFloat( wait );
299 savefile->ReadFloat( random );
300 savefile->ReadFloat( delay );
301 savefile->ReadFloat( random_delay );
302 savefile->ReadInt( nextTriggerTime );
303 savefile->ReadString( requires );
304 savefile->ReadInt( removeItem );
305 savefile->ReadBool( touchClient );
306 savefile->ReadBool( touchOther );
307 savefile->ReadBool( triggerFirst );
308 savefile->ReadBool( triggerWithSelf );
313 idTrigger_Multi::Spawn
315 "wait" : Seconds between triggerings, 0.5 default, -1 = one time only.
316 "call" : Script function to call when triggered
317 "random" wait variance, default is 0
318 Variable sized repeatable trigger. Must be targeted at one or more entities.
319 so, the basic time between firing is a random time between
320 (wait - random) and (wait + random)
323 void idTrigger_Multi::Spawn( void ) {
324 spawnArgs.GetFloat( "wait", "0.5", wait );
325 spawnArgs.GetFloat( "random", "0", random );
326 spawnArgs.GetFloat( "delay", "0", delay );
327 spawnArgs.GetFloat( "random_delay", "0", random_delay );
329 if ( random && ( random >= wait ) && ( wait >= 0 ) ) {
331 gameLocal.Warning( "idTrigger_Multi '%s' at (%s) has random >= wait", name.c_str(), GetPhysics()->GetOrigin().ToString(0) );
334 if ( random_delay && ( random_delay >= delay ) && ( delay >= 0 ) ) {
335 random_delay = delay - 1;
336 gameLocal.Warning( "idTrigger_Multi '%s' at (%s) has random_delay >= delay", name.c_str(), GetPhysics()->GetOrigin().ToString(0) );
339 spawnArgs.GetString( "requires", "", requires );
340 spawnArgs.GetInt( "removeItem", "0", removeItem );
341 spawnArgs.GetBool( "triggerFirst", "0", triggerFirst );
342 spawnArgs.GetBool( "triggerWithSelf", "0", triggerWithSelf );
344 if ( spawnArgs.GetBool( "anyTouch" ) ) {
347 } else if ( spawnArgs.GetBool( "noTouch" ) ) {
350 } else if ( spawnArgs.GetBool( "noClient" ) ) {
360 if ( spawnArgs.GetBool( "flashlight_trigger" ) ) {
361 GetPhysics()->SetContents( CONTENTS_FLASHLIGHT_TRIGGER );
363 GetPhysics()->SetContents( CONTENTS_TRIGGER );
369 idTrigger_Multi::CheckFacing
372 bool idTrigger_Multi::CheckFacing( idEntity *activator ) {
373 if ( spawnArgs.GetBool( "facing" ) ) {
374 if ( !activator->IsType( idPlayer::Type ) ) {
377 idPlayer *player = static_cast< idPlayer* >( activator );
378 float dot = player->viewAngles.ToForward() * GetPhysics()->GetAxis()[0];
379 float angle = RAD2DEG( idMath::ACos( dot ) );
380 if ( angle > spawnArgs.GetFloat( "angleLimit", "30" ) ) {
390 idTrigger_Multi::TriggerAction
393 void idTrigger_Multi::TriggerAction( idEntity *activator ) {
394 ActivateTargets( triggerWithSelf ? this : activator );
398 nextTriggerTime = gameLocal.time + SEC2MS( wait + random * gameLocal.random.CRandomFloat() );
400 // we can't just remove (this) here, because this is a touch function
401 // called while looping through area links...
402 nextTriggerTime = gameLocal.time + 1;
403 PostEventMS( &EV_Remove, 0 );
409 idTrigger_Multi::Event_TriggerAction
412 void idTrigger_Multi::Event_TriggerAction( idEntity *activator ) {
413 TriggerAction( activator );
418 idTrigger_Multi::Event_Trigger
420 the trigger was just activated
421 activated should be the entity that originated the activation sequence (ie. the original target)
422 activator should be set to the activator so it can be held through a delay
423 so wait for the delay time before firing
426 void idTrigger_Multi::Event_Trigger( idEntity *activator ) {
427 if ( nextTriggerTime > gameLocal.time ) {
428 // can't retrigger until the wait is over
432 // see if this trigger requires an item
433 if ( !gameLocal.RequirementMet( activator, requires, removeItem ) ) {
437 if ( !CheckFacing( activator ) ) {
441 if ( triggerFirst ) {
442 triggerFirst = false;
446 // don't allow it to trigger twice in a single frame
447 nextTriggerTime = gameLocal.time + 1;
450 // don't allow it to trigger again until our delay has passed
451 nextTriggerTime += SEC2MS( delay + random_delay * gameLocal.random.CRandomFloat() );
452 PostEventSec( &EV_TriggerAction, delay, activator );
454 TriggerAction( activator );
460 idTrigger_Multi::Event_Touch
463 void idTrigger_Multi::Event_Touch( idEntity *other, trace_t *trace ) {
468 bool player = other->IsType( idPlayer::Type );
470 if ( !touchClient ) {
473 if ( static_cast< idPlayer * >( other )->spectating ) {
476 } else if ( !touchOther ) {
480 if ( nextTriggerTime > gameLocal.time ) {
481 // can't retrigger until the wait is over
485 // see if this trigger requires an item
486 if ( !gameLocal.RequirementMet( other, requires, removeItem ) ) {
490 if ( !CheckFacing( other ) ) {
494 if ( spawnArgs.GetBool( "toggleTriggerFirst" ) ) {
498 nextTriggerTime = gameLocal.time + 1;
500 // don't allow it to trigger again until our delay has passed
501 nextTriggerTime += SEC2MS( delay + random_delay * gameLocal.random.CRandomFloat() );
502 PostEventSec( &EV_TriggerAction, delay, other );
504 TriggerAction( other );
509 ===============================================================================
513 ===============================================================================
516 CLASS_DECLARATION( idTrigger, idTrigger_EntityName )
517 EVENT( EV_Touch, idTrigger_EntityName::Event_Touch )
518 EVENT( EV_Activate, idTrigger_EntityName::Event_Trigger )
519 EVENT( EV_TriggerAction, idTrigger_EntityName::Event_TriggerAction )
524 idTrigger_EntityName::idTrigger_EntityName
527 idTrigger_EntityName::idTrigger_EntityName( void ) {
533 triggerFirst = false;
538 idTrigger_EntityName::Save
541 void idTrigger_EntityName::Save( idSaveGame *savefile ) const {
542 savefile->WriteFloat( wait );
543 savefile->WriteFloat( random );
544 savefile->WriteFloat( delay );
545 savefile->WriteFloat( random_delay );
546 savefile->WriteInt( nextTriggerTime );
547 savefile->WriteBool( triggerFirst );
548 savefile->WriteString( entityName );
553 idTrigger_EntityName::Restore
556 void idTrigger_EntityName::Restore( idRestoreGame *savefile ) {
557 savefile->ReadFloat( wait );
558 savefile->ReadFloat( random );
559 savefile->ReadFloat( delay );
560 savefile->ReadFloat( random_delay );
561 savefile->ReadInt( nextTriggerTime );
562 savefile->ReadBool( triggerFirst );
563 savefile->ReadString( entityName );
568 idTrigger_EntityName::Spawn
571 void idTrigger_EntityName::Spawn( void ) {
572 spawnArgs.GetFloat( "wait", "0.5", wait );
573 spawnArgs.GetFloat( "random", "0", random );
574 spawnArgs.GetFloat( "delay", "0", delay );
575 spawnArgs.GetFloat( "random_delay", "0", random_delay );
577 if ( random && ( random >= wait ) && ( wait >= 0 ) ) {
579 gameLocal.Warning( "idTrigger_EntityName '%s' at (%s) has random >= wait", name.c_str(), GetPhysics()->GetOrigin().ToString(0) );
582 if ( random_delay && ( random_delay >= delay ) && ( delay >= 0 ) ) {
583 random_delay = delay - 1;
584 gameLocal.Warning( "idTrigger_EntityName '%s' at (%s) has random_delay >= delay", name.c_str(), GetPhysics()->GetOrigin().ToString(0) );
587 spawnArgs.GetBool( "triggerFirst", "0", triggerFirst );
589 entityName = spawnArgs.GetString( "entityname" );
590 if ( !entityName.Length() ) {
591 gameLocal.Error( "idTrigger_EntityName '%s' at (%s) doesn't have 'entityname' key specified", name.c_str(), GetPhysics()->GetOrigin().ToString(0) );
596 if ( !spawnArgs.GetBool( "noTouch" ) ) {
597 GetPhysics()->SetContents( CONTENTS_TRIGGER );
603 idTrigger_EntityName::TriggerAction
606 void idTrigger_EntityName::TriggerAction( idEntity *activator ) {
607 ActivateTargets( activator );
611 nextTriggerTime = gameLocal.time + SEC2MS( wait + random * gameLocal.random.CRandomFloat() );
613 // we can't just remove (this) here, because this is a touch function
614 // called while looping through area links...
615 nextTriggerTime = gameLocal.time + 1;
616 PostEventMS( &EV_Remove, 0 );
622 idTrigger_EntityName::Event_TriggerAction
625 void idTrigger_EntityName::Event_TriggerAction( idEntity *activator ) {
626 TriggerAction( activator );
631 idTrigger_EntityName::Event_Trigger
633 the trigger was just activated
634 activated should be the entity that originated the activation sequence (ie. the original target)
635 activator should be set to the activator so it can be held through a delay
636 so wait for the delay time before firing
639 void idTrigger_EntityName::Event_Trigger( idEntity *activator ) {
640 if ( nextTriggerTime > gameLocal.time ) {
641 // can't retrigger until the wait is over
645 if ( !activator || ( activator->name != entityName ) ) {
649 if ( triggerFirst ) {
650 triggerFirst = false;
654 // don't allow it to trigger twice in a single frame
655 nextTriggerTime = gameLocal.time + 1;
658 // don't allow it to trigger again until our delay has passed
659 nextTriggerTime += SEC2MS( delay + random_delay * gameLocal.random.CRandomFloat() );
660 PostEventSec( &EV_TriggerAction, delay, activator );
662 TriggerAction( activator );
668 idTrigger_EntityName::Event_Touch
671 void idTrigger_EntityName::Event_Touch( idEntity *other, trace_t *trace ) {
676 if ( nextTriggerTime > gameLocal.time ) {
677 // can't retrigger until the wait is over
681 if ( !other || ( other->name != entityName ) ) {
685 nextTriggerTime = gameLocal.time + 1;
687 // don't allow it to trigger again until our delay has passed
688 nextTriggerTime += SEC2MS( delay + random_delay * gameLocal.random.CRandomFloat() );
689 PostEventSec( &EV_TriggerAction, delay, other );
691 TriggerAction( other );
696 ===============================================================================
700 ===============================================================================
703 const idEventDef EV_Timer( "<timer>", NULL );
705 CLASS_DECLARATION( idTrigger, idTrigger_Timer )
706 EVENT( EV_Timer, idTrigger_Timer::Event_Timer )
707 EVENT( EV_Activate, idTrigger_Timer::Event_Use )
712 idTrigger_Timer::idTrigger_Timer
715 idTrigger_Timer::idTrigger_Timer( void ) {
724 idTrigger_Timer::Save
727 void idTrigger_Timer::Save( idSaveGame *savefile ) const {
728 savefile->WriteFloat( random );
729 savefile->WriteFloat( wait );
730 savefile->WriteBool( on );
731 savefile->WriteFloat( delay );
732 savefile->WriteString( onName );
733 savefile->WriteString( offName );
738 idTrigger_Timer::Restore
741 void idTrigger_Timer::Restore( idRestoreGame *savefile ) {
742 savefile->ReadFloat( random );
743 savefile->ReadFloat( wait );
744 savefile->ReadBool( on );
745 savefile->ReadFloat( delay );
746 savefile->ReadString( onName );
747 savefile->ReadString( offName );
752 idTrigger_Timer::Spawn
754 Repeatedly fires its targets.
755 Can be turned on or off by using.
758 void idTrigger_Timer::Spawn( void ) {
759 spawnArgs.GetFloat( "random", "1", random );
760 spawnArgs.GetFloat( "wait", "1", wait );
761 spawnArgs.GetBool( "start_on", "0", on );
762 spawnArgs.GetFloat( "delay", "0", delay );
763 onName = spawnArgs.GetString( "onName" );
764 offName = spawnArgs.GetString( "offName" );
766 if ( random >= wait && wait >= 0 ) {
767 random = wait - 0.001;
768 gameLocal.Warning( "idTrigger_Timer '%s' at (%s) has random >= wait", name.c_str(), GetPhysics()->GetOrigin().ToString(0) );
772 PostEventSec( &EV_Timer, delay );
778 idTrigger_Timer::Enable
781 void idTrigger_Timer::Enable( void ) {
782 // if off, turn it on
785 PostEventSec( &EV_Timer, delay );
791 idTrigger_Timer::Disable
794 void idTrigger_Timer::Disable( void ) {
795 // if on, turn it off
798 CancelEvents( &EV_Timer );
804 idTrigger_Timer::Event_Timer
807 void idTrigger_Timer::Event_Timer( void ) {
808 ActivateTargets( this );
810 // set time before next firing
811 if ( wait >= 0.0f ) {
812 PostEventSec( &EV_Timer, wait + gameLocal.random.CRandomFloat() * random );
818 idTrigger_Timer::Event_Use
821 void idTrigger_Timer::Event_Use( idEntity *activator ) {
822 // if on, turn it off
824 if ( offName.Length() && offName.Icmp( activator->GetName() ) ) {
828 CancelEvents( &EV_Timer );
831 if ( onName.Length() && onName.Icmp( activator->GetName() ) ) {
835 PostEventSec( &EV_Timer, delay );
840 ===============================================================================
844 ===============================================================================
847 CLASS_DECLARATION( idTrigger, idTrigger_Count )
848 EVENT( EV_Activate, idTrigger_Count::Event_Trigger )
849 EVENT( EV_TriggerAction, idTrigger_Count::Event_TriggerAction )
854 idTrigger_Count::idTrigger_Count
857 idTrigger_Count::idTrigger_Count( void ) {
865 idTrigger_Count::Save
868 void idTrigger_Count::Save( idSaveGame *savefile ) const {
869 savefile->WriteInt( goal );
870 savefile->WriteInt( count );
871 savefile->WriteFloat( delay );
876 idTrigger_Count::Restore
879 void idTrigger_Count::Restore( idRestoreGame *savefile ) {
880 savefile->ReadInt( goal );
881 savefile->ReadInt( count );
882 savefile->ReadFloat( delay );
887 idTrigger_Count::Spawn
890 void idTrigger_Count::Spawn( void ) {
891 spawnArgs.GetInt( "count", "1", goal );
892 spawnArgs.GetFloat( "delay", "0", delay );
898 idTrigger_Count::Event_Trigger
901 void idTrigger_Count::Event_Trigger( idEntity *activator ) {
902 // goal of -1 means trigger has been exhausted
905 if ( count >= goal ) {
906 if (spawnArgs.GetBool("repeat")) {
911 PostEventSec( &EV_TriggerAction, delay, activator );
918 idTrigger_Count::Event_TriggerAction
921 void idTrigger_Count::Event_TriggerAction( idEntity *activator ) {
922 ActivateTargets( activator );
925 PostEventMS( &EV_Remove, 0 );
930 ===============================================================================
934 ===============================================================================
937 CLASS_DECLARATION( idTrigger, idTrigger_Hurt )
938 EVENT( EV_Touch, idTrigger_Hurt::Event_Touch )
939 EVENT( EV_Activate, idTrigger_Hurt::Event_Toggle )
945 idTrigger_Hurt::idTrigger_Hurt
948 idTrigger_Hurt::idTrigger_Hurt( void ) {
959 void idTrigger_Hurt::Save( idSaveGame *savefile ) const {
960 savefile->WriteBool( on );
961 savefile->WriteFloat( delay );
962 savefile->WriteInt( nextTime );
967 idTrigger_Hurt::Restore
970 void idTrigger_Hurt::Restore( idRestoreGame *savefile ) {
971 savefile->ReadBool( on );
972 savefile->ReadFloat( delay );
973 savefile->ReadInt( nextTime );
978 idTrigger_Hurt::Spawn
981 Can be turned on or off by using.
984 void idTrigger_Hurt::Spawn( void ) {
985 spawnArgs.GetBool( "on", "1", on );
986 spawnArgs.GetFloat( "delay", "1.0", delay );
987 nextTime = gameLocal.time;
993 idTrigger_Hurt::Event_Touch
996 void idTrigger_Hurt::Event_Touch( idEntity *other, trace_t *trace ) {
999 if ( on && other && gameLocal.time >= nextTime ) {
1000 damage = spawnArgs.GetString( "def_damage", "damage_painTrigger" );
1001 other->Damage( NULL, NULL, vec3_origin, damage, 1.0f, INVALID_JOINT );
1003 ActivateTargets( other );
1006 nextTime = gameLocal.time + SEC2MS( delay );
1012 idTrigger_Hurt::Event_Toggle
1015 void idTrigger_Hurt::Event_Toggle( idEntity *activator ) {
1021 ===============================================================================
1025 ===============================================================================
1028 CLASS_DECLARATION( idTrigger, idTrigger_Fade )
1029 EVENT( EV_Activate, idTrigger_Fade::Event_Trigger )
1034 idTrigger_Fade::Event_Trigger
1037 void idTrigger_Fade::Event_Trigger( idEntity *activator ) {
1042 player = gameLocal.GetLocalPlayer();
1044 fadeColor = spawnArgs.GetVec4( "fadeColor", "0, 0, 0, 1" );
1045 fadeTime = SEC2MS( spawnArgs.GetFloat( "fadeTime", "0.5" ) );
1046 player->playerView.Fade( fadeColor, fadeTime );
1047 PostEventMS( &EV_ActivateTargets, fadeTime, activator );
1052 ===============================================================================
1056 ===============================================================================
1059 CLASS_DECLARATION( idTrigger, idTrigger_Touch )
1060 EVENT( EV_Activate, idTrigger_Touch::Event_Trigger )
1066 idTrigger_Touch::idTrigger_Touch
1069 idTrigger_Touch::idTrigger_Touch( void ) {
1075 idTrigger_Touch::Spawn
1078 void idTrigger_Touch::Spawn( void ) {
1079 // get the clip model
1080 clipModel = new idClipModel( GetPhysics()->GetClipModel() );
1082 // remove the collision model from the physics object
1083 GetPhysics()->SetClipModel( NULL, 1.0f );
1085 if ( spawnArgs.GetBool( "start_on" ) ) {
1086 BecomeActive( TH_THINK );
1092 idTrigger_Touch::Save
1095 void idTrigger_Touch::Save( idSaveGame *savefile ) {
1096 savefile->WriteClipModel( clipModel );
1101 idTrigger_Touch::Restore
1104 void idTrigger_Touch::Restore( idRestoreGame *savefile ) {
1105 savefile->ReadClipModel( clipModel );
1110 idTrigger_Touch::TouchEntities
1113 void idTrigger_Touch::TouchEntities( void ) {
1114 int numClipModels, i;
1116 idClipModel *cm, *clipModelList[ MAX_GENTITIES ];
1118 if ( clipModel == NULL || scriptFunction == NULL ) {
1122 bounds.FromTransformedBounds( clipModel->GetBounds(), clipModel->GetOrigin(), clipModel->GetAxis() );
1123 numClipModels = gameLocal.clip.ClipModelsTouchingBounds( bounds, -1, clipModelList, MAX_GENTITIES );
1125 for ( i = 0; i < numClipModels; i++ ) {
1126 cm = clipModelList[ i ];
1128 if ( !cm->IsTraceModel() ) {
1132 idEntity *entity = cm->GetEntity();
1138 if ( !gameLocal.clip.ContentsModel( cm->GetOrigin(), cm, cm->GetAxis(), -1,
1139 clipModel->Handle(), clipModel->GetOrigin(), clipModel->GetAxis() ) ) {
1143 ActivateTargets( entity );
1145 idThread *thread = new idThread();
1146 thread->CallFunction( entity, scriptFunction, false );
1147 thread->DelayedStart( 0 );
1153 idTrigger_Touch::Think
1156 void idTrigger_Touch::Think( void ) {
1157 if ( thinkFlags & TH_THINK ) {
1165 idTrigger_Touch::Event_Trigger
1168 void idTrigger_Touch::Event_Trigger( idEntity *activator ) {
1169 if ( thinkFlags & TH_THINK ) {
1170 BecomeInactive( TH_THINK );
1172 BecomeActive( TH_THINK );
1178 idTrigger_Touch::Enable
1181 void idTrigger_Touch::Enable( void ) {
1182 BecomeActive( TH_THINK );
1187 idTrigger_Touch::Disable
1190 void idTrigger_Touch::Disable( void ) {
1191 BecomeInactive( TH_THINK );