DOOM-3-BFG

DOOM 3 BFG Edition
Log | Files | Refs

EndLevel.cpp (4657B)


      1 /*
      2 ===========================================================================
      3 
      4 Doom 3 BFG Edition GPL Source Code
      5 Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company. 
      6 
      7 This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").  
      8 
      9 Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify
     10 it under the terms of the GNU General Public License as published by
     11 the Free Software Foundation, either version 3 of the License, or
     12 (at your option) any later version.
     13 
     14 Doom 3 BFG Edition Source Code is distributed in the hope that it will be useful,
     15 but WITHOUT ANY WARRANTY; without even the implied warranty of
     16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     17 GNU General Public License for more details.
     18 
     19 You should have received a copy of the GNU General Public License
     20 along with Doom 3 BFG Edition Source Code.  If not, see <http://www.gnu.org/licenses/>.
     21 
     22 In addition, the Doom 3 BFG Edition 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 BFG Edition Source Code.  If not, please request a copy in writing from id Software at the address below.
     23 
     24 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.
     25 
     26 ===========================================================================
     27 */
     28 
     29 #include "../idlib/precompiled.h"
     30 #pragma hdrstop
     31 
     32 #include "Game_local.h"
     33 
     34 /*
     35 
     36   game_endlevel.cpp
     37 
     38   This entity is targeted to complete a level, and it also handles
     39   running the stats and moving the camera.
     40 
     41 */
     42 
     43 
     44 CLASS_DECLARATION( idEntity, idTarget_EndLevel )
     45 	EVENT( EV_Activate,		idTarget_EndLevel::Event_Trigger )
     46 END_CLASS
     47 
     48 /*
     49 ================
     50 idTarget_EndLevel::Spawn
     51 ================
     52 */
     53 void idTarget_EndLevel::Spawn( void ) {
     54 	idStr		guiName;
     55 
     56 	gui = NULL;
     57 	noGui = spawnArgs.GetBool("noGui");
     58 	if (!noGui) {
     59 		spawnArgs.GetString( "guiName", "guis/EndLevel.gui", guiName );
     60 
     61 		if (guiName.Length()) {
     62 			gui = idUserInterface::FindGui( guiName, true, false, true );
     63 		}
     64 	}
     65 
     66 	buttonsReleased = false;
     67 	readyToExit = false;
     68 
     69 	exitCommand = "";
     70 }
     71 
     72 /*
     73 ================
     74 idTarget_EndLevel::~idTarget_EndLevel()
     75 ================
     76 */
     77 idTarget_EndLevel::~idTarget_EndLevel() {
     78 	//FIXME: need to go to smart ptrs for gui allocs or the unique method 
     79 	//delete gui;
     80 }
     81 
     82 /*
     83 ================
     84 idTarget_EndLevel::Event_Trigger
     85 ================
     86 */
     87 void idTarget_EndLevel::Event_Trigger( idEntity *activator ) {
     88 	if ( gameLocal.endLevel ) {
     89 		return;
     90 	}
     91 	
     92 	// mark the endLevel, which will modify some game actions
     93 	// and pass control to us for drawing the stats and camera position
     94 	gameLocal.endLevel = this;
     95 
     96 	// grab the activating player view position
     97 	idPlayer *player = (idPlayer *)(activator);
     98 
     99 	initialViewOrg = player->GetEyePosition();
    100 	initialViewAngles = idVec3( player->viewAngles[0], player->viewAngles[1], player->viewAngles[2] );
    101 
    102 	// kill all the sounds
    103 	gameSoundWorld->StopAllSounds();
    104 
    105 	if ( noGui ) {
    106 		readyToExit = true;
    107 	}
    108 }
    109 
    110 /*
    111 ================
    112 idTarget_EndLevel::Draw
    113 ================
    114 */
    115 void idTarget_EndLevel::Draw() {
    116 
    117 	if (noGui) {
    118 		return;
    119 	}
    120 
    121 	renderView_t			renderView;
    122 
    123 	memset( &renderView, 0, sizeof( renderView ) );
    124 
    125 	renderView.width = SCREEN_WIDTH;
    126 	renderView.height = SCREEN_HEIGHT;
    127 	renderView.x = 0;
    128 	renderView.y = 0;
    129 
    130 	renderView.fov_x = 90;
    131 	renderView.fov_y = gameLocal.CalcFovY( renderView.fov_x );
    132 	renderView.time = gameLocal.time;
    133 
    134 #if 0
    135 	renderView.vieworg = initialViewOrg;
    136 	renderView.viewaxis = idAngles(initialViewAngles).toMat3();
    137 #else
    138 	renderView.vieworg = renderEntity.origin;
    139 	renderView.viewaxis = renderEntity.axis;
    140 #endif
    141 
    142 	gameRenderWorld->RenderScene( &renderView );
    143 
    144 	// draw the gui on top of the 3D view
    145 	gui->Redraw(gameLocal.time);
    146 }
    147 
    148 /*
    149 ================
    150 idTarget_EndLevel::PlayerCommand
    151 ================
    152 */
    153 void idTarget_EndLevel::PlayerCommand( int buttons ) {
    154 	if ( !( buttons & BUTTON_ATTACK ) ) {
    155 		buttonsReleased = true;
    156 		return;
    157 	}
    158 	if ( !buttonsReleased ) {
    159 		return;
    160 	}
    161 
    162 	// we will exit at the end of the next game frame
    163 	readyToExit = true;
    164 }
    165 
    166 /*
    167 ================
    168 idTarget_EndLevel::ExitCommand
    169 ================
    170 */
    171 const char *idTarget_EndLevel::ExitCommand() {
    172 	if ( !readyToExit ) {
    173 		return NULL;
    174 	}
    175 
    176 	idStr nextMap;
    177 
    178 	if (spawnArgs.GetString( "nextMap", "", nextMap )) {
    179 		sprintf( exitCommand, "map %s", nextMap.c_str() );
    180 	} else {
    181 		exitCommand = "";
    182 	}
    183 
    184 	return exitCommand;
    185 }