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 ===========================================================================
30 Invisible entities that affect other entities or the world when activated.
34 #include "../idlib/precompiled.h"
37 #include "Game_local.h"
40 ===============================================================================
44 ===============================================================================
47 CLASS_DECLARATION( idEntity, idTarget )
52 ===============================================================================
56 ===============================================================================
59 CLASS_DECLARATION( idTarget, idTarget_Remove )
60 EVENT( EV_Activate, idTarget_Remove::Event_Activate )
65 idTarget_Remove::Event_Activate
68 void idTarget_Remove::Event_Activate( idEntity *activator ) {
72 for( i = 0; i < targets.Num(); i++ ) {
73 ent = targets[ i ].GetEntity();
75 ent->PostEventMS( &EV_Remove, 0 );
79 // delete our self when done
80 PostEventMS( &EV_Remove, 0 );
85 ===============================================================================
89 ===============================================================================
92 CLASS_DECLARATION( idTarget, idTarget_Show )
93 EVENT( EV_Activate, idTarget_Show::Event_Activate )
98 idTarget_Show::Event_Activate
101 void idTarget_Show::Event_Activate( idEntity *activator ) {
105 for( i = 0; i < targets.Num(); i++ ) {
106 ent = targets[ i ].GetEntity();
112 // delete our self when done
113 PostEventMS( &EV_Remove, 0 );
118 ===============================================================================
122 ===============================================================================
125 CLASS_DECLARATION( idTarget, idTarget_Damage )
126 EVENT( EV_Activate, idTarget_Damage::Event_Activate )
131 idTarget_Damage::Event_Activate
134 void idTarget_Damage::Event_Activate( idEntity *activator ) {
139 damage = spawnArgs.GetString( "def_damage", "damage_generic" );
140 for( i = 0; i < targets.Num(); i++ ) {
141 ent = targets[ i ].GetEntity();
143 ent->Damage( this, this, vec3_origin, damage, 1.0f, INVALID_JOINT );
150 ===============================================================================
152 idTarget_SessionCommand
154 ===============================================================================
157 CLASS_DECLARATION( idTarget, idTarget_SessionCommand )
158 EVENT( EV_Activate, idTarget_SessionCommand::Event_Activate )
163 idTarget_SessionCommand::Event_Activate
166 void idTarget_SessionCommand::Event_Activate( idEntity *activator ) {
167 gameLocal.sessionCommand = spawnArgs.GetString( "command" );
172 ===============================================================================
176 Just a modified form of idTarget_SessionCommand
177 ===============================================================================
180 CLASS_DECLARATION( idTarget, idTarget_EndLevel )
181 EVENT( EV_Activate, idTarget_EndLevel::Event_Activate )
186 idTarget_EndLevel::Event_Activate
189 void idTarget_EndLevel::Event_Activate( idEntity *activator ) {
193 if ( spawnArgs.GetBool( "endOfGame" ) ) {
194 cvarSystem->SetCVarBool( "g_nightmare", true );
195 gameLocal.sessionCommand = "endofDemo";
199 if ( spawnArgs.GetBool( "endOfGame" ) ) {
200 cvarSystem->SetCVarBool( "g_nightmare", true );
201 gameLocal.sessionCommand = "disconnect";
205 if ( !spawnArgs.GetString( "nextMap", "", nextMap ) ) {
206 gameLocal.Printf( "idTarget_SessionCommand::Event_Activate: no nextMap key\n" );
210 if ( spawnArgs.GetInt( "devmap", "0" ) ) {
211 gameLocal.sessionCommand = "devmap "; // only for special demos
213 gameLocal.sessionCommand = "map ";
216 gameLocal.sessionCommand += nextMap;
221 ===============================================================================
223 idTarget_WaitForButton
225 ===============================================================================
228 CLASS_DECLARATION( idTarget, idTarget_WaitForButton )
229 EVENT( EV_Activate, idTarget_WaitForButton::Event_Activate )
234 idTarget_WaitForButton::Event_Activate
237 void idTarget_WaitForButton::Event_Activate( idEntity *activator ) {
238 if ( thinkFlags & TH_THINK ) {
239 BecomeInactive( TH_THINK );
241 // always allow during cinematics
243 BecomeActive( TH_THINK );
249 idTarget_WaitForButton::Think
252 void idTarget_WaitForButton::Think( void ) {
255 if ( thinkFlags & TH_THINK ) {
256 player = gameLocal.GetLocalPlayer();
257 if ( player && ( !player->oldButtons & BUTTON_ATTACK ) && ( player->usercmd.buttons & BUTTON_ATTACK ) ) {
258 player->usercmd.buttons &= ~BUTTON_ATTACK;
259 BecomeInactive( TH_THINK );
260 ActivateTargets( player );
263 BecomeInactive( TH_ALL );
269 ===============================================================================
271 idTarget_SetGlobalShaderParm
273 ===============================================================================
276 CLASS_DECLARATION( idTarget, idTarget_SetGlobalShaderTime )
277 EVENT( EV_Activate, idTarget_SetGlobalShaderTime::Event_Activate )
282 idTarget_SetGlobalShaderTime::Event_Activate
285 void idTarget_SetGlobalShaderTime::Event_Activate( idEntity *activator ) {
286 int parm = spawnArgs.GetInt( "globalParm" );
287 float time = -MS2SEC( gameLocal.time );
288 if ( parm >= 0 && parm < MAX_GLOBAL_SHADER_PARMS ) {
289 gameLocal.globalShaderParms[parm] = time;
294 ===============================================================================
296 idTarget_SetShaderParm
298 ===============================================================================
301 CLASS_DECLARATION( idTarget, idTarget_SetShaderParm )
302 EVENT( EV_Activate, idTarget_SetShaderParm::Event_Activate )
307 idTarget_SetShaderParm::Event_Activate
310 void idTarget_SetShaderParm::Event_Activate( idEntity *activator ) {
317 // set the color on the targets
318 if ( spawnArgs.GetVector( "_color", "1 1 1", color ) ) {
319 for( i = 0; i < targets.Num(); i++ ) {
320 ent = targets[ i ].GetEntity();
322 ent->SetColor( color[ 0 ], color[ 1 ], color[ 2 ] );
327 // set any shader parms on the targets
328 for( parmnum = 0; parmnum < MAX_ENTITY_SHADER_PARMS; parmnum++ ) {
329 if ( spawnArgs.GetFloat( va( "shaderParm%d", parmnum ), "0", value ) ) {
330 for( i = 0; i < targets.Num(); i++ ) {
331 ent = targets[ i ].GetEntity();
333 ent->SetShaderParm( parmnum, value );
336 if (spawnArgs.GetBool("toggle") && (value == 0 || value == 1)) {
340 spawnArgs.SetFloat(va("shaderParm%d", parmnum), value);
348 ===============================================================================
350 idTarget_SetShaderTime
352 ===============================================================================
355 CLASS_DECLARATION( idTarget, idTarget_SetShaderTime )
356 EVENT( EV_Activate, idTarget_SetShaderTime::Event_Activate )
361 idTarget_SetShaderTime::Event_Activate
364 void idTarget_SetShaderTime::Event_Activate( idEntity *activator ) {
369 time = -MS2SEC( gameLocal.time );
370 for( i = 0; i < targets.Num(); i++ ) {
371 ent = targets[ i ].GetEntity();
373 ent->SetShaderParm( SHADERPARM_TIMEOFFSET, time );
374 if ( ent->IsType( idLight::Type ) ) {
375 static_cast<idLight *>(ent)->SetLightParm( SHADERPARM_TIMEOFFSET, time );
382 ===============================================================================
386 ===============================================================================
389 CLASS_DECLARATION( idTarget, idTarget_FadeEntity )
390 EVENT( EV_Activate, idTarget_FadeEntity::Event_Activate )
395 idTarget_FadeEntity::idTarget_FadeEntity
398 idTarget_FadeEntity::idTarget_FadeEntity( void ) {
406 idTarget_FadeEntity::Save
409 void idTarget_FadeEntity::Save( idSaveGame *savefile ) const {
410 savefile->WriteVec4( fadeFrom );
411 savefile->WriteInt( fadeStart );
412 savefile->WriteInt( fadeEnd );
417 idTarget_FadeEntity::Restore
420 void idTarget_FadeEntity::Restore( idRestoreGame *savefile ) {
421 savefile->ReadVec4( fadeFrom );
422 savefile->ReadInt( fadeStart );
423 savefile->ReadInt( fadeEnd );
428 idTarget_FadeEntity::Event_Activate
431 void idTarget_FadeEntity::Event_Activate( idEntity *activator ) {
435 if ( !targets.Num() ) {
439 // always allow during cinematics
441 BecomeActive( TH_THINK );
444 for( i = 0; i < targets.Num(); i++ ) {
445 ent = targets[ i ].GetEntity();
447 ent->GetColor( fadeFrom );
452 fadeStart = gameLocal.time;
453 fadeEnd = gameLocal.time + SEC2MS( spawnArgs.GetFloat( "fadetime" ) );
458 idTarget_FadeEntity::Think
461 void idTarget_FadeEntity::Think( void ) {
468 if ( thinkFlags & TH_THINK ) {
470 if ( gameLocal.time >= fadeEnd ) {
472 BecomeInactive( TH_THINK );
474 frac = ( float )( gameLocal.time - fadeStart ) / ( float )( fadeEnd - fadeStart );
475 color.Lerp( fadeFrom, fadeTo, frac );
478 // set the color on the targets
479 for( i = 0; i < targets.Num(); i++ ) {
480 ent = targets[ i ].GetEntity();
482 ent->SetColor( color );
486 BecomeInactive( TH_ALL );
491 ===============================================================================
495 ===============================================================================
498 CLASS_DECLARATION( idTarget, idTarget_LightFadeIn )
499 EVENT( EV_Activate, idTarget_LightFadeIn::Event_Activate )
504 idTarget_LightFadeIn::Event_Activate
507 void idTarget_LightFadeIn::Event_Activate( idEntity *activator ) {
513 if ( !targets.Num() ) {
517 time = spawnArgs.GetFloat( "fadetime" );
519 for( i = 0; i < targets.Num(); i++ ) {
520 ent = targets[ i ].GetEntity();
524 if ( ent->IsType( idLight::Type ) ) {
525 light = static_cast<idLight *>( ent );
526 light->FadeIn( time );
528 gameLocal.Printf( "'%s' targets non-light '%s'", name.c_str(), ent->GetName() );
534 ===============================================================================
536 idTarget_LightFadeOut
538 ===============================================================================
541 CLASS_DECLARATION( idTarget, idTarget_LightFadeOut )
542 EVENT( EV_Activate, idTarget_LightFadeOut::Event_Activate )
547 idTarget_LightFadeOut::Event_Activate
550 void idTarget_LightFadeOut::Event_Activate( idEntity *activator ) {
556 if ( !targets.Num() ) {
560 time = spawnArgs.GetFloat( "fadetime" );
562 for( i = 0; i < targets.Num(); i++ ) {
563 ent = targets[ i ].GetEntity();
567 if ( ent->IsType( idLight::Type ) ) {
568 light = static_cast<idLight *>( ent );
569 light->FadeOut( time );
571 gameLocal.Printf( "'%s' targets non-light '%s'", name.c_str(), ent->GetName() );
577 ===============================================================================
581 ===============================================================================
584 CLASS_DECLARATION( idTarget, idTarget_Give )
585 EVENT( EV_Activate, idTarget_Give::Event_Activate )
593 void idTarget_Give::Spawn( void ) {
594 if ( spawnArgs.GetBool( "onSpawn" ) ) {
595 PostEventMS( &EV_Activate, 50 );
601 idTarget_Give::Event_Activate
604 void idTarget_Give::Event_Activate( idEntity *activator ) {
606 if ( spawnArgs.GetBool( "development" ) && developer.GetInteger() == 0 ) {
610 static int giveNum = 0;
611 idPlayer *player = gameLocal.GetLocalPlayer();
613 const idKeyValue *kv = spawnArgs.MatchPrefix( "item", NULL );
615 const idDict *dict = gameLocal.FindEntityDefDict( kv->GetValue(), false );
619 d2.Set( "name", va( "givenitem_%i", giveNum++ ) );
620 idEntity *ent = NULL;
621 if ( gameLocal.SpawnEntityDef( d2, &ent ) && ent && ent->IsType( idItem::Type ) ) {
622 idItem *item = static_cast<idItem*>(ent);
623 item->GiveToPlayer( gameLocal.GetLocalPlayer() );
626 kv = spawnArgs.MatchPrefix( "item", kv );
632 ===============================================================================
636 ===============================================================================
639 CLASS_DECLARATION( idTarget, idTarget_GiveEmail )
640 EVENT( EV_Activate, idTarget_GiveEmail::Event_Activate )
645 idTarget_GiveEmail::Spawn
648 void idTarget_GiveEmail::Spawn( void ) {
653 idTarget_GiveEmail::Event_Activate
656 void idTarget_GiveEmail::Event_Activate( idEntity *activator ) {
657 idPlayer *player = gameLocal.GetLocalPlayer();
658 const idDeclPDA *pda = player->GetPDA();
660 player->GiveEmail( spawnArgs.GetString( "email" ) );
662 player->ShowTip( spawnArgs.GetString( "text_infoTitle" ), spawnArgs.GetString( "text_PDANeeded" ), true );
668 ===============================================================================
672 ===============================================================================
675 CLASS_DECLARATION( idTarget, idTarget_SetModel )
676 EVENT( EV_Activate, idTarget_SetModel::Event_Activate )
681 idTarget_SetModel::Spawn
684 void idTarget_SetModel::Spawn( void ) {
687 model = spawnArgs.GetString( "newmodel" );
688 if ( declManager->FindType( DECL_MODELDEF, model, false ) == NULL ) {
689 // precache the render model
690 renderModelManager->FindModel( model );
691 // precache .cm files only
692 collisionModelManager->LoadModel( model, true );
698 idTarget_SetModel::Event_Activate
701 void idTarget_SetModel::Event_Activate( idEntity *activator ) {
702 for( int i = 0; i < targets.Num(); i++ ) {
703 idEntity *ent = targets[ i ].GetEntity();
705 ent->SetModel( spawnArgs.GetString( "newmodel" ) );
712 ===============================================================================
714 idTarget_SetInfluence
716 ===============================================================================
719 const idEventDef EV_RestoreInfluence( "<RestoreInfluece>" );
720 const idEventDef EV_GatherEntities( "<GatherEntities>" );
721 const idEventDef EV_Flash( "<Flash>", "fd" );
722 const idEventDef EV_ClearFlash( "<ClearFlash>", "f" );
724 CLASS_DECLARATION( idTarget, idTarget_SetInfluence )
725 EVENT( EV_Activate, idTarget_SetInfluence::Event_Activate )
726 EVENT( EV_RestoreInfluence, idTarget_SetInfluence::Event_RestoreInfluence )
727 EVENT( EV_GatherEntities, idTarget_SetInfluence::Event_GatherEntities )
728 EVENT( EV_Flash, idTarget_SetInfluence::Event_Flash )
729 EVENT( EV_ClearFlash, idTarget_SetInfluence::Event_ClearFlash )
734 idTarget_SetInfluence::idTarget_SetInfluence
737 idTarget_SetInfluence::idTarget_SetInfluence( void ) {
741 switchToCamera = NULL;
743 restoreOnTrigger = false;
748 idTarget_SetInfluence::Save
751 void idTarget_SetInfluence::Save( idSaveGame *savefile ) const {
754 savefile->WriteInt( lightList.Num() );
755 for( i = 0; i < lightList.Num(); i++ ) {
756 savefile->WriteInt( lightList[ i ] );
759 savefile->WriteInt( guiList.Num() );
760 for( i = 0; i < guiList.Num(); i++ ) {
761 savefile->WriteInt( guiList[ i ] );
764 savefile->WriteInt( soundList.Num() );
765 for( i = 0; i < soundList.Num(); i++ ) {
766 savefile->WriteInt( soundList[ i ] );
769 savefile->WriteInt( genericList.Num() );
770 for( i = 0; i < genericList.Num(); i++ ) {
771 savefile->WriteInt( genericList[ i ] );
774 savefile->WriteFloat( flashIn );
775 savefile->WriteFloat( flashOut );
777 savefile->WriteFloat( delay );
779 savefile->WriteString( flashInSound );
780 savefile->WriteString( flashOutSound );
782 savefile->WriteObject( switchToCamera );
784 savefile->WriteFloat( fovSetting.GetStartTime() );
785 savefile->WriteFloat( fovSetting.GetDuration() );
786 savefile->WriteFloat( fovSetting.GetStartValue() );
787 savefile->WriteFloat( fovSetting.GetEndValue() );
789 savefile->WriteBool( soundFaded );
790 savefile->WriteBool( restoreOnTrigger );
793 savefile->WriteInt( savedGuiList.Num() );
794 for( i = 0; i < savedGuiList.Num(); i++ ) {
795 for(int j = 0; j < MAX_RENDERENTITY_GUI; j++) {
796 savefile->WriteUserInterface(savedGuiList[i].gui[j], savedGuiList[i].gui[j] ? savedGuiList[i].gui[j]->IsUniqued() : false);
804 idTarget_SetInfluence::Restore
807 void idTarget_SetInfluence::Restore( idRestoreGame *savefile ) {
812 savefile->ReadInt( num );
813 for( i = 0; i < num; i++ ) {
814 savefile->ReadInt( itemNum );
815 lightList.Append( itemNum );
818 savefile->ReadInt( num );
819 for( i = 0; i < num; i++ ) {
820 savefile->ReadInt( itemNum );
821 guiList.Append( itemNum );
824 savefile->ReadInt( num );
825 for( i = 0; i < num; i++ ) {
826 savefile->ReadInt( itemNum );
827 soundList.Append( itemNum );
830 savefile->ReadInt( num );
831 for ( i = 0; i < num; i++ ) {
832 savefile->ReadInt( itemNum );
833 genericList.Append( itemNum );
836 savefile->ReadFloat( flashIn );
837 savefile->ReadFloat( flashOut );
839 savefile->ReadFloat( delay );
841 savefile->ReadString( flashInSound );
842 savefile->ReadString( flashOutSound );
844 savefile->ReadObject( reinterpret_cast<idClass *&>( switchToCamera ) );
846 savefile->ReadFloat( set );
847 fovSetting.SetStartTime( set );
848 savefile->ReadFloat( set );
849 fovSetting.SetDuration( set );
850 savefile->ReadFloat( set );
851 fovSetting.SetStartValue( set );
852 savefile->ReadFloat( set );
853 fovSetting.SetEndValue( set );
855 savefile->ReadBool( soundFaded );
856 savefile->ReadBool( restoreOnTrigger );
859 savefile->ReadInt( num );
860 for( i = 0; i < num; i++ ) {
862 for(int j = 0; j < MAX_RENDERENTITY_GUI; j++) {
863 savefile->ReadUserInterface(temp.gui[j]);
865 savedGuiList.Append( temp );
872 idTarget_SetInfluence::Spawn
875 void idTarget_SetInfluence::Spawn() {
876 PostEventMS( &EV_GatherEntities, 0 );
877 flashIn = spawnArgs.GetFloat( "flashIn", "0" );
878 flashOut = spawnArgs.GetFloat( "flashOut", "0" );
879 flashInSound = spawnArgs.GetString( "snd_flashin" );
880 flashOutSound = spawnArgs.GetString( "snd_flashout" );
881 delay = spawnArgs.GetFloat( "delay" );
883 restoreOnTrigger = false;
885 // always allow during cinematics
891 idTarget_SetInfluence::Event_Flash
894 void idTarget_SetInfluence::Event_Flash( float flash, int out ) {
895 idPlayer *player = gameLocal.GetLocalPlayer();
896 player->playerView.Fade( idVec4( 1, 1, 1, 1 ), flash );
897 const idSoundShader *shader = NULL;
898 if ( !out && flashInSound.Length() ){
899 shader = declManager->FindSound( flashInSound );
900 player->StartSoundShader( shader, SND_CHANNEL_VOICE, 0, false, NULL );
901 } else if ( out && ( flashOutSound.Length() || flashInSound.Length() ) ) {
902 shader = declManager->FindSound( flashOutSound.Length() ? flashOutSound : flashInSound );
903 player->StartSoundShader( shader, SND_CHANNEL_VOICE, 0, false, NULL );
905 PostEventSec( &EV_ClearFlash, flash, flash );
911 idTarget_SetInfluence::Event_ClearFlash
914 void idTarget_SetInfluence::Event_ClearFlash( float flash ) {
915 idPlayer *player = gameLocal.GetLocalPlayer();
916 player->playerView.Fade( vec4_zero , flash );
920 idTarget_SetInfluence::Event_GatherEntities
923 void idTarget_SetInfluence::Event_GatherEntities() {
924 int i, listedEntities;
925 idEntity *entityList[ MAX_GENTITIES ];
927 bool demonicOnly = spawnArgs.GetBool( "effect_demonic" );
928 bool lights = spawnArgs.GetBool( "effect_lights" );
929 bool sounds = spawnArgs.GetBool( "effect_sounds" );
930 bool guis = spawnArgs.GetBool( "effect_guis" );
931 bool models = spawnArgs.GetBool( "effect_models" );
932 bool vision = spawnArgs.GetBool( "effect_vision" );
933 bool targetsOnly = spawnArgs.GetBool( "targetsOnly" );
939 savedGuiList.Clear();
942 if ( spawnArgs.GetBool( "effect_all" ) ) {
943 lights = sounds = guis = models = vision = true;
947 listedEntities = targets.Num();
948 for ( i = 0; i < listedEntities; i++ ) {
949 entityList[i] = targets[i].GetEntity();
952 float radius = spawnArgs.GetFloat( "radius" );
953 listedEntities = gameLocal.EntitiesWithinRadius( GetPhysics()->GetOrigin(), radius, entityList, MAX_GENTITIES );
956 for( i = 0; i < listedEntities; i++ ) {
957 idEntity *ent = entityList[ i ];
959 if ( lights && ent->IsType( idLight::Type ) && ent->spawnArgs.FindKey( "color_demonic" ) ) {
960 lightList.Append( ent->entityNumber );
963 if ( sounds && ent->IsType( idSound::Type ) && ent->spawnArgs.FindKey( "snd_demonic" ) ) {
964 soundList.Append( ent->entityNumber );
967 if ( guis && ent->GetRenderEntity() && ent->GetRenderEntity()->gui[ 0 ] && ent->spawnArgs.FindKey( "gui_demonic" ) ) {
968 guiList.Append( ent->entityNumber );
971 savedGuiList.Append(temp);
975 if ( ent->IsType( idStaticEntity::Type ) && ent->spawnArgs.FindKey( "color_demonic" ) ) {
976 genericList.Append( ent->entityNumber );
982 temp = spawnArgs.GetString( "switchToView" );
983 switchToCamera = ( temp.Length() ) ? gameLocal.FindEntity( temp ) : NULL;
989 idTarget_SetInfluence::Event_Activate
992 void idTarget_SetInfluence::Event_Activate( idEntity *activator ) {
997 idStaticEntity *generic;
1005 player = gameLocal.GetLocalPlayer();
1007 if ( spawnArgs.GetBool( "triggerActivate" ) ) {
1008 if ( restoreOnTrigger ) {
1009 ProcessEvent( &EV_RestoreInfluence );
1010 restoreOnTrigger = false;
1013 restoreOnTrigger = true;
1016 float fadeTime = spawnArgs.GetFloat( "fadeWorldSounds" );
1018 if ( delay > 0.0f ) {
1019 PostEventSec( &EV_Activate, delay, activator );
1021 // start any sound fading now
1023 gameSoundWorld->FadeSoundClasses( 0, -40.0f, fadeTime );
1027 } else if ( fadeTime && !soundFaded ) {
1028 gameSoundWorld->FadeSoundClasses( 0, -40.0f, fadeTime );
1032 if ( spawnArgs.GetBool( "triggerTargets" ) ) {
1033 ActivateTargets( activator );
1037 PostEventSec( &EV_Flash, 0.0f, flashIn, 0 );
1040 parm = spawnArgs.GetString( "snd_influence" );
1041 if ( parm && *parm ) {
1042 PostEventSec( &EV_StartSoundShader, flashIn, parm, SND_CHANNEL_ANY );
1045 if ( switchToCamera ) {
1046 switchToCamera->PostEventSec( &EV_Activate, flashIn + 0.05f, this );
1049 int fov = spawnArgs.GetInt( "fov" );
1051 fovSetting.Init( gameLocal.time, SEC2MS( spawnArgs.GetFloat( "fovTime" ) ), player->DefaultFov(), fov );
1052 BecomeActive( TH_THINK );
1055 for ( i = 0; i < genericList.Num(); i++ ) {
1056 ent = gameLocal.entities[genericList[i]];
1057 if ( ent == NULL ) {
1060 generic = static_cast<idStaticEntity*>( ent );
1061 color = generic->spawnArgs.GetVector( "color_demonic" );
1062 colorTo.Set( color.x, color.y, color.z, 1.0f );
1063 generic->Fade( colorTo, spawnArgs.GetFloat( "fade_time", "0.25" ) );
1066 for ( i = 0; i < lightList.Num(); i++ ) {
1067 ent = gameLocal.entities[lightList[i]];
1068 if ( ent == NULL || !ent->IsType( idLight::Type ) ) {
1071 light = static_cast<idLight *>(ent);
1072 parm = light->spawnArgs.GetString( "mat_demonic" );
1073 if ( parm && *parm ) {
1074 light->SetShader( parm );
1077 color = light->spawnArgs.GetVector( "_color" );
1078 color = light->spawnArgs.GetVector( "color_demonic", color.ToString() );
1079 colorTo.Set( color.x, color.y, color.z, 1.0f );
1080 light->Fade( colorTo, spawnArgs.GetFloat( "fade_time", "0.25" ) );
1083 for ( i = 0; i < soundList.Num(); i++ ) {
1084 ent = gameLocal.entities[soundList[i]];
1085 if ( ent == NULL || !ent->IsType( idSound::Type ) ) {
1088 sound = static_cast<idSound *>(ent);
1089 parm = sound->spawnArgs.GetString( "snd_demonic" );
1090 if ( parm && *parm ) {
1091 if ( sound->spawnArgs.GetBool( "overlayDemonic" ) ) {
1092 sound->StartSound( "snd_demonic", SND_CHANNEL_DEMONIC, 0, false, NULL );
1094 sound->StopSound( SND_CHANNEL_ANY, false );
1095 sound->SetSound( parm );
1100 for ( i = 0; i < guiList.Num(); i++ ) {
1101 ent = gameLocal.entities[guiList[i]];
1102 if ( ent == NULL || ent->GetRenderEntity() == NULL ) {
1107 for ( j = 0; j < MAX_RENDERENTITY_GUI; j++ ) {
1108 if ( ent->GetRenderEntity()->gui[ j ] && ent->spawnArgs.FindKey( j == 0 ? "gui_demonic" : va( "gui_demonic%d", j+1 ) ) ) {
1110 //Backup the old one
1111 savedGuiList[i].gui[j] = ent->GetRenderEntity()->gui[ j ];
1113 ent->GetRenderEntity()->gui[ j ] = uiManager->FindGui( ent->spawnArgs.GetString( j == 0 ? "gui_demonic" : va( "gui_demonic%d", j+1 ) ), true );
1119 ent->UpdateVisuals();
1124 player->SetInfluenceLevel( spawnArgs.GetInt( "influenceLevel" ) );
1126 int snapAngle = spawnArgs.GetInt( "snapAngle" );
1128 idAngles ang( 0, snapAngle, 0 );
1129 player->SetViewAngles( ang );
1130 player->SetAngles( ang );
1133 if ( spawnArgs.GetBool( "effect_vision" ) ) {
1134 parm = spawnArgs.GetString( "mtrVision" );
1135 skin = spawnArgs.GetString( "skinVision" );
1136 player->SetInfluenceView( parm, skin, spawnArgs.GetInt( "visionRadius" ), this );
1139 parm = spawnArgs.GetString( "mtrWorld" );
1140 if ( parm && *parm ) {
1141 gameLocal.SetGlobalMaterial( declManager->FindMaterial( parm ) );
1144 if ( !restoreOnTrigger ) {
1145 PostEventMS( &EV_RestoreInfluence, SEC2MS( spawnArgs.GetFloat( "time" ) ) );
1151 idTarget_SetInfluence::Think
1154 void idTarget_SetInfluence::Think( void ) {
1155 if ( thinkFlags & TH_THINK ) {
1156 idPlayer *player = gameLocal.GetLocalPlayer();
1157 player->SetInfluenceFov( fovSetting.GetCurrentValue( gameLocal.time ) );
1158 if ( fovSetting.IsDone( gameLocal.time ) ) {
1159 if ( !spawnArgs.GetBool( "leaveFOV" ) ) {
1160 player->SetInfluenceFov( 0 );
1162 BecomeInactive( TH_THINK );
1165 BecomeInactive( TH_ALL );
1172 idTarget_SetInfluence::Event_RestoreInfluence
1175 void idTarget_SetInfluence::Event_RestoreInfluence() {
1180 idStaticEntity *generic;
1186 PostEventSec( &EV_Flash, 0.0f, flashOut, 1 );
1189 if ( switchToCamera ) {
1190 switchToCamera->PostEventMS( &EV_Activate, 0.0f, this );
1193 for ( i = 0; i < genericList.Num(); i++ ) {
1194 ent = gameLocal.entities[genericList[i]];
1195 if ( ent == NULL ) {
1198 generic = static_cast<idStaticEntity*>( ent );
1199 colorTo.Set( 1.0f, 1.0f, 1.0f, 1.0f );
1200 generic->Fade( colorTo, spawnArgs.GetFloat( "fade_time", "0.25" ) );
1203 for ( i = 0; i < lightList.Num(); i++ ) {
1204 ent = gameLocal.entities[lightList[i]];
1205 if ( ent == NULL || !ent->IsType( idLight::Type ) ) {
1208 light = static_cast<idLight *>(ent);
1209 if ( !light->spawnArgs.GetBool( "leave_demonic_mat" ) ) {
1210 const char *texture = light->spawnArgs.GetString( "texture", "lights/squarelight1" );
1211 light->SetShader( texture );
1213 color = light->spawnArgs.GetVector( "_color" );
1214 colorTo.Set( color.x, color.y, color.z, 1.0f );
1215 light->Fade( colorTo, spawnArgs.GetFloat( "fade_time", "0.25" ) );
1218 for ( i = 0; i < soundList.Num(); i++ ) {
1219 ent = gameLocal.entities[soundList[i]];
1220 if ( ent == NULL || !ent->IsType( idSound::Type ) ) {
1223 sound = static_cast<idSound *>(ent);
1224 sound->StopSound( SND_CHANNEL_ANY, false );
1225 sound->SetSound( sound->spawnArgs.GetString( "s_shader" ) );
1228 for ( i = 0; i < guiList.Num(); i++ ) {
1229 ent = gameLocal.entities[guiList[i]];
1230 if ( ent == NULL || GetRenderEntity() == NULL ) {
1234 for( j = 0; j < MAX_RENDERENTITY_GUI; j++ ) {
1235 if ( ent->GetRenderEntity()->gui[ j ] ) {
1237 ent->GetRenderEntity()->gui[ j ] = savedGuiList[i].gui[j];
1239 ent->GetRenderEntity()->gui[ j ] = uiManager->FindGui( ent->spawnArgs.GetString( j == 0 ? "gui" : va( "gui%d", j+1 ) ) );
1245 ent->UpdateVisuals();
1250 idPlayer *player = gameLocal.GetLocalPlayer();
1251 player->SetInfluenceLevel( 0 );
1252 player->SetInfluenceView( NULL, NULL, 0.0f, NULL );
1253 player->SetInfluenceFov( 0 );
1254 gameLocal.SetGlobalMaterial( NULL );
1255 float fadeTime = spawnArgs.GetFloat( "fadeWorldSounds" );
1257 gameSoundWorld->FadeSoundClasses( 0, 0.0f, fadeTime / 2.0f );
1263 ===============================================================================
1267 ===============================================================================
1270 CLASS_DECLARATION( idTarget, idTarget_SetKeyVal )
1271 EVENT( EV_Activate, idTarget_SetKeyVal::Event_Activate )
1276 idTarget_SetKeyVal::Event_Activate
1279 void idTarget_SetKeyVal::Event_Activate( idEntity *activator ) {
1283 const idKeyValue *kv;
1286 for( i = 0; i < targets.Num(); i++ ) {
1287 ent = targets[ i ].GetEntity();
1289 kv = spawnArgs.MatchPrefix("keyval");
1291 n = kv->GetValue().Find( ";" );
1293 key = kv->GetValue().Left( n );
1294 val = kv->GetValue().Right( kv->GetValue().Length() - n - 1 );
1295 ent->spawnArgs.Set( key, val );
1296 for ( int j = 0; j < MAX_RENDERENTITY_GUI; j++ ) {
1297 if ( ent->GetRenderEntity()->gui[ j ] ) {
1298 if ( idStr::Icmpn( key, "gui_", 4 ) == 0 ) {
1299 ent->GetRenderEntity()->gui[ j ]->SetStateString( key, val );
1300 ent->GetRenderEntity()->gui[ j ]->StateChanged( gameLocal.time );
1305 kv = spawnArgs.MatchPrefix( "keyval", kv );
1307 ent->UpdateChangeableSpawnArgs( NULL );
1308 ent->UpdateVisuals();
1315 ===============================================================================
1319 ===============================================================================
1322 CLASS_DECLARATION( idTarget, idTarget_SetFov )
1323 EVENT( EV_Activate, idTarget_SetFov::Event_Activate )
1329 idTarget_SetFov::Save
1332 void idTarget_SetFov::Save( idSaveGame *savefile ) const {
1334 savefile->WriteFloat( fovSetting.GetStartTime() );
1335 savefile->WriteFloat( fovSetting.GetDuration() );
1336 savefile->WriteFloat( fovSetting.GetStartValue() );
1337 savefile->WriteFloat( fovSetting.GetEndValue() );
1342 idTarget_SetFov::Restore
1345 void idTarget_SetFov::Restore( idRestoreGame *savefile ) {
1348 savefile->ReadFloat( setting );
1349 fovSetting.SetStartTime( setting );
1350 savefile->ReadFloat( setting );
1351 fovSetting.SetDuration( setting );
1352 savefile->ReadFloat( setting );
1353 fovSetting.SetStartValue( setting );
1354 savefile->ReadFloat( setting );
1355 fovSetting.SetEndValue( setting );
1357 fovSetting.GetCurrentValue( gameLocal.time );
1362 idTarget_SetFov::Event_Activate
1365 void idTarget_SetFov::Event_Activate( idEntity *activator ) {
1366 // always allow during cinematics
1369 idPlayer *player = gameLocal.GetLocalPlayer();
1370 fovSetting.Init( gameLocal.time, SEC2MS( spawnArgs.GetFloat( "time" ) ), player ? player->DefaultFov() : g_fov.GetFloat(), spawnArgs.GetFloat( "fov" ) );
1371 BecomeActive( TH_THINK );
1376 idTarget_SetFov::Think
1379 void idTarget_SetFov::Think( void ) {
1380 if ( thinkFlags & TH_THINK ) {
1381 idPlayer *player = gameLocal.GetLocalPlayer();
1382 player->SetInfluenceFov( fovSetting.GetCurrentValue( gameLocal.time ) );
1383 if ( fovSetting.IsDone( gameLocal.time ) ) {
1384 player->SetInfluenceFov( 0.0f );
1385 BecomeInactive( TH_THINK );
1388 BecomeInactive( TH_ALL );
1394 ===============================================================================
1396 idTarget_SetPrimaryObjective
1398 ===============================================================================
1401 CLASS_DECLARATION( idTarget, idTarget_SetPrimaryObjective )
1402 EVENT( EV_Activate, idTarget_SetPrimaryObjective::Event_Activate )
1407 idTarget_SetPrimaryObjective::Event_Activate
1410 void idTarget_SetPrimaryObjective::Event_Activate( idEntity *activator ) {
1411 idPlayer *player = gameLocal.GetLocalPlayer();
1412 if ( player && player->objectiveSystem ) {
1413 player->objectiveSystem->SetStateString( "missionobjective", spawnArgs.GetString( "text", common->GetLanguageDict()->GetString( "#str_04253" ) ) );
1418 ===============================================================================
1422 ===============================================================================
1425 CLASS_DECLARATION( idTarget, idTarget_LockDoor )
1426 EVENT( EV_Activate, idTarget_LockDoor::Event_Activate )
1431 idTarget_LockDoor::Event_Activate
1434 void idTarget_LockDoor::Event_Activate( idEntity *activator ) {
1439 lock = spawnArgs.GetInt( "locked", "1" );
1440 for( i = 0; i < targets.Num(); i++ ) {
1441 ent = targets[ i ].GetEntity();
1442 if ( ent && ent->IsType( idDoor::Type ) ) {
1443 if ( static_cast<idDoor *>( ent )->IsLocked() ) {
1444 static_cast<idDoor *>( ent )->Lock( 0 );
1446 static_cast<idDoor *>( ent )->Lock( lock );
1453 ===============================================================================
1455 idTarget_CallObjectFunction
1457 ===============================================================================
1460 CLASS_DECLARATION( idTarget, idTarget_CallObjectFunction )
1461 EVENT( EV_Activate, idTarget_CallObjectFunction::Event_Activate )
1466 idTarget_CallObjectFunction::Event_Activate
1469 void idTarget_CallObjectFunction::Event_Activate( idEntity *activator ) {
1472 const function_t *func;
1473 const char *funcName;
1476 funcName = spawnArgs.GetString( "call" );
1477 for( i = 0; i < targets.Num(); i++ ) {
1478 ent = targets[ i ].GetEntity();
1479 if ( ent && ent->scriptObject.HasObject() ) {
1480 func = ent->scriptObject.GetFunction( funcName );
1482 gameLocal.Error( "Function '%s' not found on entity '%s' for function call from '%s'", funcName, ent->name.c_str(), name.c_str() );
1484 if ( func->type->NumParameters() != 1 ) {
1485 gameLocal.Error( "Function '%s' on entity '%s' has the wrong number of parameters for function call from '%s'", funcName, ent->name.c_str(), name.c_str() );
1487 if ( !ent->scriptObject.GetTypeDef()->Inherits( func->type->GetParmType( 0 ) ) ) {
1488 gameLocal.Error( "Function '%s' on entity '%s' is the wrong type for function call from '%s'", funcName, ent->name.c_str(), name.c_str() );
1490 // create a thread and call the function
1491 thread = new idThread();
1492 thread->CallFunction( ent, func, true );
1500 ===============================================================================
1502 idTarget_EnableLevelWeapons
1504 ===============================================================================
1507 CLASS_DECLARATION( idTarget, idTarget_EnableLevelWeapons )
1508 EVENT( EV_Activate, idTarget_EnableLevelWeapons::Event_Activate )
1513 idTarget_EnableLevelWeapons::Event_Activate
1516 void idTarget_EnableLevelWeapons::Event_Activate( idEntity *activator ) {
1520 gameLocal.world->spawnArgs.SetBool( "no_Weapons", spawnArgs.GetBool( "disable" ) );
1522 if ( spawnArgs.GetBool( "disable" ) ) {
1523 for( i = 0; i < gameLocal.numClients; i++ ) {
1524 if ( gameLocal.entities[ i ] ) {
1525 gameLocal.entities[ i ]->ProcessEvent( &EV_Player_DisableWeapon );
1529 weap = spawnArgs.GetString( "weapon" );
1530 for( i = 0; i < gameLocal.numClients; i++ ) {
1531 if ( gameLocal.entities[ i ] ) {
1532 gameLocal.entities[ i ]->ProcessEvent( &EV_Player_EnableWeapon );
1533 if ( weap && weap[ 0 ] ) {
1534 gameLocal.entities[ i ]->PostEventSec( &EV_Player_SelectWeapon, 0.5f, weap );
1542 ===============================================================================
1546 ===============================================================================
1549 const idEventDef EV_TipOff( "<TipOff>" );
1550 extern const idEventDef EV_GetPlayerPos( "<getplayerpos>" );
1552 CLASS_DECLARATION( idTarget, idTarget_Tip )
1553 EVENT( EV_Activate, idTarget_Tip::Event_Activate )
1554 EVENT( EV_TipOff, idTarget_Tip::Event_TipOff )
1555 EVENT( EV_GetPlayerPos, idTarget_Tip::Event_GetPlayerPos )
1561 idTarget_Tip::idTarget_Tip
1564 idTarget_Tip::idTarget_Tip( void ) {
1573 void idTarget_Tip::Spawn( void ) {
1581 void idTarget_Tip::Save( idSaveGame *savefile ) const {
1582 savefile->WriteVec3( playerPos );
1587 idTarget_Tip::Restore
1590 void idTarget_Tip::Restore( idRestoreGame *savefile ) {
1591 savefile->ReadVec3( playerPos );
1596 idTarget_Tip::Event_Activate
1599 void idTarget_Tip::Event_GetPlayerPos( void ) {
1600 idPlayer *player = gameLocal.GetLocalPlayer();
1602 playerPos = player->GetPhysics()->GetOrigin();
1603 PostEventMS( &EV_TipOff, 100 );
1609 idTarget_Tip::Event_Activate
1612 void idTarget_Tip::Event_Activate( idEntity *activator ) {
1613 idPlayer *player = gameLocal.GetLocalPlayer();
1615 if ( player->IsTipVisible() ) {
1616 PostEventSec( &EV_Activate, 5.1f, activator );
1619 player->ShowTip( spawnArgs.GetString( "text_title" ), spawnArgs.GetString( "text_tip" ), false );
1620 PostEventMS( &EV_GetPlayerPos, 2000 );
1626 idTarget_Tip::Event_TipOff
1629 void idTarget_Tip::Event_TipOff( void ) {
1630 idPlayer *player = gameLocal.GetLocalPlayer();
1632 idVec3 v = player->GetPhysics()->GetOrigin() - playerPos;
1633 if ( v.Length() > 96.0f ) {
1636 PostEventMS( &EV_TipOff, 100 );
1643 ===============================================================================
1645 idTarget_GiveSecurity
1647 ===============================================================================
1650 CLASS_DECLARATION( idTarget, idTarget_GiveSecurity )
1651 EVENT( EV_Activate, idTarget_GiveSecurity::Event_Activate )
1656 idTarget_GiveEmail::Event_Activate
1659 void idTarget_GiveSecurity::Event_Activate( idEntity *activator ) {
1660 idPlayer *player = gameLocal.GetLocalPlayer();
1662 player->GiveSecurity( spawnArgs.GetString( "text_security" ) );
1668 ===============================================================================
1670 idTarget_RemoveWeapons
1672 ===============================================================================
1675 CLASS_DECLARATION( idTarget, idTarget_RemoveWeapons )
1676 EVENT( EV_Activate, idTarget_RemoveWeapons::Event_Activate )
1681 idTarget_RemoveWeapons::Event_Activate
1684 void idTarget_RemoveWeapons::Event_Activate( idEntity *activator ) {
1685 for( int i = 0; i < gameLocal.numClients; i++ ) {
1686 if ( gameLocal.entities[ i ] ) {
1687 idPlayer *player = static_cast< idPlayer* >( gameLocal.entities[i] );
1688 const idKeyValue *kv = spawnArgs.MatchPrefix( "weapon", NULL );
1690 player->RemoveWeapon( kv->GetValue() );
1691 kv = spawnArgs.MatchPrefix( "weapon", kv );
1693 player->SelectWeapon( player->weapon_fists, true );
1700 ===============================================================================
1702 idTarget_LevelTrigger
1704 ===============================================================================
1707 CLASS_DECLARATION( idTarget, idTarget_LevelTrigger )
1708 EVENT( EV_Activate, idTarget_LevelTrigger::Event_Activate )
1713 idTarget_LevelTrigger::Event_Activate
1716 void idTarget_LevelTrigger::Event_Activate( idEntity *activator ) {
1717 for( int i = 0; i < gameLocal.numClients; i++ ) {
1718 if ( gameLocal.entities[ i ] ) {
1719 idPlayer *player = static_cast< idPlayer* >( gameLocal.entities[i] );
1720 player->SetLevelTrigger( spawnArgs.GetString( "levelName" ), spawnArgs.GetString( "triggerName" ) );
1727 ===============================================================================
1729 idTarget_EnableStamina
1731 ===============================================================================
1734 CLASS_DECLARATION( idTarget, idTarget_EnableStamina )
1735 EVENT( EV_Activate, idTarget_EnableStamina::Event_Activate )
1740 idTarget_EnableStamina::Event_Activate
1743 void idTarget_EnableStamina::Event_Activate( idEntity *activator ) {
1744 for( int i = 0; i < gameLocal.numClients; i++ ) {
1745 if ( gameLocal.entities[ i ] ) {
1746 idPlayer *player = static_cast< idPlayer* >( gameLocal.entities[i] );
1747 if ( spawnArgs.GetBool( "enable" ) ) {
1748 pm_stamina.SetFloat( player->spawnArgs.GetFloat( "pm_stamina" ) );
1750 pm_stamina.SetFloat( 0.0f );
1757 ===============================================================================
1759 idTarget_FadeSoundClass
1761 ===============================================================================
1764 const idEventDef EV_RestoreVolume( "<RestoreVolume>" );
1765 CLASS_DECLARATION( idTarget, idTarget_FadeSoundClass )
1766 EVENT( EV_Activate, idTarget_FadeSoundClass::Event_Activate )
1767 EVENT( EV_RestoreVolume, idTarget_FadeSoundClass::Event_RestoreVolume )
1772 idTarget_FadeSoundClass::Event_Activate
1775 void idTarget_FadeSoundClass::Event_Activate( idEntity *activator ) {
1776 float fadeTime = spawnArgs.GetFloat( "fadeTime" );
1777 float fadeDB = spawnArgs.GetFloat( "fadeDB" );
1778 float fadeDuration = spawnArgs.GetFloat( "fadeDuration" );
1779 int fadeClass = spawnArgs.GetInt( "fadeClass" );
1780 // start any sound fading now
1782 gameSoundWorld->FadeSoundClasses( fadeClass, spawnArgs.GetBool( "fadeIn" ) ? fadeDB : 0.0f - fadeDB, fadeTime );
1783 if ( fadeDuration ) {
1784 PostEventSec( &EV_RestoreVolume, fadeDuration );
1791 idTarget_FadeSoundClass::Event_RestoreVolume
1794 void idTarget_FadeSoundClass::Event_RestoreVolume() {
1795 float fadeTime = spawnArgs.GetFloat( "fadeTime" );
1796 float fadeDB = spawnArgs.GetFloat( "fadeDB" );
1797 int fadeClass = spawnArgs.GetInt( "fadeClass" );
1799 gameSoundWorld->FadeSoundClasses( 0, fadeDB, fadeTime );