Respawn/Waypoints library for Lua
Summary
This branch exposes waypoint_t, updates respawnvars_t to include all missing variables, as well as a refactor and moving it to a new file, exposes new members from player_t related to waypoints, and exposes all respawn and waypoint functions to Lua.
The reason the respawn lib and waypoint lib are grouped together into a single MR, is because they both depend on waypoint_t from being exposed. If this is too hard to merge into master/internal, I can separate it into two MRs - I just figured it made the most sense. All commits are still atomic and can be split as needed.
Fixes #12 (closed), #311 (closed).
It changes the following:
- Exposes the following variables:
-
waypoint_tobject:- get:
mobj,onaline,nextwaypoints,prevwaypoints,nextwaypointdistances,prevwaypointdistances,numnextwaypoints,numprevwaypoints. - set:
mobj,onaline
- get:
-
respawnvars_tobject:- get and set (new):
waypoint,pointangle,airtimer,truedeath,manual,fromringshooter,init,fast,returnspeed
- get and set (new):
-
player_tobject:- get and set:
currentwaypoint,nextwaypoint,bigwaypointgap,dropdashboost - set (could already be get before):
distancetofinishanddistancetofinishprev
- get and set:
-
- Exposes the following constants:
RESPAWN_DIST,RESPAWN_TIME,RESPAWNST_NONE,RESPAWNST_MOVE,RESPAWNST_DROP,DEFAULT_WAYPOINT_RADIUS - Exposes the following globals:
waypoints(global table with all waypoints, e.g.waypoints[0]gives you the first waypoint), #waypoints (total number of waypoints) andwaypoints.iterateto iterate through all of a level's waypoints. - Exposes the following functions:
-
k_respawn:fixed_t K_RespawnOffset(player_t player, [bool flip])nil K_RespawnAtWaypoint(player_t player, waypoint_t waypoint)nil K_DoFault(player_t player)nil K_DoIngameRespawn(player_t player)int K_NextRespawnWaypointIndex(waypoint_t waypoint)
-
k_waypoint:waypoint_t K_GetFinishLineWaypoint()waypoint_t K_GetStartingWaypoint()boolean K_GetWaypointIsFinishline(waypoint_t waypoint)boolean K_GetWaypointIsShortcut(waypoint_t waypoint)boolean K_GetWaypointIsEnabled(waypoint_t waypoint)boolean K_GetWaypointIsSpawnpoint(waypoint_t waypoint)int K_GetWaypointNextID(waypoint_t waypoint)int K_GetWaypointID(waypoint_t waypoint)waypoint_t K_GetWaypointFromID(int id)int K_GetCircuitLength()int K_GetTrackComplexity()waypoint_t K_GetClosestWaypointToMobj(mobj_t mobj)waypoint_t K_GetBestWaypointForMobj(mobj_t mobj, [waypoint_t waypoint])-
boolean, table K_PathfindToWaypoint(waypoint_t sourcewaypoint, waypoint_t destinationwaypoint, [boolean useshortcuts], [boolean huntbackwards]).- Table is a representation of path_t and pathfindnode_t objects, with the following members:
numnodes(int),array(table which containsnodedata(waypoint_t), gscore (int), hscore (int) for each node),totaldist(int). Every table henceforth is like this.
- Table is a representation of path_t and pathfindnode_t objects, with the following members:
boolean, table K_PathfindThruCircuit(waypoint_t sourcewaypoint, fixed_t traveldistance, [boolean useshortcuts], [boolean huntbackwards])boolean, table K_PathfindThruCircuitSpawnable(waypoint_t sourcewaypoint, fixed_t traveldistance, [boolean useshortcuts], [boolean huntbackwards])waypoint_t K_GetNextWaypointToDestination(waypoint_t sourcewaypoint, waypoint_t destinationwaypoint, [boolean useshortcuts], [boolean huntbackwards])waypoint_t K_SearchWaypointGraphForMobj(mobj_t mobj)waypoint_t K_SearchWaypointHeapForMobj(mobj_t mobj)
-
Testing
Testing environment: ringracers_respawnWaypointsLib.exe -console -skipintro -warp RR_ROBOTNIKCOASTER +addfile respawnwaypoint.lua
A script was used, respawnwaypoint.lua, to test the following additions:
- It contains a cvar
respawnvarshuddebugthat displays the following values in the HUD:-
1: Displays the player'srespawnvars_tmembers. -
2: Displays the player'swaypoint_tmembers. -
3: Displays the return values ofK_GetFinishLineWaypoint,K_GetStartingWaypoint,K_GetClosestWaypointToMobj,K_GetCircuitLength,K_GetTrackComplexity,K_GetWaypointFromID,K_GetWaypointIsFinishline,K_GetWaypointIsShortcut,K_GetWaypointIsEnabled,K_GetWaypointIsSpawnpoint,K_GetWaypointIDandK_GetWaypointNextID. -
4: Displays the return values ofK_GetClosestWaypointToMobj,K_GetBestWaypointForMobj,K_NextRespawnWaypointIndex,K_RespawnOffset, and the player membersdistancetofinish,distancetofinishprev,bigwaypointgapanddropdashboost.
-
- It contains the following commands:
-
setrespawnvalue arg1 arg2 arg3: Sets the player node (arg1)'s respawn member (arg2) to a value (arg3). -
faultme: Faults the player usingK_DoFault. -
respawnme [arg1]: Respawns the player usingK_DoIngameRespawn. If arg1 is passed, it will respawn the player to that waypoint ID usingK_RespawnAtWaypoint. -
testpathfindtowaypoint [arg1]: TestsK_PathfindToWaypointand displays all nodes. arg1 allows to set how many waypoints from the current player waypoint to test pathfind to, defaults to 3. -
testpathfindtodistance [arg1]: TestsK_PathfindThruCircuitand displays all nodes. arg1 allows to set how much distance to pathfind to, defauls to 1028. -
testpathfindtodistancespawnable [arg1]: Same as above, but usingK_PathfindThruCircuitSpawnable. -
testpathfindtodest [arg1]: TestsK_GetNextWaypointToDestinationand displays the returned waypoint's ID. arg1 allows to set how many waypoints from the current player waypoint to test pathfind to, defaults to 3. -
iswaypointingraph [arg1]/iswaypointinheap [arg1]: Tests whether the player's current waypoint is in the graph or heap, respectively. arg1 allows to pass a specific waypoint ID to check instead. -
testforloopwaypointandtestiteratewaypoint: Allows testing looping through, and iterating through thewaypointsglobal, as well as printing the total amount of waypoints.
-
Changelog:
- Added missing
respawnvars_tvalues from the player for Lua:waypoint,pointangle,airtimer,truedeath,manual,fromringshooter,init,fast,returnspeed. - Exposed
waypoint_tfor Lua. - Exposes
player_tmemberscurrentwaypoint,nextwaypoint,bigwaypointgapanddropdashboost, and nowdistancetofinishanddistancetofinishprevmay be set as well. - Exposed all respawn and waypoint related functions to Lua.