1999-12-25 05:22:39 +00:00
|
|
|
/*
|
2000-03-24 09:08:39 +00:00
|
|
|
cvar.c
|
1999-12-25 05:22:39 +00:00
|
|
|
|
2000-03-24 09:08:39 +00:00
|
|
|
dynamic variable tracking
|
1999-12-25 05:22:39 +00:00
|
|
|
|
2000-03-24 09:08:39 +00:00
|
|
|
Copyright (C) 1996-1997 Id Software, Inc.
|
|
|
|
Copyright (C) 1999,2000 Nelson Rush.
|
|
|
|
Copyright (C) 1999,2000 contributors of the QuakeForge project
|
|
|
|
Please see the file "AUTHORS" for a list of contributors
|
1999-12-25 05:22:39 +00:00
|
|
|
|
2000-03-24 09:08:39 +00:00
|
|
|
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.
|
1999-12-25 05:22:39 +00:00
|
|
|
|
2000-03-24 09:08:39 +00:00
|
|
|
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.
|
1999-12-25 05:22:39 +00:00
|
|
|
|
2000-03-24 09:08:39 +00:00
|
|
|
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:
|
|
|
|
|
|
|
|
Free Software Foundation, Inc.
|
|
|
|
59 Temple Place - Suite 330
|
|
|
|
Boston, MA 02111-1307, USA
|
|
|
|
|
|
|
|
$Id$
|
1999-12-25 05:22:39 +00:00
|
|
|
*/
|
|
|
|
|
2000-01-28 01:03:09 +00:00
|
|
|
#include <zone.h>
|
2000-01-28 03:19:57 +00:00
|
|
|
#include <qtypes.h>
|
|
|
|
#include <qstructs.h>
|
|
|
|
#include <lib_replace.h>
|
|
|
|
#include <console.h>
|
|
|
|
#include <cmd.h>
|
2000-04-27 04:33:30 +00:00
|
|
|
#include <cvar.h>
|
|
|
|
#include <cvars.h>
|
2000-01-28 03:19:57 +00:00
|
|
|
#include <client.h>
|
2000-02-17 16:18:55 +00:00
|
|
|
#include <stdlib.h>
|
2000-03-02 22:56:25 +00:00
|
|
|
#if defined(UQUAKE) || defined(SERVERONLY)
|
2000-01-28 03:19:57 +00:00
|
|
|
#include <server.h>
|
1999-12-25 05:22:39 +00:00
|
|
|
#endif
|
2000-01-28 01:03:09 +00:00
|
|
|
#include <string.h>
|
1999-12-25 05:22:39 +00:00
|
|
|
|
2000-02-20 21:19:50 +00:00
|
|
|
#if !defined(HAVE_SNPRINTF) && defined(HAVE__SNPRINTF)
|
|
|
|
# define snprintf _snprintf
|
|
|
|
#endif
|
|
|
|
|
1999-12-25 05:22:39 +00:00
|
|
|
cvar_t *cvar_vars;
|
|
|
|
char *cvar_null_string = "";
|
2000-04-27 04:33:30 +00:00
|
|
|
cvar_t *developer;
|
2000-05-06 22:46:48 +00:00
|
|
|
cvar_alias_t *calias_vars;
|
1999-12-25 05:22:39 +00:00
|
|
|
|
2000-06-22 12:23:54 +00:00
|
|
|
// 2000-06-22 General cvar display by Maddes start
|
|
|
|
/*
|
|
|
|
============
|
|
|
|
Cvar_Display
|
|
|
|
|
|
|
|
same cvar display for all cvar commands
|
|
|
|
============
|
|
|
|
*/
|
2000-08-17 17:18:01 +00:00
|
|
|
void
|
|
|
|
Cvar_Display ( cvar_t *var )
|
2000-06-22 12:23:54 +00:00
|
|
|
{
|
|
|
|
Con_Printf ("%c%c%c ",
|
|
|
|
(var->flags & CVAR_ARCHIVE) ? 'A' : ' ', // archived
|
|
|
|
(var->flags & CVAR_ROM) ? 'R' : ' ', // read-only
|
|
|
|
(var->flags & CVAR_USER_CREATED) ? 'U' : ' '); // user-created
|
|
|
|
|
|
|
|
Con_Printf ("\"%s\" is \"%s\"", var->name, var->string);
|
|
|
|
|
|
|
|
// 2000-06-22 Range check for cvars by Maddes start
|
|
|
|
if (var->rangecheck)
|
|
|
|
{
|
|
|
|
if (var->rangecheck == 3) // boolean
|
|
|
|
{
|
|
|
|
Con_Printf (" (bool: 0/1)");
|
|
|
|
}
|
|
|
|
else if (var->rangecheck == 2) // integer
|
|
|
|
{
|
2000-07-10 21:33:13 +00:00
|
|
|
Con_Printf (" (int: %i-%i)", (int)var->minvalue, (int)var->maxvalue);
|
2000-06-22 12:23:54 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
char val[32];
|
|
|
|
int i;
|
|
|
|
|
2000-07-10 21:33:13 +00:00
|
|
|
if (var->minvalue == (int)var->minvalue)
|
2000-06-22 12:23:54 +00:00
|
|
|
{
|
2000-07-10 21:33:13 +00:00
|
|
|
sprintf (val, "%i", (int)var->minvalue);
|
2000-06-22 12:23:54 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sprintf (val, "%1f", var->minvalue);
|
|
|
|
for (i=Q_strlen(val)-1 ; i>0 && val[i]=='0' && val[i-1]!='.' ; i--)
|
|
|
|
{
|
|
|
|
val[i] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Con_Printf (" (float: %s-", val);
|
|
|
|
|
|
|
|
if (var->maxvalue == (int)var->maxvalue)
|
|
|
|
{
|
2000-07-10 21:33:13 +00:00
|
|
|
sprintf (val, "%i", (int)var->maxvalue);
|
2000-06-22 12:23:54 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sprintf (val, "%1f", var->maxvalue);
|
|
|
|
for (i=Q_strlen(val)-1 ; i>0 && val[i]=='0' && val[i-1]!='.' ; i--)
|
|
|
|
{
|
|
|
|
val[i] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Con_Printf ("%s)", val);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// 2000-06-22 Range check for cvars by Maddes end
|
|
|
|
|
|
|
|
Con_Printf ("\n");
|
|
|
|
}
|
|
|
|
// 2000-06-22 General cvar display by Maddes end
|
|
|
|
|
1999-12-25 05:22:39 +00:00
|
|
|
/*
|
|
|
|
============
|
|
|
|
Cvar_FindVar
|
|
|
|
============
|
|
|
|
*/
|
2000-08-17 17:18:01 +00:00
|
|
|
cvar_t *
|
|
|
|
Cvar_FindVar ( char *var_name )
|
1999-12-25 05:22:39 +00:00
|
|
|
{
|
|
|
|
cvar_t *var;
|
2000-03-19 15:59:51 +00:00
|
|
|
|
1999-12-25 05:22:39 +00:00
|
|
|
for (var=cvar_vars ; var ; var=var->next)
|
|
|
|
if (!Q_strcmp (var_name, var->name))
|
|
|
|
return var;
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2000-08-17 17:18:01 +00:00
|
|
|
cvar_t *
|
|
|
|
Cvar_FindAlias ( char *alias_name )
|
2000-05-06 22:46:48 +00:00
|
|
|
{
|
|
|
|
cvar_alias_t *alias;
|
|
|
|
|
|
|
|
for (alias = calias_vars ; alias ; alias=alias->next)
|
|
|
|
if (!Q_strcmp (alias_name, alias->name))
|
|
|
|
return alias->cvar;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2000-08-17 17:18:01 +00:00
|
|
|
void
|
|
|
|
Cvar_Alias_Get ( char *name, cvar_t *cvar )
|
2000-05-06 22:46:48 +00:00
|
|
|
{
|
|
|
|
cvar_alias_t *alias;
|
|
|
|
cvar_t *var;
|
|
|
|
|
|
|
|
if (Cmd_Exists (name))
|
|
|
|
{
|
|
|
|
Con_Printf ("CAlias_Get: %s is a command\n", name);
|
2000-05-06 23:03:45 +00:00
|
|
|
return;
|
2000-05-06 22:46:48 +00:00
|
|
|
}
|
|
|
|
if (Cvar_FindVar(name))
|
|
|
|
{
|
|
|
|
Con_Printf ("CAlias_Get: tried to alias used cvar name %s\n",name);
|
2000-05-06 23:03:45 +00:00
|
|
|
return;
|
2000-05-06 22:46:48 +00:00
|
|
|
}
|
2000-08-17 17:18:01 +00:00
|
|
|
var = Cvar_FindAlias(name);
|
2000-05-06 22:46:48 +00:00
|
|
|
if (!var)
|
|
|
|
{
|
|
|
|
alias = (cvar_alias_t *) malloc(sizeof(cvar_alias_t));
|
|
|
|
alias->next = calias_vars;
|
|
|
|
calias_vars = alias;
|
2000-08-17 17:18:01 +00:00
|
|
|
alias->name = strdup(name);
|
2000-05-06 22:46:48 +00:00
|
|
|
alias->cvar = cvar;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-12-25 05:22:39 +00:00
|
|
|
/*
|
|
|
|
============
|
|
|
|
Cvar_VariableValue
|
|
|
|
============
|
|
|
|
*/
|
2000-08-17 17:18:01 +00:00
|
|
|
float
|
|
|
|
Cvar_VariableValue ( char *var_name )
|
1999-12-25 05:22:39 +00:00
|
|
|
{
|
|
|
|
cvar_t *var;
|
2000-03-19 15:59:51 +00:00
|
|
|
|
1999-12-25 05:22:39 +00:00
|
|
|
var = Cvar_FindVar (var_name);
|
2000-05-06 22:46:48 +00:00
|
|
|
if (!var)
|
|
|
|
var = Cvar_FindAlias(var_name);
|
1999-12-25 05:22:39 +00:00
|
|
|
if (!var)
|
|
|
|
return 0;
|
|
|
|
return Q_atof (var->string);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
============
|
|
|
|
Cvar_VariableString
|
|
|
|
============
|
|
|
|
*/
|
2000-08-17 17:18:01 +00:00
|
|
|
char *
|
|
|
|
Cvar_VariableString ( char *var_name )
|
1999-12-25 05:22:39 +00:00
|
|
|
{
|
|
|
|
cvar_t *var;
|
2000-03-19 15:59:51 +00:00
|
|
|
|
1999-12-25 05:22:39 +00:00
|
|
|
var = Cvar_FindVar (var_name);
|
2000-05-06 22:46:48 +00:00
|
|
|
if (!var)
|
|
|
|
var = Cvar_FindAlias(var_name);
|
1999-12-25 05:22:39 +00:00
|
|
|
if (!var)
|
|
|
|
return cvar_null_string;
|
|
|
|
return var->string;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
============
|
|
|
|
Cvar_CompleteVariable
|
|
|
|
============
|
|
|
|
*/
|
2000-08-17 17:18:01 +00:00
|
|
|
char *
|
|
|
|
Cvar_CompleteVariable ( char *partial )
|
1999-12-25 05:22:39 +00:00
|
|
|
{
|
|
|
|
cvar_t *cvar;
|
2000-05-06 22:46:48 +00:00
|
|
|
cvar_alias_t *alias;
|
|
|
|
int len;
|
2000-03-19 15:59:51 +00:00
|
|
|
|
1999-12-25 05:22:39 +00:00
|
|
|
len = Q_strlen(partial);
|
2000-03-19 15:59:51 +00:00
|
|
|
|
1999-12-25 05:22:39 +00:00
|
|
|
if (!len)
|
|
|
|
return NULL;
|
2000-03-19 15:59:51 +00:00
|
|
|
|
1999-12-25 05:22:39 +00:00
|
|
|
// check exact match
|
|
|
|
for (cvar=cvar_vars ; cvar ; cvar=cvar->next)
|
|
|
|
if (!strcmp (partial,cvar->name))
|
|
|
|
return cvar->name;
|
2000-08-17 17:18:01 +00:00
|
|
|
|
2000-05-06 22:46:48 +00:00
|
|
|
// check aliases too :)
|
|
|
|
for (alias=calias_vars ; alias ; alias=alias->next)
|
|
|
|
if (!strcmp (partial, alias->name))
|
|
|
|
return alias->name;
|
1999-12-25 05:22:39 +00:00
|
|
|
|
|
|
|
// check partial match
|
|
|
|
for (cvar=cvar_vars ; cvar ; cvar=cvar->next)
|
|
|
|
if (!Q_strncmp (partial,cvar->name, len))
|
|
|
|
return cvar->name;
|
|
|
|
|
2000-05-06 22:46:48 +00:00
|
|
|
// check aliases too :)
|
|
|
|
for (alias=calias_vars ; alias ; alias=alias->next)
|
|
|
|
if (!Q_strncmp (partial, alias->name, len))
|
|
|
|
return alias->name;
|
|
|
|
|
1999-12-25 05:22:39 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef SERVERONLY
|
|
|
|
void SV_SendServerInfoChange(char *key, char *value);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
============
|
|
|
|
Cvar_Set
|
|
|
|
============
|
|
|
|
*/
|
2000-01-28 01:03:09 +00:00
|
|
|
#if defined(QUAKEWORLD)
|
2000-08-17 17:18:01 +00:00
|
|
|
void
|
|
|
|
Cvar_Set ( cvar_t *var, char *value )
|
1999-12-25 05:22:39 +00:00
|
|
|
{
|
|
|
|
if (!var)
|
|
|
|
return;
|
2000-04-03 14:30:02 +00:00
|
|
|
|
2000-02-27 07:13:32 +00:00
|
|
|
if(var->flags&CVAR_ROM) return;
|
1999-12-25 05:22:39 +00:00
|
|
|
#ifdef SERVERONLY
|
2000-02-27 07:13:32 +00:00
|
|
|
if (var->flags&CVAR_SERVERINFO)
|
1999-12-25 05:22:39 +00:00
|
|
|
{
|
2000-04-03 14:30:02 +00:00
|
|
|
Info_SetValueForKey (svs.info, var->name, value, MAX_SERVERINFO_STRING);
|
|
|
|
SV_SendServerInfoChange(var->name, value);
|
1999-12-25 05:22:39 +00:00
|
|
|
// SV_BroadcastCommand ("fullserverinfo \"%s\"\n", svs.info);
|
|
|
|
}
|
|
|
|
#else
|
2000-02-27 07:13:32 +00:00
|
|
|
if (var->flags&CVAR_USERINFO)
|
1999-12-25 05:22:39 +00:00
|
|
|
{
|
2000-04-03 14:30:02 +00:00
|
|
|
Info_SetValueForKey (cls.userinfo, var->name, value, MAX_INFO_STRING);
|
1999-12-25 05:22:39 +00:00
|
|
|
if (cls.state >= ca_connected)
|
|
|
|
{
|
|
|
|
MSG_WriteByte (&cls.netchan.message, clc_stringcmd);
|
2000-04-03 14:30:02 +00:00
|
|
|
SZ_Print (&cls.netchan.message, va("setinfo \"%s\" \"%s\"\n", var->name, value));
|
1999-12-25 05:22:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2000-03-19 15:59:51 +00:00
|
|
|
|
1999-12-25 05:22:39 +00:00
|
|
|
Z_Free (var->string); // free the old value string
|
2000-03-19 15:59:51 +00:00
|
|
|
|
1999-12-25 05:22:39 +00:00
|
|
|
var->string = Z_Malloc (Q_strlen(value)+1);
|
|
|
|
Q_strcpy (var->string, value);
|
|
|
|
var->value = Q_atof (var->string);
|
|
|
|
}
|
2000-01-28 01:03:09 +00:00
|
|
|
#elif defined(UQUAKE)
|
2000-08-17 17:18:01 +00:00
|
|
|
void
|
|
|
|
Cvar_Set ( cvar_t *var, char *value )
|
2000-01-28 01:03:09 +00:00
|
|
|
{
|
|
|
|
qboolean changed;
|
2000-06-22 12:23:54 +00:00
|
|
|
// 2000-06-22 Range check for cvars by Maddes start
|
|
|
|
char val[32];
|
|
|
|
float newvalue;
|
|
|
|
int i;
|
|
|
|
// 2000-06-22 Range check for cvars by Maddes end
|
2000-03-19 15:59:51 +00:00
|
|
|
|
2000-01-28 01:03:09 +00:00
|
|
|
if (!var)
|
|
|
|
return;
|
|
|
|
|
2000-02-16 21:30:20 +00:00
|
|
|
// Don't change if this is a CVAR_ROM
|
2000-02-27 07:13:32 +00:00
|
|
|
if(var->flags&CVAR_ROM) return;
|
2000-03-19 15:59:51 +00:00
|
|
|
|
2000-06-22 12:23:54 +00:00
|
|
|
// 2000-06-22 Range check for cvars by Maddes start
|
|
|
|
if (var->rangecheck)
|
|
|
|
{
|
|
|
|
newvalue = Q_atof (value);
|
|
|
|
|
|
|
|
if (var->rangecheck == 3) // boolean
|
|
|
|
{
|
|
|
|
if (newvalue)
|
|
|
|
{
|
|
|
|
newvalue = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
newvalue = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (var->rangecheck == 2) // integer
|
|
|
|
{
|
|
|
|
newvalue = (int)newvalue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// check limits of newvalue
|
|
|
|
if (newvalue < var->minvalue)
|
|
|
|
{
|
|
|
|
newvalue = var->minvalue;
|
|
|
|
}
|
|
|
|
if (newvalue > var->maxvalue)
|
|
|
|
{
|
|
|
|
newvalue = var->maxvalue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (newvalue == (int)newvalue)
|
|
|
|
{
|
2000-07-10 21:33:13 +00:00
|
|
|
sprintf (val, "%i", (int)newvalue);
|
2000-06-22 12:23:54 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sprintf (val, "%1f", newvalue);
|
|
|
|
for (i=Q_strlen(val)-1 ; i>0 && val[i]=='0' && val[i-1]!='.' ; i--)
|
|
|
|
{
|
|
|
|
val[i] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
changed = Q_strcmp(var->string, val);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// 2000-06-22 Range check for cvars by Maddes end
|
|
|
|
changed = Q_strcmp(var->string, value);
|
|
|
|
} // 2000-06-22 Range check for cvars by Maddes
|
|
|
|
|
|
|
|
// 2000-06-22 Fix for unnecessary cvar changing/zone usage by Maddes start
|
|
|
|
if (!changed) // nothing changed, nothing to do
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// 2000-06-22 Fix for unnecessary cvar changing/zone usage by Maddes end
|
2000-03-19 15:59:51 +00:00
|
|
|
|
2000-01-28 01:03:09 +00:00
|
|
|
Z_Free (var->string); // free the old value string
|
2000-03-19 15:59:51 +00:00
|
|
|
|
2000-06-22 12:23:54 +00:00
|
|
|
// 2000-06-22 Range check for cvars by Maddes start
|
|
|
|
if (var->rangecheck)
|
|
|
|
{
|
|
|
|
var->string = Z_Malloc (Q_strlen(val)+1);
|
|
|
|
Q_strcpy (var->string, val);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// 2000-06-22 Range check for cvars by Maddes end
|
|
|
|
var->string = Z_Malloc (Q_strlen(value)+1);
|
|
|
|
Q_strcpy (var->string, value);
|
|
|
|
} // 2000-06-22 Range check for cvars by Maddes
|
2000-01-28 01:03:09 +00:00
|
|
|
var->value = Q_atof (var->string);
|
2000-02-27 07:13:32 +00:00
|
|
|
if (var->flags&CVAR_USERINFO && changed)
|
2000-01-28 01:03:09 +00:00
|
|
|
{
|
|
|
|
if (sv.active)
|
|
|
|
SV_BroadcastPrintf ("\"%s\" changed to \"%s\"\n", var->name, var->string);
|
|
|
|
}
|
2000-08-17 17:18:01 +00:00
|
|
|
|
|
|
|
// 1999-09-06 deathmatch/coop not at the same time fix by Maddes start
|
|
|
|
if ( (var == deathmatch) && (var->value != 0) )
|
|
|
|
{
|
|
|
|
Cvar_Set (coop, "0");
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( (var == coop) && (var->value != 0) )
|
|
|
|
{
|
|
|
|
Cvar_Set (deathmatch, "0");
|
|
|
|
}
|
|
|
|
// 1999-09-06 deathmatch/coop not at the same time fix by Maddes end
|
2000-01-28 01:03:09 +00:00
|
|
|
}
|
|
|
|
#endif
|
1999-12-25 05:22:39 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
============
|
|
|
|
Cvar_Command
|
|
|
|
|
|
|
|
Handles variable inspection and changing from the console
|
|
|
|
============
|
|
|
|
*/
|
2000-08-17 17:18:01 +00:00
|
|
|
qboolean
|
|
|
|
Cvar_Command ( void )
|
1999-12-25 05:22:39 +00:00
|
|
|
{
|
|
|
|
cvar_t *v;
|
|
|
|
|
|
|
|
// check variables
|
|
|
|
v = Cvar_FindVar (Cmd_Argv(0));
|
2000-05-06 22:46:48 +00:00
|
|
|
if (!v)
|
|
|
|
v = Cvar_FindAlias (Cmd_Argv(0));
|
1999-12-25 05:22:39 +00:00
|
|
|
if (!v)
|
|
|
|
return false;
|
2000-03-19 15:59:51 +00:00
|
|
|
|
1999-12-25 05:22:39 +00:00
|
|
|
// perform a variable print or set
|
|
|
|
if (Cmd_Argc() == 1)
|
|
|
|
{
|
2000-06-22 12:23:54 +00:00
|
|
|
Cvar_Display (v); // 2000-06-22 General cvar display by Maddes
|
1999-12-25 05:22:39 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2000-04-03 14:30:02 +00:00
|
|
|
Cvar_Set (v, Cmd_Argv(1));
|
1999-12-25 05:22:39 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
============
|
|
|
|
Cvar_WriteVariables
|
|
|
|
|
|
|
|
Writes lines containing "set variable value" for all variables
|
|
|
|
with the archive flag set to true.
|
|
|
|
============
|
|
|
|
*/
|
2000-08-17 17:18:01 +00:00
|
|
|
void
|
|
|
|
Cvar_WriteVariables ( QFile *f )
|
1999-12-25 05:22:39 +00:00
|
|
|
{
|
|
|
|
cvar_t *var;
|
2000-03-19 15:59:51 +00:00
|
|
|
|
1999-12-25 05:22:39 +00:00
|
|
|
for (var = cvar_vars ; var ; var = var->next)
|
2000-02-27 07:13:32 +00:00
|
|
|
if (var->flags&CVAR_ARCHIVE)
|
2000-02-08 05:06:58 +00:00
|
|
|
Qprintf (f, "%s \"%s\"\n", var->name, var->string);
|
1999-12-25 05:22:39 +00:00
|
|
|
}
|
|
|
|
|
2000-08-17 17:18:01 +00:00
|
|
|
void
|
|
|
|
Cvar_Set_f ( void )
|
2000-02-15 11:42:12 +00:00
|
|
|
{
|
|
|
|
cvar_t *var;
|
|
|
|
char *value;
|
|
|
|
char *var_name;
|
|
|
|
|
|
|
|
if (Cmd_Argc() != 3)
|
|
|
|
{
|
|
|
|
Con_Printf ("usage: set <cvar> <value>\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var_name = Cmd_Argv (1);
|
|
|
|
value = Cmd_Argv (2);
|
|
|
|
var = Cvar_FindVar (var_name);
|
2000-05-06 22:46:48 +00:00
|
|
|
if (!var)
|
|
|
|
var = Cvar_FindAlias (var_name);
|
2000-03-19 15:59:51 +00:00
|
|
|
if (var)
|
2000-02-15 11:42:12 +00:00
|
|
|
{
|
2000-04-03 14:30:02 +00:00
|
|
|
Cvar_Set (var, value);
|
2000-03-19 15:59:51 +00:00
|
|
|
}
|
|
|
|
else
|
2000-02-15 11:42:12 +00:00
|
|
|
{
|
2000-02-27 07:13:32 +00:00
|
|
|
var = Cvar_Get (var_name, value, CVAR_USER_CREATED|CVAR_HEAP,
|
|
|
|
"User created cvar");
|
2000-03-19 15:59:51 +00:00
|
|
|
}
|
2000-02-15 11:42:12 +00:00
|
|
|
}
|
2000-03-18 02:47:51 +00:00
|
|
|
|
2000-08-17 17:18:01 +00:00
|
|
|
void
|
|
|
|
Cvar_Toggle_f ( void )
|
2000-03-18 02:47:51 +00:00
|
|
|
{
|
|
|
|
cvar_t *var;
|
|
|
|
|
|
|
|
if (Cmd_Argc() != 2)
|
|
|
|
{
|
|
|
|
Con_Printf ("toggle <cvar> : toggle a cvar on/off\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var = Cvar_FindVar (Cmd_Argv(1));
|
2000-05-06 22:46:48 +00:00
|
|
|
if (!var)
|
|
|
|
var = Cvar_FindAlias(Cmd_Argv(1));
|
2000-03-18 02:47:51 +00:00
|
|
|
if (!var)
|
|
|
|
{
|
|
|
|
Con_Printf ("Unknown variable \"%s\"\n", Cmd_Argv(1));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2000-04-03 14:30:02 +00:00
|
|
|
Cvar_Set (var, var->value ? "0" : "1");
|
2000-03-18 02:47:51 +00:00
|
|
|
}
|
|
|
|
|
2000-08-17 17:18:01 +00:00
|
|
|
void
|
|
|
|
Cvar_Help_f ( void )
|
2000-03-02 22:56:25 +00:00
|
|
|
{
|
2000-05-06 22:46:48 +00:00
|
|
|
char *var_name;
|
2000-03-02 22:56:25 +00:00
|
|
|
cvar_t *var;
|
2000-02-15 11:42:12 +00:00
|
|
|
|
2000-03-02 22:56:25 +00:00
|
|
|
if (Cmd_Argc() != 2)
|
|
|
|
{
|
2000-03-19 15:59:51 +00:00
|
|
|
Con_Printf ("usage: help <cvar>\n");
|
2000-03-02 22:56:25 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2000-05-06 22:46:48 +00:00
|
|
|
var_name = Cmd_Argv (1);
|
|
|
|
var = Cvar_FindVar (var_name);
|
|
|
|
if (!var)
|
|
|
|
var = Cvar_FindAlias (var_name);
|
|
|
|
if (var)
|
2000-03-02 22:56:25 +00:00
|
|
|
{
|
2000-05-06 22:46:48 +00:00
|
|
|
Con_Printf ("%s\n",var->description);
|
2000-03-02 22:56:25 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
Con_Printf ("variable not found\n");
|
|
|
|
}
|
2000-03-07 22:28:25 +00:00
|
|
|
|
2000-08-17 17:18:01 +00:00
|
|
|
void
|
|
|
|
Cvar_CvarList_f ( void )
|
2000-03-07 22:28:25 +00:00
|
|
|
{
|
|
|
|
cvar_t *var;
|
2000-04-03 14:30:02 +00:00
|
|
|
int i;
|
2000-06-22 12:23:54 +00:00
|
|
|
// 2000-06-22 Partial selection for CvarList command by Maddes start
|
|
|
|
char *partial;
|
|
|
|
int len;
|
|
|
|
int count;
|
|
|
|
|
|
|
|
if (Cmd_Argc() > 1)
|
|
|
|
{
|
|
|
|
partial = Cmd_Argv (1);
|
|
|
|
len = Q_strlen(partial);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
partial = NULL;
|
|
|
|
len = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
count=0;
|
|
|
|
// 2000-06-22 Partial selection for CvarList command by Maddes end
|
2000-03-07 22:28:25 +00:00
|
|
|
|
2000-04-03 14:30:02 +00:00
|
|
|
for (var=cvar_vars, i=0 ; var ; var=var->next, i++)
|
2000-03-07 22:28:25 +00:00
|
|
|
{
|
2000-06-22 12:23:54 +00:00
|
|
|
// 2000-06-22 Partial selection for CvarList command by Maddes start
|
2000-07-10 21:33:13 +00:00
|
|
|
if (partial && Q_strncmp (partial, var->name, len))
|
2000-06-22 12:23:54 +00:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
count++;
|
|
|
|
// 2000-06-22 Partial selection for CvarList command by Maddes end
|
|
|
|
Cvar_Display (var); // 2000-06-22 General cvar display by Maddes
|
|
|
|
}
|
|
|
|
|
|
|
|
// 2000-06-22 Partial selection for CvarList command by Maddes start
|
|
|
|
Con_Printf ("------------\n");
|
|
|
|
if (partial)
|
|
|
|
{
|
2000-07-10 21:33:13 +00:00
|
|
|
Con_Printf ("%i beginning with \"%s\" out of ", count, partial);
|
2000-03-07 22:28:25 +00:00
|
|
|
}
|
2000-07-10 21:33:13 +00:00
|
|
|
Con_Printf ("%i variables\n", i);
|
2000-06-22 12:23:54 +00:00
|
|
|
// 2000-06-22 Partial selection for CvarList command by Maddes end
|
2000-03-07 22:28:25 +00:00
|
|
|
}
|
|
|
|
|
2000-08-17 17:18:01 +00:00
|
|
|
void
|
2000-08-20 13:33:48 +00:00
|
|
|
Cvar_Init ( void )
|
2000-02-15 11:42:12 +00:00
|
|
|
{
|
2000-04-27 04:33:30 +00:00
|
|
|
developer = Cvar_Get ("developer","0",0,"None");
|
|
|
|
|
2000-02-15 11:42:12 +00:00
|
|
|
Cmd_AddCommand ("set", Cvar_Set_f);
|
2000-03-18 02:47:51 +00:00
|
|
|
Cmd_AddCommand ("toggle", Cvar_Toggle_f);
|
2000-03-03 19:49:28 +00:00
|
|
|
Cmd_AddCommand ("help",Cvar_Help_f);
|
2000-03-07 22:28:25 +00:00
|
|
|
Cmd_AddCommand ("cvarlist",Cvar_CvarList_f);
|
2000-02-15 11:42:12 +00:00
|
|
|
}
|
2000-02-27 07:13:32 +00:00
|
|
|
|
2000-08-17 17:18:01 +00:00
|
|
|
void
|
|
|
|
Cvar_Shutdown ( void )
|
2000-02-27 07:13:32 +00:00
|
|
|
{
|
|
|
|
cvar_t *var,*next;
|
2000-05-06 22:46:48 +00:00
|
|
|
cvar_alias_t *alias,*nextalias;
|
2000-03-19 15:59:51 +00:00
|
|
|
|
2000-05-06 22:46:48 +00:00
|
|
|
// Free cvars
|
2000-02-27 07:13:32 +00:00
|
|
|
var = cvar_vars;
|
|
|
|
while(var)
|
|
|
|
{
|
|
|
|
next = var->next;
|
|
|
|
free(var->description);
|
2000-02-27 18:51:50 +00:00
|
|
|
Z_Free(var->string);
|
2000-02-27 07:13:32 +00:00
|
|
|
free(var->name);
|
|
|
|
free(var);
|
|
|
|
var = next;
|
|
|
|
}
|
2000-08-17 17:18:01 +00:00
|
|
|
// Free aliases
|
2000-05-06 22:46:48 +00:00
|
|
|
alias = calias_vars;
|
|
|
|
while(alias)
|
|
|
|
{
|
|
|
|
nextalias = alias->next;
|
|
|
|
free(alias->name);
|
|
|
|
free(alias);
|
|
|
|
alias = nextalias;
|
|
|
|
}
|
2000-03-19 15:59:51 +00:00
|
|
|
}
|
2000-02-27 07:13:32 +00:00
|
|
|
|
|
|
|
|
2000-08-17 17:18:01 +00:00
|
|
|
cvar_t *
|
|
|
|
Cvar_Get ( char *name, char *string, int cvarflags, char *description )
|
2000-02-27 07:13:32 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
cvar_t *v;
|
|
|
|
|
|
|
|
if (Cmd_Exists (name))
|
|
|
|
{
|
|
|
|
Con_Printf ("Cvar_Get: %s is a command\n",name);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
v = Cvar_FindVar(name);
|
2000-03-19 15:59:51 +00:00
|
|
|
if (!v)
|
2000-02-27 07:13:32 +00:00
|
|
|
{
|
|
|
|
v = (cvar_t *) malloc(sizeof(cvar_t));
|
|
|
|
// Cvar doesn't exist, so we create it
|
|
|
|
v->next = cvar_vars;
|
|
|
|
cvar_vars = v;
|
|
|
|
v->name = strdup(name);
|
2000-02-27 18:51:50 +00:00
|
|
|
v->string = Z_Malloc (Q_strlen(string)+1);
|
|
|
|
Q_strcpy (v->string, string);
|
2000-02-27 07:13:32 +00:00
|
|
|
v->flags = cvarflags;
|
|
|
|
v->description = strdup(description);
|
2000-06-22 12:23:54 +00:00
|
|
|
// 2000-06-22 Range check for cvars by Maddes start
|
|
|
|
v->rangecheck = 0;
|
|
|
|
v->minvalue = 0;
|
|
|
|
v->maxvalue = 0;
|
|
|
|
// 2000-06-22 Range check for cvars by Maddes end
|
2000-03-19 15:59:51 +00:00
|
|
|
v->value = Q_atof (v->string);
|
2000-02-27 07:13:32 +00:00
|
|
|
return v;
|
|
|
|
}
|
|
|
|
// Cvar does exist, so we update the flags and return.
|
2000-03-02 22:56:25 +00:00
|
|
|
v->flags ^= CVAR_USER_CREATED;
|
2000-05-01 22:53:16 +00:00
|
|
|
v->flags ^= CVAR_HEAP;
|
|
|
|
v->flags |= cvarflags;
|
|
|
|
if (!Q_strcmp (v->description,"User created cvar"))
|
2000-08-17 17:18:01 +00:00
|
|
|
{
|
2000-05-01 22:53:16 +00:00
|
|
|
// Set with the real description
|
|
|
|
free(v->description);
|
|
|
|
v->description = strdup (description);
|
|
|
|
}
|
2000-02-27 07:13:32 +00:00
|
|
|
return v;
|
|
|
|
}
|