Esempio n. 1
0
/*
================
ParseEntity
================
*/
qboolean	ParseEntity(script_t *script)
{
	epair_t *e;
	entity_t	*mapent;
	token_t token;

	if (!PS_ReadToken(script, &token))
		return false;

	if (strcmp(token.string, "{"))
		Error ("ParseEntity: { not found");
	
	if (num_entities == MAX_MAP_ENTITIES)
		Error ("num_entities == MAX_MAP_ENTITIES");

	mapent = &entities[num_entities];
	num_entities++;

	do
	{
		if (!PS_ReadToken(script, &token))
			Error ("ParseEntity: EOF without closing brace");
		if (!strcmp(token.string, "}") )
			break;
		PS_UnreadLastToken(script);
		e = ParseEpair(script);
		e->next = mapent->epairs;
		mapent->epairs = e;
	} while (1);
	
	return true;
} //end of the function ParseEntity
Esempio n. 2
0
/*
================
Q2_ParseMapEntity
================
*/
qboolean    Q2_ParseMapEntity(script_t *script)
{
	entity_t   *mapent;
	epair_t    *e;
	side_t     *s;
	int        i, j;
	int        startbrush, startsides;
	vec_t      newdist;
	mapbrush_t *b;
	token_t    token;

	if (!PS_ReadToken(script, &token))
	{
		return false;
	}

	if (strcmp(token.string, "{"))
	{
		Error("ParseEntity: { not found");
	}

	if (num_entities == MAX_MAP_ENTITIES)
	{
		Error("num_entities == MAX_MAP_ENTITIES");
	}

	startbrush = nummapbrushes;
	startsides = nummapbrushsides;

	mapent = &entities[num_entities];
	num_entities++;
	memset(mapent, 0, sizeof(*mapent));
	mapent->firstbrush = nummapbrushes;
	mapent->numbrushes = 0;
//	mapent->portalareas[0] = -1;
//	mapent->portalareas[1] = -1;

	do
	{
		if (!PS_ReadToken(script, &token))
		{
			Error("ParseEntity: EOF without closing brace");
		} //end if
		if (!strcmp(token.string, "}"))
		{
			break;
		}
		if (!strcmp(token.string, "{"))
		{
			Q2_ParseBrush(script, mapent);
		} //end if
		else
		{
			PS_UnreadLastToken(script);
			e              = ParseEpair(script);
			e->next        = mapent->epairs;
			mapent->epairs = e;
		} //end else
	}
	while (1);

	GetVectorForKey(mapent, "origin", mapent->origin);

	//
	// if there was an origin brush, offset all of the planes and texinfo
	//
	if (mapent->origin[0] || mapent->origin[1] || mapent->origin[2])
	{
		for (i = 0 ; i < mapent->numbrushes ; i++)
		{
			b = &mapbrushes[mapent->firstbrush + i];
			for (j = 0 ; j < b->numsides ; j++)
			{
				s       = &b->original_sides[j];
				newdist = mapplanes[s->planenum].dist -
				          DotProduct(mapplanes[s->planenum].normal, mapent->origin);
				s->planenum = FindFloatPlane(mapplanes[s->planenum].normal, newdist, 0, NULL);
				s->texinfo  = TexinfoForBrushTexture(&mapplanes[s->planenum],
				                                     &side_brushtextures[s - brushsides], mapent->origin);
			}
			MakeBrushWindings(b);
		}
	}

	// group entities are just for editor convenience
	// toss all brushes into the world entity
	if (!strcmp("func_group", ValueForKey(mapent, "classname")))
	{
		Q2_MoveBrushesToWorld(mapent);
		mapent->numbrushes = 0;
		return true;
	}

	// areaportal entities move their brushes, but don't eliminate
	// the entity
	if (!strcmp("func_areaportal", ValueForKey(mapent, "classname")))
	{
		char str[128];

		if (mapent->numbrushes != 1)
		{
			Error("Entity %i: func_areaportal can only be a single brush", num_entities - 1);
		}

		b           = &mapbrushes[nummapbrushes - 1];
		b->contents = CONTENTS_AREAPORTAL;
		c_areaportals++;
		mapent->areaportalnum = c_areaportals;
		// set the portal number as "style"
		sprintf(str, "%i", c_areaportals);
		SetKeyValue(mapent, "style", str);
		Q2_MoveBrushesToWorld(mapent);
		return true;
	}

	return true;
}