Lua support for slopes
Lua finally has support for slopes!
Three new userdata types are added: pslope_t
, for slopes themselves, vector2_t
for 2D vectors, and vector3_t
for 3D vectors. The latter two only exist to make it easier to access certain variables from pslope_t
.
To access slopes of a sector, Lua now allows access to the sector_t
variables f_slope
and c_slope
, for the sector's floor and ceiling slopes respectively. A third added (bad bad bad, being removed in !312 (merged)) For FOFs, sector_t
variable, hasslope
, is used to check if there are slopes in the sector, including those from FOFs.t_slope
and b_slope
have also been added to the ffloor_t
userdata struct in Lua, for the FOF's top and bottom slopes respectively. Additionally, the mobj_t
variable standingslope
has been added to Lua, allowing you to get the slope a mobj is standing on (if they are currently on the ground, that is).
The variables of pslope_t
Lua has access to are the following:
-
valid
(boolean): Use this to check if the slope is "valid". -
o
(vector3_t): The "origin" vector of the slope. -
d
(vector2_t): The 2D "direction" vector of the slope in the X and Y directions only. This is normalised, i.e. it's the same as getting a thrust ofFRACUNIT
in the opposite direction toxydirection
. -
zdelta
(fixed_t): The rate at which the Z changes based on distance from the slope; basically every step ofd.x
anddy
in the X and Y axes moves the Z position up or down this much. -
normal
(vector3_t): This is supposed to be the normal vector of the slope, though it doesn't seem to be so much perpendicular to it as running along it right now. =| -
zangle
(angle_t): The vertical angle of the slope's plane from the ground. "flat" slopes have a zangle of 0. You cannot have a slope with a zangle of ANGLE_90 or ANGLE_270. -
xydirection
(angle_t): The horizontal angle of the slope's plane. -
sourceline
(line_t): The linedef used to create the slope. -
refpos
(UINT8): An integer value used to indicate what setup/linedef type was used to make the slope, so that slopes can be dynamically altered internally. - 1 - front floor
- 2 - front ceiling
- 3 - back floor
- 4 - back ceiling
- 5 - vertex slope
-
flags
(UINT8): The slope's flags. -
SL_NOPHYSICS
- the slope has no physics (i.e., no sliding down, no special jump physics, etc) -
SL_NODYNAMIC
- the slope is not dynamic, i.e. it will not automatically correct its zdelta, zangle or normal every tic to be correct with its original sector heights (in the case of sector-based slopes) or its vertexes (in the case of vertex slopes) -
SL_ANCHORVERTEX
- has no effect right now -
SL_VERTEXSLOPE
- the slope is a vertex slope
Of these values, only o
, zdelta
, zangle
and xydirection
can be modified. At the moment, o
can only be modified by setting slope.o
directly to a Lua table with contents along the format {x = value, y = value, z = value}
. Maybe I'll fix this at some point to allow you to change just slope.o.z
or something. Meanwhile, updating one of zdelta
or zangle
updates the other as well as the values of the normal
vector, and modifying xydirection
also updates the values of both d
and normal
vectors. As I stated already, you cannot have a slope with a zangle
of ANGLE_90 or ANGLE_270, and the game will scream at you if you dare try to set zangle
to these values.
It is not possible to modify zdelta
, zangle
or even the z
value of o
if a slope is dynamic, as the game will just automatically modify the values based on what was used to set up the slope. Make sure the slope is non-dynamic first if you do want to modify these values.
vector2_t
and vector3_t
meanwhile are just simple fixed_t
vectors: the former has only the values x
and y
, and the latter has values x
, y
and z
. It is not currently possible to modify only specific values of these structs directly (see note for modifying the o
value above).
A new function has also been added:
-
P_GetZAt(slope, x, y)
: returns the Z position of the slope at the X, Y position.slope
must be apslope_t
and the other two arguments are expected to befixed_t
. The return value is also typefixed_t
.