doom3-gpl
Doom 3 GPL source release
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
WorldSpawn.cpp
Go to the documentation of this file.
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 game_worldspawn.cpp
30 
31 Worldspawn class. Each map has one worldspawn which handles global spawnargs.
32 
33 */
34 
35 #include "../idlib/precompiled.h"
36 #pragma hdrstop
37 
38 #include "Game_local.h"
39 
40 /*
41 ================
42 idWorldspawn
43 
44 Every map should have exactly one worldspawn.
45 ================
46 */
48  EVENT( EV_Remove, idWorldspawn::Event_Remove )
49  EVENT( EV_SafeRemove, idWorldspawn::Event_Remove )
51 
52 /*
53 ================
54 idWorldspawn::Spawn
55 ================
56 */
57 void idWorldspawn::Spawn( void ) {
58  idStr scriptname;
59  idThread *thread;
60  const function_t *func;
61  const idKeyValue *kv;
62 
63  assert( gameLocal.world == NULL );
64  gameLocal.world = this;
65 
66  g_gravity.SetFloat( spawnArgs.GetFloat( "gravity", va( "%f", DEFAULT_GRAVITY ) ) );
67 
68  // disable stamina on hell levels
69  if ( spawnArgs.GetBool( "no_stamina" ) ) {
70  pm_stamina.SetFloat( 0.0f );
71  }
72 
73  // load script
74  scriptname = gameLocal.GetMapName();
75  scriptname.SetFileExtension( ".script" );
76  if ( fileSystem->ReadFile( scriptname, NULL, NULL ) > 0 ) {
77  gameLocal.program.CompileFile( scriptname );
78 
79  // call the main function by default
80  func = gameLocal.program.FindFunction( "main" );
81  if ( func != NULL ) {
82  thread = new idThread( func );
83  thread->DelayedStart( 0 );
84  }
85  }
86 
87  // call any functions specified in worldspawn
88  kv = spawnArgs.MatchPrefix( "call" );
89  while( kv != NULL ) {
90  func = gameLocal.program.FindFunction( kv->GetValue() );
91  if ( func == NULL ) {
92  gameLocal.Error( "Function '%s' not found in script for '%s' key on worldspawn", kv->GetValue().c_str(), kv->GetKey().c_str() );
93  }
94 
95  thread = new idThread( func );
96  thread->DelayedStart( 0 );
97  kv = spawnArgs.MatchPrefix( "call", kv );
98  }
99 }
100 
101 /*
102 =================
103 idWorldspawn::Save
104 =================
105 */
107 }
108 
109 /*
110 =================
111 idWorldspawn::Restore
112 =================
113 */
115  assert( gameLocal.world == this );
116 
117  g_gravity.SetFloat( spawnArgs.GetFloat( "gravity", va( "%f", DEFAULT_GRAVITY ) ) );
118 
119  // disable stamina on hell levels
120  if ( spawnArgs.GetBool( "no_stamina" ) ) {
121  pm_stamina.SetFloat( 0.0f );
122  }
123 }
124 
125 /*
126 ================
127 idWorldspawn::~idWorldspawn
128 ================
129 */
131  if ( gameLocal.world == this ) {
132  gameLocal.world = NULL;
133  }
134 }
135 
136 /*
137 ================
138 idWorldspawn::Event_Remove
139 ================
140 */
142  gameLocal.Error( "Tried to remove world" );
143 }
float GetFloat(const char *key, const char *defaultString="0") const
Definition: Dict.h:248
idStr & SetFileExtension(const char *extension)
Definition: Str.cpp:743
assert(prefInfo.fullscreenBtn)
void DelayedStart(int delay)
void Save(idRestoreGame *savefile)
Definition: WorldSpawn.cpp:106
const idStr & GetKey(void) const
Definition: Dict.h:52
virtual int ReadFile(const char *relativePath, void **buffer, ID_TIME_T *timestamp=NULL)=0
void void void void void Error(const char *fmt,...) const id_attribute((format(printf
Definition: Game_local.cpp:783
idFileSystem * fileSystem
Definition: FileSystem.cpp:500
void CompileFile(const char *filename)
const idEventDef EV_SafeRemove("remove", NULL)
idDict spawnArgs
Definition: Entity.h:122
#define EVENT(event, function)
Definition: Class.h:53
const char * GetMapName(void) const
idProgram program
Definition: Game_local.h:293
idWorldspawn * world
Definition: Game_local.h:280
idCVar g_gravity("g_gravity", DEFAULT_GRAVITY_STRING, CVAR_GAME|CVAR_FLOAT,"")
bool GetBool(const char *key, const char *defaultString="0") const
Definition: Dict.h:256
#define NULL
Definition: Lib.h:88
const idStr & GetValue(void) const
Definition: Dict.h:53
idGameLocal gameLocal
Definition: Game_local.cpp:64
#define END_CLASS
Definition: Class.h:54
const float DEFAULT_GRAVITY
Definition: Game_local.h:744
tuple f
Definition: idal.py:89
#define CLASS_DECLARATION(nameofsuperclass, nameofclass)
Definition: Class.h:110
Definition: Str.h:116
const char * c_str(void) const
Definition: Str.h:487
void Restore(idRestoreGame *savefile)
Definition: WorldSpawn.cpp:114
const idEventDef EV_Remove("<immediateremove>", NULL)
function_t * FindFunction(const char *name) const
char * va(const char *fmt,...)
Definition: Str.cpp:1568
void SetFloat(const float value)
Definition: CVarSystem.h:149
void Event_Remove(void)
Definition: WorldSpawn.cpp:141
idCVar pm_stamina("pm_stamina","24", CVAR_GAME|CVAR_NETWORKSYNC|CVAR_FLOAT,"length of time player can run")