2 ===========================================================================
5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
7 This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
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.
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.
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/>.
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.
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.
26 ===========================================================================
31 Worldspawn class. Each map has one worldspawn which handles global spawnargs.
35 #include "../idlib/precompiled.h"
38 #include "Game_local.h"
44 Every map should have exactly one worldspawn.
47 CLASS_DECLARATION( idEntity, idWorldspawn )
48 EVENT( EV_Remove, idWorldspawn::Event_Remove )
49 EVENT( EV_SafeRemove, idWorldspawn::Event_Remove )
57 void idWorldspawn::Spawn( void ) {
60 const function_t *func;
63 assert( gameLocal.world == NULL );
64 gameLocal.world = this;
66 g_gravity.SetFloat( spawnArgs.GetFloat( "gravity", va( "%f", DEFAULT_GRAVITY ) ) );
68 // disable stamina on hell levels
69 if ( spawnArgs.GetBool( "no_stamina" ) ) {
70 pm_stamina.SetFloat( 0.0f );
74 scriptname = gameLocal.GetMapName();
75 scriptname.SetFileExtension( ".script" );
76 if ( fileSystem->ReadFile( scriptname, NULL, NULL ) > 0 ) {
77 gameLocal.program.CompileFile( scriptname );
79 // call the main function by default
80 func = gameLocal.program.FindFunction( "main" );
82 thread = new idThread( func );
83 thread->DelayedStart( 0 );
87 // call any functions specified in worldspawn
88 kv = spawnArgs.MatchPrefix( "call" );
90 func = gameLocal.program.FindFunction( kv->GetValue() );
92 gameLocal.Error( "Function '%s' not found in script for '%s' key on worldspawn", kv->GetValue().c_str(), kv->GetKey().c_str() );
95 thread = new idThread( func );
96 thread->DelayedStart( 0 );
97 kv = spawnArgs.MatchPrefix( "call", kv );
106 void idWorldspawn::Save( idRestoreGame *savefile ) {
111 idWorldspawn::Restore
114 void idWorldspawn::Restore( idRestoreGame *savefile ) {
115 assert( gameLocal.world == this );
117 g_gravity.SetFloat( spawnArgs.GetFloat( "gravity", va( "%f", DEFAULT_GRAVITY ) ) );
119 // disable stamina on hell levels
120 if ( spawnArgs.GetBool( "no_stamina" ) ) {
121 pm_stamina.SetFloat( 0.0f );
127 idWorldspawn::~idWorldspawn
130 idWorldspawn::~idWorldspawn() {
131 if ( gameLocal.world == this ) {
132 gameLocal.world = NULL;
138 idWorldspawn::Event_Remove
141 void idWorldspawn::Event_Remove( void ) {
142 gameLocal.Error( "Tried to remove world" );