contractcamera.cpp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. #include "../idlib/precompiled.h"
  2. #pragma hdrstop
  3. #include "Game_local.h"
  4. const idEventDef EV_contractcamreset( "contractcamreset" );
  5. CLASS_DECLARATION( idAnimatedEntity, idContractCamera )
  6. EVENT( EV_contractcamreset, idContractCamera::Event_reset)
  7. END_CLASS
  8. void idContractCamera::Save( idSaveGame *savefile ) const
  9. {
  10. savefile->WriteInt(state);
  11. savefile->WriteInt(nextStateTime);
  12. savefile->WriteInt(maxcount);
  13. savefile->WriteInt(count);
  14. savefile->WriteObject(frobcube);
  15. savefile->WriteObject(light);
  16. }
  17. void idContractCamera::Restore( idRestoreGame *savefile )
  18. {
  19. savefile->ReadInt(state);
  20. savefile->ReadInt(nextStateTime);
  21. savefile->ReadInt(maxcount);
  22. savefile->ReadInt(count);
  23. savefile->ReadObject(reinterpret_cast<idClass *&>(frobcube));
  24. savefile->ReadObject(reinterpret_cast<idClass *&>(light));
  25. }
  26. void idContractCamera::Spawn( void )
  27. {
  28. idDict args;
  29. idVec3 up;
  30. this->GetPhysics()->GetAxis().ToAngles().ToVectors(NULL, NULL, &up);
  31. args.SetVector( "origin", this->GetPhysics()->GetOrigin() );
  32. args.Set( "model", "models/doccam/tris_cm.ase" );
  33. args.SetInt( "frobbable", 1 );
  34. args.SetInt( "corpse", 1 );
  35. args.SetInt( "noGrab", 1 );
  36. args.Set( "owner", this->GetName() );
  37. args.Set( "recordable", this->spawnArgs.GetString("recordable", "1") );
  38. //args.SetInt( "index", i );
  39. this->frobcube = gameLocal.SpawnEntityType( idStaticEntity::Type, &args );
  40. //this->frobcube->isFrobbable = false;
  41. this->SetSkin(declManager->FindSkin("skins/doccam/nocam"));
  42. state = OFF;
  43. nextStateTime = 0;
  44. maxcount = spawnArgs.GetInt("count", "5");
  45. count = 0;
  46. args.Clear();
  47. args.SetVector( "origin", this->GetPhysics()->GetOrigin() + (up * 5) );
  48. args.Set( "texture", "lights/monitorglow" );
  49. args.SetInt("alarmlight", 0);
  50. args.SetInt("start_off", 1);
  51. light = ( idLight * )gameLocal.SpawnEntityType( idLight::Type, &args );
  52. light->SetRadius(15);
  53. light->Bind(this, true);
  54. Event_reset();
  55. BecomeActive( TH_THINK );
  56. }
  57. void idContractCamera::OnFrob( idEntity* activator )
  58. {
  59. if (state == OFF)
  60. {
  61. StartSound( "snd_cameraopen" , SND_CHANNEL_ANY, 0, false, NULL );
  62. nextStateTime = Event_PlayAnim("deploy", 4);
  63. this->SetSkin(declManager->FindSkin("skins/doccam/cam"));
  64. this->frobcube->isFrobbable = false;
  65. this->state = UNFOLDING;
  66. }
  67. else if (state == PHOTODONE)
  68. {
  69. this->SetSkin(declManager->FindSkin("skins/doccam/nocam"));
  70. StartSound( "snd_putaway" , SND_CHANNEL_ANY, 0, false, NULL );
  71. idStr scriptName = spawnArgs.GetString( "call" );
  72. const function_t *scriptFunction;
  73. scriptFunction = gameLocal.program.FindFunction( scriptName );
  74. if ( scriptFunction )
  75. {
  76. idThread *thread;
  77. thread = new idThread( scriptFunction );
  78. thread->DelayedStart( 0 );
  79. }
  80. this->state = TAKEN;
  81. }
  82. else if (state == TAKEN)
  83. {
  84. gameLocal.GetLocalPlayer()->Event_hudMessage( common->GetLanguageDict()->GetString( "#str_02103" ) );
  85. StartSound( "snd_error" , SND_CHANNEL_ANY, 0, false, NULL );
  86. }
  87. }
  88. void idContractCamera::UpdateStates( void )
  89. {
  90. if (state == UNFOLDING)
  91. {
  92. if (gameLocal.GetTime() > nextStateTime)
  93. {
  94. state = PHOTOSNAPPING;
  95. }
  96. }
  97. else if (state == PHOTOSNAPPING)
  98. {
  99. StartSound( "snd_camerasnap" , SND_CHANNEL_ANY, 0, false, NULL );
  100. light->On();
  101. nextStateTime = gameLocal.time + 90;
  102. state = PHOTOSNAPDONE;
  103. count++;
  104. this->renderEntity.gui[0]->SetStateInt("gui_parm1", count);
  105. }
  106. else if (state == PHOTOSNAPDONE)
  107. {
  108. if (gameLocal.time > nextStateTime)
  109. {
  110. light->Off();
  111. if (count >= maxcount)
  112. {
  113. state = PHOTODONE;
  114. gameLocal.GetLocalPlayer()->Event_hudMessage( common->GetLanguageDict()->GetString( "#str_02110" ) );
  115. this->frobcube->isFrobbable = true;
  116. return;
  117. }
  118. state = PHOTOFLIPPING;
  119. nextStateTime = Event_PlayAnim("pageturn", 4);
  120. }
  121. }
  122. else if (state == PHOTOFLIPPING)
  123. {
  124. if (nextStateTime < gameLocal.GetTime())
  125. {
  126. state = PHOTOSNAPPING;
  127. }
  128. }
  129. }
  130. void idContractCamera::Event_reset( void )
  131. {
  132. this->SetSkin(declManager->FindSkin("skins/doccam/nocam"));
  133. this->state = OFF;
  134. this->frobcube->isFrobbable = true;
  135. count = 0;
  136. this->renderEntity.gui[0]->SetStateInt("gui_parm1", count);
  137. this->renderEntity.gui[0]->SetStateInt("gui_parm2", maxcount);
  138. }
  139. void idContractCamera::Think( void )
  140. {
  141. UpdateStates();
  142. idAnimatedEntity::Think();
  143. idAnimatedEntity::Present();
  144. }