Target.cpp 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766
  1. /*
  2. ===========================================================================
  3. Doom 3 GPL Source Code
  4. Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
  5. This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
  6. Doom 3 Source Code is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation, either version 3 of the License, or
  9. (at your option) any later version.
  10. Doom 3 Source Code is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
  16. 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.
  17. 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.
  18. ===========================================================================
  19. */
  20. /*
  21. Invisible entities that affect other entities or the world when activated.
  22. */
  23. #include "../idlib/precompiled.h"
  24. #pragma hdrstop
  25. #include "Game_local.h"
  26. /*
  27. ===============================================================================
  28. idTarget
  29. ===============================================================================
  30. */
  31. CLASS_DECLARATION( idEntity, idTarget )
  32. END_CLASS
  33. /*
  34. ===============================================================================
  35. idTarget_Remove
  36. ===============================================================================
  37. */
  38. CLASS_DECLARATION( idTarget, idTarget_Remove )
  39. EVENT( EV_Activate, idTarget_Remove::Event_Activate )
  40. END_CLASS
  41. /*
  42. ================
  43. idTarget_Remove::Event_Activate
  44. ================
  45. */
  46. void idTarget_Remove::Event_Activate( idEntity *activator ) {
  47. int i;
  48. idEntity *ent;
  49. for( i = 0; i < targets.Num(); i++ ) {
  50. ent = targets[ i ].GetEntity();
  51. if ( ent ) {
  52. ent->PostEventMS( &EV_Remove, 0 );
  53. }
  54. }
  55. // delete our self when done
  56. PostEventMS( &EV_Remove, 0 );
  57. }
  58. /*
  59. ===============================================================================
  60. idTarget_Show
  61. ===============================================================================
  62. */
  63. CLASS_DECLARATION( idTarget, idTarget_Show )
  64. EVENT( EV_Activate, idTarget_Show::Event_Activate )
  65. END_CLASS
  66. /*
  67. ================
  68. idTarget_Show::Event_Activate
  69. ================
  70. */
  71. void idTarget_Show::Event_Activate( idEntity *activator ) {
  72. int i;
  73. idEntity *ent;
  74. for( i = 0; i < targets.Num(); i++ ) {
  75. ent = targets[ i ].GetEntity();
  76. if ( ent ) {
  77. ent->Show();
  78. }
  79. }
  80. // delete our self when done
  81. PostEventMS( &EV_Remove, 0 );
  82. }
  83. /*
  84. ===============================================================================
  85. idTarget_Damage
  86. ===============================================================================
  87. */
  88. CLASS_DECLARATION( idTarget, idTarget_Damage )
  89. EVENT( EV_Activate, idTarget_Damage::Event_Activate )
  90. END_CLASS
  91. /*
  92. ================
  93. idTarget_Damage::Event_Activate
  94. ================
  95. */
  96. void idTarget_Damage::Event_Activate( idEntity *activator ) {
  97. int i;
  98. const char *damage;
  99. idEntity * ent;
  100. damage = spawnArgs.GetString( "def_damage", "damage_generic" );
  101. for( i = 0; i < targets.Num(); i++ ) {
  102. ent = targets[ i ].GetEntity();
  103. if ( ent ) {
  104. ent->Damage( this, this, vec3_origin, damage, 1.0f, INVALID_JOINT );
  105. }
  106. }
  107. }
  108. /*
  109. ===============================================================================
  110. idTarget_SessionCommand
  111. ===============================================================================
  112. */
  113. CLASS_DECLARATION( idTarget, idTarget_SessionCommand )
  114. EVENT( EV_Activate, idTarget_SessionCommand::Event_Activate )
  115. END_CLASS
  116. /*
  117. ================
  118. idTarget_SessionCommand::Event_Activate
  119. ================
  120. */
  121. void idTarget_SessionCommand::Event_Activate( idEntity *activator ) {
  122. gameLocal.sessionCommand = spawnArgs.GetString( "command" );
  123. }
  124. /*
  125. ===============================================================================
  126. idTarget_EndLevel
  127. Just a modified form of idTarget_SessionCommand
  128. ===============================================================================
  129. */
  130. CLASS_DECLARATION( idTarget, idTarget_EndLevel )
  131. EVENT( EV_Activate, idTarget_EndLevel::Event_Activate )
  132. END_CLASS
  133. /*
  134. ================
  135. idTarget_EndLevel::Event_Activate
  136. ================
  137. */
  138. void idTarget_EndLevel::Event_Activate( idEntity *activator ) {
  139. idStr nextMap;
  140. #ifdef ID_DEMO_BUILD
  141. if ( spawnArgs.GetBool( "endOfGame" ) ) {
  142. cvarSystem->SetCVarBool( "g_nightmare", true );
  143. gameLocal.sessionCommand = "endofDemo";
  144. return;
  145. }
  146. #else
  147. if ( spawnArgs.GetBool( "endOfGame" ) ) {
  148. cvarSystem->SetCVarBool( "g_nightmare", true );
  149. gameLocal.sessionCommand = "disconnect";
  150. return;
  151. }
  152. #endif
  153. if ( !spawnArgs.GetString( "nextMap", "", nextMap ) ) {
  154. gameLocal.Printf( "idTarget_SessionCommand::Event_Activate: no nextMap key\n" );
  155. return;
  156. }
  157. if ( spawnArgs.GetInt( "devmap", "0" ) ) {
  158. gameLocal.sessionCommand = "devmap "; // only for special demos
  159. } else {
  160. gameLocal.sessionCommand = "map ";
  161. }
  162. gameLocal.sessionCommand += nextMap;
  163. }
  164. /*
  165. ===============================================================================
  166. idTarget_WaitForButton
  167. ===============================================================================
  168. */
  169. CLASS_DECLARATION( idTarget, idTarget_WaitForButton )
  170. EVENT( EV_Activate, idTarget_WaitForButton::Event_Activate )
  171. END_CLASS
  172. /*
  173. ================
  174. idTarget_WaitForButton::Event_Activate
  175. ================
  176. */
  177. void idTarget_WaitForButton::Event_Activate( idEntity *activator ) {
  178. if ( thinkFlags & TH_THINK ) {
  179. BecomeInactive( TH_THINK );
  180. } else {
  181. // always allow during cinematics
  182. cinematic = true;
  183. BecomeActive( TH_THINK );
  184. }
  185. }
  186. /*
  187. ================
  188. idTarget_WaitForButton::Think
  189. ================
  190. */
  191. void idTarget_WaitForButton::Think( void ) {
  192. idPlayer *player;
  193. if ( thinkFlags & TH_THINK ) {
  194. player = gameLocal.GetLocalPlayer();
  195. if ( player && ( !player->oldButtons & BUTTON_ATTACK ) && ( player->usercmd.buttons & BUTTON_ATTACK ) ) {
  196. player->usercmd.buttons &= ~BUTTON_ATTACK;
  197. BecomeInactive( TH_THINK );
  198. ActivateTargets( player );
  199. }
  200. } else {
  201. BecomeInactive( TH_ALL );
  202. }
  203. }
  204. /*
  205. ===============================================================================
  206. idTarget_SetGlobalShaderParm
  207. ===============================================================================
  208. */
  209. CLASS_DECLARATION( idTarget, idTarget_SetGlobalShaderTime )
  210. EVENT( EV_Activate, idTarget_SetGlobalShaderTime::Event_Activate )
  211. END_CLASS
  212. /*
  213. ================
  214. idTarget_SetGlobalShaderTime::Event_Activate
  215. ================
  216. */
  217. void idTarget_SetGlobalShaderTime::Event_Activate( idEntity *activator ) {
  218. int parm = spawnArgs.GetInt( "globalParm" );
  219. float time = -MS2SEC( gameLocal.time );
  220. if ( parm >= 0 && parm < MAX_GLOBAL_SHADER_PARMS ) {
  221. gameLocal.globalShaderParms[parm] = time;
  222. }
  223. }
  224. /*
  225. ===============================================================================
  226. idTarget_SetShaderParm
  227. ===============================================================================
  228. */
  229. CLASS_DECLARATION( idTarget, idTarget_SetShaderParm )
  230. EVENT( EV_Activate, idTarget_SetShaderParm::Event_Activate )
  231. END_CLASS
  232. /*
  233. ================
  234. idTarget_SetShaderParm::Event_Activate
  235. ================
  236. */
  237. void idTarget_SetShaderParm::Event_Activate( idEntity *activator ) {
  238. int i;
  239. idEntity * ent;
  240. float value;
  241. idVec3 color;
  242. int parmnum;
  243. // set the color on the targets
  244. if ( spawnArgs.GetVector( "_color", "1 1 1", color ) ) {
  245. for( i = 0; i < targets.Num(); i++ ) {
  246. ent = targets[ i ].GetEntity();
  247. if ( ent ) {
  248. ent->SetColor( color[ 0 ], color[ 1 ], color[ 2 ] );
  249. }
  250. }
  251. }
  252. // set any shader parms on the targets
  253. for( parmnum = 0; parmnum < MAX_ENTITY_SHADER_PARMS; parmnum++ ) {
  254. if ( spawnArgs.GetFloat( va( "shaderParm%d", parmnum ), "0", value ) ) {
  255. for( i = 0; i < targets.Num(); i++ ) {
  256. ent = targets[ i ].GetEntity();
  257. if ( ent ) {
  258. ent->SetShaderParm( parmnum, value );
  259. }
  260. }
  261. if (spawnArgs.GetBool("toggle") && (value == 0 || value == 1)) {
  262. int val = value;
  263. val ^= 1;
  264. value = val;
  265. spawnArgs.SetFloat(va("shaderParm%d", parmnum), value);
  266. }
  267. }
  268. }
  269. }
  270. /*
  271. ===============================================================================
  272. idTarget_SetShaderTime
  273. ===============================================================================
  274. */
  275. CLASS_DECLARATION( idTarget, idTarget_SetShaderTime )
  276. EVENT( EV_Activate, idTarget_SetShaderTime::Event_Activate )
  277. END_CLASS
  278. /*
  279. ================
  280. idTarget_SetShaderTime::Event_Activate
  281. ================
  282. */
  283. void idTarget_SetShaderTime::Event_Activate( idEntity *activator ) {
  284. int i;
  285. idEntity * ent;
  286. float time;
  287. time = -MS2SEC( gameLocal.time );
  288. for( i = 0; i < targets.Num(); i++ ) {
  289. ent = targets[ i ].GetEntity();
  290. if ( ent ) {
  291. ent->SetShaderParm( SHADERPARM_TIMEOFFSET, time );
  292. if ( ent->IsType( idLight::Type ) ) {
  293. static_cast<idLight *>(ent)->SetLightParm( SHADERPARM_TIMEOFFSET, time );
  294. }
  295. }
  296. }
  297. }
  298. /*
  299. ===============================================================================
  300. idTarget_FadeEntity
  301. ===============================================================================
  302. */
  303. CLASS_DECLARATION( idTarget, idTarget_FadeEntity )
  304. EVENT( EV_Activate, idTarget_FadeEntity::Event_Activate )
  305. END_CLASS
  306. /*
  307. ================
  308. idTarget_FadeEntity::idTarget_FadeEntity
  309. ================
  310. */
  311. idTarget_FadeEntity::idTarget_FadeEntity( void ) {
  312. fadeFrom.Zero();
  313. fadeStart = 0;
  314. fadeEnd = 0;
  315. }
  316. /*
  317. ================
  318. idTarget_FadeEntity::Save
  319. ================
  320. */
  321. void idTarget_FadeEntity::Save( idSaveGame *savefile ) const {
  322. savefile->WriteVec4( fadeFrom );
  323. savefile->WriteInt( fadeStart );
  324. savefile->WriteInt( fadeEnd );
  325. }
  326. /*
  327. ================
  328. idTarget_FadeEntity::Restore
  329. ================
  330. */
  331. void idTarget_FadeEntity::Restore( idRestoreGame *savefile ) {
  332. savefile->ReadVec4( fadeFrom );
  333. savefile->ReadInt( fadeStart );
  334. savefile->ReadInt( fadeEnd );
  335. }
  336. /*
  337. ================
  338. idTarget_FadeEntity::Event_Activate
  339. ================
  340. */
  341. void idTarget_FadeEntity::Event_Activate( idEntity *activator ) {
  342. idEntity *ent;
  343. int i;
  344. if ( !targets.Num() ) {
  345. return;
  346. }
  347. // always allow during cinematics
  348. cinematic = true;
  349. BecomeActive( TH_THINK );
  350. ent = this;
  351. for( i = 0; i < targets.Num(); i++ ) {
  352. ent = targets[ i ].GetEntity();
  353. if ( ent ) {
  354. ent->GetColor( fadeFrom );
  355. break;
  356. }
  357. }
  358. fadeStart = gameLocal.time;
  359. fadeEnd = gameLocal.time + SEC2MS( spawnArgs.GetFloat( "fadetime" ) );
  360. }
  361. /*
  362. ================
  363. idTarget_FadeEntity::Think
  364. ================
  365. */
  366. void idTarget_FadeEntity::Think( void ) {
  367. int i;
  368. idEntity *ent;
  369. idVec4 color;
  370. idVec4 fadeTo;
  371. float frac;
  372. if ( thinkFlags & TH_THINK ) {
  373. GetColor( fadeTo );
  374. if ( gameLocal.time >= fadeEnd ) {
  375. color = fadeTo;
  376. BecomeInactive( TH_THINK );
  377. } else {
  378. frac = ( float )( gameLocal.time - fadeStart ) / ( float )( fadeEnd - fadeStart );
  379. color.Lerp( fadeFrom, fadeTo, frac );
  380. }
  381. // set the color on the targets
  382. for( i = 0; i < targets.Num(); i++ ) {
  383. ent = targets[ i ].GetEntity();
  384. if ( ent ) {
  385. ent->SetColor( color );
  386. }
  387. }
  388. } else {
  389. BecomeInactive( TH_ALL );
  390. }
  391. }
  392. /*
  393. ===============================================================================
  394. idTarget_LightFadeIn
  395. ===============================================================================
  396. */
  397. CLASS_DECLARATION( idTarget, idTarget_LightFadeIn )
  398. EVENT( EV_Activate, idTarget_LightFadeIn::Event_Activate )
  399. END_CLASS
  400. /*
  401. ================
  402. idTarget_LightFadeIn::Event_Activate
  403. ================
  404. */
  405. void idTarget_LightFadeIn::Event_Activate( idEntity *activator ) {
  406. idEntity *ent;
  407. idLight *light;
  408. int i;
  409. float time;
  410. if ( !targets.Num() ) {
  411. return;
  412. }
  413. time = spawnArgs.GetFloat( "fadetime" );
  414. ent = this;
  415. for( i = 0; i < targets.Num(); i++ ) {
  416. ent = targets[ i ].GetEntity();
  417. if ( !ent ) {
  418. continue;
  419. }
  420. if ( ent->IsType( idLight::Type ) ) {
  421. light = static_cast<idLight *>( ent );
  422. light->FadeIn( time );
  423. } else {
  424. gameLocal.Printf( "'%s' targets non-light '%s'", name.c_str(), ent->GetName() );
  425. }
  426. }
  427. }
  428. /*
  429. ===============================================================================
  430. idTarget_LightFadeOut
  431. ===============================================================================
  432. */
  433. CLASS_DECLARATION( idTarget, idTarget_LightFadeOut )
  434. EVENT( EV_Activate, idTarget_LightFadeOut::Event_Activate )
  435. END_CLASS
  436. /*
  437. ================
  438. idTarget_LightFadeOut::Event_Activate
  439. ================
  440. */
  441. void idTarget_LightFadeOut::Event_Activate( idEntity *activator ) {
  442. idEntity *ent;
  443. idLight *light;
  444. int i;
  445. float time;
  446. if ( !targets.Num() ) {
  447. return;
  448. }
  449. time = spawnArgs.GetFloat( "fadetime" );
  450. ent = this;
  451. for( i = 0; i < targets.Num(); i++ ) {
  452. ent = targets[ i ].GetEntity();
  453. if ( !ent ) {
  454. continue;
  455. }
  456. if ( ent->IsType( idLight::Type ) ) {
  457. light = static_cast<idLight *>( ent );
  458. light->FadeOut( time );
  459. } else {
  460. gameLocal.Printf( "'%s' targets non-light '%s'", name.c_str(), ent->GetName() );
  461. }
  462. }
  463. }
  464. /*
  465. ===============================================================================
  466. idTarget_Give
  467. ===============================================================================
  468. */
  469. CLASS_DECLARATION( idTarget, idTarget_Give )
  470. EVENT( EV_Activate, idTarget_Give::Event_Activate )
  471. END_CLASS
  472. /*
  473. ================
  474. idTarget_Give::Spawn
  475. ================
  476. */
  477. void idTarget_Give::Spawn( void ) {
  478. if ( spawnArgs.GetBool( "onSpawn" ) ) {
  479. PostEventMS( &EV_Activate, 50 );
  480. }
  481. }
  482. /*
  483. ================
  484. idTarget_Give::Event_Activate
  485. ================
  486. */
  487. void idTarget_Give::Event_Activate( idEntity *activator ) {
  488. if ( spawnArgs.GetBool( "development" ) && developer.GetInteger() == 0 ) {
  489. return;
  490. }
  491. static int giveNum = 0;
  492. idPlayer *player = gameLocal.GetLocalPlayer();
  493. if ( player ) {
  494. const idKeyValue *kv = spawnArgs.MatchPrefix( "item", NULL );
  495. while ( kv ) {
  496. const idDict *dict = gameLocal.FindEntityDefDict( kv->GetValue(), false );
  497. if ( dict ) {
  498. idDict d2;
  499. d2.Copy( *dict );
  500. d2.Set( "name", va( "givenitem_%i", giveNum++ ) );
  501. idEntity *ent = NULL;
  502. if ( gameLocal.SpawnEntityDef( d2, &ent ) && ent && ent->IsType( idItem::Type ) ) {
  503. idItem *item = static_cast<idItem*>(ent);
  504. item->GiveToPlayer( gameLocal.GetLocalPlayer() );
  505. }
  506. }
  507. kv = spawnArgs.MatchPrefix( "item", kv );
  508. }
  509. }
  510. }
  511. /*
  512. ===============================================================================
  513. idTarget_GiveEmail
  514. ===============================================================================
  515. */
  516. CLASS_DECLARATION( idTarget, idTarget_GiveEmail )
  517. EVENT( EV_Activate, idTarget_GiveEmail::Event_Activate )
  518. END_CLASS
  519. /*
  520. ================
  521. idTarget_GiveEmail::Spawn
  522. ================
  523. */
  524. void idTarget_GiveEmail::Spawn( void ) {
  525. }
  526. /*
  527. ================
  528. idTarget_GiveEmail::Event_Activate
  529. ================
  530. */
  531. void idTarget_GiveEmail::Event_Activate( idEntity *activator ) {
  532. idPlayer *player = gameLocal.GetLocalPlayer();
  533. const idDeclPDA *pda = player->GetPDA();
  534. if ( pda ) {
  535. player->GiveEmail( spawnArgs.GetString( "email" ) );
  536. } else {
  537. player->ShowTip( spawnArgs.GetString( "text_infoTitle" ), spawnArgs.GetString( "text_PDANeeded" ), true );
  538. }
  539. }
  540. /*
  541. ===============================================================================
  542. idTarget_SetModel
  543. ===============================================================================
  544. */
  545. CLASS_DECLARATION( idTarget, idTarget_SetModel )
  546. EVENT( EV_Activate, idTarget_SetModel::Event_Activate )
  547. END_CLASS
  548. /*
  549. ================
  550. idTarget_SetModel::Spawn
  551. ================
  552. */
  553. void idTarget_SetModel::Spawn( void ) {
  554. const char *model;
  555. model = spawnArgs.GetString( "newmodel" );
  556. if ( declManager->FindType( DECL_MODELDEF, model, false ) == NULL ) {
  557. // precache the render model
  558. renderModelManager->FindModel( model );
  559. // precache .cm files only
  560. collisionModelManager->LoadModel( model, true );
  561. }
  562. }
  563. /*
  564. ================
  565. idTarget_SetModel::Event_Activate
  566. ================
  567. */
  568. void idTarget_SetModel::Event_Activate( idEntity *activator ) {
  569. for( int i = 0; i < targets.Num(); i++ ) {
  570. idEntity *ent = targets[ i ].GetEntity();
  571. if ( ent ) {
  572. ent->SetModel( spawnArgs.GetString( "newmodel" ) );
  573. }
  574. }
  575. }
  576. /*
  577. ===============================================================================
  578. idTarget_SetInfluence
  579. ===============================================================================
  580. */
  581. const idEventDef EV_RestoreInfluence( "<RestoreInfluece>" );
  582. const idEventDef EV_GatherEntities( "<GatherEntities>" );
  583. const idEventDef EV_Flash( "<Flash>", "fd" );
  584. const idEventDef EV_ClearFlash( "<ClearFlash>", "f" );
  585. CLASS_DECLARATION( idTarget, idTarget_SetInfluence )
  586. EVENT( EV_Activate, idTarget_SetInfluence::Event_Activate )
  587. EVENT( EV_RestoreInfluence, idTarget_SetInfluence::Event_RestoreInfluence )
  588. EVENT( EV_GatherEntities, idTarget_SetInfluence::Event_GatherEntities )
  589. EVENT( EV_Flash, idTarget_SetInfluence::Event_Flash )
  590. EVENT( EV_ClearFlash, idTarget_SetInfluence::Event_ClearFlash )
  591. END_CLASS
  592. /*
  593. ================
  594. idTarget_SetInfluence::idTarget_SetInfluence
  595. ================
  596. */
  597. idTarget_SetInfluence::idTarget_SetInfluence( void ) {
  598. flashIn = 0.0f;
  599. flashOut = 0.0f;
  600. delay = 0.0f;
  601. switchToCamera = NULL;
  602. soundFaded = false;
  603. restoreOnTrigger = false;
  604. }
  605. /*
  606. ================
  607. idTarget_SetInfluence::Save
  608. ================
  609. */
  610. void idTarget_SetInfluence::Save( idSaveGame *savefile ) const {
  611. int i;
  612. savefile->WriteInt( lightList.Num() );
  613. for( i = 0; i < lightList.Num(); i++ ) {
  614. savefile->WriteInt( lightList[ i ] );
  615. }
  616. savefile->WriteInt( guiList.Num() );
  617. for( i = 0; i < guiList.Num(); i++ ) {
  618. savefile->WriteInt( guiList[ i ] );
  619. }
  620. savefile->WriteInt( soundList.Num() );
  621. for( i = 0; i < soundList.Num(); i++ ) {
  622. savefile->WriteInt( soundList[ i ] );
  623. }
  624. savefile->WriteInt( genericList.Num() );
  625. for( i = 0; i < genericList.Num(); i++ ) {
  626. savefile->WriteInt( genericList[ i ] );
  627. }
  628. savefile->WriteFloat( flashIn );
  629. savefile->WriteFloat( flashOut );
  630. savefile->WriteFloat( delay );
  631. savefile->WriteString( flashInSound );
  632. savefile->WriteString( flashOutSound );
  633. savefile->WriteObject( switchToCamera );
  634. savefile->WriteFloat( fovSetting.GetStartTime() );
  635. savefile->WriteFloat( fovSetting.GetDuration() );
  636. savefile->WriteFloat( fovSetting.GetStartValue() );
  637. savefile->WriteFloat( fovSetting.GetEndValue() );
  638. savefile->WriteBool( soundFaded );
  639. savefile->WriteBool( restoreOnTrigger );
  640. }
  641. /*
  642. ================
  643. idTarget_SetInfluence::Restore
  644. ================
  645. */
  646. void idTarget_SetInfluence::Restore( idRestoreGame *savefile ) {
  647. int i, num;
  648. int itemNum;
  649. float set;
  650. savefile->ReadInt( num );
  651. for( i = 0; i < num; i++ ) {
  652. savefile->ReadInt( itemNum );
  653. lightList.Append( itemNum );
  654. }
  655. savefile->ReadInt( num );
  656. for( i = 0; i < num; i++ ) {
  657. savefile->ReadInt( itemNum );
  658. guiList.Append( itemNum );
  659. }
  660. savefile->ReadInt( num );
  661. for( i = 0; i < num; i++ ) {
  662. savefile->ReadInt( itemNum );
  663. soundList.Append( itemNum );
  664. }
  665. savefile->ReadInt( num );
  666. for ( i = 0; i < num; i++ ) {
  667. savefile->ReadInt( itemNum );
  668. genericList.Append( itemNum );
  669. }
  670. savefile->ReadFloat( flashIn );
  671. savefile->ReadFloat( flashOut );
  672. savefile->ReadFloat( delay );
  673. savefile->ReadString( flashInSound );
  674. savefile->ReadString( flashOutSound );
  675. savefile->ReadObject( reinterpret_cast<idClass *&>( switchToCamera ) );
  676. savefile->ReadFloat( set );
  677. fovSetting.SetStartTime( set );
  678. savefile->ReadFloat( set );
  679. fovSetting.SetDuration( set );
  680. savefile->ReadFloat( set );
  681. fovSetting.SetStartValue( set );
  682. savefile->ReadFloat( set );
  683. fovSetting.SetEndValue( set );
  684. savefile->ReadBool( soundFaded );
  685. savefile->ReadBool( restoreOnTrigger );
  686. }
  687. /*
  688. ================
  689. idTarget_SetInfluence::Spawn
  690. ================
  691. */
  692. void idTarget_SetInfluence::Spawn() {
  693. PostEventMS( &EV_GatherEntities, 0 );
  694. flashIn = spawnArgs.GetFloat( "flashIn", "0" );
  695. flashOut = spawnArgs.GetFloat( "flashOut", "0" );
  696. flashInSound = spawnArgs.GetString( "snd_flashin" );
  697. flashOutSound = spawnArgs.GetString( "snd_flashout" );
  698. delay = spawnArgs.GetFloat( "delay" );
  699. soundFaded = false;
  700. restoreOnTrigger = false;
  701. // always allow during cinematics
  702. cinematic = true;
  703. }
  704. /*
  705. ================
  706. idTarget_SetInfluence::Event_Flash
  707. ================
  708. */
  709. void idTarget_SetInfluence::Event_Flash( float flash, int out ) {
  710. idPlayer *player = gameLocal.GetLocalPlayer();
  711. player->playerView.Fade( idVec4( 1, 1, 1, 1 ), flash );
  712. const idSoundShader *shader = NULL;
  713. if ( !out && flashInSound.Length() ){
  714. shader = declManager->FindSound( flashInSound );
  715. player->StartSoundShader( shader, SND_CHANNEL_VOICE, 0, false, NULL );
  716. } else if ( out && ( flashOutSound.Length() || flashInSound.Length() ) ) {
  717. shader = declManager->FindSound( flashOutSound.Length() ? flashOutSound : flashInSound );
  718. player->StartSoundShader( shader, SND_CHANNEL_VOICE, 0, false, NULL );
  719. }
  720. PostEventSec( &EV_ClearFlash, flash, flash );
  721. }
  722. /*
  723. ================
  724. idTarget_SetInfluence::Event_ClearFlash
  725. ================
  726. */
  727. void idTarget_SetInfluence::Event_ClearFlash( float flash ) {
  728. idPlayer *player = gameLocal.GetLocalPlayer();
  729. player->playerView.Fade( vec4_zero , flash );
  730. }
  731. /*
  732. ================
  733. idTarget_SetInfluence::Event_GatherEntities
  734. ================
  735. */
  736. void idTarget_SetInfluence::Event_GatherEntities() {
  737. int i, listedEntities;
  738. idEntity *entityList[ MAX_GENTITIES ];
  739. bool demonicOnly = spawnArgs.GetBool( "effect_demonic" );
  740. bool lights = spawnArgs.GetBool( "effect_lights" );
  741. bool sounds = spawnArgs.GetBool( "effect_sounds" );
  742. bool guis = spawnArgs.GetBool( "effect_guis" );
  743. bool models = spawnArgs.GetBool( "effect_models" );
  744. bool vision = spawnArgs.GetBool( "effect_vision" );
  745. bool targetsOnly = spawnArgs.GetBool( "targetsOnly" );
  746. lightList.Clear();
  747. guiList.Clear();
  748. soundList.Clear();
  749. if ( spawnArgs.GetBool( "effect_all" ) ) {
  750. lights = sounds = guis = models = vision = true;
  751. }
  752. if ( targetsOnly ) {
  753. listedEntities = targets.Num();
  754. for ( i = 0; i < listedEntities; i++ ) {
  755. entityList[i] = targets[i].GetEntity();
  756. }
  757. } else {
  758. float radius = spawnArgs.GetFloat( "radius" );
  759. listedEntities = gameLocal.EntitiesWithinRadius( GetPhysics()->GetOrigin(), radius, entityList, MAX_GENTITIES );
  760. }
  761. for( i = 0; i < listedEntities; i++ ) {
  762. idEntity *ent = entityList[ i ];
  763. if ( ent ) {
  764. if ( lights && ent->IsType( idLight::Type ) && ent->spawnArgs.FindKey( "color_demonic" ) ) {
  765. lightList.Append( ent->entityNumber );
  766. continue;
  767. }
  768. if ( sounds && ent->IsType( idSound::Type ) && ent->spawnArgs.FindKey( "snd_demonic" ) ) {
  769. soundList.Append( ent->entityNumber );
  770. continue;
  771. }
  772. if ( guis && ent->GetRenderEntity() && ent->GetRenderEntity()->gui[ 0 ] && ent->spawnArgs.FindKey( "gui_demonic" ) ) {
  773. guiList.Append( ent->entityNumber );
  774. continue;
  775. }
  776. if ( ent->IsType( idStaticEntity::Type ) && ent->spawnArgs.FindKey( "color_demonic" ) ) {
  777. genericList.Append( ent->entityNumber );
  778. continue;
  779. }
  780. }
  781. }
  782. idStr temp;
  783. temp = spawnArgs.GetString( "switchToView" );
  784. switchToCamera = ( temp.Length() ) ? gameLocal.FindEntity( temp ) : NULL;
  785. }
  786. /*
  787. ================
  788. idTarget_SetInfluence::Event_Activate
  789. ================
  790. */
  791. void idTarget_SetInfluence::Event_Activate( idEntity *activator ) {
  792. int i, j;
  793. idEntity *ent;
  794. idLight *light;
  795. idSound *sound;
  796. idStaticEntity *generic;
  797. const char *parm;
  798. const char *skin;
  799. bool update;
  800. idVec3 color;
  801. idVec4 colorTo;
  802. idPlayer *player;
  803. player = gameLocal.GetLocalPlayer();
  804. if ( spawnArgs.GetBool( "triggerActivate" ) ) {
  805. if ( restoreOnTrigger ) {
  806. ProcessEvent( &EV_RestoreInfluence );
  807. restoreOnTrigger = false;
  808. return;
  809. }
  810. restoreOnTrigger = true;
  811. }
  812. float fadeTime = spawnArgs.GetFloat( "fadeWorldSounds" );
  813. if ( delay > 0.0f ) {
  814. PostEventSec( &EV_Activate, delay, activator );
  815. delay = 0.0f;
  816. // start any sound fading now
  817. if ( fadeTime ) {
  818. gameSoundWorld->FadeSoundClasses( 0, -40.0f, fadeTime );
  819. soundFaded = true;
  820. }
  821. return;
  822. } else if ( fadeTime && !soundFaded ) {
  823. gameSoundWorld->FadeSoundClasses( 0, -40.0f, fadeTime );
  824. soundFaded = true;
  825. }
  826. if ( spawnArgs.GetBool( "triggerTargets" ) ) {
  827. ActivateTargets( activator );
  828. }
  829. if ( flashIn ) {
  830. PostEventSec( &EV_Flash, 0.0f, flashIn, 0 );
  831. }
  832. parm = spawnArgs.GetString( "snd_influence" );
  833. if ( parm && *parm ) {
  834. PostEventSec( &EV_StartSoundShader, flashIn, parm, SND_CHANNEL_ANY );
  835. }
  836. if ( switchToCamera ) {
  837. switchToCamera->PostEventSec( &EV_Activate, flashIn + 0.05f, this );
  838. }
  839. int fov = spawnArgs.GetInt( "fov" );
  840. if ( fov ) {
  841. fovSetting.Init( gameLocal.time, SEC2MS( spawnArgs.GetFloat( "fovTime" ) ), player->DefaultFov(), fov );
  842. BecomeActive( TH_THINK );
  843. }
  844. for ( i = 0; i < genericList.Num(); i++ ) {
  845. ent = gameLocal.entities[genericList[i]];
  846. if ( ent == NULL ) {
  847. continue;
  848. }
  849. generic = static_cast<idStaticEntity*>( ent );
  850. color = generic->spawnArgs.GetVector( "color_demonic" );
  851. colorTo.Set( color.x, color.y, color.z, 1.0f );
  852. generic->Fade( colorTo, spawnArgs.GetFloat( "fade_time", "0.25" ) );
  853. }
  854. for ( i = 0; i < lightList.Num(); i++ ) {
  855. ent = gameLocal.entities[lightList[i]];
  856. if ( ent == NULL || !ent->IsType( idLight::Type ) ) {
  857. continue;
  858. }
  859. light = static_cast<idLight *>(ent);
  860. parm = light->spawnArgs.GetString( "mat_demonic" );
  861. if ( parm && *parm ) {
  862. light->SetShader( parm );
  863. }
  864. color = light->spawnArgs.GetVector( "_color" );
  865. color = light->spawnArgs.GetVector( "color_demonic", color.ToString() );
  866. colorTo.Set( color.x, color.y, color.z, 1.0f );
  867. light->Fade( colorTo, spawnArgs.GetFloat( "fade_time", "0.25" ) );
  868. }
  869. for ( i = 0; i < soundList.Num(); i++ ) {
  870. ent = gameLocal.entities[soundList[i]];
  871. if ( ent == NULL || !ent->IsType( idSound::Type ) ) {
  872. continue;
  873. }
  874. sound = static_cast<idSound *>(ent);
  875. parm = sound->spawnArgs.GetString( "snd_demonic" );
  876. if ( parm && *parm ) {
  877. if ( sound->spawnArgs.GetBool( "overlayDemonic" ) ) {
  878. sound->StartSound( "snd_demonic", SND_CHANNEL_DEMONIC, 0, false, NULL );
  879. } else {
  880. sound->StopSound( SND_CHANNEL_ANY, false );
  881. sound->SetSound( parm );
  882. }
  883. }
  884. }
  885. for ( i = 0; i < guiList.Num(); i++ ) {
  886. ent = gameLocal.entities[guiList[i]];
  887. if ( ent == NULL || ent->GetRenderEntity() == NULL ) {
  888. continue;
  889. }
  890. update = false;
  891. for ( j = 0; j < MAX_RENDERENTITY_GUI; j++ ) {
  892. if ( ent->GetRenderEntity()->gui[ j ] && ent->spawnArgs.FindKey( j == 0 ? "gui_demonic" : va( "gui_demonic%d", j+1 ) ) ) {
  893. ent->GetRenderEntity()->gui[ j ] = uiManager->FindGui( ent->spawnArgs.GetString( j == 0 ? "gui_demonic" : va( "gui_demonic%d", j+1 ) ), true );
  894. update = true;
  895. }
  896. }
  897. if ( update ) {
  898. ent->UpdateVisuals();
  899. ent->Present();
  900. }
  901. }
  902. player->SetInfluenceLevel( spawnArgs.GetInt( "influenceLevel" ) );
  903. int snapAngle = spawnArgs.GetInt( "snapAngle" );
  904. if ( snapAngle ) {
  905. idAngles ang( 0, snapAngle, 0 );
  906. player->SetViewAngles( ang );
  907. player->SetAngles( ang );
  908. }
  909. if ( spawnArgs.GetBool( "effect_vision" ) ) {
  910. parm = spawnArgs.GetString( "mtrVision" );
  911. skin = spawnArgs.GetString( "skinVision" );
  912. player->SetInfluenceView( parm, skin, spawnArgs.GetInt( "visionRadius" ), this );
  913. }
  914. parm = spawnArgs.GetString( "mtrWorld" );
  915. if ( parm && *parm ) {
  916. gameLocal.SetGlobalMaterial( declManager->FindMaterial( parm ) );
  917. }
  918. if ( !restoreOnTrigger ) {
  919. PostEventMS( &EV_RestoreInfluence, SEC2MS( spawnArgs.GetFloat( "time" ) ) );
  920. }
  921. }
  922. /*
  923. ================
  924. idTarget_SetInfluence::Think
  925. ================
  926. */
  927. void idTarget_SetInfluence::Think( void ) {
  928. if ( thinkFlags & TH_THINK ) {
  929. idPlayer *player = gameLocal.GetLocalPlayer();
  930. player->SetInfluenceFov( fovSetting.GetCurrentValue( gameLocal.time ) );
  931. if ( fovSetting.IsDone( gameLocal.time ) ) {
  932. if ( !spawnArgs.GetBool( "leaveFOV" ) ) {
  933. player->SetInfluenceFov( 0 );
  934. }
  935. BecomeInactive( TH_THINK );
  936. }
  937. } else {
  938. BecomeInactive( TH_ALL );
  939. }
  940. }
  941. /*
  942. ================
  943. idTarget_SetInfluence::Event_RestoreInfluence
  944. ================
  945. */
  946. void idTarget_SetInfluence::Event_RestoreInfluence() {
  947. int i, j;
  948. idEntity *ent;
  949. idLight *light;
  950. idSound *sound;
  951. idStaticEntity *generic;
  952. bool update;
  953. idVec3 color;
  954. idVec4 colorTo;
  955. if ( flashOut ) {
  956. PostEventSec( &EV_Flash, 0.0f, flashOut, 1 );
  957. }
  958. if ( switchToCamera ) {
  959. switchToCamera->PostEventMS( &EV_Activate, 0.0f, this );
  960. }
  961. for ( i = 0; i < genericList.Num(); i++ ) {
  962. ent = gameLocal.entities[genericList[i]];
  963. if ( ent == NULL ) {
  964. continue;
  965. }
  966. generic = static_cast<idStaticEntity*>( ent );
  967. colorTo.Set( 1.0f, 1.0f, 1.0f, 1.0f );
  968. generic->Fade( colorTo, spawnArgs.GetFloat( "fade_time", "0.25" ) );
  969. }
  970. for ( i = 0; i < lightList.Num(); i++ ) {
  971. ent = gameLocal.entities[lightList[i]];
  972. if ( ent == NULL || !ent->IsType( idLight::Type ) ) {
  973. continue;
  974. }
  975. light = static_cast<idLight *>(ent);
  976. if ( !light->spawnArgs.GetBool( "leave_demonic_mat" ) ) {
  977. const char *texture = light->spawnArgs.GetString( "texture", "lights/squarelight1" );
  978. light->SetShader( texture );
  979. }
  980. color = light->spawnArgs.GetVector( "_color" );
  981. colorTo.Set( color.x, color.y, color.z, 1.0f );
  982. light->Fade( colorTo, spawnArgs.GetFloat( "fade_time", "0.25" ) );
  983. }
  984. for ( i = 0; i < soundList.Num(); i++ ) {
  985. ent = gameLocal.entities[soundList[i]];
  986. if ( ent == NULL || !ent->IsType( idSound::Type ) ) {
  987. continue;
  988. }
  989. sound = static_cast<idSound *>(ent);
  990. sound->StopSound( SND_CHANNEL_ANY, false );
  991. sound->SetSound( sound->spawnArgs.GetString( "s_shader" ) );
  992. }
  993. for ( i = 0; i < guiList.Num(); i++ ) {
  994. ent = gameLocal.entities[guiList[i]];
  995. if ( ent == NULL || GetRenderEntity() == NULL ) {
  996. continue;
  997. }
  998. update = false;
  999. for( j = 0; j < MAX_RENDERENTITY_GUI; j++ ) {
  1000. if ( ent->GetRenderEntity()->gui[ j ] ) {
  1001. ent->GetRenderEntity()->gui[ j ] = uiManager->FindGui( ent->spawnArgs.GetString( j == 0 ? "gui" : va( "gui%d", j+1 ) ) );
  1002. update = true;
  1003. }
  1004. }
  1005. if ( update ) {
  1006. ent->UpdateVisuals();
  1007. ent->Present();
  1008. }
  1009. }
  1010. idPlayer *player = gameLocal.GetLocalPlayer();
  1011. player->SetInfluenceLevel( 0 );
  1012. player->SetInfluenceView( NULL, NULL, 0.0f, NULL );
  1013. player->SetInfluenceFov( 0 );
  1014. gameLocal.SetGlobalMaterial( NULL );
  1015. float fadeTime = spawnArgs.GetFloat( "fadeWorldSounds" );
  1016. if ( fadeTime ) {
  1017. gameSoundWorld->FadeSoundClasses( 0, 0.0f, fadeTime / 2.0f );
  1018. }
  1019. }
  1020. /*
  1021. ===============================================================================
  1022. idTarget_SetKeyVal
  1023. ===============================================================================
  1024. */
  1025. CLASS_DECLARATION( idTarget, idTarget_SetKeyVal )
  1026. EVENT( EV_Activate, idTarget_SetKeyVal::Event_Activate )
  1027. END_CLASS
  1028. /*
  1029. ================
  1030. idTarget_SetKeyVal::Event_Activate
  1031. ================
  1032. */
  1033. void idTarget_SetKeyVal::Event_Activate( idEntity *activator ) {
  1034. int i;
  1035. idStr key, val;
  1036. idEntity *ent;
  1037. const idKeyValue *kv;
  1038. int n;
  1039. for( i = 0; i < targets.Num(); i++ ) {
  1040. ent = targets[ i ].GetEntity();
  1041. if ( ent ) {
  1042. kv = spawnArgs.MatchPrefix("keyval");
  1043. while ( kv ) {
  1044. n = kv->GetValue().Find( ";" );
  1045. if ( n > 0 ) {
  1046. key = kv->GetValue().Left( n );
  1047. val = kv->GetValue().Right( kv->GetValue().Length() - n - 1 );
  1048. ent->spawnArgs.Set( key, val );
  1049. for ( int j = 0; j < MAX_RENDERENTITY_GUI; j++ ) {
  1050. if ( ent->GetRenderEntity()->gui[ j ] ) {
  1051. if ( idStr::Icmpn( key, "gui_", 4 ) == 0 ) {
  1052. ent->GetRenderEntity()->gui[ j ]->SetStateString( key, val );
  1053. ent->GetRenderEntity()->gui[ j ]->StateChanged( gameLocal.time );
  1054. }
  1055. }
  1056. }
  1057. }
  1058. kv = spawnArgs.MatchPrefix( "keyval", kv );
  1059. }
  1060. ent->UpdateChangeableSpawnArgs( NULL );
  1061. ent->UpdateVisuals();
  1062. ent->Present();
  1063. }
  1064. }
  1065. }
  1066. /*
  1067. ===============================================================================
  1068. idTarget_SetFov
  1069. ===============================================================================
  1070. */
  1071. CLASS_DECLARATION( idTarget, idTarget_SetFov )
  1072. EVENT( EV_Activate, idTarget_SetFov::Event_Activate )
  1073. END_CLASS
  1074. /*
  1075. ================
  1076. idTarget_SetFov::Save
  1077. ================
  1078. */
  1079. void idTarget_SetFov::Save( idSaveGame *savefile ) const {
  1080. savefile->WriteFloat( fovSetting.GetStartTime() );
  1081. savefile->WriteFloat( fovSetting.GetDuration() );
  1082. savefile->WriteFloat( fovSetting.GetStartValue() );
  1083. savefile->WriteFloat( fovSetting.GetEndValue() );
  1084. }
  1085. /*
  1086. ================
  1087. idTarget_SetFov::Restore
  1088. ================
  1089. */
  1090. void idTarget_SetFov::Restore( idRestoreGame *savefile ) {
  1091. float setting;
  1092. savefile->ReadFloat( setting );
  1093. fovSetting.SetStartTime( setting );
  1094. savefile->ReadFloat( setting );
  1095. fovSetting.SetDuration( setting );
  1096. savefile->ReadFloat( setting );
  1097. fovSetting.SetStartValue( setting );
  1098. savefile->ReadFloat( setting );
  1099. fovSetting.SetEndValue( setting );
  1100. fovSetting.GetCurrentValue( gameLocal.time );
  1101. }
  1102. /*
  1103. ================
  1104. idTarget_SetFov::Event_Activate
  1105. ================
  1106. */
  1107. void idTarget_SetFov::Event_Activate( idEntity *activator ) {
  1108. // always allow during cinematics
  1109. cinematic = true;
  1110. idPlayer *player = gameLocal.GetLocalPlayer();
  1111. fovSetting.Init( gameLocal.time, SEC2MS( spawnArgs.GetFloat( "time" ) ), player ? player->DefaultFov() : g_fov.GetFloat(), spawnArgs.GetFloat( "fov" ) );
  1112. BecomeActive( TH_THINK );
  1113. }
  1114. /*
  1115. ================
  1116. idTarget_SetFov::Think
  1117. ================
  1118. */
  1119. void idTarget_SetFov::Think( void ) {
  1120. if ( thinkFlags & TH_THINK ) {
  1121. idPlayer *player = gameLocal.GetLocalPlayer();
  1122. player->SetInfluenceFov( fovSetting.GetCurrentValue( gameLocal.time ) );
  1123. if ( fovSetting.IsDone( gameLocal.time ) ) {
  1124. player->SetInfluenceFov( 0.0f );
  1125. BecomeInactive( TH_THINK );
  1126. }
  1127. } else {
  1128. BecomeInactive( TH_ALL );
  1129. }
  1130. }
  1131. /*
  1132. ===============================================================================
  1133. idTarget_SetPrimaryObjective
  1134. ===============================================================================
  1135. */
  1136. CLASS_DECLARATION( idTarget, idTarget_SetPrimaryObjective )
  1137. EVENT( EV_Activate, idTarget_SetPrimaryObjective::Event_Activate )
  1138. END_CLASS
  1139. /*
  1140. ================
  1141. idTarget_SetPrimaryObjective::Event_Activate
  1142. ================
  1143. */
  1144. void idTarget_SetPrimaryObjective::Event_Activate( idEntity *activator ) {
  1145. idPlayer *player = gameLocal.GetLocalPlayer();
  1146. if ( player && player->objectiveSystem ) {
  1147. player->objectiveSystem->SetStateString( "missionobjective", spawnArgs.GetString( "text", common->GetLanguageDict()->GetString( "#str_04253" ) ) );
  1148. }
  1149. }
  1150. /*
  1151. ===============================================================================
  1152. idTarget_LockDoor
  1153. ===============================================================================
  1154. */
  1155. CLASS_DECLARATION( idTarget, idTarget_LockDoor )
  1156. EVENT( EV_Activate, idTarget_LockDoor::Event_Activate )
  1157. END_CLASS
  1158. /*
  1159. ================
  1160. idTarget_LockDoor::Event_Activate
  1161. ================
  1162. */
  1163. void idTarget_LockDoor::Event_Activate( idEntity *activator ) {
  1164. int i;
  1165. idEntity *ent;
  1166. int lock;
  1167. lock = spawnArgs.GetInt( "locked", "1" );
  1168. for( i = 0; i < targets.Num(); i++ ) {
  1169. ent = targets[ i ].GetEntity();
  1170. if ( ent && ent->IsType( idDoor::Type ) ) {
  1171. if ( static_cast<idDoor *>( ent )->IsLocked() ) {
  1172. static_cast<idDoor *>( ent )->Lock( 0 );
  1173. } else {
  1174. static_cast<idDoor *>( ent )->Lock( lock );
  1175. }
  1176. }
  1177. }
  1178. }
  1179. /*
  1180. ===============================================================================
  1181. idTarget_CallObjectFunction
  1182. ===============================================================================
  1183. */
  1184. CLASS_DECLARATION( idTarget, idTarget_CallObjectFunction )
  1185. EVENT( EV_Activate, idTarget_CallObjectFunction::Event_Activate )
  1186. END_CLASS
  1187. /*
  1188. ================
  1189. idTarget_CallObjectFunction::Event_Activate
  1190. ================
  1191. */
  1192. void idTarget_CallObjectFunction::Event_Activate( idEntity *activator ) {
  1193. int i;
  1194. idEntity *ent;
  1195. const function_t *func;
  1196. const char *funcName;
  1197. idThread *thread;
  1198. funcName = spawnArgs.GetString( "call" );
  1199. for( i = 0; i < targets.Num(); i++ ) {
  1200. ent = targets[ i ].GetEntity();
  1201. if ( ent && ent->scriptObject.HasObject() ) {
  1202. func = ent->scriptObject.GetFunction( funcName );
  1203. if ( !func ) {
  1204. gameLocal.Error( "Function '%s' not found on entity '%s' for function call from '%s'", funcName, ent->name.c_str(), name.c_str() );
  1205. }
  1206. if ( func->type->NumParameters() != 1 ) {
  1207. gameLocal.Error( "Function '%s' on entity '%s' has the wrong number of parameters for function call from '%s'", funcName, ent->name.c_str(), name.c_str() );
  1208. }
  1209. if ( !ent->scriptObject.GetTypeDef()->Inherits( func->type->GetParmType( 0 ) ) ) {
  1210. gameLocal.Error( "Function '%s' on entity '%s' is the wrong type for function call from '%s'", funcName, ent->name.c_str(), name.c_str() );
  1211. }
  1212. // create a thread and call the function
  1213. thread = new idThread();
  1214. thread->CallFunction( ent, func, true );
  1215. thread->Start();
  1216. }
  1217. }
  1218. }
  1219. /*
  1220. ===============================================================================
  1221. idTarget_EnableLevelWeapons
  1222. ===============================================================================
  1223. */
  1224. CLASS_DECLARATION( idTarget, idTarget_EnableLevelWeapons )
  1225. EVENT( EV_Activate, idTarget_EnableLevelWeapons::Event_Activate )
  1226. END_CLASS
  1227. /*
  1228. ================
  1229. idTarget_EnableLevelWeapons::Event_Activate
  1230. ================
  1231. */
  1232. void idTarget_EnableLevelWeapons::Event_Activate( idEntity *activator ) {
  1233. int i;
  1234. const char *weap;
  1235. gameLocal.world->spawnArgs.SetBool( "no_Weapons", spawnArgs.GetBool( "disable" ) );
  1236. if ( spawnArgs.GetBool( "disable" ) ) {
  1237. for( i = 0; i < gameLocal.numClients; i++ ) {
  1238. if ( gameLocal.entities[ i ] ) {
  1239. gameLocal.entities[ i ]->ProcessEvent( &EV_Player_DisableWeapon );
  1240. }
  1241. }
  1242. } else {
  1243. weap = spawnArgs.GetString( "weapon" );
  1244. for( i = 0; i < gameLocal.numClients; i++ ) {
  1245. if ( gameLocal.entities[ i ] ) {
  1246. gameLocal.entities[ i ]->ProcessEvent( &EV_Player_EnableWeapon );
  1247. if ( weap && weap[ 0 ] ) {
  1248. gameLocal.entities[ i ]->PostEventSec( &EV_Player_SelectWeapon, 0.5f, weap );
  1249. }
  1250. }
  1251. }
  1252. }
  1253. }
  1254. /*
  1255. ===============================================================================
  1256. idTarget_Tip
  1257. ===============================================================================
  1258. */
  1259. const idEventDef EV_TipOff( "<TipOff>" );
  1260. extern const idEventDef EV_GetPlayerPos( "<getplayerpos>" );
  1261. CLASS_DECLARATION( idTarget, idTarget_Tip )
  1262. EVENT( EV_Activate, idTarget_Tip::Event_Activate )
  1263. EVENT( EV_TipOff, idTarget_Tip::Event_TipOff )
  1264. EVENT( EV_GetPlayerPos, idTarget_Tip::Event_GetPlayerPos )
  1265. END_CLASS
  1266. /*
  1267. ================
  1268. idTarget_Tip::idTarget_Tip
  1269. ================
  1270. */
  1271. idTarget_Tip::idTarget_Tip( void ) {
  1272. playerPos.Zero();
  1273. }
  1274. /*
  1275. ================
  1276. idTarget_Tip::Spawn
  1277. ================
  1278. */
  1279. void idTarget_Tip::Spawn( void ) {
  1280. }
  1281. /*
  1282. ================
  1283. idTarget_Tip::Save
  1284. ================
  1285. */
  1286. void idTarget_Tip::Save( idSaveGame *savefile ) const {
  1287. savefile->WriteVec3( playerPos );
  1288. }
  1289. /*
  1290. ================
  1291. idTarget_Tip::Restore
  1292. ================
  1293. */
  1294. void idTarget_Tip::Restore( idRestoreGame *savefile ) {
  1295. savefile->ReadVec3( playerPos );
  1296. }
  1297. /*
  1298. ================
  1299. idTarget_Tip::Event_Activate
  1300. ================
  1301. */
  1302. void idTarget_Tip::Event_GetPlayerPos( void ) {
  1303. idPlayer *player = gameLocal.GetLocalPlayer();
  1304. if ( player ) {
  1305. playerPos = player->GetPhysics()->GetOrigin();
  1306. PostEventMS( &EV_TipOff, 100 );
  1307. }
  1308. }
  1309. /*
  1310. ================
  1311. idTarget_Tip::Event_Activate
  1312. ================
  1313. */
  1314. void idTarget_Tip::Event_Activate( idEntity *activator ) {
  1315. idPlayer *player = gameLocal.GetLocalPlayer();
  1316. if ( player ) {
  1317. if ( player->IsTipVisible() ) {
  1318. PostEventSec( &EV_Activate, 5.1f, activator );
  1319. return;
  1320. }
  1321. player->ShowTip( spawnArgs.GetString( "text_title" ), spawnArgs.GetString( "text_tip" ), false );
  1322. PostEventMS( &EV_GetPlayerPos, 2000 );
  1323. }
  1324. }
  1325. /*
  1326. ================
  1327. idTarget_Tip::Event_TipOff
  1328. ================
  1329. */
  1330. void idTarget_Tip::Event_TipOff( void ) {
  1331. idPlayer *player = gameLocal.GetLocalPlayer();
  1332. if ( player ) {
  1333. idVec3 v = player->GetPhysics()->GetOrigin() - playerPos;
  1334. if ( v.Length() > 96.0f ) {
  1335. player->HideTip();
  1336. } else {
  1337. PostEventMS( &EV_TipOff, 100 );
  1338. }
  1339. }
  1340. }
  1341. /*
  1342. ===============================================================================
  1343. idTarget_GiveSecurity
  1344. ===============================================================================
  1345. */
  1346. CLASS_DECLARATION( idTarget, idTarget_GiveSecurity )
  1347. EVENT( EV_Activate, idTarget_GiveSecurity::Event_Activate )
  1348. END_CLASS
  1349. /*
  1350. ================
  1351. idTarget_GiveEmail::Event_Activate
  1352. ================
  1353. */
  1354. void idTarget_GiveSecurity::Event_Activate( idEntity *activator ) {
  1355. idPlayer *player = gameLocal.GetLocalPlayer();
  1356. if ( player ) {
  1357. player->GiveSecurity( spawnArgs.GetString( "text_security" ) );
  1358. }
  1359. }
  1360. /*
  1361. ===============================================================================
  1362. idTarget_RemoveWeapons
  1363. ===============================================================================
  1364. */
  1365. CLASS_DECLARATION( idTarget, idTarget_RemoveWeapons )
  1366. EVENT( EV_Activate, idTarget_RemoveWeapons::Event_Activate )
  1367. END_CLASS
  1368. /*
  1369. ================
  1370. idTarget_RemoveWeapons::Event_Activate
  1371. ================
  1372. */
  1373. void idTarget_RemoveWeapons::Event_Activate( idEntity *activator ) {
  1374. for( int i = 0; i < gameLocal.numClients; i++ ) {
  1375. if ( gameLocal.entities[ i ] ) {
  1376. idPlayer *player = static_cast< idPlayer* >( gameLocal.entities[i] );
  1377. const idKeyValue *kv = spawnArgs.MatchPrefix( "weapon", NULL );
  1378. while ( kv ) {
  1379. player->RemoveWeapon( kv->GetValue() );
  1380. kv = spawnArgs.MatchPrefix( "weapon", kv );
  1381. }
  1382. player->SelectWeapon( player->weapon_fists, true );
  1383. }
  1384. }
  1385. }
  1386. /*
  1387. ===============================================================================
  1388. idTarget_LevelTrigger
  1389. ===============================================================================
  1390. */
  1391. CLASS_DECLARATION( idTarget, idTarget_LevelTrigger )
  1392. EVENT( EV_Activate, idTarget_LevelTrigger::Event_Activate )
  1393. END_CLASS
  1394. /*
  1395. ================
  1396. idTarget_LevelTrigger::Event_Activate
  1397. ================
  1398. */
  1399. void idTarget_LevelTrigger::Event_Activate( idEntity *activator ) {
  1400. for( int i = 0; i < gameLocal.numClients; i++ ) {
  1401. if ( gameLocal.entities[ i ] ) {
  1402. idPlayer *player = static_cast< idPlayer* >( gameLocal.entities[i] );
  1403. player->SetLevelTrigger( spawnArgs.GetString( "levelName" ), spawnArgs.GetString( "triggerName" ) );
  1404. }
  1405. }
  1406. }
  1407. /*
  1408. ===============================================================================
  1409. idTarget_EnableStamina
  1410. ===============================================================================
  1411. */
  1412. CLASS_DECLARATION( idTarget, idTarget_EnableStamina )
  1413. EVENT( EV_Activate, idTarget_EnableStamina::Event_Activate )
  1414. END_CLASS
  1415. /*
  1416. ================
  1417. idTarget_EnableStamina::Event_Activate
  1418. ================
  1419. */
  1420. void idTarget_EnableStamina::Event_Activate( idEntity *activator ) {
  1421. for( int i = 0; i < gameLocal.numClients; i++ ) {
  1422. if ( gameLocal.entities[ i ] ) {
  1423. idPlayer *player = static_cast< idPlayer* >( gameLocal.entities[i] );
  1424. if ( spawnArgs.GetBool( "enable" ) ) {
  1425. pm_stamina.SetFloat( player->spawnArgs.GetFloat( "pm_stamina" ) );
  1426. } else {
  1427. pm_stamina.SetFloat( 0.0f );
  1428. }
  1429. }
  1430. }
  1431. }
  1432. /*
  1433. ===============================================================================
  1434. idTarget_FadeSoundClass
  1435. ===============================================================================
  1436. */
  1437. const idEventDef EV_RestoreVolume( "<RestoreVolume>" );
  1438. CLASS_DECLARATION( idTarget, idTarget_FadeSoundClass )
  1439. EVENT( EV_Activate, idTarget_FadeSoundClass::Event_Activate )
  1440. EVENT( EV_RestoreVolume, idTarget_FadeSoundClass::Event_RestoreVolume )
  1441. END_CLASS
  1442. /*
  1443. ================
  1444. idTarget_FadeSoundClass::Event_Activate
  1445. ================
  1446. */
  1447. void idTarget_FadeSoundClass::Event_Activate( idEntity *activator ) {
  1448. float fadeTime = spawnArgs.GetFloat( "fadeTime" );
  1449. float fadeDB = spawnArgs.GetFloat( "fadeDB" );
  1450. float fadeDuration = spawnArgs.GetFloat( "fadeDuration" );
  1451. int fadeClass = spawnArgs.GetInt( "fadeClass" );
  1452. // start any sound fading now
  1453. if ( fadeTime ) {
  1454. gameSoundWorld->FadeSoundClasses( fadeClass, spawnArgs.GetBool( "fadeIn" ) ? fadeDB : 0.0f - fadeDB, fadeTime );
  1455. if ( fadeDuration ) {
  1456. PostEventSec( &EV_RestoreVolume, fadeDuration );
  1457. }
  1458. }
  1459. }
  1460. /*
  1461. ================
  1462. idTarget_FadeSoundClass::Event_RestoreVolume
  1463. ================
  1464. */
  1465. void idTarget_FadeSoundClass::Event_RestoreVolume() {
  1466. float fadeTime = spawnArgs.GetFloat( "fadeTime" );
  1467. float fadeDB = spawnArgs.GetFloat( "fadeDB" );
  1468. int fadeClass = spawnArgs.GetInt( "fadeClass" );
  1469. // restore volume
  1470. gameSoundWorld->FadeSoundClasses( 0, fadeDB, fadeTime );
  1471. }