forked from TTimo/bspc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaas_cfg.c
More file actions
312 lines (282 loc) · 10.6 KB
/
Copy pathaas_cfg.c
File metadata and controls
312 lines (282 loc) · 10.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
/*
===========================================================================
Return to Castle Wolfenstein single player GPL Source Code
Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company.
This file is part of the Return to Castle Wolfenstein single player GPL Source Code (RTCW SP Source Code).
RTCW SP Source Code is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
RTCW SP Source Code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with RTCW SP Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the RTCW SP 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 RTCW SP Source Code. If not, please request a copy in writing from id Software at the address below.
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.
===========================================================================
*/
#include <float.h>
//===========================================================================
//
// Name: cfg.c
// Function:
// Programmer: Mr Elusive (MrElusive@demigod.demon.nl)
// Last update: 1997-12-04
// Tab Size: 3
//===========================================================================
#include "qbsp.h"
#include "botlib/aasfile.h"
#include "aas_store.h"
#include "aas_cfg.h"
#include "botlib/l_precomp.h"
#include "botlib/l_struct.h"
#include "botlib/l_libvar.h"
#include <stddef.h>
///////////////////////////////////
extern void LibVarSet( char *var_name, char *value );
///////////////////////////////////
//structure field offsets
#define BBOX_OFS( x ) (int)&( ( (aas_bbox_t *)0 )->x )
#define CFG_OFS( x ) (int)&( ( (cfg_t *)0 )->x )
//bounding box definition
fielddef_t bbox_fields[] =
{
{"presencetype", BBOX_OFS( presencetype ), FT_INT},
{"flags", BBOX_OFS( flags ), FT_INT},
{"mins", BBOX_OFS( mins ), FT_FLOAT | FT_ARRAY, 3},
{"maxs", BBOX_OFS( maxs ), FT_FLOAT | FT_ARRAY, 3},
{NULL, 0, 0, 0}
};
fielddef_t cfg_fields[] =
{
{"phys_gravitydirection", CFG_OFS( phys_gravitydirection ), FT_FLOAT | FT_ARRAY, 3},
{"phys_friction", CFG_OFS( phys_friction ), FT_FLOAT},
{"phys_stopspeed", CFG_OFS( phys_stopspeed ), FT_FLOAT},
{"phys_gravity", CFG_OFS( phys_gravity ), FT_FLOAT},
{"phys_waterfriction", CFG_OFS( phys_waterfriction ), FT_FLOAT},
{"phys_watergravity", CFG_OFS( phys_watergravity ), FT_FLOAT},
{"phys_maxvelocity", CFG_OFS( phys_maxvelocity ), FT_FLOAT},
{"phys_maxwalkvelocity", CFG_OFS( phys_maxwalkvelocity ), FT_FLOAT},
{"phys_maxcrouchvelocity", CFG_OFS( phys_maxcrouchvelocity ), FT_FLOAT},
{"phys_maxswimvelocity", CFG_OFS( phys_maxswimvelocity ), FT_FLOAT},
{"phys_walkaccelerate", CFG_OFS( phys_walkaccelerate ), FT_FLOAT},
{"phys_airaccelerate", CFG_OFS( phys_airaccelerate ), FT_FLOAT},
{"phys_swimaccelerate", CFG_OFS( phys_swimaccelerate ), FT_FLOAT},
{"phys_maxstep", CFG_OFS( phys_maxstep ), FT_FLOAT},
{"phys_maxsteepness", CFG_OFS( phys_maxsteepness ), FT_FLOAT},
{"phys_maxwaterjump", CFG_OFS( phys_maxwaterjump ), FT_FLOAT},
{"phys_maxbarrier", CFG_OFS( phys_maxbarrier ), FT_FLOAT},
{"phys_jumpvel", CFG_OFS( phys_jumpvel ), FT_FLOAT},
{"phys_falldelta5", CFG_OFS( phys_falldelta5 ), FT_FLOAT},
{"phys_falldelta10", CFG_OFS( phys_falldelta10 ), FT_FLOAT},
{"rs_waterjump", CFG_OFS( rs_waterjump ), FT_FLOAT},
{"rs_teleport", CFG_OFS( rs_teleport ), FT_FLOAT},
{"rs_barrierjump", CFG_OFS( rs_barrierjump ), FT_FLOAT},
{"rs_startcrouch", CFG_OFS( rs_startcrouch ), FT_FLOAT},
{"rs_startgrapple", CFG_OFS( rs_startgrapple ), FT_FLOAT},
{"rs_startwalkoffledge", CFG_OFS( rs_startwalkoffledge ), FT_FLOAT},
{"rs_startjump", CFG_OFS( rs_startjump ), FT_FLOAT},
{"rs_rocketjump", CFG_OFS( rs_rocketjump ), FT_FLOAT},
{"rs_bfgjump", CFG_OFS( rs_bfgjump ), FT_FLOAT},
{"rs_jumppad", CFG_OFS( rs_jumppad ), FT_FLOAT},
{"rs_aircontrolledjumppad", CFG_OFS( rs_aircontrolledjumppad ), FT_FLOAT},
{"rs_funcbob", CFG_OFS( rs_funcbob ), FT_FLOAT},
{"rs_startelevator", CFG_OFS( rs_startelevator ), FT_FLOAT},
{"rs_falldamage5", CFG_OFS( rs_falldamage5 ), FT_FLOAT},
{"rs_falldamage10", CFG_OFS( rs_falldamage10 ), FT_FLOAT},
{"rs_maxjumpfallheight", CFG_OFS( rs_maxjumpfallheight ), FT_FLOAT},
{"rs_allowladders", CFG_OFS( rs_allowladders ), FT_INT},
{NULL, 0, 0, 0}
};
structdef_t bbox_struct =
{
sizeof( aas_bbox_t ), bbox_fields
};
structdef_t cfg_struct =
{
sizeof( cfg_t ), cfg_fields
};
//global cfg
cfg_t cfg;
#if 0
//===========================================================================
// the default Q3A configuration
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
void DefaultCfg( void ) {
int i;
// default all float values to infinite
for ( i = 0; cfg_fields[i].name; i++ )
{
if ( ( cfg_fields[i].type & FT_TYPE ) == FT_FLOAT ) {
*( float * )( ( (char*)&cfg ) + cfg_fields[i].offset ) = FLT_MAX;
}
} //end for
//
cfg.numbboxes = 2;
//bbox 0
cfg.bboxes[0].presencetype = PRESENCE_NORMAL;
cfg.bboxes[0].flags = 0;
cfg.bboxes[0].mins[0] = -18;
cfg.bboxes[0].mins[1] = -18;
cfg.bboxes[0].mins[2] = -24;
cfg.bboxes[0].maxs[0] = 18;
cfg.bboxes[0].maxs[1] = 18;
cfg.bboxes[0].maxs[2] = 48;
//bbox 1
cfg.bboxes[1].presencetype = PRESENCE_CROUCH;
cfg.bboxes[1].flags = 1;
cfg.bboxes[1].mins[0] = -18;
cfg.bboxes[1].mins[1] = -18;
cfg.bboxes[1].mins[2] = -24;
cfg.bboxes[1].maxs[0] = 18;
cfg.bboxes[1].maxs[1] = 18;
cfg.bboxes[1].maxs[2] = 24;
//
cfg.allpresencetypes = PRESENCE_NORMAL | PRESENCE_CROUCH;
cfg.phys_gravitydirection[0] = 0;
cfg.phys_gravitydirection[1] = 0;
cfg.phys_gravitydirection[2] = -1;
cfg.phys_maxsteepness = 0.7;
// cfg.phys_maxbarrier = -999;//32; // RIDAH: this is calculated at run-time now, from the gravity and jump velocity settings
} //end of the function DefaultCfg
#else
//===========================================================================
// the default Q3A configuration
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
void DefaultCfg( void ) {
int i;
// default all float values to infinite
for ( i = 0; cfg_fields[i].name; i++ )
{
if ( ( cfg_fields[i].type & FT_TYPE ) == FT_FLOAT ) {
*( float * )( ( (char*)&cfg ) + cfg_fields[i].offset ) = FLT_MAX;
}
} //end for
//
cfg.numbboxes = 2;
//bbox 0
cfg.bboxes[0].presencetype = PRESENCE_NORMAL;
cfg.bboxes[0].flags = 0;
cfg.bboxes[0].mins[0] = -15;
cfg.bboxes[0].mins[1] = -15;
cfg.bboxes[0].mins[2] = -24;
cfg.bboxes[0].maxs[0] = 15;
cfg.bboxes[0].maxs[1] = 15;
cfg.bboxes[0].maxs[2] = 32;
//bbox 1
cfg.bboxes[1].presencetype = PRESENCE_CROUCH;
cfg.bboxes[1].flags = 1;
cfg.bboxes[1].mins[0] = -15;
cfg.bboxes[1].mins[1] = -15;
cfg.bboxes[1].mins[2] = -24;
cfg.bboxes[1].maxs[0] = 15;
cfg.bboxes[1].maxs[1] = 15;
cfg.bboxes[1].maxs[2] = 16;
//
cfg.allpresencetypes = PRESENCE_NORMAL | PRESENCE_CROUCH;
cfg.phys_gravitydirection[0] = 0;
cfg.phys_gravitydirection[1] = 0;
cfg.phys_gravitydirection[2] = -1;
cfg.phys_maxsteepness = 0.7;
// cfg.phys_maxbarrier = -999;//32; // RIDAH: this is calculated at run-time now, from the gravity and jump velocity settings
} //end of the function DefaultCfg
#endif
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
char * QDECL va( char *format, ... ) {
va_list argptr;
static char string[2][32000]; // in case va is called by nested functions
static int index = 0;
char *buf;
buf = string[index & 1];
index++;
va_start( argptr, format );
vsprintf( buf, format,argptr );
va_end( argptr );
return buf;
} //end of the function va
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
void SetCfgLibVars( void ) {
int i;
float value;
for ( i = 0; cfg_fields[i].name; i++ )
{
if ( ( cfg_fields[i].type & FT_TYPE ) == FT_FLOAT ) {
value = *( float * )( ( (char*)&cfg ) + cfg_fields[i].offset );
if ( value != FLT_MAX ) {
LibVarSet( cfg_fields[i].name, va( "%f", value ) );
} //end if
} //end if
} //end for
} //end of the function SetCfgLibVars
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
int LoadCfgFile( char *filename ) {
source_t *source;
token_t token;
int settingsdefined;
source = LoadSourceFile( filename );
if ( !source ) {
Log_Print( "couldn't open cfg file %s\n", filename );
return false;
} //end if
settingsdefined = false;
memset( &cfg, 0, sizeof( cfg_t ) );
while ( PC_ReadToken( source, &token ) )
{
if ( !stricmp( token.string, "bbox" ) ) {
if ( cfg.numbboxes >= AAS_MAX_BBOXES ) {
SourceError( source, "too many bounding box volumes defined" );
} //end if
if ( !ReadStructure( source, &bbox_struct, (char *) &cfg.bboxes[cfg.numbboxes] ) ) {
FreeSource( source );
return false;
} //end if
cfg.allpresencetypes |= cfg.bboxes[cfg.numbboxes].presencetype;
cfg.numbboxes++;
} //end if
else if ( !stricmp( token.string, "settings" ) ) {
if ( settingsdefined ) {
SourceWarning( source, "settings already defined\n" );
} //end if
settingsdefined = true;
if ( !ReadStructure( source, &cfg_struct, (char *) &cfg ) ) {
FreeSource( source );
return false;
} //end if
} //end else if
} //end while
if ( VectorLength( cfg.phys_gravitydirection ) < 0.9 || VectorLength( cfg.phys_gravitydirection ) > 1.1 ) {
SourceError( source, "invalid gravity direction specified" );
} //end if
if ( cfg.numbboxes <= 0 ) {
SourceError( source, "no bounding volumes specified" );
} //end if
FreeSource( source );
SetCfgLibVars();
Log_Print( "using cfg file %s\n", filename );
return true;
} //end of the function LoadCfgFile