return var->string;
}
+/*
+============
+Cvar_VariableDefString
+============
+*/
+const char *Cvar_VariableDefString (const char *var_name)
+{
+ cvar_t *var;
+
+ var = Cvar_FindVar (var_name);
+ if (!var)
+ return cvar_null_string;
+ return var->defstring;
+}
+
/*
============
}
if (developer.integer)
- Con_Printf("Cvar_SetQuick({\"%s\", \"%s\", %i}, \"%s\");\n", var->name, var->string, var->flags, value);
+ Con_Printf("Cvar_SetQuick({\"%s\", \"%s\", %i, \"%s\"}, \"%s\");\n", var->name, var->string, var->flags, var->defstring, value);
Cvar_SetQuick_Internal(var, value);
}
*/
void Cvar_RegisterVariable (cvar_t *variable)
{
- cvar_t *cvar, *cvar2;
+ cvar_t *current, *next, *cvar;
char *oldstr;
if (developer.integer)
variable->flags |= (cvar->flags & ~CVAR_ALLOCATED);
// cvar->string is now owned by variable instead
variable->string = cvar->string;
+ variable->defstring = cvar->defstring;
variable->value = atof (variable->string);
variable->integer = (int) variable->value;
// replace cvar with this one...
else
{
// otherwise find it somewhere in the list
- for (cvar2 = cvar_vars;cvar2->next != cvar;cvar2 = cvar2->next);
- if (cvar2->next == cvar)
- cvar2->next = variable;
+ for (current = cvar_vars;current->next != cvar;current = current->next)
+ ;
+ current->next = variable;
}
// get rid of old allocated cvar
- // (but not the cvar->string, because we kept that)
+ // (but not cvar->string and cvar->defstring, because we kept those)
Z_Free(cvar->name);
Z_Free(cvar);
}
oldstr = variable->string;
variable->string = Z_Malloc (strlen(variable->string)+1);
strcpy (variable->string, oldstr);
+ variable->defstring = Z_Malloc (strlen(variable->string)+1);
+ strcpy (variable->defstring, oldstr);
variable->value = atof (variable->string);
variable->integer = (int) variable->value;
// link the variable in
// alphanumerical order
- for( cvar = NULL, cvar2 = cvar_vars ; cvar2 && strcmp( cvar2->name, variable->name ) < 0 ; cvar = cvar2, cvar2 = cvar->next )
+ for( current = NULL, next = cvar_vars ; next && strcmp( next->name, variable->name ) < 0 ; current = next, next = next->next )
;
- if( cvar ) {
- cvar->next = variable;
+ if( current ) {
+ current->next = variable;
} else {
cvar_vars = variable;
}
- variable->next = cvar2;
+ variable->next = next;
}
/*
{
cvar->flags |= flags;
Cvar_SetQuick_Internal (cvar, value);
+ // also set the default value (but only once)
+ if (~cvar->flags & CVAR_DEFAULTSET)
+ {
+ cvar->flags |= CVAR_DEFAULTSET;
+
+ Z_Free(cvar->defstring);
+ cvar->defstring = Z_Malloc(strlen(value) + 1);
+ strcpy(cvar->defstring, value);
+ }
return cvar;
}
// allocate a new cvar, cvar name, and cvar string
// FIXME: these never get Z_Free'd
cvar = Z_Malloc(sizeof(cvar_t));
- cvar->flags = flags | CVAR_ALLOCATED;
+ cvar->flags = flags | CVAR_ALLOCATED | CVAR_DEFAULTSET;
cvar->name = Z_Malloc(strlen(name)+1);
strcpy(cvar->name, name);
cvar->string = Z_Malloc(strlen(value)+1);
strcpy(cvar->string, value);
+ cvar->defstring = Z_Malloc(strlen(value)+1);
+ strcpy(cvar->defstring, value);
cvar->value = atof (cvar->string);
cvar->integer = (int) cvar->value;
// perform a variable print or set
if (Cmd_Argc() == 1)
{
- Con_Printf("\"%s\" is \"%s\"\n", v->name, v->string);
+ Con_Printf("\"%s\" is \"%s\" [\"%s\"]\n", v->name, v->string, v->defstring);
return true;
}
if (partial && strncasecmp (partial,cvar->name,len))
continue;
- Con_Printf("%s is \"%s\"\n", cvar->name, cvar->string);
+ Con_Printf("%s is \"%s\" [\"%s\"]\n", cvar->name, cvar->string, cvar->defstring);
count++;
}
// used to determine if flags is valid
#define CVAR_MAXFLAGSVAL 7
// for internal use only!
+#define CVAR_DEFAULTSET (1<<30)
#define CVAR_ALLOCATED (1<<31)
/*
typedef struct cvar_s
{
int flags;
+
char *name;
+
char *string;
int integer;
float value;
float vector[3];
+
+ char *defstring;
+
//menucvar_t menuinfo;
struct cvar_s *next;
} cvar_t;
const char *Cvar_VariableString (const char *var_name);
// returns an empty string if not defined
+const char *Cvar_VariableDefString (const char *var_name);
+// returns an empty string if not defined
+
const char *Cvar_CompleteVariable (const char *partial);
// attempts to match a partial variable name for command line completion
// returns NULL if nothing fits
VM_altstr_prepare,
VM_altstr_get,
VM_altstr_set,
- VM_altstr_ins, // 86
- 0,0,0,0, // 90
+ VM_altstr_ins,
+ VM_findflags,
+ VM_findchainflags,
+ VM_cvar_defstring, // 89
+ 0, // 90
e10, // 100
e100, // 200
e100, // 300
name = PRVM_G_STRING(OFS_PARM0);
if(!name)
- PRVM_ERROR("VM_str_cvar: %s: null string\n", PRVM_NAME);
+ PRVM_ERROR("VM_cvar_string: %s: null string\n", PRVM_NAME);
VM_CheckEmptyString(name);
PRVM_G_INT(OFS_RETURN) = PRVM_SetEngineString(out);
}
+
+/*
+========================
+VM_cvar_defstring
+
+const string VM_cvar_defstring (string)
+========================
+*/
+void VM_cvar_defstring (void)
+{
+ char *out;
+ const char *name;
+ const char *cvar_string;
+ VM_SAFEPARMCOUNT(1,VM_cvar_string);
+
+ name = PRVM_G_STRING(OFS_PARM0);
+
+ if(!name)
+ PRVM_ERROR("VM_cvar_defstring: %s: null string\n", PRVM_NAME);
+
+ VM_CheckEmptyString(name);
+
+ out = VM_GetTempString();
+
+ cvar_string = Cvar_VariableDefString(name);
+
+ strcpy(out, cvar_string);
+
+ PRVM_G_INT(OFS_RETURN) = PRVM_SetEngineString(out);
+}
/*
=================
VM_cvar_set
entity findchain(.string field, string match)
=========
*/
-int PRVM_ED_FindFieldOffset(const char *field);
// chained search for strings in entity fields
// entity(.string field, string match) findchain = #402;
void VM_findchain (void)
VM_RETURN_EDICT(chain);
}
+/*
+========================
+VM_findflags
+
+entity findflags(entity start, .float field, float match)
+========================
+*/
+// LordHavoc: search for flags in float fields
+void VM_findflags (void)
+{
+ int e;
+ int f;
+ int s;
+ prvm_edict_t *ed;
+
+ VM_SAFEPARMCOUNT(3, VM_findflags);
+
+
+ e = PRVM_G_EDICTNUM(OFS_PARM0);
+ f = PRVM_G_INT(OFS_PARM1);
+ s = (int)PRVM_G_FLOAT(OFS_PARM2);
+
+ for (e++ ; e < prog->num_edicts ; e++)
+ {
+ prog->xfunction->builtinsprofile++;
+ ed = PRVM_EDICT_NUM(e);
+ if (ed->priv.required->free)
+ continue;
+ if ((int)PRVM_E_FLOAT(ed,f) & s)
+ {
+ VM_RETURN_EDICT(ed);
+ return;
+ }
+ }
+
+ VM_RETURN_EDICT(prog->edicts);
+}
+
+/*
+========================
+VM_findchainflags
+
+entity findchainflags(.float field, float match)
+========================
+*/
+// LordHavoc: chained search for flags in float fields
+void VM_findchainflags (void)
+{
+ int i;
+ int f;
+ int s;
+ int chain_of;
+ prvm_edict_t *ent, *chain;
+
+ VM_SAFEPARMCOUNT(2, VM_findchainflags);
+
+ if(!prog->flag & PRVM_FE_CHAIN)
+ PRVM_ERROR("VM_findchainflags: %s doesnt have a chain field !\n", PRVM_NAME);
+
+ chain_of = PRVM_ED_FindField("chain")->ofs;
+
+ chain = (prvm_edict_t *)prog->edicts;
+
+ f = PRVM_G_INT(OFS_PARM0);
+ s = (int)PRVM_G_FLOAT(OFS_PARM1);
+
+ ent = PRVM_NEXT_EDICT(prog->edicts);
+ for (i = 1;i < prog->num_edicts;i++, ent = PRVM_NEXT_EDICT(ent))
+ {
+ prog->xfunction->builtinsprofile++;
+ if (ent->priv.required->free)
+ continue;
+ if (!((int)PRVM_E_FLOAT(ent,f) & s))
+ continue;
+
+ PRVM_E_INT(ent,chain_of) = PRVM_EDICT_TO_PROG(chain);
+ chain = ent;
+ }
+
+ VM_RETURN_EDICT(chain);
+}
+
/*
=========
VM_coredump
float itof(intt ent)
intt ftoi(float num)
+-------will be removed soon----------
float altstr_count(string)
string altstr_prepare(string)
string altstr_get(string,float)
string altstr_set(string altstr, float num, string set)
string altstr_ins(string altstr, float num, string set)
+--------------------------------------
+
+entity findflags(entity start, .float field, float match)
+entity findchainflags(.float field, float match)
+
+const string VM_cvar_defstring (string)
perhaps only : Menu : WriteMsg
===============================
void VM_localcmd (void);
void VM_cvar (void);
void VM_cvar_string(void);
+void VM_cvar_defstring (void);
void VM_cvar_set (void);
void VM_dprint (void);
void VM_ftos (void);
void VM_findfloat (void);
void VM_findchain (void);
void VM_findchainfloat (void);
+void VM_findflags (void);
+void VM_findchainflags (void);
void VM_precache_file (void);
void VM_precache_error (void);
void VM_precache_sound (void);
void VM_ceil (void);
void VM_nextent (void);
-// REMOVE THESE
-sizebuf_t *VM_WriteDest (void);
-void VM_WriteByte (void);
-void VM_WriteChar (void);
-void VM_WriteShort (void);
-void VM_WriteLong (void);
-void VM_WriteAngle (void);
-void VM_WriteCoord (void);
-void VM_WriteString (void);
-void VM_WriteEntity (void);
-
void VM_changelevel (void);
void VM_sin (void);
void VM_cos (void);
}
prog->progs = (dprograms_t *)FS_LoadFile (filename, prog->progs_mempool, false);
- if (prog->progs == NULL)
+ if (prog->progs == NULL || fs_filesize < sizeof(dprograms_t))
PRVM_ERROR ("PRVM_LoadProgs: couldn't load %s for %s", filename, PRVM_NAME);
Con_DPrintf("%s programs occupy %iK.\n", PRVM_NAME, fs_filesize/1024);
}
}
- PRVM_LoadLNO( filename );
+ PRVM_LoadLNO(filename);
PRVM_Init_Exec();
void PRVM_PrintStatement (dstatement_t *s)
{
int i;
+
+ if( prog->statement_linenums ) {
+ int opnum;
+
+ opnum = s - prog->statements;
+ Con_Printf( "%s:%i: ", PRVM_GetString( prog->xfunction->s_file ), prog->statement_linenums[ opnum ] );
+ }
if ( (unsigned)s->op < sizeof(prvm_opnames)/sizeof(prvm_opnames[0]))
{
prog->xfunction->profile += profile - startprofile;
startprofile = profile;
prog->xstatement = st - prog->statements;
- Host_Error("assignment to world entity in %s", PRVM_NAME);
+ PRVM_ERROR("forbidden assignment to null/world entity in %s", PRVM_NAME);
return;
}
ed = PRVM_PROG_TO_EDICT(OPA->edict);
VM_RETURN_EDICT(chain);
}
-// LordHavoc: search for flags in float fields
-void PF_findflags (void)
-{
- int e;
- int f;
- int s;
- prvm_edict_t *ed;
-
- e = PRVM_G_EDICTNUM(OFS_PARM0);
- f = PRVM_G_INT(OFS_PARM1);
- s = (int)PRVM_G_FLOAT(OFS_PARM2);
-
- for (e++ ; e < prog->num_edicts ; e++)
- {
- prog->xfunction->builtinsprofile++;
- ed = PRVM_EDICT_NUM(e);
- if (ed->priv.server->free)
- continue;
- if ((int)PRVM_E_FLOAT(ed,f) & s)
- {
- VM_RETURN_EDICT(ed);
- return;
- }
- }
-
- VM_RETURN_EDICT(prog->edicts);
-}
-
-// LordHavoc: chained search for flags in float fields
-void PF_findchainflags (void)
-{
- int i;
- int f;
- int s;
- prvm_edict_t *ent, *chain;
-
- chain = (prvm_edict_t *)prog->edicts;
-
- f = PRVM_G_INT(OFS_PARM0);
- s = (int)PRVM_G_FLOAT(OFS_PARM1);
-
- ent = PRVM_NEXT_EDICT(prog->edicts);
- for (i = 1;i < prog->num_edicts;i++, ent = PRVM_NEXT_EDICT(ent))
- {
- prog->xfunction->builtinsprofile++;
- if (ent->priv.server->free)
- continue;
- if (!((int)PRVM_E_FLOAT(ent,f) & s))
- continue;
-
- ent->fields.server->chain = PRVM_EDICT_TO_PROG(chain);
- chain = ent;
- }
-
- VM_RETURN_EDICT(chain);
-}
-
void PF_precache_file (void)
{ // precache_file is only used to copy files with qcc, it does nothing
PRVM_G_INT(OFS_RETURN) = PRVM_G_INT(OFS_PARM0);
VM_search_getsize, // #446 float(float handle) search_getsize (DP_FS_SEARCH)
VM_search_getfilename, // #447 string(float handle, float num) search_getfilename (DP_FS_SEARCH)
VM_cvar_string, // #448 string(string s) cvar_string (DP_QC_CVAR_STRING)
-PF_findflags, // #449 entity(entity start, .float fld, float match) findflags (DP_QC_FINDFLAGS)
-PF_findchainflags, // #450 entity(.float fld, float match) findchainflags (DP_QC_FINDCHAINFLAGS)
+VM_findflags, // #449 entity(entity start, .float fld, float match) findflags (DP_QC_FINDFLAGS)
+VM_findchainflags, // #450 entity(.float fld, float match) findchainflags (DP_QC_FINDCHAINFLAGS)
PF_gettagindex, // #451 float(entity ent, string tagname) gettagindex (DP_QC_GETTAGINFO)
PF_gettaginfo, // #452 vector(entity ent, float tagindex) gettaginfo (DP_QC_GETTAGINFO)
PF_dropclient, // #453 void(entity clent) dropclient (DP_SV_DROPCLIENT)