2001-02-19 21:15:25 +00:00
|
|
|
/*
|
|
|
|
pr_edict.c
|
|
|
|
|
|
|
|
entity dictionary
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
static __attribute__ ((unused)) const char rcsid[] =
|
|
|
|
"$Id$";
|
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
# include <string.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRINGS_H
|
|
|
|
# include <strings.h>
|
|
|
|
#endif
|
2001-03-28 17:17:56 +00:00
|
|
|
#include <stdarg.h>
|
2001-04-10 20:07:11 +00:00
|
|
|
#include <stdio.h>
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2002-07-31 05:19:03 +00:00
|
|
|
#include "QF/cbuf.h"
|
2001-03-27 20:33:07 +00:00
|
|
|
#include "QF/crc.h"
|
|
|
|
#include "QF/cvar.h"
|
2002-09-14 07:00:40 +00:00
|
|
|
#include "QF/dstring.h"
|
2001-03-27 20:33:07 +00:00
|
|
|
#include "QF/hash.h"
|
2002-09-14 07:51:53 +00:00
|
|
|
#include "QF/idparse.h"
|
2001-03-27 20:33:07 +00:00
|
|
|
#include "QF/progs.h"
|
|
|
|
#include "QF/qdefs.h"
|
|
|
|
#include "QF/qendian.h"
|
2002-08-27 07:16:28 +00:00
|
|
|
#include "QF/quakefs.h"
|
2001-09-21 04:22:46 +00:00
|
|
|
#include "QF/sys.h"
|
2001-03-27 20:33:07 +00:00
|
|
|
#include "QF/zone.h"
|
|
|
|
#include "QF/va.h"
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-12-08 08:19:48 +00:00
|
|
|
#include "compat.h"
|
|
|
|
|
2002-10-08 19:46:42 +00:00
|
|
|
cvar_t *pr_boundscheck;
|
|
|
|
cvar_t *pr_deadbeef_ents;
|
|
|
|
cvar_t *pr_deadbeef_locals;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2002-10-08 19:46:42 +00:00
|
|
|
int pr_type_size[ev_type_count] = {
|
2002-05-17 16:44:47 +00:00
|
|
|
1, // ev_void
|
|
|
|
1, // ev_string
|
|
|
|
1, // ev_float
|
|
|
|
3, // ev_vector
|
|
|
|
1, // ev_entity
|
|
|
|
1, // ev_field
|
|
|
|
1, // ev_func
|
|
|
|
1, // ev_pointer
|
|
|
|
4, // ev_quaternion
|
|
|
|
1, // ev_integer
|
|
|
|
1, // ev_uinteger
|
|
|
|
0, // ev_short value in opcode
|
2002-06-12 22:37:18 +00:00
|
|
|
0, // ev_struct variable
|
|
|
|
0, // ev_object variable
|
|
|
|
0, // ev_class variable
|
2002-05-17 16:44:47 +00:00
|
|
|
2, // ev_sel
|
2002-06-12 22:37:18 +00:00
|
|
|
0, // ev_array variable
|
2001-02-19 21:15:25 +00:00
|
|
|
};
|
|
|
|
|
2002-10-08 19:46:42 +00:00
|
|
|
const char *pr_type_name[ev_type_count] = {
|
2001-03-27 03:57:17 +00:00
|
|
|
"void",
|
|
|
|
"string",
|
|
|
|
"float",
|
|
|
|
"vector",
|
|
|
|
"entity",
|
|
|
|
"field",
|
|
|
|
"function",
|
|
|
|
"pointer",
|
2001-07-23 01:31:22 +00:00
|
|
|
"quaternion",
|
|
|
|
"integer",
|
2001-11-09 01:03:35 +00:00
|
|
|
"uinteger",
|
2001-12-07 20:07:38 +00:00
|
|
|
"short",
|
2001-12-08 08:19:48 +00:00
|
|
|
"struct",
|
2002-05-10 23:19:57 +00:00
|
|
|
"object",
|
|
|
|
"Class",
|
|
|
|
"SEL",
|
2002-06-12 22:37:18 +00:00
|
|
|
"array",
|
2001-03-27 03:57:17 +00:00
|
|
|
};
|
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
/*
|
|
|
|
ED_ClearEdict
|
|
|
|
|
|
|
|
Sets everything to NULL
|
|
|
|
*/
|
|
|
|
void
|
2002-10-08 19:46:42 +00:00
|
|
|
ED_ClearEdict (progs_t *pr, edict_t *e, int val)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2003-04-17 00:01:48 +00:00
|
|
|
unsigned int i;
|
2001-04-19 22:42:01 +00:00
|
|
|
|
2001-03-02 19:18:04 +00:00
|
|
|
if (NUM_FOR_EDICT(pr,e)<*pr->reserved_edicts)
|
2001-10-18 16:42:14 +00:00
|
|
|
Sys_Printf("clearing reserved edict %d\n", NUM_FOR_EDICT(pr,e));
|
2001-04-19 22:42:01 +00:00
|
|
|
for (i=0; i < pr->progs->entityfields; i++)
|
2001-07-22 20:20:46 +00:00
|
|
|
e->v[i].integer_var = val;
|
2001-02-19 21:15:25 +00:00
|
|
|
e->free = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
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.
|
|
|
|
*/
|
2002-10-08 19:46:42 +00:00
|
|
|
edict_t *
|
|
|
|
ED_Alloc (progs_t *pr)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
edict_t *e;
|
2001-02-28 09:12:01 +00:00
|
|
|
int start = pr->reserved_edicts ? *pr->reserved_edicts : 0;
|
2001-03-04 05:42:26 +00:00
|
|
|
int max_edicts = pr->pr_edictareasize / pr->pr_edict_size;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-28 09:12:01 +00:00
|
|
|
for (i = start + 1; i < *(pr)->num_edicts; i++) {
|
2001-02-19 21:15:25 +00:00
|
|
|
e = EDICT_NUM (pr, i);
|
|
|
|
// the first couple seconds of server time can involve a lot of
|
|
|
|
// freeing and allocating, so relax the replacement policy
|
|
|
|
if (e->free && (e->freetime < 2 || *(pr)->time - e->freetime > 0.5)) {
|
2001-04-19 22:42:01 +00:00
|
|
|
ED_ClearEdict (pr, e, 0);
|
2001-02-19 21:15:25 +00:00
|
|
|
return e;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-03-04 05:42:26 +00:00
|
|
|
if (i == max_edicts) {
|
2001-09-21 04:22:46 +00:00
|
|
|
Sys_Printf ("WARNING: ED_Alloc: no free edicts\n");
|
2001-02-19 21:15:25 +00:00
|
|
|
i--; // step on whatever is the last edict
|
|
|
|
e = EDICT_NUM (pr, i);
|
|
|
|
if (pr->unlink)
|
|
|
|
pr->unlink (e);
|
|
|
|
} else
|
|
|
|
(*(pr)->num_edicts)++;
|
|
|
|
e = EDICT_NUM (pr, i);
|
2001-04-19 22:42:01 +00:00
|
|
|
ED_ClearEdict (pr, e, 0);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
return e;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
ED_Free
|
|
|
|
|
|
|
|
Marks the edict as free
|
|
|
|
FIXME: walk all entities and NULL out references to this entity
|
|
|
|
*/
|
|
|
|
void
|
2002-10-08 19:46:42 +00:00
|
|
|
ED_Free (progs_t *pr, edict_t *ed)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
if (pr->unlink)
|
|
|
|
pr->unlink (ed); // unlink from world bsp
|
|
|
|
|
2001-09-23 00:36:21 +00:00
|
|
|
if (pr_deadbeef_ents->int_val) {
|
2001-04-22 04:58:33 +00:00
|
|
|
ED_ClearEdict (pr, ed, 0xdeadbeef);
|
|
|
|
} else {
|
2001-08-12 04:14:25 +00:00
|
|
|
if (pr->free_edict)
|
|
|
|
pr->free_edict (pr, ed);
|
|
|
|
else
|
|
|
|
ED_ClearEdict (pr, ed, 0);
|
2001-04-22 04:58:33 +00:00
|
|
|
}
|
2001-02-19 21:15:25 +00:00
|
|
|
ed->free = true;
|
|
|
|
ed->freetime = *(pr)->time;
|
|
|
|
}
|
|
|
|
|
|
|
|
//===========================================================================
|
|
|
|
|
|
|
|
/*
|
|
|
|
PR_ValueString
|
|
|
|
|
2002-10-08 19:46:42 +00:00
|
|
|
Returns a string describing *data in a type-specific manner
|
2001-02-19 21:15:25 +00:00
|
|
|
*/
|
2003-01-06 18:28:13 +00:00
|
|
|
static const char *
|
2002-10-08 19:46:42 +00:00
|
|
|
PR_ValueString (progs_t *pr, etype_t type, pr_type_t *val)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2002-10-08 19:46:42 +00:00
|
|
|
static char line[256];
|
|
|
|
ddef_t *def;
|
|
|
|
dfunction_t *f;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
type &= ~DEF_SAVEGLOBAL;
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case ev_string:
|
2003-02-24 03:07:26 +00:00
|
|
|
if (PR_StringValid (pr, val->string_var))
|
|
|
|
snprintf (line, sizeof (line), "%s",
|
|
|
|
PR_GetString (pr, val->string_var));
|
|
|
|
else
|
|
|
|
strcpy (line, "*** invalid ***");
|
2001-02-19 21:15:25 +00:00
|
|
|
break;
|
|
|
|
case ev_entity:
|
|
|
|
snprintf (line, sizeof (line), "entity %i",
|
2001-09-23 01:29:52 +00:00
|
|
|
NUM_FOR_BAD_EDICT (pr, PROG_TO_EDICT (pr, val->entity_var)));
|
2001-02-19 21:15:25 +00:00
|
|
|
break;
|
2001-03-01 23:03:40 +00:00
|
|
|
case ev_func:
|
2002-07-16 19:03:56 +00:00
|
|
|
if (val->func_var < 0 || val->func_var >= pr->progs->numfunctions)
|
|
|
|
snprintf (line, sizeof (line), "INVALID:%d", val->func_var);
|
|
|
|
else if (!val->func_var)
|
|
|
|
return "NULL";
|
|
|
|
else {
|
|
|
|
f = pr->pr_functions + val->func_var;
|
|
|
|
snprintf (line, sizeof (line), "%s()",
|
|
|
|
PR_GetString (pr, f->s_name));
|
|
|
|
}
|
2001-02-19 21:15:25 +00:00
|
|
|
break;
|
|
|
|
case ev_field:
|
2001-07-22 20:20:46 +00:00
|
|
|
def = ED_FieldAtOfs (pr, val->integer_var);
|
2001-02-28 02:25:03 +00:00
|
|
|
snprintf (line, sizeof (line), ".%s",
|
|
|
|
PR_GetString (pr, def->s_name));
|
2001-02-19 21:15:25 +00:00
|
|
|
break;
|
|
|
|
case ev_void:
|
|
|
|
strcpy (line, "void");
|
|
|
|
break;
|
|
|
|
case ev_float:
|
2002-10-08 19:46:42 +00:00
|
|
|
snprintf (line, sizeof (line), "%g", val->float_var);
|
2001-02-19 21:15:25 +00:00
|
|
|
break;
|
|
|
|
case ev_vector:
|
2002-10-08 19:46:42 +00:00
|
|
|
snprintf (line, sizeof (line), "'%g %g %g'",
|
2001-07-23 01:31:22 +00:00
|
|
|
val->vector_var[0], val->vector_var[1],
|
|
|
|
val->vector_var[2]);
|
2001-02-19 21:15:25 +00:00
|
|
|
break;
|
|
|
|
case ev_pointer:
|
2002-10-08 19:46:42 +00:00
|
|
|
snprintf (line, sizeof (line), "[$%x]", val->integer_var);
|
2001-02-19 21:15:25 +00:00
|
|
|
break;
|
2001-07-23 01:31:22 +00:00
|
|
|
case ev_quaternion:
|
2002-10-08 19:46:42 +00:00
|
|
|
snprintf (line, sizeof (line), "'%g %g %g %g'",
|
2001-07-23 01:31:22 +00:00
|
|
|
val->vector_var[0], val->vector_var[1],
|
|
|
|
val->vector_var[2], val->vector_var[3]);
|
|
|
|
break;
|
|
|
|
case ev_integer:
|
|
|
|
snprintf (line, sizeof (line), "%d", val->integer_var);
|
|
|
|
break;
|
2001-11-13 18:04:55 +00:00
|
|
|
case ev_uinteger:
|
2002-10-08 19:46:42 +00:00
|
|
|
snprintf (line, sizeof (line), "$%08x", val->uinteger_var);
|
2001-11-13 18:04:55 +00:00
|
|
|
break;
|
2003-03-26 18:45:44 +00:00
|
|
|
case ev_sel:
|
|
|
|
snprintf (line, sizeof (line), "(SEL) %s",
|
|
|
|
PR_GetString (pr, val->string_var));
|
|
|
|
break;
|
2001-02-19 21:15:25 +00:00
|
|
|
default:
|
|
|
|
snprintf (line, sizeof (line), "bad type %i", type);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return line;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
PR_GlobalString
|
|
|
|
|
2002-09-14 07:00:40 +00:00
|
|
|
Returns a string with a description and the contents of a global
|
2001-02-19 21:15:25 +00:00
|
|
|
*/
|
2002-09-14 07:00:40 +00:00
|
|
|
dstring_t *
|
2002-10-08 19:46:42 +00:00
|
|
|
PR_GlobalString (progs_t *pr, int ofs, etype_t type)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2002-09-14 07:00:40 +00:00
|
|
|
ddef_t *def = NULL;
|
|
|
|
static dstring_t *line = NULL;
|
2003-01-06 18:28:13 +00:00
|
|
|
const char *s;
|
2002-09-14 07:00:40 +00:00
|
|
|
|
|
|
|
if (!line)
|
|
|
|
line = dstring_newstr();
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-12-07 20:07:38 +00:00
|
|
|
if (type == ev_short) {
|
2002-09-14 07:00:40 +00:00
|
|
|
dsprintf (line, "%04x", (short) ofs);
|
2001-12-07 20:07:38 +00:00
|
|
|
return line;
|
|
|
|
}
|
2002-09-14 07:00:40 +00:00
|
|
|
|
2001-07-19 07:27:14 +00:00
|
|
|
if (pr_debug->int_val && pr->debug)
|
|
|
|
def = PR_Get_Local_Def (pr, ofs);
|
|
|
|
if (!def)
|
|
|
|
def = ED_GlobalAtOfs (pr, ofs);
|
2001-08-13 23:49:04 +00:00
|
|
|
if (!def && type == ev_void)
|
2002-10-08 19:46:42 +00:00
|
|
|
dsprintf (line, "[$%x]", ofs);
|
2001-02-19 21:15:25 +00:00
|
|
|
else {
|
2003-01-06 18:28:13 +00:00
|
|
|
const char *name = "?";
|
|
|
|
const char *oi = "";
|
2001-08-13 23:49:04 +00:00
|
|
|
if (def) {
|
|
|
|
if (type == ev_void)
|
|
|
|
type = def->type;
|
|
|
|
name = PR_GetString (pr, def->s_name);
|
2003-04-17 00:01:48 +00:00
|
|
|
if (type != (etype_t) (def->type & ~DEF_SAVEGLOBAL))
|
2002-09-14 07:00:40 +00:00
|
|
|
oi = "?";
|
2001-08-13 23:49:04 +00:00
|
|
|
}
|
2002-09-14 07:00:40 +00:00
|
|
|
|
2002-05-13 19:37:36 +00:00
|
|
|
if (ofs > pr->globals_size)
|
|
|
|
s = "Out of bounds";
|
|
|
|
else
|
|
|
|
s = PR_ValueString (pr, type, &pr->pr_globals[ofs]);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2002-09-14 07:00:40 +00:00
|
|
|
if (strequal(name, "IMMEDIATE") || strequal(name, ".imm")) {
|
|
|
|
if (type == ev_string)
|
|
|
|
dsprintf (line, "\"%s\"", s);
|
|
|
|
else
|
|
|
|
dsprintf (line, "%s", s);
|
|
|
|
} else if (strequal(name, "?"))
|
2003-02-21 15:09:02 +00:00
|
|
|
dsprintf (line, "[$%x](%08x)", ofs,
|
|
|
|
pr->pr_globals[ofs].integer_var);
|
2002-09-14 07:00:40 +00:00
|
|
|
else {
|
|
|
|
if (type == ev_func)
|
|
|
|
dsprintf (line, "%s%s", name, oi);
|
|
|
|
else
|
|
|
|
dsprintf (line, "%s%s(%s)", name, oi, s);
|
|
|
|
}
|
|
|
|
}
|
2001-02-19 21:15:25 +00:00
|
|
|
return line;
|
|
|
|
}
|
|
|
|
|
2002-09-14 07:00:40 +00:00
|
|
|
dstring_t *
|
2002-10-08 19:46:42 +00:00
|
|
|
PR_GlobalStringNoContents (progs_t *pr, int ofs, etype_t type)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2002-09-14 07:00:40 +00:00
|
|
|
static dstring_t *line = NULL;
|
|
|
|
ddef_t *def = NULL;
|
|
|
|
|
|
|
|
if (!line)
|
|
|
|
line = dstring_newstr();
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-12-08 08:19:48 +00:00
|
|
|
if (type == ev_short) {
|
2002-09-14 07:00:40 +00:00
|
|
|
dsprintf (line, "%x", (short) ofs);
|
2001-12-08 08:19:48 +00:00
|
|
|
return line;
|
|
|
|
}
|
2002-09-14 07:00:40 +00:00
|
|
|
|
2001-07-19 07:27:14 +00:00
|
|
|
if (pr_debug->int_val && pr->debug)
|
|
|
|
def = PR_Get_Local_Def (pr, ofs);
|
|
|
|
if (!def)
|
|
|
|
def = ED_GlobalAtOfs (pr, ofs);
|
2001-02-19 21:15:25 +00:00
|
|
|
if (!def)
|
2002-10-08 19:46:42 +00:00
|
|
|
dsprintf (line, "[$%x]", ofs);
|
2001-02-19 21:15:25 +00:00
|
|
|
else
|
2002-09-14 07:00:40 +00:00
|
|
|
dsprintf (line, "%s", PR_GetString (pr, def->s_name));
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
return line;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
ED_Print
|
|
|
|
|
|
|
|
For debugging
|
|
|
|
*/
|
|
|
|
void
|
2002-10-08 19:46:42 +00:00
|
|
|
ED_Print (progs_t *pr, edict_t *ed)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2002-10-08 19:46:42 +00:00
|
|
|
int l;
|
2003-04-17 00:01:48 +00:00
|
|
|
unsigned int i;
|
2002-10-08 19:46:42 +00:00
|
|
|
char *name;
|
|
|
|
int type;
|
|
|
|
ddef_t *d;
|
|
|
|
pr_type_t *v;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
if (ed->free) {
|
2001-09-21 04:22:46 +00:00
|
|
|
Sys_Printf ("FREE\n");
|
2001-02-19 21:15:25 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-09-23 01:29:52 +00:00
|
|
|
Sys_Printf ("\nEDICT %i:\n", NUM_FOR_BAD_EDICT (pr, ed));
|
2003-03-05 18:18:42 +00:00
|
|
|
for (i = 0; i < pr->progs->numfielddefs; i++) {
|
2001-02-19 21:15:25 +00:00
|
|
|
d = &pr->pr_fielddefs[i];
|
2003-03-05 18:18:42 +00:00
|
|
|
if (!d->s_name) // null field def (probably 1st)
|
|
|
|
continue;
|
2001-02-19 21:15:25 +00:00
|
|
|
name = PR_GetString (pr, d->s_name);
|
|
|
|
if (name[strlen (name) - 2] == '_')
|
|
|
|
continue; // skip _x, _y, _z vars
|
|
|
|
|
2001-03-02 19:18:04 +00:00
|
|
|
v = ed->v + d->ofs;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
// if the value is still all 0, skip the field
|
|
|
|
type = d->type & ~DEF_SAVEGLOBAL;
|
|
|
|
|
2001-08-22 21:07:06 +00:00
|
|
|
switch (type) {
|
|
|
|
case ev_entity:
|
|
|
|
case ev_integer:
|
2003-03-26 18:45:44 +00:00
|
|
|
case ev_uinteger:
|
|
|
|
case ev_pointer:
|
2001-08-22 21:07:06 +00:00
|
|
|
case ev_func:
|
|
|
|
case ev_field:
|
|
|
|
if (!v->integer_var)
|
|
|
|
continue;
|
2001-02-19 21:15:25 +00:00
|
|
|
break;
|
2003-03-26 18:45:44 +00:00
|
|
|
case ev_sel:
|
|
|
|
if (!v[0].integer_var
|
|
|
|
&& !PR_GetString (pr, v[1].string_var)[0])
|
|
|
|
continue;
|
|
|
|
break;
|
2001-08-22 21:07:06 +00:00
|
|
|
case ev_string:
|
|
|
|
if (!PR_GetString (pr, v->string_var)[0])
|
|
|
|
continue;
|
|
|
|
break;
|
|
|
|
case ev_float:
|
|
|
|
if (!v->float_var)
|
|
|
|
continue;
|
|
|
|
break;
|
|
|
|
case ev_vector:
|
|
|
|
if (!v[0].float_var && !v[1].float_var && !v[2].float_var)
|
|
|
|
continue;
|
|
|
|
break;
|
|
|
|
default:
|
2002-05-18 00:49:16 +00:00
|
|
|
PR_Error (pr, "ED_Print: Unhandled type %d", type);
|
2001-08-22 21:07:06 +00:00
|
|
|
}
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-09-21 04:22:46 +00:00
|
|
|
Sys_Printf ("%s", name);
|
2001-02-19 21:15:25 +00:00
|
|
|
l = strlen (name);
|
|
|
|
while (l++ < 15)
|
2001-09-21 04:22:46 +00:00
|
|
|
Sys_Printf (" ");
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-09-21 04:22:46 +00:00
|
|
|
Sys_Printf ("%s\n", PR_ValueString (pr, d->type, v));
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2002-10-08 19:46:42 +00:00
|
|
|
ED_PrintNum (progs_t *pr, int ent)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
ED_Print (pr, EDICT_NUM (pr, ent));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
ED_PrintEdicts
|
|
|
|
|
|
|
|
For debugging, prints all the entities in the current server
|
|
|
|
*/
|
|
|
|
void
|
2001-07-19 03:18:11 +00:00
|
|
|
ED_PrintEdicts (progs_t *pr, const char *fieldval)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2002-10-08 19:46:42 +00:00
|
|
|
int i;
|
2001-07-19 03:18:11 +00:00
|
|
|
int count;
|
2002-10-08 19:46:42 +00:00
|
|
|
ddef_t *def;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-07-19 03:18:11 +00:00
|
|
|
def = ED_FindField(pr, "classname");
|
|
|
|
|
|
|
|
if (fieldval && fieldval[0] && def) {
|
|
|
|
count = 0;
|
|
|
|
for (i = 0; i < *(pr)->num_edicts; i++)
|
2003-04-22 18:20:15 +00:00
|
|
|
if (strequal(fieldval,
|
|
|
|
E_GSTRING (pr, EDICT_NUM(pr, i), def->ofs))) {
|
2001-07-19 03:18:11 +00:00
|
|
|
ED_PrintNum (pr, i);
|
|
|
|
count++;
|
|
|
|
}
|
2001-09-21 04:22:46 +00:00
|
|
|
Sys_Printf ("%i entities\n", count);
|
2001-07-19 03:18:11 +00:00
|
|
|
} else {
|
|
|
|
for (i = 0; i < *(pr)->num_edicts; i++)
|
|
|
|
ED_PrintNum (pr, i);
|
2001-09-21 04:22:46 +00:00
|
|
|
Sys_Printf ("%i entities\n", *(pr)->num_edicts);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
ED_Count
|
|
|
|
|
|
|
|
For debugging
|
|
|
|
*/
|
|
|
|
void
|
2002-10-08 19:46:42 +00:00
|
|
|
ED_Count (progs_t *pr)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2002-10-08 19:46:42 +00:00
|
|
|
int i;
|
|
|
|
int active, models, solid, step, zombie;
|
|
|
|
ddef_t *solid_def;
|
|
|
|
ddef_t *model_def;
|
|
|
|
edict_t *ent;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-28 09:12:01 +00:00
|
|
|
solid_def = ED_FindField (pr, "solid");
|
|
|
|
model_def = ED_FindField (pr, "model");
|
2001-09-20 19:34:02 +00:00
|
|
|
active = models = solid = step = zombie = 0;
|
2001-02-19 21:15:25 +00:00
|
|
|
for (i = 0; i < *(pr)->num_edicts; i++) {
|
|
|
|
ent = EDICT_NUM (pr, i);
|
2001-09-20 19:34:02 +00:00
|
|
|
if (ent->free) {
|
|
|
|
if (*(pr)->time - ent->freetime <= 0.5)
|
|
|
|
zombie++;
|
2001-02-19 21:15:25 +00:00
|
|
|
continue;
|
2001-09-20 19:34:02 +00:00
|
|
|
}
|
2001-02-19 21:15:25 +00:00
|
|
|
active++;
|
2001-02-28 09:12:01 +00:00
|
|
|
if (solid_def && ent->v[solid_def->ofs].float_var)
|
2001-02-19 21:15:25 +00:00
|
|
|
solid++;
|
2001-02-28 09:12:01 +00:00
|
|
|
if (model_def && ent->v[model_def->ofs].float_var)
|
2001-02-19 21:15:25 +00:00
|
|
|
models++;
|
|
|
|
}
|
|
|
|
|
2001-09-21 04:22:46 +00:00
|
|
|
Sys_Printf ("num_edicts:%3i\n", *(pr)->num_edicts);
|
|
|
|
Sys_Printf ("active :%3i\n", active);
|
|
|
|
Sys_Printf ("view :%3i\n", models);
|
|
|
|
Sys_Printf ("touch :%3i\n", solid);
|
|
|
|
Sys_Printf ("zombie :%3i\n", zombie);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2002-10-08 19:46:42 +00:00
|
|
|
edict_t *
|
|
|
|
EDICT_NUM (progs_t *pr, int n)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-03-04 05:42:26 +00:00
|
|
|
int offs = n * pr->pr_edict_size;
|
|
|
|
if (offs < 0 || n >= pr->pr_edictareasize)
|
2001-09-23 01:29:52 +00:00
|
|
|
PR_RunError (pr, "EDICT_NUM: bad number %i", n);
|
2001-10-08 03:46:44 +00:00
|
|
|
|
2001-03-04 05:42:26 +00:00
|
|
|
return PROG_TO_EDICT (pr, offs);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2001-09-23 01:29:52 +00:00
|
|
|
NUM_FOR_BAD_EDICT (progs_t *pr, edict_t *e)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2002-10-08 19:46:42 +00:00
|
|
|
int b;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-28 02:25:03 +00:00
|
|
|
b = (byte *) e - (byte *) * (pr)->edicts;
|
2001-02-19 21:15:25 +00:00
|
|
|
b = b / pr->pr_edict_size;
|
|
|
|
|
2001-09-23 01:29:52 +00:00
|
|
|
return b;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
NUM_FOR_EDICT (progs_t *pr, edict_t *e)
|
|
|
|
{
|
2002-10-08 19:46:42 +00:00
|
|
|
int b;
|
2001-09-23 01:29:52 +00:00
|
|
|
|
|
|
|
b = NUM_FOR_BAD_EDICT (pr, e);
|
|
|
|
|
2001-06-06 00:38:05 +00:00
|
|
|
if (b && (b < 0 || b >= *(pr)->num_edicts))
|
2001-09-23 01:29:52 +00:00
|
|
|
PR_RunError (pr, "NUM_FOR_EDICT: bad pointer %d %p %p", b, e, * (pr)->edicts);
|
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
return b;
|
|
|
|
}
|
2002-10-29 05:07:10 +00:00
|
|
|
|
|
|
|
qboolean
|
|
|
|
PR_EdictValid (progs_t *pr, int e)
|
|
|
|
{
|
|
|
|
if (e < 0 || e >= pr->pr_edictareasize)
|
|
|
|
return false;
|
|
|
|
if (e % pr->pr_edict_size)
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|