Target.cpp 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802
  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. #ifdef _D3XP
  641. savefile->WriteInt( savedGuiList.Num() );
  642. for( i = 0; i < savedGuiList.Num(); i++ ) {
  643. for(int j = 0; j < MAX_RENDERENTITY_GUI; j++) {
  644. savefile->WriteUserInterface(savedGuiList[i].gui[j], savedGuiList[i].gui[j] ? savedGuiList[i].gui[j]->IsUniqued() : false);
  645. }
  646. }
  647. #endif
  648. }
  649. /*
  650. ================
  651. idTarget_SetInfluence::Restore
  652. ================
  653. */
  654. void idTarget_SetInfluence::Restore( idRestoreGame *savefile ) {
  655. int i, num;
  656. int itemNum;
  657. float set;
  658. savefile->ReadInt( num );
  659. for( i = 0; i < num; i++ ) {
  660. savefile->ReadInt( itemNum );
  661. lightList.Append( itemNum );
  662. }
  663. savefile->ReadInt( num );
  664. for( i = 0; i < num; i++ ) {
  665. savefile->ReadInt( itemNum );
  666. guiList.Append( itemNum );
  667. }
  668. savefile->ReadInt( num );
  669. for( i = 0; i < num; i++ ) {
  670. savefile->ReadInt( itemNum );
  671. soundList.Append( itemNum );
  672. }
  673. savefile->ReadInt( num );
  674. for ( i = 0; i < num; i++ ) {
  675. savefile->ReadInt( itemNum );
  676. genericList.Append( itemNum );
  677. }
  678. savefile->ReadFloat( flashIn );
  679. savefile->ReadFloat( flashOut );
  680. savefile->ReadFloat( delay );
  681. savefile->ReadString( flashInSound );
  682. savefile->ReadString( flashOutSound );
  683. savefile->ReadObject( reinterpret_cast<idClass *&>( switchToCamera ) );
  684. savefile->ReadFloat( set );
  685. fovSetting.SetStartTime( set );
  686. savefile->ReadFloat( set );
  687. fovSetting.SetDuration( set );
  688. savefile->ReadFloat( set );
  689. fovSetting.SetStartValue( set );
  690. savefile->ReadFloat( set );
  691. fovSetting.SetEndValue( set );
  692. savefile->ReadBool( soundFaded );
  693. savefile->ReadBool( restoreOnTrigger );
  694. #ifdef _D3XP
  695. savefile->ReadInt( num );
  696. for( i = 0; i < num; i++ ) {
  697. SavedGui_t temp;
  698. for(int j = 0; j < MAX_RENDERENTITY_GUI; j++) {
  699. savefile->ReadUserInterface(temp.gui[j]);
  700. }
  701. savedGuiList.Append( temp );
  702. }
  703. #endif
  704. }
  705. /*
  706. ================
  707. idTarget_SetInfluence::Spawn
  708. ================
  709. */
  710. void idTarget_SetInfluence::Spawn() {
  711. PostEventMS( &EV_GatherEntities, 0 );
  712. flashIn = spawnArgs.GetFloat( "flashIn", "0" );
  713. flashOut = spawnArgs.GetFloat( "flashOut", "0" );
  714. flashInSound = spawnArgs.GetString( "snd_flashin" );
  715. flashOutSound = spawnArgs.GetString( "snd_flashout" );
  716. delay = spawnArgs.GetFloat( "delay" );
  717. soundFaded = false;
  718. restoreOnTrigger = false;
  719. // always allow during cinematics
  720. cinematic = true;
  721. }
  722. /*
  723. ================
  724. idTarget_SetInfluence::Event_Flash
  725. ================
  726. */
  727. void idTarget_SetInfluence::Event_Flash( float flash, int out ) {
  728. idPlayer *player = gameLocal.GetLocalPlayer();
  729. player->playerView.Fade( idVec4( 1, 1, 1, 1 ), flash );
  730. const idSoundShader *shader = NULL;
  731. if ( !out && flashInSound.Length() ){
  732. shader = declManager->FindSound( flashInSound );
  733. player->StartSoundShader( shader, SND_CHANNEL_VOICE, 0, false, NULL );
  734. } else if ( out && ( flashOutSound.Length() || flashInSound.Length() ) ) {
  735. shader = declManager->FindSound( flashOutSound.Length() ? flashOutSound : flashInSound );
  736. player->StartSoundShader( shader, SND_CHANNEL_VOICE, 0, false, NULL );
  737. }
  738. PostEventSec( &EV_ClearFlash, flash, flash );
  739. }
  740. /*
  741. ================
  742. idTarget_SetInfluence::Event_ClearFlash
  743. ================
  744. */
  745. void idTarget_SetInfluence::Event_ClearFlash( float flash ) {
  746. idPlayer *player = gameLocal.GetLocalPlayer();
  747. player->playerView.Fade( vec4_zero , flash );
  748. }
  749. /*
  750. ================
  751. idTarget_SetInfluence::Event_GatherEntities
  752. ================
  753. */
  754. void idTarget_SetInfluence::Event_GatherEntities() {
  755. int i, listedEntities;
  756. idEntity *entityList[ MAX_GENTITIES ];
  757. bool demonicOnly = spawnArgs.GetBool( "effect_demonic" );
  758. bool lights = spawnArgs.GetBool( "effect_lights" );
  759. bool sounds = spawnArgs.GetBool( "effect_sounds" );
  760. bool guis = spawnArgs.GetBool( "effect_guis" );
  761. bool models = spawnArgs.GetBool( "effect_models" );
  762. bool vision = spawnArgs.GetBool( "effect_vision" );
  763. bool targetsOnly = spawnArgs.GetBool( "targetsOnly" );
  764. lightList.Clear();
  765. guiList.Clear();
  766. soundList.Clear();
  767. #ifdef _D3XP
  768. savedGuiList.Clear();
  769. #endif
  770. if ( spawnArgs.GetBool( "effect_all" ) ) {
  771. lights = sounds = guis = models = vision = true;
  772. }
  773. if ( targetsOnly ) {
  774. listedEntities = targets.Num();
  775. for ( i = 0; i < listedEntities; i++ ) {
  776. entityList[i] = targets[i].GetEntity();
  777. }
  778. } else {
  779. float radius = spawnArgs.GetFloat( "radius" );
  780. listedEntities = gameLocal.EntitiesWithinRadius( GetPhysics()->GetOrigin(), radius, entityList, MAX_GENTITIES );
  781. }
  782. for( i = 0; i < listedEntities; i++ ) {
  783. idEntity *ent = entityList[ i ];
  784. if ( ent ) {
  785. if ( lights && ent->IsType( idLight::Type ) && ent->spawnArgs.FindKey( "color_demonic" ) ) {
  786. lightList.Append( ent->entityNumber );
  787. continue;
  788. }
  789. if ( sounds && ent->IsType( idSound::Type ) && ent->spawnArgs.FindKey( "snd_demonic" ) ) {
  790. soundList.Append( ent->entityNumber );
  791. continue;
  792. }
  793. if ( guis && ent->GetRenderEntity() && ent->GetRenderEntity()->gui[ 0 ] && ent->spawnArgs.FindKey( "gui_demonic" ) ) {
  794. guiList.Append( ent->entityNumber );
  795. #ifdef _D3XP
  796. SavedGui_t temp;
  797. savedGuiList.Append(temp);
  798. #endif
  799. continue;
  800. }
  801. if ( ent->IsType( idStaticEntity::Type ) && ent->spawnArgs.FindKey( "color_demonic" ) ) {
  802. genericList.Append( ent->entityNumber );
  803. continue;
  804. }
  805. }
  806. }
  807. idStr temp;
  808. temp = spawnArgs.GetString( "switchToView" );
  809. switchToCamera = ( temp.Length() ) ? gameLocal.FindEntity( temp ) : NULL;
  810. }
  811. /*
  812. ================
  813. idTarget_SetInfluence::Event_Activate
  814. ================
  815. */
  816. void idTarget_SetInfluence::Event_Activate( idEntity *activator ) {
  817. int i, j;
  818. idEntity *ent;
  819. idLight *light;
  820. idSound *sound;
  821. idStaticEntity *generic;
  822. const char *parm;
  823. const char *skin;
  824. bool update;
  825. idVec3 color;
  826. idVec4 colorTo;
  827. idPlayer *player;
  828. player = gameLocal.GetLocalPlayer();
  829. if ( spawnArgs.GetBool( "triggerActivate" ) ) {
  830. if ( restoreOnTrigger ) {
  831. ProcessEvent( &EV_RestoreInfluence );
  832. restoreOnTrigger = false;
  833. return;
  834. }
  835. restoreOnTrigger = true;
  836. }
  837. float fadeTime = spawnArgs.GetFloat( "fadeWorldSounds" );
  838. if ( delay > 0.0f ) {
  839. PostEventSec( &EV_Activate, delay, activator );
  840. delay = 0.0f;
  841. // start any sound fading now
  842. if ( fadeTime ) {
  843. gameSoundWorld->FadeSoundClasses( 0, -40.0f, fadeTime );
  844. soundFaded = true;
  845. }
  846. return;
  847. } else if ( fadeTime && !soundFaded ) {
  848. gameSoundWorld->FadeSoundClasses( 0, -40.0f, fadeTime );
  849. soundFaded = true;
  850. }
  851. if ( spawnArgs.GetBool( "triggerTargets" ) ) {
  852. ActivateTargets( activator );
  853. }
  854. if ( flashIn ) {
  855. PostEventSec( &EV_Flash, 0.0f, flashIn, 0 );
  856. }
  857. parm = spawnArgs.GetString( "snd_influence" );
  858. if ( parm && *parm ) {
  859. PostEventSec( &EV_StartSoundShader, flashIn, parm, SND_CHANNEL_ANY );
  860. }
  861. if ( switchToCamera ) {
  862. switchToCamera->PostEventSec( &EV_Activate, flashIn + 0.05f, this );
  863. }
  864. int fov = spawnArgs.GetInt( "fov" );
  865. if ( fov ) {
  866. fovSetting.Init( gameLocal.time, SEC2MS( spawnArgs.GetFloat( "fovTime" ) ), player->DefaultFov(), fov );
  867. BecomeActive( TH_THINK );
  868. }
  869. for ( i = 0; i < genericList.Num(); i++ ) {
  870. ent = gameLocal.entities[genericList[i]];
  871. if ( ent == NULL ) {
  872. continue;
  873. }
  874. generic = static_cast<idStaticEntity*>( ent );
  875. color = generic->spawnArgs.GetVector( "color_demonic" );
  876. colorTo.Set( color.x, color.y, color.z, 1.0f );
  877. generic->Fade( colorTo, spawnArgs.GetFloat( "fade_time", "0.25" ) );
  878. }
  879. for ( i = 0; i < lightList.Num(); i++ ) {
  880. ent = gameLocal.entities[lightList[i]];
  881. if ( ent == NULL || !ent->IsType( idLight::Type ) ) {
  882. continue;
  883. }
  884. light = static_cast<idLight *>(ent);
  885. parm = light->spawnArgs.GetString( "mat_demonic" );
  886. if ( parm && *parm ) {
  887. light->SetShader( parm );
  888. }
  889. color = light->spawnArgs.GetVector( "_color" );
  890. color = light->spawnArgs.GetVector( "color_demonic", color.ToString() );
  891. colorTo.Set( color.x, color.y, color.z, 1.0f );
  892. light->Fade( colorTo, spawnArgs.GetFloat( "fade_time", "0.25" ) );
  893. }
  894. for ( i = 0; i < soundList.Num(); i++ ) {
  895. ent = gameLocal.entities[soundList[i]];
  896. if ( ent == NULL || !ent->IsType( idSound::Type ) ) {
  897. continue;
  898. }
  899. sound = static_cast<idSound *>(ent);
  900. parm = sound->spawnArgs.GetString( "snd_demonic" );
  901. if ( parm && *parm ) {
  902. if ( sound->spawnArgs.GetBool( "overlayDemonic" ) ) {
  903. sound->StartSound( "snd_demonic", SND_CHANNEL_DEMONIC, 0, false, NULL );
  904. } else {
  905. sound->StopSound( SND_CHANNEL_ANY, false );
  906. sound->SetSound( parm );
  907. }
  908. }
  909. }
  910. for ( i = 0; i < guiList.Num(); i++ ) {
  911. ent = gameLocal.entities[guiList[i]];
  912. if ( ent == NULL || ent->GetRenderEntity() == NULL ) {
  913. continue;
  914. }
  915. update = false;
  916. for ( j = 0; j < MAX_RENDERENTITY_GUI; j++ ) {
  917. if ( ent->GetRenderEntity()->gui[ j ] && ent->spawnArgs.FindKey( j == 0 ? "gui_demonic" : va( "gui_demonic%d", j+1 ) ) ) {
  918. #ifdef _D3XP
  919. //Backup the old one
  920. savedGuiList[i].gui[j] = ent->GetRenderEntity()->gui[ j ];
  921. #endif
  922. ent->GetRenderEntity()->gui[ j ] = uiManager->FindGui( ent->spawnArgs.GetString( j == 0 ? "gui_demonic" : va( "gui_demonic%d", j+1 ) ), true );
  923. update = true;
  924. }
  925. }
  926. if ( update ) {
  927. ent->UpdateVisuals();
  928. ent->Present();
  929. }
  930. }
  931. player->SetInfluenceLevel( spawnArgs.GetInt( "influenceLevel" ) );
  932. int snapAngle = spawnArgs.GetInt( "snapAngle" );
  933. if ( snapAngle ) {
  934. idAngles ang( 0, snapAngle, 0 );
  935. player->SetViewAngles( ang );
  936. player->SetAngles( ang );
  937. }
  938. if ( spawnArgs.GetBool( "effect_vision" ) ) {
  939. parm = spawnArgs.GetString( "mtrVision" );
  940. skin = spawnArgs.GetString( "skinVision" );
  941. player->SetInfluenceView( parm, skin, spawnArgs.GetInt( "visionRadius" ), this );
  942. }
  943. parm = spawnArgs.GetString( "mtrWorld" );
  944. if ( parm && *parm ) {
  945. gameLocal.SetGlobalMaterial( declManager->FindMaterial( parm ) );
  946. }
  947. if ( !restoreOnTrigger ) {
  948. PostEventMS( &EV_RestoreInfluence, SEC2MS( spawnArgs.GetFloat( "time" ) ) );
  949. }
  950. }
  951. /*
  952. ================
  953. idTarget_SetInfluence::Think
  954. ================
  955. */
  956. void idTarget_SetInfluence::Think( void ) {
  957. if ( thinkFlags & TH_THINK ) {
  958. idPlayer *player = gameLocal.GetLocalPlayer();
  959. player->SetInfluenceFov( fovSetting.GetCurrentValue( gameLocal.time ) );
  960. if ( fovSetting.IsDone( gameLocal.time ) ) {
  961. if ( !spawnArgs.GetBool( "leaveFOV" ) ) {
  962. player->SetInfluenceFov( 0 );
  963. }
  964. BecomeInactive( TH_THINK );
  965. }
  966. } else {
  967. BecomeInactive( TH_ALL );
  968. }
  969. }
  970. /*
  971. ================
  972. idTarget_SetInfluence::Event_RestoreInfluence
  973. ================
  974. */
  975. void idTarget_SetInfluence::Event_RestoreInfluence() {
  976. int i, j;
  977. idEntity *ent;
  978. idLight *light;
  979. idSound *sound;
  980. idStaticEntity *generic;
  981. bool update;
  982. idVec3 color;
  983. idVec4 colorTo;
  984. if ( flashOut ) {
  985. PostEventSec( &EV_Flash, 0.0f, flashOut, 1 );
  986. }
  987. if ( switchToCamera ) {
  988. switchToCamera->PostEventMS( &EV_Activate, 0.0f, this );
  989. }
  990. for ( i = 0; i < genericList.Num(); i++ ) {
  991. ent = gameLocal.entities[genericList[i]];
  992. if ( ent == NULL ) {
  993. continue;
  994. }
  995. generic = static_cast<idStaticEntity*>( ent );
  996. colorTo.Set( 1.0f, 1.0f, 1.0f, 1.0f );
  997. generic->Fade( colorTo, spawnArgs.GetFloat( "fade_time", "0.25" ) );
  998. }
  999. for ( i = 0; i < lightList.Num(); i++ ) {
  1000. ent = gameLocal.entities[lightList[i]];
  1001. if ( ent == NULL || !ent->IsType( idLight::Type ) ) {
  1002. continue;
  1003. }
  1004. light = static_cast<idLight *>(ent);
  1005. if ( !light->spawnArgs.GetBool( "leave_demonic_mat" ) ) {
  1006. const char *texture = light->spawnArgs.GetString( "texture", "lights/squarelight1" );
  1007. light->SetShader( texture );
  1008. }
  1009. color = light->spawnArgs.GetVector( "_color" );
  1010. colorTo.Set( color.x, color.y, color.z, 1.0f );
  1011. light->Fade( colorTo, spawnArgs.GetFloat( "fade_time", "0.25" ) );
  1012. }
  1013. for ( i = 0; i < soundList.Num(); i++ ) {
  1014. ent = gameLocal.entities[soundList[i]];
  1015. if ( ent == NULL || !ent->IsType( idSound::Type ) ) {
  1016. continue;
  1017. }
  1018. sound = static_cast<idSound *>(ent);
  1019. sound->StopSound( SND_CHANNEL_ANY, false );
  1020. sound->SetSound( sound->spawnArgs.GetString( "s_shader" ) );
  1021. }
  1022. for ( i = 0; i < guiList.Num(); i++ ) {
  1023. ent = gameLocal.entities[guiList[i]];
  1024. if ( ent == NULL || GetRenderEntity() == NULL ) {
  1025. continue;
  1026. }
  1027. update = false;
  1028. for( j = 0; j < MAX_RENDERENTITY_GUI; j++ ) {
  1029. if ( ent->GetRenderEntity()->gui[ j ] ) {
  1030. #ifdef _D3XP
  1031. ent->GetRenderEntity()->gui[ j ] = savedGuiList[i].gui[j];
  1032. #else
  1033. ent->GetRenderEntity()->gui[ j ] = uiManager->FindGui( ent->spawnArgs.GetString( j == 0 ? "gui" : va( "gui%d", j+1 ) ) );
  1034. #endif
  1035. update = true;
  1036. }
  1037. }
  1038. if ( update ) {
  1039. ent->UpdateVisuals();
  1040. ent->Present();
  1041. }
  1042. }
  1043. idPlayer *player = gameLocal.GetLocalPlayer();
  1044. player->SetInfluenceLevel( 0 );
  1045. player->SetInfluenceView( NULL, NULL, 0.0f, NULL );
  1046. player->SetInfluenceFov( 0 );
  1047. gameLocal.SetGlobalMaterial( NULL );
  1048. float fadeTime = spawnArgs.GetFloat( "fadeWorldSounds" );
  1049. if ( fadeTime ) {
  1050. gameSoundWorld->FadeSoundClasses( 0, 0.0f, fadeTime / 2.0f );
  1051. }
  1052. }
  1053. /*
  1054. ===============================================================================
  1055. idTarget_SetKeyVal
  1056. ===============================================================================
  1057. */
  1058. CLASS_DECLARATION( idTarget, idTarget_SetKeyVal )
  1059. EVENT( EV_Activate, idTarget_SetKeyVal::Event_Activate )
  1060. END_CLASS
  1061. /*
  1062. ================
  1063. idTarget_SetKeyVal::Event_Activate
  1064. ================
  1065. */
  1066. void idTarget_SetKeyVal::Event_Activate( idEntity *activator ) {
  1067. int i;
  1068. idStr key, val;
  1069. idEntity *ent;
  1070. const idKeyValue *kv;
  1071. int n;
  1072. for( i = 0; i < targets.Num(); i++ ) {
  1073. ent = targets[ i ].GetEntity();
  1074. if ( ent ) {
  1075. kv = spawnArgs.MatchPrefix("keyval");
  1076. while ( kv ) {
  1077. n = kv->GetValue().Find( ";" );
  1078. if ( n > 0 ) {
  1079. key = kv->GetValue().Left( n );
  1080. val = kv->GetValue().Right( kv->GetValue().Length() - n - 1 );
  1081. ent->spawnArgs.Set( key, val );
  1082. for ( int j = 0; j < MAX_RENDERENTITY_GUI; j++ ) {
  1083. if ( ent->GetRenderEntity()->gui[ j ] ) {
  1084. if ( idStr::Icmpn( key, "gui_", 4 ) == 0 ) {
  1085. ent->GetRenderEntity()->gui[ j ]->SetStateString( key, val );
  1086. ent->GetRenderEntity()->gui[ j ]->StateChanged( gameLocal.time );
  1087. }
  1088. }
  1089. }
  1090. }
  1091. kv = spawnArgs.MatchPrefix( "keyval", kv );
  1092. }
  1093. ent->UpdateChangeableSpawnArgs( NULL );
  1094. ent->UpdateVisuals();
  1095. ent->Present();
  1096. }
  1097. }
  1098. }
  1099. /*
  1100. ===============================================================================
  1101. idTarget_SetFov
  1102. ===============================================================================
  1103. */
  1104. CLASS_DECLARATION( idTarget, idTarget_SetFov )
  1105. EVENT( EV_Activate, idTarget_SetFov::Event_Activate )
  1106. END_CLASS
  1107. /*
  1108. ================
  1109. idTarget_SetFov::Save
  1110. ================
  1111. */
  1112. void idTarget_SetFov::Save( idSaveGame *savefile ) const {
  1113. savefile->WriteFloat( fovSetting.GetStartTime() );
  1114. savefile->WriteFloat( fovSetting.GetDuration() );
  1115. savefile->WriteFloat( fovSetting.GetStartValue() );
  1116. savefile->WriteFloat( fovSetting.GetEndValue() );
  1117. }
  1118. /*
  1119. ================
  1120. idTarget_SetFov::Restore
  1121. ================
  1122. */
  1123. void idTarget_SetFov::Restore( idRestoreGame *savefile ) {
  1124. float setting;
  1125. savefile->ReadFloat( setting );
  1126. fovSetting.SetStartTime( setting );
  1127. savefile->ReadFloat( setting );
  1128. fovSetting.SetDuration( setting );
  1129. savefile->ReadFloat( setting );
  1130. fovSetting.SetStartValue( setting );
  1131. savefile->ReadFloat( setting );
  1132. fovSetting.SetEndValue( setting );
  1133. fovSetting.GetCurrentValue( gameLocal.time );
  1134. }
  1135. /*
  1136. ================
  1137. idTarget_SetFov::Event_Activate
  1138. ================
  1139. */
  1140. void idTarget_SetFov::Event_Activate( idEntity *activator ) {
  1141. // always allow during cinematics
  1142. cinematic = true;
  1143. idPlayer *player = gameLocal.GetLocalPlayer();
  1144. fovSetting.Init( gameLocal.time, SEC2MS( spawnArgs.GetFloat( "time" ) ), player ? player->DefaultFov() : g_fov.GetFloat(), spawnArgs.GetFloat( "fov" ) );
  1145. BecomeActive( TH_THINK );
  1146. }
  1147. /*
  1148. ================
  1149. idTarget_SetFov::Think
  1150. ================
  1151. */
  1152. void idTarget_SetFov::Think( void ) {
  1153. if ( thinkFlags & TH_THINK ) {
  1154. idPlayer *player = gameLocal.GetLocalPlayer();
  1155. player->SetInfluenceFov( fovSetting.GetCurrentValue( gameLocal.time ) );
  1156. if ( fovSetting.IsDone( gameLocal.time ) ) {
  1157. player->SetInfluenceFov( 0.0f );
  1158. BecomeInactive( TH_THINK );
  1159. }
  1160. } else {
  1161. BecomeInactive( TH_ALL );
  1162. }
  1163. }
  1164. /*
  1165. ===============================================================================
  1166. idTarget_SetPrimaryObjective
  1167. ===============================================================================
  1168. */
  1169. CLASS_DECLARATION( idTarget, idTarget_SetPrimaryObjective )
  1170. EVENT( EV_Activate, idTarget_SetPrimaryObjective::Event_Activate )
  1171. END_CLASS
  1172. /*
  1173. ================
  1174. idTarget_SetPrimaryObjective::Event_Activate
  1175. ================
  1176. */
  1177. void idTarget_SetPrimaryObjective::Event_Activate( idEntity *activator ) {
  1178. idPlayer *player = gameLocal.GetLocalPlayer();
  1179. if ( player && player->objectiveSystem ) {
  1180. player->objectiveSystem->SetStateString( "missionobjective", spawnArgs.GetString( "text", common->GetLanguageDict()->GetString( "#str_04253" ) ) );
  1181. }
  1182. }
  1183. /*
  1184. ===============================================================================
  1185. idTarget_LockDoor
  1186. ===============================================================================
  1187. */
  1188. CLASS_DECLARATION( idTarget, idTarget_LockDoor )
  1189. EVENT( EV_Activate, idTarget_LockDoor::Event_Activate )
  1190. END_CLASS
  1191. /*
  1192. ================
  1193. idTarget_LockDoor::Event_Activate
  1194. ================
  1195. */
  1196. void idTarget_LockDoor::Event_Activate( idEntity *activator ) {
  1197. int i;
  1198. idEntity *ent;
  1199. int lock;
  1200. lock = spawnArgs.GetInt( "locked", "1" );
  1201. for( i = 0; i < targets.Num(); i++ ) {
  1202. ent = targets[ i ].GetEntity();
  1203. if ( ent && ent->IsType( idDoor::Type ) ) {
  1204. if ( static_cast<idDoor *>( ent )->IsLocked() ) {
  1205. static_cast<idDoor *>( ent )->Lock( 0 );
  1206. } else {
  1207. static_cast<idDoor *>( ent )->Lock( lock );
  1208. }
  1209. }
  1210. }
  1211. }
  1212. /*
  1213. ===============================================================================
  1214. idTarget_CallObjectFunction
  1215. ===============================================================================
  1216. */
  1217. CLASS_DECLARATION( idTarget, idTarget_CallObjectFunction )
  1218. EVENT( EV_Activate, idTarget_CallObjectFunction::Event_Activate )
  1219. END_CLASS
  1220. /*
  1221. ================
  1222. idTarget_CallObjectFunction::Event_Activate
  1223. ================
  1224. */
  1225. void idTarget_CallObjectFunction::Event_Activate( idEntity *activator ) {
  1226. int i;
  1227. idEntity *ent;
  1228. const function_t *func;
  1229. const char *funcName;
  1230. idThread *thread;
  1231. funcName = spawnArgs.GetString( "call" );
  1232. for( i = 0; i < targets.Num(); i++ ) {
  1233. ent = targets[ i ].GetEntity();
  1234. if ( ent && ent->scriptObject.HasObject() ) {
  1235. func = ent->scriptObject.GetFunction( funcName );
  1236. if ( !func ) {
  1237. gameLocal.Error( "Function '%s' not found on entity '%s' for function call from '%s'", funcName, ent->name.c_str(), name.c_str() );
  1238. }
  1239. if ( func->type->NumParameters() != 1 ) {
  1240. 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() );
  1241. }
  1242. if ( !ent->scriptObject.GetTypeDef()->Inherits( func->type->GetParmType( 0 ) ) ) {
  1243. gameLocal.Error( "Function '%s' on entity '%s' is the wrong type for function call from '%s'", funcName, ent->name.c_str(), name.c_str() );
  1244. }
  1245. // create a thread and call the function
  1246. thread = new idThread();
  1247. thread->CallFunction( ent, func, true );
  1248. thread->Start();
  1249. }
  1250. }
  1251. }
  1252. /*
  1253. ===============================================================================
  1254. idTarget_EnableLevelWeapons
  1255. ===============================================================================
  1256. */
  1257. CLASS_DECLARATION( idTarget, idTarget_EnableLevelWeapons )
  1258. EVENT( EV_Activate, idTarget_EnableLevelWeapons::Event_Activate )
  1259. END_CLASS
  1260. /*
  1261. ================
  1262. idTarget_EnableLevelWeapons::Event_Activate
  1263. ================
  1264. */
  1265. void idTarget_EnableLevelWeapons::Event_Activate( idEntity *activator ) {
  1266. int i;
  1267. const char *weap;
  1268. gameLocal.world->spawnArgs.SetBool( "no_Weapons", spawnArgs.GetBool( "disable" ) );
  1269. if ( spawnArgs.GetBool( "disable" ) ) {
  1270. for( i = 0; i < gameLocal.numClients; i++ ) {
  1271. if ( gameLocal.entities[ i ] ) {
  1272. gameLocal.entities[ i ]->ProcessEvent( &EV_Player_DisableWeapon );
  1273. }
  1274. }
  1275. } else {
  1276. weap = spawnArgs.GetString( "weapon" );
  1277. for( i = 0; i < gameLocal.numClients; i++ ) {
  1278. if ( gameLocal.entities[ i ] ) {
  1279. gameLocal.entities[ i ]->ProcessEvent( &EV_Player_EnableWeapon );
  1280. if ( weap && weap[ 0 ] ) {
  1281. gameLocal.entities[ i ]->PostEventSec( &EV_Player_SelectWeapon, 0.5f, weap );
  1282. }
  1283. }
  1284. }
  1285. }
  1286. }
  1287. /*
  1288. ===============================================================================
  1289. idTarget_Tip
  1290. ===============================================================================
  1291. */
  1292. const idEventDef EV_TipOff( "<TipOff>" );
  1293. extern const idEventDef EV_GetPlayerPos( "<getplayerpos>" );
  1294. CLASS_DECLARATION( idTarget, idTarget_Tip )
  1295. EVENT( EV_Activate, idTarget_Tip::Event_Activate )
  1296. EVENT( EV_TipOff, idTarget_Tip::Event_TipOff )
  1297. EVENT( EV_GetPlayerPos, idTarget_Tip::Event_GetPlayerPos )
  1298. END_CLASS
  1299. /*
  1300. ================
  1301. idTarget_Tip::idTarget_Tip
  1302. ================
  1303. */
  1304. idTarget_Tip::idTarget_Tip( void ) {
  1305. playerPos.Zero();
  1306. }
  1307. /*
  1308. ================
  1309. idTarget_Tip::Spawn
  1310. ================
  1311. */
  1312. void idTarget_Tip::Spawn( void ) {
  1313. }
  1314. /*
  1315. ================
  1316. idTarget_Tip::Save
  1317. ================
  1318. */
  1319. void idTarget_Tip::Save( idSaveGame *savefile ) const {
  1320. savefile->WriteVec3( playerPos );
  1321. }
  1322. /*
  1323. ================
  1324. idTarget_Tip::Restore
  1325. ================
  1326. */
  1327. void idTarget_Tip::Restore( idRestoreGame *savefile ) {
  1328. savefile->ReadVec3( playerPos );
  1329. }
  1330. /*
  1331. ================
  1332. idTarget_Tip::Event_Activate
  1333. ================
  1334. */
  1335. void idTarget_Tip::Event_GetPlayerPos( void ) {
  1336. idPlayer *player = gameLocal.GetLocalPlayer();
  1337. if ( player ) {
  1338. playerPos = player->GetPhysics()->GetOrigin();
  1339. PostEventMS( &EV_TipOff, 100 );
  1340. }
  1341. }
  1342. /*
  1343. ================
  1344. idTarget_Tip::Event_Activate
  1345. ================
  1346. */
  1347. void idTarget_Tip::Event_Activate( idEntity *activator ) {
  1348. idPlayer *player = gameLocal.GetLocalPlayer();
  1349. if ( player ) {
  1350. if ( player->IsTipVisible() ) {
  1351. PostEventSec( &EV_Activate, 5.1f, activator );
  1352. return;
  1353. }
  1354. player->ShowTip( spawnArgs.GetString( "text_title" ), spawnArgs.GetString( "text_tip" ), false );
  1355. PostEventMS( &EV_GetPlayerPos, 2000 );
  1356. }
  1357. }
  1358. /*
  1359. ================
  1360. idTarget_Tip::Event_TipOff
  1361. ================
  1362. */
  1363. void idTarget_Tip::Event_TipOff( void ) {
  1364. idPlayer *player = gameLocal.GetLocalPlayer();
  1365. if ( player ) {
  1366. idVec3 v = player->GetPhysics()->GetOrigin() - playerPos;
  1367. if ( v.Length() > 96.0f ) {
  1368. player->HideTip();
  1369. } else {
  1370. PostEventMS( &EV_TipOff, 100 );
  1371. }
  1372. }
  1373. }
  1374. /*
  1375. ===============================================================================
  1376. idTarget_GiveSecurity
  1377. ===============================================================================
  1378. */
  1379. CLASS_DECLARATION( idTarget, idTarget_GiveSecurity )
  1380. EVENT( EV_Activate, idTarget_GiveSecurity::Event_Activate )
  1381. END_CLASS
  1382. /*
  1383. ================
  1384. idTarget_GiveEmail::Event_Activate
  1385. ================
  1386. */
  1387. void idTarget_GiveSecurity::Event_Activate( idEntity *activator ) {
  1388. idPlayer *player = gameLocal.GetLocalPlayer();
  1389. if ( player ) {
  1390. player->GiveSecurity( spawnArgs.GetString( "text_security" ) );
  1391. }
  1392. }
  1393. /*
  1394. ===============================================================================
  1395. idTarget_RemoveWeapons
  1396. ===============================================================================
  1397. */
  1398. CLASS_DECLARATION( idTarget, idTarget_RemoveWeapons )
  1399. EVENT( EV_Activate, idTarget_RemoveWeapons::Event_Activate )
  1400. END_CLASS
  1401. /*
  1402. ================
  1403. idTarget_RemoveWeapons::Event_Activate
  1404. ================
  1405. */
  1406. void idTarget_RemoveWeapons::Event_Activate( idEntity *activator ) {
  1407. for( int i = 0; i < gameLocal.numClients; i++ ) {
  1408. if ( gameLocal.entities[ i ] ) {
  1409. idPlayer *player = static_cast< idPlayer* >( gameLocal.entities[i] );
  1410. const idKeyValue *kv = spawnArgs.MatchPrefix( "weapon", NULL );
  1411. while ( kv ) {
  1412. player->RemoveWeapon( kv->GetValue() );
  1413. kv = spawnArgs.MatchPrefix( "weapon", kv );
  1414. }
  1415. player->SelectWeapon( player->weapon_fists, true );
  1416. }
  1417. }
  1418. }
  1419. /*
  1420. ===============================================================================
  1421. idTarget_LevelTrigger
  1422. ===============================================================================
  1423. */
  1424. CLASS_DECLARATION( idTarget, idTarget_LevelTrigger )
  1425. EVENT( EV_Activate, idTarget_LevelTrigger::Event_Activate )
  1426. END_CLASS
  1427. /*
  1428. ================
  1429. idTarget_LevelTrigger::Event_Activate
  1430. ================
  1431. */
  1432. void idTarget_LevelTrigger::Event_Activate( idEntity *activator ) {
  1433. for( int i = 0; i < gameLocal.numClients; i++ ) {
  1434. if ( gameLocal.entities[ i ] ) {
  1435. idPlayer *player = static_cast< idPlayer* >( gameLocal.entities[i] );
  1436. player->SetLevelTrigger( spawnArgs.GetString( "levelName" ), spawnArgs.GetString( "triggerName" ) );
  1437. }
  1438. }
  1439. }
  1440. /*
  1441. ===============================================================================
  1442. idTarget_EnableStamina
  1443. ===============================================================================
  1444. */
  1445. CLASS_DECLARATION( idTarget, idTarget_EnableStamina )
  1446. EVENT( EV_Activate, idTarget_EnableStamina::Event_Activate )
  1447. END_CLASS
  1448. /*
  1449. ================
  1450. idTarget_EnableStamina::Event_Activate
  1451. ================
  1452. */
  1453. void idTarget_EnableStamina::Event_Activate( idEntity *activator ) {
  1454. for( int i = 0; i < gameLocal.numClients; i++ ) {
  1455. if ( gameLocal.entities[ i ] ) {
  1456. idPlayer *player = static_cast< idPlayer* >( gameLocal.entities[i] );
  1457. if ( spawnArgs.GetBool( "enable" ) ) {
  1458. pm_stamina.SetFloat( player->spawnArgs.GetFloat( "pm_stamina" ) );
  1459. } else {
  1460. pm_stamina.SetFloat( 0.0f );
  1461. }
  1462. }
  1463. }
  1464. }
  1465. /*
  1466. ===============================================================================
  1467. idTarget_FadeSoundClass
  1468. ===============================================================================
  1469. */
  1470. const idEventDef EV_RestoreVolume( "<RestoreVolume>" );
  1471. CLASS_DECLARATION( idTarget, idTarget_FadeSoundClass )
  1472. EVENT( EV_Activate, idTarget_FadeSoundClass::Event_Activate )
  1473. EVENT( EV_RestoreVolume, idTarget_FadeSoundClass::Event_RestoreVolume )
  1474. END_CLASS
  1475. /*
  1476. ================
  1477. idTarget_FadeSoundClass::Event_Activate
  1478. ================
  1479. */
  1480. void idTarget_FadeSoundClass::Event_Activate( idEntity *activator ) {
  1481. float fadeTime = spawnArgs.GetFloat( "fadeTime" );
  1482. float fadeDB = spawnArgs.GetFloat( "fadeDB" );
  1483. float fadeDuration = spawnArgs.GetFloat( "fadeDuration" );
  1484. int fadeClass = spawnArgs.GetInt( "fadeClass" );
  1485. // start any sound fading now
  1486. if ( fadeTime ) {
  1487. gameSoundWorld->FadeSoundClasses( fadeClass, spawnArgs.GetBool( "fadeIn" ) ? fadeDB : 0.0f - fadeDB, fadeTime );
  1488. if ( fadeDuration ) {
  1489. PostEventSec( &EV_RestoreVolume, fadeDuration );
  1490. }
  1491. }
  1492. }
  1493. /*
  1494. ================
  1495. idTarget_FadeSoundClass::Event_RestoreVolume
  1496. ================
  1497. */
  1498. void idTarget_FadeSoundClass::Event_RestoreVolume() {
  1499. float fadeTime = spawnArgs.GetFloat( "fadeTime" );
  1500. float fadeDB = spawnArgs.GetFloat( "fadeDB" );
  1501. int fadeClass = spawnArgs.GetInt( "fadeClass" );
  1502. // restore volume
  1503. gameSoundWorld->FadeSoundClasses( 0, fadeDB, fadeTime );
  1504. }