1999-12-25 05:22:39 +00:00
|
|
|
/*
|
2000-03-24 12:43:07 +00:00
|
|
|
pr_edict.c
|
1999-12-25 05:22:39 +00:00
|
|
|
|
2000-03-24 12:43:07 +00:00
|
|
|
entity dictionary
|
1999-12-25 05:22:39 +00:00
|
|
|
|
2000-03-24 12:43:07 +00:00
|
|
|
Copyright (C) 1996-1997 Id Software, Inc.
|
|
|
|
Copyright (C) 1999,2000 Nelson Rush.
|
|
|
|
Copyright (C) 1999,2000 contributors of the QuakeForge project
|
|
|
|
Please see the file "AUTHORS" for a list of contributors
|
1999-12-25 05:22:39 +00:00
|
|
|
|
2000-03-24 12:43:07 +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.
|
1999-12-25 05:22:39 +00:00
|
|
|
|
2000-03-24 12:43:07 +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.
|
1999-12-25 05:22:39 +00:00
|
|
|
|
2000-03-24 12:43:07 +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$
|
1999-12-25 05:22:39 +00:00
|
|
|
*/
|
|
|
|
|
2000-02-11 04:55:11 +00:00
|
|
|
#include <ctype.h>
|
|
|
|
#include <quakedef.h>
|
2000-01-29 18:46:26 +00:00
|
|
|
#include <qtypes.h>
|
2000-02-11 04:55:11 +00:00
|
|
|
#include <net.h>
|
2000-01-29 18:46:26 +00:00
|
|
|
#include <cmd.h>
|
2000-02-11 04:55:11 +00:00
|
|
|
#include <sys.h>
|
2000-02-03 00:34:12 +00:00
|
|
|
#include <console.h>
|
2000-02-11 04:55:11 +00:00
|
|
|
#include <protocol.h>
|
|
|
|
#include <server.h>
|
|
|
|
#include <phys.h>
|
|
|
|
#include <mathlib.h>
|
|
|
|
#include <world.h>
|
|
|
|
#include <crc.h>
|
2000-01-29 18:46:26 +00:00
|
|
|
|
1999-12-25 05:22:39 +00:00
|
|
|
dprograms_t *progs;
|
|
|
|
dfunction_t *pr_functions;
|
|
|
|
char *pr_strings;
|
|
|
|
ddef_t *pr_fielddefs;
|
|
|
|
ddef_t *pr_globaldefs;
|
|
|
|
dstatement_t *pr_statements;
|
|
|
|
globalvars_t *pr_global_struct;
|
|
|
|
float *pr_globals; // same as pr_global_struct
|
|
|
|
int pr_edict_size; // in bytes
|
|
|
|
|
2000-01-03 04:45:54 +00:00
|
|
|
#ifdef QUAKEWORLD
|
1999-12-25 05:22:39 +00:00
|
|
|
int type_size[8] = {1,sizeof(void *)/4,1,3,1,1,sizeof(void *)/4,sizeof(void *)/4};
|
2000-01-03 04:45:54 +00:00
|
|
|
#else
|
|
|
|
unsigned short pr_crc;
|
|
|
|
int type_size[8] = {1,sizeof(string_t)/4,1,3,1,1,sizeof(func_t)/4,sizeof(void *)/4};
|
|
|
|
#endif
|
1999-12-25 05:22:39 +00:00
|
|
|
|
|
|
|
ddef_t *ED_FieldAtOfs (int ofs);
|
|
|
|
qboolean ED_ParseEpair (void *base, ddef_t *key, char *s);
|
|
|
|
|
2000-01-03 04:45:54 +00:00
|
|
|
#ifndef QUAKEWORLD
|
2000-02-27 07:13:32 +00:00
|
|
|
//cvar_t nomonsters = {"nomonsters", "0"};
|
|
|
|
cvar_t *nomonsters;
|
|
|
|
//cvar_t gamecfg = {"gamecfg", "0"};
|
|
|
|
cvar_t *gamecfg;
|
|
|
|
//cvar_t scratch1 = {"scratch1", "0"};
|
|
|
|
cvar_t *scratch1;
|
|
|
|
//cvar_t scratch2 = {"scratch2", "0"};
|
|
|
|
cvar_t *scratch2;
|
|
|
|
//cvar_t scratch3 = {"scratch3", "0"};
|
|
|
|
cvar_t *scratch3;
|
|
|
|
//cvar_t scratch4 = {"scratch4", "0"};
|
|
|
|
cvar_t *scratch4;
|
|
|
|
//cvar_t savedgamecfg = {"savedgamecfg", "0", CVAR_ARCHIVE};
|
|
|
|
cvar_t *savedgamecfg;
|
|
|
|
//cvar_t saved1 = {"saved1", "0", CVAR_ARCHIVE};
|
|
|
|
cvar_t *saved1;
|
|
|
|
//cvar_t saved2 = {"saved2", "0", CVAR_ARCHIVE};
|
|
|
|
cvar_t *saved2;
|
|
|
|
//cvar_t saved3 = {"saved3", "0", CVAR_ARCHIVE};
|
|
|
|
cvar_t *saved3;
|
|
|
|
//cvar_t saved4 = {"saved4", "0", CVAR_ARCHIVE};
|
|
|
|
cvar_t *saved4;
|
2000-01-03 04:45:54 +00:00
|
|
|
#endif
|
|
|
|
|
1999-12-25 05:22:39 +00:00
|
|
|
#define MAX_FIELD_LEN 64
|
|
|
|
#define GEFV_CACHESIZE 2
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
ddef_t *pcache;
|
|
|
|
char field[MAX_FIELD_LEN];
|
|
|
|
} gefv_cache;
|
|
|
|
|
|
|
|
static gefv_cache gefvCache[GEFV_CACHESIZE] = {{NULL, ""}, {NULL, ""}};
|
|
|
|
|
2000-01-03 04:45:54 +00:00
|
|
|
#ifdef QUAKEWORLD
|
1999-12-25 05:22:39 +00:00
|
|
|
func_t SpectatorConnect;
|
|
|
|
func_t SpectatorThink;
|
|
|
|
func_t SpectatorDisconnect;
|
2000-01-03 04:45:54 +00:00
|
|
|
#endif
|
1999-12-25 05:22:39 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
|
|
|
ED_ClearEdict
|
|
|
|
|
|
|
|
Sets everything to NULL
|
|
|
|
=================
|
|
|
|
*/
|
|
|
|
void ED_ClearEdict (edict_t *e)
|
|
|
|
{
|
|
|
|
memset (&e->v, 0, progs->entityfields * 4);
|
|
|
|
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.
|
|
|
|
=================
|
|
|
|
*/
|
|
|
|
edict_t *ED_Alloc (void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
edict_t *e;
|
|
|
|
|
2000-01-03 04:45:54 +00:00
|
|
|
#ifdef QUAKEWORLD
|
1999-12-25 05:22:39 +00:00
|
|
|
for ( i=MAX_CLIENTS+1 ; i<sv.num_edicts ; i++)
|
2000-01-03 04:45:54 +00:00
|
|
|
#else
|
|
|
|
for ( i=svs.maxclients+1 ; i<sv.num_edicts ; i++)
|
|
|
|
#endif
|
1999-12-25 05:22:39 +00:00
|
|
|
{
|
|
|
|
e = EDICT_NUM(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 || sv.time - e->freetime > 0.5 ) )
|
|
|
|
{
|
|
|
|
ED_ClearEdict (e);
|
|
|
|
return e;
|
|
|
|
}
|
|
|
|
}
|
2000-03-19 15:59:51 +00:00
|
|
|
|
1999-12-25 05:22:39 +00:00
|
|
|
if (i == MAX_EDICTS)
|
2000-01-03 04:45:54 +00:00
|
|
|
#ifdef QUAKEWORLD
|
1999-12-25 05:22:39 +00:00
|
|
|
{
|
|
|
|
Con_Printf ("WARNING: ED_Alloc: no free edicts\n");
|
|
|
|
i--; // step on whatever is the last edict
|
|
|
|
e = EDICT_NUM(i);
|
|
|
|
SV_UnlinkEdict(e);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
sv.num_edicts++;
|
2000-01-03 04:45:54 +00:00
|
|
|
#else
|
|
|
|
Sys_Error ("ED_Alloc: no free edicts");
|
|
|
|
|
|
|
|
sv.num_edicts++;
|
|
|
|
#endif
|
|
|
|
|
1999-12-25 05:22:39 +00:00
|
|
|
e = EDICT_NUM(i);
|
|
|
|
ED_ClearEdict (e);
|
|
|
|
|
|
|
|
return e;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
|
|
|
ED_Free
|
|
|
|
|
|
|
|
Marks the edict as free
|
|
|
|
FIXME: walk all entities and NULL out references to this entity
|
|
|
|
=================
|
|
|
|
*/
|
|
|
|
void ED_Free (edict_t *ed)
|
|
|
|
{
|
|
|
|
SV_UnlinkEdict (ed); // unlink from world bsp
|
|
|
|
|
|
|
|
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-03-19 15:59:51 +00:00
|
|
|
|
1999-12-25 05:22:39 +00:00
|
|
|
ed->freetime = sv.time;
|
|
|
|
}
|
|
|
|
|
|
|
|
//===========================================================================
|
|
|
|
|
|
|
|
/*
|
|
|
|
============
|
|
|
|
ED_GlobalAtOfs
|
|
|
|
============
|
|
|
|
*/
|
|
|
|
ddef_t *ED_GlobalAtOfs (int ofs)
|
|
|
|
{
|
|
|
|
ddef_t *def;
|
|
|
|
int i;
|
2000-03-19 15:59:51 +00:00
|
|
|
|
1999-12-25 05:22:39 +00:00
|
|
|
for (i=0 ; i<progs->numglobaldefs ; i++)
|
|
|
|
{
|
|
|
|
def = &pr_globaldefs[i];
|
|
|
|
if (def->ofs == ofs)
|
|
|
|
return def;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
============
|
|
|
|
ED_FieldAtOfs
|
|
|
|
============
|
|
|
|
*/
|
|
|
|
ddef_t *ED_FieldAtOfs (int ofs)
|
|
|
|
{
|
|
|
|
ddef_t *def;
|
|
|
|
int i;
|
2000-03-19 15:59:51 +00:00
|
|
|
|
1999-12-25 05:22:39 +00:00
|
|
|
for (i=0 ; i<progs->numfielddefs ; i++)
|
|
|
|
{
|
|
|
|
def = &pr_fielddefs[i];
|
|
|
|
if (def->ofs == ofs)
|
|
|
|
return def;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
============
|
|
|
|
ED_FindField
|
|
|
|
============
|
|
|
|
*/
|
|
|
|
ddef_t *ED_FindField (char *name)
|
|
|
|
{
|
|
|
|
ddef_t *def;
|
|
|
|
int i;
|
2000-03-19 15:59:51 +00:00
|
|
|
|
1999-12-25 05:22:39 +00:00
|
|
|
for (i=0 ; i<progs->numfielddefs ; i++)
|
|
|
|
{
|
|
|
|
def = &pr_fielddefs[i];
|
|
|
|
if (!strcmp(PR_GetString(def->s_name),name) )
|
|
|
|
return def;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
============
|
|
|
|
ED_FindGlobal
|
|
|
|
============
|
|
|
|
*/
|
|
|
|
ddef_t *ED_FindGlobal (char *name)
|
|
|
|
{
|
|
|
|
ddef_t *def;
|
|
|
|
int i;
|
2000-03-19 15:59:51 +00:00
|
|
|
|
1999-12-25 05:22:39 +00:00
|
|
|
for (i=0 ; i<progs->numglobaldefs ; i++)
|
|
|
|
{
|
|
|
|
def = &pr_globaldefs[i];
|
|
|
|
if (!strcmp(PR_GetString(def->s_name),name) )
|
|
|
|
return def;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
============
|
|
|
|
ED_FindFunction
|
|
|
|
============
|
|
|
|
*/
|
|
|
|
dfunction_t *ED_FindFunction (char *name)
|
|
|
|
{
|
|
|
|
dfunction_t *func;
|
|
|
|
int i;
|
2000-03-19 15:59:51 +00:00
|
|
|
|
1999-12-25 05:22:39 +00:00
|
|
|
for (i=0 ; i<progs->numfunctions ; i++)
|
|
|
|
{
|
|
|
|
func = &pr_functions[i];
|
|
|
|
if (!strcmp(PR_GetString(func->s_name),name) )
|
|
|
|
return func;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
eval_t *GetEdictFieldValue(edict_t *ed, char *field)
|
|
|
|
{
|
|
|
|
ddef_t *def = NULL;
|
|
|
|
int i;
|
|
|
|
static int rep = 0;
|
|
|
|
|
|
|
|
for (i=0 ; i<GEFV_CACHESIZE ; i++)
|
|
|
|
{
|
|
|
|
if (!strcmp(field, gefvCache[i].field))
|
|
|
|
{
|
|
|
|
def = gefvCache[i].pcache;
|
|
|
|
goto Done;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
def = ED_FindField (field);
|
|
|
|
|
|
|
|
if (strlen(field) < MAX_FIELD_LEN)
|
|
|
|
{
|
|
|
|
gefvCache[rep].pcache = def;
|
|
|
|
strcpy (gefvCache[rep].field, field);
|
|
|
|
rep ^= 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
Done:
|
|
|
|
if (!def)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return (eval_t *)((char *)&ed->v + def->ofs*4);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
============
|
|
|
|
PR_ValueString
|
|
|
|
|
|
|
|
Returns a string describing *data in a type specific manner
|
|
|
|
=============
|
|
|
|
*/
|
|
|
|
char *PR_ValueString (etype_t type, eval_t *val)
|
|
|
|
{
|
|
|
|
static char line[256];
|
|
|
|
ddef_t *def;
|
|
|
|
dfunction_t *f;
|
2000-03-19 15:59:51 +00:00
|
|
|
|
1999-12-25 05:22:39 +00:00
|
|
|
type &= ~DEF_SAVEGLOBAL;
|
|
|
|
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case ev_string:
|
2000-01-05 00:05:48 +00:00
|
|
|
snprintf(line, sizeof(line), "%s", PR_GetString(val->string));
|
1999-12-25 05:22:39 +00:00
|
|
|
break;
|
2000-03-19 15:59:51 +00:00
|
|
|
case ev_entity:
|
2000-01-05 00:05:48 +00:00
|
|
|
snprintf(line, sizeof(line), "entity %i", NUM_FOR_EDICT(PROG_TO_EDICT(val->edict)) );
|
1999-12-25 05:22:39 +00:00
|
|
|
break;
|
|
|
|
case ev_function:
|
|
|
|
f = pr_functions + val->function;
|
2000-01-05 00:05:48 +00:00
|
|
|
snprintf(line, sizeof(line), "%s()", PR_GetString(f->s_name));
|
1999-12-25 05:22:39 +00:00
|
|
|
break;
|
|
|
|
case ev_field:
|
|
|
|
def = ED_FieldAtOfs ( val->_int );
|
2000-01-05 00:05:48 +00:00
|
|
|
snprintf(line, sizeof(line), ".%s", PR_GetString(def->s_name));
|
1999-12-25 05:22:39 +00:00
|
|
|
break;
|
|
|
|
case ev_void:
|
2000-01-05 00:05:48 +00:00
|
|
|
snprintf(line, sizeof(line), "void");
|
1999-12-25 05:22:39 +00:00
|
|
|
break;
|
|
|
|
case ev_float:
|
2000-01-05 00:05:48 +00:00
|
|
|
snprintf(line, sizeof(line), "%5.1f", val->_float);
|
1999-12-25 05:22:39 +00:00
|
|
|
break;
|
|
|
|
case ev_vector:
|
2000-01-05 00:05:48 +00:00
|
|
|
snprintf(line, sizeof(line), "'%5.1f %5.1f %5.1f'", val->vector[0], val->vector[1], val->vector[2]);
|
1999-12-25 05:22:39 +00:00
|
|
|
break;
|
|
|
|
case ev_pointer:
|
2000-01-05 00:05:48 +00:00
|
|
|
snprintf(line, sizeof(line), "pointer");
|
1999-12-25 05:22:39 +00:00
|
|
|
break;
|
|
|
|
default:
|
2000-01-05 00:05:48 +00:00
|
|
|
snprintf(line, sizeof(line), "bad type %i", type);
|
1999-12-25 05:22:39 +00:00
|
|
|
break;
|
|
|
|
}
|
2000-03-19 15:59:51 +00:00
|
|
|
|
1999-12-25 05:22:39 +00:00
|
|
|
return line;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
============
|
|
|
|
PR_UglyValueString
|
|
|
|
|
|
|
|
Returns a string describing *data in a type specific manner
|
|
|
|
Easier to parse than PR_ValueString
|
|
|
|
=============
|
|
|
|
*/
|
|
|
|
char *PR_UglyValueString (etype_t type, eval_t *val)
|
|
|
|
{
|
|
|
|
static char line[256];
|
|
|
|
ddef_t *def;
|
|
|
|
dfunction_t *f;
|
2000-03-19 15:59:51 +00:00
|
|
|
|
1999-12-25 05:22:39 +00:00
|
|
|
type &= ~DEF_SAVEGLOBAL;
|
|
|
|
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case ev_string:
|
2000-01-05 00:05:48 +00:00
|
|
|
snprintf(line, sizeof(line), "%s", PR_GetString(val->string));
|
1999-12-25 05:22:39 +00:00
|
|
|
break;
|
2000-03-19 15:59:51 +00:00
|
|
|
case ev_entity:
|
2000-01-05 00:05:48 +00:00
|
|
|
snprintf(line, sizeof(line), "%i", NUM_FOR_EDICT(PROG_TO_EDICT(val->edict)));
|
1999-12-25 05:22:39 +00:00
|
|
|
break;
|
|
|
|
case ev_function:
|
|
|
|
f = pr_functions + val->function;
|
2000-01-05 00:05:48 +00:00
|
|
|
snprintf(line, sizeof(line), "%s", PR_GetString(f->s_name));
|
1999-12-25 05:22:39 +00:00
|
|
|
break;
|
|
|
|
case ev_field:
|
|
|
|
def = ED_FieldAtOfs ( val->_int );
|
2000-01-05 00:05:48 +00:00
|
|
|
snprintf(line, sizeof(line), "%s", PR_GetString(def->s_name));
|
1999-12-25 05:22:39 +00:00
|
|
|
break;
|
|
|
|
case ev_void:
|
2000-01-05 00:05:48 +00:00
|
|
|
snprintf(line, sizeof(line), "void");
|
1999-12-25 05:22:39 +00:00
|
|
|
break;
|
|
|
|
case ev_float:
|
2000-01-05 00:05:48 +00:00
|
|
|
snprintf(line, sizeof(line), "%f", val->_float);
|
1999-12-25 05:22:39 +00:00
|
|
|
break;
|
|
|
|
case ev_vector:
|
2000-01-05 00:05:48 +00:00
|
|
|
snprintf(line, sizeof(line), "%f %f %f", val->vector[0], val->vector[1], val->vector[2]);
|
1999-12-25 05:22:39 +00:00
|
|
|
break;
|
|
|
|
default:
|
2000-01-05 00:05:48 +00:00
|
|
|
snprintf(line, sizeof(line), "bad type %i", type);
|
1999-12-25 05:22:39 +00:00
|
|
|
break;
|
|
|
|
}
|
2000-03-19 15:59:51 +00:00
|
|
|
|
1999-12-25 05:22:39 +00:00
|
|
|
return line;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
============
|
|
|
|
PR_GlobalString
|
|
|
|
|
|
|
|
Returns a string with a description and the contents of a global,
|
|
|
|
padded to 20 field width
|
|
|
|
============
|
|
|
|
*/
|
|
|
|
char *PR_GlobalString (int ofs)
|
|
|
|
{
|
|
|
|
char *s;
|
|
|
|
int i;
|
|
|
|
ddef_t *def;
|
|
|
|
void *val;
|
|
|
|
static char line[128];
|
2000-03-19 15:59:51 +00:00
|
|
|
|
1999-12-25 05:22:39 +00:00
|
|
|
val = (void *)&pr_globals[ofs];
|
|
|
|
def = ED_GlobalAtOfs(ofs);
|
|
|
|
if (!def)
|
2000-01-05 00:05:48 +00:00
|
|
|
snprintf(line, sizeof(line),"%i(???)", ofs);
|
1999-12-25 05:22:39 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
s = PR_ValueString (def->type, val);
|
2000-01-05 00:05:48 +00:00
|
|
|
snprintf(line, sizeof(line),"%i(%s)%s", ofs, PR_GetString(def->s_name), s);
|
1999-12-25 05:22:39 +00:00
|
|
|
}
|
2000-03-19 15:59:51 +00:00
|
|
|
|
1999-12-25 05:22:39 +00:00
|
|
|
i = strlen(line);
|
|
|
|
for ( ; i<20 ; i++)
|
|
|
|
strcat (line," ");
|
|
|
|
strcat (line," ");
|
2000-03-19 15:59:51 +00:00
|
|
|
|
1999-12-25 05:22:39 +00:00
|
|
|
return line;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *PR_GlobalStringNoContents (int ofs)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
ddef_t *def;
|
|
|
|
static char line[128];
|
2000-03-19 15:59:51 +00:00
|
|
|
|
1999-12-25 05:22:39 +00:00
|
|
|
def = ED_GlobalAtOfs(ofs);
|
|
|
|
if (!def)
|
2000-01-05 00:05:48 +00:00
|
|
|
snprintf(line, sizeof(line),"%i(???)", ofs);
|
1999-12-25 05:22:39 +00:00
|
|
|
else
|
2000-01-05 00:05:48 +00:00
|
|
|
snprintf(line, sizeof(line),"%i(%s)", ofs, PR_GetString(def->s_name));
|
2000-03-19 15:59:51 +00:00
|
|
|
|
1999-12-25 05:22:39 +00:00
|
|
|
i = strlen(line);
|
|
|
|
for ( ; i<20 ; i++)
|
|
|
|
strcat (line," ");
|
|
|
|
strcat (line," ");
|
2000-03-19 15:59:51 +00:00
|
|
|
|
1999-12-25 05:22:39 +00:00
|
|
|
return line;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
=============
|
|
|
|
ED_Print
|
|
|
|
|
|
|
|
For debugging
|
|
|
|
=============
|
|
|
|
*/
|
|
|
|
void ED_Print (edict_t *ed)
|
|
|
|
{
|
|
|
|
int l;
|
|
|
|
ddef_t *d;
|
|
|
|
int *v;
|
|
|
|
int i, j;
|
|
|
|
char *name;
|
|
|
|
int type;
|
|
|
|
|
|
|
|
if (ed->free)
|
|
|
|
{
|
|
|
|
Con_Printf ("FREE\n");
|
|
|
|
return;
|
|
|
|
}
|
2000-03-19 15:59:51 +00:00
|
|
|
|
1999-12-25 05:22:39 +00:00
|
|
|
for (i=1 ; i<progs->numfielddefs ; i++)
|
|
|
|
{
|
|
|
|
d = &pr_fielddefs[i];
|
|
|
|
name = PR_GetString(d->s_name);
|
|
|
|
if (name[strlen(name)-2] == '_')
|
|
|
|
continue; // skip _x, _y, _z vars
|
2000-03-19 15:59:51 +00:00
|
|
|
|
1999-12-25 05:22:39 +00:00
|
|
|
v = (int *)((char *)&ed->v + d->ofs*4);
|
|
|
|
|
|
|
|
// if the value is still all 0, skip the field
|
|
|
|
type = d->type & ~DEF_SAVEGLOBAL;
|
2000-03-19 15:59:51 +00:00
|
|
|
|
1999-12-25 05:22:39 +00:00
|
|
|
for (j=0 ; j<type_size[type] ; j++)
|
|
|
|
if (v[j])
|
|
|
|
break;
|
|
|
|
if (j == type_size[type])
|
|
|
|
continue;
|
2000-03-19 15:59:51 +00:00
|
|
|
|
1999-12-25 05:22:39 +00:00
|
|
|
Con_Printf ("%s",name);
|
|
|
|
l = strlen (name);
|
|
|
|
while (l++ < 15)
|
|
|
|
Con_Printf (" ");
|
|
|
|
|
2000-03-19 15:59:51 +00:00
|
|
|
Con_Printf ("%s\n", PR_ValueString(d->type, (eval_t *)v));
|
1999-12-25 05:22:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=============
|
|
|
|
ED_Write
|
|
|
|
|
|
|
|
For savegames
|
|
|
|
=============
|
|
|
|
*/
|
2000-02-08 05:06:58 +00:00
|
|
|
void ED_Write (QFile *f, edict_t *ed)
|
1999-12-25 05:22:39 +00:00
|
|
|
{
|
|
|
|
ddef_t *d;
|
|
|
|
int *v;
|
|
|
|
int i, j;
|
|
|
|
char *name;
|
|
|
|
int type;
|
|
|
|
|
2000-02-08 05:06:58 +00:00
|
|
|
Qprintf (f, "{\n");
|
1999-12-25 05:22:39 +00:00
|
|
|
|
|
|
|
if (ed->free)
|
|
|
|
{
|
2000-02-08 05:06:58 +00:00
|
|
|
Qprintf (f, "}\n");
|
1999-12-25 05:22:39 +00:00
|
|
|
return;
|
|
|
|
}
|
2000-03-19 15:59:51 +00:00
|
|
|
|
1999-12-25 05:22:39 +00:00
|
|
|
for (i=1 ; i<progs->numfielddefs ; i++)
|
|
|
|
{
|
|
|
|
d = &pr_fielddefs[i];
|
|
|
|
name = PR_GetString(d->s_name);
|
|
|
|
if (name[strlen(name)-2] == '_')
|
|
|
|
continue; // skip _x, _y, _z vars
|
2000-03-19 15:59:51 +00:00
|
|
|
|
1999-12-25 05:22:39 +00:00
|
|
|
v = (int *)((char *)&ed->v + d->ofs*4);
|
|
|
|
|
|
|
|
// if the value is still all 0, skip the field
|
|
|
|
type = d->type & ~DEF_SAVEGLOBAL;
|
|
|
|
for (j=0 ; j<type_size[type] ; j++)
|
|
|
|
if (v[j])
|
|
|
|
break;
|
|
|
|
if (j == type_size[type])
|
|
|
|
continue;
|
2000-03-19 15:59:51 +00:00
|
|
|
|
2000-02-08 05:06:58 +00:00
|
|
|
Qprintf (f,"\"%s\" ",name);
|
2000-03-19 15:59:51 +00:00
|
|
|
Qprintf (f,"\"%s\"\n", PR_UglyValueString(d->type, (eval_t *)v));
|
1999-12-25 05:22:39 +00:00
|
|
|
}
|
|
|
|
|
2000-02-08 05:06:58 +00:00
|
|
|
Qprintf (f, "}\n");
|
1999-12-25 05:22:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ED_PrintNum (int ent)
|
|
|
|
{
|
|
|
|
ED_Print (EDICT_NUM(ent));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=============
|
|
|
|
ED_PrintEdicts
|
|
|
|
|
|
|
|
For debugging, prints all the entities in the current server
|
|
|
|
=============
|
|
|
|
*/
|
|
|
|
void ED_PrintEdicts (void)
|
|
|
|
{
|
|
|
|
int i;
|
2000-03-19 15:59:51 +00:00
|
|
|
|
1999-12-25 05:22:39 +00:00
|
|
|
Con_Printf ("%i entities\n", sv.num_edicts);
|
|
|
|
for (i=0 ; i<sv.num_edicts ; i++)
|
|
|
|
{
|
|
|
|
Con_Printf ("\nEDICT %i:\n",i);
|
|
|
|
ED_PrintNum (i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=============
|
|
|
|
ED_PrintEdict_f
|
|
|
|
|
|
|
|
For debugging, prints a single edicy
|
|
|
|
=============
|
|
|
|
*/
|
|
|
|
void ED_PrintEdict_f (void)
|
|
|
|
{
|
|
|
|
int i;
|
2000-03-19 15:59:51 +00:00
|
|
|
|
1999-12-25 05:22:39 +00:00
|
|
|
i = Q_atoi (Cmd_Argv(1));
|
2000-01-03 04:45:54 +00:00
|
|
|
#ifdef QUAKEWORLD
|
1999-12-25 05:22:39 +00:00
|
|
|
Con_Printf ("\n EDICT %i:\n",i);
|
2000-01-03 04:45:54 +00:00
|
|
|
#else
|
|
|
|
if (i >= sv.num_edicts)
|
|
|
|
{
|
|
|
|
Con_Printf("Bad edict number\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
1999-12-25 05:22:39 +00:00
|
|
|
ED_PrintNum (i);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=============
|
|
|
|
ED_Count
|
|
|
|
|
|
|
|
For debugging
|
|
|
|
=============
|
|
|
|
*/
|
|
|
|
void ED_Count (void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
edict_t *ent;
|
|
|
|
int active, models, solid, step;
|
|
|
|
|
|
|
|
active = models = solid = step = 0;
|
|
|
|
for (i=0 ; i<sv.num_edicts ; i++)
|
|
|
|
{
|
|
|
|
ent = EDICT_NUM(i);
|
|
|
|
if (ent->free)
|
|
|
|
continue;
|
|
|
|
active++;
|
|
|
|
if (ent->v.solid)
|
|
|
|
solid++;
|
|
|
|
if (ent->v.model)
|
|
|
|
models++;
|
|
|
|
if (ent->v.movetype == MOVETYPE_STEP)
|
|
|
|
step++;
|
|
|
|
}
|
|
|
|
|
|
|
|
Con_Printf ("num_edicts:%3i\n", sv.num_edicts);
|
|
|
|
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
|
|
|
|
==============================================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
=============
|
|
|
|
ED_WriteGlobals
|
|
|
|
=============
|
|
|
|
*/
|
2000-02-08 05:06:58 +00:00
|
|
|
void ED_WriteGlobals (QFile *f)
|
1999-12-25 05:22:39 +00:00
|
|
|
{
|
|
|
|
ddef_t *def;
|
|
|
|
int i;
|
|
|
|
char *name;
|
|
|
|
int type;
|
|
|
|
|
2000-02-08 05:06:58 +00:00
|
|
|
Qprintf (f,"{\n");
|
1999-12-25 05:22:39 +00:00
|
|
|
for (i=0 ; i<progs->numglobaldefs ; i++)
|
|
|
|
{
|
|
|
|
def = &pr_globaldefs[i];
|
|
|
|
type = def->type;
|
|
|
|
if ( !(def->type & DEF_SAVEGLOBAL) )
|
|
|
|
continue;
|
|
|
|
type &= ~DEF_SAVEGLOBAL;
|
|
|
|
|
|
|
|
if (type != ev_string
|
|
|
|
&& type != ev_float
|
|
|
|
&& type != ev_entity)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
name = PR_GetString(def->s_name);
|
2000-02-08 05:06:58 +00:00
|
|
|
Qprintf (f,"\"%s\" ", name);
|
2000-03-19 15:59:51 +00:00
|
|
|
Qprintf (f,"\"%s\"\n", PR_UglyValueString(type, (eval_t *)&pr_globals[def->ofs]));
|
1999-12-25 05:22:39 +00:00
|
|
|
}
|
2000-02-08 05:06:58 +00:00
|
|
|
Qprintf (f,"}\n");
|
1999-12-25 05:22:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=============
|
|
|
|
ED_ParseGlobals
|
|
|
|
=============
|
|
|
|
*/
|
|
|
|
void ED_ParseGlobals (char *data)
|
|
|
|
{
|
|
|
|
char keyname[64];
|
|
|
|
ddef_t *key;
|
|
|
|
|
|
|
|
while (1)
|
2000-03-19 15:59:51 +00:00
|
|
|
{
|
1999-12-25 05:22:39 +00:00
|
|
|
// parse key
|
|
|
|
data = COM_Parse (data);
|
|
|
|
if (com_token[0] == '}')
|
|
|
|
break;
|
|
|
|
if (!data)
|
2000-01-03 04:45:54 +00:00
|
|
|
#ifdef QUAKEWORLD
|
1999-12-25 05:22:39 +00:00
|
|
|
SV_Error ("ED_ParseEntity: EOF without closing brace");
|
2000-01-03 04:45:54 +00:00
|
|
|
#else
|
|
|
|
Sys_Error ("ED_ParseEntity: EOF without closing brace");
|
|
|
|
#endif
|
1999-12-25 05:22:39 +00:00
|
|
|
|
|
|
|
strcpy (keyname, com_token);
|
|
|
|
|
2000-03-19 15:59:51 +00:00
|
|
|
// parse value
|
1999-12-25 05:22:39 +00:00
|
|
|
data = COM_Parse (data);
|
|
|
|
if (!data)
|
2000-01-03 04:45:54 +00:00
|
|
|
#ifdef QUAKEWORLD
|
1999-12-25 05:22:39 +00:00
|
|
|
SV_Error ("ED_ParseEntity: EOF without closing brace");
|
2000-01-03 04:45:54 +00:00
|
|
|
#else
|
|
|
|
Sys_Error ("ED_ParseEntity: EOF without closing brace");
|
|
|
|
#endif
|
1999-12-25 05:22:39 +00:00
|
|
|
|
|
|
|
if (com_token[0] == '}')
|
2000-01-03 04:45:54 +00:00
|
|
|
#ifdef QUAKEWORLD
|
1999-12-25 05:22:39 +00:00
|
|
|
SV_Error ("ED_ParseEntity: closing brace without data");
|
2000-01-03 04:45:54 +00:00
|
|
|
#else
|
|
|
|
Sys_Error ("ED_ParseEntity: closing brace without data");
|
|
|
|
#endif
|
1999-12-25 05:22:39 +00:00
|
|
|
|
|
|
|
key = ED_FindGlobal (keyname);
|
|
|
|
if (!key)
|
|
|
|
{
|
|
|
|
Con_Printf ("%s is not a global\n", keyname);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ED_ParseEpair ((void *)pr_globals, key, com_token))
|
2000-01-03 04:45:54 +00:00
|
|
|
#ifdef QUAKEWORLD
|
1999-12-25 05:22:39 +00:00
|
|
|
SV_Error ("ED_ParseGlobals: parse error");
|
2000-01-03 04:45:54 +00:00
|
|
|
#else
|
|
|
|
Host_Error ("ED_ParseGlobals: parse error");
|
|
|
|
#endif
|
1999-12-25 05:22:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
=============
|
|
|
|
ED_NewString
|
|
|
|
=============
|
|
|
|
*/
|
|
|
|
char *ED_NewString (char *string)
|
|
|
|
{
|
|
|
|
char *new, *new_p;
|
|
|
|
int i,l;
|
2000-03-19 15:59:51 +00:00
|
|
|
|
1999-12-25 05:22:39 +00:00
|
|
|
l = strlen(string) + 1;
|
|
|
|
new = Hunk_Alloc (l);
|
|
|
|
new_p = new;
|
|
|
|
|
|
|
|
for (i=0 ; i< l ; i++)
|
|
|
|
{
|
|
|
|
if (string[i] == '\\' && i < l-1)
|
|
|
|
{
|
|
|
|
i++;
|
|
|
|
if (string[i] == 'n')
|
|
|
|
*new_p++ = '\n';
|
|
|
|
else
|
|
|
|
*new_p++ = '\\';
|
|
|
|
}
|
|
|
|
else
|
|
|
|
*new_p++ = string[i];
|
|
|
|
}
|
2000-03-19 15:59:51 +00:00
|
|
|
|
1999-12-25 05:22:39 +00:00
|
|
|
return new;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
=============
|
|
|
|
ED_ParseEval
|
|
|
|
|
|
|
|
Can parse either fields or globals
|
|
|
|
returns false if error
|
|
|
|
=============
|
|
|
|
*/
|
|
|
|
qboolean ED_ParseEpair (void *base, ddef_t *key, char *s)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
char string[128];
|
|
|
|
ddef_t *def;
|
|
|
|
char *v, *w;
|
|
|
|
void *d;
|
|
|
|
dfunction_t *func;
|
2000-03-19 15:59:51 +00:00
|
|
|
|
1999-12-25 05:22:39 +00:00
|
|
|
d = (void *)((int *)base + key->ofs);
|
2000-03-19 15:59:51 +00:00
|
|
|
|
1999-12-25 05:22:39 +00:00
|
|
|
switch (key->type & ~DEF_SAVEGLOBAL)
|
|
|
|
{
|
|
|
|
case ev_string:
|
|
|
|
*(string_t *)d = PR_SetString(ED_NewString (s));
|
|
|
|
break;
|
2000-03-19 15:59:51 +00:00
|
|
|
|
1999-12-25 05:22:39 +00:00
|
|
|
case ev_float:
|
|
|
|
*(float *)d = atof (s);
|
|
|
|
break;
|
2000-03-19 15:59:51 +00:00
|
|
|
|
1999-12-25 05:22:39 +00:00
|
|
|
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;
|
2000-03-19 15:59:51 +00:00
|
|
|
|
1999-12-25 05:22:39 +00:00
|
|
|
case ev_entity:
|
|
|
|
*(int *)d = EDICT_TO_PROG(EDICT_NUM(atoi (s)));
|
|
|
|
break;
|
2000-03-19 15:59:51 +00:00
|
|
|
|
1999-12-25 05:22:39 +00:00
|
|
|
case ev_field:
|
|
|
|
def = ED_FindField (s);
|
|
|
|
if (!def)
|
|
|
|
{
|
|
|
|
Con_Printf ("Can't find field %s\n", s);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
*(int *)d = G_INT(def->ofs);
|
|
|
|
break;
|
2000-03-19 15:59:51 +00:00
|
|
|
|
1999-12-25 05:22:39 +00:00
|
|
|
case ev_function:
|
|
|
|
func = ED_FindFunction (s);
|
|
|
|
if (!func)
|
|
|
|
{
|
|
|
|
Con_Printf ("Can't find function %s\n", s);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
*(func_t *)d = func - pr_functions;
|
|
|
|
break;
|
2000-03-19 15:59:51 +00:00
|
|
|
|
1999-12-25 05:22:39 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
====================
|
|
|
|
ED_ParseEdict
|
|
|
|
|
|
|
|
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.
|
|
|
|
====================
|
|
|
|
*/
|
|
|
|
char *ED_ParseEdict (char *data, edict_t *ent)
|
|
|
|
{
|
|
|
|
ddef_t *key;
|
|
|
|
qboolean anglehack;
|
|
|
|
qboolean init;
|
|
|
|
char keyname[256];
|
2000-01-14 03:41:40 +00:00
|
|
|
#ifndef QUAKEWORLD
|
2000-01-03 04:45:54 +00:00
|
|
|
int n;
|
2000-01-14 03:41:40 +00:00
|
|
|
#endif
|
1999-12-25 05:22:39 +00:00
|
|
|
|
|
|
|
init = false;
|
|
|
|
|
|
|
|
// clear it
|
|
|
|
if (ent != sv.edicts) // hack
|
|
|
|
memset (&ent->v, 0, progs->entityfields * 4);
|
|
|
|
|
|
|
|
// go through all the dictionary pairs
|
|
|
|
while (1)
|
2000-03-19 15:59:51 +00:00
|
|
|
{
|
1999-12-25 05:22:39 +00:00
|
|
|
// parse key
|
|
|
|
data = COM_Parse (data);
|
|
|
|
if (com_token[0] == '}')
|
|
|
|
break;
|
|
|
|
if (!data)
|
2000-01-03 04:45:54 +00:00
|
|
|
#ifdef QUAKEWORLD
|
1999-12-25 05:22:39 +00:00
|
|
|
SV_Error ("ED_ParseEntity: EOF without closing brace");
|
2000-01-03 04:45:54 +00:00
|
|
|
#else
|
|
|
|
Sys_Error ("ED_ParseEntity: EOF without closing brace");
|
|
|
|
#endif
|
2000-03-19 15:59:51 +00:00
|
|
|
|
1999-12-25 05:22:39 +00:00
|
|
|
// anglehack is to allow QuakeEd to write single scalar angles
|
|
|
|
// and allow them to be turned into vectors. (FIXME...)
|
|
|
|
if (!strcmp(com_token, "angle"))
|
|
|
|
{
|
|
|
|
strcpy (com_token, "angles");
|
|
|
|
anglehack = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
anglehack = false;
|
|
|
|
|
|
|
|
// FIXME: change light to _light to get rid of this hack
|
|
|
|
if (!strcmp(com_token, "light"))
|
|
|
|
strcpy (com_token, "light_lev"); // hack for single light def
|
|
|
|
|
|
|
|
strcpy (keyname, com_token);
|
2000-01-03 04:45:54 +00:00
|
|
|
|
|
|
|
#ifndef QUAKEWORLD
|
|
|
|
// another hack to fix heynames with trailing spaces
|
|
|
|
n = strlen(keyname);
|
|
|
|
while (n && keyname[n-1] == ' ')
|
|
|
|
{
|
|
|
|
keyname[n-1] = 0;
|
|
|
|
n--;
|
|
|
|
}
|
|
|
|
#endif
|
2000-03-19 15:59:51 +00:00
|
|
|
|
|
|
|
// parse value
|
1999-12-25 05:22:39 +00:00
|
|
|
data = COM_Parse (data);
|
|
|
|
if (!data)
|
2000-01-03 04:45:54 +00:00
|
|
|
#ifdef QUAKEWORLD
|
1999-12-25 05:22:39 +00:00
|
|
|
SV_Error ("ED_ParseEntity: EOF without closing brace");
|
2000-01-03 04:45:54 +00:00
|
|
|
#else
|
|
|
|
Sys_Error ("ED_ParseEntity: EOF without closing brace");
|
|
|
|
#endif
|
1999-12-25 05:22:39 +00:00
|
|
|
|
|
|
|
if (com_token[0] == '}')
|
2000-01-03 04:45:54 +00:00
|
|
|
#ifdef QUAKEWORLD
|
1999-12-25 05:22:39 +00:00
|
|
|
SV_Error ("ED_ParseEntity: closing brace without data");
|
2000-01-03 04:45:54 +00:00
|
|
|
#else
|
|
|
|
Sys_Error ("ED_ParseEntity: closing brace without data");
|
|
|
|
#endif
|
1999-12-25 05:22:39 +00:00
|
|
|
|
2000-03-19 15:59:51 +00:00
|
|
|
init = true;
|
1999-12-25 05:22:39 +00:00
|
|
|
|
|
|
|
// keynames with a leading underscore are used for utility comments,
|
|
|
|
// and are immediately discarded by quake
|
|
|
|
if (keyname[0] == '_')
|
|
|
|
continue;
|
2000-03-19 15:59:51 +00:00
|
|
|
|
1999-12-25 05:22:39 +00:00
|
|
|
key = ED_FindField (keyname);
|
|
|
|
if (!key)
|
|
|
|
{
|
|
|
|
Con_Printf ("%s is not a field\n", keyname);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (anglehack)
|
|
|
|
{
|
|
|
|
char temp[32];
|
|
|
|
strcpy (temp, com_token);
|
2000-01-05 00:05:48 +00:00
|
|
|
snprintf(com_token, sizeof(com_token), "0 %s 0", temp);
|
1999-12-25 05:22:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!ED_ParseEpair ((void *)&ent->v, key, com_token))
|
2000-01-03 04:45:54 +00:00
|
|
|
#ifdef QUAKEWORLD
|
1999-12-25 05:22:39 +00:00
|
|
|
SV_Error ("ED_ParseEdict: parse error");
|
2000-01-03 04:45:54 +00:00
|
|
|
#else
|
|
|
|
Host_Error ("ED_ParseEdict: parse error");
|
|
|
|
#endif
|
1999-12-25 05:22:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!init)
|
|
|
|
ent->free = true;
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
ED_LoadFromFile
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
Creates a server's entity / program execution context by
|
|
|
|
parsing textual entity definitions out of an ent file.
|
|
|
|
|
|
|
|
Used for both fresh maps and savegame loads. A fresh map would also need
|
|
|
|
to call ED_CallSpawnFunctions () to let the objects initialize themselves.
|
|
|
|
================
|
|
|
|
*/
|
|
|
|
void ED_LoadFromFile (char *data)
|
2000-03-19 15:59:51 +00:00
|
|
|
{
|
1999-12-25 05:22:39 +00:00
|
|
|
edict_t *ent;
|
|
|
|
int inhibit;
|
|
|
|
dfunction_t *func;
|
2000-03-19 15:59:51 +00:00
|
|
|
|
1999-12-25 05:22:39 +00:00
|
|
|
ent = NULL;
|
|
|
|
inhibit = 0;
|
|
|
|
pr_global_struct->time = sv.time;
|
2000-03-19 15:59:51 +00:00
|
|
|
|
1999-12-25 05:22:39 +00:00
|
|
|
// parse ents
|
|
|
|
while (1)
|
|
|
|
{
|
2000-03-19 15:59:51 +00:00
|
|
|
// parse the opening brace
|
1999-12-25 05:22:39 +00:00
|
|
|
data = COM_Parse (data);
|
|
|
|
if (!data)
|
|
|
|
break;
|
|
|
|
if (com_token[0] != '{')
|
2000-01-03 04:45:54 +00:00
|
|
|
#ifdef QUAKEWORLD
|
1999-12-25 05:22:39 +00:00
|
|
|
SV_Error ("ED_LoadFromFile: found %s when expecting {",com_token);
|
2000-01-03 04:45:54 +00:00
|
|
|
#else
|
|
|
|
Sys_Error ("ED_LoadFromFile: found %s when expecting {",com_token);
|
|
|
|
#endif
|
1999-12-25 05:22:39 +00:00
|
|
|
|
|
|
|
if (!ent)
|
|
|
|
ent = EDICT_NUM(0);
|
|
|
|
else
|
|
|
|
ent = ED_Alloc ();
|
|
|
|
data = ED_ParseEdict (data, ent);
|
2000-03-19 15:59:51 +00:00
|
|
|
|
1999-12-25 05:22:39 +00:00
|
|
|
// remove things from different skill levels or deathmatch
|
2000-02-27 07:13:32 +00:00
|
|
|
if (deathmatch->value)
|
2000-01-03 04:45:54 +00:00
|
|
|
{
|
|
|
|
if (((int)ent->v.spawnflags & SPAWNFLAG_NOT_DEATHMATCH))
|
|
|
|
{
|
2000-03-19 15:59:51 +00:00
|
|
|
ED_Free (ent);
|
2000-01-03 04:45:54 +00:00
|
|
|
inhibit++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ((current_skill == 0 && ((int)ent->v.spawnflags & SPAWNFLAG_NOT_EASY))
|
|
|
|
|| (current_skill == 1 && ((int)ent->v.spawnflags & SPAWNFLAG_NOT_MEDIUM))
|
|
|
|
|| (current_skill >= 2 && ((int)ent->v.spawnflags & SPAWNFLAG_NOT_HARD)) )
|
1999-12-25 05:22:39 +00:00
|
|
|
{
|
2000-03-19 15:59:51 +00:00
|
|
|
ED_Free (ent);
|
1999-12-25 05:22:39 +00:00
|
|
|
inhibit++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// immediately call spawn function
|
|
|
|
//
|
|
|
|
if (!ent->v.classname)
|
|
|
|
{
|
|
|
|
Con_Printf ("No classname for:\n");
|
|
|
|
ED_Print (ent);
|
|
|
|
ED_Free (ent);
|
|
|
|
continue;
|
|
|
|
}
|
2000-03-19 15:59:51 +00:00
|
|
|
|
1999-12-25 05:22:39 +00:00
|
|
|
// look for the spawn function
|
|
|
|
func = ED_FindFunction ( PR_GetString(ent->v.classname) );
|
|
|
|
|
|
|
|
if (!func)
|
|
|
|
{
|
|
|
|
Con_Printf ("No spawn function for:\n");
|
|
|
|
ED_Print (ent);
|
|
|
|
ED_Free (ent);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
pr_global_struct->self = EDICT_TO_PROG(ent);
|
|
|
|
PR_ExecuteProgram (func - pr_functions);
|
2000-01-03 04:45:54 +00:00
|
|
|
#ifdef QUAKEWORLD
|
1999-12-25 05:22:39 +00:00
|
|
|
SV_FlushSignon();
|
2000-01-03 04:45:54 +00:00
|
|
|
#endif
|
2000-03-19 15:59:51 +00:00
|
|
|
}
|
1999-12-25 05:22:39 +00:00
|
|
|
|
|
|
|
Con_DPrintf ("%i entities inhibited\n", inhibit);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============
|
|
|
|
PR_LoadProgs
|
|
|
|
===============
|
|
|
|
*/
|
|
|
|
void PR_LoadProgs (void)
|
|
|
|
{
|
2000-01-06 00:29:41 +00:00
|
|
|
int i;
|
1999-12-25 05:22:39 +00:00
|
|
|
|
|
|
|
// flush the non-C variable lookup cache
|
|
|
|
for (i=0 ; i<GEFV_CACHESIZE ; i++)
|
|
|
|
gefvCache[i].field[0] = 0;
|
|
|
|
|
2000-01-03 04:45:54 +00:00
|
|
|
#ifndef QUAKEWORLD
|
|
|
|
CRC_Init (&pr_crc);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef QUAKEWORLD
|
1999-12-25 05:22:39 +00:00
|
|
|
progs = (dprograms_t *)COM_LoadHunkFile ("qwprogs.dat");
|
|
|
|
if (!progs)
|
2000-01-03 04:45:54 +00:00
|
|
|
#endif
|
1999-12-25 05:22:39 +00:00
|
|
|
progs = (dprograms_t *)COM_LoadHunkFile ("progs.dat");
|
|
|
|
if (!progs)
|
2000-01-03 04:45:54 +00:00
|
|
|
#ifdef QUAKEWORLD
|
1999-12-25 05:22:39 +00:00
|
|
|
SV_Error ("PR_LoadProgs: couldn't load progs.dat");
|
2000-01-03 04:45:54 +00:00
|
|
|
#else
|
|
|
|
Sys_Error ("PR_LoadProgs: couldn't load progs.dat");
|
|
|
|
#endif
|
1999-12-25 05:22:39 +00:00
|
|
|
Con_DPrintf ("Programs occupy %iK.\n", com_filesize/1024);
|
|
|
|
|
2000-01-03 04:45:54 +00:00
|
|
|
#ifdef QUAKEWORLD
|
2000-01-06 00:29:41 +00:00
|
|
|
{
|
|
|
|
char num[32];
|
|
|
|
|
|
|
|
// add prog crc to the serverinfo
|
|
|
|
snprintf(num, sizeof(num), "%i", CRC_Block ((byte *)progs,
|
|
|
|
com_filesize));
|
|
|
|
Info_SetValueForStarKey(svs.info, "*progs", num,
|
|
|
|
MAX_SERVERINFO_STRING);
|
|
|
|
}
|
2000-01-03 04:45:54 +00:00
|
|
|
#else
|
|
|
|
for (i=0 ; i<com_filesize ; i++)
|
|
|
|
CRC_ProcessByte (&pr_crc, ((byte *)progs)[i]);
|
|
|
|
#endif
|
1999-12-25 05:22:39 +00:00
|
|
|
|
|
|
|
// byte swap the header
|
|
|
|
for (i=0 ; i<sizeof(*progs)/4 ; i++)
|
2000-03-19 15:59:51 +00:00
|
|
|
((int *)progs)[i] = LittleLong ( ((int *)progs)[i] );
|
1999-12-25 05:22:39 +00:00
|
|
|
|
|
|
|
if (progs->version != PROG_VERSION)
|
2000-01-03 04:45:54 +00:00
|
|
|
#ifdef QUAKEWORLD
|
1999-12-25 05:22:39 +00:00
|
|
|
SV_Error ("progs.dat has wrong version number (%i should be %i)", progs->version, PROG_VERSION);
|
2000-01-03 04:45:54 +00:00
|
|
|
#else
|
|
|
|
Sys_Error ("progs.dat has wrong version number (%i should be %i)", progs->version, PROG_VERSION);
|
|
|
|
#endif
|
1999-12-25 05:22:39 +00:00
|
|
|
if (progs->crc != PROGHEADER_CRC)
|
2000-01-03 04:45:54 +00:00
|
|
|
#ifdef QUAKEWORLD
|
1999-12-25 05:22:39 +00:00
|
|
|
SV_Error ("You must have the progs.dat from QuakeWorld installed");
|
2000-01-03 04:45:54 +00:00
|
|
|
#else
|
|
|
|
Sys_Error ("progs.dat system vars have been modified, progdefs.h is out of date");
|
|
|
|
#endif
|
1999-12-25 05:22:39 +00:00
|
|
|
|
|
|
|
pr_functions = (dfunction_t *)((byte *)progs + progs->ofs_functions);
|
|
|
|
pr_strings = (char *)progs + progs->ofs_strings;
|
|
|
|
pr_globaldefs = (ddef_t *)((byte *)progs + progs->ofs_globaldefs);
|
|
|
|
pr_fielddefs = (ddef_t *)((byte *)progs + progs->ofs_fielddefs);
|
|
|
|
pr_statements = (dstatement_t *)((byte *)progs + progs->ofs_statements);
|
|
|
|
|
2000-01-03 04:45:54 +00:00
|
|
|
#ifdef QUAKEWORLD
|
1999-12-25 05:22:39 +00:00
|
|
|
num_prstr = 0;
|
2000-01-03 04:45:54 +00:00
|
|
|
#endif
|
1999-12-25 05:22:39 +00:00
|
|
|
|
|
|
|
pr_global_struct = (globalvars_t *)((byte *)progs + progs->ofs_globals);
|
|
|
|
pr_globals = (float *)pr_global_struct;
|
2000-03-19 15:59:51 +00:00
|
|
|
|
1999-12-25 05:22:39 +00:00
|
|
|
pr_edict_size = progs->entityfields * 4 + sizeof (edict_t) - sizeof(entvars_t);
|
2000-03-19 15:59:51 +00:00
|
|
|
|
1999-12-25 05:22:39 +00:00
|
|
|
// byte swap the lumps
|
|
|
|
for (i=0 ; i<progs->numstatements ; i++)
|
|
|
|
{
|
|
|
|
pr_statements[i].op = LittleShort(pr_statements[i].op);
|
|
|
|
pr_statements[i].a = LittleShort(pr_statements[i].a);
|
|
|
|
pr_statements[i].b = LittleShort(pr_statements[i].b);
|
|
|
|
pr_statements[i].c = LittleShort(pr_statements[i].c);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i=0 ; i<progs->numfunctions; i++)
|
|
|
|
{
|
|
|
|
pr_functions[i].first_statement = LittleLong (pr_functions[i].first_statement);
|
|
|
|
pr_functions[i].parm_start = LittleLong (pr_functions[i].parm_start);
|
|
|
|
pr_functions[i].s_name = LittleLong (pr_functions[i].s_name);
|
|
|
|
pr_functions[i].s_file = LittleLong (pr_functions[i].s_file);
|
|
|
|
pr_functions[i].numparms = LittleLong (pr_functions[i].numparms);
|
|
|
|
pr_functions[i].locals = LittleLong (pr_functions[i].locals);
|
2000-03-19 15:59:51 +00:00
|
|
|
}
|
1999-12-25 05:22:39 +00:00
|
|
|
|
|
|
|
for (i=0 ; i<progs->numglobaldefs ; i++)
|
|
|
|
{
|
|
|
|
pr_globaldefs[i].type = LittleShort (pr_globaldefs[i].type);
|
|
|
|
pr_globaldefs[i].ofs = LittleShort (pr_globaldefs[i].ofs);
|
|
|
|
pr_globaldefs[i].s_name = LittleLong (pr_globaldefs[i].s_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i=0 ; i<progs->numfielddefs ; i++)
|
|
|
|
{
|
|
|
|
pr_fielddefs[i].type = LittleShort (pr_fielddefs[i].type);
|
|
|
|
if (pr_fielddefs[i].type & DEF_SAVEGLOBAL)
|
2000-01-03 04:45:54 +00:00
|
|
|
#ifdef QUAKEWORLD
|
1999-12-25 05:22:39 +00:00
|
|
|
SV_Error ("PR_LoadProgs: pr_fielddefs[i].type & DEF_SAVEGLOBAL");
|
2000-01-03 04:45:54 +00:00
|
|
|
#else
|
|
|
|
Sys_Error ("PR_LoadProgs: pr_fielddefs[i].type & DEF_SAVEGLOBAL");
|
|
|
|
#endif
|
1999-12-25 05:22:39 +00:00
|
|
|
pr_fielddefs[i].ofs = LittleShort (pr_fielddefs[i].ofs);
|
|
|
|
pr_fielddefs[i].s_name = LittleLong (pr_fielddefs[i].s_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i=0 ; i<progs->numglobals ; i++)
|
|
|
|
((int *)pr_globals)[i] = LittleLong (((int *)pr_globals)[i]);
|
|
|
|
|
2000-01-03 04:45:54 +00:00
|
|
|
#ifdef QUAKEWORLD
|
2000-01-06 00:29:41 +00:00
|
|
|
{
|
|
|
|
dfunction_t *f;
|
|
|
|
|
|
|
|
// Zoid, find the spectator functions
|
|
|
|
SpectatorConnect = SpectatorThink = SpectatorDisconnect = 0;
|
|
|
|
|
|
|
|
if ((f = ED_FindFunction ("SpectatorConnect")) != NULL)
|
|
|
|
SpectatorConnect = (func_t)(f - pr_functions);
|
|
|
|
if ((f = ED_FindFunction ("SpectatorThink")) != NULL)
|
|
|
|
SpectatorThink = (func_t)(f - pr_functions);
|
|
|
|
if ((f = ED_FindFunction ("SpectatorDisconnect")) != NULL)
|
|
|
|
SpectatorDisconnect = (func_t)(f - pr_functions);
|
|
|
|
}
|
2000-01-03 04:45:54 +00:00
|
|
|
#endif
|
1999-12-25 05:22:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============
|
|
|
|
PR_Init
|
|
|
|
===============
|
|
|
|
*/
|
|
|
|
void PR_Init (void)
|
|
|
|
{
|
|
|
|
Cmd_AddCommand ("edict", ED_PrintEdict_f);
|
|
|
|
Cmd_AddCommand ("edicts", ED_PrintEdicts);
|
|
|
|
Cmd_AddCommand ("edictcount", ED_Count);
|
|
|
|
Cmd_AddCommand ("profile", PR_Profile_f);
|
2000-01-03 04:45:54 +00:00
|
|
|
#ifndef QUAKEWORLD
|
2000-02-27 07:13:32 +00:00
|
|
|
// Cvar_RegisterVariable (&nomonsters);
|
|
|
|
nomonsters = Cvar_Get ("nomonsters","0",0,"None");
|
|
|
|
// Cvar_RegisterVariable (&gamecfg);
|
|
|
|
gamecfg = Cvar_Get ("gamecfg","0",0,"None");
|
|
|
|
// Cvar_RegisterVariable (&scratch1);
|
|
|
|
scratch1 = Cvar_Get ("scratch1","0",0,"None");
|
|
|
|
// Cvar_RegisterVariable (&scratch2);
|
|
|
|
scratch2 = Cvar_Get ("scratch2","0",0,"None");
|
|
|
|
// Cvar_RegisterVariable (&scratch3);
|
|
|
|
scratch3 = Cvar_Get ("scratch3","0",0,"None");
|
|
|
|
// Cvar_RegisterVariable (&scratch4);
|
|
|
|
scratch4 = Cvar_Get ("scratch4","0",0,"None");
|
|
|
|
// Cvar_RegisterVariable (&savedgamecfg);
|
|
|
|
savedgamecfg = Cvar_Get ("savedgamecfg","0",CVAR_ARCHIVE,"None");
|
|
|
|
// Cvar_RegisterVariable (&saved1);
|
|
|
|
saved1 = Cvar_Get ("saved1","0",CVAR_ARCHIVE,"None");
|
|
|
|
// Cvar_RegisterVariable (&saved2);
|
|
|
|
saved2 = Cvar_Get ("saved2","0",CVAR_ARCHIVE,"None");
|
|
|
|
// Cvar_RegisterVariable (&saved3);
|
|
|
|
saved3 = Cvar_Get ("saved3","0",CVAR_ARCHIVE,"None");
|
|
|
|
// Cvar_RegisterVariable (&saved4);
|
|
|
|
saved4 = Cvar_Get ("saved4","0",CVAR_ARCHIVE,"None");
|
2000-01-03 04:45:54 +00:00
|
|
|
#endif
|
1999-12-25 05:22:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
edict_t *EDICT_NUM(int n)
|
|
|
|
{
|
|
|
|
if (n < 0 || n >= MAX_EDICTS)
|
2000-01-03 04:45:54 +00:00
|
|
|
#ifdef QUAKEWORLD
|
1999-12-25 05:22:39 +00:00
|
|
|
SV_Error ("EDICT_NUM: bad number %i", n);
|
2000-01-03 04:45:54 +00:00
|
|
|
#else
|
|
|
|
Sys_Error ("EDICT_NUM: bad number %i", n);
|
|
|
|
#endif
|
1999-12-25 05:22:39 +00:00
|
|
|
return (edict_t *)((byte *)sv.edicts+ (n)*pr_edict_size);
|
|
|
|
}
|
|
|
|
|
|
|
|
int NUM_FOR_EDICT(edict_t *e)
|
|
|
|
{
|
|
|
|
int b;
|
2000-03-19 15:59:51 +00:00
|
|
|
|
1999-12-25 05:22:39 +00:00
|
|
|
b = (byte *)e - (byte *)sv.edicts;
|
|
|
|
b = b / pr_edict_size;
|
2000-03-19 15:59:51 +00:00
|
|
|
|
1999-12-25 05:22:39 +00:00
|
|
|
if (b < 0 || b >= sv.num_edicts)
|
2000-01-03 04:45:54 +00:00
|
|
|
#ifdef QUAKEWORLD
|
1999-12-25 05:22:39 +00:00
|
|
|
SV_Error ("NUM_FOR_EDICT: bad pointer");
|
2000-01-03 04:45:54 +00:00
|
|
|
#else
|
|
|
|
Sys_Error ("NUM_FOR_EDICT: bad pointer");
|
|
|
|
#endif
|
1999-12-25 05:22:39 +00:00
|
|
|
return b;
|
|
|
|
}
|
|
|
|
|
|
|
|
|