Sector type 200 bug

From DoomWiki.org

In Hexen, sector type 200 is supposed to make a sector use the secondary sky defined in MAPINFO instead of the primary sky. However, this does not work on ceilings due to a mistake in the R_Subsector() function, which always uses 0 instead of the sector's special for ceilings.

Technical details[edit]

The function R_DrawPlanes(), in R_PLANE.C, contains code to switch which sky texture to use depending on whether sector type 200 is used:

	if(pl->special == 200)
	{ // Use sky 2
		offset = Sky2ColumnOffset>>16;
		skyTexture = texturetranslation[Sky2Texture];
	}
	else
	{ // Use sky 1
		offset = Sky1ColumnOffset>>16;
		skyTexture = texturetranslation[Sky1Texture];
	}

However, this check is not done directly on the sector, which R_DrawPlanes() does not have access to, but on the visplane. The visplane is created (if needed) by R_FindPlane(), also in R_PLANE.C, which is called by R_Subsector() in R_BSP.C. It is in this function that the problem is found:

if(frontsector->floorheight < viewz)
{
	floorplane = R_FindPlane(frontsector->floorheight,
		frontsector->floorpic, frontsector->lightlevel,
		frontsector->special);
}
else
{
	floorplane = NULL;
}

if(frontsector->ceilingheight > viewz
	|| frontsector->ceilingpic == skyflatnum)
{
	ceilingplane = R_FindPlane(frontsector->ceilingheight,
		frontsector->ceilingpic, frontsector->lightlevel, 0);
}
else
{
	ceilingplane = NULL;
}

As can be seen, for floors, the last parameter sent to R_FindPlane() is the sector's special; but for ceilings, it is instead always the value 0.

As a result, the code for using sky 2 instead of sky 1 can never be reached when drawing a sky ceiling, but it can work when drawing a sky floor.

External links[edit]