123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278 |
- /*
- ===========================================================================
- 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.
- ===========================================================================
- */
- /*
- Various utility objects and functions.
- */
- #include "../idlib/precompiled.h"
- #pragma hdrstop
- #include "Game_local.h"
- const int JUMPPAD_EFFECT_DELAY = 100;
- /*
- ===============================================================================
- idSpawnableEntity
- A simple, spawnable entity with a model and no functionable ability of it's own.
- For example, it can be used as a placeholder during development, for marking
- locations on maps for script, or for simple placed models without any behavior
- that can be bound to other entities. Should not be subclassed.
- ===============================================================================
- */
- CLASS_DECLARATION( idEntity, idSpawnableEntity )
- END_CLASS
- /*
- ======================
- idSpawnableEntity::Spawn
- ======================
- */
- void idSpawnableEntity::Spawn() {
- // this just holds dict information
- }
- /*
- ===============================================================================
- idPlayerStart
- ===============================================================================
- */
- const idEventDef EV_TeleportStage( "<TeleportStage>", "e" );
- CLASS_DECLARATION( idEntity, idPlayerStart )
- EVENT( EV_Activate, idPlayerStart::Event_TeleportPlayer )
- EVENT( EV_TeleportStage, idPlayerStart::Event_TeleportStage )
- END_CLASS
- /*
- ===============
- idPlayerStart::idPlayerStart
- ================
- */
- idPlayerStart::idPlayerStart( void ) {
- teleportStage = 0;
- }
- /*
- ===============
- idPlayerStart::Spawn
- ================
- */
- void idPlayerStart::Spawn( void ) {
- teleportStage = 0;
- }
- /*
- ================
- idPlayerStart::Save
- ================
- */
- void idPlayerStart::Save( idSaveGame *savefile ) const {
- savefile->WriteInt( teleportStage );
- }
- /*
- ================
- idPlayerStart::Restore
- ================
- */
- void idPlayerStart::Restore( idRestoreGame *savefile ) {
- savefile->ReadInt( teleportStage );
- }
- /*
- ================
- idPlayerStart::ClientReceiveEvent
- ================
- */
- bool idPlayerStart::ClientReceiveEvent( int event, int time, const idBitMsg &msg ) {
- int entityNumber;
- switch( event ) {
- case EVENT_TELEPORTPLAYER: {
- entityNumber = msg.ReadBits( GENTITYNUM_BITS );
- idPlayer *player = static_cast<idPlayer *>( gameLocal.entities[entityNumber] );
- if ( player != NULL && player->IsType( idPlayer::Type ) ) {
- Event_TeleportPlayer( player );
- }
- return true;
- }
- default: {
- return idEntity::ClientReceiveEvent( event, time, msg );
- }
- }
- return false;
- }
- /*
- ===============
- idPlayerStart::Event_TeleportStage
- FIXME: add functionality to fx system ( could be done with player scripting too )
- ================
- */
- void idPlayerStart::Event_TeleportStage( idEntity *_player ) {
- idPlayer *player;
- if ( !_player->IsType( idPlayer::Type ) ) {
- common->Warning( "idPlayerStart::Event_TeleportStage: entity is not an idPlayer\n" );
- return;
- }
- player = static_cast<idPlayer*>(_player);
- float teleportDelay = spawnArgs.GetFloat( "teleportDelay" );
- switch ( teleportStage ) {
- case 0:
- player->playerView.Flash( colorWhite, 125 );
- player->SetInfluenceLevel( INFLUENCE_LEVEL3 );
- player->SetInfluenceView( spawnArgs.GetString( "mtr_teleportFx" ), NULL, 0.0f, NULL );
- gameSoundWorld->FadeSoundClasses( 0, -20.0f, teleportDelay );
- player->StartSound( "snd_teleport_start", SND_CHANNEL_BODY2, 0, false, NULL );
- teleportStage++;
- PostEventSec( &EV_TeleportStage, teleportDelay, player );
- break;
- case 1:
- gameSoundWorld->FadeSoundClasses( 0, 0.0f, 0.25f );
- teleportStage++;
- PostEventSec( &EV_TeleportStage, 0.25f, player );
- break;
- case 2:
- player->SetInfluenceView( NULL, NULL, 0.0f, NULL );
- TeleportPlayer( player );
- player->StopSound( SND_CHANNEL_BODY2, false );
- player->SetInfluenceLevel( INFLUENCE_NONE );
- teleportStage = 0;
- break;
- default:
- break;
- }
- }
- /*
- ===============
- idPlayerStart::TeleportPlayer
- ================
- */
- void idPlayerStart::TeleportPlayer( idPlayer *player ) {
- float pushVel = spawnArgs.GetFloat( "push", "300" );
- float f = spawnArgs.GetFloat( "visualEffect", "0" );
- const char *viewName = spawnArgs.GetString( "visualView", "" );
- idEntity *ent = viewName ? gameLocal.FindEntity( viewName ) : NULL;
- #ifdef _D3XP
- SetTimeState ts( player->timeGroup );
- #endif
- //BC stop clambering.
- player->StopClamber();
- if ( f && ent ) {
- // place in private camera view for some time
- // the entity needs to teleport to where the camera view is to have the PVS right
- player->Teleport( ent->GetPhysics()->GetOrigin(), ang_zero, this );
- player->StartSound( "snd_teleport_enter", SND_CHANNEL_ANY, 0, false, NULL );
- player->SetPrivateCameraView( static_cast<idCamera*>(ent) );
- // the player entity knows where to spawn from the previous Teleport call
- if ( !gameLocal.isClient ) {
- player->PostEventSec( &EV_Player_ExitTeleporter, f );
- }
- } else {
- // direct to exit, Teleport will take care of the killbox
- float pitch = spawnArgs.GetFloat("pitch","0");
- idAngles ang = GetPhysics()->GetAxis().ToAngles();
- ang.pitch = pitch;
- player->Teleport( GetPhysics()->GetOrigin(), ang, NULL );
- // multiplayer hijacked this entity, so only push the player in multiplayer
- if ( gameLocal.isMultiplayer ) {
- player->GetPhysics()->SetLinearVelocity( GetPhysics()->GetAxis()[0] * pushVel );
- }
-
- }
- }
- /*
- ===============
- idPlayerStart::Event_TeleportPlayer
- ================
- */
- void idPlayerStart::Event_TeleportPlayer( idEntity *activator ) {
- idPlayer *player;
- if ( activator->IsType( idPlayer::Type ) ) {
- player = static_cast<idPlayer*>( activator );
- } else {
- player = gameLocal.GetLocalPlayer();
- }
- if ( player ) {
- if ( spawnArgs.GetBool( "visualFx" ) ) {
- teleportStage = 0;
- Event_TeleportStage( player );
- } else {
- if ( gameLocal.isServer ) {
- idBitMsg msg;
- byte msgBuf[MAX_EVENT_PARAM_SIZE];
- msg.Init( msgBuf, sizeof( msgBuf ) );
- msg.BeginWriting();
- msg.WriteBits( player->entityNumber, GENTITYNUM_BITS );
- ServerSendEvent( EVENT_TELEPORTPLAYER, &msg, false, -1 );
- }
- TeleportPlayer( player );
- }
- }
- }
- /*
- ===============================================================================
- idActivator
- ===============================================================================
- */
- CLASS_DECLARATION( idEntity, idActivator )
- EVENT( EV_Activate, idActivator::Event_Activate )
- END_CLASS
- /*
- ===============
- idActivator::Save
- ================
- */
- void idActivator::Save( idSaveGame *savefile ) const {
- savefile->WriteBool( stay_on );
- }
- /*
- ===============
- idActivator::Restore
- ================
- */
- void idActivator::Restore( idRestoreGame *savefile ) {
- savefile->ReadBool( stay_on );
- if ( stay_on ) {
- BecomeActive( TH_THINK );
- }
- }
- /*
- ===============
- idActivator::Spawn
- ================
- */
- void idActivator::Spawn( void ) {
- bool start_off;
- spawnArgs.GetBool( "stay_on", "0", stay_on );
- spawnArgs.GetBool( "start_off", "0", start_off );
- GetPhysics()->SetClipBox( idBounds( vec3_origin ).Expand( 4 ), 1.0f );
- GetPhysics()->SetContents( 0 );
- if ( !start_off ) {
- BecomeActive( TH_THINK );
- }
- }
- /*
- ===============
- idActivator::Think
- ================
- */
- void idActivator::Think( void ) {
- RunPhysics();
- if ( thinkFlags & TH_THINK ) {
- if ( TouchTriggers() ) {
- if ( !stay_on ) {
- BecomeInactive( TH_THINK );
- }
- }
- }
- Present();
- }
- /*
- ===============
- idActivator::Activate
- ================
- */
- void idActivator::Event_Activate( idEntity *activator ) {
- if ( thinkFlags & TH_THINK ) {
- BecomeInactive( TH_THINK );
- } else {
- BecomeActive( TH_THINK );
- }
- }
- /*
- ===============================================================================
- idPathCorner
- ===============================================================================
- */
- CLASS_DECLARATION( idEntity, idPathCorner )
- EVENT( AI_RandomPath, idPathCorner::Event_RandomPath )
- END_CLASS
- /*
- =====================
- idPathCorner::Spawn
- =====================
- */
- void idPathCorner::Spawn( void ) {
- }
- /*
- =====================
- idPathCorner::DrawDebugInfo
- =====================
- */
- void idPathCorner::DrawDebugInfo( void ) {
- idEntity *ent;
- idBounds bnds( idVec3( -4.0, -4.0f, -8.0f ), idVec3( 4.0, 4.0f, 64.0f ) );
- for( ent = gameLocal.spawnedEntities.Next(); ent != NULL; ent = ent->spawnNode.Next() ) {
- if ( !ent->IsType( idPathCorner::Type ) ) {
- continue;
- }
- idVec3 org = ent->GetPhysics()->GetOrigin();
- gameRenderWorld->DebugBounds( colorRed, bnds, org, 0 );
- }
- }
- /*
- ============
- idPathCorner::RandomPath
- ============
- */
- idPathCorner *idPathCorner::RandomPath( const idEntity *source, const idEntity *ignore ) {
- int i;
- int num;
- int which;
- idEntity *ent;
- idPathCorner *path[ MAX_GENTITIES ];
- num = 0;
- for( i = 0; i < source->targets.Num(); i++ ) {
- ent = source->targets[ i ].GetEntity();
- if ( ent && ( ent != ignore ) && ent->IsType( idPathCorner::Type ) ) {
- path[ num++ ] = static_cast<idPathCorner *>( ent );
- if ( num >= MAX_GENTITIES ) {
- break;
- }
- }
- }
- if ( !num ) {
- return NULL;
- }
- which = gameLocal.random.RandomInt( num );
- return path[ which ];
- }
- /*
- =====================
- idPathCorner::Event_RandomPath
- =====================
- */
- void idPathCorner::Event_RandomPath( void ) {
- idPathCorner *path;
- path = RandomPath( this, NULL );
- idThread::ReturnEntity( path );
- }
- /*
- ===============================================================================
- idDamagable
-
- ===============================================================================
- */
- const idEventDef EV_RestoreDamagable( "<RestoreDamagable>" );
- CLASS_DECLARATION( idEntity, idDamagable )
- EVENT( EV_Activate, idDamagable::Event_BecomeBroken )
- EVENT( EV_RestoreDamagable, idDamagable::Event_RestoreDamagable )
- END_CLASS
- /*
- ================
- idDamagable::idDamagable
- ================
- */
- idDamagable::idDamagable( void ) {
- count = 0;
- nextTriggerTime = 0;
- }
- /*
- ================
- idDamagable::Save
- ================
- */
- void idDamagable::Save( idSaveGame *savefile ) const {
- savefile->WriteInt( count );
- savefile->WriteInt( nextTriggerTime );
- }
- /*
- ================
- idDamagable::Restore
- ================
- */
- void idDamagable::Restore( idRestoreGame *savefile ) {
- savefile->ReadInt( count );
- savefile->ReadInt( nextTriggerTime );
- }
- /*
- ================
- idDamagable::Spawn
- ================
- */
- void idDamagable::Spawn( void ) {
- idStr broken;
- health = spawnArgs.GetInt( "health", "5" );
- spawnArgs.GetInt( "count", "1", count );
- nextTriggerTime = 0;
-
- // make sure the model gets cached
- spawnArgs.GetString( "broken", "", broken );
- if ( broken.Length() && !renderModelManager->CheckModel( broken ) ) {
- gameLocal.Error( "idDamagable '%s' at (%s): cannot load broken model '%s'", name.c_str(), GetPhysics()->GetOrigin().ToString(0), broken.c_str() );
- }
- fl.takedamage = true;
- GetPhysics()->SetContents( CONTENTS_SOLID );
- }
- /*
- ================
- idDamagable::BecomeBroken
- ================
- */
- void idDamagable::BecomeBroken( idEntity *activator ) {
- float forceState;
- int numStates;
- int cycle;
- float wait;
-
- if ( gameLocal.time < nextTriggerTime ) {
- return;
- }
- spawnArgs.GetFloat( "wait", "0.1", wait );
- nextTriggerTime = gameLocal.time + SEC2MS( wait );
- if ( count > 0 ) {
- count--;
- if ( !count ) {
- fl.takedamage = false;
- } else {
- health = spawnArgs.GetInt( "health", "5" );
- }
- }
- idStr broken;
- spawnArgs.GetString( "broken", "", broken );
- if ( broken.Length() ) {
- SetModel( broken );
- }
- // offset the start time of the shader to sync it to the gameLocal time
- renderEntity.shaderParms[ SHADERPARM_TIMEOFFSET ] = -MS2SEC( gameLocal.time );
- spawnArgs.GetInt( "numstates", "1", numStates );
- spawnArgs.GetInt( "cycle", "0", cycle );
- spawnArgs.GetFloat( "forcestate", "0", forceState );
- // set the state parm
- if ( cycle ) {
- renderEntity.shaderParms[ SHADERPARM_MODE ]++;
- if ( renderEntity.shaderParms[ SHADERPARM_MODE ] > numStates ) {
- renderEntity.shaderParms[ SHADERPARM_MODE ] = 0;
- }
- } else if ( forceState ) {
- renderEntity.shaderParms[ SHADERPARM_MODE ] = forceState;
- } else {
- renderEntity.shaderParms[ SHADERPARM_MODE ] = gameLocal.random.RandomInt( numStates ) + 1;
- }
- renderEntity.shaderParms[ SHADERPARM_TIMEOFFSET ] = -MS2SEC( gameLocal.time );
- ActivateTargets( activator );
- if ( spawnArgs.GetBool( "hideWhenBroken" ) ) {
- Hide();
- PostEventMS( &EV_RestoreDamagable, nextTriggerTime - gameLocal.time );
- BecomeActive( TH_THINK );
- }
- }
- /*
- ================
- idDamagable::Killed
- ================
- */
- void idDamagable::Killed( idEntity *inflictor, idEntity *attacker, int damage, const idVec3 &dir, int location ) {
- if ( gameLocal.time < nextTriggerTime ) {
- health += damage;
- return;
- }
- BecomeBroken( attacker );
- }
- #ifdef _D3XP
- /*
- ================
- idDamagable::Hide
- ================
- */
- void idDamagable::Hide( void ) {
- idEntity::Hide();
- GetPhysics()->SetContents( 0 );
- }
- /*
- ================
- idDamagable::Show
- ================
- */
- void idDamagable::Show( void ) {
- idEntity::Show();
- GetPhysics()->SetContents( CONTENTS_SOLID );
- }
- #endif
- /*
- ================
- idDamagable::Event_BecomeBroken
- ================
- */
- void idDamagable::Event_BecomeBroken( idEntity *activator ) {
- BecomeBroken( activator );
- }
- /*
- ================
- idDamagable::Event_RestoreDamagable
- ================
- */
- void idDamagable::Event_RestoreDamagable( void ) {
- health = spawnArgs.GetInt( "health", "5" );
- Show();
- }
- // Jump pad.
- // from Raven's Quake 4 source code.
- const idEventDef EV_UpdatePeak( "UpdatePeak", NULL );
- const idEventDef EV_ActivatePad( "activatepad", "d" );
- CLASS_DECLARATION( idForceField, idJumpPad )
- EVENT( EV_FindTargets, idJumpPad::Event_FindTargets )
- EVENT( EV_UpdatePeak, idJumpPad::Event_UpdatePeak )
- EVENT( EV_ActivatePad, idJumpPad::Event_ActivatePad )
- END_CLASS
- void idJumpPad::Save( idSaveGame *savefile ) const
- {
- savefile->WriteInt(lastEffectTime);
- savefile->WriteBool(activepad);
- savefile->WriteMat3(effectAxis);
- }
- void idJumpPad::Restore( idRestoreGame *savefile )
- {
- savefile->ReadInt(lastEffectTime);
- savefile->ReadBool(activepad);
- savefile->ReadMat3(effectAxis);
- }
- void idJumpPad::Event_ActivatePad( int value )
- {
- activepad = value;
- }
- /*
- ================
- rvJumpPad::Think
- ================
- */
- void idJumpPad::Think( void )
- {
- if ( !activepad )
- return;
- //do not launch player if player is holding the launcher.
- bool isCarrying = false;
- if (gameLocal.GetLocalPlayer()->pickerWeapon.dragEnt.IsValid())
- {
- if (idStr::Icmp(this->spawnArgs.GetString("owner"), gameLocal.GetLocalPlayer()->pickerWeapon.dragEnt.GetEntity()->GetName()) == 0)
- {
- isCarrying = true;
- }
- }
- if ( (thinkFlags & TH_THINK) && !isCarrying )
- {
- // evaluate force
- forceField.Evaluate( gameLocal.time );
-
- // If force has been applied to an entity and jump pad effect hasnt been played for a bit
- // then play it now.
- if ( forceField.GetLastApplyTime ( ) - lastEffectTime > JUMPPAD_EFFECT_DELAY )
- {
- // start locally
- StartSound( "snd_jump", SND_CHANNEL_ITEM, 0, false, NULL );
- const char *smokeName = spawnArgs.GetString( "smoke_jump" );
- if ( *smokeName != '\0' )
- {
- const idDeclParticle *smokeFly = NULL;
- smokeFly = static_cast<const idDeclParticle *>( declManager->FindType( DECL_PARTICLE, smokeName ) );
- if (smokeFly)
- {
- gameLocal.smokeParticles->EmitSmoke( smokeFly, gameLocal.time, 0,
- renderEntity.origin, effectAxis, timeGroup );
- }
- }
- /*
- if ( spawnArgs.GetString( "fx_jump" )[ 0 ] )
- {
- PlayEffect( "fx_jump", renderEntity.origin, effectAxis, false, vec3_origin, false );
- }
- */
-
- this->lastEffectTime = gameLocal.time;
- }
- }
- Present();
- forceField.clipModel->SetPosition(this->GetPhysics()->GetOrigin(), this->GetPhysics()->GetAxis());
-
- }
- /*
- ================
- rvJumpPad::Spawn
- ================
- */
- void idJumpPad::Spawn( void ) {
- forceField.SetApplyType( FORCEFIELD_APPLY_VELOCITY );
- //forceField.SetOwner( this );
- this->lastEffectTime = 100;
- this->thinkFlags |= TH_THINK;
- //call this manually for the Launcher scriptobject.
- Event_FindTargets();
- forceField.owner = this;
- activepad = 1;
- if ( spawnArgs.GetBool("start_off", "0"))
- {
- activepad = 0;
- }
- }
- /*
- ================
- rvJumpPad::Event_FindTargets
- ================
- */
- void idJumpPad::Event_FindTargets( void ) {
- FindTargets();
- RemoveNullTargets();
- if ( targets.Num() )
- {
- idEntity* ent;
- ent = targets[0].GetEntity();
- assert( ent );
-
- idVec3 vert;
- idVec3 diff;
- idVec3 vel;
- idVec3 localGravity( ent->GetPhysics()->GetGravity() );
- idVec3 localGravityNormal = ent->GetPhysics()->GetGravityNormal();
- float time;
- float dist;
-
- // Find the distance along the gravity vector between the jump pad and its target
- diff = (ent->GetPhysics()->GetOrigin() - GetPhysics()->GetOrigin());
- vert = (diff * localGravityNormal) * localGravityNormal;
-
- // Determine how long it would take to cover the distance along the gravity vector
- time = idMath::Sqrt( vert.Length() / (0.5f * localGravity.Length()) );
-
- if ( !time )
- {
- PostEventMS( &EV_Remove, 0 );
- return;
- }
- // The final velocity is the direction between the jump pad and its target using
- // the travel time to determine the forward vector and adding in an inverse gravity vector.
- vel = diff - vert;
- dist = vel.Normalize();
-
- vel = vel * (dist / time);
- vel += (localGravity * -time);
- forceField.Uniform( vel );
- // calculate a coordinate axis where the vector to the jumppad target is forward
- // use this to play the fx_jump fx
- diff.Normalize();
- effectAxis = diff.ToMat3();
- }
- }
- void idJumpPad::Event_UpdateMultiplier(float value)
- {
- forceField.forceMultiplier = value;
- }
- void idJumpPad::Event_UpdatePeak( void )
- {
- Event_FindTargets();
- }
- /*
- ===============
- rvJumpPad::ClientReceiveEvent
- ===============
- */
- bool idJumpPad::ClientReceiveEvent( int event, int time, const idBitMsg &msg ) {
- switch ( event ) {
- case EVENT_JUMPFX: {
- /*
- if ( spawnArgs.GetString( "fx_jump" )[ 0 ] )
- {
- PlayEffect( "fx_jump", renderEntity.origin, effectAxis, false, vec3_origin, false );
- }
- */
- StartSound( "snd_jump", SND_CHANNEL_ITEM, 0, false, NULL );
- return true;
- }
- default:
- return idEntity::ClientReceiveEvent( event, time, msg );
- }
- }
- /* idAttractor ================================================================ */
- const idEventDef EV_attractortoggle( "attractortoggle", "d" );
- CLASS_DECLARATION( idTarget, idAttractor )
- EVENT( EV_attractortoggle, idAttractor::Event_attractortoggle)
- END_CLASS
- void idAttractor::Spawn( void )
- {
- idStr jointName;
- idStr entName;
- jointName = spawnArgs.GetString("joint", "");
- if (jointName.Length() <= 0)
- {
- common->Warning("Warning: idAttractor %s is missing 'joint' field.\n", this->name.c_str() );
- delete this;
- return;
- }
- entName = spawnArgs.GetString("entity", "");
- if (entName.Length() <= 0)
- {
- common->Warning("Warning: idAttractor %s is missing 'entity' field.\n", this->name.c_str() );
- delete this;
- return;
- }
- this->targEnt = gameLocal.FindEntity( entName );
- if (!this->targEnt.IsValid())
- {
- common->Warning("Warning: idAttractor %s couldn't find entity: %s\n", this->name.c_str() , entName.c_str() );
- delete this;
- return;
- }
- this->contactID = this->targEnt.GetEntity()->GetAnimator()->GetJointHandle( jointName );
- if (!this->contactID)
- {
- common->Warning("Warning: idAttractor couldn't find joint: %s on entity: %s\n", jointName.c_str(), this->name.c_str() );
- delete this;
- return;
- }
- if ( developer.GetBool() )
- gameRenderWorld->DebugLine(colorYellow, this->GetPhysics()->GetOrigin(), this->GetPhysics()->GetOrigin() + idVec3(0,0,2), 200);
- isActive = 1;
- }
- void idAttractor::Event_attractortoggle(int value)
- {
- isActive = value;
- }
- void idAttractor::Think( void )
- {
- if (!isActive)
- return;
-
- idVec3 forceDir, v, objectCenter;
- float forceAmt;
- float mass;
- float distanceToGoal;
- float damping = 0.5f;
- if (!this->targEnt.IsValid())
- {
- common->Warning("Warning: idAttractor couldn't find targEnt.\n");
- //common->Warning("Warning: idAttractor %s couldn't find targEnt. TargEnt was deleted?\n", this->name );
- delete this;
- return;
- }
- objectCenter = this->targEnt.GetEntity()->GetPhysics()->GetAbsBounds(this->contactID).GetCenter();
- mass = this->targEnt.GetEntity()->GetPhysics()->GetMass(this->contactID);
- forceDir = this->GetPhysics()->GetOrigin() - objectCenter;
-
-
- distanceToGoal = forceDir.Length();
- forceDir.Normalize();
- forceAmt = (1000.f * mass) + (3000.f * distanceToGoal * mass);
- this->targEnt.GetEntity()->GetPhysics()->AddForce( this->contactID, objectCenter, forceDir * forceAmt );
- //v = this->targEnt.GetEntity()->GetPhysics()->GetLinearVelocity( this->contactID );
- //this->targEnt.GetEntity()->GetPhysics()->SetLinearVelocity( v * damping, this->contactID );
- if (distanceToGoal <= 1 && spawnArgs.GetBool("auto_remove", "1"))
- {
- idStr callbackEntName = spawnArgs.GetString("callbackEnt", "");
- idStr callbackFuncName = spawnArgs.GetString("callbackFunc", "");
- if (callbackEntName.Length() > 0 && callbackFuncName.Length() > 0)
- {
- idEntity *callbackEnt = gameLocal.FindEntity( callbackEntName );
-
- if (callbackEnt)
- {
- gameLocal.GetLocalPlayer()->UseFrob( callbackEnt, callbackFuncName );
- }
- }
- //common->Printf("dist: %f\n", distanceToGoal);
- //gameRenderWorld->DebugCircle(idVec4(1,0,0,1), objectCenter, idVec3(0,0,1), 0.5, 4, 20000);
- //gameRenderWorld->DebugArrow(idVec4(1,0,0,1), objectCenter, this->GetPhysics()->GetOrigin(), 1, 20000);
- ActivateTargets( this );
- delete this;
- return;
- }
- }
- /*
- ===============================================================================
- idExplodable
-
- ===============================================================================
- */
- CLASS_DECLARATION( idEntity, idExplodable )
- EVENT( EV_Activate, idExplodable::Event_Explode )
- END_CLASS
- /*
- ================
- idExplodable::Spawn
- ================
- */
- void idExplodable::Spawn( void ) {
- Hide();
- bool startoff;
- this->spawnArgs.GetBool( "start_off", "1", startoff );
- if (!startoff)
- {
- Event_Explode( NULL );
- }
- }
- /*
- ================
- idExplodable::Event_Explode
- ================
- */
- void idExplodable::Event_Explode( idEntity *activator ) {
- const char *temp;
- if ( spawnArgs.GetString( "def_damage", "damage_explosion", &temp ) ) {
- gameLocal.RadiusDamage( GetPhysics()->GetOrigin(), activator, activator, this, this, temp );
- }
- StartSound( "snd_explode", SND_CHANNEL_ANY, 0, false, NULL );
- // Show() calls UpdateVisuals, so we don't need to call it ourselves after setting the shaderParms
- renderEntity.shaderParms[SHADERPARM_RED] = 1.0f;
- renderEntity.shaderParms[SHADERPARM_GREEN] = 1.0f;
- renderEntity.shaderParms[SHADERPARM_BLUE] = 1.0f;
- renderEntity.shaderParms[SHADERPARM_ALPHA] = 1.0f;
- renderEntity.shaderParms[SHADERPARM_TIMEOFFSET] = -MS2SEC( gameLocal.time );
- renderEntity.shaderParms[SHADERPARM_DIVERSITY] = 0.0f;
- Show();
- PostEventMS( &EV_Remove, 12000 );
- ActivateTargets( activator );
- }
- /*
- ===============================================================================
- idSpring
-
- ===============================================================================
- */
- CLASS_DECLARATION( idEntity, idSpring )
- EVENT( EV_PostSpawn, idSpring::Event_LinkSpring )
- END_CLASS
- /*
- ================
- idSpring::Think
- ================
- */
- void idSpring::Think( void ) {
- idVec3 start, end, origin;
- idMat3 axis;
- // run physics
- RunPhysics();
- if ( thinkFlags & TH_THINK ) {
- // evaluate force
- spring.Evaluate( gameLocal.time );
- start = p1;
- if ( ent1->GetPhysics() ) {
- axis = ent1->GetPhysics()->GetAxis();
- origin = ent1->GetPhysics()->GetOrigin();
- start = origin + start * axis;
- }
- end = p2;
- if ( ent2->GetPhysics() ) {
- axis = ent2->GetPhysics()->GetAxis();
- origin = ent2->GetPhysics()->GetOrigin();
- end = origin + p2 * axis;
- }
-
- gameRenderWorld->DebugLine( idVec4(1, 1, 0, 1), start, end, 0, true );
- }
- Present();
- }
- /*
- ================
- idSpring::Event_LinkSpring
- ================
- */
- void idSpring::Event_LinkSpring( void ) {
- idStr name1, name2;
- spawnArgs.GetString( "ent1", "", name1 );
- spawnArgs.GetString( "ent2", "", name2 );
- if ( name1.Length() ) {
- ent1 = gameLocal.FindEntity( name1 );
- if ( !ent1 ) {
- gameLocal.Error( "idSpring '%s' at (%s): cannot find first entity '%s'", name.c_str(), GetPhysics()->GetOrigin().ToString(0), name1.c_str() );
- }
- }
- else {
- ent1 = gameLocal.entities[ENTITYNUM_WORLD];
- }
- if ( name2.Length() ) {
- ent2 = gameLocal.FindEntity( name2 );
- if ( !ent2 ) {
- gameLocal.Error( "idSpring '%s' at (%s): cannot find second entity '%s'", name.c_str(), GetPhysics()->GetOrigin().ToString(0), name2.c_str() );
- }
- }
- else {
- ent2 = gameLocal.entities[ENTITYNUM_WORLD];
- }
- spring.SetPosition( ent1->GetPhysics(), id1, p1, ent2->GetPhysics(), id2, p2 );
- BecomeActive( TH_THINK );
- }
- /*
- ================
- idSpring::Spawn
- ================
- */
- void idSpring::Spawn( void ) {
- float Kstretch, damping, restLength;
- float Kcompression;
- spawnArgs.GetInt( "id1", "0", id1 );
- spawnArgs.GetInt( "id2", "0", id2 );
- spawnArgs.GetVector( "point1", "0 0 0", p1 );
- spawnArgs.GetVector( "point2", "0 0 0", p2 );
- spawnArgs.GetFloat( "constant", "100.0f", Kstretch );
- spawnArgs.GetFloat( "constant", "100.0f", Kcompression );
- spawnArgs.GetFloat( "damping", "10.0f", damping );
- spawnArgs.GetFloat( "restlength", "0.0f", restLength );
- spring.InitSpring( Kstretch, Kcompression, damping, restLength );
- ent1 = ent2 = NULL;
- PostEventMS( &EV_PostSpawn, 0 );
- }
- /*
- ===============================================================================
- idForceField
-
- ===============================================================================
- */
- const idEventDef EV_Toggle( "Toggle", NULL );
- CLASS_DECLARATION( idEntity, idForceField )
- EVENT( EV_Activate, idForceField::Event_Activate )
- EVENT( EV_Toggle, idForceField::Event_Toggle )
- EVENT( EV_FindTargets, idForceField::Event_FindTargets )
- END_CLASS
- /*
- ===============
- idForceField::Toggle
- ================
- */
- void idForceField::Toggle( void ) {
- if ( thinkFlags & TH_THINK ) {
- BecomeInactive( TH_THINK );
- } else {
- BecomeActive( TH_THINK );
- }
- }
- /*
- ================
- idForceField::Think
- ================
- */
- void idForceField::Think( void ) {
- if ( thinkFlags & TH_THINK ) {
- // evaluate force
- forceField.Evaluate( gameLocal.time );
- }
- Present();
- }
- /*
- ================
- idForceField::Save
- ================
- */
- void idForceField::Save( idSaveGame *savefile ) const {
- savefile->WriteStaticObject( forceField );
- }
- /*
- ================
- idForceField::Restore
- ================
- */
- void idForceField::Restore( idRestoreGame *savefile ) {
- savefile->ReadStaticObject( forceField );
- }
- /*
- ================
- idForceField::Spawn
- ================
- */
- void idForceField::Spawn( void ) {
- idVec3 uniform;
- float explosion, implosion, randomTorque;
- if ( spawnArgs.GetVector( "uniform", "0 0 0", uniform ) ) {
- forceField.Uniform( uniform );
- } else if ( spawnArgs.GetFloat( "explosion", "0", explosion ) ) {
- forceField.Explosion( explosion );
- } else if ( spawnArgs.GetFloat( "implosion", "0", implosion ) ) {
- forceField.Implosion( implosion );
- }
- if ( spawnArgs.GetFloat( "randomTorque", "0", randomTorque ) ) {
- forceField.RandomTorque( randomTorque );
- }
- if ( spawnArgs.GetBool( "applyForce", "0" ) ) {
- forceField.SetApplyType( FORCEFIELD_APPLY_FORCE );
- } else if ( spawnArgs.GetBool( "applyImpulse", "0" ) ) {
- forceField.SetApplyType( FORCEFIELD_APPLY_IMPULSE );
- } else {
- forceField.SetApplyType( FORCEFIELD_APPLY_VELOCITY );
- }
- forceField.SetPlayerOnly( spawnArgs.GetBool( "playerOnly", "0" ) );
- forceField.SetMonsterOnly( spawnArgs.GetBool( "monsterOnly", "0" ) );
- // set the collision model on the force field
- forceField.SetClipModel( 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 );
- }
- }
- /*
- ===============
- idForceField::Event_Toggle
- ================
- */
- void idForceField::Event_Toggle( void ) {
- Toggle();
- }
- /*
- ================
- idForceField::Event_Activate
- ================
- */
- void idForceField::Event_Activate( idEntity *activator ) {
- float wait;
- Toggle();
- if ( spawnArgs.GetFloat( "wait", "0.01", wait ) ) {
- PostEventSec( &EV_Toggle, wait );
- }
- }
- /*
- ================
- idForceField::Event_FindTargets
- ================
- */
- void idForceField::Event_FindTargets( void ) {
- FindTargets();
- RemoveNullTargets();
- if ( targets.Num() ) {
- forceField.Uniform( targets[0].GetEntity()->GetPhysics()->GetOrigin() - GetPhysics()->GetOrigin() );
- }
- }
- /*
- ===============================================================================
- idAnimated
- ===============================================================================
- */
- const idEventDef EV_AnimStart( "startAnim" );
- const idEventDef EV_Animated_Start( "<start>" );
- const idEventDef EV_LaunchMissiles( "launchMissiles", "ssssdf" );
- const idEventDef EV_LaunchMissilesUpdate( "<launchMissiles>", "dddd" );
- const idEventDef EV_AnimDone( "<AnimDone>", "d" );
- const idEventDef EV_StartRagdoll( "startRagdoll" );
- #ifdef _D3XP
- const idEventDef EV_SetAnimation( "setAnimation", "s" );
- const idEventDef EV_GetAnimationLength( "getAnimationLength", NULL, 'f' );
- #endif
- CLASS_DECLARATION( idAFEntity_Gibbable, idAnimated )
- EVENT( EV_Activate, idAnimated::Event_Activate )
- EVENT( EV_AnimStart, idAnimated::Event_Start )
- EVENT( EV_Animated_Start, idAnimated::Event_Start )
- EVENT( EV_StartRagdoll, idAnimated::Event_StartRagdoll )
- EVENT( EV_AnimDone, idAnimated::Event_AnimDone )
- EVENT( EV_Footstep, idAnimated::Event_Footstep )
- EVENT( EV_FootstepLeft, idAnimated::Event_Footstep )
- EVENT( EV_FootstepRight, idAnimated::Event_Footstep )
- EVENT( EV_LaunchMissiles, idAnimated::Event_LaunchMissiles )
- EVENT( EV_LaunchMissilesUpdate, idAnimated::Event_LaunchMissilesUpdate )
- #ifdef _D3XP
- EVENT( EV_SetAnimation, idAnimated::Event_SetAnimation )
- EVENT( EV_GetAnimationLength, idAnimated::Event_GetAnimationLength )
- #endif
- END_CLASS
- /*
- ===============
- idAnimated::idAnimated
- ================
- */
- idAnimated::idAnimated() {
- anim = 0;
- blendFrames = 0;
- soundJoint = INVALID_JOINT;
- activated = false;
- combatModel = NULL;
- activator = NULL;
- current_anim_index = 0;
- num_anims = 0;
- }
- /*
- ===============
- idAnimated::idAnimated
- ================
- */
- idAnimated::~idAnimated() {
- delete combatModel;
- combatModel = NULL;
- }
- /*
- ===============
- idAnimated::Save
- ================
- */
- void idAnimated::Save( idSaveGame *savefile ) const {
- savefile->WriteInt( current_anim_index );
- savefile->WriteInt( num_anims );
- savefile->WriteInt( anim );
- savefile->WriteInt( blendFrames );
- savefile->WriteJoint( soundJoint );
- activator.Save( savefile );
- savefile->WriteBool( activated );
- }
- /*
- ===============
- idAnimated::Restore
- ================
- */
- void idAnimated::Restore( idRestoreGame *savefile ) {
- savefile->ReadInt( current_anim_index );
- savefile->ReadInt( num_anims );
- savefile->ReadInt( anim );
- savefile->ReadInt( blendFrames );
- savefile->ReadJoint( soundJoint );
- activator.Restore( savefile );
- savefile->ReadBool( activated );
- }
- /*
- ===============
- idAnimated::Spawn
- ================
- */
- void idAnimated::Spawn( void ) {
- idStr animname;
- int anim2;
- float wait;
- const char *joint;
- joint = spawnArgs.GetString( "sound_bone", "origin" );
- soundJoint = animator.GetJointHandle( joint );
- if ( soundJoint == INVALID_JOINT ) {
- gameLocal.Warning( "idAnimated '%s' at (%s): cannot find joint '%s' for sound playback", name.c_str(), GetPhysics()->GetOrigin().ToString(0), joint );
- }
- LoadAF();
- // allow bullets to collide with a combat model
- if ( spawnArgs.GetBool( "combatModel", "0" ) ) {
- combatModel = new idClipModel( modelDefHandle );
- }
- // allow the entity to take damage
- if ( spawnArgs.GetBool( "takeDamage", "0" ) ) {
- fl.takedamage = true;
- }
- blendFrames = 0;
- current_anim_index = 0;
- spawnArgs.GetInt( "num_anims", "0", num_anims );
- blendFrames = spawnArgs.GetInt( "blend_in" );
- animname = spawnArgs.GetString( num_anims ? "anim1" : "anim" );
- if ( !animname.Length() ) {
- anim = 0;
- } else {
- anim = animator.GetAnim( animname );
- if ( !anim ) {
- gameLocal.Error( "idAnimated '%s' at (%s): cannot find anim '%s'", name.c_str(), GetPhysics()->GetOrigin().ToString(0), animname.c_str() );
- }
- }
- if ( spawnArgs.GetBool( "hide" ) ) {
- Hide();
- if ( !num_anims ) {
- blendFrames = 0;
- }
- } else if ( spawnArgs.GetString( "start_anim", "", animname ) ) {
- anim2 = animator.GetAnim( animname );
- if ( !anim2 ) {
- gameLocal.Error( "idAnimated '%s' at (%s): cannot find anim '%s'", name.c_str(), GetPhysics()->GetOrigin().ToString(0), animname.c_str() );
- }
- animator.CycleAnim( ANIMCHANNEL_ALL, anim2, gameLocal.time, 0 );
- } else if ( anim ) {
- // init joints to the first frame of the animation
- animator.SetFrame( ANIMCHANNEL_ALL, anim, 1, gameLocal.time, 0 );
- if ( !num_anims ) {
- blendFrames = 0;
- }
- }
- if (spawnArgs.GetInt("corpse", "0"))
- {
- //GetPhysics()->SetContents( CONTENTS_CORPSE );
- GetPhysics()->SetContents( CONTENTS_RENDERMODEL );
- GetPhysics()->SetClipMask( MASK_SOLID | CONTENTS_MOVEABLECLIP );
- }
- spawnArgs.GetFloat( "wait", "-1", wait );
- //bc
- StartSound( "snd_ambient", SND_CHANNEL_AMBIENT, 0, false, NULL );
- if ( wait >= 0 ) {
- PostEventSec( &EV_Activate, wait, this );
- }
- }
- /*
- ===============
- idAnimated::LoadAF
- ===============
- */
- bool idAnimated::LoadAF( void ) {
- idStr fileName;
- if ( !spawnArgs.GetString( "ragdoll", "*unknown*", fileName ) ) {
- return false;
- }
- af.SetAnimator( GetAnimator() );
- return af.Load( this, fileName );
- }
- /*
- ===============
- idAnimated::GetPhysicsToSoundTransform
- ===============
- */
- bool idAnimated::GetPhysicsToSoundTransform( idVec3 &origin, idMat3 &axis ) {
- animator.GetJointTransform( soundJoint, gameLocal.time, origin, axis );
- axis = renderEntity.axis;
- return true;
- }
- /*
- ================
- idAnimated::StartRagdoll
- ================
- */
- bool idAnimated::StartRagdoll( void ) {
- // if no AF loaded
- if ( !af.IsLoaded() ) {
- return false;
- }
- // if the AF is already active
- if ( af.IsActive() ) {
- return true;
- }
- // disable any collision model used
- GetPhysics()->DisableClip();
- // start using the AF
- af.StartFromCurrentPose( spawnArgs.GetInt( "velocityTime", "0" ) );
-
- return true;
- }
- /*
- =====================
- idAnimated::PlayNextAnim
- =====================
- */
- void idAnimated::PlayNextAnim( void ) {
- const char *animname;
- int len;
- int cycle;
- if ( current_anim_index >= num_anims ) {
- Hide();
- if ( spawnArgs.GetBool( "remove" ) ) {
- PostEventMS( &EV_Remove, 0 );
- } else {
- current_anim_index = 0;
- }
- return;
- }
- Show();
- current_anim_index++;
- spawnArgs.GetString( va( "anim%d", current_anim_index ), NULL, &animname );
- if ( !animname ) {
- anim = 0;
- animator.Clear( ANIMCHANNEL_ALL, gameLocal.time, FRAME2MS( blendFrames ) );
- return;
- }
- anim = animator.GetAnim( animname );
- if ( !anim ) {
- gameLocal.Warning( "missing anim '%s' on %s", animname, name.c_str() );
- return;
- }
- if ( g_debugCinematic.GetBool() ) {
- gameLocal.Printf( "%d: '%s' start anim '%s'\n", gameLocal.framenum, GetName(), animname );
- }
-
- spawnArgs.GetInt( "cycle", "1", cycle );
- if ( ( current_anim_index == num_anims ) && spawnArgs.GetBool( "loop_last_anim" ) ) {
- cycle = -1;
- }
- animator.CycleAnim( ANIMCHANNEL_ALL, anim, gameLocal.time, FRAME2MS( blendFrames ) );
- animator.CurrentAnim( ANIMCHANNEL_ALL )->SetCycleCount( cycle );
- len = animator.CurrentAnim( ANIMCHANNEL_ALL )->PlayLength();
- if ( len >= 0 ) {
- PostEventMS( &EV_AnimDone, len, current_anim_index );
- }
- // offset the start time of the shader to sync it to the game time
- renderEntity.shaderParms[ SHADERPARM_TIMEOFFSET ] = -MS2SEC( gameLocal.time );
- animator.ForceUpdate();
- UpdateAnimation();
- UpdateVisuals();
- Present();
- }
- /*
- ===============
- idAnimated::Event_StartRagdoll
- ================
- */
- void idAnimated::Event_StartRagdoll( void ) {
- StartRagdoll();
- }
- /*
- ===============
- idAnimated::Event_AnimDone
- ================
- */
- void idAnimated::Event_AnimDone( int animindex ) {
- if ( g_debugCinematic.GetBool() ) {
- const idAnim *animPtr = animator.GetAnim( anim );
- gameLocal.Printf( "%d: '%s' end anim '%s'\n", gameLocal.framenum, GetName(), animPtr ? animPtr->Name() : "" );
- }
- if ( ( animindex >= num_anims ) && spawnArgs.GetBool( "remove" ) ) {
- Hide();
- PostEventMS( &EV_Remove, 0 );
- } else if ( spawnArgs.GetBool( "auto_advance" ) ) {
- PlayNextAnim();
- }
- else if ( spawnArgs.GetBool( "cycle" ) )
- {
- //bc if cycle is set, then repeat the last played animation.
- animator.CycleAnim( ANIMCHANNEL_ALL, anim, gameLocal.time, 0 );
- }
- else {
- activated = false;
- }
- if (spawnArgs.GetBool( "notriggeronanim" ))
- return;
-
- ActivateTargets( activator.GetEntity() );
- }
- /*
- ===============
- idAnimated::Event_Activate
- ================
- */
- void idAnimated::Event_Activate( idEntity *_activator ) {
-
- gameLocal.GetLocalPlayer()->UseFrob( this, "onActivate" );
-
- if ( num_anims ) {
- PlayNextAnim();
- activator = _activator;
- return;
- }
- if ( activated ) {
- // already activated
- return;
- }
- activated = true;
- activator = _activator;
- ProcessEvent( &EV_Animated_Start );
- }
- /*
- ===============
- idAnimated::Event_Start
- ================
- */
- void idAnimated::Event_Start( void ) {
- int cycle;
- int len;
- Show();
- if ( num_anims ) {
- PlayNextAnim();
- return;
- }
- if ( anim ) {
- if ( g_debugCinematic.GetBool() ) {
- const idAnim *animPtr = animator.GetAnim( anim );
- gameLocal.Printf( "%d: '%s' start anim '%s'\n", gameLocal.framenum, GetName(), animPtr ? animPtr->Name() : "" );
- }
- spawnArgs.GetInt( "cycle", "1", cycle );
- animator.CycleAnim( ANIMCHANNEL_ALL, anim, gameLocal.time, FRAME2MS( blendFrames ) );
- animator.CurrentAnim( ANIMCHANNEL_ALL )->SetCycleCount( cycle );
- len = animator.CurrentAnim( ANIMCHANNEL_ALL )->PlayLength();
- if ( len >= 0 ) {
- PostEventMS( &EV_AnimDone, len, 1 );
- }
- }
- // offset the start time of the shader to sync it to the game time
- renderEntity.shaderParms[ SHADERPARM_TIMEOFFSET ] = -MS2SEC( gameLocal.time );
- animator.ForceUpdate();
- UpdateAnimation();
- UpdateVisuals();
- Present();
- }
- /*
- ===============
- idAnimated::Event_Footstep
- ===============
- */
- void idAnimated::Event_Footstep( void ) {
- StartSound( "snd_footstep", SND_CHANNEL_BODY, 0, false, NULL );
- }
- /*
- =====================
- idAnimated::Event_LaunchMissilesUpdate
- =====================
- */
- void idAnimated::Event_LaunchMissilesUpdate( int launchjoint, int targetjoint, int numshots, int framedelay ) {
- idVec3 launchPos;
- idVec3 targetPos;
- idMat3 axis;
- idVec3 dir;
- idEntity * ent;
- idProjectile * projectile;
- const idDict * projectileDef;
- const char * projectilename;
- projectilename = spawnArgs.GetString( "projectilename" );
- projectileDef = gameLocal.FindEntityDefDict( projectilename, false );
- if ( !projectileDef ) {
- gameLocal.Warning( "idAnimated '%s' at (%s): 'launchMissiles' called with unknown projectile '%s'", name.c_str(), GetPhysics()->GetOrigin().ToString(0), projectilename );
- return;
- }
- StartSound( "snd_missile", SND_CHANNEL_WEAPON, 0, false, NULL );
- animator.GetJointTransform( ( jointHandle_t )launchjoint, gameLocal.time, launchPos, axis );
- launchPos = renderEntity.origin + launchPos * renderEntity.axis;
-
- animator.GetJointTransform( ( jointHandle_t )targetjoint, gameLocal.time, targetPos, axis );
- targetPos = renderEntity.origin + targetPos * renderEntity.axis;
- dir = targetPos - launchPos;
- dir.Normalize();
- gameLocal.SpawnEntityDef( *projectileDef, &ent, false );
- if ( !ent || !ent->IsType( idProjectile::Type ) ) {
- gameLocal.Error( "idAnimated '%s' at (%s): in 'launchMissiles' call '%s' is not an idProjectile", name.c_str(), GetPhysics()->GetOrigin().ToString(0), projectilename );
- }
- projectile = ( idProjectile * )ent;
- projectile->Create( this, launchPos, dir );
- projectile->Launch( launchPos, dir, vec3_origin );
- if ( numshots > 0 ) {
- PostEventMS( &EV_LaunchMissilesUpdate, FRAME2MS( framedelay ), launchjoint, targetjoint, numshots - 1, framedelay );
- }
- }
- /*
- =====================
- idAnimated::Event_LaunchMissiles
- =====================
- */
- void idAnimated::Event_LaunchMissiles( const char *projectilename, const char *sound, const char *launchjoint, const char *targetjoint, int numshots, int framedelay ) {
- const idDict * projectileDef;
- jointHandle_t launch;
- jointHandle_t target;
- projectileDef = gameLocal.FindEntityDefDict( projectilename, false );
- if ( !projectileDef ) {
- gameLocal.Warning( "idAnimated '%s' at (%s): unknown projectile '%s'", name.c_str(), GetPhysics()->GetOrigin().ToString(0), projectilename );
- return;
- }
- launch = animator.GetJointHandle( launchjoint );
- if ( launch == INVALID_JOINT ) {
- gameLocal.Warning( "idAnimated '%s' at (%s): unknown launch joint '%s'", name.c_str(), GetPhysics()->GetOrigin().ToString(0), launchjoint );
- gameLocal.Error( "Unknown joint '%s'", launchjoint );
- }
- target = animator.GetJointHandle( targetjoint );
- if ( target == INVALID_JOINT ) {
- gameLocal.Warning( "idAnimated '%s' at (%s): unknown target joint '%s'", name.c_str(), GetPhysics()->GetOrigin().ToString(0), targetjoint );
- }
- spawnArgs.Set( "projectilename", projectilename );
- spawnArgs.Set( "missilesound", sound );
- CancelEvents( &EV_LaunchMissilesUpdate );
- ProcessEvent( &EV_LaunchMissilesUpdate, launch, target, numshots - 1, framedelay );
- }
- #ifdef _D3XP
- /*
- =====================
- idAnimated::Event_SetAnimation
- =====================
- */
- void idAnimated::Event_SetAnimation( const char *animName ) {
- //BSM Nerve: Need to add some error checking so we don't change the animation
- //in the middle of the existing animation
- anim = animator.GetAnim( animName );
- if ( !anim ) {
- gameLocal.Error( "idAnimated '%s' at (%s): cannot find anim '%s'", name.c_str(), GetPhysics()->GetOrigin().ToString(0), animName );
- }
-
- //bc force the next animation to trigger.
- activated = false;
- }
- /*
- =====================
- idAnimated::Event_GetAnimationLength
- =====================
- */
- void idAnimated::Event_GetAnimationLength() {
- float length = 0;
- if(anim) {
- length = (float)(animator.AnimLength( anim )) / 1000.f;
- }
- idThread::ReturnFloat(length);
- }
- #endif
- /*
- ===============================================================================
- idStaticEntity
- Some static entities may be optimized into inline geometry by dmap
- ===============================================================================
- */
- CLASS_DECLARATION( idEntity, idStaticEntity )
- EVENT( EV_Activate, idStaticEntity::Event_Activate )
- END_CLASS
- /*
- ===============
- idStaticEntity::idStaticEntity
- ===============
- */
- idStaticEntity::idStaticEntity( void ) {
- spawnTime = 0;
- active = false;
- fadeFrom.Set( 1, 1, 1, 1 );
- fadeTo.Set( 1, 1, 1, 1 );
- fadeStart = 0;
- fadeEnd = 0;
- runGui = false;
- isCam = false;
- spinning = false;
- }
- /*
- ===============
- idStaticEntity::Save
- ===============
- */
- void idStaticEntity::Save( idSaveGame *savefile ) const {
- savefile->WriteInt( spawnTime );
- savefile->WriteBool( active );
- savefile->WriteVec4( fadeFrom );
- savefile->WriteVec4( fadeTo );
- savefile->WriteInt( fadeStart );
- savefile->WriteInt( fadeEnd );
- savefile->WriteBool( runGui );
- //bc
- savefile->WriteBool(spinning);
- savefile->WriteBool(isCam);
- }
- /*
- ===============
- idStaticEntity::Restore
- ===============
- */
- void idStaticEntity::Restore( idRestoreGame *savefile ) {
- savefile->ReadInt( spawnTime );
- savefile->ReadBool( active );
- savefile->ReadVec4( fadeFrom );
- savefile->ReadVec4( fadeTo );
- savefile->ReadInt( fadeStart );
- savefile->ReadInt( fadeEnd );
- savefile->ReadBool( runGui );
- //bc
- savefile->ReadBool(spinning);
- savefile->ReadBool(isCam);
- }
- /*
- ===============
- idStaticEntity::Spawn
- ===============
- */
- void idStaticEntity::Spawn( void ) {
- bool solid;
- bool hidden;
- bool corpse;
- isCam = false;
- spinning = false;
- // an inline static model will not do anything at all
- if ( spawnArgs.GetBool( "inline" ) || gameLocal.world->spawnArgs.GetBool( "inlineAllStatics" ) ) {
- Hide();
- return;
- }
- solid = spawnArgs.GetBool( "solid" );
- hidden = spawnArgs.GetBool( "hide" );
- if ( solid && !hidden ) {
- GetPhysics()->SetContents( CONTENTS_SOLID );
- } else {
- GetPhysics()->SetContents( 0 );
- }
- corpse = spawnArgs.GetBool("corpse");
- if (corpse && !hidden)
- {
- //GetPhysics()->SetContents( CONTENTS_CORPSE );
- GetPhysics()->SetContents( CONTENTS_RENDERMODEL );
- GetPhysics()->SetClipMask( MASK_SOLID | CONTENTS_MOVEABLECLIP );
- }
-
- spawnTime = gameLocal.time;
- active = false;
- idStr model = spawnArgs.GetString( "model" );
- if ( model.Find( ".prt" ) >= 0 ) {
- // we want the parametric particles out of sync with each other
- renderEntity.shaderParms[ SHADERPARM_TIMEOFFSET ] = gameLocal.random.RandomInt( 32767 );
- }
- fadeFrom.Set( 1, 1, 1, 1 );
- fadeTo.Set( 1, 1, 1, 1 );
- fadeStart = 0;
- fadeEnd = 0;
- // NOTE: this should be used very rarely because it is expensive
- runGui = spawnArgs.GetBool( "runGui" );
- if ( runGui ) {
- BecomeActive( TH_THINK );
- }
- //BC 12-20-2013 add this to make idstaticentity update its cameraviews
- idStr cameraName = spawnArgs.GetString( "cameraTarget" );
- if ( cameraName.Length() > 0)
- {
- BecomeActive( TH_THINK );
- this->isCam = true;
- }
- spinning = spawnArgs.GetBool( "spin" );
- if ( spinning )
- {
- BecomeActive( TH_THINK );
- }
- //hide splines
- if (spawnArgs.FindKeyIndex("curve_Nurbs") >= 0 || spawnArgs.FindKeyIndex("curve_CatmullRomSpline") >= 0)
- {
- this->Hide();
- }
- }
- /*
- ================
- idStaticEntity::ShowEditingDialog
- ================
- */
- void idStaticEntity::ShowEditingDialog( void ) {
- common->InitTool( EDITOR_PARTICLE, &spawnArgs );
- }
- /*
- ================
- idStaticEntity::Think
- ================
- */
- void idStaticEntity::Think( void ) {
- idEntity::Think();
- if (isCam)
- {
- UpdateVisuals();
- }
- if ( thinkFlags & TH_THINK ) {
- if ( runGui && renderEntity.gui[0] ) {
- idPlayer *player = gameLocal.GetLocalPlayer();
- if ( player ) {
- if ( !player->objectiveSystemOpen ) {
- renderEntity.gui[0]->StateChanged( gameLocal.time, true );
- if ( renderEntity.gui[1] ) {
- renderEntity.gui[1]->StateChanged( gameLocal.time, true );
- }
- if ( renderEntity.gui[2] ) {
- renderEntity.gui[2]->StateChanged( gameLocal.time, true );
- }
- }
- }
- }
- if ( fadeEnd > 0 ) {
- idVec4 color;
- if ( gameLocal.time < fadeEnd ) {
- color.Lerp( fadeFrom, fadeTo, ( float )( gameLocal.time - fadeStart ) / ( float )( fadeEnd - fadeStart ) );
- } else {
- color = fadeTo;
- fadeEnd = 0;
- BecomeInactive( TH_THINK );
- }
- SetColor( color );
- }
- }
- if (spinning)
- {
- idAngles ang;
- idVec3 org;
- ang.pitch = ang.roll = 0.0f;
- ang.yaw = ( gameLocal.time & 4095 ) * 360.0f / -4096.0f;
- SetAngles( ang );
- }
- }
- /*
- ================
- idStaticEntity::Fade
- ================
- */
- void idStaticEntity::Fade( const idVec4 &to, float fadeTime ) {
- GetColor( fadeFrom );
- fadeTo = to;
- fadeStart = gameLocal.time;
- fadeEnd = gameLocal.time + SEC2MS( fadeTime );
- BecomeActive( TH_THINK );
- }
- /*
- ================
- idStaticEntity::Hide
- ================
- */
- void idStaticEntity::Hide( void ) {
- idEntity::Hide();
- GetPhysics()->SetContents( 0 );
- }
- /*
- ================
- idStaticEntity::Show
- ================
- */
- void idStaticEntity::Show( void ) {
- idEntity::Show();
- if ( spawnArgs.GetBool( "solid" ) ) {
- GetPhysics()->SetContents( CONTENTS_SOLID );
- }
- }
- /*
- ================
- idStaticEntity::Event_Activate
- ================
- */
- void idStaticEntity::Event_Activate( idEntity *activator ) {
- idStr activateGui;
- if (spawnArgs.GetBool( "scripttriggered", "1" ))
- {
- gameLocal.GetLocalPlayer()->UseFrob( this, "onActivate" );
- return;
- }
- spawnTime = gameLocal.time;
- active = !active;
- const idKeyValue *kv = spawnArgs.FindKey( "hide" );
- if ( kv ) {
- if ( IsHidden() ) {
- Show();
- } else {
- Hide();
- }
- }
- renderEntity.shaderParms[ SHADERPARM_TIMEOFFSET ] = -MS2SEC( spawnTime );
- renderEntity.shaderParms[5] = active;
- // this change should be a good thing, it will automatically turn on
- // lights etc.. when triggered so that does not have to be specifically done
- // with trigger parms.. it MIGHT break things so need to keep an eye on it
- renderEntity.shaderParms[ SHADERPARM_MODE ] = ( renderEntity.shaderParms[ SHADERPARM_MODE ] ) ? 0.0f : 1.0f;
- BecomeActive( TH_UPDATEVISUALS );
- }
- /*
- ================
- idStaticEntity::WriteToSnapshot
- ================
- */
- void idStaticEntity::WriteToSnapshot( idBitMsgDelta &msg ) const {
- GetPhysics()->WriteToSnapshot( msg );
- WriteBindToSnapshot( msg );
- WriteColorToSnapshot( msg );
- WriteGUIToSnapshot( msg );
- msg.WriteBits( IsHidden()?1:0, 1 );
- }
- /*
- ================
- idStaticEntity::ReadFromSnapshot
- ================
- */
- void idStaticEntity::ReadFromSnapshot( const idBitMsgDelta &msg ) {
- bool hidden;
- GetPhysics()->ReadFromSnapshot( msg );
- ReadBindFromSnapshot( msg );
- ReadColorFromSnapshot( msg );
- ReadGUIFromSnapshot( msg );
- hidden = msg.ReadBits( 1 ) == 1;
- if ( hidden != IsHidden() ) {
- if ( hidden ) {
- Hide();
- } else {
- Show();
- }
- }
- if ( msg.HasChanged() ) {
- UpdateVisuals();
- }
- }
- /*
- ===============================================================================
- idFuncEmitter
- ===============================================================================
- */
- const idEventDef EV_emitter_isenabled( "isemitterenabled", NULL, 'd' );
- const idEventDef EV_emitter_enable( "emitterenable", "d" );
- CLASS_DECLARATION( idStaticEntity, idFuncEmitter )
- EVENT( EV_Activate, idFuncEmitter::Event_Activate )
- EVENT( EV_emitter_enable, idFuncEmitter::Event_Enable )
- EVENT( EV_emitter_isenabled, idFuncEmitter::Event_IsEnabled )
- END_CLASS
- /*
- ===============
- idFuncEmitter::idFuncEmitter
- ===============
- */
- idFuncEmitter::idFuncEmitter( void ) {
- hidden = false;
- }
- /*
- ===============
- idFuncEmitter::Spawn
- ===============
- */
- void idFuncEmitter::Spawn( void ) {
- if ( spawnArgs.GetBool( "start_off" ) ) {
- hidden = true;
- renderEntity.shaderParms[SHADERPARM_PARTICLE_STOPTIME] = MS2SEC( 1 );
- UpdateVisuals();
- } else {
- hidden = false;
- }
- }
- /*
- ===============
- idFuncEmitter::Save
- ===============
- */
- void idFuncEmitter::Save( idSaveGame *savefile ) const {
- savefile->WriteBool( hidden );
- }
- /*
- ===============
- idFuncEmitter::Restore
- ===============
- */
- void idFuncEmitter::Restore( idRestoreGame *savefile ) {
- savefile->ReadBool( hidden );
- }
- void idFuncEmitter::Event_IsEnabled( )
- {
- if (hidden)
- idThread::ReturnInt( 0 );
- else
- idThread::ReturnInt( 1 );
- }
- void idFuncEmitter::Event_Enable( int value )
- {
- if (value > 0 && hidden == false)
- return;
- if (value <= 0 && hidden == true)
- return;
- if (value > 0)
- {
- hidden = true;
- }
- else
- {
- hidden = false;
- }
- Event_Activate(NULL);
- }
- /*
- ================
- idFuncEmitter::Event_Activate
- ================
- */
- void idFuncEmitter::Event_Activate( idEntity *activator ) {
- if ( hidden || spawnArgs.GetBool( "cycleTrigger" ) ) {
- renderEntity.shaderParms[SHADERPARM_PARTICLE_STOPTIME] = 0;
- renderEntity.shaderParms[SHADERPARM_TIMEOFFSET] = -MS2SEC( gameLocal.time );
- hidden = false;
- } else {
- renderEntity.shaderParms[SHADERPARM_PARTICLE_STOPTIME] = MS2SEC( gameLocal.time );
- hidden = true;
- }
- UpdateVisuals();
- }
- /*
- ================
- idFuncEmitter::WriteToSnapshot
- ================
- */
- void idFuncEmitter::WriteToSnapshot( idBitMsgDelta &msg ) const {
- msg.WriteBits( hidden ? 1 : 0, 1 );
- msg.WriteFloat( renderEntity.shaderParms[ SHADERPARM_PARTICLE_STOPTIME ] );
- msg.WriteFloat( renderEntity.shaderParms[ SHADERPARM_TIMEOFFSET ] );
- }
- /*
- ================
- idFuncEmitter::ReadFromSnapshot
- ================
- */
- void idFuncEmitter::ReadFromSnapshot( const idBitMsgDelta &msg ) {
- hidden = msg.ReadBits( 1 ) != 0;
- renderEntity.shaderParms[ SHADERPARM_PARTICLE_STOPTIME ] = msg.ReadFloat();
- renderEntity.shaderParms[ SHADERPARM_TIMEOFFSET ] = msg.ReadFloat();
- if ( msg.HasChanged() ) {
- UpdateVisuals();
- }
- }
- /*
- ===============================================================================
- idFuncSplat
- ===============================================================================
- */
- const idEventDef EV_Splat( "<Splat>" );
- CLASS_DECLARATION( idFuncEmitter, idFuncSplat )
- EVENT( EV_Activate, idFuncSplat::Event_Activate )
- EVENT( EV_Splat, idFuncSplat::Event_Splat )
- END_CLASS
- /*
- ===============
- idFuncSplat::idFuncSplat
- ===============
- */
- idFuncSplat::idFuncSplat( void ) {
- }
- /*
- ===============
- idFuncSplat::Spawn
- ===============
- */
- void idFuncSplat::Spawn( void ) {
- }
- /*
- ================
- idFuncSplat::Event_Splat
- ================
- */
- void idFuncSplat::Event_Splat( void ) {
- const char *splat = NULL;
- int count = spawnArgs.GetInt( "splatCount", "1" );
- for ( int i = 0; i < count; i++ ) {
- splat = spawnArgs.RandomPrefix( "mtr_splat", gameLocal.random );
- if ( splat && *splat ) {
- float size = spawnArgs.GetFloat( "splatSize", "128" );
- float dist = spawnArgs.GetFloat( "splatDistance", "128" );
- float angle = spawnArgs.GetFloat( "splatAngle", "0" );
- gameLocal.ProjectDecal( GetPhysics()->GetOrigin(), GetPhysics()->GetAxis()[2], dist, true, size, splat, angle );
- }
- }
- StartSound( "snd_splat", SND_CHANNEL_ANY, 0, false, NULL );
- }
- /*
- ================
- idFuncSplat::Event_Activate
- ================
- */
- void idFuncSplat::Event_Activate( idEntity *activator ) {
- idFuncEmitter::Event_Activate( activator );
- PostEventSec( &EV_Splat, spawnArgs.GetFloat( "splatDelay", "0.25" ) );
- StartSound( "snd_spurt", SND_CHANNEL_ANY, 0, false, NULL );
- }
- /*
- ===============================================================================
- idFuncSmoke
- ===============================================================================
- */
- CLASS_DECLARATION( idEntity, idFuncSmoke )
- EVENT( EV_Activate, idFuncSmoke::Event_Activate )
- END_CLASS
- /*
- ===============
- idFuncSmoke::idFuncSmoke
- ===============
- */
- idFuncSmoke::idFuncSmoke() {
- smokeTime = 0;
- smoke = NULL;
- restart = false;
- }
- /*
- ===============
- idFuncSmoke::Save
- ===============
- */
- void idFuncSmoke::Save( idSaveGame *savefile ) const {
- savefile->WriteInt( smokeTime );
- savefile->WriteParticle( smoke );
- savefile->WriteBool( restart );
- }
- /*
- ===============
- idFuncSmoke::Restore
- ===============
- */
- void idFuncSmoke::Restore( idRestoreGame *savefile ) {
- savefile->ReadInt( smokeTime );
- savefile->ReadParticle( smoke );
- savefile->ReadBool( restart );
- }
- /*
- ===============
- idFuncSmoke::Spawn
- ===============
- */
- void idFuncSmoke::Spawn( void ) {
- const char *smokeName = spawnArgs.GetString( "smoke" );
- if ( *smokeName != '\0' ) {
- smoke = static_cast<const idDeclParticle *>( declManager->FindType( DECL_PARTICLE, smokeName ) );
- } else {
- smoke = NULL;
- }
- if ( spawnArgs.GetBool( "start_off" ) ) {
- smokeTime = 0;
- restart = false;
- } else if ( smoke ) {
- smokeTime = gameLocal.time;
- BecomeActive( TH_UPDATEPARTICLES );
- restart = true;
- }
- GetPhysics()->SetContents( 0 );
- }
- /*
- ================
- idFuncSmoke::Event_Activate
- ================
- */
- void idFuncSmoke::Event_Activate( idEntity *activator ) {
- if ( thinkFlags & TH_UPDATEPARTICLES ) {
- restart = false;
- return;
- } else {
- BecomeActive( TH_UPDATEPARTICLES );
- restart = true;
- smokeTime = gameLocal.time;
- }
- }
- /*
- ===============
- idFuncSmoke::Think
- ================
- */
- void idFuncSmoke::Think( void ) {
- // if we are completely closed off from the player, don't do anything at all
- if ( CheckDormant() || smoke == NULL || smokeTime == -1 ) {
- return;
- }
- if ( ( thinkFlags & TH_UPDATEPARTICLES) && !IsHidden() ) {
- if ( !gameLocal.smokeParticles->EmitSmoke( smoke, smokeTime, gameLocal.random.CRandomFloat(), GetPhysics()->GetOrigin(), GetPhysics()->GetAxis(), timeGroup /*_D3XP*/ ) ) {
- if ( restart ) {
- smokeTime = gameLocal.time;
- } else {
- smokeTime = 0;
- BecomeInactive( TH_UPDATEPARTICLES );
- }
- }
- }
- }
- /*
- ===============================================================================
- idTextEntity
- ===============================================================================
- */
- CLASS_DECLARATION( idEntity, idTextEntity )
- END_CLASS
- /*
- ================
- idTextEntity::Spawn
- ================
- */
- void idTextEntity::Spawn( void ) {
- // these are cached as the are used each frame
- text = spawnArgs.GetString( "text" );
- playerOriented = spawnArgs.GetBool( "playerOriented" );
- bool force = spawnArgs.GetBool( "force" );
- if ( developer.GetBool() || force ) {
- BecomeActive(TH_THINK);
- }
- }
- /*
- ================
- idTextEntity::Save
- ================
- */
- void idTextEntity::Save( idSaveGame *savefile ) const {
- savefile->WriteString( text );
- savefile->WriteBool( playerOriented );
- }
- /*
- ================
- idTextEntity::Restore
- ================
- */
- void idTextEntity::Restore( idRestoreGame *savefile ) {
- savefile->ReadString( text );
- savefile->ReadBool( playerOriented );
- }
- /*
- ================
- idTextEntity::Think
- ================
- */
- void idTextEntity::Think( void ) {
- if ( thinkFlags & TH_THINK ) {
- gameRenderWorld->DrawText( text, GetPhysics()->GetOrigin(), 0.25, colorWhite, playerOriented ? gameLocal.GetLocalPlayer()->viewAngles.ToMat3() : GetPhysics()->GetAxis().Transpose(), 1 );
- for ( int i = 0; i < targets.Num(); i++ ) {
- if ( targets[i].GetEntity() ) {
- gameRenderWorld->DebugArrow( colorBlue, GetPhysics()->GetOrigin(), targets[i].GetEntity()->GetPhysics()->GetOrigin(), 1 );
- }
- }
- } else {
- BecomeInactive( TH_ALL );
- }
- }
- /*
- ===============================================================================
- idVacuumSeperatorEntity
- Can be triggered to let vacuum through a portal (blown out window)
- ===============================================================================
- */
- const idEventDef EV_VacuumToggle( "vacuumtoggle", "d" );
- CLASS_DECLARATION( idEntity, idVacuumSeparatorEntity )
- EVENT( EV_Activate, idVacuumSeparatorEntity::Event_Activate )
- EVENT( EV_VacuumToggle, idVacuumSeparatorEntity::Event_VacuumToggle )
- END_CLASS
- /*
- ================
- idVacuumSeparatorEntity::idVacuumSeparatorEntity
- ================
- */
- idVacuumSeparatorEntity::idVacuumSeparatorEntity( void ) {
- portal = 0;
- }
- /*
- ================
- idVacuumSeparatorEntity::Save
- ================
- */
- void idVacuumSeparatorEntity::Save( idSaveGame *savefile ) const {
- savefile->WriteInt( (int)portal );
- savefile->WriteInt( gameRenderWorld->GetPortalState( portal ) );
- }
- /*
- ================
- idVacuumSeparatorEntity::Restore
- ================
- */
- void idVacuumSeparatorEntity::Restore( idRestoreGame *savefile ) {
- int state;
- savefile->ReadInt( (int &)portal );
- savefile->ReadInt( state );
- gameLocal.SetPortalState( portal, state );
- }
- /*
- ================
- idVacuumSeparatorEntity::Spawn
- ================
- */
- void idVacuumSeparatorEntity::Spawn() {
- idBounds b;
- b = idBounds( spawnArgs.GetVector( "origin" ) ).Expand( 16 );
- portal = gameRenderWorld->FindPortal( b );
- if ( !portal ) {
- gameLocal.Warning( "VacuumSeparator '%s' didn't contact a portal", spawnArgs.GetString( "name" ) );
- return;
- }
- gameLocal.SetPortalState( portal, PS_BLOCK_AIR | PS_BLOCK_LOCATION );
- }
- /*
- ================
- idVacuumSeparatorEntity::Event_Activate
- ================
- */
- void idVacuumSeparatorEntity::Event_Activate( idEntity *activator ) {
- if ( !portal ) {
- return;
- }
- gameLocal.SetPortalState( portal, PS_BLOCK_NONE );
- }
- void idVacuumSeparatorEntity::Event_VacuumToggle(int value)
- {
- if ( !portal ) {
- return;
- }
- gameLocal.SetPortalState( portal, value ? (PS_BLOCK_AIR | PS_BLOCK_LOCATION) : PS_BLOCK_NONE );
- }
- /*
- ===============================================================================
- idLocationSeparatorEntity
- ===============================================================================
- */
- CLASS_DECLARATION( idEntity, idLocationSeparatorEntity )
- END_CLASS
- /*
- ================
- idLocationSeparatorEntity::Spawn
- ================
- */
- void idLocationSeparatorEntity::Spawn() {
- idBounds b;
- b = idBounds( spawnArgs.GetVector( "origin" ) ).Expand( 16 );
- qhandle_t portal = gameRenderWorld->FindPortal( b );
- if ( !portal ) {
- gameLocal.Warning( "LocationSeparator '%s' didn't contact a portal", spawnArgs.GetString( "name" ) );
- }
- gameLocal.SetPortalState( portal, PS_BLOCK_LOCATION );
- }
- /*
- ===============================================================================
- idVacuumEntity
- Levels should only have a single vacuum entity.
- ===============================================================================
- */
- CLASS_DECLARATION( idEntity, idVacuumEntity )
- END_CLASS
- /*
- ================
- idVacuumEntity::Spawn
- ================
- */
- void idVacuumEntity::Spawn() {
- if ( gameLocal.vacuumAreaNum != -1 ) {
- gameLocal.Warning( "idVacuumEntity::Spawn: multiple idVacuumEntity in level" );
- return;
- }
- idVec3 org = spawnArgs.GetVector( "origin" );
- gameLocal.vacuumAreaNum = gameRenderWorld->PointInArea( org );
- }
- /*
- ===============================================================================
- idLocationEntity
- ===============================================================================
- */
- CLASS_DECLARATION( idEntity, idLocationEntity )
- END_CLASS
- /*
- ======================
- idLocationEntity::Spawn
- ======================
- */
- void idLocationEntity::Spawn() {
- idStr realName;
- // this just holds dict information
- // if "location" not already set, use the entity name.
- if ( !spawnArgs.GetString( "location", "", realName ) ) {
- spawnArgs.Set( "location", name );
- }
- }
- /*
- ======================
- idLocationEntity::GetLocation
- ======================
- */
- const char *idLocationEntity::GetLocation( void ) const {
- return spawnArgs.GetString( "location" );
- }
- /*
- ===============================================================================
- idBeam
- ===============================================================================
- */
- const idEventDef EV_SetWidth( "SetWidth", "f" );
- CLASS_DECLARATION( idEntity, idBeam )
- EVENT( EV_PostSpawn, idBeam::Event_MatchTarget )
- EVENT( EV_Activate, idBeam::Event_Activate )
- EVENT( EV_SetWidth, idBeam::Event_SetWidth )
- END_CLASS
- /*
- ===============
- idBeam::idBeam
- ===============
- */
- idBeam::idBeam() {
- target = NULL;
- master = NULL;
- }
- /*
- ===============
- idBeam::Save
- ===============
- */
- void idBeam::Save( idSaveGame *savefile ) const {
- target.Save( savefile );
- master.Save( savefile );
- }
- /*
- ===============
- idBeam::Restore
- ===============
- */
- void idBeam::Restore( idRestoreGame *savefile ) {
- target.Restore( savefile );
- master.Restore( savefile );
- }
- /*
- ===============
- idBeam::Spawn
- ===============
- */
- void idBeam::Spawn( void ) {
- float width;
- if ( spawnArgs.GetFloat( "width", "0", width ) ) {
- renderEntity.shaderParms[ SHADERPARM_BEAM_WIDTH ] = width;
- }
- SetModel( "_BEAM" );
- Hide();
- PostEventMS( &EV_PostSpawn, 0 );
- }
- /*
- ================
- idBeam::Think
- ================
- */
- void idBeam::Think( void ) {
- idBeam *masterEnt;
- if ( !IsHidden() && !target.GetEntity() ) {
- // hide if our target is removed
- Hide();
- }
- RunPhysics();
- masterEnt = master.GetEntity();
- if ( masterEnt ) {
- const idVec3 &origin = GetPhysics()->GetOrigin();
- masterEnt->SetBeamTarget( origin );
- }
- Present();
- }
- /*
- ================
- idBeam::SetMaster
- ================
- */
- void idBeam::SetMaster( idBeam *masterbeam ) {
- master = masterbeam;
- }
- /*
- ================
- idBeam::SetBeamTarget
- ================
- */
- void idBeam::SetBeamTarget( const idVec3 &origin ) {
- if ( ( renderEntity.shaderParms[ SHADERPARM_BEAM_END_X ] != origin.x ) || ( renderEntity.shaderParms[ SHADERPARM_BEAM_END_Y ] != origin.y ) || ( renderEntity.shaderParms[ SHADERPARM_BEAM_END_Z ] != origin.z ) ) {
- renderEntity.shaderParms[ SHADERPARM_BEAM_END_X ] = origin.x;
- renderEntity.shaderParms[ SHADERPARM_BEAM_END_Y ] = origin.y;
- renderEntity.shaderParms[ SHADERPARM_BEAM_END_Z ] = origin.z;
- UpdateVisuals();
- }
- }
- /*
- ================
- idBeam::Show
- ================
- */
- void idBeam::Show( void ) {
- idBeam *targetEnt;
- idEntity::Show();
- targetEnt = target.GetEntity();
- if ( targetEnt ) {
- const idVec3 &origin = targetEnt->GetPhysics()->GetOrigin();
- SetBeamTarget( origin );
- }
- }
- void idBeam::Event_SetWidth( float value )
- {
- renderEntity.shaderParms[ SHADERPARM_BEAM_WIDTH ] = value;
- UpdateVisuals();
- }
- /*
- ================
- idBeam::Event_MatchTarget
- ================
- */
- void idBeam::Event_MatchTarget( void ) {
- int i;
- idEntity *targetEnt;
- idBeam *targetBeam;
- if ( !targets.Num() ) {
- return;
- }
- targetBeam = NULL;
- for( i = 0; i < targets.Num(); i++ ) {
- targetEnt = targets[ i ].GetEntity();
- if ( targetEnt && targetEnt->IsType( idBeam::Type ) ) {
- targetBeam = static_cast<idBeam *>( targetEnt );
- break;
- }
- }
- if ( !targetBeam ) {
- gameLocal.Error( "Could not find valid beam target for '%s'", name.c_str() );
- }
- target = targetBeam;
- targetBeam->SetMaster( this );
- if ( !spawnArgs.GetBool( "start_off" ) ) {
- Show();
- }
- }
- /*
- ================
- idBeam::Event_Activate
- ================
- */
- void idBeam::Event_Activate( idEntity *activator ) {
- if ( IsHidden() ) {
- Show();
- } else {
- Hide();
- }
- }
- /*
- ================
- idBeam::WriteToSnapshot
- ================
- */
- void idBeam::WriteToSnapshot( idBitMsgDelta &msg ) const {
- GetPhysics()->WriteToSnapshot( msg );
- WriteBindToSnapshot( msg );
- WriteColorToSnapshot( msg );
- msg.WriteFloat( renderEntity.shaderParms[SHADERPARM_BEAM_END_X] );
- msg.WriteFloat( renderEntity.shaderParms[SHADERPARM_BEAM_END_Y] );
- msg.WriteFloat( renderEntity.shaderParms[SHADERPARM_BEAM_END_Z] );
- }
- /*
- ================
- idBeam::ReadFromSnapshot
- ================
- */
- void idBeam::ReadFromSnapshot( const idBitMsgDelta &msg ) {
- GetPhysics()->ReadFromSnapshot( msg );
- ReadBindFromSnapshot( msg );
- ReadColorFromSnapshot( msg );
- renderEntity.shaderParms[SHADERPARM_BEAM_END_X] = msg.ReadFloat();
- renderEntity.shaderParms[SHADERPARM_BEAM_END_Y] = msg.ReadFloat();
- renderEntity.shaderParms[SHADERPARM_BEAM_END_Z] = msg.ReadFloat();
- if ( msg.HasChanged() ) {
- UpdateVisuals();
- }
- }
- /*
- ===============================================================================
- idLiquid
- ===============================================================================
- */
- CLASS_DECLARATION( idEntity, idLiquid )
- EVENT( EV_Touch, idLiquid::Event_Touch )
- END_CLASS
- /*
- ================
- idLiquid::Save
- ================
- */
- void idLiquid::Save( idSaveGame *savefile ) const {
- // Nothing to save
- }
- /*
- ================
- idLiquid::Restore
- ================
- */
- void idLiquid::Restore( idRestoreGame *savefile ) {
- //FIXME: NO!
- Spawn();
- }
- /*
- ================
- idLiquid::Spawn
- ================
- */
- void idLiquid::Spawn() {
- /*
- model = dynamic_cast<idRenderModelLiquid *>( renderEntity.hModel );
- if ( !model ) {
- gameLocal.Error( "Entity '%s' must have liquid model", name.c_str() );
- }
- model->Reset();
- GetPhysics()->SetContents( CONTENTS_TRIGGER );
- */
- }
- /*
- ================
- idLiquid::Event_Touch
- ================
- */
- void idLiquid::Event_Touch( idEntity *other, trace_t *trace ) {
- // FIXME: for QuakeCon
- /*
- idVec3 pos;
- pos = other->GetPhysics()->GetOrigin() - GetPhysics()->GetOrigin();
- model->IntersectBounds( other->GetPhysics()->GetBounds().Translate( pos ), -10.0f );
- */
- }
- /*
- ===============================================================================
- idShaking
- ===============================================================================
- */
- CLASS_DECLARATION( idEntity, idShaking )
- EVENT( EV_Activate, idShaking::Event_Activate )
- END_CLASS
- /*
- ===============
- idShaking::idShaking
- ===============
- */
- idShaking::idShaking() {
- active = false;
- }
- /*
- ===============
- idShaking::Save
- ===============
- */
- void idShaking::Save( idSaveGame *savefile ) const {
- savefile->WriteBool( active );
- savefile->WriteStaticObject( physicsObj );
- }
- /*
- ===============
- idShaking::Restore
- ===============
- */
- void idShaking::Restore( idRestoreGame *savefile ) {
- savefile->ReadBool( active );
- savefile->ReadStaticObject( physicsObj );
- RestorePhysics( &physicsObj );
- }
- /*
- ===============
- idShaking::Spawn
- ===============
- */
- void idShaking::Spawn( void ) {
- physicsObj.SetSelf( this );
- physicsObj.SetClipModel( new idClipModel( GetPhysics()->GetClipModel() ), 1.0f );
- physicsObj.SetOrigin( GetPhysics()->GetOrigin() );
- physicsObj.SetAxis( GetPhysics()->GetAxis() );
- physicsObj.SetClipMask( MASK_SOLID );
- SetPhysics( &physicsObj );
-
- active = false;
- if ( !spawnArgs.GetBool( "start_off" ) ) {
- BeginShaking();
- }
- }
- /*
- ================
- idShaking::BeginShaking
- ================
- */
- void idShaking::BeginShaking( void ) {
- int phase;
- idAngles shake;
- int period;
- active = true;
- phase = gameLocal.random.RandomInt( 1000 );
- shake = spawnArgs.GetAngles( "shake", "0.5 0.5 0.5" );
- period = spawnArgs.GetFloat( "period", "0.05" ) * 1000;
- physicsObj.SetAngularExtrapolation( extrapolation_t(EXTRAPOLATION_DECELSINE|EXTRAPOLATION_NOSTOP), phase, period * 0.25f, GetPhysics()->GetAxis().ToAngles(), shake, ang_zero );
- }
- /*
- ================
- idShaking::Event_Activate
- ================
- */
- void idShaking::Event_Activate( idEntity *activator ) {
- if ( !active ) {
- BeginShaking();
- } else {
- active = false;
- physicsObj.SetAngularExtrapolation( EXTRAPOLATION_NONE, 0, 0, physicsObj.GetAxis().ToAngles(), ang_zero, ang_zero );
- }
- }
- /*
- ===============================================================================
- idEarthQuake
- ===============================================================================
- */
- CLASS_DECLARATION( idEntity, idEarthQuake )
- EVENT( EV_Activate, idEarthQuake::Event_Activate )
- END_CLASS
- /*
- ===============
- idEarthQuake::idEarthQuake
- ===============
- */
- idEarthQuake::idEarthQuake() {
- wait = 0.0f;
- random = 0.0f;
- nextTriggerTime = 0;
- shakeStopTime = 0;
- triggered = false;
- playerOriented = false;
- disabled = false;
- shakeTime = 0.0f;
- }
- /*
- ===============
- idEarthQuake::Save
- ===============
- */
- void idEarthQuake::Save( idSaveGame *savefile ) const {
- savefile->WriteInt( nextTriggerTime );
- savefile->WriteInt( shakeStopTime );
- savefile->WriteFloat( wait );
- savefile->WriteFloat( random );
- savefile->WriteBool( triggered );
- savefile->WriteBool( playerOriented );
- savefile->WriteBool( disabled );
- savefile->WriteFloat( shakeTime );
- }
- /*
- ===============
- idEarthQuake::Restore
- ===============
- */
- void idEarthQuake::Restore( idRestoreGame *savefile ) {
- savefile->ReadInt( nextTriggerTime );
- savefile->ReadInt( shakeStopTime );
- savefile->ReadFloat( wait );
- savefile->ReadFloat( random );
- savefile->ReadBool( triggered );
- savefile->ReadBool( playerOriented );
- savefile->ReadBool( disabled );
- savefile->ReadFloat( shakeTime );
- if ( shakeStopTime > gameLocal.time ) {
- BecomeActive( TH_THINK );
- }
- }
- /*
- ===============
- idEarthQuake::Spawn
- ===============
- */
- void idEarthQuake::Spawn( void ) {
- nextTriggerTime = 0;
- shakeStopTime = 0;
- wait = spawnArgs.GetFloat( "wait", "15" );
- random = spawnArgs.GetFloat( "random", "5" );
- triggered = spawnArgs.GetBool( "triggered" );
- playerOriented = spawnArgs.GetBool( "playerOriented" );
- disabled = false;
- shakeTime = spawnArgs.GetFloat( "shakeTime", "0" );
- if ( !triggered ){
- PostEventSec( &EV_Activate, spawnArgs.GetFloat( "wait" ), this );
- }
- BecomeInactive( TH_THINK );
- }
- /*
- ================
- idEarthQuake::Event_Activate
- ================
- */
- void idEarthQuake::Event_Activate( idEntity *activator ) {
-
- if ( nextTriggerTime > gameLocal.time ) {
- return;
- }
- if ( disabled && activator == this ) {
- return;
- }
- idPlayer *player = gameLocal.GetLocalPlayer();
- if ( player == NULL ) {
- return;
- }
- nextTriggerTime = 0;
- if ( !triggered && activator != this ){
- // if we are not triggered ( i.e. random ), disable or enable
- disabled ^= 1;
- if (disabled) {
- return;
- } else {
- PostEventSec( &EV_Activate, wait + random * gameLocal.random.CRandomFloat(), this );
- }
- }
- ActivateTargets( activator );
- const idSoundShader *shader = declManager->FindSound( spawnArgs.GetString( "snd_quake" ) );
- if ( playerOriented ) {
- player->StartSoundShader( shader, SND_CHANNEL_ANY, SSF_GLOBAL, false, NULL );
- } else {
- StartSoundShader( shader, SND_CHANNEL_ANY, SSF_GLOBAL, false, NULL );
- }
- if ( shakeTime > 0.0f ) {
- shakeStopTime = gameLocal.time + SEC2MS( shakeTime );
- BecomeActive( TH_THINK );
- }
- if ( wait > 0.0f ) {
- if ( !triggered ) {
- PostEventSec( &EV_Activate, wait + random * gameLocal.random.CRandomFloat(), this );
- } else {
- nextTriggerTime = gameLocal.time + SEC2MS( wait + random * gameLocal.random.CRandomFloat() );
- }
- } else if ( shakeTime == 0.0f ) {
- PostEventMS( &EV_Remove, 0 );
- }
- }
- /*
- ===============
- idEarthQuake::Think
- ================
- */
- void idEarthQuake::Think( void ) {
- if ( thinkFlags & TH_THINK ) {
- if ( gameLocal.time > shakeStopTime ) {
- BecomeInactive( TH_THINK );
- if ( wait <= 0.0f ) {
- PostEventMS( &EV_Remove, 0 );
- }
- return;
- }
- float shakeVolume = gameSoundWorld->CurrentShakeAmplitudeForPosition( gameLocal.time, gameLocal.GetLocalPlayer()->firstPersonViewOrigin );
- gameLocal.RadiusPush( GetPhysics()->GetOrigin(), 256, 1500 * shakeVolume, this, this, 1.0f, true );
- }
- BecomeInactive( TH_UPDATEVISUALS );
- }
- /*
- ===============================================================================
- idFuncPortal
- ===============================================================================
- */
- const idEventDef EV_portal_activate( "portalactivate", "d" );
- CLASS_DECLARATION( idEntity, idFuncPortal )
- EVENT( EV_Activate, idFuncPortal::Event_Activate )
- EVENT( EV_portal_activate, idFuncPortal::Event_portalactivate)
- END_CLASS
- /*
- ===============
- idFuncPortal::idFuncPortal
- ===============
- */
- idFuncPortal::idFuncPortal() {
- portal = 0;
- state = false;
- }
- /*
- ===============
- idFuncPortal::Save
- ===============
- */
- void idFuncPortal::Save( idSaveGame *savefile ) const {
- savefile->WriteInt( (int)portal );
- savefile->WriteBool( state );
- }
- /*
- ===============
- idFuncPortal::Restore
- ===============
- */
- void idFuncPortal::Restore( idRestoreGame *savefile ) {
- savefile->ReadInt( (int &)portal );
- savefile->ReadBool( state );
- gameLocal.SetPortalState( portal, state ? PS_BLOCK_ALL : PS_BLOCK_NONE );
- }
- /*
- ===============
- idFuncPortal::Spawn
- ===============
- */
- void idFuncPortal::Spawn( void ) {
- portal = gameRenderWorld->FindPortal( GetPhysics()->GetAbsBounds().Expand( 32.0f ) );
- if ( portal > 0 ) {
- state = spawnArgs.GetBool( "start_on" );
- gameLocal.SetPortalState( portal, state ? PS_BLOCK_ALL : PS_BLOCK_NONE );
- }
- }
- /*
- ================
- idFuncPortal::Event_Activate
- ================
- */
- void idFuncPortal::Event_Activate( idEntity *activator ) {
- if ( portal > 0 ) {
- state = !state;
- gameLocal.SetPortalState( portal, state ? PS_BLOCK_ALL : PS_BLOCK_NONE );
- }
- }
- void idFuncPortal::Event_portalactivate( int value )
- {
- if (value <= 0)
- {
- gameLocal.SetPortalState( portal, PS_BLOCK_NONE );
- }
- else
- {
- gameLocal.SetPortalState( portal, PS_BLOCK_ALL );
- }
- }
- /*
- ===============================================================================
- idFuncAASPortal
- ===============================================================================
- */
- CLASS_DECLARATION( idEntity, idFuncAASPortal )
- EVENT( EV_Activate, idFuncAASPortal::Event_Activate )
- END_CLASS
- /*
- ===============
- idFuncAASPortal::idFuncAASPortal
- ===============
- */
- idFuncAASPortal::idFuncAASPortal() {
- state = false;
- }
- /*
- ===============
- idFuncAASPortal::Save
- ===============
- */
- void idFuncAASPortal::Save( idSaveGame *savefile ) const {
- savefile->WriteBool( state );
- }
- /*
- ===============
- idFuncAASPortal::Restore
- ===============
- */
- void idFuncAASPortal::Restore( idRestoreGame *savefile ) {
- savefile->ReadBool( state );
- gameLocal.SetAASAreaState( GetPhysics()->GetAbsBounds(), AREACONTENTS_CLUSTERPORTAL, state );
- }
- /*
- ===============
- idFuncAASPortal::Spawn
- ===============
- */
- void idFuncAASPortal::Spawn( void ) {
- state = spawnArgs.GetBool( "start_on" );
- gameLocal.SetAASAreaState( GetPhysics()->GetAbsBounds(), AREACONTENTS_CLUSTERPORTAL, state );
- }
- /*
- ================
- idFuncAASPortal::Event_Activate
- ================
- */
- void idFuncAASPortal::Event_Activate( idEntity *activator ) {
- state ^= 1;
- gameLocal.SetAASAreaState( GetPhysics()->GetAbsBounds(), AREACONTENTS_CLUSTERPORTAL, state );
- }
- /*
- ===============================================================================
- idFuncAASObstacle
- ===============================================================================
- */
- CLASS_DECLARATION( idEntity, idFuncAASObstacle )
- EVENT( EV_Activate, idFuncAASObstacle::Event_Activate )
- END_CLASS
- /*
- ===============
- idFuncAASObstacle::idFuncAASObstacle
- ===============
- */
- idFuncAASObstacle::idFuncAASObstacle() {
- state = false;
- }
- /*
- ===============
- idFuncAASObstacle::Save
- ===============
- */
- void idFuncAASObstacle::Save( idSaveGame *savefile ) const {
- savefile->WriteBool( state );
- }
- /*
- ===============
- idFuncAASObstacle::Restore
- ===============
- */
- void idFuncAASObstacle::Restore( idRestoreGame *savefile ) {
- savefile->ReadBool( state );
- gameLocal.SetAASAreaState( GetPhysics()->GetAbsBounds(), AREACONTENTS_OBSTACLE, state );
- }
- /*
- ===============
- idFuncAASObstacle::Spawn
- ===============
- */
- void idFuncAASObstacle::Spawn( void ) {
- state = spawnArgs.GetBool( "start_on" );
- gameLocal.SetAASAreaState( GetPhysics()->GetAbsBounds(), AREACONTENTS_OBSTACLE, state );
- }
- /*
- ================
- idFuncAASObstacle::Event_Activate
- ================
- */
- void idFuncAASObstacle::Event_Activate( idEntity *activator ) {
- state ^= 1;
- gameLocal.SetAASAreaState( GetPhysics()->GetAbsBounds(), AREACONTENTS_OBSTACLE, state );
- }
- /*
- ===============================================================================
- idFuncRadioChatter
- ===============================================================================
- */
- const idEventDef EV_ResetRadioHud( "<resetradiohud>", "e" );
- CLASS_DECLARATION( idEntity, idFuncRadioChatter )
- EVENT( EV_Activate, idFuncRadioChatter::Event_Activate )
- EVENT( EV_ResetRadioHud, idFuncRadioChatter::Event_ResetRadioHud )
- END_CLASS
- /*
- ===============
- idFuncRadioChatter::idFuncRadioChatter
- ===============
- */
- idFuncRadioChatter::idFuncRadioChatter() {
- time = 0.0;
- }
- /*
- ===============
- idFuncRadioChatter::Save
- ===============
- */
- void idFuncRadioChatter::Save( idSaveGame *savefile ) const {
- savefile->WriteFloat( time );
- }
- /*
- ===============
- idFuncRadioChatter::Restore
- ===============
- */
- void idFuncRadioChatter::Restore( idRestoreGame *savefile ) {
- savefile->ReadFloat( time );
- }
- /*
- ===============
- idFuncRadioChatter::Spawn
- ===============
- */
- void idFuncRadioChatter::Spawn( void ) {
- time = spawnArgs.GetFloat( "time", "5.0" );
- }
- /*
- ================
- idFuncRadioChatter::Event_Activate
- ================
- */
- void idFuncRadioChatter::Event_Activate( idEntity *activator ) {
- idPlayer *player;
- const char *sound;
- const idSoundShader *shader;
- int length;
-
- if ( activator->IsType( idPlayer::Type ) ) {
- player = static_cast<idPlayer *>( activator );
- } else {
- player = gameLocal.GetLocalPlayer();
- }
- player->hud->HandleNamedEvent( "radioChatterUp" );
- sound = spawnArgs.GetString( "snd_radiochatter", "" );
- if ( sound && *sound ) {
- shader = declManager->FindSound( sound );
- player->StartSoundShader( shader, SND_CHANNEL_RADIO, SSF_GLOBAL, false, &length );
- time = MS2SEC( length + 150 );
- }
- // we still put the hud up because this is used with no sound on
- // certain frame commands when the chatter is triggered
- PostEventSec( &EV_ResetRadioHud, time, player );
- }
- /*
- ================
- idFuncRadioChatter::Event_ResetRadioHud
- ================
- */
- void idFuncRadioChatter::Event_ResetRadioHud( idEntity *activator ) {
- idPlayer *player = ( activator->IsType( idPlayer::Type ) ) ? static_cast<idPlayer *>( activator ) : gameLocal.GetLocalPlayer();
- player->hud->HandleNamedEvent( "radioChatterDown" );
- ActivateTargets( activator );
- }
- /*
- ===============================================================================
- idPhantomObjects
- ===============================================================================
- */
- CLASS_DECLARATION( idEntity, idPhantomObjects )
- EVENT( EV_Activate, idPhantomObjects::Event_Activate )
- END_CLASS
- /*
- ===============
- idPhantomObjects::idPhantomObjects
- ===============
- */
- idPhantomObjects::idPhantomObjects() {
- target = NULL;
- end_time = 0;
- throw_time = 0.0f;
- shake_time = 0.0f;
- shake_ang.Zero();
- speed = 0.0f;
- min_wait = 0;
- max_wait = 0;
- fl.neverDormant = false;
- }
- /*
- ===============
- idPhantomObjects::Save
- ===============
- */
- void idPhantomObjects::Save( idSaveGame *savefile ) const {
- int i;
- savefile->WriteInt( end_time );
- savefile->WriteFloat( throw_time );
- savefile->WriteFloat( shake_time );
- savefile->WriteVec3( shake_ang );
- savefile->WriteFloat( speed );
- savefile->WriteInt( min_wait );
- savefile->WriteInt( max_wait );
- target.Save( savefile );
- savefile->WriteInt( targetTime.Num() );
- for( i = 0; i < targetTime.Num(); i++ ) {
- savefile->WriteInt( targetTime[ i ] );
- }
- for( i = 0; i < lastTargetPos.Num(); i++ ) {
- savefile->WriteVec3( lastTargetPos[ i ] );
- }
- }
- /*
- ===============
- idPhantomObjects::Restore
- ===============
- */
- void idPhantomObjects::Restore( idRestoreGame *savefile ) {
- int num;
- int i;
- savefile->ReadInt( end_time );
- savefile->ReadFloat( throw_time );
- savefile->ReadFloat( shake_time );
- savefile->ReadVec3( shake_ang );
- savefile->ReadFloat( speed );
- savefile->ReadInt( min_wait );
- savefile->ReadInt( max_wait );
- target.Restore( savefile );
-
- savefile->ReadInt( num );
- targetTime.SetGranularity( 1 );
- targetTime.SetNum( num );
- lastTargetPos.SetGranularity( 1 );
- lastTargetPos.SetNum( num );
- for( i = 0; i < num; i++ ) {
- savefile->ReadInt( targetTime[ i ] );
- }
- for( i = 0; i < num; i++ ) {
- savefile->ReadVec3( lastTargetPos[ i ] );
- }
- }
- /*
- ===============
- idPhantomObjects::Spawn
- ===============
- */
- void idPhantomObjects::Spawn( void ) {
- throw_time = spawnArgs.GetFloat( "time", "5" );
- speed = spawnArgs.GetFloat( "speed", "1200" );
- shake_time = spawnArgs.GetFloat( "shake_time", "1" );
- throw_time -= shake_time;
- if ( throw_time < 0.0f ) {
- throw_time = 0.0f;
- }
- min_wait = SEC2MS( spawnArgs.GetFloat( "min_wait", "1" ) );
- max_wait = SEC2MS( spawnArgs.GetFloat( "max_wait", "3" ) );
- shake_ang = spawnArgs.GetVector( "shake_ang", "65 65 65" );
- Hide();
- GetPhysics()->SetContents( 0 );
- }
- /*
- ================
- idPhantomObjects::Event_Activate
- ================
- */
- void idPhantomObjects::Event_Activate( idEntity *activator ) {
- int i;
- float time;
- float frac;
- float scale;
- if ( thinkFlags & TH_THINK ) {
- BecomeInactive( TH_THINK );
- return;
- }
- RemoveNullTargets();
- if ( !targets.Num() ) {
- return;
- }
- if ( !activator || !activator->IsType( idActor::Type ) ) {
- target = gameLocal.GetLocalPlayer();
- } else {
- target = static_cast<idActor *>( activator );
- }
-
- end_time = gameLocal.time + SEC2MS( spawnArgs.GetFloat( "end_time", "0" ) );
- targetTime.SetNum( targets.Num() );
- lastTargetPos.SetNum( targets.Num() );
- const idVec3 &toPos = target.GetEntity()->GetEyePosition();
- // calculate the relative times of all the objects
- time = 0.0f;
- for( i = 0; i < targetTime.Num(); i++ ) {
- targetTime[ i ] = SEC2MS( time );
- lastTargetPos[ i ] = toPos;
- frac = 1.0f - ( float )i / ( float )targetTime.Num();
- time += ( gameLocal.random.RandomFloat() + 1.0f ) * 0.5f * frac + 0.1f;
- }
- // scale up the times to fit within throw_time
- scale = throw_time / time;
- for( i = 0; i < targetTime.Num(); i++ ) {
- targetTime[ i ] = gameLocal.time + SEC2MS( shake_time )+ targetTime[ i ] * scale;
- }
- BecomeActive( TH_THINK );
- }
- /*
- ===============
- idPhantomObjects::Think
- ================
- */
- void idPhantomObjects::Think( void ) {
- int i;
- int num;
- float time;
- idVec3 vel;
- idVec3 ang;
- idEntity *ent;
- idActor *targetEnt;
- idPhysics *entPhys;
- trace_t tr;
- // if we are completely closed off from the player, don't do anything at all
- if ( CheckDormant() ) {
- return;
- }
- if ( !( thinkFlags & TH_THINK ) ) {
- BecomeInactive( thinkFlags & ~TH_THINK );
- return;
- }
- targetEnt = target.GetEntity();
- if ( !targetEnt || ( targetEnt->health <= 0 ) || ( end_time && ( gameLocal.time > end_time ) ) || gameLocal.inCinematic ) {
- BecomeInactive( TH_THINK );
- }
- const idVec3 &toPos = targetEnt->GetEyePosition();
- num = 0;
- for ( i = 0; i < targets.Num(); i++ ) {
- ent = targets[ i ].GetEntity();
- if ( !ent ) {
- continue;
- }
-
- if ( ent->fl.hidden ) {
- // don't throw hidden objects
- continue;
- }
- if ( !targetTime[ i ] ) {
- // already threw this object
- continue;
- }
- num++;
- time = MS2SEC( targetTime[ i ] - gameLocal.time );
- if ( time > shake_time ) {
- continue;
- }
- entPhys = ent->GetPhysics();
- const idVec3 &entOrg = entPhys->GetOrigin();
- gameLocal.clip.TracePoint( tr, entOrg, toPos, MASK_OPAQUE, ent );
- if ( tr.fraction >= 1.0f || ( gameLocal.GetTraceEntity( tr ) == targetEnt ) ) {
- lastTargetPos[ i ] = toPos;
- }
- if ( time < 0.0f ) {
- idAI::PredictTrajectory( entPhys->GetOrigin(), lastTargetPos[ i ], speed, entPhys->GetGravity(),
- entPhys->GetClipModel(), entPhys->GetClipMask(), 256.0f, ent, targetEnt, ai_debugTrajectory.GetBool() ? 1 : 0, vel );
- vel *= speed;
- entPhys->SetLinearVelocity( vel );
- if ( !end_time ) {
- targetTime[ i ] = 0;
- } else {
- targetTime[ i ] = gameLocal.time + gameLocal.random.RandomInt( max_wait - min_wait ) + min_wait;
- }
- if ( ent->IsType( idMoveable::Type ) ) {
- idMoveable *ment = static_cast<idMoveable*>( ent );
- ment->EnableDamage( true, 2.5f );
- }
- } else {
- // this is not the right way to set the angular velocity, but the effect is nice, so I'm keeping it. :)
- ang.Set( gameLocal.random.CRandomFloat() * shake_ang.x, gameLocal.random.CRandomFloat() * shake_ang.y, gameLocal.random.CRandomFloat() * shake_ang.z );
- ang *= ( 1.0f - time / shake_time );
- entPhys->SetAngularVelocity( ang );
- }
- }
- if ( !num ) {
- BecomeInactive( TH_THINK );
- }
- }
- #ifdef _D3XP
- /*
- ===============================================================================
- idShockwave
- ===============================================================================
- */
- CLASS_DECLARATION( idEntity, idShockwave )
- EVENT( EV_Activate, idShockwave::Event_Activate )
- END_CLASS
- /*
- ===============
- idShockwave::idShockwave
- ===============
- */
- idShockwave::idShockwave() {
- isActive = false;
- startTime = 0;
- duration = 0;
- startSize = 0.f;
- endSize = 0.f;
- currentSize = 0.f;
- magnitude = 0.f;
- height = 0.0f;
- playerDamaged = false;
- playerDamageSize = 0.0f;
- }
- /*
- ===============
- idShockwave::~idShockwave
- ===============
- */
- idShockwave::~idShockwave() {
- }
- /*
- ===============
- idShockwave::Save
- ===============
- */
- void idShockwave::Save( idSaveGame *savefile ) const {
- savefile->WriteBool( isActive );
- savefile->WriteInt( startTime );
- savefile->WriteInt( duration );
- savefile->WriteFloat( startSize );
- savefile->WriteFloat( endSize );
- savefile->WriteFloat( currentSize );
- savefile->WriteFloat( magnitude );
- savefile->WriteFloat( height );
- savefile->WriteBool( playerDamaged );
- savefile->WriteFloat( playerDamageSize );
- }
- /*
- ===============
- idShockwave::Restore
- ===============
- */
- void idShockwave::Restore( idRestoreGame *savefile ) {
- savefile->ReadBool( isActive );
- savefile->ReadInt( startTime );
- savefile->ReadInt( duration );
- savefile->ReadFloat( startSize );
- savefile->ReadFloat( endSize );
- savefile->ReadFloat( currentSize );
- savefile->ReadFloat( magnitude );
- savefile->ReadFloat( height );
- savefile->ReadBool( playerDamaged );
- savefile->ReadFloat( playerDamageSize );
-
- }
- /*
- ===============
- idShockwave::Spawn
- ===============
- */
- void idShockwave::Spawn() {
- spawnArgs.GetInt( "duration", "1000", duration );
- spawnArgs.GetFloat( "startsize", "8", startSize );
- spawnArgs.GetFloat( "endsize", "512", endSize );
- spawnArgs.GetFloat( "magnitude", "100", magnitude );
- spawnArgs.GetFloat( "height", "0", height);
- spawnArgs.GetFloat( "player_damage_size", "20", playerDamageSize);
- if ( spawnArgs.GetBool( "start_on" ) ) {
- ProcessEvent( &EV_Activate, this );
- }
- }
- /*
- ===============
- idShockwave::Think
- ===============
- */
- void idShockwave::Think() {
- int endTime;
- if ( !isActive ) {
- BecomeInactive( TH_THINK );
- return;
- }
- endTime = startTime + duration;
- if ( gameLocal.time < endTime ) {
- float u;
- float newSize;
- // Expand shockwave
- u = (float)(gameLocal.time - startTime) / (float)duration;
- newSize = startSize + u * (endSize - startSize);
- // Find all clipmodels between currentSize and newSize
- idVec3 pos, end;
- idClipModel *clipModelList[ MAX_GENTITIES ];
- idClipModel *clip;
- idEntity *ent;
- int i, listedClipModels;
- // Set bounds
- pos = GetPhysics()->GetOrigin();
- float zVal;
- if(!height) {
- zVal = newSize;
- } else {
- zVal = height/2.0f;
- }
-
- //Expand in a sphere
- end = pos + idVec3( newSize, newSize, zVal );
- idBounds bounds( end );
- end = pos + idVec3( -newSize, -newSize, -zVal );
- bounds.AddPoint( end );
-
- if(g_debugShockwave.GetBool()) {
- gameRenderWorld->DebugBounds(colorRed, bounds, vec3_origin);
- }
- listedClipModels = gameLocal.clip.ClipModelsTouchingBounds( bounds, -1, clipModelList, MAX_GENTITIES );
- for ( i = 0; i < listedClipModels; i++ ) {
- clip = clipModelList[ i ];
- ent = clip->GetEntity();
- if ( ent->IsHidden() ) {
- continue;
- }
- if ( !ent->IsType( idMoveable::Type ) && !ent->IsType( idAFEntity_Base::Type ) && !ent->IsType( idPlayer::Type )) {
- continue;
- }
- idVec3 point = ent->GetPhysics()->GetOrigin();
- idVec3 force = point - pos;
- float dist = force.Normalize();
- if(ent->IsType( idPlayer::Type )) {
- if(ent->GetPhysics()->GetAbsBounds().IntersectsBounds(bounds)) {
-
- //For player damage we check the current radius and a specified player damage ring size
- if ( dist <= newSize && dist > newSize-playerDamageSize ) {
- idStr damageDef = spawnArgs.GetString("def_player_damage", "");
- if(damageDef.Length() > 0 && !playerDamaged) {
- playerDamaged = true; //Only damage once per shockwave
- idPlayer* player = static_cast< idPlayer* >( ent );
- idVec3 dir = ent->GetPhysics()->GetOrigin() - pos;
- dir.NormalizeFast();
- player->Damage(NULL, NULL, dir, damageDef, 1.0f, INVALID_JOINT);
- }
- }
- }
- } else {
- // If the object is inside the current expansion...
- if ( dist <= newSize && dist > currentSize ) {
- force.z += 4.f;
- force.NormalizeFast();
- if ( ent->IsType( idAFEntity_Base::Type ) ) {
- force = force * (ent->GetPhysics()->GetMass() * magnitude * 0.01f);
- } else {
- force = force * ent->GetPhysics()->GetMass() * magnitude;
- }
- // Kick it up, move force point off object origin
- float rad = ent->GetPhysics()->GetBounds().GetRadius();
- point.x += gameLocal.random.CRandomFloat() * rad;
- point.y += gameLocal.random.CRandomFloat() * rad;
- int j;
- for( j=0; j < ent->GetPhysics()->GetNumClipModels(); j++ ) {
- ent->GetPhysics()->AddForce( j, point, force );
- }
- }
- }
- }
- // Update currentSize for next frame
- currentSize = newSize;
- } else {
- // turn off
- isActive = false;
- }
- }
- /*
- ===============
- idShockwave::Event_Activate
- ===============
- */
- void idShockwave::Event_Activate( idEntity *activator ) {
- isActive = true;
- startTime = gameLocal.time;
- playerDamaged = false;
- BecomeActive( TH_THINK );
- }
- /*
- ===============================================================================
- idFuncMountedObject
- ===============================================================================
- */
- CLASS_DECLARATION( idEntity, idFuncMountedObject )
- EVENT( EV_Touch, idFuncMountedObject::Event_Touch )
- EVENT( EV_Activate, idFuncMountedObject::Event_Activate )
- END_CLASS
- /*
- ===============
- idFuncMountedObject::idFuncMountedObject
- ===============
- */
- idFuncMountedObject::idFuncMountedObject() {
- isMounted = false;
- scriptFunction = NULL;
- mountedPlayer = NULL;
- harc = 0;
- varc = 0;
- }
- /*
- ===============
- idFuncMountedObject::idFuncMountedObject
- ===============
- */
- idFuncMountedObject::~idFuncMountedObject() {
- }
- /*
- ===============
- idFuncMountedObject::Spawn
- ===============
- */
- void idFuncMountedObject::Spawn( void ) {
- // Get viewOffset
- spawnArgs.GetInt( "harc", "45", harc );
- spawnArgs.GetInt( "varc", "30", varc );
- // Get script function
- idStr funcName = spawnArgs.GetString( "call", "" );
- if ( funcName.Length() ) {
- scriptFunction = gameLocal.program.FindFunction( funcName );
- if ( scriptFunction == NULL ) {
- gameLocal.Warning( "idFuncMountedObject '%s' at (%s) calls unknown function '%s'\n", name.c_str(), GetPhysics()->GetOrigin().ToString(0), funcName.c_str() );
- }
- }
- BecomeActive( TH_THINK );
- }
- /*
- ================
- idFuncMountedObject::Think
- ================
- */
- void idFuncMountedObject::Think( void ) {
- idEntity::Think();
- }
- /*
- ================
- idFuncMountedObject::GetViewInfo
- ================
- */
- void idFuncMountedObject::GetAngleRestrictions( int &yaw_min, int &yaw_max, int &pitch ) {
- idMat3 axis;
- idAngles angs;
- axis = GetPhysics()->GetAxis();
- angs = axis.ToAngles();
- yaw_min = angs.yaw - harc;
- yaw_min = idMath::AngleNormalize180( yaw_min );
- yaw_max = angs.yaw + harc;
- yaw_max = idMath::AngleNormalize180( yaw_max );
- pitch = varc;
- }
- /*
- ================
- idFuncMountedObject::Event_Touch
- ================
- */
- void idFuncMountedObject::Event_Touch( idEntity *other, trace_t *trace ) {
- ProcessEvent( &EV_Activate, other );
- }
- /*
- ================
- idFuncMountedObject::Event_Activate
- ================
- */
- void idFuncMountedObject::Event_Activate( idEntity *activator ) {
- if ( !isMounted && activator->IsType( idPlayer::Type ) ) {
- idPlayer *client = (idPlayer *)activator;
- mountedPlayer = client;
- /*
- // Place player at path_corner targeted by mounted object
- int i;
- idPathCorner *spot;
- for ( i = 0; i < targets.Num(); i++ ) {
- if ( targets[i]->IsType( idPathCorner::Type ) ) {
- spot = (idPathCorner*)targets[i];
- break;
- }
- }
- mountedPlayer->GetPhysics()->SetOrigin( spot->GetPhysics()->GetOrigin() );
- mountedPlayer->GetPhysics()->SetAxis( spot->GetPhysics()->GetAxis() );
- */
- mountedPlayer->Bind( this, true );
- mountedPlayer->mountedObject = this;
- // Call a script function
- idThread *mountthread;
- if ( scriptFunction ) {
- mountthread = new idThread( scriptFunction );
- mountthread->DelayedStart( 0 );
- }
- isMounted = true;
- }
- }
- /*
- ===============================================================================
- idFuncMountedWeapon
- ===============================================================================
- */
- CLASS_DECLARATION( idFuncMountedObject, idFuncMountedWeapon )
- EVENT( EV_PostSpawn, idFuncMountedWeapon::Event_PostSpawn )
- END_CLASS
- idFuncMountedWeapon::idFuncMountedWeapon() {
- turret = NULL;
- weaponLastFireTime = 0;
- weaponFireDelay = 0;
- projectile = NULL;
- }
- idFuncMountedWeapon::~idFuncMountedWeapon() {
- }
- void idFuncMountedWeapon::Spawn( void ) {
- // Get projectile info
- projectile = gameLocal.FindEntityDefDict( spawnArgs.GetString( "def_projectile" ), false );
- if ( !projectile ) {
- gameLocal.Warning( "Invalid projectile on func_mountedweapon." );
- }
- float firerate;
- spawnArgs.GetFloat( "firerate", "3", firerate );
- weaponFireDelay = 1000.f / firerate;
- // Get the firing sound
- idStr fireSound;
- spawnArgs.GetString( "snd_fire", "", fireSound );
- soundFireWeapon = declManager->FindSound( fireSound );
- PostEventMS( &EV_PostSpawn, 0 );
- }
- void idFuncMountedWeapon::Think( void ) {
- if ( isMounted && turret ) {
- idVec3 vec = mountedPlayer->viewAngles.ToForward();
- idAngles ang = mountedPlayer->GetLocalVector( vec ).ToAngles();
- turret->GetPhysics()->SetAxis( ang.ToMat3() );
- turret->UpdateVisuals();
- // Check for firing
- if ( mountedPlayer->usercmd.buttons & BUTTON_ATTACK && ( gameLocal.time > weaponLastFireTime + weaponFireDelay ) ) {
- // FIRE!
- idEntity *ent;
- idProjectile *proj;
- idBounds projBounds;
- idVec3 dir;
- gameLocal.SpawnEntityDef( *projectile, &ent );
- if ( !ent || !ent->IsType( idProjectile::Type ) ) {
- const char *projectileName = spawnArgs.GetString( "def_projectile" );
- gameLocal.Error( "'%s' is not an idProjectile", projectileName );
- }
- mountedPlayer->GetViewPos( muzzleOrigin, muzzleAxis );
- muzzleOrigin += ( muzzleAxis[0] * 128 );
- muzzleOrigin -= ( muzzleAxis[2] * 20 );
- dir = muzzleAxis[0];
- proj = static_cast<idProjectile *>(ent);
- proj->Create( this, muzzleOrigin, dir );
- projBounds = proj->GetPhysics()->GetBounds().Rotate( proj->GetPhysics()->GetAxis() );
- proj->Launch( muzzleOrigin, dir, vec3_origin );
- StartSoundShader( soundFireWeapon, SND_CHANNEL_WEAPON, SSF_GLOBAL, false, NULL );
- weaponLastFireTime = gameLocal.time;
- }
- }
- idFuncMountedObject::Think();
- }
- void idFuncMountedWeapon::Event_PostSpawn( void ) {
- if ( targets.Num() >= 1 ) {
- for ( int i=0; i < targets.Num(); i++ ) {
- if ( targets[i].GetEntity()->IsType( idStaticEntity::Type ) ) {
- turret = targets[i].GetEntity();
- break;
- }
- }
- } else {
- gameLocal.Warning( "idFuncMountedWeapon::Spawn: Please target one model for a turret\n" );
- }
- }
- /*
- ===============================================================================
- idPortalSky
- ===============================================================================
- */
- CLASS_DECLARATION( idEntity, idPortalSky )
- EVENT( EV_PostSpawn, idPortalSky::Event_PostSpawn )
- EVENT( EV_Activate, idPortalSky::Event_Activate )
- END_CLASS
- /*
- ===============
- idPortalSky::idPortalSky
- ===============
- */
- idPortalSky::idPortalSky( void ) {
- }
- /*
- ===============
- idPortalSky::~idPortalSky
- ===============
- */
- idPortalSky::~idPortalSky( void ) {
- }
- /*
- ===============
- idPortalSky::Spawn
- ===============
- */
- void idPortalSky::Spawn( void ) {
- if ( !spawnArgs.GetBool( "triggered" ) ) {
- PostEventMS( &EV_PostSpawn, 1 );
- }
- }
- /*
- ================
- idPortalSky::Event_PostSpawn
- ================
- */
- void idPortalSky::Event_PostSpawn() {
- gameLocal.SetPortalSkyEnt( this );
- }
- /*
- ================
- idPortalSky::Event_Activate
- ================
- */
- void idPortalSky::Event_Activate( idEntity *activator ) {
- gameLocal.SetPortalSkyEnt( this );
- }
- #endif /* _D3XP */
|