Beispiel #1
0
/*
 * Parses an edict out of the given string,
 * returning the new position ed should be
 * a properly initialized empty edict.
 */
char *ED_ParseEdict(char *data, edict_t *ent)
{
  qboolean init;
  char keyname[256];
  const char *com_token;

  if (!ent) {
    return NULL;
  }

  init = false;
  memset(&st, 0, sizeof(st));

  /* go through all the dictionary pairs */
  while (1) {
    /* parse key */
    com_token = COM_Parse(&data);

    if (com_token[0] == '}') {
      break;
    }

    if (!data) {
      PF_error("ED_ParseEntity: EOF without closing brace");
    }

    Q_strlcpy(keyname, com_token, sizeof(keyname));

    /* parse value */
    com_token = COM_Parse(&data);

    if (!data) {
      PF_error("ED_ParseEntity: EOF without closing brace");
    }

    if (com_token[0] == '}') {
      PF_error("ED_ParseEntity: closing brace without data");
    }

    init = true;

    /* keynames with a leading underscore are
       used for utility comments, and are
       immediately discarded by quake */
    if (keyname[0] == '_') {
      continue;
    }

    ED_ParseField(keyname, com_token, ent);
  }

  if (!init) {
    memset(ent, 0, sizeof(*ent));
  }

  return data;
}
Beispiel #2
0
/*
====================
ED_ParseEdict

Parses an edict out of the given string, returning the new position
ed should be a properly initialized empty edict.
====================
*/
static void ED_ParseEdict(const char **data, edict_t *ent)
{
    qboolean    init;
    char        *key, *value;

    init = qfalse;
    memset(&st, 0, sizeof(st));

// go through all the dictionary pairs
    while (1) {
        // parse key
        key = COM_Parse(data);
        if (key[0] == '}')
            break;
        if (!*data)
            gi.error("%s: EOF without closing brace", __func__);

        // parse value
        value = COM_Parse(data);
        if (!*data)
            gi.error("%s: EOF without closing brace", __func__);

        if (value[0] == '}')
            gi.error("%s: closing brace without data", __func__);

        init = qtrue;

        // keynames with a leading underscore are used for utility comments,
        // and are immediately discarded by quake
        if (key[0] == '_')
            continue;

        if (!ED_ParseField(g_fields, key, value, (byte *)ent)) {
            if (!ED_ParseField(g_temps, key, value, (byte *)&st)) {
                gi.dprintf("%s: %s is not a field\n", __func__, key);
            }
        }
    }

    if (!init)
        memset(ent, 0, sizeof(*ent));
}
Beispiel #3
0
/*
====================
ED_ParseEdict

Parses an edict out of the given string, returning the new position
ed should be a properly initialized empty edict.
====================
*/
char *ED_ParseEdict (char *data, edict_t *ent)
{
	qboolean	init;
	char		keyname[256];
	char		*com_token;
	//Knightmare added
	qboolean	alias_loaded = false;

	init = false;
	memset (&st, 0, sizeof(st));

	// Knightmare- look for and load an alias for this ent
	alias_loaded = ED_ParseEntityAlias (data, ent);


// go through all the dictionary pairs
	while (1)
	{	
	// parse key
		com_token = COM_Parse (&data);
		if (com_token[0] == '}')
			break;
		if (!data)
			gi.error ("ED_ParseEntity: EOF without closing brace");

		strncpy (keyname, com_token, sizeof(keyname)-1);
		
	// parse value	
		com_token = COM_Parse (&data);
		if (!data)
			gi.error ("ED_ParseEntity: EOF without closing brace");

		if (com_token[0] == '}')
			gi.error ("ED_ParseEntity: closing brace without data");

		init = true;	

	// keynames with a leading underscore are used for utility comments,
	// and are immediately discarded by quake
		if (keyname[0] == '_')
			continue;

		// Knightmare- if the classname was replaced by an alias, don't load it back
		if (alias_loaded && !strcmp(keyname, "classname"))
			continue;

		ED_ParseField (keyname, com_token, ent);
	}

	if (!init)
		memset (ent, 0, sizeof(*ent));

	return data;
}
Beispiel #4
0
/*
====================
ED_ParseEdict

Parses an edict out of the given string, returning the new position
ed should be a properly initialized empty edict.
====================
*/
char *ED_ParseEdict (char *data, edict_t *ent)
{
	qboolean	init;
	char		keyname[256];
	const char	*com_token;

	if (!ent || !data)
	{
		return NULL;
	}

	init = false;
	memset (&st, 0, sizeof(st));

	// go through all the dictionary pairs
	while (1)
	{	
		// parse key
		com_token = COM_Parse (&data);
		if (com_token[0] == '}')
			break;
		if (!data)
			gi.error ("ED_ParseEntity: EOF without closing brace");

		strncpy (keyname, com_token, sizeof(keyname)-1);
		
		// parse value	
		com_token = COM_Parse (&data);
		if (!data)
			gi.error ("ED_ParseEntity: EOF without closing brace");

		if (com_token[0] == '}')
			gi.error ("ED_ParseEntity: closing brace without data");

		init = true;	

		// keynames with a leading underscore are used for utility comments,
		// and are immediately discarded by quake
		if (keyname[0] == '_')
			continue;

		ED_ParseField (keyname, com_token, ent);
	}

	if (!init)
		memset (ent, 0, sizeof(*ent));

	return data;
}
Beispiel #5
0
/*
* ED_ParseEdict
* 
* Parses an edict out of the given string, returning the new position
* ed should be a properly initialized empty edict.
*/
static char *ED_ParseEdict( char *data, edict_t *ent )
{
	bool init;
	char keyname[256];
	char *com_token;

	init = false;
	memset( &st, 0, sizeof( st ) );
	level.spawning_entity = ent;

	// go through all the dictionary pairs
	while( 1 )
	{
		// parse key
		com_token = COM_Parse( &data );
		if( com_token[0] == '}' )
			break;
		if( !data )
			G_Error( "ED_ParseEntity: EOF without closing brace" );

		Q_strncpyz( keyname, com_token, sizeof( keyname ) );

		// parse value
		com_token = COM_Parse( &data );
		if( !data )
			G_Error( "ED_ParseEntity: EOF without closing brace" );

		if( com_token[0] == '}' )
			G_Error( "ED_ParseEntity: closing brace without data" );

		init = true;

		// keynames with a leading underscore are used for utility comments,
		// and are immediately discarded by quake
		if( keyname[0] == '_' )
			continue;

		ED_ParseField( keyname, com_token, ent );
	}

	if( !init )
		ent->classname = NULL;
	if( ent->classname && ent->helpmessage )
		ent->mapmessage_index = G_RegisterHelpMessage( ent->helpmessage );

	return data;
}
Beispiel #6
0
/**
 * @brief Parses an edict out of the given string, returning the new position
 * @param[in] data The string to parse from
 * @param[in] ent should be a properly initialized empty edict.
 */
static const char *ED_ParseEdict (const char *data, edict_t * ent)
{
	bool init;
	char keyname[MAX_VAR];

	init = false;
	OBJZERO(st);

	/* go through all the dictionary pairs */
	while (1) {
		/* parse key */
		const char *c = Com_Parse(&data);
		if (c[0] == '}')
			break;
		if (!data)
			gi.Error("ED_ParseEntity: EOF without closing brace");

		Q_strncpyz(keyname, c, sizeof(keyname));

		/* parse value */
		c = Com_Parse(&data);
		if (!data)
			gi.Error("ED_ParseEntity: EOF without closing brace");

		if (c[0] == '}')
			gi.Error("ED_ParseEntity: closing brace without data");

		init = true;

		/* keynames with a leading underscore are used for utility comments,
		 * and are immediately discarded by ufo */
		if (keyname[0] == '_')
			continue;

		ED_ParseField(keyname, c, ent);
	}

	if (!init)
		OBJZERO(*ent);

	return data;
}
Beispiel #7
0
/*
====================
ED_ParseEntityAlias

Parses an edict, looking for its classname, and then
looks in the entity alias file for an alias, and
loads that if found.
Returns true if an alias was loaded for the given entity.
====================
*/
qboolean ED_ParseEntityAlias (char *data, edict_t *ent)
{
	qboolean	classname_found, alias_found, alias_loaded;
	char		*search_data;
	char		*search_token;
	char		entclassname[256];
	char		keyname[256];
	int			braceLevel;

	classname_found = false;
	alias_found	= false;
	alias_loaded = false;
	braceLevel = 0;

	if (!alias_data) // If no alias file was loaded, don't bother
		return false;

	search_data = data;  // copy entity data postion
	// go through all the dictionary pairs looking for the classname
	while (1)
	{	//parse keyname
		search_token = COM_Parse (&search_data);
		if (!search_data)
			gi.error ("ED_ParseEntityAlias: end of entity data without closing brace");
		if (search_token[0] == '}')
			break;
		if (!strcmp(search_token, "classname"))
			classname_found = true;

		// parse value	
		search_token = COM_Parse (&search_data);
		if (!search_data)
			gi.error ("ED_ParseEntityAlias: end of entity data without closing brace");
		if (search_token[0] == '}')
			gi.error ("ED_ParseEntityAlias: closing brace without entity data");
		// if we've found the classname, exit loop
		if (classname_found) {
			strncpy (entclassname, search_token, sizeof(entclassname)-1);
			break;
		}
	}
	// then search the entalias.def file for that classname
	if (classname_found)
	{
		search_data = alias_data;	// copy alias data postion
 		while (search_data < (alias_data + alias_data_size))
		{
			search_token = COM_Parse (&search_data);
			if (!search_data)
				return false;
			if (!search_token)
				break;
			// see if we're inside the braces of an alias definition
			if (search_token[0] == '{') braceLevel++;
			else if (search_token[0] == '}') braceLevel--;
			if (braceLevel < 0) {
				gi.dprintf ("ED_ParseEntityAlias: closing brace without matching opening brace\n");
				return false;
			}
			// matching classname must be outside braces
			if (!strcmp(search_token, entclassname) && (braceLevel == 0)) {
				//gi.dprintf ("Alias for %s found in alias script file.\n", search_token);
				alias_found = true;
				break;
			}
		}
		// then if that classname is found, load the fields from that alias
		if (alias_found)
		{	// get the opening curly brace
			search_token = COM_Parse (&search_data);
			if (!search_data) {
				gi.dprintf ("ED_ParseEntityAlias: unexpected EOF\n");
				return false;
			}
			if (search_token[0] != '{') {
				gi.dprintf ("ED_ParseEntityAlias: found %s when expecting {\n", search_token);
				return false;
			}
			// go through all the dictionary pairs
			while (search_data < (alias_data + alias_data_size))
			{	
			// parse key
				search_token = COM_Parse (&search_data);
				if (!search_data) {
					gi.dprintf ("ED_ParseEntityAlias: EOF without closing brace\n");
					return false;
				}
				if (search_token[0] == '}')
					break;
				strncpy (keyname, search_token, sizeof(keyname)-1);
				
			// parse value	
				search_token = COM_Parse (&search_data);
				if (!search_data) {
					gi.dprintf ("ED_ParseEntityAlias: EOF without closing brace\n");
					return false;
				}
				if (search_token[0] == '}') {
					gi.dprintf ("ED_ParseEntityAlias: closing brace without data\n");
					return false;
				}
				ED_ParseField (keyname, search_token, ent);
				alias_loaded = true;
			}
		}
	}
	return alias_loaded;
}
Beispiel #8
0
/*
====================
ED_ParseEdict

Parses an edict out of the given string, returning the new position
ed should be a properly initialized empty edict.
====================
*/
char *ED_ParseEdict (char *data, edict_t *ent)
{
	qboolean	init;
	char		keyname[256];
	char		*com_token;
	//Knightmare added
	qboolean	alias_loaded = false;

	init = false;
	memset (&st, 0, sizeof(st));

	// Knightmare- look for and load an alias for this ent
	alias_loaded = ED_ParseEntityAlias (data, ent);

// go through all the dictionary pairs
	while (1)
	{	
	// parse key
		com_token = COM_Parse (&data);
		if (com_token[0] == '}')
			break;
		if (!data)
			gi.error ("ED_ParseEntity: EOF without closing brace");

		strncpy (keyname, com_token, sizeof(keyname)-1);
		
	// parse value	
		com_token = COM_Parse (&data);
		if (!data)
			gi.error ("ED_ParseEntity: EOF without closing brace");

		if (com_token[0] == '}')
			gi.error ("ED_ParseEntity: closing brace without data");

		init = true;

	// Knightmare: check for _clientonly here
		if (!strcmp(keyname, "_clientonly"))
		{
			int val = atoi(com_token);

			// value of 2 or higher = remove, 1 = server-side bbox clip only
			if (val > 1)
				G_FreeEdict (ent);
			else if (val == 1)
				ent->svflags |= SVF_NOCLIENT;
		}

	// keynames with a leading underscore are used for utility comments,
	// and are immediately discarded by quake
		if (keyname[0] == '_')
			continue;

		// Knightmare- if the classname was replaced by an alias, don't load it back
		if (alias_loaded && !strcmp(keyname, "classname"))
			continue;

		ED_ParseField (keyname, com_token, ent);
	}

	if (!init)
		memset (ent, 0, sizeof(*ent));

	return data;
}