prog->error_cmd("%s: Bad string", prog->name);
}
+qbool PRVM_ConsoleCommand (prvm_prog_t *prog, const char *text, int *func, qbool preserve_self, int curself, double ptime, qbool prog_loaded, const char *error_message)
+{
+ int restorevm_tempstringsbuf_cursize;
+ int save_self = 0; // hush compiler warning
+ qbool r = false;
+
+ if(!prog_loaded)
+ return false;
+
+ if(func)
+ {
+ if(preserve_self)
+ save_self = PRVM_gameglobaledict(self);
+ if(ptime)
+ PRVM_gameglobalfloat(time) = ptime;
+ PRVM_gameglobaledict(self) = curself;
+ restorevm_tempstringsbuf_cursize = prog->tempstringsbuf.cursize;
+ PRVM_G_INT(OFS_PARM0) = PRVM_SetTempString(prog, text);
+ prog->ExecuteProgram(prog, *func, error_message);
+ prog->tempstringsbuf.cursize = restorevm_tempstringsbuf_cursize;
+ if(preserve_self)
+ PRVM_gameglobaledict(self) = save_self;
+ r = (int) PRVM_G_FLOAT(OFS_RETURN) != 0;
+ }
+
+ return r;
+}
+
void VM_GenerateFrameGroupBlend(prvm_prog_t *prog, framegroupblend_t *framegroupblend, const prvm_edict_t *ed)
{
// self.frame is the interpolation target (new frame)
=========
VM_localsound
-localsound(string sample)
+localsound(string sample, float chan, float vol)
=========
*/
void VM_localsound(prvm_prog_t *prog)
{
const char *s;
+ float chan, vol;
- VM_SAFEPARMCOUNT(1,VM_localsound);
+ VM_SAFEPARMCOUNTRANGE(1, 3,VM_localsound);
s = PRVM_G_STRING(OFS_PARM0);
-
- if(!S_LocalSound (s))
+ if(prog->argc == 3)
+ {
+ chan = PRVM_G_FLOAT(OFS_PARM1);
+ vol = PRVM_G_FLOAT(OFS_PARM2) == 0 ? 1 : PRVM_G_FLOAT(OFS_PARM2);
+ if(!S_LocalSoundEx(s, chan, vol))
+ {
+ PRVM_G_FLOAT(OFS_RETURN) = -4;
+ VM_Warning(prog, "VM_localsound: Failed to play %s for %s !\n", s, prog->name);
+ return;
+ }
+ }
+ else if(!S_LocalSound (s))
{
PRVM_G_FLOAT(OFS_RETURN) = -4;
VM_Warning(prog, "VM_localsound: Failed to play %s for %s !\n", s, prog->name);
/*
=================
-VM_localcmd_client
+VM_localcmd_local
Sends text over to the client's execution buffer
cmd (string, ...)
=================
*/
-void VM_localcmd_client(prvm_prog_t *prog)
+void VM_localcmd_local(prvm_prog_t *prog)
{
char string[VM_STRINGTEMP_LENGTH];
- VM_SAFEPARMCOUNTRANGE(1, 8, VM_localcmd_client);
+ VM_SAFEPARMCOUNTRANGE(1, 8, VM_localcmd_local);
VM_VarString(prog, 0, string, sizeof(string));
- Cbuf_AddText(&cmd_client, string);
+ Cbuf_AddText(cmd_local, string);
}
/*
char string[VM_STRINGTEMP_LENGTH];
VM_SAFEPARMCOUNTRANGE(1, 8, VM_localcmd_server);
VM_VarString(prog, 0, string, sizeof(string));
- Cbuf_AddText(&cmd_server, string);
+ Cbuf_AddText(cmd_local, string);
}
static qbool PRVM_Cvar_ReadOk(prvm_prog_t *prog, const char *string)
VM_SAFEPARMCOUNT(1, VM_ftoe);
ent = (prvm_int_t)PRVM_G_FLOAT(OFS_PARM0);
- if (ent < 0 || ent >= prog->max_edicts || PRVM_PROG_TO_EDICT(ent)->priv.required->free)
+ if (ent < 0 || ent >= prog->max_edicts || PRVM_PROG_TO_EDICT(ent)->free)
ent = 0; // return world instead of a free or invalid entity
PRVM_G_INT(OFS_RETURN) = ent;
if (developer.integer > 0)
VM_Warning(prog, "VM_remove: tried to remove the null entity or a reserved entity!\n" );
}
- else if( ed->priv.required->free )
+ else if( ed->free )
{
if (developer.integer > 0)
VM_Warning(prog, "VM_remove: tried to remove an already freed entity!\n" );
{
prog->xfunction->builtinsprofile++;
ed = PRVM_EDICT_NUM(e);
- if (ed->priv.required->free)
+ if (ed->free)
continue;
t = PRVM_E_STRING(ed,f);
if (!t)
{
prog->xfunction->builtinsprofile++;
ed = PRVM_EDICT_NUM(e);
- if (ed->priv.required->free)
+ if (ed->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->priv.required->free)
+ if (ent->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->priv.required->free)
+ if (ent->free)
continue;
if (PRVM_E_FLOAT(ent,f) != s)
continue;
{
prog->xfunction->builtinsprofile++;
ed = PRVM_EDICT_NUM(e);
- if (ed->priv.required->free)
+ if (ed->free)
continue;
if (!PRVM_E_FLOAT(ed,f))
continue;
for (i = 1;i < prog->num_edicts;i++, ent = PRVM_NEXT_EDICT(ent))
{
prog->xfunction->builtinsprofile++;
- if (ent->priv.required->free)
+ if (ent->free)
continue;
if (!PRVM_E_FLOAT(ent,f))
continue;
*/
void VM_coredump(prvm_prog_t *prog)
{
- cmd_state_t *cmd = !host_isclient.integer ? &cmd_server : &cmd_client;
VM_SAFEPARMCOUNT(0,VM_coredump);
- Cbuf_AddText(cmd, "prvm_edicts ");
- Cbuf_AddText(cmd, prog->name);
- Cbuf_AddText(cmd, "\n");
+ Cbuf_AddText(cmd_local, "prvm_edicts ");
+ Cbuf_AddText(cmd_local, prog->name);
+ Cbuf_AddText(cmd_local, "\n");
}
/*
return;
}
ent = PRVM_EDICT_NUM(i);
- if (!ent->priv.required->free)
+ if (!ent->free)
{
VM_RETURN_EDICT(ent);
return;
return;
svs.changelevel_issued = true;
- Cbuf_AddText(&cmd_server, va(vabuf, sizeof(vabuf), "changelevel %s\n", PRVM_G_STRING(OFS_PARM0)));
+ Cbuf_AddText(cmd_local, va(vabuf, sizeof(vabuf), "changelevel %s\n", PRVM_G_STRING(OFS_PARM0)));
}
/*
return;
// check for overlap with a command
- if (Cmd_Exists(&cmd_client, name) || Cmd_Exists(&cmd_server, name))
+ if (Cmd_Exists(cmd_local, name))
{
VM_Warning(prog, "VM_registercvar: %s is a command\n", name);
return;
}
ent = PRVM_G_EDICT(OFS_PARM1);
- if(ent->priv.required->free)
+ if(ent->free)
{
VM_Warning(prog, "VM_writetofile: %s: entity %i is free !\n", prog->name, PRVM_NUM_FOR_EDICT(ent));
return;
// get the entity
ent = PRVM_G_EDICT(OFS_PARM1);
- if(ent->priv.required->free)
+ if(ent->free)
{
PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog, "");
VM_Warning(prog, "VM_entityfielddata: %s: entity %i is free !\n", prog->name, PRVM_NUM_FOR_EDICT(ent));
// get the entity
ent = PRVM_G_EDICT(OFS_PARM1);
- if(ent->priv.required->free)
+ if(ent->free)
{
VM_Warning(prog, "VM_entityfielddata: %s: entity %i is free !\n", prog->name, PRVM_NUM_FOR_EDICT(ent));
PRVM_G_FLOAT(OFS_RETURN) = 0.0f;
// get edict and test it
ent = PRVM_G_EDICT(OFS_PARM0);
- if (ent->priv.required->free)
+ if (ent->free)
prog->error_cmd("VM_parseentitydata: %s: Can only set already spawned entities (entity %i is free)!", prog->name, PRVM_NUM_FOR_EDICT(ent));
data = PRVM_G_STRING(OFS_PARM1);
VM_Warning(prog, "changeyaw: can not modify world entity\n");
return;
}
- if (ent->priv.server->free)
+ if (ent->free)
{
VM_Warning(prog, "changeyaw: can not modify free entity\n");
return;
VM_Warning(prog, "changepitch: can not modify world entity\n");
return;
}
- if (ent->priv.server->free)
+ if (ent->free)
{
VM_Warning(prog, "changepitch: can not modify free entity\n");
return;
void VM_wasfreed (prvm_prog_t *prog)
{
VM_SAFEPARMCOUNT(1, VM_wasfreed);
- PRVM_G_FLOAT(OFS_RETURN) = PRVM_G_EDICT(OFS_PARM0)->priv.required->free;
+ PRVM_G_FLOAT(OFS_RETURN) = PRVM_G_EDICT(OFS_PARM0)->free;
}
void VM_SetTraceGlobals(prvm_prog_t *prog, const trace_t *trace)
static msurface_t *getsurface(model_t *model, int surfacenum)
{
- if (surfacenum < 0 || surfacenum >= model->nummodelsurfaces)
+ if (surfacenum < 0 || surfacenum >= model->submodelsurfaces_end - model->submodelsurfaces_start)
return NULL;
- return model->data_surfaces + surfacenum + model->firstmodelsurface;
+ return model->data_surfaces + surfacenum + model->submodelsurfaces_start;
}
ed = PRVM_G_EDICT(OFS_PARM0);
VectorCopy(PRVM_G_VECTOR(OFS_PARM1), point);
- if (!ed || ed->priv.server->free)
+ if (!ed || ed->free)
return;
model = getmodel(prog, ed);
if (!model || !model->num_surfaces)
applytransform_inverted(prog, point, ed, p);
best = -1;
bestdist = 1000000000;
- for (surfacenum = 0;surfacenum < model->nummodelsurfaces;surfacenum++)
+ for (surfacenum = model->submodelsurfaces_start;surfacenum < model->submodelsurfaces_end;surfacenum++)
{
- surface = model->data_surfaces + surfacenum + model->firstmodelsurface;
+ surface = model->data_surfaces + surfacenum;
// first see if the nearest point on the surface's box is closer than the previous match
clipped[0] = bound(surface->mins[0], p[0], surface->maxs[0]) - p[0];
clipped[1] = bound(surface->mins[1], p[1], surface->maxs[1]) - p[1];
if (dist < bestdist)
{
// that's closer too, store it as the best match
- best = surfacenum;
+ best = surfacenum - model->submodelsurfaces_start;
bestdist = dist;
}
}
// physics builtins
//
+#ifdef USEODE
#define VM_physics_ApplyCmd(ed,f) if (!ed->priv.server->ode_body) VM_physics_newstackfunction(prog, ed, f); else World_Physics_ApplyCmd(ed, f)
static edict_odefunc_t *VM_physics_newstackfunction(prvm_prog_t *prog, prvm_edict_t *ed, edict_odefunc_t *f)
}
return newfunc;
}
+#endif
// void(entity e, float physics_enabled) physics_enable = #;
void VM_physics_enable(prvm_prog_t *prog)
{
+#ifdef USEODE
prvm_edict_t *ed;
edict_odefunc_t f;
-
+#endif
VM_SAFEPARMCOUNT(2, VM_physics_enable);
+#ifdef USEODE
ed = PRVM_G_EDICT(OFS_PARM0);
if (!ed)
{
}
f.type = PRVM_G_FLOAT(OFS_PARM1) == 0 ? ODEFUNC_DISABLE : ODEFUNC_ENABLE;
VM_physics_ApplyCmd(ed, &f);
+#endif
}
// void(entity e, vector force, vector relative_ofs) physics_addforce = #;
void VM_physics_addforce(prvm_prog_t *prog)
{
+#ifdef USEODE
prvm_edict_t *ed;
edict_odefunc_t f;
-
+#endif
VM_SAFEPARMCOUNT(3, VM_physics_addforce);
+#ifdef USEODE
ed = PRVM_G_EDICT(OFS_PARM0);
if (!ed)
{
VectorCopy(PRVM_G_VECTOR(OFS_PARM1), f.v1);
VectorCopy(PRVM_G_VECTOR(OFS_PARM2), f.v2);
VM_physics_ApplyCmd(ed, &f);
+#endif
}
// void(entity e, vector torque) physics_addtorque = #;
void VM_physics_addtorque(prvm_prog_t *prog)
{
+#ifdef USEODE
prvm_edict_t *ed;
edict_odefunc_t f;
-
+#endif
VM_SAFEPARMCOUNT(2, VM_physics_addtorque);
+#ifdef USEODE
ed = PRVM_G_EDICT(OFS_PARM0);
if (!ed)
{
f.type = ODEFUNC_TORQUE;
VectorCopy(PRVM_G_VECTOR(OFS_PARM1), f.v1);
VM_physics_ApplyCmd(ed, &f);
+#endif
}
extern cvar_t prvm_coverage;