1 /*
2 ===========================================================================
3
4 Doom 3 GPL Source Code
5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
6
7 This file is part of the Doom 3 GPL Source Code ("Doom 3 Source Code").
8
9 Doom 3 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 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 Source Code. If not, see <http://www.gnu.org/licenses/>.
21
22 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.
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 "sys/platform.h"
30
31 #include "EndLevel.h"
32
33 /*
34
35 game_endlevel.cpp
36
37 This entity is targeted to complete a level, and it also handles
38 running the stats and moving the camera.
39
40 */
41
42
CLASS_DECLARATION(idEntity,idTarget_EndLevel)43 CLASS_DECLARATION( idEntity, idTarget_EndLevel )
44 EVENT( EV_Activate, idTarget_EndLevel::Event_Trigger )
45 END_CLASS
46
47 /*
48 ================
49 idTarget_EndLevel::Spawn
50 ================
51 */
52 void idTarget_EndLevel::Spawn( void ) {
53 idStr guiName;
54
55 gui = NULL;
56 noGui = spawnArgs.GetBool("noGui");
57 if (!noGui) {
58 spawnArgs.GetString( "guiName", "guis/EndLevel.gui", guiName );
59
60 if (guiName.Length()) {
61 gui = idUserInterface::FindGui( guiName, true, false, true );
62 }
63 }
64
65 buttonsReleased = false;
66 readyToExit = false;
67
68 exitCommand = "";
69 }
70
71 /*
72 ================
73 idTarget_EndLevel::~idTarget_EndLevel()
74 ================
75 */
~idTarget_EndLevel()76 idTarget_EndLevel::~idTarget_EndLevel() {
77 //FIXME: need to go to smart ptrs for gui allocs or the unique method
78 //delete gui;
79 }
80
81 /*
82 ================
83 idTarget_EndLevel::Event_Trigger
84 ================
85 */
Event_Trigger(idEntity * activator)86 void idTarget_EndLevel::Event_Trigger( idEntity *activator ) {
87 if ( gameLocal.endLevel ) {
88 return;
89 }
90
91 // mark the endLevel, which will modify some game actions
92 // and pass control to us for drawing the stats and camera position
93 gameLocal.endLevel = this;
94
95 // grab the activating player view position
96 idPlayer *player = (idPlayer *)(activator);
97
98 initialViewOrg = player->GetEyePosition();
99 initialViewAngles = idVec3( player->viewAngles[0], player->viewAngles[1], player->viewAngles[2] );
100
101 // kill all the sounds
102 gameSoundWorld->StopAllSounds();
103
104 if ( noGui ) {
105 readyToExit = true;
106 }
107 }
108
109 /*
110 ================
111 idTarget_EndLevel::Draw
112 ================
113 */
Draw()114 void idTarget_EndLevel::Draw() {
115
116 if (noGui) {
117 return;
118 }
119
120 renderView_t renderView;
121
122 memset( &renderView, 0, sizeof( renderView ) );
123
124 renderView.width = SCREEN_WIDTH;
125 renderView.height = SCREEN_HEIGHT;
126 renderView.x = 0;
127 renderView.y = 0;
128
129 renderView.fov_x = 90;
130 renderView.fov_y = gameLocal.CalcFovY( renderView.fov_x );
131 renderView.time = gameLocal.time;
132
133 #if 0
134 renderView.vieworg = initialViewOrg;
135 renderView.viewaxis = idAngles(initialViewAngles).toMat3();
136 #else
137 renderView.vieworg = renderEntity.origin;
138 renderView.viewaxis = renderEntity.axis;
139 #endif
140
141 gameRenderWorld->RenderScene( &renderView );
142
143 // draw the gui on top of the 3D view
144 gui->Redraw(gameLocal.time);
145 }
146
147 /*
148 ================
149 idTarget_EndLevel::PlayerCommand
150 ================
151 */
PlayerCommand(int buttons)152 void idTarget_EndLevel::PlayerCommand( int buttons ) {
153 if ( !( buttons & BUTTON_ATTACK ) ) {
154 buttonsReleased = true;
155 return;
156 }
157 if ( !buttonsReleased ) {
158 return;
159 }
160
161 // we will exit at the end of the next game frame
162 readyToExit = true;
163 }
164
165 /*
166 ================
167 idTarget_EndLevel::ExitCommand
168 ================
169 */
ExitCommand()170 const char *idTarget_EndLevel::ExitCommand() {
171 if ( !readyToExit ) {
172 return NULL;
173 }
174
175 idStr nextMap;
176
177 if (spawnArgs.GetString( "nextMap", "", nextMap )) {
178 sprintf( exitCommand, "map %s", nextMap.c_str() );
179 } else {
180 exitCommand = "";
181 }
182
183 return exitCommand;
184 }
185