// kind of helper function
static qboolean checkextension(const char *name)
{
- int len;
+ size_t len;
char *e, *start;
len = strlen(name);
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
if (developer.integer)
{
VM_VarString(0, string, sizeof(string));
+#if 1
+ Con_Printf("%s", string);
+#else
Con_Printf("%s: %s", PRVM_NAME, string);
+#endif
}
}
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)
if(!prog->flag & PRVM_FE_CHAIN)
PRVM_ERROR("VM_findchain: %s doesnt have a chain field !\n", PRVM_NAME);
- chain_of = PRVM_ED_FindFieldOffset ("chain");
+ chain_of = PRVM_ED_FindField("chain")->ofs;
chain = prog->edicts;
if(!prog->flag & PRVM_FE_CHAIN)
PRVM_ERROR("VM_findchainfloat: %s doesnt have a chain field !\n", PRVM_NAME);
- chain_of = PRVM_ED_FindFieldOffset ("chain");
+ chain_of = PRVM_ED_FindField("chain")->ofs;
chain = (prvm_edict_t *)prog->edicts;
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
modestring = "wb";
break;
default:
- Con_Printf("VM_fopen: %s no such mode %i (valid: 0 = read, 1 = append, 2 = write)\n", PRVM_NAME, mode);
+ Con_Printf("VM_fopen: %s: no such mode %i (valid: 0 = read, 1 = append, 2 = write)\n", PRVM_NAME, mode);
PRVM_G_FLOAT(OFS_RETURN) = -3;
return;
}
VM_FILES[filenum] = FS_Open(va("data/%s", filename), modestring, false, false);
if (VM_FILES[filenum] == NULL && mode == 0)
VM_FILES[filenum] = FS_Open(va("%s", filename), modestring, false, false);
- if (developer.integer)
- Con_Printf("fopen: %s mode %s opened as #%i\n", filename, modestring, filenum);
if (VM_FILES[filenum] == NULL)
+ {
+ if (developer.integer)
+ Con_Printf("VM_fopen: %s: %s mode %s failed\n", PRVM_NAME, filename, modestring);
PRVM_G_FLOAT(OFS_RETURN) = -1;
+ }
else
+ {
+ if (developer.integer)
+ Con_Printf("VM_fopen: %s: %s mode %s opened as #%i\n", PRVM_NAME, filename, modestring, filenum);
PRVM_G_FLOAT(OFS_RETURN) = filenum;
+ }
}
/*
return;
}
if (developer.integer)
- Con_Printf("fclose #%i\n", filenum);
+ Con_Printf("VM_fclose: %s: #%i closed\n", PRVM_NAME, filenum);
FS_Close(VM_FILES[filenum]);
VM_FILES[filenum] = NULL;
}
//void(float fhandle, string s) fputs = #113; // writes a line of text to the end of the file
void VM_fputs(void)
{
- int stringlength;
+ size_t stringlength;
char string[VM_STRINGTEMP_LENGTH];
int filenum;
char *tokens[256], tokenbuf[4096];
void VM_tokenize (void)
{
- int pos;
+ size_t pos;
const char *p;
VM_SAFEPARMCOUNT(1,VM_tokenize);