EndLevel.cpp 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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. #include "../idlib/precompiled.h"
  21. #pragma hdrstop
  22. #include "Game_local.h"
  23. /*
  24. game_endlevel.cpp
  25. This entity is targeted to complete a level, and it also handles
  26. running the stats and moving the camera.
  27. */
  28. CLASS_DECLARATION( idEntity, idTarget_EndLevel )
  29. EVENT( EV_Activate, idTarget_EndLevel::Event_Trigger )
  30. END_CLASS
  31. /*
  32. ================
  33. idTarget_EndLevel::Spawn
  34. ================
  35. */
  36. void idTarget_EndLevel::Spawn( void ) {
  37. idStr guiName;
  38. gui = NULL;
  39. noGui = spawnArgs.GetBool("noGui");
  40. if (!noGui) {
  41. spawnArgs.GetString( "guiName", "guis/EndLevel.gui", guiName );
  42. if (guiName.Length()) {
  43. gui = idUserInterface::FindGui( guiName, true, false, true );
  44. }
  45. }
  46. buttonsReleased = false;
  47. readyToExit = false;
  48. exitCommand = "";
  49. }
  50. /*
  51. ================
  52. idTarget_EndLevel::~idTarget_EndLevel()
  53. ================
  54. */
  55. idTarget_EndLevel::~idTarget_EndLevel() {
  56. //FIXME: need to go to smart ptrs for gui allocs or the unique method
  57. //delete gui;
  58. }
  59. /*
  60. ================
  61. idTarget_EndLevel::Event_Trigger
  62. ================
  63. */
  64. void idTarget_EndLevel::Event_Trigger( idEntity *activator ) {
  65. if ( gameLocal.endLevel ) {
  66. return;
  67. }
  68. // mark the endLevel, which will modify some game actions
  69. // and pass control to us for drawing the stats and camera position
  70. gameLocal.endLevel = this;
  71. // grab the activating player view position
  72. idPlayer *player = (idPlayer *)(activator);
  73. initialViewOrg = player->GetEyePosition();
  74. initialViewAngles = idVec3( player->viewAngles[0], player->viewAngles[1], player->viewAngles[2] );
  75. // kill all the sounds
  76. gameSoundWorld->StopAllSounds();
  77. if ( noGui ) {
  78. readyToExit = true;
  79. }
  80. }
  81. /*
  82. ================
  83. idTarget_EndLevel::Draw
  84. ================
  85. */
  86. void idTarget_EndLevel::Draw() {
  87. if (noGui) {
  88. return;
  89. }
  90. renderView_t renderView;
  91. memset( &renderView, 0, sizeof( renderView ) );
  92. renderView.width = SCREEN_WIDTH;
  93. renderView.height = SCREEN_HEIGHT;
  94. renderView.x = 0;
  95. renderView.y = 0;
  96. renderView.fov_x = 90;
  97. renderView.fov_y = gameLocal.CalcFovY( renderView.fov_x );
  98. renderView.time = gameLocal.time;
  99. #if 0
  100. renderView.vieworg = initialViewOrg;
  101. renderView.viewaxis = idAngles(initialViewAngles).toMat3();
  102. #else
  103. renderView.vieworg = renderEntity.origin;
  104. renderView.viewaxis = renderEntity.axis;
  105. #endif
  106. gameRenderWorld->RenderScene( &renderView );
  107. // draw the gui on top of the 3D view
  108. gui->Redraw(gameLocal.time);
  109. }
  110. /*
  111. ================
  112. idTarget_EndLevel::PlayerCommand
  113. ================
  114. */
  115. void idTarget_EndLevel::PlayerCommand( int buttons ) {
  116. if ( !( buttons & BUTTON_ATTACK ) ) {
  117. buttonsReleased = true;
  118. return;
  119. }
  120. if ( !buttonsReleased ) {
  121. return;
  122. }
  123. // we will exit at the end of the next game frame
  124. readyToExit = true;
  125. }
  126. /*
  127. ================
  128. idTarget_EndLevel::ExitCommand
  129. ================
  130. */
  131. const char *idTarget_EndLevel::ExitCommand() {
  132. if ( !readyToExit ) {
  133. return NULL;
  134. }
  135. idStr nextMap;
  136. if (spawnArgs.GetString( "nextMap", "", nextMap )) {
  137. sprintf( exitCommand, "map %s", nextMap.c_str() );
  138. } else {
  139. exitCommand = "";
  140. }
  141. return exitCommand;
  142. }