2000-05-10 20:33:16 +00:00
|
|
|
/*
|
2000-05-11 16:03:29 +00:00
|
|
|
pr_edict.c
|
2000-05-10 20:33:16 +00:00
|
|
|
|
2000-05-22 07:10:16 +00:00
|
|
|
entity dictionary
|
2000-05-10 20:33:16 +00:00
|
|
|
|
2000-05-11 16:03:29 +00:00
|
|
|
Copyright (C) 1996-1997 Id Software, Inc.
|
2000-05-10 20:33:16 +00:00
|
|
|
|
2000-05-11 16:03:29 +00:00
|
|
|
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.
|
2000-05-10 20:33:16 +00:00
|
|
|
|
2000-05-11 16:03:29 +00:00
|
|
|
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.
|
2000-05-10 20:33:16 +00:00
|
|
|
|
2000-05-11 16:03:29 +00:00
|
|
|
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
|
|
|
|
|
|
|
|
$Id$
|
2000-05-10 20:33:16 +00:00
|
|
|
*/
|
2000-05-10 11:29:38 +00:00
|
|
|
|
2000-05-17 10:03:19 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
2000-12-08 06:51:37 +00:00
|
|
|
# include "config.h"
|
2000-05-17 10:03:19 +00:00
|
|
|
#endif
|
2000-12-28 05:18:38 +00:00
|
|
|
|
2000-12-30 02:16:36 +00:00
|
|
|
#ifdef HAVE_STRING_H
|
2000-12-28 05:18:38 +00:00
|
|
|
#include <string.h>
|
2000-12-30 02:16:36 +00:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRINGS_H
|
|
|
|
#include <strings.h>
|
|
|
|
#endif
|
2000-12-28 05:18:38 +00:00
|
|
|
|
2000-05-21 08:24:45 +00:00
|
|
|
#include "cmd.h"
|
2000-12-28 05:18:38 +00:00
|
|
|
#include "console.h"
|
2000-05-21 08:24:45 +00:00
|
|
|
#include "crc.h"
|
2000-12-28 05:18:38 +00:00
|
|
|
#include "cvar.h"
|
|
|
|
#include "progs.h"
|
|
|
|
#include "qdefs.h"
|
2000-05-21 08:24:45 +00:00
|
|
|
#include "qendian.h"
|
|
|
|
#include "quakefs.h"
|
2000-12-28 05:18:38 +00:00
|
|
|
#include "server.h"
|
|
|
|
#include "world.h"
|
2000-05-21 08:24:45 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
cvar_t *r_skyname;
|
|
|
|
cvar_t *pr_boundscheck;
|
2000-10-29 22:02:29 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
void SV_Error (char *error, ...);
|
2000-12-31 07:43:09 +00:00
|
|
|
void FindEdictFieldOffsets (progs_t *pr);
|
2000-05-10 11:29:38 +00:00
|
|
|
|
2000-12-28 06:49:26 +00:00
|
|
|
int type_size[8] = {
|
|
|
|
1,
|
|
|
|
sizeof (void *) / 4,
|
|
|
|
1,
|
|
|
|
3,
|
|
|
|
1,
|
|
|
|
1,
|
|
|
|
sizeof (void *) / 4,
|
|
|
|
sizeof (void *) / 4
|
|
|
|
};
|
2000-05-10 11:29:38 +00:00
|
|
|
|
2000-12-31 07:43:09 +00:00
|
|
|
ddef_t *ED_FieldAtOfs (progs_t *pr, int ofs);
|
|
|
|
qboolean ED_ParseEpair (progs_t *pr, void *base, ddef_t *key, char *s);
|
2000-05-10 20:33:16 +00:00
|
|
|
|
|
|
|
#define MAX_FIELD_LEN 64
|
|
|
|
#define GEFV_CACHESIZE 2
|
|
|
|
|
|
|
|
typedef struct {
|
2000-12-08 06:51:37 +00:00
|
|
|
ddef_t *pcache;
|
|
|
|
char field[MAX_FIELD_LEN];
|
2000-05-10 20:33:16 +00:00
|
|
|
} gefv_cache;
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
static gefv_cache gefvCache[GEFV_CACHESIZE] = { {NULL, ""}, {NULL, ""} };
|
2000-05-10 20:33:16 +00:00
|
|
|
|
2000-05-10 11:29:38 +00:00
|
|
|
/*
|
2000-12-31 07:43:09 +00:00
|
|
|
ED_ClearEdict
|
2000-05-10 11:29:38 +00:00
|
|
|
|
2000-12-31 07:43:09 +00:00
|
|
|
Sets everything to NULL
|
2000-05-10 11:29:38 +00:00
|
|
|
*/
|
2000-12-08 06:51:37 +00:00
|
|
|
void
|
2000-12-31 07:43:09 +00:00
|
|
|
ED_ClearEdict (progs_t *pr, edict_t *e)
|
2000-05-10 11:29:38 +00:00
|
|
|
{
|
2000-12-31 07:43:09 +00:00
|
|
|
memset (&e->v, 0, pr->progs->entityfields * 4);
|
2000-05-10 11:29:38 +00:00
|
|
|
e->free = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2000-12-31 07:43:09 +00:00
|
|
|
ED_Alloc
|
|
|
|
|
|
|
|
Either finds a free edict, or allocates a new one.
|
|
|
|
Try to avoid reusing an entity that was recently freed, because it
|
|
|
|
can cause the client to think the entity morphed into something else
|
|
|
|
instead of being removed and recreated, which can cause interpolated
|
|
|
|
angles and bad trails.
|
2000-05-10 11:29:38 +00:00
|
|
|
*/
|
2000-12-28 06:49:26 +00:00
|
|
|
edict_t *
|
2000-12-31 07:43:09 +00:00
|
|
|
ED_Alloc (progs_t *pr)
|
2000-05-10 11:29:38 +00:00
|
|
|
{
|
2000-12-08 06:51:37 +00:00
|
|
|
int i;
|
|
|
|
edict_t *e;
|
2000-05-10 11:29:38 +00:00
|
|
|
|
2001-01-02 03:22:46 +00:00
|
|
|
for (i = MAX_CLIENTS + 1; i < *(pr)->num_edicts; i++) {
|
2000-12-31 07:43:09 +00:00
|
|
|
e = EDICT_NUM (pr, i);
|
2000-05-10 11:29:38 +00:00
|
|
|
// the first couple seconds of server time can involve a lot of
|
|
|
|
// freeing and allocating, so relax the replacement policy
|
2001-01-02 03:22:46 +00:00
|
|
|
if (e->free && (e->freetime < 2 || *(pr)->time - e->freetime > 0.5)) {
|
2000-12-31 07:43:09 +00:00
|
|
|
ED_ClearEdict (pr, e);
|
2000-05-10 11:29:38 +00:00
|
|
|
return e;
|
|
|
|
}
|
|
|
|
}
|
2000-12-08 06:51:37 +00:00
|
|
|
|
|
|
|
if (i == MAX_EDICTS) {
|
2000-05-10 11:29:38 +00:00
|
|
|
Con_Printf ("WARNING: ED_Alloc: no free edicts\n");
|
2000-12-08 06:51:37 +00:00
|
|
|
i--; // step on whatever is the last edict
|
2000-12-31 07:43:09 +00:00
|
|
|
e = EDICT_NUM (pr, i);
|
2001-01-03 07:08:28 +00:00
|
|
|
if (pr->unlink)
|
|
|
|
pr->unlink (e);
|
2000-12-08 06:51:37 +00:00
|
|
|
} else
|
2001-01-02 03:22:46 +00:00
|
|
|
(*(pr)->num_edicts)++;
|
2000-12-31 07:43:09 +00:00
|
|
|
e = EDICT_NUM (pr, i);
|
|
|
|
ED_ClearEdict (pr, e);
|
2000-05-10 11:29:38 +00:00
|
|
|
|
|
|
|
return e;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2000-12-31 07:43:09 +00:00
|
|
|
ED_Free
|
2000-05-10 11:29:38 +00:00
|
|
|
|
2000-12-31 07:43:09 +00:00
|
|
|
Marks the edict as free
|
|
|
|
FIXME: walk all entities and NULL out references to this entity
|
2000-05-10 11:29:38 +00:00
|
|
|
*/
|
2000-12-08 06:51:37 +00:00
|
|
|
void
|
2000-12-31 07:43:09 +00:00
|
|
|
ED_Free (progs_t *pr, edict_t *ed)
|
2000-05-10 11:29:38 +00:00
|
|
|
{
|
2001-01-03 07:08:28 +00:00
|
|
|
if (pr->unlink)
|
|
|
|
pr->unlink (ed); // unlink from world bsp
|
2000-05-10 11:29:38 +00:00
|
|
|
|
|
|
|
ed->free = true;
|
|
|
|
ed->v.model = 0;
|
|
|
|
ed->v.takedamage = 0;
|
|
|
|
ed->v.modelindex = 0;
|
|
|
|
ed->v.colormap = 0;
|
|
|
|
ed->v.skin = 0;
|
|
|
|
ed->v.frame = 0;
|
|
|
|
VectorCopy (vec3_origin, ed->v.origin);
|
|
|
|
VectorCopy (vec3_origin, ed->v.angles);
|
|
|
|
ed->v.nextthink = -1;
|
|
|
|
ed->v.solid = 0;
|
2000-12-08 06:51:37 +00:00
|
|
|
|
2001-01-02 03:22:46 +00:00
|
|
|
ed->freetime = *(pr)->time;
|
2000-05-10 11:29:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//===========================================================================
|
|
|
|
|
|
|
|
/*
|
2000-12-31 07:43:09 +00:00
|
|
|
ED_GlobalAtOfs
|
2000-05-10 11:29:38 +00:00
|
|
|
*/
|
2000-12-28 06:49:26 +00:00
|
|
|
ddef_t *
|
2000-12-31 07:43:09 +00:00
|
|
|
ED_GlobalAtOfs (progs_t *pr, int ofs)
|
2000-05-10 11:29:38 +00:00
|
|
|
{
|
2000-12-08 06:51:37 +00:00
|
|
|
ddef_t *def;
|
|
|
|
int i;
|
|
|
|
|
2000-12-31 07:43:09 +00:00
|
|
|
for (i = 0; i < pr->progs->numglobaldefs; i++) {
|
|
|
|
def = &pr->pr_globaldefs[i];
|
2000-05-10 11:29:38 +00:00
|
|
|
if (def->ofs == ofs)
|
|
|
|
return def;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2000-12-31 07:43:09 +00:00
|
|
|
ED_FieldAtOfs
|
2000-05-10 11:29:38 +00:00
|
|
|
*/
|
2000-12-28 06:49:26 +00:00
|
|
|
ddef_t *
|
2000-12-31 07:43:09 +00:00
|
|
|
ED_FieldAtOfs (progs_t *pr, int ofs)
|
2000-05-10 11:29:38 +00:00
|
|
|
{
|
2000-12-08 06:51:37 +00:00
|
|
|
ddef_t *def;
|
|
|
|
int i;
|
|
|
|
|
2000-12-31 07:43:09 +00:00
|
|
|
for (i = 0; i < pr->progs->numfielddefs; i++) {
|
|
|
|
def = &pr->pr_fielddefs[i];
|
2000-05-10 11:29:38 +00:00
|
|
|
if (def->ofs == ofs)
|
|
|
|
return def;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2000-12-31 07:43:09 +00:00
|
|
|
ED_FindField
|
2000-05-10 11:29:38 +00:00
|
|
|
*/
|
2000-12-28 06:49:26 +00:00
|
|
|
ddef_t *
|
2000-12-31 07:43:09 +00:00
|
|
|
ED_FindField (progs_t *pr, char *name)
|
2000-05-10 11:29:38 +00:00
|
|
|
{
|
2000-12-08 06:51:37 +00:00
|
|
|
ddef_t *def;
|
|
|
|
int i;
|
|
|
|
|
2000-12-31 07:43:09 +00:00
|
|
|
for (i = 0; i < pr->progs->numfielddefs; i++) {
|
|
|
|
def = &pr->pr_fielddefs[i];
|
|
|
|
if (!strcmp (PR_GetString (pr, def->s_name), name))
|
2000-05-10 11:29:38 +00:00
|
|
|
return def;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2000-12-31 07:43:09 +00:00
|
|
|
ED_FindGlobal
|
2000-05-10 11:29:38 +00:00
|
|
|
*/
|
2000-12-28 06:49:26 +00:00
|
|
|
ddef_t *
|
2000-12-31 07:43:09 +00:00
|
|
|
ED_FindGlobal (progs_t *pr, char *name)
|
2000-05-10 11:29:38 +00:00
|
|
|
{
|
2000-12-08 06:51:37 +00:00
|
|
|
ddef_t *def;
|
|
|
|
int i;
|
|
|
|
|
2000-12-31 07:43:09 +00:00
|
|
|
for (i = 0; i < pr->progs->numglobaldefs; i++) {
|
|
|
|
def = &pr->pr_globaldefs[i];
|
|
|
|
if (!strcmp (PR_GetString (pr, def->s_name), name))
|
2000-05-10 11:29:38 +00:00
|
|
|
return def;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2000-12-31 07:43:09 +00:00
|
|
|
ED_FindFunction
|
2000-05-10 11:29:38 +00:00
|
|
|
*/
|
2000-12-08 06:51:37 +00:00
|
|
|
dfunction_t *
|
2000-12-31 07:43:09 +00:00
|
|
|
ED_FindFunction (progs_t *pr, char *name)
|
2000-05-10 11:29:38 +00:00
|
|
|
{
|
2000-12-08 06:51:37 +00:00
|
|
|
dfunction_t *func;
|
|
|
|
int i;
|
|
|
|
|
2000-12-31 07:43:09 +00:00
|
|
|
for (i = 0; i < pr->progs->numfunctions; i++) {
|
|
|
|
func = &pr->pr_functions[i];
|
|
|
|
if (!strcmp (PR_GetString (pr, func->s_name), name))
|
2000-05-10 11:29:38 +00:00
|
|
|
return func;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2000-12-11 09:59:27 +00:00
|
|
|
eval_t *
|
2000-12-31 07:43:09 +00:00
|
|
|
GetEdictFieldValue (progs_t *pr, edict_t *ed, char *field)
|
2000-05-10 20:33:16 +00:00
|
|
|
{
|
2000-12-08 06:51:37 +00:00
|
|
|
ddef_t *def = NULL;
|
|
|
|
int i;
|
|
|
|
static int rep = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < GEFV_CACHESIZE; i++) {
|
|
|
|
if (!strcmp (field, gefvCache[i].field)) {
|
2000-05-10 20:33:16 +00:00
|
|
|
def = gefvCache[i].pcache;
|
|
|
|
goto Done;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-12-31 07:43:09 +00:00
|
|
|
def = ED_FindField (pr, field);
|
2000-05-10 20:33:16 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
if (strlen (field) < MAX_FIELD_LEN) {
|
2000-05-10 20:33:16 +00:00
|
|
|
gefvCache[rep].pcache = def;
|
|
|
|
strcpy (gefvCache[rep].field, field);
|
|
|
|
rep ^= 1;
|
|
|
|
}
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
Done:
|
2000-05-10 20:33:16 +00:00
|
|
|
if (!def)
|
|
|
|
return NULL;
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
return (eval_t *) ((char *) &ed->v + def->ofs * 4);
|
2000-05-10 20:33:16 +00:00
|
|
|
}
|
|
|
|
|
2000-05-10 11:29:38 +00:00
|
|
|
/*
|
2000-12-31 07:43:09 +00:00
|
|
|
PR_ValueString
|
2000-05-10 11:29:38 +00:00
|
|
|
|
2000-12-31 07:43:09 +00:00
|
|
|
Returns a string describing *data in a type specific manner
|
2000-05-10 11:29:38 +00:00
|
|
|
*/
|
2000-12-11 09:59:27 +00:00
|
|
|
char *
|
2000-12-31 07:43:09 +00:00
|
|
|
PR_ValueString (progs_t *pr, etype_t type, eval_t *val)
|
2000-05-10 11:29:38 +00:00
|
|
|
{
|
2000-12-08 06:51:37 +00:00
|
|
|
static char line[256];
|
|
|
|
ddef_t *def;
|
|
|
|
dfunction_t *f;
|
|
|
|
|
2000-05-10 11:29:38 +00:00
|
|
|
type &= ~DEF_SAVEGLOBAL;
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
switch (type) {
|
|
|
|
case ev_string:
|
2000-12-31 07:43:09 +00:00
|
|
|
snprintf (line, sizeof (line), "%s", PR_GetString (pr, val->string));
|
2000-12-08 06:51:37 +00:00
|
|
|
break;
|
|
|
|
case ev_entity:
|
|
|
|
snprintf (line, sizeof (line), "entity %i",
|
2001-01-02 03:22:46 +00:00
|
|
|
NUM_FOR_EDICT (pr, PROG_TO_EDICT (pr, val->edict)));
|
2000-12-08 06:51:37 +00:00
|
|
|
break;
|
|
|
|
case ev_function:
|
2000-12-31 07:43:09 +00:00
|
|
|
f = pr->pr_functions + val->function;
|
|
|
|
snprintf (line, sizeof (line), "%s()", PR_GetString (pr, f->s_name));
|
2000-12-08 06:51:37 +00:00
|
|
|
break;
|
|
|
|
case ev_field:
|
2000-12-31 07:43:09 +00:00
|
|
|
def = ED_FieldAtOfs (pr, val->_int);
|
|
|
|
snprintf (line, sizeof (line), ".%s", PR_GetString (pr, def->s_name));
|
2000-12-08 06:51:37 +00:00
|
|
|
break;
|
|
|
|
case ev_void:
|
|
|
|
strcpy (line, "void");
|
|
|
|
break;
|
|
|
|
case ev_float:
|
|
|
|
snprintf (line, sizeof (line), "%5.1f", val->_float);
|
|
|
|
break;
|
|
|
|
case ev_vector:
|
|
|
|
snprintf (line, sizeof (line), "'%5.1f %5.1f %5.1f'",
|
|
|
|
val->vector[0], val->vector[1], val->vector[2]);
|
|
|
|
break;
|
|
|
|
case ev_pointer:
|
|
|
|
strcpy (line, "pointer");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
snprintf (line, sizeof (line), "bad type %i", type);
|
|
|
|
break;
|
2000-05-10 11:29:38 +00:00
|
|
|
}
|
2000-12-08 06:51:37 +00:00
|
|
|
|
2000-05-10 11:29:38 +00:00
|
|
|
return line;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2000-12-31 07:43:09 +00:00
|
|
|
PR_UglyValueString
|
2000-05-10 11:29:38 +00:00
|
|
|
|
2000-12-31 07:43:09 +00:00
|
|
|
Returns a string describing *data in a type specific manner
|
|
|
|
Easier to parse than PR_ValueString
|
2000-05-10 11:29:38 +00:00
|
|
|
*/
|
2000-12-11 09:59:27 +00:00
|
|
|
char *
|
2000-12-31 07:43:09 +00:00
|
|
|
PR_UglyValueString (progs_t *pr, etype_t type, eval_t *val)
|
2000-05-10 11:29:38 +00:00
|
|
|
{
|
2000-12-08 06:51:37 +00:00
|
|
|
static char line[256];
|
|
|
|
ddef_t *def;
|
|
|
|
dfunction_t *f;
|
|
|
|
|
2000-05-10 11:29:38 +00:00
|
|
|
type &= ~DEF_SAVEGLOBAL;
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
switch (type) {
|
|
|
|
case ev_string:
|
2000-12-31 07:43:09 +00:00
|
|
|
snprintf (line, sizeof (line), "%s", PR_GetString (pr, val->string));
|
2000-12-08 06:51:37 +00:00
|
|
|
break;
|
|
|
|
case ev_entity:
|
|
|
|
snprintf (line, sizeof (line), "%i",
|
2001-01-02 03:22:46 +00:00
|
|
|
NUM_FOR_EDICT (pr, PROG_TO_EDICT (pr, val->edict)));
|
2000-12-08 06:51:37 +00:00
|
|
|
break;
|
|
|
|
case ev_function:
|
2000-12-31 07:43:09 +00:00
|
|
|
f = pr->pr_functions + val->function;
|
|
|
|
snprintf (line, sizeof (line), "%s", PR_GetString (pr, f->s_name));
|
2000-12-08 06:51:37 +00:00
|
|
|
break;
|
|
|
|
case ev_field:
|
2000-12-31 07:43:09 +00:00
|
|
|
def = ED_FieldAtOfs (pr, val->_int);
|
|
|
|
snprintf (line, sizeof (line), "%s", PR_GetString (pr, def->s_name));
|
2000-12-08 06:51:37 +00:00
|
|
|
break;
|
|
|
|
case ev_void:
|
|
|
|
strcpy (line, "void");
|
|
|
|
break;
|
|
|
|
case ev_float:
|
|
|
|
snprintf (line, sizeof (line), "%f", val->_float);
|
|
|
|
break;
|
|
|
|
case ev_vector:
|
|
|
|
snprintf (line, sizeof (line), "%f %f %f", val->vector[0],
|
|
|
|
val->vector[1], val->vector[2]);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
snprintf (line, sizeof (line), "bad type %i", type);
|
|
|
|
break;
|
2000-05-10 11:29:38 +00:00
|
|
|
}
|
2000-12-08 06:51:37 +00:00
|
|
|
|
2000-05-10 11:29:38 +00:00
|
|
|
return line;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2000-12-31 07:43:09 +00:00
|
|
|
PR_GlobalString
|
2000-05-10 11:29:38 +00:00
|
|
|
|
2000-12-31 07:43:09 +00:00
|
|
|
Returns a string with a description and the contents of a global,
|
|
|
|
padded to 20 field width
|
2000-05-10 11:29:38 +00:00
|
|
|
*/
|
2000-12-11 09:59:27 +00:00
|
|
|
char *
|
2000-12-31 07:43:09 +00:00
|
|
|
PR_GlobalString (progs_t *pr, int ofs)
|
2000-05-10 11:29:38 +00:00
|
|
|
{
|
2000-12-08 06:51:37 +00:00
|
|
|
char *s;
|
|
|
|
int i;
|
|
|
|
ddef_t *def;
|
|
|
|
void *val;
|
|
|
|
static char line[128];
|
|
|
|
|
2000-12-31 07:43:09 +00:00
|
|
|
val = (void *) &pr->pr_globals[ofs];
|
|
|
|
def = ED_GlobalAtOfs (pr, ofs);
|
2000-05-10 11:29:38 +00:00
|
|
|
if (!def)
|
2000-12-08 06:51:37 +00:00
|
|
|
snprintf (line, sizeof (line), "%i(?)", ofs);
|
|
|
|
else {
|
2000-12-31 07:43:09 +00:00
|
|
|
s = PR_ValueString (pr, def->type, val);
|
2000-12-08 06:51:37 +00:00
|
|
|
snprintf (line, sizeof (line), "%i(%s)%s", ofs,
|
2000-12-31 07:43:09 +00:00
|
|
|
PR_GetString (pr, def->s_name), s);
|
2000-05-10 11:29:38 +00:00
|
|
|
}
|
2000-12-08 06:51:37 +00:00
|
|
|
|
|
|
|
i = strlen (line);
|
|
|
|
for (; i < 20; i++)
|
|
|
|
strncat (line, " ", sizeof (line) - strlen (line));
|
|
|
|
strncat (line, " ", sizeof (line) - strlen (line));
|
|
|
|
|
2000-05-10 11:29:38 +00:00
|
|
|
return line;
|
|
|
|
}
|
|
|
|
|
2000-12-11 09:59:27 +00:00
|
|
|
char *
|
2000-12-31 07:43:09 +00:00
|
|
|
PR_GlobalStringNoContents (progs_t *pr, int ofs)
|
2000-05-10 11:29:38 +00:00
|
|
|
{
|
2000-12-08 06:51:37 +00:00
|
|
|
int i;
|
|
|
|
ddef_t *def;
|
|
|
|
static char line[128];
|
|
|
|
|
2000-12-31 07:43:09 +00:00
|
|
|
def = ED_GlobalAtOfs (pr, ofs);
|
2000-05-10 11:29:38 +00:00
|
|
|
if (!def)
|
2000-12-08 06:51:37 +00:00
|
|
|
snprintf (line, sizeof (line), "%i(?)", ofs);
|
2000-05-10 11:29:38 +00:00
|
|
|
else
|
2000-12-08 06:51:37 +00:00
|
|
|
snprintf (line, sizeof (line), "%i(%s)", ofs,
|
2000-12-31 07:43:09 +00:00
|
|
|
PR_GetString (pr, def->s_name));
|
2000-12-08 06:51:37 +00:00
|
|
|
|
|
|
|
i = strlen (line);
|
|
|
|
for (; i < 20; i++)
|
|
|
|
strncat (line, " ", sizeof (line) - strlen (line));
|
|
|
|
strncat (line, " ", sizeof (line) - strlen (line));
|
|
|
|
|
2000-05-10 11:29:38 +00:00
|
|
|
return line;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2000-12-31 07:43:09 +00:00
|
|
|
ED_Print
|
2000-05-10 11:29:38 +00:00
|
|
|
|
2000-12-31 07:43:09 +00:00
|
|
|
For debugging
|
2000-05-10 11:29:38 +00:00
|
|
|
*/
|
2000-12-08 06:51:37 +00:00
|
|
|
void
|
2000-12-31 07:43:09 +00:00
|
|
|
ED_Print (progs_t *pr, edict_t *ed)
|
2000-05-10 11:29:38 +00:00
|
|
|
{
|
2000-12-08 06:51:37 +00:00
|
|
|
int l;
|
|
|
|
ddef_t *d;
|
|
|
|
int *v;
|
|
|
|
int i, j;
|
|
|
|
char *name;
|
|
|
|
int type;
|
|
|
|
|
|
|
|
if (ed->free) {
|
2000-05-10 11:29:38 +00:00
|
|
|
Con_Printf ("FREE\n");
|
|
|
|
return;
|
|
|
|
}
|
2000-12-08 06:51:37 +00:00
|
|
|
|
2000-12-31 07:43:09 +00:00
|
|
|
for (i = 1; i < pr->progs->numfielddefs; i++) {
|
|
|
|
d = &pr->pr_fielddefs[i];
|
|
|
|
name = PR_GetString (pr, d->s_name);
|
2000-12-08 06:51:37 +00:00
|
|
|
if (name[strlen (name) - 2] == '_')
|
|
|
|
continue; // skip _x, _y, _z vars
|
2000-05-10 11:29:38 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
v = (int *) ((char *) &ed->v + d->ofs * 4);
|
|
|
|
|
|
|
|
// if the value is still all 0, skip the field
|
2000-05-10 11:29:38 +00:00
|
|
|
type = d->type & ~DEF_SAVEGLOBAL;
|
2000-12-08 06:51:37 +00:00
|
|
|
|
|
|
|
for (j = 0; j < type_size[type]; j++)
|
2000-05-10 11:29:38 +00:00
|
|
|
if (v[j])
|
|
|
|
break;
|
|
|
|
if (j == type_size[type])
|
|
|
|
continue;
|
2000-12-08 06:51:37 +00:00
|
|
|
|
|
|
|
Con_Printf ("%s", name);
|
2000-05-10 11:29:38 +00:00
|
|
|
l = strlen (name);
|
|
|
|
while (l++ < 15)
|
|
|
|
Con_Printf (" ");
|
|
|
|
|
2000-12-31 07:43:09 +00:00
|
|
|
Con_Printf ("%s\n", PR_ValueString (pr, d->type, (eval_t *) v));
|
2000-05-10 11:29:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2000-12-31 07:43:09 +00:00
|
|
|
ED_Write
|
2000-05-10 11:29:38 +00:00
|
|
|
|
2000-12-31 07:43:09 +00:00
|
|
|
For savegames
|
2000-05-10 11:29:38 +00:00
|
|
|
*/
|
2000-12-08 06:51:37 +00:00
|
|
|
void
|
2000-12-31 07:43:09 +00:00
|
|
|
ED_Write (progs_t *pr, QFile *f, edict_t *ed)
|
2000-05-10 11:29:38 +00:00
|
|
|
{
|
2000-12-08 06:51:37 +00:00
|
|
|
ddef_t *d;
|
|
|
|
int *v;
|
|
|
|
int i, j;
|
|
|
|
char *name;
|
|
|
|
int type;
|
2000-05-10 11:29:38 +00:00
|
|
|
|
2000-09-27 19:44:26 +00:00
|
|
|
Qprintf (f, "{\n");
|
2000-05-10 11:29:38 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
if (ed->free) {
|
2000-09-27 19:44:26 +00:00
|
|
|
Qprintf (f, "}\n");
|
2000-05-10 11:29:38 +00:00
|
|
|
return;
|
|
|
|
}
|
2000-12-08 06:51:37 +00:00
|
|
|
|
2000-12-31 07:43:09 +00:00
|
|
|
for (i = 1; i < pr->progs->numfielddefs; i++) {
|
|
|
|
d = &pr->pr_fielddefs[i];
|
|
|
|
name = PR_GetString (pr, d->s_name);
|
2000-12-08 06:51:37 +00:00
|
|
|
if (name[strlen (name) - 2] == '_')
|
|
|
|
continue; // skip _x, _y, _z vars
|
|
|
|
|
|
|
|
v = (int *) ((char *) &ed->v + d->ofs * 4);
|
2000-05-10 11:29:38 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
// if the value is still all 0, skip the field
|
2000-05-10 11:29:38 +00:00
|
|
|
type = d->type & ~DEF_SAVEGLOBAL;
|
2000-12-08 06:51:37 +00:00
|
|
|
for (j = 0; j < type_size[type]; j++)
|
2000-05-10 11:29:38 +00:00
|
|
|
if (v[j])
|
|
|
|
break;
|
|
|
|
if (j == type_size[type])
|
|
|
|
continue;
|
2000-12-08 06:51:37 +00:00
|
|
|
|
|
|
|
Qprintf (f, "\"%s\" ", name);
|
2000-12-31 07:43:09 +00:00
|
|
|
Qprintf (f, "\"%s\"\n", PR_UglyValueString (pr, d->type, (eval_t *) v));
|
2000-05-10 11:29:38 +00:00
|
|
|
}
|
|
|
|
|
2000-09-27 19:44:26 +00:00
|
|
|
Qprintf (f, "}\n");
|
2000-05-10 11:29:38 +00:00
|
|
|
}
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
void
|
2000-12-31 07:43:09 +00:00
|
|
|
ED_PrintNum (progs_t *pr, int ent)
|
2000-05-10 11:29:38 +00:00
|
|
|
{
|
2000-12-31 07:43:09 +00:00
|
|
|
ED_Print (pr, EDICT_NUM (pr, ent));
|
2000-05-10 11:29:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2000-12-31 07:43:09 +00:00
|
|
|
ED_PrintEdicts
|
2000-05-10 11:29:38 +00:00
|
|
|
|
2000-12-31 07:43:09 +00:00
|
|
|
For debugging, prints all the entities in the current server
|
2000-05-10 11:29:38 +00:00
|
|
|
*/
|
2000-12-08 06:51:37 +00:00
|
|
|
void
|
2000-12-31 07:43:09 +00:00
|
|
|
ED_PrintEdicts (progs_t *pr)
|
2000-05-10 11:29:38 +00:00
|
|
|
{
|
2000-12-08 06:51:37 +00:00
|
|
|
int i;
|
|
|
|
|
2001-01-02 03:22:46 +00:00
|
|
|
Con_Printf ("%i entities\n", *(pr)->num_edicts);
|
|
|
|
for (i = 0; i < *(pr)->num_edicts; i++) {
|
2000-12-08 06:51:37 +00:00
|
|
|
Con_Printf ("\nEDICT %i:\n", i);
|
2000-12-31 07:43:09 +00:00
|
|
|
ED_PrintNum (pr, i);
|
2000-05-10 11:29:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2000-12-31 07:43:09 +00:00
|
|
|
ED_Count
|
2000-05-10 11:29:38 +00:00
|
|
|
|
2000-12-31 07:43:09 +00:00
|
|
|
For debugging
|
2000-05-10 11:29:38 +00:00
|
|
|
*/
|
2000-12-08 06:51:37 +00:00
|
|
|
void
|
2000-12-31 07:43:09 +00:00
|
|
|
ED_Count (progs_t *pr)
|
2000-05-10 11:29:38 +00:00
|
|
|
{
|
2000-12-08 06:51:37 +00:00
|
|
|
int i;
|
|
|
|
edict_t *ent;
|
|
|
|
int active, models, solid, step;
|
2000-05-10 11:29:38 +00:00
|
|
|
|
|
|
|
active = models = solid = step = 0;
|
2001-01-02 03:22:46 +00:00
|
|
|
for (i = 0; i < *(pr)->num_edicts; i++) {
|
2000-12-31 07:43:09 +00:00
|
|
|
ent = EDICT_NUM (pr, i);
|
2000-05-10 11:29:38 +00:00
|
|
|
if (ent->free)
|
|
|
|
continue;
|
|
|
|
active++;
|
|
|
|
if (ent->v.solid)
|
|
|
|
solid++;
|
|
|
|
if (ent->v.model)
|
|
|
|
models++;
|
|
|
|
if (ent->v.movetype == MOVETYPE_STEP)
|
|
|
|
step++;
|
|
|
|
}
|
|
|
|
|
2001-01-02 03:22:46 +00:00
|
|
|
Con_Printf ("num_edicts:%3i\n", *(pr)->num_edicts);
|
2000-05-10 11:29:38 +00:00
|
|
|
Con_Printf ("active :%3i\n", active);
|
|
|
|
Con_Printf ("view :%3i\n", models);
|
|
|
|
Con_Printf ("touch :%3i\n", solid);
|
|
|
|
Con_Printf ("step :%3i\n", step);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
==============================================================================
|
|
|
|
|
|
|
|
ARCHIVING GLOBALS
|
|
|
|
|
|
|
|
FIXME: need to tag constants, doesn't really work
|
|
|
|
==============================================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2000-12-31 07:43:09 +00:00
|
|
|
ED_WriteGlobals
|
2000-05-10 11:29:38 +00:00
|
|
|
*/
|
2000-12-08 06:51:37 +00:00
|
|
|
void
|
2000-12-31 07:43:09 +00:00
|
|
|
ED_WriteGlobals (progs_t *pr, QFile *f)
|
2000-05-10 11:29:38 +00:00
|
|
|
{
|
2000-12-08 06:51:37 +00:00
|
|
|
ddef_t *def;
|
|
|
|
int i;
|
|
|
|
char *name;
|
|
|
|
int type;
|
|
|
|
|
|
|
|
Qprintf (f, "{\n");
|
2000-12-31 07:43:09 +00:00
|
|
|
for (i = 0; i < pr->progs->numglobaldefs; i++) {
|
|
|
|
def = &pr->pr_globaldefs[i];
|
2000-05-10 11:29:38 +00:00
|
|
|
type = def->type;
|
2000-12-08 06:51:37 +00:00
|
|
|
if (!(def->type & DEF_SAVEGLOBAL))
|
2000-05-10 11:29:38 +00:00
|
|
|
continue;
|
|
|
|
type &= ~DEF_SAVEGLOBAL;
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
if (type != ev_string && type != ev_float && type != ev_entity)
|
2000-05-10 11:29:38 +00:00
|
|
|
continue;
|
|
|
|
|
2000-12-31 07:43:09 +00:00
|
|
|
name = PR_GetString (pr, def->s_name);
|
2000-12-08 06:51:37 +00:00
|
|
|
Qprintf (f, "\"%s\" ", name);
|
|
|
|
Qprintf (f, "\"%s\"\n",
|
2000-12-31 07:43:09 +00:00
|
|
|
PR_UglyValueString (pr, type, (eval_t *) &pr->pr_globals[def->ofs]));
|
2000-05-10 11:29:38 +00:00
|
|
|
}
|
2000-12-08 06:51:37 +00:00
|
|
|
Qprintf (f, "}\n");
|
2000-05-10 11:29:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2000-12-31 07:43:09 +00:00
|
|
|
ED_ParseGlobals
|
2000-05-10 11:29:38 +00:00
|
|
|
*/
|
2000-12-08 06:51:37 +00:00
|
|
|
void
|
2000-12-31 07:43:09 +00:00
|
|
|
ED_ParseGlobals (progs_t *pr, char *data)
|
2000-05-10 11:29:38 +00:00
|
|
|
{
|
2000-12-08 06:51:37 +00:00
|
|
|
char keyname[64];
|
|
|
|
ddef_t *key;
|
2000-05-10 11:29:38 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
while (1) {
|
|
|
|
// parse key
|
2000-05-10 11:29:38 +00:00
|
|
|
data = COM_Parse (data);
|
|
|
|
if (com_token[0] == '}')
|
|
|
|
break;
|
|
|
|
if (!data)
|
|
|
|
SV_Error ("ED_ParseEntity: EOF without closing brace");
|
|
|
|
|
|
|
|
strcpy (keyname, com_token);
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
// parse value
|
2000-05-10 11:29:38 +00:00
|
|
|
data = COM_Parse (data);
|
|
|
|
if (!data)
|
|
|
|
SV_Error ("ED_ParseEntity: EOF without closing brace");
|
|
|
|
|
|
|
|
if (com_token[0] == '}')
|
|
|
|
SV_Error ("ED_ParseEntity: closing brace without data");
|
|
|
|
|
2000-12-31 07:43:09 +00:00
|
|
|
key = ED_FindGlobal (pr, keyname);
|
2000-12-08 06:51:37 +00:00
|
|
|
if (!key) {
|
2000-05-10 11:29:38 +00:00
|
|
|
Con_Printf ("%s is not a global\n", keyname);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2000-12-31 07:43:09 +00:00
|
|
|
if (!ED_ParseEpair (pr, (void *) pr->pr_globals, key, com_token))
|
2000-05-10 11:29:38 +00:00
|
|
|
SV_Error ("ED_ParseGlobals: parse error");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2000-12-31 07:43:09 +00:00
|
|
|
ED_NewString
|
2000-05-10 11:29:38 +00:00
|
|
|
*/
|
2000-12-11 09:59:27 +00:00
|
|
|
char *
|
2000-12-31 07:43:09 +00:00
|
|
|
ED_NewString (progs_t *pr, char *string)
|
2000-05-10 11:29:38 +00:00
|
|
|
{
|
2000-12-08 06:51:37 +00:00
|
|
|
char *new, *new_p;
|
|
|
|
int i, l;
|
|
|
|
|
|
|
|
l = strlen (string) + 1;
|
2000-05-10 11:29:38 +00:00
|
|
|
new = Hunk_Alloc (l);
|
|
|
|
new_p = new;
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
for (i = 0; i < l; i++) {
|
|
|
|
if (string[i] == '\\' && i < l - 1) {
|
2000-05-10 11:29:38 +00:00
|
|
|
i++;
|
|
|
|
if (string[i] == 'n')
|
|
|
|
*new_p++ = '\n';
|
|
|
|
else
|
|
|
|
*new_p++ = '\\';
|
2000-12-08 06:51:37 +00:00
|
|
|
} else
|
2000-05-10 11:29:38 +00:00
|
|
|
*new_p++ = string[i];
|
|
|
|
}
|
2000-12-08 06:51:37 +00:00
|
|
|
|
2000-05-10 11:29:38 +00:00
|
|
|
return new;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2000-12-31 07:43:09 +00:00
|
|
|
ED_ParseEval
|
2000-05-10 11:29:38 +00:00
|
|
|
|
2000-12-31 07:43:09 +00:00
|
|
|
Can parse either fields or globals
|
|
|
|
returns false if error
|
2000-05-10 11:29:38 +00:00
|
|
|
*/
|
2000-12-08 06:51:37 +00:00
|
|
|
qboolean
|
2000-12-31 07:43:09 +00:00
|
|
|
ED_ParseEpair (progs_t *pr, void *base, ddef_t *key, char *s)
|
2000-05-10 11:29:38 +00:00
|
|
|
{
|
2000-12-08 06:51:37 +00:00
|
|
|
int i;
|
|
|
|
char string[128];
|
|
|
|
ddef_t *def;
|
|
|
|
char *v, *w;
|
|
|
|
void *d;
|
|
|
|
dfunction_t *func;
|
|
|
|
|
|
|
|
d = (void *) ((int *) base + key->ofs);
|
|
|
|
|
|
|
|
switch (key->type & ~DEF_SAVEGLOBAL) {
|
|
|
|
case ev_string:
|
2000-12-31 07:43:09 +00:00
|
|
|
*(string_t *) d = PR_SetString (pr, ED_NewString (pr, s));
|
2000-12-08 06:51:37 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ev_float:
|
|
|
|
*(float *) d = atof (s);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ev_vector:
|
|
|
|
strcpy (string, s);
|
|
|
|
v = string;
|
|
|
|
w = string;
|
|
|
|
for (i = 0; i < 3; i++) {
|
|
|
|
while (*v && *v != ' ')
|
|
|
|
v++;
|
|
|
|
*v = 0;
|
|
|
|
((float *) d)[i] = atof (w);
|
|
|
|
w = v = v + 1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ev_entity:
|
2001-01-02 03:22:46 +00:00
|
|
|
*(int *) d = EDICT_TO_PROG (pr, EDICT_NUM (pr, atoi (s)));
|
2000-12-08 06:51:37 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ev_field:
|
2000-12-31 07:43:09 +00:00
|
|
|
def = ED_FindField (pr, s);
|
2000-12-08 06:51:37 +00:00
|
|
|
if (!def) {
|
|
|
|
Con_Printf ("Can't find field %s\n", s);
|
|
|
|
return false;
|
|
|
|
}
|
2000-12-31 07:43:09 +00:00
|
|
|
*(int *) d = G_INT (pr, def->ofs);
|
2000-12-08 06:51:37 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ev_function:
|
2000-12-31 07:43:09 +00:00
|
|
|
func = ED_FindFunction (pr, s);
|
2000-12-08 06:51:37 +00:00
|
|
|
if (!func) {
|
|
|
|
Con_Printf ("Can't find function %s\n", s);
|
|
|
|
return false;
|
|
|
|
}
|
2000-12-31 07:43:09 +00:00
|
|
|
*(func_t *) d = func - pr->pr_functions;
|
2000-12-08 06:51:37 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2000-05-10 11:29:38 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2000-12-31 07:43:09 +00:00
|
|
|
ED_ParseEdict
|
2000-05-10 11:29:38 +00:00
|
|
|
|
2000-12-31 07:43:09 +00:00
|
|
|
Parses an edict out of the given string, returning the new position
|
|
|
|
ed should be a properly initialized empty edict.
|
|
|
|
Used for initial level load and for savegames.
|
2000-05-10 11:29:38 +00:00
|
|
|
*/
|
2000-12-11 09:59:27 +00:00
|
|
|
char *
|
2000-12-31 07:43:09 +00:00
|
|
|
ED_ParseEdict (progs_t *pr, char *data, edict_t *ent)
|
2000-05-10 11:29:38 +00:00
|
|
|
{
|
2000-12-08 06:51:37 +00:00
|
|
|
ddef_t *key;
|
|
|
|
qboolean anglehack;
|
|
|
|
qboolean init;
|
|
|
|
char keyname[256];
|
2000-05-10 11:29:38 +00:00
|
|
|
|
|
|
|
init = false;
|
|
|
|
|
|
|
|
// clear it
|
2001-01-02 03:22:46 +00:00
|
|
|
if (ent != *(pr)->edicts) // hack
|
2000-12-31 07:43:09 +00:00
|
|
|
memset (&ent->v, 0, pr->progs->entityfields * 4);
|
2000-05-10 11:29:38 +00:00
|
|
|
|
|
|
|
// go through all the dictionary pairs
|
2000-12-08 06:51:37 +00:00
|
|
|
while (1) {
|
|
|
|
// parse key
|
2000-05-10 11:29:38 +00:00
|
|
|
data = COM_Parse (data);
|
|
|
|
if (com_token[0] == '}')
|
|
|
|
break;
|
|
|
|
if (!data)
|
|
|
|
SV_Error ("ED_ParseEntity: EOF without closing brace");
|
2000-12-08 06:51:37 +00:00
|
|
|
|
2000-05-19 03:06:05 +00:00
|
|
|
// anglehack is to allow QuakeEd to write single scalar angles
|
|
|
|
// and allow them to be turned into vectors. (FIXME...)
|
2000-12-08 06:51:37 +00:00
|
|
|
if (!strcmp (com_token, "angle")) {
|
2000-05-19 03:06:05 +00:00
|
|
|
strcpy (com_token, "angles");
|
|
|
|
anglehack = true;
|
|
|
|
} else
|
|
|
|
anglehack = false;
|
2000-05-10 11:29:38 +00:00
|
|
|
|
2000-05-19 03:06:05 +00:00
|
|
|
// FIXME: change light to _light to get rid of this hack
|
2000-12-08 06:51:37 +00:00
|
|
|
if (!strcmp (com_token, "light"))
|
2000-05-19 03:06:05 +00:00
|
|
|
strcpy (com_token, "light_lev"); // hack for single light def
|
2000-05-10 11:29:38 +00:00
|
|
|
|
|
|
|
strcpy (keyname, com_token);
|
2000-12-08 06:51:37 +00:00
|
|
|
|
|
|
|
// parse value
|
2000-05-10 11:29:38 +00:00
|
|
|
data = COM_Parse (data);
|
|
|
|
if (!data)
|
|
|
|
SV_Error ("ED_ParseEntity: EOF without closing brace");
|
|
|
|
|
|
|
|
if (com_token[0] == '}')
|
|
|
|
SV_Error ("ED_ParseEntity: closing brace without data");
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
init = true;
|
2000-05-10 11:29:38 +00:00
|
|
|
|
|
|
|
// keynames with a leading underscore are used for utility comments,
|
|
|
|
// and are immediately discarded by quake
|
|
|
|
if (keyname[0] == '_')
|
|
|
|
continue;
|
2000-05-19 03:06:05 +00:00
|
|
|
|
2000-12-31 07:43:09 +00:00
|
|
|
key = ED_FindField (pr, keyname);
|
2000-12-08 06:51:37 +00:00
|
|
|
if (!key) {
|
2001-01-03 05:54:35 +00:00
|
|
|
if (!ED_Parse_Extra_Fields (pr, keyname, com_token)) {
|
|
|
|
Con_Printf ("%s is not a field\n", keyname);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (anglehack) {
|
|
|
|
char temp[32];
|
2000-05-10 11:29:38 +00:00
|
|
|
|
2001-01-03 05:54:35 +00:00
|
|
|
strncpy (temp, com_token, sizeof (temp));
|
|
|
|
temp[sizeof (temp) - 1] = 0;
|
|
|
|
snprintf (com_token, sizeof (com_token), "0 %s 0", temp);
|
|
|
|
}
|
2000-12-08 06:51:37 +00:00
|
|
|
|
2001-01-03 05:54:35 +00:00
|
|
|
if (!ED_ParseEpair (pr, (void *) &ent->v, key, com_token))
|
|
|
|
SV_Error ("ED_ParseEdict: parse error");
|
2000-12-05 11:08:30 +00:00
|
|
|
}
|
2000-05-10 11:29:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!init)
|
|
|
|
ent->free = true;
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2000-12-31 07:43:09 +00:00
|
|
|
ED_LoadFromFile
|
2000-05-10 11:29:38 +00:00
|
|
|
|
2000-12-31 07:43:09 +00:00
|
|
|
The entities are directly placed in the array, rather than allocated with
|
|
|
|
ED_Alloc, because otherwise an error loading the map would have entity
|
|
|
|
number references out of order.
|
2000-05-10 11:29:38 +00:00
|
|
|
|
2000-12-31 07:43:09 +00:00
|
|
|
Creates a server's entity / program execution context by
|
|
|
|
parsing textual entity definitions out of an ent file.
|
2000-05-10 11:29:38 +00:00
|
|
|
|
2000-12-31 07:43:09 +00:00
|
|
|
Used for both fresh maps and savegame loads. A fresh map would also need
|
|
|
|
to call ED_CallSpawnFunctions () to let the objects initialize themselves.
|
2000-05-10 11:29:38 +00:00
|
|
|
*/
|
2000-12-08 06:51:37 +00:00
|
|
|
void
|
2000-12-31 07:43:09 +00:00
|
|
|
ED_LoadFromFile (progs_t *pr, char *data)
|
2000-12-08 06:51:37 +00:00
|
|
|
{
|
|
|
|
edict_t *ent;
|
|
|
|
int inhibit;
|
|
|
|
dfunction_t *func;
|
|
|
|
|
2000-05-10 11:29:38 +00:00
|
|
|
ent = NULL;
|
|
|
|
inhibit = 0;
|
2001-01-02 03:22:46 +00:00
|
|
|
pr->pr_global_struct->time = *(pr)->time;
|
2000-12-08 06:51:37 +00:00
|
|
|
|
2000-05-10 11:29:38 +00:00
|
|
|
// parse ents
|
2000-12-08 06:51:37 +00:00
|
|
|
while (1) {
|
|
|
|
// parse the opening brace
|
2000-05-10 11:29:38 +00:00
|
|
|
data = COM_Parse (data);
|
|
|
|
if (!data)
|
|
|
|
break;
|
|
|
|
if (com_token[0] != '{')
|
2000-12-08 06:51:37 +00:00
|
|
|
SV_Error ("ED_LoadFromFile: found %s when expecting {", com_token);
|
2000-05-10 11:29:38 +00:00
|
|
|
|
|
|
|
if (!ent)
|
2000-12-31 07:43:09 +00:00
|
|
|
ent = EDICT_NUM (pr, 0);
|
2000-05-10 11:29:38 +00:00
|
|
|
else
|
2000-12-31 07:43:09 +00:00
|
|
|
ent = ED_Alloc (pr);
|
|
|
|
data = ED_ParseEdict (pr, data, ent);
|
2000-12-08 06:51:37 +00:00
|
|
|
|
2000-05-10 11:29:38 +00:00
|
|
|
// remove things from different skill levels or deathmatch
|
2000-12-08 06:51:37 +00:00
|
|
|
if (((int) ent->v.spawnflags & SPAWNFLAG_NOT_DEATHMATCH)) {
|
2000-12-31 07:43:09 +00:00
|
|
|
ED_Free (pr, ent);
|
2000-05-10 11:29:38 +00:00
|
|
|
inhibit++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
//
|
|
|
|
// immediately call spawn function
|
|
|
|
//
|
2000-12-08 06:51:37 +00:00
|
|
|
if (!ent->v.classname) {
|
2000-05-10 11:29:38 +00:00
|
|
|
Con_Printf ("No classname for:\n");
|
2000-12-31 07:43:09 +00:00
|
|
|
ED_Print (pr, ent);
|
|
|
|
ED_Free (pr, ent);
|
2000-05-10 11:29:38 +00:00
|
|
|
continue;
|
|
|
|
}
|
2000-12-08 06:51:37 +00:00
|
|
|
// look for the spawn function
|
2000-12-31 07:43:09 +00:00
|
|
|
func = ED_FindFunction (pr, PR_GetString (pr, ent->v.classname));
|
2000-05-10 11:29:38 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
if (!func) {
|
2000-05-10 11:29:38 +00:00
|
|
|
Con_Printf ("No spawn function for:\n");
|
2000-12-31 07:43:09 +00:00
|
|
|
ED_Print (pr, ent);
|
|
|
|
ED_Free (pr, ent);
|
2000-05-10 11:29:38 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2001-01-02 03:22:46 +00:00
|
|
|
pr->pr_global_struct->self = EDICT_TO_PROG (pr, ent);
|
2000-12-31 07:43:09 +00:00
|
|
|
PR_ExecuteProgram (pr, func - pr->pr_functions);
|
2001-01-03 07:08:28 +00:00
|
|
|
if (pr->flush)
|
|
|
|
pr->flush ();
|
2000-12-08 06:51:37 +00:00
|
|
|
}
|
2000-05-10 11:29:38 +00:00
|
|
|
|
|
|
|
Con_DPrintf ("%i entities inhibited\n", inhibit);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2000-12-31 07:43:09 +00:00
|
|
|
PR_LoadProgs
|
2000-05-10 11:29:38 +00:00
|
|
|
*/
|
2000-12-08 06:51:37 +00:00
|
|
|
void
|
2000-12-31 07:43:09 +00:00
|
|
|
PR_LoadProgs (progs_t *pr)
|
2000-05-10 11:29:38 +00:00
|
|
|
{
|
2000-12-08 06:51:37 +00:00
|
|
|
int i;
|
2000-12-06 13:23:44 +00:00
|
|
|
dstatement_t *st;
|
2000-05-10 11:29:38 +00:00
|
|
|
|
2000-05-10 20:33:16 +00:00
|
|
|
// flush the non-C variable lookup cache
|
2000-12-08 06:51:37 +00:00
|
|
|
for (i = 0; i < GEFV_CACHESIZE; i++)
|
2000-05-10 20:33:16 +00:00
|
|
|
gefvCache[i].field[0] = 0;
|
|
|
|
|
2000-12-31 07:43:09 +00:00
|
|
|
pr->progs = (dprograms_t *) COM_LoadHunkFile ("qwprogs.dat");
|
|
|
|
if (!pr->progs)
|
|
|
|
pr->progs = (dprograms_t *) COM_LoadHunkFile ("progs.dat");
|
|
|
|
if (!pr->progs)
|
2000-12-08 06:51:37 +00:00
|
|
|
SV_Error ("PR_LoadProgs: couldn't load progs.dat");
|
2000-12-06 13:23:44 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
Con_DPrintf ("Programs occupy %iK.\n", com_filesize / 1024);
|
2000-05-10 11:29:38 +00:00
|
|
|
|
2001-01-03 05:54:35 +00:00
|
|
|
// store prog crc
|
|
|
|
pr->crc = CRC_Block ((byte *) pr->progs, com_filesize);
|
2000-05-10 11:29:38 +00:00
|
|
|
|
|
|
|
// byte swap the header
|
2000-12-31 07:43:09 +00:00
|
|
|
for (i = 0; i < sizeof (*pr->progs) / 4; i++)
|
|
|
|
((int *) pr->progs)[i] = LittleLong (((int *) pr->progs)[i]);
|
2000-05-10 11:29:38 +00:00
|
|
|
|
2000-12-31 07:43:09 +00:00
|
|
|
if (pr->progs->version != PROG_VERSION)
|
2000-12-08 06:51:37 +00:00
|
|
|
SV_Error ("progs.dat has wrong version number (%i should be %i)",
|
2000-12-31 07:43:09 +00:00
|
|
|
pr->progs->version, PROG_VERSION);
|
|
|
|
if (pr->progs->crc != PROGHEADER_CRC)
|
2000-12-06 18:27:23 +00:00
|
|
|
SV_Error ("You must have the qwprogs.dat from QuakeWorld installed");
|
2000-05-10 11:29:38 +00:00
|
|
|
|
2000-12-31 07:43:09 +00:00
|
|
|
pr->pr_functions = (dfunction_t *) ((byte *) pr->progs + pr->progs->ofs_functions);
|
|
|
|
pr->pr_strings = (char *) pr->progs + pr->progs->ofs_strings;
|
|
|
|
pr->pr_globaldefs = (ddef_t *) ((byte *) pr->progs + pr->progs->ofs_globaldefs);
|
|
|
|
pr->pr_fielddefs = (ddef_t *) ((byte *) pr->progs + pr->progs->ofs_fielddefs);
|
|
|
|
pr->pr_statements = (dstatement_t *) ((byte *) pr->progs + pr->progs->ofs_statements);
|
2000-05-10 11:29:38 +00:00
|
|
|
|
2000-12-31 07:43:09 +00:00
|
|
|
pr->num_prstr = 0;
|
2000-05-10 11:29:38 +00:00
|
|
|
|
2000-12-31 07:43:09 +00:00
|
|
|
pr->pr_global_struct = (globalvars_t *) ((byte *) pr->progs + pr->progs->ofs_globals);
|
|
|
|
pr->pr_globals = (float *) pr->pr_global_struct;
|
2000-12-08 06:51:37 +00:00
|
|
|
|
2000-12-31 07:43:09 +00:00
|
|
|
pr->pr_edict_size =
|
2000-12-08 06:51:37 +00:00
|
|
|
|
2000-12-31 07:43:09 +00:00
|
|
|
pr->progs->entityfields * 4 + sizeof (edict_t) - sizeof (entvars_t);
|
2000-12-06 13:23:44 +00:00
|
|
|
|
2000-12-31 07:43:09 +00:00
|
|
|
pr->pr_edictareasize = pr->pr_edict_size * MAX_EDICTS;
|
2000-12-06 13:23:44 +00:00
|
|
|
|
2000-05-10 11:29:38 +00:00
|
|
|
// byte swap the lumps
|
2000-12-31 07:43:09 +00:00
|
|
|
for (i = 0; i < pr->progs->numstatements; i++) {
|
|
|
|
pr->pr_statements[i].op = LittleShort (pr->pr_statements[i].op);
|
|
|
|
pr->pr_statements[i].a = LittleShort (pr->pr_statements[i].a);
|
|
|
|
pr->pr_statements[i].b = LittleShort (pr->pr_statements[i].b);
|
|
|
|
pr->pr_statements[i].c = LittleShort (pr->pr_statements[i].c);
|
2000-05-10 11:29:38 +00:00
|
|
|
}
|
|
|
|
|
2000-12-31 07:43:09 +00:00
|
|
|
for (i = 0; i < pr->progs->numfunctions; i++) {
|
|
|
|
pr->pr_functions[i].first_statement =
|
|
|
|
LittleLong (pr->pr_functions[i].first_statement);
|
|
|
|
pr->pr_functions[i].parm_start = LittleLong (pr->pr_functions[i].parm_start);
|
|
|
|
pr->pr_functions[i].s_name = LittleLong (pr->pr_functions[i].s_name);
|
|
|
|
pr->pr_functions[i].s_file = LittleLong (pr->pr_functions[i].s_file);
|
|
|
|
pr->pr_functions[i].numparms = LittleLong (pr->pr_functions[i].numparms);
|
|
|
|
pr->pr_functions[i].locals = LittleLong (pr->pr_functions[i].locals);
|
2000-12-08 06:51:37 +00:00
|
|
|
}
|
2000-05-10 11:29:38 +00:00
|
|
|
|
2000-12-31 07:43:09 +00:00
|
|
|
for (i = 0; i < pr->progs->numglobaldefs; i++) {
|
|
|
|
pr->pr_globaldefs[i].type = LittleShort (pr->pr_globaldefs[i].type);
|
|
|
|
pr->pr_globaldefs[i].ofs = LittleShort (pr->pr_globaldefs[i].ofs);
|
|
|
|
pr->pr_globaldefs[i].s_name = LittleLong (pr->pr_globaldefs[i].s_name);
|
2000-05-10 11:29:38 +00:00
|
|
|
}
|
|
|
|
|
2000-12-31 07:43:09 +00:00
|
|
|
for (i = 0; i < pr->progs->numfielddefs; i++) {
|
|
|
|
pr->pr_fielddefs[i].type = LittleShort (pr->pr_fielddefs[i].type);
|
|
|
|
if (pr->pr_fielddefs[i].type & DEF_SAVEGLOBAL)
|
2000-12-08 06:51:37 +00:00
|
|
|
SV_Error ("PR_LoadProgs: pr_fielddefs[i].type & DEF_SAVEGLOBAL");
|
2000-12-31 07:43:09 +00:00
|
|
|
pr->pr_fielddefs[i].ofs = LittleShort (pr->pr_fielddefs[i].ofs);
|
|
|
|
pr->pr_fielddefs[i].s_name = LittleLong (pr->pr_fielddefs[i].s_name);
|
2000-05-10 11:29:38 +00:00
|
|
|
}
|
|
|
|
|
2000-12-31 07:43:09 +00:00
|
|
|
for (i = 0; i < pr->progs->numglobals; i++)
|
|
|
|
((int *) pr->pr_globals)[i] = LittleLong (((int *) pr->pr_globals)[i]);
|
2000-08-20 19:47:37 +00:00
|
|
|
|
2000-06-30 05:54:28 +00:00
|
|
|
// LordHavoc: Ender added this
|
2000-12-31 07:43:09 +00:00
|
|
|
FindEdictFieldOffsets (pr);
|
2000-05-10 11:29:38 +00:00
|
|
|
|
2000-12-06 13:23:44 +00:00
|
|
|
// LordHavoc: bounds check anything static
|
2000-12-31 07:43:09 +00:00
|
|
|
for (i = 0, st = pr->pr_statements; i < pr->progs->numstatements; i++, st++) {
|
2000-12-08 06:51:37 +00:00
|
|
|
switch (st->op) {
|
|
|
|
case OP_IF:
|
|
|
|
case OP_IFNOT:
|
2000-12-31 07:43:09 +00:00
|
|
|
if ((unsigned short) st->a >= pr->progs->numglobals || st->b + i < 0
|
|
|
|
|| st->b + i >= pr->progs->numstatements)
|
2000-12-08 06:51:37 +00:00
|
|
|
SV_Error
|
|
|
|
("PR_LoadProgs: out of bounds IF/IFNOT (statement %d)\n",
|
|
|
|
i);
|
|
|
|
break;
|
|
|
|
case OP_GOTO:
|
2000-12-31 07:43:09 +00:00
|
|
|
if (st->a + i < 0 || st->a + i >= pr->progs->numstatements)
|
2000-12-08 06:51:37 +00:00
|
|
|
SV_Error
|
|
|
|
("PR_LoadProgs: out of bounds GOTO (statement %d)\n",
|
|
|
|
i);
|
|
|
|
break;
|
|
|
|
// global global global
|
|
|
|
case OP_ADD_F:
|
|
|
|
case OP_ADD_V:
|
|
|
|
case OP_SUB_F:
|
|
|
|
case OP_SUB_V:
|
|
|
|
case OP_MUL_F:
|
|
|
|
case OP_MUL_V:
|
|
|
|
case OP_MUL_FV:
|
|
|
|
case OP_MUL_VF:
|
|
|
|
case OP_DIV_F:
|
|
|
|
case OP_BITAND:
|
|
|
|
case OP_BITOR:
|
|
|
|
case OP_GE:
|
|
|
|
case OP_LE:
|
|
|
|
case OP_GT:
|
|
|
|
case OP_LT:
|
|
|
|
case OP_AND:
|
|
|
|
case OP_OR:
|
|
|
|
case OP_EQ_F:
|
|
|
|
case OP_EQ_V:
|
|
|
|
case OP_EQ_S:
|
|
|
|
case OP_EQ_E:
|
|
|
|
case OP_EQ_FNC:
|
|
|
|
case OP_NE_F:
|
|
|
|
case OP_NE_V:
|
|
|
|
case OP_NE_S:
|
|
|
|
case OP_NE_E:
|
|
|
|
case OP_NE_FNC:
|
|
|
|
case OP_ADDRESS:
|
|
|
|
case OP_LOAD_F:
|
|
|
|
case OP_LOAD_FLD:
|
|
|
|
case OP_LOAD_ENT:
|
|
|
|
case OP_LOAD_S:
|
|
|
|
case OP_LOAD_FNC:
|
|
|
|
case OP_LOAD_V:
|
2000-12-31 07:43:09 +00:00
|
|
|
if ((unsigned short) st->a >= pr->progs->numglobals
|
|
|
|
|| (unsigned short) st->b >= pr->progs->numglobals
|
|
|
|
|| (unsigned short) st->c >= pr->progs->numglobals)
|
2000-12-08 06:51:37 +00:00
|
|
|
SV_Error
|
|
|
|
("PR_LoadProgs: out of bounds global index (statement %d)\n",
|
|
|
|
i);
|
|
|
|
break;
|
|
|
|
// global none global
|
|
|
|
case OP_NOT_F:
|
|
|
|
case OP_NOT_V:
|
|
|
|
case OP_NOT_S:
|
|
|
|
case OP_NOT_FNC:
|
|
|
|
case OP_NOT_ENT:
|
2000-12-31 07:43:09 +00:00
|
|
|
if ((unsigned short) st->a >= pr->progs->numglobals
|
|
|
|
|| (unsigned short) st->c >= pr->progs->numglobals)
|
2000-12-08 06:51:37 +00:00
|
|
|
SV_Error
|
|
|
|
("PR_LoadProgs: out of bounds global index (statement %d)\n",
|
|
|
|
i);
|
|
|
|
break;
|
|
|
|
// 2 globals
|
|
|
|
case OP_STOREP_F:
|
|
|
|
case OP_STOREP_ENT:
|
|
|
|
case OP_STOREP_FLD:
|
|
|
|
case OP_STOREP_S:
|
|
|
|
case OP_STOREP_FNC:
|
|
|
|
case OP_STORE_F:
|
|
|
|
case OP_STORE_ENT:
|
|
|
|
case OP_STORE_FLD:
|
|
|
|
case OP_STORE_S:
|
|
|
|
case OP_STORE_FNC:
|
|
|
|
case OP_STATE:
|
|
|
|
case OP_STOREP_V:
|
|
|
|
case OP_STORE_V:
|
2000-12-31 07:43:09 +00:00
|
|
|
if ((unsigned short) st->a >= pr->progs->numglobals
|
|
|
|
|| (unsigned short) st->b >= pr->progs->numglobals)
|
2000-12-08 06:51:37 +00:00
|
|
|
SV_Error
|
|
|
|
("PR_LoadProgs: out of bounds global index (statement %d)\n",
|
|
|
|
i);
|
|
|
|
break;
|
|
|
|
// 1 global
|
|
|
|
case OP_CALL0:
|
|
|
|
case OP_CALL1:
|
|
|
|
case OP_CALL2:
|
|
|
|
case OP_CALL3:
|
|
|
|
case OP_CALL4:
|
|
|
|
case OP_CALL5:
|
|
|
|
case OP_CALL6:
|
|
|
|
case OP_CALL7:
|
|
|
|
case OP_CALL8:
|
|
|
|
case OP_DONE:
|
|
|
|
case OP_RETURN:
|
2000-12-31 07:43:09 +00:00
|
|
|
if ((unsigned short) st->a >= pr->progs->numglobals)
|
2000-12-08 06:51:37 +00:00
|
|
|
SV_Error
|
|
|
|
("PR_LoadProgs: out of bounds global index (statement %d)\n",
|
|
|
|
i);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
SV_Error ("PR_LoadProgs: unknown opcode %d at statement %d\n",
|
|
|
|
st->op, i);
|
|
|
|
break;
|
2000-12-06 13:23:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-12-31 07:43:09 +00:00
|
|
|
FindEdictFieldOffsets (pr); // LordHavoc: update field offset
|
2000-12-08 06:51:37 +00:00
|
|
|
// list
|
2000-12-06 13:23:44 +00:00
|
|
|
}
|
2000-05-10 11:29:38 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
void
|
|
|
|
PR_Init_Cvars (void)
|
2000-10-29 15:35:24 +00:00
|
|
|
{
|
2000-12-08 06:51:37 +00:00
|
|
|
pr_boundscheck =
|
|
|
|
Cvar_Get ("pr_boundscheck", "1", CVAR_NONE,
|
|
|
|
"Server progs bounds checking");
|
2000-10-29 15:35:24 +00:00
|
|
|
}
|
|
|
|
|
2001-01-03 07:08:28 +00:00
|
|
|
void
|
|
|
|
PR_Init (void)
|
|
|
|
{
|
|
|
|
}
|
2000-05-10 11:29:38 +00:00
|
|
|
|
2000-12-11 09:59:27 +00:00
|
|
|
edict_t *
|
2000-12-31 07:43:09 +00:00
|
|
|
EDICT_NUM (progs_t *pr, int n)
|
2000-05-10 11:29:38 +00:00
|
|
|
{
|
|
|
|
if (n < 0 || n >= MAX_EDICTS)
|
|
|
|
SV_Error ("EDICT_NUM: bad number %i", n);
|
2001-01-02 03:22:46 +00:00
|
|
|
return (edict_t *) ((byte *) *(pr)->edicts + (n) * pr->pr_edict_size);
|
2000-05-10 11:29:38 +00:00
|
|
|
}
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
int
|
2000-12-31 07:43:09 +00:00
|
|
|
NUM_FOR_EDICT (progs_t *pr, edict_t *e)
|
2000-05-10 11:29:38 +00:00
|
|
|
{
|
2000-12-08 06:51:37 +00:00
|
|
|
int b;
|
|
|
|
|
2001-01-02 03:22:46 +00:00
|
|
|
b = (byte *) e - (byte *) *(pr)->edicts;
|
2000-12-31 07:43:09 +00:00
|
|
|
b = b / pr->pr_edict_size;
|
2000-12-08 06:51:37 +00:00
|
|
|
|
2001-01-02 03:22:46 +00:00
|
|
|
if (b < 0 || b >= *(pr)->num_edicts)
|
2000-05-10 11:29:38 +00:00
|
|
|
SV_Error ("NUM_FOR_EDICT: bad pointer");
|
|
|
|
return b;
|
|
|
|
}
|