Skip to content

Expose gameplay functions from k_kart.c to Lua

Summary

This MR exposes various gameplay-related functions from k_kart.c (as well as two from p_user.c, two from k_endcam.c, and one from k_hitlag.c) to Lua. In addition, it fixes K_FindJawzTarget so it that it returns a mobj_t type and allows its angle to be set.

It exposes the following:

  • boolean K_KartSolidBounce(mobj_t bounceMobj, mobj_t solidMobj)
  • void K_AwardPlayerRings(player_t player, UINT16 rings, boolean overload)
  • void K_DoPowerClash(mobj_t t1, mobj_t t2)
  • mobj_t K_CreatePaperItem(fixed_t x, fixed_t y, fixed_t z, angle_t angle, SINT8 flip, UINT8 type, UINT16 amount)
  • mobj_t K_FlingPaperItem(fixed_t x, fixed_t y, fixed_t z, angle_t angle, SINT8 flip, UINT8 type, UINT16 amount)
  • boolean K_PlayerGuard(player_t player)
  • void K_SetTireGrease(player_t player, tic_t tics)
  • void K_PlayerJustBumped(player_t player)
  • void K_TumbleInterrupt(player_t player)
  • void K_DoInvincibility(player_t player, tic_t time)
  • INT32 P_GivePlayerSpheres(player_t player, INT32 num_spheres)
  • void P_DoAllPlayersExit(pflags_t flags, boolean givelife)
  • void K_DoGuardBreak(mobj_t t1, mobj_t t2)
  • void K_DebtStingPlayer(player_t player, mobj_t source)
  • void K_StartRoundWinCamera(mobj_torigin, angle_t focusAngle, fixed_t finalRadius, tic_t panDuration, fixed_t panSpeed)
  • boolean K_EndCameraIsFreezing(void)
  • void K_SetHitLagForObjects(mobj_t victim, mobj_t inflictor, mobj_t source, INT32 tics, boolean fromDamage)
  • void K_BattleAwardHit(player_t player, player_t victim, mobj_t inflictor, UINT8 bumpersRemoved)
  • void K_GiveBumpersToPlayer(player_t player, player_t victim, UINT8 amount)
  • void K_GivePointsToPlayer(player_t player, player_t victim, UINT8 amount)
  • mobj_t K_ThrowKartItem(player_t player, boolean missile, mobjtype_t mapthing, INT32 defaultDir, INT32 altthrow, angle_t angleOffset)
  • INT32 K_GetKartRingPower(player_t player, boolean boosted)
  • INT16 K_UpdateSteeringValue(INT16 inputSteering, INT16 destSteering)
  • INT16 K_GetKartTurnValue(player_t player, INT16 turnvalue)
  • INT32 K_GetUnderwaterTurnAdjust(player_t player)
  • INT32 K_GetKartDriftSparkValueForStage(player_t player, UINT8 stage)
  • void K_UpdateAllPlayerPositions(void)
  • SINT8 K_GetTotallyRandomResult(UINT8 useodds)
  • void K_ApplyTripWire(player_t player, tripwirestate_t state)
    • Also exposes the tripwirestate_t values: TRIPSTATE_NONE, TRIPSTATE_PASSED and TRIPSTATE_BLOCKED
  • boolean K_FastFallBounce(player_t player)
  • void K_EggmanTransfer(player_t source, player_t victim)

Testing

Some videos:

ringracers0629

ringracers0630

Testing environment: ringracers_gameplayFunctionsLua.exe -console -skipintro -warp RR_TESTRUN +addfile gameplayfuncs.lua

To test some battle-specific functions, this command can be run: battletest 1; forcebots 1; map test run -gametype Battle -force

I used a script, gameplayfuncs.lua, to test all of the additions. Namely:

  • There's a HUD hook, controlled by gameplayhuddebug, that displays the following return values: K_PlayerGuard, K_FindJawzTarget, K_EndCameraIsFreezing, K_GetKartRingPower, K_UpdateSteeringValue, K_GetKartTurnValue and K_GetUnderwaterTurnAdjust.
  • There's the following commands that test various functions:
    • solidbouncetest:
      • Spawns a thok object in front of the player with a collision hook that uses K_KartSolidBounce to handle the bounce. When a collision happens, K_PlayerJustBumped is run for player objects and K_SetHitLagForObjects is run for both objects for a second.
    • awardrings (rings) [overload]:
      • Awards rings to the player as if picked from a ring capsule or ring box. Overload parameter defaults to true.
      • Examples: awardrings 20, awardrings 50, awardrings 200 false.
      • Tests K_AwardPlayerRings.
    • clashtest: Spawns a thok object in front of the player with a collision hook. When a collision happens, K_PlayerJustBumped is run for player objects and K_DoPowerClash is run for both objects.
    • paperitem [type] [amount]:
      • Spawns a paper item in front of the player.
      • Examples: paperitem, paperitem 5, paperitem 6 4.
      • Tests K_CreatePaperItem.
    • flingpaperitem [type] [amount]:
      • Likewise as paperitem, but flings it instead.
      • Examples: flingpaperitem, flingpaperitem 5, flingpaperitem 6 4.
      • Tests K_FlingPaperItem.
    • tiregrease (tics):
      • Applies tire grease to the player.
      • Examples: tiregrease 35, tiregrease 140.
      • Tests K_SetTireGrease.
    • tumbleinterrupt:
      • Downgrades the player's tumble into wipeout. A sister command tumbleme exists for testing this.
      • Tests K_TumbleInterrupt.
    • invincme (tics):
      • Applies invincibility to the player and its effects.
      • Examples: invincme 35, invincme 140.
      • Tests K_DoInvincibility.
    • givespheres (amount):
      • In battle, capsules and versus, this function gives the player the number of spheres.
      • Examples: givespheres 10, givespheres 40.
      • Tests P_GivePlayerSpheres.
    • allplayersexit (flags) [trygivelife]:
      • Exits all players from the level.
      • Examples: allplayersexit 0 true, allplayersexit 2048.
      • Tests P_DoAllPlayersExit.
    • guardbreak (node):
      • Does a guardbreak on the selected player.
      • Examples: guardbreak 1, guardbreak 2.
      • Tests K_DoGuardBreak.
    • ringsting (node) [source]:
      • Does a ring sting on the selected player. If a source (by node) is set, it increases the sting duration based on weight.
      • Examples: ringsting 0, ringsting 1 0.
      • Tests K_DebtStingPlayer.
    • endcamera [focusangle] [finalradius] [panduration] [panspeed]:
      • Starts the battle end camera.
      • Examples: endcamera. endcamera 90 400 70 128.
      • Tests K_StartRoundWinCamera.
    • battleawardhit (victimnode) (damage):
      • This awards the player points in gamemodes that use them, such as battle. Damage (and whether the victim is dead) influences whether the level ends on a win.
      • Example: battleawardhit 1, battleawardhit 2 3.
      • Tests K_BattleAwardHit.
    • givebumpers [victim] [amount]:
      • Gives the player bumpers. If victim is set, it will have their color. Amount controls the amount of bumpers given.
      • Example: givebumers, givebumpers 1, givebumpers 2 2.
      • Tests K_GiveBumpersToPlayer.
    • givepoints [victim] [amount]:
      • Awards the player the given amount of points. If a victim is set, the visual will be colored to match the victim.
      • Example: givepoints, givepoints 1, givepoints 2 3.
      • Tests K_GivePointsToPlayer.
    • throwkartitem [missile] [mapthing] [defaultDir] [altthrow] [angleOffset]:
      • Throws an item from the player's position. Missile controls whether the item is lobbed or thrown forward. Mapthing is the object type to throw. defaultDir is the direction to throw the item if the player's throw direction is neutral. Altthrow is whether the way items are thrown will vary or not (1 is for gachaboms, 2 is for kitchen sinks). angleOffset describles the angle offset the item will use when thrown.
      • Examples: throwkartitem, throwkartitem 1 MT_GACHABOM -1 1 0.
      • Tests K_ThrowKartItem.
      • There seems to be a weird bug with lobbed items when this function is called from a command. However, there's a PlayerThink hook that throws a banana, a lobbed item, from the player, which means this aspect should work correctly in thinkers.
    • kartdsvforstage [value]:
      • Prints the value required to reach a specific drift spark value for the player's skin. Value sets which stage to check.
      • Examples: kartdsvforstage, kartdsvforstage 2, kartdsvforstage 4.
      • Tests K_GetKartDriftSparkValueForStage.
    • updateallplayerpositions:
      • Updates all of the player's positions based on their progress in a race or score in battle.
      • Tests K_UpdateAllPlayerPositions.
    • totallyrandomitem [value]:
      • Prints in chat a totally random item from the given itemodds value.
      • Examples: totallyrandomitem, totallyrandomitem 1, totallyrandomitem 7.
      • Tests K_GetTotallyRandomResult.
    • applytripwire [value]:
      • Acts as if the player crossed a tripwire. Value determines whether they crossed it or not.
      • Examples: applytripwire 1, applytripwire 2.
      • Tests K_ApplyTripWire.
    • fastfallbounce [value]:
      • Makes the player perform the fastfall bounce technique. Value sets their fastfall value.
      • Example: fastfallbounce 1, fastfallbounce 35.
      • Tests K_FastFallBounce.
    • eggmantransfer [node]:
      • Acts as it the player transfered their Eggman Monitor to another player.
      • Examples: eggmantransfer 1, eggmantransfer 2.
      • Tests K_EggmanTransfer.

Changelog

  • Lua: Fixed K_FindJawzTarget so that it properly returns a mobj_t, and allow angle to be set.
  • Lua: Exposed tripwirestate_t values: TRIPSTATE_NONE, TRIPSTATE_PASSED and TRIPSTATE_BLOCKED
  • Lua: Exposed boolean K_KartSolidBounce(mobj_t bounceMobj, mobj_t solidMobj)
  • Lua: Exposed void K_AwardPlayerRings(player_t player, UINT16 rings, boolean overload)
  • Lua: Exposed void K_DoPowerClash(mobj_t t1, mobj_t t2)
  • Lua: Exposed mobj_t K_CreatePaperItem(fixed_t x, fixed_t y, fixed_t z, angle_t angle, SINT8 flip, UINT8 type, UINT16 amount)
  • Lua: Exposed mobj_t K_FlingPaperItem(fixed_t x, fixed_t y, fixed_t z, angle_t angle, SINT8 flip, UINT8 type, UINT16 amount)
  • Lua: Exposed boolean K_PlayerGuard(player_t player)
  • Lua: Exposed void K_SetTireGrease(player_t player, tic_t tics)
  • Lua: Exposed void K_PlayerJustBumped(player_t player)
  • Lua: Exposed void K_TumbleInterrupt(player_t player)
  • Lua: Exposed void K_DoInvincibility(player_t player, tic_t time)
  • Lua: Exposed INT32 P_GivePlayerSpheres(player_t player, INT32 num_spheres)
  • Lua: Exposed void P_DoAllPlayersExit(pflags_t flags, boolean givelife)
  • Lua: Exposed void K_DoGuardBreak(mobj_t t1, mobj_t t2)
  • Lua: Exposed void K_DebtStingPlayer(player_t player, mobj_t source)
  • Lua: Exposed void K_StartRoundWinCamera(mobj_torigin, angle_t focusAngle, fixed_t finalRadius, tic_t panDuration, fixed_t panSpeed)
  • Lua: Exposed boolean K_EndCameraIsFreezing(void)
  • Lua: Exposed void K_SetHitLagForObjects(mobj_t victim, mobj_t inflictor, mobj_t source, INT32 tics, boolean fromDamage)
  • Lua: Exposed void K_BattleAwardHit(player_t player, player_t victim, mobj_t inflictor, UINT8 bumpersRemoved)
  • Lua: Exposed void K_GiveBumpersToPlayer(player_t player, player_t victim, UINT8 amount)
  • Lua: Exposed void K_GivePointsToPlayer(player_t player, player_t victim, UINT8 amount)
  • Lua: Exposed mobj_t K_ThrowKartItem(player_t player, boolean missile, mobjtype_t mapthing, INT32 defaultDir, INT32 altthrow, angle_t angleOffset)
  • Lua: Exposed INT32 K_GetKartRingPower(player_t player, boolean boosted)
  • Lua: Exposed INT16 K_UpdateSteeringValue(INT16 inputSteering, INT16 destSteering)
  • Lua: Exposed INT16 K_GetKartTurnValue(player_t player, INT16 turnvalue)
  • Lua: Exposed INT32 K_GetUnderwaterTurnAdjust(player_t player)
  • Lua: Exposed INT32 K_GetKartDriftSparkValueForStage(player_t player, UINT8 stage)
  • Lua: Exposed void K_UpdateAllPlayerPositions(void)
  • Lua: Exposed SINT8 K_GetTotallyRandomResult(UINT8 useodds)
  • Lua: Exposed void K_ApplyTripWire(player_t player, tripwirestate_t state)
  • Lua: Exposed boolean K_FastFallBounce(player_t player)
  • Lua: Exposed void K_EggmanTransfer(player_t source, player_t victim)

Merge request reports

Loading