string search_getfilename(float handle, float num)
string chr(float ascii)
+
+float etof(entity ent)
+entity ftoe(float num)
perhaps only : Menu : WriteMsg
===============================
float gethostcachevalue(float type)
string gethostcachestring(float type, float hostnr)
-
+ parseentitydata(entity ent, string data)
*/
#include "quakedef.h"
static char vm_string_temp[VM_STRINGTEMP_BUFFERS][VM_STRINGTEMP_LENGTH];
static int vm_string_tempindex = 0;
-// qc cvar
-#define MAX_QC_CVARS 128 * PRVM_MAXPROGS
-cvar_t vm_qc_cvar[MAX_QC_CVARS];
-int vm_currentqc_cvar;
-
// qc file handling
#define MAX_VMFILES 256
#define MAX_PRVMFILES MAX_VMFILES * PRVM_MAXPROGS
char string[VM_STRINGTEMP_LENGTH];
VM_VarString(0, string, sizeof(string));
- Con_Printf ("======%S ERROR in %s:\n%s\n", PRVM_NAME, PRVM_GetString(prog->xfunction->s_name), string);
+ Con_Printf("======%S ERROR in %s:\n%s\n", PRVM_NAME, PRVM_GetString(prog->xfunction->s_name), string);
if(prog->self)
{
ed = PRVM_G_EDICT(prog->self->ofs);
- PRVM_ED_Print (ed);
+ PRVM_ED_Print(ed);
}
PRVM_ERROR ("%s: Program error", PRVM_NAME);
char string[VM_STRINGTEMP_LENGTH];
VM_VarString(0, string, sizeof(string));
- Con_Printf ("======%s OBJECT ERROR in %s:\n%s\n", PRVM_NAME, PRVM_GetString(prog->xfunction->s_name), string);
+ Con_Printf("======%s OBJECT ERROR in %s:\n%s\n", PRVM_NAME, PRVM_GetString(prog->xfunction->s_name), string);
if(prog->self)
{
ed = PRVM_G_EDICT (prog->self->ofs);
- PRVM_ED_Print (ed);
+ PRVM_ED_Print(ed);
PRVM_ED_Free (ed);
}
char string[VM_STRINGTEMP_LENGTH];
VM_VarString(0, string, sizeof(string));
- Con_Printf(string);
+ Con_Print(string);
}
/*
if(!sv.active)
{
- Con_Printf("VM_bprint: game is not server(%s) !", PRVM_NAME);
+ Con_Printf("VM_bprint: game is not server(%s) !\n", PRVM_NAME);
return;
}
VM_VarString(0, string, sizeof(string));
- SV_BroadcastPrintf("%s", string);
+ SV_BroadcastPrint(string);
}
/*
clientnum = PRVM_G_FLOAT(OFS_PARM0);
if (!sv.active || clientnum < 0 || clientnum >= svs.maxclients || !svs.clients[clientnum].active)
{
- Con_Printf("VM_sprint: %s: invalid client or server is not active !", PRVM_NAME);
+ Con_Printf("VM_sprint: %s: invalid client or server is not active !\n", PRVM_NAME);
return;
}
s = PRVM_G_STRING(OFS_PARM0);
- if(!S_GetCached(s))
+ if(!S_LocalSound(s, true))
{
- Con_Printf("VM_localsound: %s : %s not cached !\n", PRVM_NAME, s);
+ Con_Printf("VM_localsound: Failed to play %s for %s !\n", s, PRVM_NAME);
PRVM_G_FLOAT(OFS_RETURN) = -4;
return;
}
- S_LocalSound(s);
PRVM_G_FLOAT(OFS_RETURN) = 1;
}
strcpy(out, cvar_string);
- PRVM_G_INT(OFS_PARM0) = PRVM_SetString(out);
+ PRVM_G_INT(OFS_RETURN) = PRVM_SetString(out);
}
/*
PRVM_G_FLOAT(OFS_RETURN) = atof(string);
}
+/*
+========================
+VM_etof
+
+float etof(entity ent)
+========================
+*/
+void VM_etof(void)
+{
+ VM_SAFEPARMCOUNT(1, VM_etof);
+ PRVM_G_FLOAT(OFS_RETURN) = PRVM_G_INT(OFS_PARM0);
+}
+
+/*
+========================
+VM_ftoe
+
+entity ftoe(float num)
+========================
+*/
+void VM_ftoe(void)
+{
+ int ent;
+ VM_SAFEPARMCOUNT(1, VM_ftoe);
+
+ ent = PRVM_G_FLOAT(OFS_PARM0);
+ if(PRVM_PROG_TO_EDICT(ent)->p.e->free)
+ PRVM_ERROR ("VM_ftoe: %s tried to access a freed entity (entity %i)!\n", PRVM_NAME, ent);
+
+ PRVM_G_INT(OFS_RETURN) = ent;
+}
+
/*
=========
VM_spawn
=========
VM_remove
-entity remove()
+remove(entity e)
=========
*/
{
prog->xfunction->builtinsprofile++;
ed = PRVM_EDICT_NUM(e);
- if (ed->e->free)
+ if (ed->p.e->free)
continue;
t = PRVM_E_STRING(ed,f);
if (!t)
{
prog->xfunction->builtinsprofile++;
ed = PRVM_EDICT_NUM(e);
- if (ed->e->free)
+ if (ed->p.e->free)
continue;
if (PRVM_E_FLOAT(ed,f) == s)
{
for (i = 1;i < prog->num_edicts;i++, ent = PRVM_NEXT_EDICT(ent))
{
prog->xfunction->builtinsprofile++;
- if (ent->e->free)
+ if (ent->p.e->free)
continue;
t = PRVM_E_STRING(ent,f);
if (!t)
for (i = 1;i < prog->num_edicts;i++, ent = PRVM_NEXT_EDICT(ent))
{
prog->xfunction->builtinsprofile++;
- if (ent->e->free)
+ if (ent->p.e->free)
continue;
if (E_FLOAT(ent,f) != s)
continue;
PRVM_G_INT(OFS_RETURN) = PRVM_G_INT(OFS_PARM0);
VM_CheckEmptyString (s);
- if(S_GetCached(s))
- {
- Con_Printf("VM_precache_sound: %s already cached (%s)\n", s, PRVM_NAME);
- return;
- }
-
- if(!S_PrecacheSound(s,true))
- Con_Printf("VM_prache_sound: Failed to load %s for %s\n", s, PRVM_NAME);
+ if(!S_PrecacheSound(s,true, true, true))
+ Con_Printf("VM_precache_sound: Failed to load %s for %s\n", s, PRVM_NAME);
}
/*
return;
}
ent = PRVM_EDICT_NUM(i);
- if (!ent->e->free)
+ if (!ent->p.e->free)
{
VM_RETURN_EDICT(ent);
return;
void VM_WriteAngle (void)
{
- MSG_WriteAngle (VM_WriteDest(), PRVM_G_FLOAT(OFS_PARM0));
+ MSG_WriteAngle (VM_WriteDest(), PRVM_G_FLOAT(OFS_PARM0), sv.protocol);
}
void VM_WriteCoord (void)
{
- MSG_WriteDPCoord (VM_WriteDest(), PRVM_G_FLOAT(OFS_PARM0));
+ MSG_WriteCoord (VM_WriteDest(), PRVM_G_FLOAT(OFS_PARM0), sv.protocol);
}
void VM_WriteString (void)
void VM_registercvar (void)
{
char *name, *value;
- cvar_t *variable;
- int flags;
+ int flags;
VM_SAFEPARMCOUNT(3,VM_registercvar);
// check for overlap with a command
if (Cmd_Exists (name))
{
- Con_Printf ("VM_registercvar: %s is a command\n", name);
+ Con_Printf("VM_registercvar: %s is a command\n", name);
return;
}
- if (vm_currentqc_cvar >= MAX_QC_CVARS)
- PRVM_ERROR ("VM_registercvar: ran out of cvar slots (%i)\n", MAX_QC_CVARS);
+ Cvar_Get(name, value, 0);
-// copy the name and value
- variable = &vm_qc_cvar[vm_currentqc_cvar++];
- variable->flags = flags;
- variable->name = Z_Malloc (strlen(name)+1);
- strcpy (variable->name, name);
- variable->string = Z_Malloc (strlen(value)+1);
- strcpy (variable->string, value);
- variable->value = atof (value);
-
- Cvar_RegisterVariable(variable);
PRVM_G_FLOAT(OFS_RETURN) = 1; // success
}
if (entnum < 1 || entnum > svs.maxclients || !svs.clients[entnum-1].active)
{
- Con_Printf ("tried to setcolor a non-client\n");
+ Con_Print("tried to setcolor a non-client\n");
return;
}
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;
}
return;
}
VM_FILES[filenum] = FS_Open(va("data/%s", filename), modestring, false);
+ if (VM_FILES[filenum] == NULL && mode == 0)
+ VM_FILES[filenum] = FS_Open(va("%s", filename), modestring, false);
+
if (VM_FILES[filenum] == NULL)
PRVM_G_FLOAT(OFS_RETURN) = -1;
else
c = FS_Getc(VM_FILES[filenum]);
if (developer.integer)
Con_Printf("fgets: %s: %s\n", PRVM_NAME, string);
- if (c >= 0)
+ if (c >= 0 || end)
PRVM_G_INT(OFS_RETURN) = PRVM_SetString(string);
else
PRVM_G_INT(OFS_RETURN) = 0;
i = PRVM_G_FLOAT(OFS_PARM0);
if (!sv.active || i < 0 || i >= svs.maxclients || !svs.clients[i].active)
{
- Con_Printf("VM_clientcommand: %s: invalid client/server is not active !", PRVM_NAME);
+ Con_Printf("VM_clientcommand: %s: invalid client/server is not active !\n", PRVM_NAME);
return;
}
for (i = 0;i < model->data_overridetagnamesforskin[(unsigned int)tagentity->v->skin].num_overridetagnames;i++)
if (!strcmp(tagname, model->data_overridetagnamesforskin[(unsigned int)tagentity->v->skin].data_overridetagnames[i].name))
v->_float = i + 1;
+ // FIXME: use a model function to get tag info (need to handle skeletal)
if (v->_float == 0 && model->alias.aliasnum_tags)
for (i = 0;i < model->alias.aliasnum_tags;i++)
if (!strcmp(tagname, model->alias.aliasdata_tags[i].name))
PRVM_ED_LoadFromFile(PRVM_G_STRING(OFS_PARM0));
}
+/*
+========================
+VM_M_parseentitydata
+
+parseentitydata(entity ent, string data)
+========================
+*/
+void VM_M_parseentitydata(void)
+{
+ prvm_edict_t *ent;
+ const char *data;
+
+ VM_SAFEPARMCOUNT(2, VM_parseentitydata);
+
+ // get edict and test it
+ ent = PRVM_G_EDICT(OFS_PARM0);
+ if (ent->p.e->free)
+ PRVM_ERROR ("VM_parseentitydata: %s: Can only set already spawned entities (entity %i is free)!\n", PRVM_NAME, PRVM_NUM_FOR_EDICT(ent));
+
+ data = PRVM_G_STRING(OFS_PARM1);
+
+ // parse the opening brace
+ if (!COM_ParseToken(&data, false) || com_token[0] != '{' )
+ PRVM_ERROR ("VM_parseentitydata: %s: Couldn't parse entity data:\n%s\n", PRVM_NAME, data );
+
+ PRVM_ED_ParseEdict (data, ent);
+}
+
/*
=========
VM_loadfromfile
}
// not conform with VM_fopen
- data = FS_LoadFile(filename, false);
+ data = FS_LoadFile(filename, tempmempool, false);
if (data == NULL)
PRVM_G_FLOAT(OFS_RETURN) = -1;
}
if(pos[2] || scale[2])
- Con_Printf("VM_drawcharacter: z value%c from %s discarded",(pos[2] && scale[2]) ? 's' : 0,((pos[2] && scale[2]) ? "pos and scale" : (pos[2] ? "pos" : "scale")));
+ Con_Printf("VM_drawcharacter: z value%c from %s discarded\n",(pos[2] && scale[2]) ? 's' : 0,((pos[2] && scale[2]) ? "pos and scale" : (pos[2] ? "pos" : "scale")));
if(!scale[0] || !scale[1])
{
}
if(pos[2] || scale[2])
- Con_Printf("VM_drawstring: z value%c from %s discarded",(pos[2] && scale[2]) ? 's' : 0,((pos[2] && scale[2]) ? "pos and scale" : (pos[2] ? "pos" : "scale")));
+ Con_Printf("VM_drawstring: z value%c from %s discarded\n",(pos[2] && scale[2]) ? 's' : 0,((pos[2] && scale[2]) ? "pos and scale" : (pos[2] ? "pos" : "scale")));
DrawQ_String (pos[0], pos[1], string, 0, scale[0], scale[1], rgb[0], rgb[1], rgb[2], PRVM_G_FLOAT(OFS_PARM4), flag);
PRVM_G_FLOAT(OFS_RETURN) = 1;
}
if(pos[2] || size[2])
- Con_Printf("VM_drawstring: z value%c from %s discarded",(pos[2] && size[2]) ? 's' : 0,((pos[2] && size[2]) ? "pos and size" : (pos[2] ? "pos" : "size")));
+ Con_Printf("VM_drawstring: z value%c from %s discarded\n",(pos[2] && size[2]) ? 's' : 0,((pos[2] && size[2]) ? "pos and size" : (pos[2] ? "pos" : "size")));
DrawQ_Pic(pos[0], pos[1], pic, size[0], size[1], rgb[0], rgb[1], rgb[2], PRVM_G_FLOAT(OFS_PARM4), flag);
PRVM_G_FLOAT(OFS_RETURN) = 1;
}
if(pos[2] || size[2])
- Con_Printf("VM_drawstring: z value%c from %s discarded",(pos[2] && size[2]) ? 's' : 0,((pos[2] && size[2]) ? "pos and size" : (pos[2] ? "pos" : "size")));
+ Con_Printf("VM_drawstring: z value%c from %s discarded\n",(pos[2] && size[2]) ? 's' : 0,((pos[2] && size[2]) ? "pos and size" : (pos[2] ? "pos" : "size")));
DrawQ_Pic(pos[0], pos[1], 0, size[0], size[1], rgb[0], rgb[1], rgb[2], PRVM_G_FLOAT(OFS_PARM3), flag);
PRVM_G_FLOAT(OFS_RETURN) = 1;
void VM_Cmd_Init(void)
{
// only init the stuff for the current prog
- VM_STRINGS_MEMPOOL = Mem_AllocPool(va("vm_stringsmempool[%s]",PRVM_NAME));
+ VM_STRINGS_MEMPOOL = Mem_AllocPool(va("vm_stringsmempool[%s]",PRVM_NAME), 0, NULL);
VM_Files_Init();
VM_Search_Init();
}
}
ent = PRVM_G_EDICT(OFS_PARM1);
- if(ent->e->free)
+ if(ent->p.e->free)
{
Con_Printf("VM_M_writetofile: %s: entity %i is free !\n", PRVM_NAME, PRVM_EDICT_NUM(OFS_PARM1));
return;
type = PRVM_G_FLOAT( OFS_PARM0 );
if( type < 0 || type > 4 )
- Con_Printf ( "VM_M_gethostcachevalue: bad type %i!\n", type );
+ Con_Printf( "VM_M_gethostcachevalue: bad type %i!\n", type );
else switch(type)
{
case 0:
return;
case 2:
PRVM_G_FLOAT ( OFS_RETURN ) = masterreplycount;
+ return;
case 3:
PRVM_G_FLOAT ( OFS_RETURN ) = serverquerycount;
+ return;
case 4:
PRVM_G_FLOAT ( OFS_RETURN ) = serverreplycount;
+ return;
}
}
if(type < 0 || type > 2)
{
- Con_Printf("VM_M_gethostcachestring: bad string type requested!\n");
+ Con_Print("VM_M_gethostcachestring: bad string type requested!\n");
return;
}
if(hostnr < 0 || hostnr >= hostCacheCount)
{
- Con_Printf("VM_M_gethostcachestring: bad hostnr passed!\n");
+ Con_Print("VM_M_gethostcachestring: bad hostnr passed!\n");
return;
}
VM_search_end,
VM_search_getsize,
VM_search_getfilename, // 77
- VM_chr, //78
- 0,0,// 80
+ VM_chr,
+ VM_etof,
+ VM_ftoe,// 80
e10, // 90
e10, // 100
e100, // 200
VM_M_keynumtostring,
VM_M_findkeysforcommand,// 610
VM_M_gethostcachevalue,
- VM_M_gethostcachestring // 612
+ VM_M_gethostcachestring,
+ VM_M_parseentitydata // 613
};
const int vm_m_numbuiltins = sizeof(vm_m_builtins) / sizeof(prvm_builtin_t);