forked from slotzero/manquake
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cvar.c
329 lines (275 loc) · 8.05 KB
/
cvar.c
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
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
/*
Copyright (C) 1996-1997 Id Software, Inc.
This program 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 2
of the License, or (at your option) any later version.
This program 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 this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
// cvar.c -- dynamic variable tracking
#include "quakedef.h"
cvar_t *cvar_vars;
char *cvar_null_string = "";
/*
============
Cvar_FindVar
============
*/
cvar_t *Cvar_FindVar (char *var_name)
{
cvar_t *var;
for (var=cvar_vars ; var ; var=var->next)
if (!strcmp (var_name, var->name))
return var;
return NULL;
}
/*
============
Cvar_VariableValue
============
*/
float Cvar_VariableValue (char *var_name)
{
cvar_t *var;
var = Cvar_FindVar (var_name);
if (!var)
return 0;
return atof (var->string);
}
/*
============
Cvar_VariableString
============
*/
char *Cvar_VariableString (char *var_name)
{
cvar_t *var;
var = Cvar_FindVar (var_name);
if (!var)
return cvar_null_string;
return var->string;
}
/*
============
Cvar_CompleteVariable
============
*/
char *Cvar_CompleteVariable (char *partial)
{
cvar_t *cvar;
int len;
len = strlen(partial);
if (!len)
return NULL;
// check functions
for (cvar=cvar_vars ; cvar ; cvar=cvar->next)
if (!strncmp (partial,cvar->name, len))
return cvar->name;
return NULL;
}
/*
============
Cvar_Set
============
*/
void Cvar_Set (char *var_name, char *value)
{
cvar_t *var;
qboolean changed;
var = Cvar_FindVar (var_name);
if (!var)
{ // there is an error in C code if this happens
Con_Printf ("Cvar_Set: variable %s not found\n", var_name);
return;
}
changed = strcmp(var->string, value);
Z_Free (var->string); // free the old value string
var->string = Z_Malloc (strlen(value)+1);
strcpy (var->string, value);
var->value = atof (var->string);
if ((var->server == 1) && changed) // JPG - so that server = 2 will mute the variable
{
if (sv.active)
SV_BroadcastPrintf ("\"%s\" changed to \"%s\"\n", var->name, var->string);
}
// JPG 3.00 - rcon (64 doesn't mean anything special, but we need some extra space because NET_MAXMESSAGE == RCON_BUFF_SIZE)
if (rcon_active && (rcon_message.cursize < rcon_message.maxsize - strlen(var->name) - strlen(var->string) - 64))
{
rcon_message.cursize--;
MSG_WriteString(&rcon_message, va("\"%s\" set to \"%s\"\n", var->name, var->string));
}
}
/*
============
Cvar_SetValue
============
*/
void Cvar_SetValue (char *var_name, float value)
{
char val[32];
dpsnprintf (val, sizeof(val), "%f",value);
Cvar_Set (var_name, val);
}
/*
============
Cvar_RegisterVariable
Adds a freestanding variable to the variable list.
============
*/
void Cvar_RegisterVariable (cvar_t *variable)
{
char *oldstr;
// first check to see if it has allready been defined
if (Cvar_FindVar (variable->name))
{
Con_Printf ("Can't register variable %s, already defined\n", variable->name); // JPG 3.02 allready->already
return;
}
// check for overlap with a command
if (Cmd_Exists (variable->name))
{
Con_Printf ("Cvar_RegisterVariable: %s is a command\n", variable->name);
return;
}
// copy the value off, because future sets will Z_Free it
oldstr = variable->string;
variable->string = Z_Malloc (strlen(variable->string)+1);
strcpy (variable->string, oldstr);
variable->value = atof (variable->string);
// link the variable in
variable->next = cvar_vars;
cvar_vars = variable;
}
/*
============
Cvar_Command
Handles variable inspection and changing from the console
============
*/
qboolean Cvar_Command (void)
{
cvar_t *v;
// check variables
v = Cvar_FindVar (Cmd_Argv(0));
if (!v)
return false;
// perform a variable print or set
if (Cmd_Argc() == 1)
{
Con_Printf ("\"%s\" is \"%s\"\n", v->name, v->string);
return true;
}
Cvar_Set (v->name, Cmd_Argv(1));
return true;
}
/*
============
Cvar_WriteVariables
Writes lines containing "set variable value" for all variables
with the archive flag set to true.
============
*/
void Cvar_WriteVariables (FILE *f)
{
cvar_t *var;
for (var = cvar_vars ; var ; var = var->next)
if (var->archive)
fprintf (f, "%s \"%s\"\n", var->name, var->string);
}
//============================================================================
cvar_t lcd_x = {"lcd_x","0"};
cvar_t lcd_yaw = {"lcd_yaw","0"};
cvar_t v_centermove = {"v_centermove", "0.15", false};
cvar_t v_centerspeed = {"v_centerspeed","500"};
cvar_t v_iyaw_cycle = {"v_iyaw_cycle", "2", false};
cvar_t v_iroll_cycle = {"v_iroll_cycle", "0.5", false};
cvar_t v_ipitch_cycle = {"v_ipitch_cycle", "1", false};
cvar_t v_iyaw_level = {"v_iyaw_level", "0.3", false};
cvar_t v_iroll_level = {"v_iroll_level", "0.1", false};
cvar_t v_ipitch_level = {"v_ipitch_level", "0.3", false};
cvar_t v_idlescale = {"v_idlescale", "0", false};
cvar_t crosshair = {"crosshair", "0", true};
cvar_t cl_crossx = {"cl_crossx", "0", false};
cvar_t cl_crossy = {"cl_crossy", "0", false};
cvar_t gl_cshiftpercent = {"gl_cshiftpercent", "100", false};
cvar_t scr_ofsx = {"scr_ofsx","0", false};
cvar_t scr_ofsy = {"scr_ofsy","0", false};
cvar_t scr_ofsz = {"scr_ofsz","0", false};
cvar_t cl_rollspeed = {"cl_rollspeed", "200"};
cvar_t cl_rollangle = {"cl_rollangle", "2.0"};
cvar_t cl_bob = {"cl_bob","0.02", false};
cvar_t cl_bobcycle = {"cl_bobcycle","0.6", false};
cvar_t cl_bobup = {"cl_bobup","0.5", false};
cvar_t v_kicktime = {"v_kicktime", "0.5", false};
cvar_t v_kickroll = {"v_kickroll", "0.6", false};
cvar_t v_kickpitch = {"v_kickpitch", "0.6", false};
cvar_t v_gamma = {"gamma", "1", true};
cvar_t pq_waterblend = {"pq_waterblend", "1"};
cvar_t pq_quadblend = {"pq_quadblend", "1"};
cvar_t pq_ringblend = {"pq_ringblend", "1"};
cvar_t pq_pentblend = {"pq_pentblend", "1"};
cvar_t pq_suitblend = {"pq_suitblend", "1"};
cvar_t r_polyblend = {"r_polyblend", "1"};
cvar_t con_notifytime = {"con_notifytime","3"};
cvar_t cl_name = {"cl_name", "player", true};
cvar_t cl_color = {"_cl_color", "0", true};
cvar_t pq_confilter = {"pq_confilter", "0"};
cvar_t pq_timestamp = {"pq_timestamp", "0"};
cvar_t pq_removecr = {"pq_removecr", "1"};
/*
=============
Cvar_Init
These aren't actually used for anything but I left them
intact because some mods might use them.
=============
*/
void Cvar_Init (void)
{
// from view.c
Cvar_RegisterVariable (&lcd_x);
Cvar_RegisterVariable (&lcd_yaw);
Cvar_RegisterVariable (&v_centermove);
Cvar_RegisterVariable (&v_centerspeed);
Cvar_RegisterVariable (&v_iyaw_cycle);
Cvar_RegisterVariable (&v_iroll_cycle);
Cvar_RegisterVariable (&v_ipitch_cycle);
Cvar_RegisterVariable (&v_iyaw_level);
Cvar_RegisterVariable (&v_iroll_level);
Cvar_RegisterVariable (&v_ipitch_level);
Cvar_RegisterVariable (&v_idlescale);
Cvar_RegisterVariable (&crosshair);
Cvar_RegisterVariable (&cl_crossx);
Cvar_RegisterVariable (&cl_crossy);
Cvar_RegisterVariable (&gl_cshiftpercent);
Cvar_RegisterVariable (&scr_ofsx);
Cvar_RegisterVariable (&scr_ofsy);
Cvar_RegisterVariable (&scr_ofsz);
Cvar_RegisterVariable (&cl_rollspeed);
Cvar_RegisterVariable (&cl_rollangle);
Cvar_RegisterVariable (&cl_bob);
Cvar_RegisterVariable (&cl_bobcycle);
Cvar_RegisterVariable (&cl_bobup);
Cvar_RegisterVariable (&v_kicktime);
Cvar_RegisterVariable (&v_kickroll);
Cvar_RegisterVariable (&v_kickpitch);
Cvar_RegisterVariable (&v_gamma);
Cvar_RegisterVariable (&pq_waterblend);
Cvar_RegisterVariable (&pq_quadblend);
Cvar_RegisterVariable (&pq_pentblend);
Cvar_RegisterVariable (&pq_ringblend);
Cvar_RegisterVariable (&pq_suitblend);
Cvar_RegisterVariable (&r_polyblend);
// from console.c
Cvar_RegisterVariable (&con_notifytime);
Cvar_RegisterVariable (&pq_confilter);
Cvar_RegisterVariable (&pq_timestamp);
Cvar_RegisterVariable (&pq_removecr);
// for chat messages
Cvar_RegisterVariable (&cl_name);
}