#include "quakedef.h"
-cvar_t sv_aim = {CVAR_SAVE, "sv_aim", "2"}; //"0.93"}; // LordHavoc: disabled autoaim by default
+cvar_t sv_aim = {CVAR_SAVE, "sv_aim", "2"}; //"0.93"}; // LordHavoc: disabled autoaim by default
+cvar_t pr_zone_min_strings = {0, "pr_zone_min_strings", "64"};
+
+mempool_t *pr_strings_mempool;
+
+#define MAX_VARSTRING 4096
+
+char pr_varstring_temp[MAX_VARSTRING];
#define RETURN_EDICT(e) (((int *)pr_globals)[OFS_RETURN] = EDICT_TO_PROG(e))
char *PF_VarString (int first)
{
- int i;
- static char out[4096]; // FIXME: buffer overflow potential
+ int i, j, end;
+ char *s;
- out[0] = 0;
+ end = 0;
for (i = first;i < pr_argc;i++)
- strcat (out, G_STRING((OFS_PARM0+i*3)));
- return out;
+ {
+ // LordHavoc: FIXME: this is just a strlcat inlined
+ s = G_STRING((OFS_PARM0+i*3));
+ j = strlen(s);
+ if (j > MAX_VARSTRING - 1 - end)
+ j = MAX_VARSTRING - 1 - end;
+ if (j > 0)
+ {
+ memcpy(pr_varstring_temp + end, s, j);
+ end += j;
+ }
+ }
+ pr_varstring_temp[end] = 0;
+ return pr_varstring_temp;
}
char *ENGINE_EXTENSIONS =
"DP_TE_PARTICLERAIN "
"DP_TE_PARTICLESNOW "
"DP_TE_SPARK "
+"FRIK_FILE "
"NEH_CMD_PLAY2 "
"NEH_RESTOREGAME "
+"QSG_FILE "
"TW_SV_STEPCONTROL "
;
edict_t *ed;
s = PF_VarString(0);
- Con_Printf ("======SERVER ERROR in %s:\n%s\n", pr_strings + pr_xfunction->s_name, s);
+ Con_Printf ("======SERVER ERROR in %s:\n%s\n", PR_GetString(pr_xfunction->s_name), s);
ed = PROG_TO_EDICT(pr_global_struct->self);
ED_Print (ed);
edict_t *ed;
s = PF_VarString(0);
- Con_Printf ("======OBJECT ERROR in %s:\n%s\n", pr_strings + pr_xfunction->s_name, s);
+ Con_Printf ("======OBJECT ERROR in %s:\n%s\n", PR_GetString(pr_xfunction->s_name), s);
ed = PROG_TO_EDICT(pr_global_struct->self);
ED_Print (ed);
ED_Free (ed);
{
edict_t *e;
float *org;
-
+
e = G_EDICT(OFS_PARM0);
org = G_VECTOR(OFS_PARM1);
- VectorCopy (org, e->v.origin);
+ VectorCopy (org, e->v->origin);
SV_LinkEdict (e, false);
}
void SetMinMaxSize (edict_t *e, float *min, float *max, qboolean rotate)
{
int i;
-
+
for (i=0 ; i<3 ; i++)
if (min[i] > max[i])
Host_Error ("backwards mins/maxs");
// set derived values
- VectorCopy (min, e->v.mins);
- VectorCopy (max, e->v.maxs);
- VectorSubtract (max, min, e->v.size);
+ VectorCopy (min, e->v->mins);
+ VectorCopy (max, e->v->maxs);
+ VectorSubtract (max, min, e->v->size);
SV_LinkEdict (e, false);
}
{
edict_t *e;
float *min, *max;
-
+
e = G_EDICT(OFS_PARM0);
min = G_VECTOR(OFS_PARM1);
max = G_VECTOR(OFS_PARM2);
Host_Error ("no precache: %s\n", m);
- e->v.model = m - pr_strings;
- e->v.modelindex = i;
+ e->v->model = PR_SetString(*check);
+ e->v->modelindex = i;
- mod = sv.models[ (int)e->v.modelindex];
+ mod = sv.models[ (int)e->v->modelindex];
if (mod)
SetMinMaxSize (e, mod->normalmins, mod->normalmaxs, true);
char *s;
client_t *client;
int entnum;
-
+
entnum = G_EDICTNUM(OFS_PARM0);
s = PF_VarString(1);
-
+
if (entnum < 1 || entnum > svs.maxclients)
{
Con_Printf ("tried to sprint to a non-client\n");
return;
}
-
+
client = &svs.clients[entnum-1];
-
+
MSG_WriteChar (&client->message,svc_print);
MSG_WriteString (&client->message, s );
}
char *s;
client_t *client;
int entnum;
-
+
entnum = G_EDICTNUM(OFS_PARM0);
s = PF_VarString(1);
-
+
if (entnum < 1 || entnum > svs.maxclients)
{
Con_Printf ("tried to sprint to a non-client\n");
return;
}
-
+
client = &svs.clients[entnum-1];
-
+
MSG_WriteChar (&client->message,svc_centerprint);
MSG_WriteString (&client->message, s );
}
float *value1;
vec3_t newvalue;
float new;
-
+
value1 = G_VECTOR(OFS_PARM0);
new = value1[0] * value1[0] + value1[1] * value1[1] + value1[2]*value1[2];
new = sqrt(new);
-
+
if (new == 0)
newvalue[0] = newvalue[1] = newvalue[2] = 0;
else
newvalue[1] = value1[1] * new;
newvalue[2] = value1[2] * new;
}
-
- VectorCopy (newvalue, G_VECTOR(OFS_RETURN));
+
+ VectorCopy (newvalue, G_VECTOR(OFS_RETURN));
}
/*
new = value1[0] * value1[0] + value1[1] * value1[1] + value1[2]*value1[2];
new = sqrt(new);
-
+
G_FLOAT(OFS_RETURN) = new;
}
{
float *value1;
float yaw;
-
+
value1 = G_VECTOR(OFS_PARM0);
if (value1[1] == 0 && value1[0] == 0)
float *value1;
float forward;
float yaw, pitch;
-
+
value1 = G_VECTOR(OFS_PARM0);
if (value1[1] == 0 && value1[0] == 0)
void PF_random (void)
{
float num;
-
+
num = (rand ()&0x7fff) / ((float)0x7fff);
-
+
G_FLOAT(OFS_RETURN) = num;
}
float *org, *dir;
float color;
float count;
-
+
org = G_VECTOR(OFS_PARM0);
dir = G_VECTOR(OFS_PARM1);
color = G_FLOAT(OFS_PARM2);
float vol, attenuation;
int i, soundnum, large;
- pos = G_VECTOR (OFS_PARM0);
+ pos = G_VECTOR (OFS_PARM0);
samp = G_STRING(OFS_PARM1);
vol = G_FLOAT(OFS_PARM2);
attenuation = G_FLOAT(OFS_PARM3);
-
+
// check to see if samp was properly precached
for (soundnum=0, check = sv.sound_precache ; *check ; check++, soundnum++)
if (!strcmp(*check,samp))
edict_t *entity;
int volume;
float attenuation;
-
+
entity = G_EDICT(OFS_PARM0);
channel = G_FLOAT(OFS_PARM1);
sample = G_STRING(OFS_PARM2);
volume = G_FLOAT(OFS_PARM3) * 255;
attenuation = G_FLOAT(OFS_PARM4);
-
+
if (volume < 0 || volume > 255)
Host_Error ("SV_StartSound: volume = %i", volume);
int nomonsters;
edict_t *ent;
+ pr_xfunction->builtinsprofile += 30;
+
v1 = G_VECTOR(OFS_PARM0);
v2 = G_VECTOR(OFS_PARM1);
nomonsters = G_FLOAT(OFS_PARM2);
int nomonsters;
edict_t *ent;
+ pr_xfunction->builtinsprofile += 30;
+
v1 = G_VECTOR(OFS_PARM0);
m1 = G_VECTOR(OFS_PARM1);
m2 = G_VECTOR(OFS_PARM2);
pr_global_struct->trace_inopen = trace.inopen;
VectorCopy (trace.endpos, pr_global_struct->trace_endpos);
VectorCopy (trace.plane.normal, pr_global_struct->trace_plane_normal);
- pr_global_struct->trace_plane_dist = trace.plane.dist;
+ pr_global_struct->trace_plane_dist = trace.plane.dist;
if (trace.ent)
pr_global_struct->trace_ent = EDICT_TO_PROG(trace.ent);
else
edict_t *ent;
edict_t *ignore;
+ pr_xfunction->builtinsprofile += 600;
+
ent = G_EDICT(OFS_PARM0);
ignore = G_EDICT(OFS_PARM1);
pr_global_struct->trace_inopen = trace.inopen;
VectorCopy (trace.endpos, pr_global_struct->trace_endpos);
VectorCopy (trace.plane.normal, pr_global_struct->trace_plane_normal);
- pr_global_struct->trace_plane_dist = trace.plane.dist;
+ pr_global_struct->trace_plane_dist = trace.plane.dist;
if (trace.ent)
pr_global_struct->trace_ent = EDICT_TO_PROG(trace.ent);
else
for ( ; ; i++)
{
+ pr_xfunction->builtinsprofile++;
if (i == svs.maxclients+1)
i = 1;
if (ent->free)
continue;
- if (ent->v.health <= 0)
+ if (ent->v->health <= 0)
continue;
- if ((int)ent->v.flags & FL_NOTARGET)
+ if ((int)ent->v->flags & FL_NOTARGET)
continue;
// anything that is a client, or has a client as an enemy
}
// get the PVS for the entity
- VectorAdd (ent->v.origin, ent->v.view_ofs, org);
+ VectorAdd (ent->v->origin, ent->v->view_ofs, org);
leaf = Mod_PointInLeaf (org, sv.worldmodel);
pvs = Mod_LeafPVS (leaf, sv.worldmodel);
memcpy (checkpvs, pvs, (sv.worldmodel->numleafs+7)>>3 );
// return check if it might be visible
ent = EDICT_NUM(sv.lastcheck);
- if (ent->free || ent->v.health <= 0)
+ if (ent->free || ent->v->health <= 0)
{
RETURN_EDICT(sv.edicts);
return;
// if current entity can't possibly see the check entity, return 0
self = PROG_TO_EDICT(pr_global_struct->self);
- VectorAdd (self->v.origin, self->v.view_ofs, view);
+ VectorAdd (self->v->origin, self->v->view_ofs, view);
leaf = Mod_PointInLeaf (view, sv.worldmodel);
if (leaf)
{
int entnum;
char *str;
client_t *old;
-
+
entnum = G_EDICTNUM(OFS_PARM0);
if (entnum < 1 || entnum > svs.maxclients)
Host_Error ("Parm 0 not a client");
- str = G_STRING(OFS_PARM1);
+ str = G_STRING(OFS_PARM1);
old = host_client;
host_client = &svs.clients[entnum-1];
{
char *str;
- str = G_STRING(OFS_PARM0);
+ str = G_STRING(OFS_PARM0);
Cbuf_AddText (str);
}
void PF_cvar (void)
{
char *str;
-
+
str = G_STRING(OFS_PARM0);
G_FLOAT(OFS_RETURN) = Cvar_VariableValue (str);
void PF_cvar_set (void)
{
char *var, *val;
-
+
var = G_STRING(OFS_PARM0);
val = G_STRING(OFS_PARM1);
-
+
Cvar_Set (var, val);
}
int i;
chain = (edict_t *)sv.edicts;
-
+
org = G_VECTOR(OFS_PARM0);
radius = G_FLOAT(OFS_PARM1);
radius2 = radius * radius;
ent = NEXT_EDICT(sv.edicts);
for (i=1 ; i<sv.num_edicts ; i++, ent = NEXT_EDICT(ent))
{
+ pr_xfunction->builtinsprofile++;
if (ent->free)
continue;
- if (ent->v.solid == SOLID_NOT)
+ if (ent->v->solid == SOLID_NOT)
continue;
// LordHavoc: compare against bounding box rather than center,
// and use DotProduct instead of Length, major speedup
- eorg[0] = (org[0] - ent->v.origin[0]) - bound(ent->v.mins[0], (org[0] - ent->v.origin[0]), ent->v.maxs[0]);
- eorg[1] = (org[1] - ent->v.origin[1]) - bound(ent->v.mins[1], (org[1] - ent->v.origin[1]), ent->v.maxs[1]);
- eorg[2] = (org[2] - ent->v.origin[2]) - bound(ent->v.mins[2], (org[2] - ent->v.origin[2]), ent->v.maxs[2]);
+ eorg[0] = (org[0] - ent->v->origin[0]) - bound(ent->v->mins[0], (org[0] - ent->v->origin[0]), ent->v->maxs[0]);
+ eorg[1] = (org[1] - ent->v->origin[1]) - bound(ent->v->mins[1], (org[1] - ent->v->origin[1]), ent->v->maxs[1]);
+ eorg[2] = (org[2] - ent->v->origin[2]) - bound(ent->v->mins[2], (org[2] - ent->v->origin[2]), ent->v->maxs[2]);
if (DotProduct(eorg, eorg) > radius2)
continue;
-
- ent->v.chain = EDICT_TO_PROG(chain);
+
+ ent->v->chain = EDICT_TO_PROG(chain);
chain = ent;
}
s = PR_GetTempString();
// LordHavoc: ftos improvement
sprintf (s, "%g", v);
- G_INT(OFS_RETURN) = s - pr_strings;
+ G_INT(OFS_RETURN) = PR_SetString(s);
}
void PF_fabs (void)
char *s;
s = PR_GetTempString();
sprintf (s, "'%5.1f %5.1f %5.1f'", G_VECTOR(OFS_PARM0)[0], G_VECTOR(OFS_PARM0)[1], G_VECTOR(OFS_PARM0)[2]);
- G_INT(OFS_RETURN) = s - pr_strings;
+ G_INT(OFS_RETURN) = PR_SetString(s);
}
void PF_etos (void)
char *s;
s = PR_GetTempString();
sprintf (s, "entity %i", G_EDICTNUM(OFS_PARM0));
- G_INT(OFS_RETURN) = s - pr_strings;
+ G_INT(OFS_RETURN) = PR_SetString(s);
}
void PF_Spawn (void)
{
edict_t *ed;
+ pr_xfunction->builtinsprofile += 20;
ed = ED_Alloc();
RETURN_EDICT(ed);
}
void PF_Remove (void)
{
edict_t *ed;
+ pr_xfunction->builtinsprofile += 20;
ed = G_EDICT(OFS_PARM0);
if (ed == sv.edicts)
for (e++ ; e < sv.num_edicts ; e++)
{
+ pr_xfunction->builtinsprofile++;
ed = EDICT_NUM(e);
if (ed->free)
continue;
// LordHavoc: added this for searching float, int, and entity reference fields
void PF_FindFloat (void)
{
- int e;
+ int e;
int f;
float s;
edict_t *ed;
e = G_EDICTNUM(OFS_PARM0);
f = G_INT(OFS_PARM1);
s = G_FLOAT(OFS_PARM2);
-
+
for (e++ ; e < sv.num_edicts ; e++)
{
+ pr_xfunction->builtinsprofile++;
ed = EDICT_NUM(e);
if (ed->free)
continue;
// entity(.string field, string match) findchain = #402;
void PF_findchain (void)
{
- int i;
+ int i;
int f;
char *s, *t;
edict_t *ent, *chain;
RETURN_EDICT(sv.edicts);
return;
}
-
+
ent = NEXT_EDICT(sv.edicts);
for (i = 1;i < sv.num_edicts;i++, ent = NEXT_EDICT(ent))
{
+ pr_xfunction->builtinsprofile++;
if (ent->free)
continue;
t = E_STRING(ent,f);
if (strcmp(t,s))
continue;
- ent->v.chain = EDICT_TO_PROG(chain);
+ ent->v->chain = EDICT_TO_PROG(chain);
chain = ent;
}
// entity(.string field, float match) findchainfloat = #403;
void PF_findchainfloat (void)
{
- int i;
+ int i;
int f;
float s;
edict_t *ent, *chain;
f = G_INT(OFS_PARM0);
s = G_FLOAT(OFS_PARM1);
-
+
ent = NEXT_EDICT(sv.edicts);
for (i = 1;i < sv.num_edicts;i++, ent = NEXT_EDICT(ent))
{
+ pr_xfunction->builtinsprofile++;
if (ent->free)
continue;
if (E_FLOAT(ent,f) != s)
continue;
- ent->v.chain = EDICT_TO_PROG(chain);
+ ent->v->chain = EDICT_TO_PROG(chain);
chain = ent;
}
s = G_STRING(OFS_PARM0);
G_INT(OFS_RETURN) = G_INT(OFS_PARM0);
PR_CheckEmptyString (s);
-
+
for (i=0 ; i<MAX_SOUNDS ; i++)
{
if (!sv.sound_precache[i])
{
char *s;
int i;
-
+
if (sv.state != ss_loading)
Host_Error ("PF_Precache_*: Precache can only be done in spawn functions");
edict_t *ent;
float yaw, dist;
vec3_t move;
- dfunction_t *oldf;
+ mfunction_t *oldf;
int oldself;
-
+
ent = PROG_TO_EDICT(pr_global_struct->self);
yaw = G_FLOAT(OFS_PARM0);
dist = G_FLOAT(OFS_PARM1);
-
- if ( !( (int)ent->v.flags & (FL_ONGROUND|FL_FLY|FL_SWIM) ) )
+
+ if ( !( (int)ent->v->flags & (FL_ONGROUND|FL_FLY|FL_SWIM) ) )
{
G_FLOAT(OFS_RETURN) = 0;
return;
}
yaw = yaw*M_PI*2 / 360;
-
+
move[0] = cos(yaw)*dist;
move[1] = sin(yaw)*dist;
move[2] = 0;
// save program state, because SV_movestep may call other progs
oldf = pr_xfunction;
oldself = pr_global_struct->self;
-
+
G_FLOAT(OFS_RETURN) = SV_movestep(ent, move, true);
-
-
+
+
// restore program state
pr_xfunction = oldf;
pr_global_struct->self = oldself;
ent = PROG_TO_EDICT(pr_global_struct->self);
- VectorCopy (ent->v.origin, end);
+ VectorCopy (ent->v->origin, end);
end[2] -= 256;
- trace = SV_Move (ent->v.origin, ent->v.mins, ent->v.maxs, end, MOVE_NORMAL, ent);
+ trace = SV_Move (ent->v->origin, ent->v->mins, ent->v->maxs, end, MOVE_NORMAL, ent);
- if (trace.fraction == 1 || trace.allsolid)
+ if (trace.fraction == 1)
G_FLOAT(OFS_RETURN) = 0;
else
{
- VectorCopy (trace.endpos, ent->v.origin);
+ VectorCopy (trace.endpos, ent->v->origin);
SV_LinkEdict (ent, false);
- ent->v.flags = (int)ent->v.flags | FL_ONGROUND;
- ent->v.groundentity = EDICT_TO_PROG(trace.ent);
+ ent->v->flags = (int)ent->v->flags | FL_ONGROUND;
+ ent->v->groundentity = EDICT_TO_PROG(trace.ent);
G_FLOAT(OFS_RETURN) = 1;
// if support is destroyed, keep suspended (gross hack for floating items in various maps)
ent->suspendedinairflag = true;
i = G_EDICTNUM(OFS_PARM0);
while (1)
{
+ pr_xfunction->builtinsprofile++;
i++;
if (i == sv.num_edicts)
{
ent = G_EDICT(OFS_PARM0);
speed = G_FLOAT(OFS_PARM1);
- VectorCopy (ent->v.origin, start);
+ VectorCopy (ent->v->origin, start);
start[2] += 20;
// try sending a trace straight
VectorCopy (pr_global_struct->v_forward, dir);
VectorMA (start, 2048, dir, end);
tr = SV_Move (start, vec3_origin, vec3_origin, end, MOVE_NORMAL, ent);
- if (tr.ent && ((edict_t *)tr.ent)->v.takedamage == DAMAGE_AIM
- && (!teamplay.integer || ent->v.team <=0 || ent->v.team != ((edict_t *)tr.ent)->v.team) )
+ if (tr.ent && ((edict_t *)tr.ent)->v->takedamage == DAMAGE_AIM
+ && (!teamplay.integer || ent->v->team <=0 || ent->v->team != ((edict_t *)tr.ent)->v->team) )
{
VectorCopy (pr_global_struct->v_forward, G_VECTOR(OFS_RETURN));
return;
check = NEXT_EDICT(sv.edicts);
for (i=1 ; i<sv.num_edicts ; i++, check = NEXT_EDICT(check) )
{
- if (check->v.takedamage != DAMAGE_AIM)
+ pr_xfunction->builtinsprofile++;
+ if (check->v->takedamage != DAMAGE_AIM)
continue;
if (check == ent)
continue;
- if (teamplay.integer && ent->v.team > 0 && ent->v.team == check->v.team)
+ if (teamplay.integer && ent->v->team > 0 && ent->v->team == check->v->team)
continue; // don't aim at teammate
for (j=0 ; j<3 ; j++)
- end[j] = check->v.origin[j]
- + 0.5*(check->v.mins[j] + check->v.maxs[j]);
+ end[j] = check->v->origin[j]
+ + 0.5*(check->v->mins[j] + check->v->maxs[j]);
VectorSubtract (end, start, dir);
VectorNormalize (dir);
dist = DotProduct (dir, pr_global_struct->v_forward);
if (bestent)
{
- VectorSubtract (bestent->v.origin, ent->v.origin, dir);
+ VectorSubtract (bestent->v->origin, ent->v->origin, dir);
dist = DotProduct (dir, pr_global_struct->v_forward);
VectorScale (pr_global_struct->v_forward, dist, end);
end[2] = dir[2];
float ideal, current, move, speed;
ent = PROG_TO_EDICT(pr_global_struct->self);
- current = ANGLEMOD(ent->v.angles[1]);
- ideal = ent->v.ideal_yaw;
- speed = ent->v.yaw_speed;
+ current = ANGLEMOD(ent->v->angles[1]);
+ ideal = ent->v->ideal_yaw;
+ speed = ent->v->yaw_speed;
if (current == ideal)
return;
move = -speed;
}
- ent->v.angles[1] = ANGLEMOD (current + move);
+ ent->v->angles[1] = ANGLEMOD (current + move);
}
/*
eval_t *val;
ent = G_EDICT(OFS_PARM0);
- current = ANGLEMOD( ent->v.angles[0] );
+ current = ANGLEMOD( ent->v->angles[0] );
if ((val = GETEDICTFIELDVALUE(ent, eval_idealpitch)))
ideal = val->_float;
else
move = -speed;
}
- ent->v.angles[0] = ANGLEMOD (current + move);
+ ent->v->angles[0] = ANGLEMOD (current + move);
}
/*
ent = G_EDICT(OFS_PARM0);
large = false;
- if (ent->v.modelindex >= 256 || ent->v.frame >= 256)
+ if (ent->v->modelindex >= 256 || ent->v->frame >= 256)
large = true;
if (large)
{
MSG_WriteByte (&sv.signon,svc_spawnstatic2);
- MSG_WriteShort (&sv.signon, ent->v.modelindex);
- MSG_WriteShort (&sv.signon, ent->v.frame);
+ MSG_WriteShort (&sv.signon, ent->v->modelindex);
+ MSG_WriteShort (&sv.signon, ent->v->frame);
}
else
{
MSG_WriteByte (&sv.signon,svc_spawnstatic);
- MSG_WriteByte (&sv.signon, ent->v.modelindex);
- MSG_WriteByte (&sv.signon, ent->v.frame);
+ MSG_WriteByte (&sv.signon, ent->v->modelindex);
+ MSG_WriteByte (&sv.signon, ent->v->frame);
}
- MSG_WriteByte (&sv.signon, ent->v.colormap);
- MSG_WriteByte (&sv.signon, ent->v.skin);
+ MSG_WriteByte (&sv.signon, ent->v->colormap);
+ MSG_WriteByte (&sv.signon, ent->v->skin);
for (i=0 ; i<3 ; i++)
{
- MSG_WriteDPCoord(&sv.signon, ent->v.origin[i]);
- MSG_WriteAngle(&sv.signon, ent->v.angles[i]);
+ MSG_WriteDPCoord(&sv.signon, ent->v->origin[i]);
+ MSG_WriteAngle(&sv.signon, ent->v->angles[i]);
}
// throw the entity away now
edict_t *in, *out;
in = G_EDICT(OFS_PARM0);
out = G_EDICT(OFS_PARM1);
- memcpy(out, in, pr_edict_size);
+ memcpy(out->v, in->v, progs->entityfields * 4);
}
/*
=================
-PF_setcolor
+PF_setcolors
sets the color of a client and broadcasts the update to all connected clients
-setcolor(clientent, value)
+setcolors(clientent, value)
=================
*/
-void PF_setcolor (void)
+void PF_setcolors (void)
{
client_t *client;
int entnum, i;
client = &svs.clients[entnum-1];
client->colors = i;
- client->edict->v.team = (i & 15) + 1;
+ client->edict->v->team = (i & 15) + 1;
MSG_WriteByte (&sv.reliable_datagram, svc_updatecolors);
MSG_WriteByte (&sv.reliable_datagram, entnum - 1);
model_t *model;
if (!ed || ed->free)
return NULL;
- modelindex = ed->v.modelindex;
+ modelindex = ed->v->modelindex;
if (modelindex < 1 || modelindex >= MAX_MODELS)
return NULL;
model = sv.models[modelindex];
if (pointnum < 0 || pointnum >= surf->poly_numverts)
return;
// FIXME: implement rotation/scaling
- VectorAdd(&surf->poly_verts[pointnum * 3], ed->v.origin, G_VECTOR(OFS_RETURN));
+ VectorAdd(&surf->poly_verts[pointnum * 3], ed->v->origin, G_VECTOR(OFS_RETURN));
}
//PF_getsurfacenormal, // #436 vector(entity e, float s) getsurfacenormal = #436;
void PF_getsurfacenormal(void)
G_INT(OFS_RETURN) = 0;
if (!(surf = getsurface(G_EDICT(OFS_PARM0), G_FLOAT(OFS_PARM1))))
return;
- G_INT(OFS_RETURN) = surf->texinfo->texture->name - pr_strings;
+ G_INT(OFS_RETURN) = PR_SetString(surf->texinfo->texture->name);
}
//PF_getsurfacenearpoint, // #438 float(entity e, vector p) getsurfacenearpoint = #438;
void PF_getsurfacenearpoint(void)
if (!ed || ed->free)
return;
- modelindex = ed->v.modelindex;
+ modelindex = ed->v->modelindex;
if (modelindex < 1 || modelindex >= MAX_MODELS)
return;
model = sv.models[modelindex];
return;
// FIXME: implement rotation/scaling
- VectorSubtract(point, ed->v.origin, p);
+ VectorSubtract(point, ed->v->origin, p);
best = -1;
bestdist = 1000000000;
for (surfnum = 0;surfnum < model->nummodelsurfaces;surfnum++)
if (!(surf = getsurface(ed, G_FLOAT(OFS_PARM1))))
return;
// FIXME: implement rotation/scaling
- VectorSubtract(G_VECTOR(OFS_PARM2), ed->v.origin, p);
+ VectorSubtract(G_VECTOR(OFS_PARM2), ed->v->origin, p);
clippointtosurface(surf, p, out);
// FIXME: implement rotation/scaling
- VectorAdd(out, ed->v.origin, G_VECTOR(OFS_RETURN));
+ VectorAdd(out, ed->v->origin, G_VECTOR(OFS_RETURN));
}
void PF_Fixme (void)
Host_Error ("unimplemented QC builtin"); // LordHavoc: was misspelled (bulitin)
}
+#define MAX_PRFILES 256
+
+qfile_t *pr_files[MAX_PRFILES];
+
+void PR_Files_Init(void)
+{
+ memset(pr_files, 0, sizeof(pr_files));
+}
+
+void PR_Files_CloseAll(void)
+{
+ int i;
+ for (i = 0;i < MAX_PRFILES;i++)
+ {
+ if (pr_files[i])
+ FS_Close(pr_files[i]);
+ pr_files[i] = NULL;
+ }
+}
+
+//float(string s) stof = #81; // get numerical value from a string
+void PF_stof(void)
+{
+ char *s = PF_VarString(0);
+ G_FLOAT(OFS_RETURN) = atof(s);
+}
+
+//float(string filename, float mode) fopen = #110; // opens a file inside quake/gamedir/data/ (mode is FILE_READ, FILE_APPEND, or FILE_WRITE), returns fhandle >= 0 if successful, or fhandle < 0 if unable to open file for any reason
+void PF_fopen(void)
+{
+ int filenum, mode;
+ char *modestring, *filename;
+ for (filenum = 0;filenum < MAX_PRFILES;filenum++)
+ if (pr_files[filenum] == NULL)
+ break;
+ if (filenum >= MAX_PRFILES)
+ {
+ Con_Printf("PF_fopen: ran out of file handles (%i)\n", MAX_PRFILES);
+ G_FLOAT(OFS_RETURN) = -2;
+ return;
+ }
+ mode = G_FLOAT(OFS_PARM1);
+ switch(mode)
+ {
+ case 0: // FILE_READ
+ modestring = "rb";
+ break;
+ case 1: // FILE_APPEND
+ modestring = "ab";
+ break;
+ case 2: // FILE_WRITE
+ modestring = "wb";
+ break;
+ default:
+ Con_Printf("PF_fopen: no such mode %i (valid: 0 = read, 1 = append, 2 = write)\n", mode);
+ G_FLOAT(OFS_RETURN) = -3;
+ return;
+ }
+ filename = G_STRING(OFS_PARM0);
+ // .. is parent directory on many platforms
+ // / is parent directory on Amiga
+ // : is root of drive on Amiga (also used as a directory separator on Mac, but / works there too, so that's a bad idea)
+ // \ is a windows-ism (so it's naughty to use it, / works on all platforms)
+ if ((filename[0] == '.' && filename[1] == '.') || filename[0] == '/' || strrchr(filename, ':') || strrchr(filename, '\\'))
+ {
+ Con_Printf("PF_fopen: dangerous or non-portable filename \"%s\" not allowed. (contains : or \\ or begins with .. or /)\n", filename);
+ G_FLOAT(OFS_RETURN) = -4;
+ return;
+ }
+ pr_files[filenum] = FS_Open(va("data/%s", filename), modestring, false);
+ if (pr_files[filenum] == NULL)
+ G_FLOAT(OFS_RETURN) = -1;
+ else
+ G_FLOAT(OFS_RETURN) = filenum;
+}
+
+//void(float fhandle) fclose = #111; // closes a file
+void PF_fclose(void)
+{
+ int filenum = G_FLOAT(OFS_PARM0);
+ if (filenum < 0 || filenum >= MAX_PRFILES)
+ {
+ Con_Printf("PF_fclose: invalid file handle %i\n", filenum);
+ return;
+ }
+ if (pr_files[filenum] == NULL)
+ {
+ Con_Printf("PF_fclose: no such file handle %i (or file has been closed)\n", filenum);
+ return;
+ }
+ FS_Close(pr_files[filenum]);
+ pr_files[filenum] = NULL;
+}
+
+//string(float fhandle) fgets = #112; // reads a line of text from the file and returns as a tempstring
+void PF_fgets(void)
+{
+ int c, end;
+ static char string[MAX_VARSTRING];
+ int filenum = G_FLOAT(OFS_PARM0);
+ if (filenum < 0 || filenum >= MAX_PRFILES)
+ {
+ Con_Printf("PF_fgets: invalid file handle %i\n", filenum);
+ return;
+ }
+ if (pr_files[filenum] == NULL)
+ {
+ Con_Printf("PF_fgets: no such file handle %i (or file has been closed)\n", filenum);
+ return;
+ }
+ end = 0;
+ for (;;)
+ {
+ c = FS_Getc(pr_files[filenum]);
+ if (c == '\r' || c == '\n' || c < 0)
+ break;
+ if (end < MAX_VARSTRING - 1)
+ string[end++] = c;
+ }
+ string[end] = 0;
+ // remove \n following \r
+ if (c == '\r')
+ c = FS_Getc(pr_files[filenum]);
+ if (developer.integer)
+ Con_Printf("fgets: %s\n", string);
+ if (c >= 0)
+ G_INT(OFS_RETURN) = PR_SetString(string);
+ else
+ G_INT(OFS_RETURN) = 0;
+}
+
+//void(float fhandle, string s) fputs = #113; // writes a line of text to the end of the file
+void PF_fputs(void)
+{
+ int stringlength;
+ char *s = PF_VarString(1);
+ int filenum = G_FLOAT(OFS_PARM0);
+ if (filenum < 0 || filenum >= MAX_PRFILES)
+ {
+ Con_Printf("PF_fputs: invalid file handle %i\n", filenum);
+ return;
+ }
+ if (pr_files[filenum] == NULL)
+ {
+ Con_Printf("PF_fputs: no such file handle %i (or file has been closed)\n", filenum);
+ return;
+ }
+ if ((stringlength = strlen(s)))
+ FS_Write(pr_files[filenum], s, stringlength);
+ if (developer.integer)
+ Con_Printf("fputs: %s\n", s);
+}
+
+//float(string s) strlen = #114; // returns how many characters are in a string
+void PF_strlen(void)
+{
+ char *s;
+ s = G_STRING(OFS_PARM0);
+ if (s)
+ G_FLOAT(OFS_RETURN) = strlen(s);
+ else
+ G_FLOAT(OFS_RETURN) = 0;
+}
+
+//string(string s1, string s2) strcat = #115; // concatenates two strings (for example "abc", "def" would return "abcdef") and returns as a tempstring
+void PF_strcat(void)
+{
+ char *s = PF_VarString(0);
+ G_INT(OFS_RETURN) = PR_SetString(s);
+}
+
+//string(string s, float start, float length) substring = #116; // returns a section of a string as a tempstring
+void PF_substring(void)
+{
+ int end, start, length, slen;
+ char *s;
+ char string[MAX_VARSTRING];
+ s = G_STRING(OFS_PARM0);
+ start = G_FLOAT(OFS_PARM1);
+ length = G_FLOAT(OFS_PARM2);
+ if (s)
+ slen = strlen(s);
+ else
+ slen = 0;
+ if (start < 0)
+ start = 0;
+ if (length > slen - start)
+ length = slen - start;
+ if (length > MAX_VARSTRING - 1)
+ length = MAX_VARSTRING - 1;
+ end = 0;
+ if (length > 0)
+ {
+ memcpy(string, s + start, length);
+ end = length;
+ }
+ string[end] = 0;
+ G_INT(OFS_RETURN) = PR_SetString(string);
+}
+
+//vector(string s) stov = #117; // returns vector value from a string
+void PF_stov(void)
+{
+ Math_atov(PF_VarString(0), G_VECTOR(OFS_RETURN));
+}
+//string(string s) strzone = #118; // makes a copy of a string into the string zone and returns it, this is often used to keep around a tempstring for longer periods of time (tempstrings are replaced often)
+void PF_strzone(void)
+{
+ char *in, *out;
+ in = G_STRING(OFS_PARM0);
+ out = Mem_Alloc(pr_strings_mempool, strlen(in) + 1);
+ strcpy(out, in);
+ G_INT(OFS_RETURN) = PR_SetString(out);
+}
+
+//void(string s) strunzone = #119; // removes a copy of a string from the string zone (you can not use that string again or it may crash!!!)
+void PF_strunzone(void)
+{
+ Mem_Free(G_STRING(OFS_PARM0));
+}
builtin_t pr_builtin[] =
{
PF_Fixme, // #79 LordHavoc: dunno who owns 79-89, so these are just padding
PF_Fixme, // #80
-PF_Fixme, // #81
+PF_stof, // #81 float(string s) stof = #81;
PF_Fixme, // #82
PF_Fixme, // #83
PF_Fixme, // #84
PF_FindFloat, // #98
PF_checkextension, // #99
#define a PF_Fixme, PF_Fixme, PF_Fixme, PF_Fixme, PF_Fixme, PF_Fixme, PF_Fixme, PF_Fixme, PF_Fixme, PF_Fixme,
-#define aa a a a a a a a a a a
-aa // #200
-aa // #300
-aa // #400
+a // #100-109
+PF_fopen, // #110 float(string filename, float mode) fopen = #110;
+PF_fclose, // #111 void(float fhandle) fclose = #111;
+PF_fgets, // #112 string(float fhandle) fgets = #112;
+PF_fputs, // #113 void(float fhandle, string s) fputs = #113;
+PF_strlen, // #114 float(string s) strlen = #114;
+PF_strcat, // #115 string(string s1, string s2) strcat = #115;
+PF_substring, // #116 string(string s, float start, float length) substring = #116;
+PF_stov, // #117 vector(string) stov = #117;
+PF_strzone, // #118 string(string s) strzone = #118;
+PF_strunzone, // #119 void(string s) strunzone = #119;
+a // #120-129
+a // #130-139
+a // #140-149
+a // #150-159
+a // #160-169
+a // #170-179
+a // #180-189
+a // #190-199
+a a a a a a a a a a // #200-299
+a a a a a a a a a a // #300-399
PF_copyentity, // #400 LordHavoc: builtin range (4xx)
-PF_setcolor, // #401
+PF_setcolors, // #401
PF_findchain, // #402
PF_findchainfloat, // #403
PF_effect, // #404
builtin_t *pr_builtins = pr_builtin;
int pr_numbuiltins = sizeof(pr_builtin)/sizeof(pr_builtin[0]);
+void PR_Cmd_Init(void)
+{
+ pr_strings_mempool = Mem_AllocPool("pr_stringszone");
+ PR_Files_Init();
+}
+
+void PR_Cmd_Reset(void)
+{
+ Mem_EmptyPool(pr_strings_mempool);
+ PR_Files_CloseAll();
+}
+