From 5a62e902a0019c1f8acc15c8e1313c4fb1dd9b91 Mon Sep 17 00:00:00 2001 From: JugadorXEI Date: Sat, 26 Oct 2024 19:52:20 +0200 Subject: [PATCH] Expose K_GetItemRouletteDistance, K_FindUseodds and K_CreateAndShuffleItemReel to Lua --- src/k_roulette.c | 10 +--------- src/k_roulette.h | 30 ++++++++++++++++++++++++++++++ src/lua_baselib.c | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+), 9 deletions(-) diff --git a/src/k_roulette.c b/src/k_roulette.c index 6a22f2269..c5000f1f2 100644 --- a/src/k_roulette.c +++ b/src/k_roulette.c @@ -502,15 +502,7 @@ static UINT32 K_ScaleItemDistance(const player_t *player, UINT32 distance, UINT8 /*-------------------------------------------------- static UINT32 K_GetItemRouletteDistance(const player_t *player, UINT8 numPlayers) - Gets a player's distance used for the item - roulette, including all scaling factors. - - Input Arguments:- - player - The player to get the distance of. - numPlayers - Number of players in the game. - - Return:- - The player's finalized item distance. + See header file for description. --------------------------------------------------*/ UINT32 K_GetItemRouletteDistance(const player_t *player, UINT8 numPlayers) { diff --git a/src/k_roulette.h b/src/k_roulette.h index 7af1b98d8..3d356f75a 100644 --- a/src/k_roulette.h +++ b/src/k_roulette.h @@ -278,8 +278,38 @@ void K_KartItemRoulette(player_t *const player, ticcmd_t *cmd); void K_KartGetItemResult(player_t *const player, kartitems_t getitem); +/*-------------------------------------------------- + static UINT32 K_GetItemRouletteDistance(const player_t *player, UINT8 numPlayers) + + Gets a player's distance used for the item + roulette, including all scaling factors. + + Input Arguments:- + player - The player to get the distance of. + numPlayers - Number of players in the game. + + Return:- + The player's finalized item distance. +--------------------------------------------------*/ + UINT32 K_GetItemRouletteDistance(const player_t *player, UINT8 numPlayers); +/*-------------------------------------------------- + static UINT8 K_FindUseodds(const player_t *player, itemroulette_t *const roulette) + + Gets which item bracket the player is in. + This can be adjusted depending on which + items being turned off. + + Input Arguments:- + player - The player the roulette is for. + roulette - The item roulette data. + + Return:- + The item bracket the player is in, as an + index to the array. +--------------------------------------------------*/ + #ifdef __cplusplus } // extern "C" #endif diff --git a/src/lua_baselib.c b/src/lua_baselib.c index 911edcc7d..6ca5fa891 100644 --- a/src/lua_baselib.c +++ b/src/lua_baselib.c @@ -4320,6 +4320,36 @@ static int lib_kKartGetItemResult(lua_State *L) return 0; } +static int lib_kGetItemRouletteDistance(lua_State *L) +{ + player_t *player = *((player_t **)luaL_checkudata(L, 1, META_PLAYER)); + UINT8 numPlayers = luaL_checkinteger(L, 2); + INLEVEL + + if (!player) + return LUA_ErrInvalid(L, "player_t"); + + lua_pushinteger(L, K_GetItemRouletteDistance(player, numPlayers)); + return 1; +} + +static int lib_kCreateAndShuffleItemReel(lua_State *L) +{ + player_t *player = NULL; + itemroulette_t *itemRoulette = NULL; + + getItemRouletteOrPlayerBasedOnFirstParam(L, &player, &itemRoulette); + boolean freeplay = lua_optboolean(L, 2); + + NOHUD + INLEVEL + if (!player && !itemRoulette) + return LUA_ErrInvalid(L, "player_t/itemroulette_t"); + + K_CreateAndShuffleItemReel(player, itemRoulette, freeplay); + return 0; +} + static int lib_getTimeMicros(lua_State *L) { lua_pushinteger(L, I_GetPreciseTime() / (I_GetPrecisePrecision() / 1000000)); @@ -4622,6 +4652,9 @@ static luaL_Reg lib[] = { {"K_StartEggmanRoulette", lib_kStartEggmanRoulette}, {"K_StopRoulette", lib_kStopRoulette}, {"K_KartGetItemResult", lib_kKartGetItemResult}, + {"K_GetItemRouletteDistance", lib_kGetItemRouletteDistance}, + {"K_FindUseodds", lib_kFindUseodds}, + {"K_CreateAndShuffleItemReel", lib_kCreateAndShuffleItemReel}, // hu_stuff technically? {"HU_DoTitlecardCEcho", lib_startTitlecardCecho},