]> icculus.org git repositories - icculus/iodoom3.git/blob - neo/game/WorldSpawn.cpp
Use the same OpenAL headers on all platforms.
[icculus/iodoom3.git] / neo / game / WorldSpawn.cpp
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 */
47 CLASS_DECLARATION( idEntity, idWorldspawn )
48         EVENT( EV_Remove,                               idWorldspawn::Event_Remove )
49         EVENT( EV_SafeRemove,                   idWorldspawn::Event_Remove )
50 END_CLASS
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 */
106 void idWorldspawn::Save( idRestoreGame *savefile ) {
107 }
108
109 /*
110 =================
111 idWorldspawn::Restore
112 =================
113 */
114 void idWorldspawn::Restore( idRestoreGame *savefile ) {
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 */
130 idWorldspawn::~idWorldspawn() {
131         if ( gameLocal.world == this ) {
132                 gameLocal.world = NULL;
133         }
134 }
135
136 /*
137 ================
138 idWorldspawn::Event_Remove
139 ================
140 */
141 void idWorldspawn::Event_Remove( void ) {
142         gameLocal.Error( "Tried to remove world" );
143 }