1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702 |
- /*
- ===========================================================================
- Doom 3 GPL Source Code
- Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
- This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
- Doom 3 Source Code is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
- Doom 3 Source Code is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
- 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.
- 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.
- ===========================================================================
- */
- #include "../idlib/precompiled.h"
- #pragma hdrstop
- #include "Game_local.h"
- /*
- ===============================================================================
- idTrigger
-
- ===============================================================================
- */
- const idEventDef EV_Enable( "enable", NULL );
- const idEventDef EV_Disable( "disable", NULL );
- const idEventDef EV_IsEnabled( "IsEnabled", NULL, 'd' );
- CLASS_DECLARATION( idEntity, idTrigger )
- EVENT( EV_Enable, idTrigger::Event_Enable )
- EVENT( EV_Disable, idTrigger::Event_Disable )
- EVENT( EV_IsEnabled, idTrigger::Event_IsEnabled )
- END_CLASS
- /*
- ================
- idTrigger::DrawDebugInfo
- ================
- */
- void idTrigger::DrawDebugInfo( void ) {
- idMat3 axis = gameLocal.GetLocalPlayer()->viewAngles.ToMat3();
- idVec3 up = axis[ 2 ] * 5.0f;
- idBounds viewTextBounds( gameLocal.GetLocalPlayer()->GetPhysics()->GetOrigin() );
- idBounds viewBounds( gameLocal.GetLocalPlayer()->GetPhysics()->GetOrigin() );
- idBounds box( idVec3( -4.0f, -4.0f, -4.0f ), idVec3( 4.0f, 4.0f, 4.0f ) );
- idEntity *ent;
- idEntity *target;
- int i;
- bool show;
- const function_t *func;
- viewTextBounds.ExpandSelf( 128.0f );
- viewBounds.ExpandSelf( 512.0f );
- for( ent = gameLocal.spawnedEntities.Next(); ent != NULL; ent = ent->spawnNode.Next() ) {
- if ( ent->GetPhysics()->GetContents() & ( CONTENTS_TRIGGER | CONTENTS_FLASHLIGHT_TRIGGER ) ) {
- show = viewBounds.IntersectsBounds( ent->GetPhysics()->GetAbsBounds() );
- if ( !show ) {
- for( i = 0; i < ent->targets.Num(); i++ ) {
- target = ent->targets[ i ].GetEntity();
- if ( target && viewBounds.IntersectsBounds( target->GetPhysics()->GetAbsBounds() ) ) {
- show = true;
- break;
- }
- }
- }
- if ( !show ) {
- continue;
- }
- gameRenderWorld->DebugBounds( colorOrange, ent->GetPhysics()->GetAbsBounds() );
- if ( viewTextBounds.IntersectsBounds( ent->GetPhysics()->GetAbsBounds() ) ) {
- gameRenderWorld->DrawText( ent->name.c_str(), ent->GetPhysics()->GetAbsBounds().GetCenter(), 0.1f, colorWhite, axis, 1 );
- gameRenderWorld->DrawText( ent->GetEntityDefName(), ent->GetPhysics()->GetAbsBounds().GetCenter() + up, 0.1f, colorWhite, axis, 1 );
- if ( ent->IsType( idTrigger::Type ) ) {
- func = static_cast<idTrigger *>( ent )->GetScriptFunction();
- } else {
- func = NULL;
- }
- if ( func ) {
- gameRenderWorld->DrawText( va( "call script '%s'", func->Name() ), ent->GetPhysics()->GetAbsBounds().GetCenter() - up, 0.1f, colorWhite, axis, 1 );
- }
- }
- for( i = 0; i < ent->targets.Num(); i++ ) {
- target = ent->targets[ i ].GetEntity();
- if ( target ) {
- gameRenderWorld->DebugArrow( colorYellow, ent->GetPhysics()->GetAbsBounds().GetCenter(), target->GetPhysics()->GetOrigin(), 10, 0 );
- gameRenderWorld->DebugBounds( colorGreen, box, target->GetPhysics()->GetOrigin() );
- if ( viewTextBounds.IntersectsBounds( target->GetPhysics()->GetAbsBounds() ) ) {
- gameRenderWorld->DrawText( target->name.c_str(), target->GetPhysics()->GetAbsBounds().GetCenter(), 0.1f, colorWhite, axis, 1 );
- }
- }
- }
- }
- }
- }
- /*
- ================
- idTrigger::Enable
- ================
- */
- void idTrigger::Enable( void ) {
- GetPhysics()->SetContents( CONTENTS_TRIGGER );
- GetPhysics()->EnableClip();
- }
- /*
- ================
- idTrigger::Disable
- ================
- */
- void idTrigger::Disable( void ) {
- // we may be relinked if we're bound to another object, so clear the contents as well
- GetPhysics()->SetContents( 0 );
- GetPhysics()->DisableClip();
- }
- /*
- ================
- idTrigger::CallScript
- ================
- */
- void idTrigger::CallScript( void ) const {
- idThread *thread;
- if ( scriptFunction ) {
- thread = new idThread( scriptFunction );
- thread->DelayedStart( 0 );
- }
- }
- /*
- ================
- idTrigger::GetScriptFunction
- ================
- */
- const function_t *idTrigger::GetScriptFunction( void ) const {
- return scriptFunction;
- }
- /*
- ================
- idTrigger::Save
- ================
- */
- void idTrigger::Save( idSaveGame *savefile ) const {
- if ( scriptFunction ) {
- savefile->WriteString( scriptFunction->Name() );
- } else {
- savefile->WriteString( "" );
- }
- }
- /*
- ================
- idTrigger::Restore
- ================
- */
- void idTrigger::Restore( idRestoreGame *savefile ) {
- idStr funcname;
- savefile->ReadString( funcname );
- if ( funcname.Length() ) {
- scriptFunction = gameLocal.program.FindFunction( funcname );
- if ( scriptFunction == NULL ) {
- gameLocal.Warning( "idTrigger_Multi '%s' at (%s) calls unknown function '%s'", name.c_str(), GetPhysics()->GetOrigin().ToString(0), funcname.c_str() );
- }
- } else {
- scriptFunction = NULL;
- }
- }
- void idTrigger::Event_IsEnabled( void )
- {
- if (GetPhysics()->GetContents() <= 0)
- {
- idThread::ReturnInt( 0 );
- return;
- }
- idThread::ReturnInt( 1 );
- }
- /*
- ================
- idTrigger::Event_Enable
- ================
- */
- void idTrigger::Event_Enable( void ) {
- Enable();
- }
- /*
- ================
- idTrigger::Event_Disable
- ================
- */
- void idTrigger::Event_Disable( void ) {
- Disable();
- }
- /*
- ================
- idTrigger::idTrigger
- ================
- */
- idTrigger::idTrigger() {
- scriptFunction = NULL;
- }
- /*
- ================
- idTrigger::Spawn
- ================
- */
- void idTrigger::Spawn( void ) {
- GetPhysics()->SetContents( CONTENTS_TRIGGER );
- idStr funcname = spawnArgs.GetString( "call", "" );
- if ( funcname.Length() ) {
- scriptFunction = gameLocal.program.FindFunction( funcname );
- if ( scriptFunction == NULL ) {
- gameLocal.Warning( "trigger '%s' at (%s) calls unknown function '%s'", name.c_str(), GetPhysics()->GetOrigin().ToString(0), funcname.c_str() );
- }
- } else {
- scriptFunction = NULL;
- }
- }
- /*
- ===============================================================================
- idTrigger_Multi
-
- ===============================================================================
- */
- const idEventDef EV_TriggerAction( "<triggerAction>", "e" );
- const idEventDef EV_TriggerActivate( "triggeractivate", "d" );
- CLASS_DECLARATION( idTrigger, idTrigger_Multi )
- EVENT( EV_Touch, idTrigger_Multi::Event_Touch )
- EVENT( EV_Activate, idTrigger_Multi::Event_Trigger )
- EVENT( EV_TriggerAction, idTrigger_Multi::Event_TriggerAction )
- EVENT( EV_TriggerActivate, idTrigger_Multi::Event_TriggerActivate )
- END_CLASS
- void idTrigger_Multi::Event_TriggerActivate( int value )
- {
- if (value >= 1)
- {
- triggerFirst = false;
- }
- else
- {
- triggerFirst = true;
- }
- }
- /*
- ================
- idTrigger_Multi::idTrigger_Multi
- ================
- */
- idTrigger_Multi::idTrigger_Multi( void ) {
- wait = 0.0f;
- random = 0.0f;
- delay = 0.0f;
- random_delay = 0.0f;
- nextTriggerTime = 0;
- removeItem = 0;
- touchClient = false;
- touchOther = false;
- triggerFirst = false;
- triggerWithSelf = false;
- }
- /*
- ================
- idTrigger_Multi::Save
- ================
- */
- void idTrigger_Multi::Save( idSaveGame *savefile ) const {
- savefile->WriteFloat( wait );
- savefile->WriteFloat( random );
- savefile->WriteFloat( delay );
- savefile->WriteFloat( random_delay );
- savefile->WriteInt( nextTriggerTime );
- savefile->WriteString( requires );
- savefile->WriteInt( removeItem );
- savefile->WriteBool( touchClient );
- savefile->WriteBool( touchOther );
- savefile->WriteBool( triggerFirst );
- savefile->WriteBool( triggerWithSelf );
- }
- /*
- ================
- idTrigger_Multi::Restore
- ================
- */
- void idTrigger_Multi::Restore( idRestoreGame *savefile ) {
- savefile->ReadFloat( wait );
- savefile->ReadFloat( random );
- savefile->ReadFloat( delay );
- savefile->ReadFloat( random_delay );
- savefile->ReadInt( nextTriggerTime );
- savefile->ReadString( requires );
- savefile->ReadInt( removeItem );
- savefile->ReadBool( touchClient );
- savefile->ReadBool( touchOther );
- savefile->ReadBool( triggerFirst );
- savefile->ReadBool( triggerWithSelf );
- }
- /*
- ================
- idTrigger_Multi::Spawn
- "wait" : Seconds between triggerings, 0.5 default, -1 = one time only.
- "call" : Script function to call when triggered
- "random" wait variance, default is 0
- Variable sized repeatable trigger. Must be targeted at one or more entities.
- so, the basic time between firing is a random time between
- (wait - random) and (wait + random)
- ================
- */
- void idTrigger_Multi::Spawn( void ) {
- spawnArgs.GetFloat( "wait", "0.5", wait );
- spawnArgs.GetFloat( "random", "0", random );
- spawnArgs.GetFloat( "delay", "0", delay );
- spawnArgs.GetFloat( "random_delay", "0", random_delay );
-
- if ( random && ( random >= wait ) && ( wait >= 0 ) ) {
- random = wait - 1;
- gameLocal.Warning( "idTrigger_Multi '%s' at (%s) has random >= wait", name.c_str(), GetPhysics()->GetOrigin().ToString(0) );
- }
- if ( random_delay && ( random_delay >= delay ) && ( delay >= 0 ) ) {
- random_delay = delay - 1;
- gameLocal.Warning( "idTrigger_Multi '%s' at (%s) has random_delay >= delay", name.c_str(), GetPhysics()->GetOrigin().ToString(0) );
- }
- spawnArgs.GetString( "requires", "", requires );
- spawnArgs.GetInt( "removeItem", "0", removeItem );
- spawnArgs.GetBool( "triggerFirst", "0", triggerFirst );
- spawnArgs.GetBool( "triggerWithSelf", "0", triggerWithSelf );
- if ( spawnArgs.GetBool( "anyTouch" ) ) {
- touchClient = true;
- touchOther = true;
- } else if ( spawnArgs.GetBool( "noTouch" ) ) {
- touchClient = false;
- touchOther = false;
- } else if ( spawnArgs.GetBool( "noClient" ) ) {
- touchClient = false;
- touchOther = true;
- } else {
- touchClient = true;
- touchOther = false;
- }
- nextTriggerTime = 0;
- if ( spawnArgs.GetBool( "flashlight_trigger" ) ) {
- GetPhysics()->SetContents( CONTENTS_FLASHLIGHT_TRIGGER );
- } else {
- GetPhysics()->SetContents( CONTENTS_TRIGGER );
- }
- }
- /*
- ================
- idTrigger_Multi::CheckFacing
- ================
- */
- bool idTrigger_Multi::CheckFacing( idEntity *activator ) {
- if ( spawnArgs.GetBool( "facing" ) ) {
- if ( !activator->IsType( idPlayer::Type ) ) {
- return true;
- }
- idPlayer *player = static_cast< idPlayer* >( activator );
- float dot = player->viewAngles.ToForward() * GetPhysics()->GetAxis()[0];
- float angle = RAD2DEG( idMath::ACos( dot ) );
- if ( angle > spawnArgs.GetFloat( "angleLimit", "30" ) ) {
- return false;
- }
- }
- return true;
- }
- /*
- ================
- idTrigger_Multi::TriggerAction
- ================
- */
- void idTrigger_Multi::TriggerAction( idEntity *activator ) {
- ActivateTargets( triggerWithSelf ? this : activator );
- CallScript();
- if ( wait >= 0 ) {
- nextTriggerTime = gameLocal.time + SEC2MS( wait + random * gameLocal.random.CRandomFloat() );
- } else {
- // we can't just remove (this) here, because this is a touch function
- // called while looping through area links...
- #ifdef _D3XP
- // If the player spawned inside the trigger, the player Spawn function called Think directly,
- // allowing for multiple triggers on a trigger_once. Increasing the nextTriggerTime prevents it.
- nextTriggerTime = gameLocal.time + 99999;
- #else
- nextTriggerTime = gameLocal.time + 1;
- #endif
- PostEventMS( &EV_Remove, 0 );
- }
- }
- /*
- ================
- idTrigger_Multi::Event_TriggerAction
- ================
- */
- void idTrigger_Multi::Event_TriggerAction( idEntity *activator ) {
- TriggerAction( activator );
- }
- /*
- ================
- idTrigger_Multi::Event_Trigger
- the trigger was just activated
- activated should be the entity that originated the activation sequence (ie. the original target)
- activator should be set to the activator so it can be held through a delay
- so wait for the delay time before firing
- ================
- */
- void idTrigger_Multi::Event_Trigger( idEntity *activator ) {
- if ( nextTriggerTime > gameLocal.time ) {
- // can't retrigger until the wait is over
- return;
- }
- // see if this trigger requires an item
- if ( !gameLocal.RequirementMet( activator, requires, removeItem ) ) {
- return;
- }
- if ( !CheckFacing( activator ) ) {
- return;
- }
- if ( triggerFirst ) {
- triggerFirst = false;
- return;
- }
- // don't allow it to trigger twice in a single frame
- nextTriggerTime = gameLocal.time + 1;
- if ( delay > 0 ) {
- // don't allow it to trigger again until our delay has passed
- nextTriggerTime += SEC2MS( delay + random_delay * gameLocal.random.CRandomFloat() );
- PostEventSec( &EV_TriggerAction, delay, activator );
- } else {
- TriggerAction( activator );
- }
- //BC recording.
- idEntity *recordEnt;
- recordEnt = gameLocal.FindEntity( "world1" );
- if (recordEnt)
- {
- if (this->spawnArgs.GetBool("recordable", "0"))
- {
- static_cast<idWorldManager *>( recordEnt )->RecordFrob(this->GetName());
- }
- }
- }
- /*
- ================
- idTrigger_Multi::Event_Touch
- ================
- */
- void idTrigger_Multi::Event_Touch( idEntity *other, trace_t *trace ) {
- if( triggerFirst ) {
- return;
- }
- bool player = other->IsType( idPlayer::Type );
- if ( player ) {
- if ( !touchClient ) {
- return;
- }
- if ( static_cast< idPlayer * >( other )->spectating ) {
- return;
- }
- } else if ( !touchOther ) {
- return;
- }
- if ( nextTriggerTime > gameLocal.time ) {
- // can't retrigger until the wait is over
- return;
- }
- // see if this trigger requires an item
- if ( !gameLocal.RequirementMet( other, requires, removeItem ) ) {
- return;
- }
- if ( !CheckFacing( other ) ) {
- return;
- }
- if ( spawnArgs.GetBool( "toggleTriggerFirst" ) ) {
- triggerFirst = true;
- }
- if (player && spawnArgs.GetBool( "falltrigger" ))
- {
- StartSound( "snd_camerasnap" , SND_CHANNEL_ANY, 0, false, NULL );
-
-
- if (gameLocal.GetLocalPlayer()->inDeck)
- {
- //kick player out of deck.
- //cvarSystem->SetCVarBool("deckActive", true, 0);
- //gameLocal.GetLocalPlayer()->deckEnt.GetEntity()->GetPhysics()->SetOrigin(popcornpos);
-
- //gameLocal.sessionCommand = "stopgui";
-
- gameLocal.GetLocalPlayer()->ExitDeck(true);
- }
- const char *manualPos = this->spawnArgs.GetString("target");
- if (manualPos)
- {
- idEntity *manualEnt = gameLocal.FindEntity( manualPos );
- if (manualEnt)
- {
- other->SetOrigin( manualEnt->GetPhysics()->GetOrigin() + idVec3(0,0,1) );
- other->GetPhysics()->PutToRest();
- return;
- }
- }
- //current.velocity.Zero();
- idVec3 popcornpos = static_cast< idPlayer * >( other )->popcornPosition;
-
- if (popcornpos == vec3_zero)
- {
- //no valid popcorn position.
- //reset player to spawn point.
- int spawnIndex = 0;
- idEntity *recordEnt;
- recordEnt = gameLocal.FindEntity( "world1" );
- if (recordEnt)
- {
- spawnIndex = static_cast<idWorldManager *>( recordEnt )->index;
- }
- idEntity *spawnEnt;
- spawnEnt = gameLocal.FindEntity( va("heliinsertion%d", spawnIndex) );
-
- if (spawnEnt)
- {
- other->SetOrigin( spawnEnt->GetPhysics()->GetOrigin() + idVec3(0,0,1) );
- other->GetPhysics()->PutToRest();
- }
- }
- else
- {
- other->SetOrigin( popcornpos + idVec3(0,0,1) );
- other->GetPhysics()->PutToRest();
- }
- }
- nextTriggerTime = gameLocal.time + 1;
- if ( delay > 0 ) {
- // don't allow it to trigger again until our delay has passed
- nextTriggerTime += SEC2MS( delay + random_delay * gameLocal.random.CRandomFloat() );
- PostEventSec( &EV_TriggerAction, delay, other );
- } else {
- TriggerAction( other );
- }
- }
- CLASS_DECLARATION( idTrigger, idTrigger_classname )
- EVENT( EV_Touch, idTrigger_classname::Event_Touch )
- END_CLASS
- idTrigger_classname::idTrigger_classname( void )
- {
- wait = 0.0f;
- nextTriggerTime = 0;
- triggerFirst = false;
- }
- void idTrigger_classname::Spawn( void ) {
- spawnArgs.GetFloat( "wait", "0.5", wait );
-
- spawnArgs.GetBool( "triggerFirst", "0", triggerFirst );
- className = spawnArgs.GetString( "class" );
- if ( !className.Length() )
- {
- gameLocal.Error( "idTrigger_classname '%s' at (%s) doesn't have 'classname' key specified", name.c_str(), GetPhysics()->GetOrigin().ToString(0) );
- }
- nextTriggerTime = 0;
- GetPhysics()->SetContents( CONTENTS_TRIGGER );
- }
- void idTrigger_classname::TriggerAction( idEntity *activator )
- {
- ActivateTargets( activator );
- CallScript();
- if ( wait >= 0 )
- {
- nextTriggerTime = gameLocal.time + SEC2MS( wait );
- }
- else
- {
- // we can't just remove (this) here, because this is a touch function
- // called while looping through area links...
- nextTriggerTime = gameLocal.time + 1;
- PostEventMS( &EV_Remove, 0 );
- }
- }
- void idTrigger_classname::Event_TriggerAction( idEntity *activator )
- {
- TriggerAction( activator );
- }
- void idTrigger_classname::Event_Trigger( idEntity *activator )
- {
- if ( nextTriggerTime > gameLocal.time )
- {
- // can't retrigger until the wait is over
- return;
- }
- if ( !activator || ( activator->spawnArgs.GetString("classname") != className ) )
- {
- return;
- }
-
- if ( triggerFirst )
- {
- triggerFirst = false;
- return;
- }
- // don't allow it to trigger twice in a single frame
- nextTriggerTime = gameLocal.time + 1;
- TriggerAction( activator );
- }
- /*
- ================
- idTrigger_EntityName::Event_Touch
- ================
- */
- void idTrigger_classname::Event_Touch( idEntity *other, trace_t *trace )
- {
- if( triggerFirst )
- {
- return;
- }
- if ( nextTriggerTime > gameLocal.time )
- {
- // can't retrigger until the wait is over
- return;
- }
-
- if ( !other || ( other->spawnArgs.GetString("classname") != className ) )
- {
- return;
- }
- nextTriggerTime = gameLocal.time + 1;
- TriggerAction( other );
- }
- /*
- ===============================================================================
- idTrigger_EntityName
-
- ===============================================================================
- */
- CLASS_DECLARATION( idTrigger, idTrigger_EntityName )
- EVENT( EV_Touch, idTrigger_EntityName::Event_Touch )
- EVENT( EV_Activate, idTrigger_EntityName::Event_Trigger )
- EVENT( EV_TriggerAction, idTrigger_EntityName::Event_TriggerAction )
- END_CLASS
- /*
- ================
- idTrigger_EntityName::idTrigger_EntityName
- ================
- */
- idTrigger_EntityName::idTrigger_EntityName( void ) {
- wait = 0.0f;
- random = 0.0f;
- delay = 0.0f;
- random_delay = 0.0f;
- nextTriggerTime = 0;
- triggerFirst = false;
- }
- /*
- ================
- idTrigger_EntityName::Save
- ================
- */
- void idTrigger_EntityName::Save( idSaveGame *savefile ) const {
- savefile->WriteFloat( wait );
- savefile->WriteFloat( random );
- savefile->WriteFloat( delay );
- savefile->WriteFloat( random_delay );
- savefile->WriteInt( nextTriggerTime );
- savefile->WriteBool( triggerFirst );
- savefile->WriteString( entityName );
- }
- /*
- ================
- idTrigger_EntityName::Restore
- ================
- */
- void idTrigger_EntityName::Restore( idRestoreGame *savefile ) {
- savefile->ReadFloat( wait );
- savefile->ReadFloat( random );
- savefile->ReadFloat( delay );
- savefile->ReadFloat( random_delay );
- savefile->ReadInt( nextTriggerTime );
- savefile->ReadBool( triggerFirst );
- savefile->ReadString( entityName );
- }
- /*
- ================
- idTrigger_EntityName::Spawn
- ================
- */
- void idTrigger_EntityName::Spawn( void ) {
- spawnArgs.GetFloat( "wait", "0.5", wait );
- spawnArgs.GetFloat( "random", "0", random );
- spawnArgs.GetFloat( "delay", "0", delay );
- spawnArgs.GetFloat( "random_delay", "0", random_delay );
-
- if ( random && ( random >= wait ) && ( wait >= 0 ) ) {
- random = wait - 1;
- gameLocal.Warning( "idTrigger_EntityName '%s' at (%s) has random >= wait", name.c_str(), GetPhysics()->GetOrigin().ToString(0) );
- }
- if ( random_delay && ( random_delay >= delay ) && ( delay >= 0 ) ) {
- random_delay = delay - 1;
- gameLocal.Warning( "idTrigger_EntityName '%s' at (%s) has random_delay >= delay", name.c_str(), GetPhysics()->GetOrigin().ToString(0) );
- }
- spawnArgs.GetBool( "triggerFirst", "0", triggerFirst );
- entityName = spawnArgs.GetString( "entityname" );
- if ( !entityName.Length() ) {
- gameLocal.Error( "idTrigger_EntityName '%s' at (%s) doesn't have 'entityname' key specified", name.c_str(), GetPhysics()->GetOrigin().ToString(0) );
- }
- nextTriggerTime = 0;
- if ( !spawnArgs.GetBool( "noTouch" ) ) {
- GetPhysics()->SetContents( CONTENTS_TRIGGER );
- }
- }
- /*
- ================
- idTrigger_EntityName::TriggerAction
- ================
- */
- void idTrigger_EntityName::TriggerAction( idEntity *activator ) {
- ActivateTargets( activator );
- CallScript();
- if ( wait >= 0 ) {
- nextTriggerTime = gameLocal.time + SEC2MS( wait + random * gameLocal.random.CRandomFloat() );
- } else {
- // we can't just remove (this) here, because this is a touch function
- // called while looping through area links...
- nextTriggerTime = gameLocal.time + 1;
- PostEventMS( &EV_Remove, 0 );
- }
- }
- /*
- ================
- idTrigger_EntityName::Event_TriggerAction
- ================
- */
- void idTrigger_EntityName::Event_TriggerAction( idEntity *activator ) {
- TriggerAction( activator );
- }
- /*
- ================
- idTrigger_EntityName::Event_Trigger
- the trigger was just activated
- activated should be the entity that originated the activation sequence (ie. the original target)
- activator should be set to the activator so it can be held through a delay
- so wait for the delay time before firing
- ================
- */
- void idTrigger_EntityName::Event_Trigger( idEntity *activator ) {
- if ( nextTriggerTime > gameLocal.time ) {
- // can't retrigger until the wait is over
- return;
- }
- if ( !activator || ( activator->name != entityName ) ) {
- return;
- }
- if ( triggerFirst ) {
- triggerFirst = false;
- return;
- }
- // don't allow it to trigger twice in a single frame
- nextTriggerTime = gameLocal.time + 1;
- if ( delay > 0 ) {
- // don't allow it to trigger again until our delay has passed
- nextTriggerTime += SEC2MS( delay + random_delay * gameLocal.random.CRandomFloat() );
- PostEventSec( &EV_TriggerAction, delay, activator );
- } else {
- TriggerAction( activator );
- }
- }
- /*
- ================
- idTrigger_EntityName::Event_Touch
- ================
- */
- void idTrigger_EntityName::Event_Touch( idEntity *other, trace_t *trace ) {
- if( triggerFirst ) {
- return;
- }
- if ( nextTriggerTime > gameLocal.time ) {
- // can't retrigger until the wait is over
- return;
- }
- if ( !other || ( other->name != entityName ) ) {
- return;
- }
- nextTriggerTime = gameLocal.time + 1;
- if ( delay > 0 )
- {
- // don't allow it to trigger again until our delay has passed
- nextTriggerTime += SEC2MS( delay + random_delay * gameLocal.random.CRandomFloat() );
- PostEventSec( &EV_TriggerAction, delay, other );
- }
- else
- {
- //bc this is VERY car-specific hack to ensure all four corners of the car are within the "hidey" trigger.
- if ( other->IsType( idActivator::Type ) )
- {
- idAngles otherAngles;
- idVec3 size;
- idVec3 forward;
- idVec3 right;
- other->spawnArgs.GetVector( "size", "0 0 0", size );
- if (size.x != 0 && size.y != 0 && size.z != 0)
- {
- otherAngles = other->GetPhysics()->GetAxis().ToAngles();
- forward = otherAngles.ToForward();
- otherAngles.yaw += 90;
- right = otherAngles.ToForward();
- idVec3 frontLeft = other->GetPhysics()->GetAbsBounds().GetCenter() + forward * (size.x/2) + right * (size.y/2);
- idVec3 frontRight = other->GetPhysics()->GetAbsBounds().GetCenter() + forward * (size.x/2) + right * -(size.y/2);
- idVec3 rearLeft = other->GetPhysics()->GetAbsBounds().GetCenter() + forward * -(size.x/2) + right * (size.y/2);
- idVec3 rearRight = other->GetPhysics()->GetAbsBounds().GetCenter() + forward * -(size.x/2) + right * -(size.y/2);
- /*
- gameRenderWorld->DebugCircle( colorWhite, frontLeft, idVec3(0,0,1), 4, 6, 500 );
- gameRenderWorld->DebugCircle( colorWhite, frontRight, idVec3(0,0,1), 4, 6, 500 );
- gameRenderWorld->DebugCircle( colorWhite, rearLeft, idVec3(0,0,1), 4, 6, 500 );
- gameRenderWorld->DebugCircle( colorWhite, rearRight, idVec3(0,0,1), 4, 6, 500 );
- */
- if (!this->GetPhysics()->GetAbsBounds().ContainsPoint( frontLeft)
- || !this->GetPhysics()->GetAbsBounds().ContainsPoint( frontRight)
- || !this->GetPhysics()->GetAbsBounds().ContainsPoint( rearLeft)
- || !this->GetPhysics()->GetAbsBounds().ContainsPoint( rearRight))
- {
- return;
- }
- else
- {
- //inside the trigger.
- idEntity *carMaster = gameLocal.FindEntity( other->spawnArgs.GetString( "master" ) );
- if (carMaster)
- {
- gameLocal.GetLocalPlayer()->UseFrob( carMaster, "inEntTrigger" );
- TriggerAction( other );
- return;
- }
- return;
- }
- }
- }
- TriggerAction( other );
- }
- }
- /*
- ===============================================================================
- idTrigger_Timer
-
- ===============================================================================
- */
- const idEventDef EV_Timer( "<timer>", NULL );
- CLASS_DECLARATION( idTrigger, idTrigger_Timer )
- EVENT( EV_Timer, idTrigger_Timer::Event_Timer )
- EVENT( EV_Activate, idTrigger_Timer::Event_Use )
- END_CLASS
- /*
- ================
- idTrigger_Timer::idTrigger_Timer
- ================
- */
- idTrigger_Timer::idTrigger_Timer( void ) {
- random = 0.0f;
- wait = 0.0f;
- on = false;
- delay = 0.0f;
- }
- /*
- ================
- idTrigger_Timer::Save
- ================
- */
- void idTrigger_Timer::Save( idSaveGame *savefile ) const {
- savefile->WriteFloat( random );
- savefile->WriteFloat( wait );
- savefile->WriteBool( on );
- savefile->WriteFloat( delay );
- savefile->WriteString( onName );
- savefile->WriteString( offName );
- }
- /*
- ================
- idTrigger_Timer::Restore
- ================
- */
- void idTrigger_Timer::Restore( idRestoreGame *savefile ) {
- savefile->ReadFloat( random );
- savefile->ReadFloat( wait );
- savefile->ReadBool( on );
- savefile->ReadFloat( delay );
- savefile->ReadString( onName );
- savefile->ReadString( offName );
- }
- /*
- ================
- idTrigger_Timer::Spawn
- Repeatedly fires its targets.
- Can be turned on or off by using.
- ================
- */
- void idTrigger_Timer::Spawn( void ) {
- spawnArgs.GetFloat( "random", "1", random );
- spawnArgs.GetFloat( "wait", "1", wait );
- spawnArgs.GetBool( "start_on", "0", on );
- spawnArgs.GetFloat( "delay", "0", delay );
- onName = spawnArgs.GetString( "onName" );
- offName = spawnArgs.GetString( "offName" );
- if ( random >= wait && wait >= 0 ) {
- random = wait - 0.001;
- gameLocal.Warning( "idTrigger_Timer '%s' at (%s) has random >= wait", name.c_str(), GetPhysics()->GetOrigin().ToString(0) );
- }
- if ( on ) {
- PostEventSec( &EV_Timer, delay );
- }
- }
- /*
- ================
- idTrigger_Timer::Enable
- ================
- */
- void idTrigger_Timer::Enable( void ) {
- // if off, turn it on
- if ( !on ) {
- on = true;
- PostEventSec( &EV_Timer, delay );
- }
- }
- /*
- ================
- idTrigger_Timer::Disable
- ================
- */
- void idTrigger_Timer::Disable( void ) {
- // if on, turn it off
- if ( on ) {
- on = false;
- CancelEvents( &EV_Timer );
- }
- }
- /*
- ================
- idTrigger_Timer::Event_Timer
- ================
- */
- void idTrigger_Timer::Event_Timer( void ) {
- ActivateTargets( this );
- // set time before next firing
- if ( wait >= 0.0f ) {
- PostEventSec( &EV_Timer, wait + gameLocal.random.CRandomFloat() * random );
- }
- }
- /*
- ================
- idTrigger_Timer::Event_Use
- ================
- */
- void idTrigger_Timer::Event_Use( idEntity *activator ) {
- // if on, turn it off
- if ( on ) {
- if ( offName.Length() && offName.Icmp( activator->GetName() ) ) {
- return;
- }
- on = false;
- CancelEvents( &EV_Timer );
- } else {
- // turn it on
- if ( onName.Length() && onName.Icmp( activator->GetName() ) ) {
- return;
- }
- on = true;
- PostEventSec( &EV_Timer, delay );
- }
- }
- /*
- ===============================================================================
- idTrigger_Count
-
- ===============================================================================
- */
- CLASS_DECLARATION( idTrigger, idTrigger_Count )
- EVENT( EV_Activate, idTrigger_Count::Event_Trigger )
- EVENT( EV_TriggerAction, idTrigger_Count::Event_TriggerAction )
- END_CLASS
- /*
- ================
- idTrigger_Count::idTrigger_Count
- ================
- */
- idTrigger_Count::idTrigger_Count( void ) {
- goal = 0;
- count = 0;
- delay = 0.0f;
- }
- /*
- ================
- idTrigger_Count::Save
- ================
- */
- void idTrigger_Count::Save( idSaveGame *savefile ) const {
- savefile->WriteInt( goal );
- savefile->WriteInt( count );
- savefile->WriteFloat( delay );
- }
- /*
- ================
- idTrigger_Count::Restore
- ================
- */
- void idTrigger_Count::Restore( idRestoreGame *savefile ) {
- savefile->ReadInt( goal );
- savefile->ReadInt( count );
- savefile->ReadFloat( delay );
- }
- /*
- ================
- idTrigger_Count::Spawn
- ================
- */
- void idTrigger_Count::Spawn( void ) {
- spawnArgs.GetInt( "count", "1", goal );
- spawnArgs.GetFloat( "delay", "0", delay );
- count = 0;
- }
- /*
- ================
- idTrigger_Count::Event_Trigger
- ================
- */
- void idTrigger_Count::Event_Trigger( idEntity *activator ) {
- // goal of -1 means trigger has been exhausted
- if (goal >= 0) {
- count++;
- if ( count >= goal ) {
- if (spawnArgs.GetBool("repeat")) {
- count = 0;
- } else {
- goal = -1;
- }
- PostEventSec( &EV_TriggerAction, delay, activator );
- }
- }
- }
- /*
- ================
- idTrigger_Count::Event_TriggerAction
- ================
- */
- void idTrigger_Count::Event_TriggerAction( idEntity *activator ) {
- ActivateTargets( activator );
- CallScript();
- if ( goal == -1 ) {
- PostEventMS( &EV_Remove, 0 );
- }
- }
- const idEventDef EV_triggerpushactivate( "triggerpushactivate", "d" );
- //bc trigger push.
- CLASS_DECLARATION( idTrigger, idTrigger_Push )
- EVENT( EV_Touch, idTrigger_Push::Event_Touch )
- EVENT( EV_triggerpushactivate, idTrigger_Push::Event_triggerpushactivate )
- END_CLASS
- idTrigger_Push::idTrigger_Push( void )
- {
- on = false;
- wait = 0.2f;
- yaw = 0;
- pitch = -20;
- force = 256;
- }
- void idTrigger_Push::Save( idSaveGame *savefile ) const {
- savefile->WriteBool( on );
- savefile->WriteInt( nextTime );
- savefile->WriteInt( yaw );
- savefile->WriteInt( pitch);
- savefile->WriteInt( force );
- savefile->WriteFloat( wait );
-
- }
- /*
- ================
- idTrigger_Hurt::Restore
- ================
- */
- void idTrigger_Push::Restore( idRestoreGame *savefile ) {
- savefile->ReadBool( on );
- savefile->ReadInt( nextTime );
- savefile->ReadInt( yaw );
- savefile->ReadInt( pitch);
- savefile->ReadInt( force );
- savefile->ReadFloat( wait );
- }
- void idTrigger_Push::Spawn( void )
- {
- spawnArgs.GetBool( "start_on", "1", on );
- spawnArgs.GetFloat( "wait", "0.2", wait );
- spawnArgs.GetInt( "yaw", "0", yaw );
- spawnArgs.GetInt( "pitch", "-20", pitch );
- spawnArgs.GetInt( "force", "256", force );
- nextTime = gameLocal.time;
- Enable();
- }
- void idTrigger_Push::Event_Touch( idEntity *other, trace_t *trace )
- {
- if ( on && other && gameLocal.time >= nextTime )
- {
- //push the thing.
- idAngles ang;
- ang.pitch = pitch;
- ang.yaw = yaw;
- ang.roll = 0;
- idVec3 dir;
- dir = ang.ToForward();
- dir *= force;
- other->GetPhysics()->SetLinearVelocity( other->GetPhysics()->GetLinearVelocity() + dir );
- nextTime = gameLocal.time + SEC2MS( wait );
- }
- }
- void idTrigger_Push::Event_triggerpushactivate( int value )
- {
- if (value > 0)
- {
- on = 1;
- }
- else
- {
- on = 0;
- }
- }
- /*
- ===============================================================================
- idTrigger_Hurt
-
- ===============================================================================
- */
- CLASS_DECLARATION( idTrigger, idTrigger_Hurt )
- EVENT( EV_Touch, idTrigger_Hurt::Event_Touch )
- EVENT( EV_Activate, idTrigger_Hurt::Event_Toggle )
- END_CLASS
- /*
- ================
- idTrigger_Hurt::idTrigger_Hurt
- ================
- */
- idTrigger_Hurt::idTrigger_Hurt( void ) {
- on = false;
- delay = 0.0f;
- nextTime = 0;
- }
- /*
- ================
- idTrigger_Hurt::Save
- ================
- */
- void idTrigger_Hurt::Save( idSaveGame *savefile ) const {
- savefile->WriteBool( on );
- savefile->WriteFloat( delay );
- savefile->WriteInt( nextTime );
- }
- /*
- ================
- idTrigger_Hurt::Restore
- ================
- */
- void idTrigger_Hurt::Restore( idRestoreGame *savefile ) {
- savefile->ReadBool( on );
- savefile->ReadFloat( delay );
- savefile->ReadInt( nextTime );
- }
- /*
- ================
- idTrigger_Hurt::Spawn
- Damages activator
- Can be turned on or off by using.
- ================
- */
- void idTrigger_Hurt::Spawn( void ) {
- spawnArgs.GetBool( "on", "1", on );
- spawnArgs.GetFloat( "delay", "1.0", delay );
- nextTime = gameLocal.time;
- Enable();
- }
- /*
- ================
- idTrigger_Hurt::Event_Touch
- ================
- */
- void idTrigger_Hurt::Event_Touch( idEntity *other, trace_t *trace ) {
- const char *damage;
- if ( on && other && gameLocal.time >= nextTime ) {
- #ifdef _D3XP
- bool playerOnly = spawnArgs.GetBool( "playerOnly" );
- if ( playerOnly ) {
- if ( !other->IsType( idPlayer::Type ) ) {
- return;
- }
- }
- #endif
- damage = spawnArgs.GetString( "def_damage", "damage_painTrigger" );
- #ifdef _D3XP
- idVec3 dir = vec3_origin;
- if(spawnArgs.GetBool("kick_from_center", "0")) {
- dir = other->GetPhysics()->GetOrigin() - GetPhysics()->GetOrigin();
- dir.Normalize();
- }
- other->Damage( NULL, NULL, dir, damage, 1.0f, INVALID_JOINT );
- #else
- other->Damage( NULL, NULL, vec3_origin, damage, 1.0f, INVALID_JOINT );
- #endif
- ActivateTargets( other );
- CallScript();
- nextTime = gameLocal.time + SEC2MS( delay );
- }
- }
- /*
- ================
- idTrigger_Hurt::Event_Toggle
- ================
- */
- void idTrigger_Hurt::Event_Toggle( idEntity *activator ) {
- on = !on;
- }
- /*
- ===============================================================================
- idTrigger_Fade
- ===============================================================================
- */
- CLASS_DECLARATION( idTrigger, idTrigger_Fade )
- EVENT( EV_Activate, idTrigger_Fade::Event_Trigger )
- END_CLASS
- /*
- ================
- idTrigger_Fade::Event_Trigger
- ================
- */
- void idTrigger_Fade::Event_Trigger( idEntity *activator ) {
- idVec4 fadeColor;
- int fadeTime;
- idPlayer *player;
- player = gameLocal.GetLocalPlayer();
- if ( player ) {
- fadeColor = spawnArgs.GetVec4( "fadeColor", "0, 0, 0, 1" );
- fadeTime = SEC2MS( spawnArgs.GetFloat( "fadeTime", "0.5" ) );
- player->playerView.Fade( fadeColor, fadeTime );
- PostEventMS( &EV_ActivateTargets, fadeTime, activator );
- }
- }
- /*
- ===============================================================================
- idTrigger_Touch
-
- ===============================================================================
- */
- CLASS_DECLARATION( idTrigger, idTrigger_Touch )
- EVENT( EV_Activate, idTrigger_Touch::Event_Trigger )
- END_CLASS
- /*
- ================
- idTrigger_Touch::idTrigger_Touch
- ================
- */
- idTrigger_Touch::idTrigger_Touch( void ) {
- clipModel = NULL;
- }
- /*
- ================
- idTrigger_Touch::Spawn
- ================
- */
- void idTrigger_Touch::Spawn( void ) {
- // get the clip model
- clipModel = new idClipModel( GetPhysics()->GetClipModel() );
- // remove the collision model from the physics object
- GetPhysics()->SetClipModel( NULL, 1.0f );
- if ( spawnArgs.GetBool( "start_on" ) ) {
- BecomeActive( TH_THINK );
- }
- }
- /*
- ================
- idTrigger_Touch::Save
- ================
- */
- void idTrigger_Touch::Save( idSaveGame *savefile ) {
- savefile->WriteClipModel( clipModel );
- }
- /*
- ================
- idTrigger_Touch::Restore
- ================
- */
- void idTrigger_Touch::Restore( idRestoreGame *savefile ) {
- savefile->ReadClipModel( clipModel );
- }
- /*
- ================
- idTrigger_Touch::TouchEntities
- ================
- */
- void idTrigger_Touch::TouchEntities( void ) {
- int numClipModels, i;
- idBounds bounds;
- idClipModel *cm, *clipModelList[ MAX_GENTITIES ];
- if ( clipModel == NULL || scriptFunction == NULL ) {
- return;
- }
- bounds.FromTransformedBounds( clipModel->GetBounds(), clipModel->GetOrigin(), clipModel->GetAxis() );
- numClipModels = gameLocal.clip.ClipModelsTouchingBounds( bounds, -1, clipModelList, MAX_GENTITIES );
- for ( i = 0; i < numClipModels; i++ ) {
- cm = clipModelList[ i ];
- if ( !cm->IsTraceModel() ) {
- continue;
- }
- idEntity *entity = cm->GetEntity();
- if ( !entity ) {
- continue;
- }
-
- if ( !gameLocal.clip.ContentsModel( cm->GetOrigin(), cm, cm->GetAxis(), -1,
- clipModel->Handle(), clipModel->GetOrigin(), clipModel->GetAxis() ) ) {
- continue;
- }
- ActivateTargets( entity );
- idThread *thread = new idThread();
- thread->CallFunction( entity, scriptFunction, false );
- thread->DelayedStart( 0 );
- }
- }
- /*
- ================
- idTrigger_Touch::Think
- ================
- */
- void idTrigger_Touch::Think( void ) {
- if ( thinkFlags & TH_THINK ) {
- TouchEntities();
- }
- idEntity::Think();
- }
- /*
- ================
- idTrigger_Touch::Event_Trigger
- ================
- */
- void idTrigger_Touch::Event_Trigger( idEntity *activator ) {
- if ( thinkFlags & TH_THINK ) {
- BecomeInactive( TH_THINK );
- } else {
- BecomeActive( TH_THINK );
- }
- }
- /*
- ================
- idTrigger_Touch::Enable
- ================
- */
- void idTrigger_Touch::Enable( void ) {
- BecomeActive( TH_THINK );
- }
- /*
- ================
- idTrigger_Touch::Disable
- ================
- */
- void idTrigger_Touch::Disable( void ) {
- BecomeInactive( TH_THINK );
- }
- #ifdef CTF
- /*
- ===============================================================================
- idTrigger_Flag
- ===============================================================================
- */
- CLASS_DECLARATION( idTrigger_Multi, idTrigger_Flag )
- EVENT( EV_Touch, idTrigger_Flag::Event_Touch )
- END_CLASS
- idTrigger_Flag::idTrigger_Flag( void ) {
- team = -1;
- player = false;
- eventFlag = NULL;
- }
- void idTrigger_Flag::Spawn( void ) {
- team = spawnArgs.GetInt( "team", "0" );
- player = spawnArgs.GetBool( "player", "0" );
- idStr funcname = spawnArgs.GetString( "eventflag", "" );
- if ( funcname.Length() ) {
- eventFlag = idEventDef::FindEvent( funcname );// gameLocal.program.FindFunction( funcname );//, &idItemTeam::Type );
- if ( eventFlag == NULL ) {
- gameLocal.Warning( "trigger '%s' at (%s) event unknown '%s'", name.c_str(), GetPhysics()->GetOrigin().ToString(0), funcname.c_str() );
- }
- } else {
- eventFlag = NULL;
- }
- idTrigger_Multi::Spawn();
- }
- void idTrigger_Flag::Event_Touch( idEntity *other, trace_t *trace ) {
- bool bTrigger = false;
- idItemTeam * flag = NULL;
- if ( player ) {
- if ( !other->IsType( idPlayer::Type ) )
- return;
- idPlayer * player = static_cast<idPlayer *>(other);
- if ( player->carryingFlag == false )
- return;
- if ( team != -1 && ( player->team != team || (player->team != 0 && player->team != 1)) )
- return;
- idItemTeam * flags[2];
- flags[0] = gameLocal.mpGame.GetTeamFlag( 0 );
- flags[1] = gameLocal.mpGame.GetTeamFlag( 1 );
- int iFriend = 1 - player->team; // index to the flag player team wants
- int iOpp = player->team; // index to the flag opp team wants
- // flag is captured if :
- // 1)flag is truely bound to the player
- // 2)opponent flag has been return
- if ( flags[iFriend]->carried && !flags[iFriend]->dropped && //flags[iFriend]->IsBoundTo( player ) &&
- !flags[iOpp]->carried && !flags[iOpp]->dropped )
- flag = flags[iFriend];
- else
- return;
- } else {
- if ( !other->IsType( idItemTeam::Type ) )
- return;
- idItemTeam * item = static_cast<idItemTeam *>( other );
- if ( item->team == team || team == -1 ) {
- flag = item;
- }
- else
- return;
- }
- if ( flag ) {
- switch ( eventFlag->GetNumArgs() ) {
- default :
- case 0 :
- flag->PostEventMS( eventFlag, 0 );
- break;
- case 1 :
- flag->PostEventMS( eventFlag, 0, NULL );
- break;
- case 2 :
- flag->PostEventMS( eventFlag, 0, NULL, NULL );
- break;
- }
- /*
- ServerSendEvent( eventFlag->GetEventNum(), NULL, true, false );
- idThread *thread;
- if ( scriptFlag ) {
- thread = new idThread();
- thread->CallFunction( flag, scriptFlag, false );
- thread->DelayedStart( 0 );
- }
- */
- idTrigger_Multi::Event_Touch( other, trace );
- }
- }
- #endif
|