2001-08-21 22:34:20 +00:00
|
|
|
/*
|
|
|
|
pr_cmds.c
|
|
|
|
|
|
|
|
(description)
|
|
|
|
|
|
|
|
Copyright (C) 1996-1997 Id Software, Inc.
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
|
|
|
See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to:
|
|
|
|
|
|
|
|
Free Software Foundation, Inc.
|
|
|
|
59 Temple Place - Suite 330
|
|
|
|
Boston, MA 02111-1307, USA
|
|
|
|
|
|
|
|
*/
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
2003-01-15 15:31:36 +00:00
|
|
|
|
2001-09-10 12:56:23 +00:00
|
|
|
#ifdef HAVE_ERRNO_H
|
|
|
|
# include <errno.h>
|
|
|
|
#endif
|
2001-08-21 22:34:20 +00:00
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
# include <string.h>
|
|
|
|
#endif
|
2001-08-26 01:08:09 +00:00
|
|
|
#ifdef HAVE_STRINGS_H
|
|
|
|
# include <strings.h>
|
|
|
|
#endif
|
|
|
|
|
2001-08-22 03:24:25 +00:00
|
|
|
#include <stdlib.h>
|
2001-08-21 22:34:20 +00:00
|
|
|
|
|
|
|
#include "QF/cvar.h"
|
2004-01-04 07:42:43 +00:00
|
|
|
#include "QF/dstring.h"
|
2001-08-26 01:08:09 +00:00
|
|
|
#include "QF/mathlib.h"
|
2001-08-22 03:24:25 +00:00
|
|
|
#include "QF/progs.h"
|
2001-09-21 04:22:46 +00:00
|
|
|
#include "QF/sys.h"
|
2001-08-22 03:24:25 +00:00
|
|
|
#include "QF/zone.h"
|
2001-08-21 22:34:20 +00:00
|
|
|
|
2001-08-29 17:45:53 +00:00
|
|
|
#include "compat.h"
|
|
|
|
|
2007-03-10 12:00:59 +00:00
|
|
|
VISIBLE const char *pr_gametype = "";
|
2002-01-20 03:09:03 +00:00
|
|
|
|
2001-09-10 12:56:23 +00:00
|
|
|
/* BUILT-IN FUNCTIONS */
|
2001-08-21 22:34:20 +00:00
|
|
|
|
2007-03-10 12:00:59 +00:00
|
|
|
VISIBLE char *
|
2022-02-06 10:34:46 +00:00
|
|
|
PF_VarString (progs_t *pr, int first, int argc)
|
2001-08-21 22:34:20 +00:00
|
|
|
{
|
2007-06-09 09:43:21 +00:00
|
|
|
char *out, *dst;
|
|
|
|
const char *src;
|
2001-09-10 12:56:23 +00:00
|
|
|
int len, i;
|
2022-02-04 13:15:24 +00:00
|
|
|
pr_type_t **argv = pr->pr_params;
|
|
|
|
|
|
|
|
for (len = 0, i = first; i < argc; i++)
|
2022-04-26 06:10:00 +00:00
|
|
|
len += strlen (PR_GetString (pr, *(pr_string_t *) argv[i]));
|
2021-07-28 06:01:45 +00:00
|
|
|
dst = out = Hunk_TempAlloc (0, len + 1);
|
2022-02-04 13:15:24 +00:00
|
|
|
for (i = first; i < argc; i++) {
|
2022-04-26 06:10:00 +00:00
|
|
|
src = PR_GetString (pr, PR_PTR (string, argv[i]));
|
2007-06-09 09:43:21 +00:00
|
|
|
while (*src)
|
|
|
|
*dst++ = *src++;
|
|
|
|
}
|
|
|
|
*dst = 0;
|
2001-08-21 22:34:20 +00:00
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2004-01-04 07:42:43 +00:00
|
|
|
vector (vector v) normalize
|
2001-08-21 22:34:20 +00:00
|
|
|
*/
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
PF_normalize (progs_t *pr, void *data)
|
2001-08-21 22:34:20 +00:00
|
|
|
{
|
2001-09-10 12:56:23 +00:00
|
|
|
float new;
|
|
|
|
float *value1;
|
|
|
|
vec3_t newvalue;
|
2001-08-21 22:34:20 +00:00
|
|
|
|
2002-07-24 21:42:33 +00:00
|
|
|
value1 = P_VECTOR (pr, 0);
|
2001-08-21 22:34:20 +00:00
|
|
|
|
2001-08-26 01:08:09 +00:00
|
|
|
new = value1[0] * value1[0] + value1[1] * value1[1] + value1[2] *
|
|
|
|
value1[2];
|
2001-08-21 22:34:20 +00:00
|
|
|
new = sqrt (new);
|
|
|
|
|
|
|
|
if (new == 0)
|
|
|
|
newvalue[0] = newvalue[1] = newvalue[2] = 0;
|
|
|
|
else {
|
|
|
|
new = 1 / new;
|
|
|
|
newvalue[0] = value1[0] * new;
|
|
|
|
newvalue[1] = value1[1] * new;
|
|
|
|
newvalue[2] = value1[2] * new;
|
|
|
|
}
|
|
|
|
|
2002-07-24 21:42:33 +00:00
|
|
|
VectorCopy (newvalue, R_VECTOR (pr));
|
2001-08-21 22:34:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2004-01-04 07:42:43 +00:00
|
|
|
float (vector v) vlen
|
2001-08-21 22:34:20 +00:00
|
|
|
*/
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
PF_vlen (progs_t *pr, void *data)
|
2001-08-21 22:34:20 +00:00
|
|
|
{
|
2001-09-10 12:56:23 +00:00
|
|
|
float new;
|
|
|
|
float *value1;
|
2001-08-21 22:34:20 +00:00
|
|
|
|
2002-07-24 21:42:33 +00:00
|
|
|
value1 = P_VECTOR (pr, 0);
|
2001-08-21 22:34:20 +00:00
|
|
|
|
2001-08-26 01:08:09 +00:00
|
|
|
new = value1[0] * value1[0] + value1[1] * value1[1] + value1[2] *
|
|
|
|
value1[2];
|
2001-08-21 22:34:20 +00:00
|
|
|
new = sqrt (new);
|
|
|
|
|
2002-07-24 21:42:33 +00:00
|
|
|
R_FLOAT (pr) = new;
|
2001-08-21 22:34:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2004-01-04 07:42:43 +00:00
|
|
|
float (vector v) vectoyaw
|
2001-08-21 22:34:20 +00:00
|
|
|
*/
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
PF_vectoyaw (progs_t *pr, void *data)
|
2001-08-21 22:34:20 +00:00
|
|
|
{
|
2001-09-10 12:56:23 +00:00
|
|
|
float yaw;
|
|
|
|
float *value1;
|
2001-08-21 22:34:20 +00:00
|
|
|
|
2002-07-24 21:42:33 +00:00
|
|
|
value1 = P_VECTOR (pr, 0);
|
2001-08-21 22:34:20 +00:00
|
|
|
|
|
|
|
if (value1[1] == 0 && value1[0] == 0)
|
|
|
|
yaw = 0;
|
|
|
|
else {
|
|
|
|
yaw = (int) (atan2 (value1[1], value1[0]) * 180 / M_PI);
|
|
|
|
if (yaw < 0)
|
|
|
|
yaw += 360;
|
|
|
|
}
|
|
|
|
|
2002-07-24 21:42:33 +00:00
|
|
|
R_FLOAT (pr) = yaw;
|
2001-08-21 22:34:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2004-01-04 07:42:43 +00:00
|
|
|
vector (vector v) vectoangles
|
2001-08-21 22:34:20 +00:00
|
|
|
*/
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
PF_vectoangles (progs_t *pr, void *data)
|
2001-08-21 22:34:20 +00:00
|
|
|
{
|
2001-09-10 12:56:23 +00:00
|
|
|
float forward, pitch, yaw;
|
|
|
|
float *value1;
|
2001-08-21 22:34:20 +00:00
|
|
|
|
2002-07-24 21:42:33 +00:00
|
|
|
value1 = P_VECTOR (pr, 0);
|
2001-08-21 22:34:20 +00:00
|
|
|
|
|
|
|
if (value1[1] == 0 && value1[0] == 0) {
|
|
|
|
yaw = 0;
|
|
|
|
if (value1[2] > 0)
|
|
|
|
pitch = 90;
|
|
|
|
else
|
|
|
|
pitch = 270;
|
|
|
|
} else {
|
|
|
|
yaw = (int) (atan2 (value1[1], value1[0]) * 180 / M_PI);
|
|
|
|
if (yaw < 0)
|
|
|
|
yaw += 360;
|
|
|
|
|
|
|
|
forward = sqrt (value1[0] * value1[0] + value1[1] * value1[1]);
|
|
|
|
pitch = (int) (atan2 (value1[2], forward) * 180 / M_PI);
|
|
|
|
if (pitch < 0)
|
|
|
|
pitch += 360;
|
|
|
|
}
|
|
|
|
|
2002-07-25 14:58:02 +00:00
|
|
|
R_VECTOR (pr)[0] = pitch;
|
|
|
|
R_VECTOR (pr)[1] = yaw;
|
|
|
|
R_VECTOR (pr)[2] = 0;
|
2001-08-21 22:34:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2004-01-04 07:42:43 +00:00
|
|
|
float () random
|
2001-08-21 22:34:20 +00:00
|
|
|
|
|
|
|
Returns a number from 0<= num < 1
|
|
|
|
*/
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
PF_random (progs_t *pr, void *data)
|
2001-08-21 22:34:20 +00:00
|
|
|
{
|
2001-09-10 12:56:23 +00:00
|
|
|
float num;
|
2001-08-21 22:34:20 +00:00
|
|
|
|
|
|
|
num = (rand () & 0x7fff) / ((float) 0x7fff);
|
|
|
|
|
2002-07-24 21:42:33 +00:00
|
|
|
R_FLOAT (pr) = num;
|
2001-08-21 22:34:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2004-01-04 07:42:43 +00:00
|
|
|
void () break
|
2001-08-21 22:34:20 +00:00
|
|
|
*/
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
PF_break (progs_t *pr, void *data)
|
2001-08-21 22:34:20 +00:00
|
|
|
{
|
2001-09-21 04:22:46 +00:00
|
|
|
Sys_Printf ("break statement\n");
|
2002-09-07 06:48:15 +00:00
|
|
|
PR_DumpState (pr);
|
2001-08-21 22:34:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2012-05-21 23:23:22 +00:00
|
|
|
float (string s) cvar
|
2001-08-21 22:34:20 +00:00
|
|
|
*/
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
PF_cvar (progs_t *pr, void *data)
|
2001-08-21 22:34:20 +00:00
|
|
|
{
|
2001-09-10 12:56:23 +00:00
|
|
|
const char *str;
|
2001-08-21 22:34:20 +00:00
|
|
|
|
2003-04-22 18:20:15 +00:00
|
|
|
str = P_GSTRING (pr, 0);
|
2001-08-21 22:34:20 +00:00
|
|
|
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
R_FLOAT (pr) = Cvar_Value (str);
|
2001-08-21 22:34:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2004-01-04 07:42:43 +00:00
|
|
|
void (string var, string val) cvar_set
|
2001-08-21 22:34:20 +00:00
|
|
|
*/
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
PF_cvar_set (progs_t *pr, void *data)
|
2001-08-21 22:34:20 +00:00
|
|
|
{
|
2001-09-10 12:56:23 +00:00
|
|
|
const char *var_name, *val;
|
|
|
|
cvar_t *var;
|
2001-08-21 22:34:20 +00:00
|
|
|
|
2003-04-22 18:20:15 +00:00
|
|
|
var_name = P_GSTRING (pr, 0);
|
|
|
|
val = P_GSTRING (pr, 1);
|
2001-08-21 22:34:20 +00:00
|
|
|
var = Cvar_FindVar (var_name);
|
|
|
|
if (!var)
|
|
|
|
var = Cvar_FindAlias (var_name);
|
|
|
|
if (!var) {
|
2001-09-21 04:22:46 +00:00
|
|
|
Sys_Printf ("PF_cvar_set: variable %s not found\n", var_name);
|
2001-08-21 22:34:20 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
Cvar_SetVar (var, val);
|
2001-08-21 22:34:20 +00:00
|
|
|
}
|
|
|
|
|
2004-01-04 07:42:43 +00:00
|
|
|
/*
|
|
|
|
float (float f) fabs
|
|
|
|
*/
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
PF_fabs (progs_t *pr, void *data)
|
2001-08-21 22:34:20 +00:00
|
|
|
{
|
2001-09-10 12:56:23 +00:00
|
|
|
float v;
|
2001-08-21 22:34:20 +00:00
|
|
|
|
2002-07-24 21:42:33 +00:00
|
|
|
v = P_FLOAT (pr, 0);
|
|
|
|
R_FLOAT (pr) = fabs (v);
|
2001-08-21 22:34:20 +00:00
|
|
|
}
|
|
|
|
|
2004-01-04 07:42:43 +00:00
|
|
|
/*
|
|
|
|
entity (entity start, .(...) fld, ... match) find
|
|
|
|
*/
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
PF_find (progs_t *pr, void *data)
|
2001-08-21 22:34:20 +00:00
|
|
|
{
|
2004-01-04 07:42:43 +00:00
|
|
|
const char *s = 0, *t; // ev_string
|
|
|
|
int i; // ev_vector
|
2022-01-16 13:15:18 +00:00
|
|
|
pr_uint_t e, f;
|
2001-09-21 19:28:08 +00:00
|
|
|
etype_t type;
|
2020-02-22 13:33:44 +00:00
|
|
|
pr_def_t *field_def;
|
2001-09-10 12:56:23 +00:00
|
|
|
edict_t *ed;
|
2001-08-21 22:34:20 +00:00
|
|
|
|
2002-07-24 21:42:33 +00:00
|
|
|
e = P_EDICTNUM (pr, 0);
|
|
|
|
f = P_INT (pr, 1);
|
2004-11-05 11:49:00 +00:00
|
|
|
field_def = PR_FieldAtOfs (pr, f);
|
2001-08-26 06:35:03 +00:00
|
|
|
if (!field_def)
|
2003-01-20 21:28:36 +00:00
|
|
|
PR_RunError (pr, "PF_Find: bad search field: %d", f);
|
2001-08-26 06:35:03 +00:00
|
|
|
type = field_def->type & ~DEF_SAVEGLOBAL;
|
|
|
|
|
|
|
|
if (type == ev_string) {
|
2003-04-22 18:20:15 +00:00
|
|
|
s = P_GSTRING (pr, 2);
|
2001-08-26 06:35:03 +00:00
|
|
|
if (!s)
|
|
|
|
PR_RunError (pr, "PF_Find: bad search string");
|
|
|
|
}
|
2001-08-21 22:34:20 +00:00
|
|
|
|
2001-08-22 03:24:25 +00:00
|
|
|
for (e++; e < *pr->num_edicts; e++) {
|
2001-08-21 22:34:20 +00:00
|
|
|
ed = EDICT_NUM (pr, e);
|
|
|
|
if (ed->free)
|
|
|
|
continue;
|
2001-08-26 06:35:03 +00:00
|
|
|
switch (type) {
|
|
|
|
case ev_string:
|
2003-04-22 18:20:15 +00:00
|
|
|
t = E_GSTRING (pr, ed, f);
|
2001-08-26 06:35:03 +00:00
|
|
|
if (!t)
|
|
|
|
continue;
|
|
|
|
if (strcmp (t, s))
|
|
|
|
continue;
|
|
|
|
RETURN_EDICT (pr, ed);
|
|
|
|
return;
|
|
|
|
case ev_float:
|
2002-07-24 21:42:33 +00:00
|
|
|
if (P_FLOAT (pr, 2) != E_FLOAT (ed, f))
|
2001-08-26 06:35:03 +00:00
|
|
|
continue;
|
|
|
|
RETURN_EDICT (pr, ed);
|
|
|
|
return;
|
|
|
|
case ev_vector:
|
|
|
|
for (i = 0; i <= 2; i++)
|
2002-07-24 21:42:33 +00:00
|
|
|
if (P_FLOAT (pr, 2 + i) != E_FLOAT (ed, f + i))
|
2001-08-26 06:35:03 +00:00
|
|
|
continue;
|
|
|
|
RETURN_EDICT (pr, ed);
|
|
|
|
return;
|
2022-01-18 04:21:06 +00:00
|
|
|
case ev_int:
|
2001-08-26 06:35:03 +00:00
|
|
|
case ev_entity:
|
2002-07-24 21:42:33 +00:00
|
|
|
if (P_INT (pr, 2) != E_INT (ed, f))
|
2001-08-26 06:35:03 +00:00
|
|
|
continue;
|
|
|
|
RETURN_EDICT (pr, ed);
|
|
|
|
return;
|
|
|
|
default:
|
|
|
|
PR_Error (pr, "PF_Find: unsupported search field");
|
2001-08-21 22:34:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-17 05:11:54 +00:00
|
|
|
RETURN_EDICT (pr, EDICT_NUM (pr, 0));
|
2001-08-21 22:34:20 +00:00
|
|
|
}
|
|
|
|
|
2004-01-04 07:42:43 +00:00
|
|
|
/*
|
|
|
|
void () coredump
|
|
|
|
*/
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
PF_coredump (progs_t *pr, void *data)
|
2001-08-21 22:34:20 +00:00
|
|
|
{
|
|
|
|
ED_PrintEdicts (pr, "");
|
|
|
|
}
|
|
|
|
|
2004-01-04 07:42:43 +00:00
|
|
|
/*
|
|
|
|
void () traceon
|
|
|
|
*/
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
PF_traceon (progs_t *pr, void *data)
|
2001-08-21 22:34:20 +00:00
|
|
|
{
|
|
|
|
pr->pr_trace = true;
|
2004-11-07 03:00:00 +00:00
|
|
|
pr->pr_trace_depth = pr->pr_depth;
|
2001-08-21 22:34:20 +00:00
|
|
|
}
|
|
|
|
|
2004-01-04 07:42:43 +00:00
|
|
|
/*
|
|
|
|
void () traceoff
|
|
|
|
*/
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
PF_traceoff (progs_t *pr, void *data)
|
2001-08-21 22:34:20 +00:00
|
|
|
{
|
|
|
|
pr->pr_trace = false;
|
|
|
|
}
|
|
|
|
|
2004-01-04 07:42:43 +00:00
|
|
|
/*
|
|
|
|
void (entity e) eprint
|
|
|
|
*/
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
PF_eprint (progs_t *pr, void *data)
|
2001-08-21 22:34:20 +00:00
|
|
|
{
|
2021-07-25 00:54:08 +00:00
|
|
|
ED_PrintNum (pr, P_EDICTNUM (pr, 0), 0);
|
2001-08-21 22:34:20 +00:00
|
|
|
}
|
|
|
|
|
2004-01-04 07:42:43 +00:00
|
|
|
/*
|
|
|
|
void (string s) dprint
|
|
|
|
*/
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
PF_dprint (progs_t *pr, void *data)
|
2001-08-21 22:34:20 +00:00
|
|
|
{
|
2022-02-06 10:34:46 +00:00
|
|
|
Sys_Printf ("%s", PF_VarString (pr, 0, 1));
|
2001-08-21 22:34:20 +00:00
|
|
|
}
|
|
|
|
|
2004-01-04 07:42:43 +00:00
|
|
|
/*
|
|
|
|
float (float v) rint
|
|
|
|
*/
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
PF_rint (progs_t *pr, void *data)
|
2001-08-21 22:34:20 +00:00
|
|
|
{
|
2001-09-10 12:56:23 +00:00
|
|
|
float f;
|
2001-08-21 22:34:20 +00:00
|
|
|
|
2002-07-24 21:42:33 +00:00
|
|
|
f = P_FLOAT (pr, 0);
|
2001-08-21 22:34:20 +00:00
|
|
|
if (f > 0)
|
2002-07-24 21:42:33 +00:00
|
|
|
R_FLOAT (pr) = (int) (f + 0.5);
|
2001-08-21 22:34:20 +00:00
|
|
|
else
|
2002-07-24 21:42:33 +00:00
|
|
|
R_FLOAT (pr) = (int) (f - 0.5);
|
2001-08-21 22:34:20 +00:00
|
|
|
}
|
|
|
|
|
2004-01-04 07:42:43 +00:00
|
|
|
/*
|
|
|
|
float (float v) floor
|
|
|
|
*/
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
PF_floor (progs_t *pr, void *data)
|
2001-08-21 22:34:20 +00:00
|
|
|
{
|
2002-07-24 21:42:33 +00:00
|
|
|
R_FLOAT (pr) = floor (P_FLOAT (pr, 0));
|
2001-08-21 22:34:20 +00:00
|
|
|
}
|
|
|
|
|
2004-01-04 07:42:43 +00:00
|
|
|
/*
|
|
|
|
float (float v) ceil
|
|
|
|
*/
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
PF_ceil (progs_t *pr, void *data)
|
2001-08-21 22:34:20 +00:00
|
|
|
{
|
2002-07-24 21:42:33 +00:00
|
|
|
R_FLOAT (pr) = ceil (P_FLOAT (pr, 0));
|
2001-08-21 22:34:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2004-01-04 07:42:43 +00:00
|
|
|
entity (entity e) nextent
|
2001-08-21 22:34:20 +00:00
|
|
|
*/
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
PF_nextent (progs_t *pr, void *data)
|
2001-08-21 22:34:20 +00:00
|
|
|
{
|
2022-01-16 13:15:18 +00:00
|
|
|
pr_uint_t i;
|
2001-09-10 12:56:23 +00:00
|
|
|
edict_t *ent;
|
2001-08-21 22:34:20 +00:00
|
|
|
|
2002-07-24 21:42:33 +00:00
|
|
|
i = P_EDICTNUM (pr, 0);
|
2001-08-21 22:34:20 +00:00
|
|
|
while (1) {
|
|
|
|
i++;
|
2001-08-22 03:24:25 +00:00
|
|
|
if (i == *pr->num_edicts) {
|
2013-01-17 05:11:54 +00:00
|
|
|
RETURN_EDICT (pr, EDICT_NUM (pr, 0));
|
2001-08-21 22:34:20 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
ent = EDICT_NUM (pr, i);
|
|
|
|
if (!ent->free) {
|
|
|
|
RETURN_EDICT (pr, ent);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-09-26 22:26:31 +00:00
|
|
|
// we assume that ints are smaller than floats
|
|
|
|
#ifdef FLT_MAX_10_EXP
|
|
|
|
# define STRING_BUF (FLT_MAX_10_EXP + 8)
|
|
|
|
#else
|
|
|
|
# define STRING_BUF 128
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
2022-01-18 04:21:06 +00:00
|
|
|
int (float f) ftoi
|
2001-09-26 22:26:31 +00:00
|
|
|
*/
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
PF_ftoi (progs_t *pr, void *data)
|
2001-09-26 22:26:31 +00:00
|
|
|
{
|
2002-07-24 21:42:33 +00:00
|
|
|
R_INT (pr) = P_FLOAT (pr, 0);
|
2001-09-26 22:26:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
string (float f) ftos
|
|
|
|
*/
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
PF_ftos (progs_t *pr, void *data)
|
2001-09-26 22:26:31 +00:00
|
|
|
{
|
|
|
|
char string[STRING_BUF];
|
|
|
|
int i;
|
|
|
|
|
|
|
|
// trimming 0s idea thanks to Maddes
|
2002-07-24 21:42:33 +00:00
|
|
|
i = snprintf (string, sizeof (string), "%1.6f", P_FLOAT (pr, 0)) - 1;
|
2001-09-26 22:26:31 +00:00
|
|
|
for (; i > 0; i--) {
|
|
|
|
if (string[i] == '0')
|
|
|
|
string[i] = '\0';
|
|
|
|
else if (string[i] == '.') {
|
|
|
|
string[i] = '\0';
|
|
|
|
break;
|
|
|
|
} else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
RETURN_STRING (pr, string);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2022-01-18 04:21:06 +00:00
|
|
|
float (int i) itof
|
2001-09-26 22:26:31 +00:00
|
|
|
*/
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
PF_itof (progs_t *pr, void *data)
|
2001-09-26 22:26:31 +00:00
|
|
|
{
|
2002-07-24 21:42:33 +00:00
|
|
|
R_FLOAT (pr) = P_INT (pr, 0);
|
2001-09-26 22:26:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2022-01-18 04:21:06 +00:00
|
|
|
string (int i) itos
|
2001-09-26 22:26:31 +00:00
|
|
|
*/
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
PF_itos (progs_t *pr, void *data)
|
2001-09-26 22:26:31 +00:00
|
|
|
{
|
|
|
|
char string[STRING_BUF];
|
|
|
|
|
2002-07-24 21:42:33 +00:00
|
|
|
snprintf (string, sizeof (string), "%d", P_INT (pr, 0));
|
2001-09-26 22:26:31 +00:00
|
|
|
|
|
|
|
RETURN_STRING (pr, string);
|
|
|
|
}
|
|
|
|
|
2001-08-21 22:34:20 +00:00
|
|
|
/*
|
2001-09-26 22:26:31 +00:00
|
|
|
float (string s) stof
|
2001-08-21 22:34:20 +00:00
|
|
|
*/
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
PF_stof (progs_t *pr, void *data)
|
2001-08-21 22:34:20 +00:00
|
|
|
{
|
2003-04-22 18:20:15 +00:00
|
|
|
R_FLOAT (pr) = atof (P_GSTRING (pr, 0));
|
2001-09-26 22:26:31 +00:00
|
|
|
}
|
2001-08-21 22:34:20 +00:00
|
|
|
|
2001-09-26 22:26:31 +00:00
|
|
|
/*
|
2022-01-18 04:21:06 +00:00
|
|
|
int (string s) stoi
|
2001-09-26 22:26:31 +00:00
|
|
|
*/
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
PF_stoi (progs_t *pr, void *data)
|
2001-09-26 22:26:31 +00:00
|
|
|
{
|
2003-04-22 18:20:15 +00:00
|
|
|
R_INT (pr) = atoi (P_GSTRING (pr, 0));
|
2001-09-26 22:26:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
vector (string s) stov
|
|
|
|
*/
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
PF_stov (progs_t *pr, void *data)
|
2001-09-26 22:26:31 +00:00
|
|
|
{
|
|
|
|
float v[3] = {0, 0, 0};
|
|
|
|
|
2003-04-22 18:20:15 +00:00
|
|
|
sscanf (P_GSTRING (pr, 0), "'%f %f %f'", v, v + 1, v + 2);
|
2001-09-26 22:26:31 +00:00
|
|
|
|
|
|
|
RETURN_VECTOR (pr, v);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
string (vector v) vtos
|
|
|
|
*/
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
PF_vtos (progs_t *pr, void *data)
|
2001-09-26 22:26:31 +00:00
|
|
|
{
|
|
|
|
char string[STRING_BUF * 3 + 5];
|
|
|
|
|
|
|
|
snprintf (string, sizeof (string), "'%5.1f %5.1f %5.1f'",
|
2002-07-24 21:42:33 +00:00
|
|
|
P_VECTOR (pr, 0)[0],
|
|
|
|
P_VECTOR (pr, 0)[1],
|
|
|
|
P_VECTOR (pr, 0)[2]);
|
2001-08-21 22:34:20 +00:00
|
|
|
|
2001-09-26 22:26:31 +00:00
|
|
|
RETURN_STRING (pr, string);
|
2001-08-21 22:34:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2004-01-04 07:42:43 +00:00
|
|
|
float (string char, string s) charcount
|
2001-08-21 22:34:20 +00:00
|
|
|
*/
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
PF_charcount (progs_t *pr, void *data)
|
2001-08-21 22:34:20 +00:00
|
|
|
{
|
2001-09-10 12:56:23 +00:00
|
|
|
char goal;
|
2001-08-21 22:34:20 +00:00
|
|
|
const char *s;
|
2001-09-10 12:56:23 +00:00
|
|
|
int count;
|
2001-08-21 22:34:20 +00:00
|
|
|
|
2003-04-22 18:20:15 +00:00
|
|
|
goal = (P_GSTRING (pr, 0))[0];
|
2001-08-26 00:05:31 +00:00
|
|
|
if (goal == '\0') {
|
2002-07-24 21:42:33 +00:00
|
|
|
R_FLOAT (pr) = 0;
|
2001-08-26 00:05:31 +00:00
|
|
|
return;
|
|
|
|
}
|
2001-08-21 22:34:20 +00:00
|
|
|
|
|
|
|
count = 0;
|
2003-04-22 18:20:15 +00:00
|
|
|
s = P_GSTRING (pr, 1);
|
2001-08-21 22:34:20 +00:00
|
|
|
while (*s) {
|
|
|
|
if (*s == goal)
|
|
|
|
count++;
|
|
|
|
s++;
|
|
|
|
}
|
2002-07-24 21:42:33 +00:00
|
|
|
R_FLOAT (pr) = count;
|
2001-08-21 22:34:20 +00:00
|
|
|
}
|
|
|
|
|
2001-08-27 03:17:59 +00:00
|
|
|
#if (INT_MAX == 2147483647) && (INT_MIN == -2147483648)
|
|
|
|
# define INT_WIDTH 11
|
|
|
|
#else /* I hope... */
|
|
|
|
# define INT_WIDTH 20
|
|
|
|
#endif
|
|
|
|
|
2004-01-04 07:42:43 +00:00
|
|
|
/*
|
|
|
|
string () gametype
|
|
|
|
*/
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
PF_gametype (progs_t *pr, void *data)
|
2002-01-20 03:09:03 +00:00
|
|
|
{
|
|
|
|
RETURN_STRING (pr, pr_gametype);
|
|
|
|
}
|
|
|
|
|
2004-11-12 11:15:00 +00:00
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
PF_PR_SetField (progs_t *pr, void *data)
|
2004-11-12 11:15:00 +00:00
|
|
|
{
|
|
|
|
edict_t *ent = P_EDICT (pr, 0);
|
2020-02-22 13:33:44 +00:00
|
|
|
pr_def_t *field = PR_FindField (pr, P_GSTRING (pr, 1));
|
2004-11-12 11:15:00 +00:00
|
|
|
const char *value = P_GSTRING (pr, 2);
|
|
|
|
|
|
|
|
R_INT (pr) = 0;
|
|
|
|
if (field)
|
2013-01-17 05:11:54 +00:00
|
|
|
R_INT (pr) = ED_ParseEpair (pr, &E_fld (ent, 0), field, value);
|
2004-11-12 11:15:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
PF_PR_FindFunction (progs_t *pr, void *data)
|
2004-11-12 11:15:00 +00:00
|
|
|
{
|
|
|
|
dfunction_t *func = PR_FindFunction (pr, P_GSTRING (pr, 0));
|
|
|
|
R_FUNCTION (pr) = 0;
|
|
|
|
if (func)
|
|
|
|
R_FUNCTION (pr) = func - pr->pr_functions;
|
|
|
|
}
|
|
|
|
|
2004-01-06 07:00:39 +00:00
|
|
|
#define QF (PR_RANGE_QF << PR_RANGE_SHIFT) |
|
|
|
|
|
2022-01-23 12:54:03 +00:00
|
|
|
#define bi(x,n,np,params...) {#x, PF_##x, n, np, {params}}
|
|
|
|
#define p(type) PR_PARAM(type)
|
2004-01-04 07:42:43 +00:00
|
|
|
static builtin_t builtins[] = {
|
2022-01-23 12:54:03 +00:00
|
|
|
bi(break, 6, 0),
|
|
|
|
bi(random, 7, 0),
|
|
|
|
bi(normalize, 9, 1, p(vector)),
|
|
|
|
bi(vlen, 12, 1, p(vector)),
|
|
|
|
bi(vectoyaw, 13, 1, p(vector)),
|
|
|
|
bi(find, 18, -3, p(entity), p(field)),
|
|
|
|
bi(dprint, 25, -1),
|
|
|
|
bi(ftos, 26, 1, p(float)),
|
|
|
|
bi(vtos, 27, 1, p(vector)),
|
|
|
|
bi(coredump, 28, 0),
|
|
|
|
bi(traceon, 29, 0),
|
|
|
|
bi(traceoff, 30, 0),
|
|
|
|
bi(eprint, 31, 1, p(entity)),
|
|
|
|
bi(rint, 36, 1, p(float)),
|
|
|
|
bi(floor, 37, 1, p(float)),
|
|
|
|
bi(ceil, 38, 1, p(float)),
|
|
|
|
bi(fabs, 43, 1, p(float)),
|
|
|
|
bi(cvar, 45, 1, p(string)),
|
|
|
|
bi(nextent, 47, 1, p(entity)),
|
|
|
|
bi(vectoangles, 51, 1, p(vector)),
|
|
|
|
bi(cvar_set, 72, 2, p(string), p(string)),
|
|
|
|
bi(stof, 81, 1, p(string)),
|
|
|
|
|
|
|
|
|
|
|
|
bi(charcount, QF 101, 2, p(string), p(string)),
|
|
|
|
bi(ftoi, QF 110, 1, p(float)),
|
|
|
|
bi(itof, QF 111, 1, p(int)),
|
|
|
|
bi(itos, QF 112, 1, p(int)),
|
|
|
|
bi(stoi, QF 113, 1, p(string)),
|
|
|
|
bi(stov, QF 114, 1, p(string)),
|
|
|
|
bi(gametype, QF 115, 0),
|
|
|
|
|
|
|
|
bi(PR_SetField, -1, 3, p(entity), p(string), p(string)),
|
|
|
|
bi(PR_FindFunction, -1, 1, p(string)),
|
2004-01-06 05:51:09 +00:00
|
|
|
{0}
|
2004-01-04 07:42:43 +00:00
|
|
|
};
|
|
|
|
|
2007-03-10 12:00:59 +00:00
|
|
|
VISIBLE void
|
2001-08-22 03:24:25 +00:00
|
|
|
PR_Cmds_Init (progs_t *pr)
|
|
|
|
{
|
2022-01-23 15:20:05 +00:00
|
|
|
PR_RegisterBuiltins (pr, builtins, 0);
|
2004-01-06 05:51:09 +00:00
|
|
|
}
|