Getzrange

From EDukeWiki
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

getzrange <x> <y> <z> <sector> <ceilingz> <ceilinghit> <floorz> <floorhit> <walldist> <clipmask>

Given a starting point and its containing sector, calculate (1) the z coordinates of (2) the objects that would be first hit by a quadratic, floor-aligned sprite pointing parallel to the grid and having side length 2*<walldist>, when travelling in a straight line up- and downwards (respectively for <ceiling...> and <floor...>). The <clipmask> is specified in the same fashion as in hitscan.

<ceilinghit> and <floorhit> can take the following values:

  • 16384 + sectnum, if a ceiling or floor was hit first
  • 49152 + spritenum, if a sprite was hit first

The behaviour in corner cases (sectnum invalid, x/y/z not in sectnum, etc.) should not be relied upon.

Example: Checking for spritebridges

The state below checks if the current actor is on a spritebridge, and if so, "returns" the id of that sprite.

// assumption: relevant variables are declared
defstate check_spritebridge
	 geta[].x my_x
	 geta[].y my_y
	 geta[].z my_z
	 geta[].sectnum sectnum
	 
	 getzrange my_x my_y my_z sectnum
		 ceilingz
		 ceilinghit
		 floorz
		 floorhit
		 256
 		 CLIPMASK0
		
	set outputSpriteId -1
	ifge floorhit 49152
	{
		sub floorhit 49152
		
		ifvarand sprite[floorhit].cstat 32
			set outputSpriteId floorhit
	}
       
       // outputSpriteId now contains either -1 if no spritebridge is detected, or the id of the spritebridge if there is
ends