From bf278f4fcc06b8b93e2445c5548487288da0fe52 Mon Sep 17 00:00:00 2001 From: JugadorXEI Date: Sun, 27 Oct 2024 17:08:11 +0100 Subject: [PATCH] Expose K_ScaleItemDistance and K_ItemOddsScale to Lua --- src/k_roulette.c | 25 ++++++------------------- src/k_roulette.h | 32 ++++++++++++++++++++++++++++++++ src/lua_baselib.c | 17 +++++++++++++++++ 3 files changed, 55 insertions(+), 19 deletions(-) diff --git a/src/k_roulette.c b/src/k_roulette.c index 6bec64905..bac0b1e71 100644 --- a/src/k_roulette.c +++ b/src/k_roulette.c @@ -399,17 +399,9 @@ botItemPriority_e K_GetBotItemPriority(kartitems_t result) /*-------------------------------------------------- static fixed_t K_ItemOddsScale(UINT8 playerCount) - A multiplier for odds and distances to scale - them with the player count. - - Input Arguments:- - playerCount - Number of players in the game. - - Return:- - Fixed point number, to multiply odds or - distances by. + See header file for description. --------------------------------------------------*/ -static fixed_t K_ItemOddsScale(UINT8 playerCount) +fixed_t K_ItemOddsScale(UINT8 playerCount) { const UINT8 basePlayer = 8; // The player count we design most of the game around. fixed_t playerScaling = 0; @@ -462,7 +454,7 @@ static UINT32 K_UndoMapScaling(UINT32 distance) } /*-------------------------------------------------- - static UINT32 K_ScaleItemDistance(UINT32 distance, UINT8 numPlayers) + UINT32 K_ScaleItemDistance(UINT32 distance, UINT8 numPlayers) Adjust item distance for lobby-size scaling as well as Frantic Items. @@ -475,10 +467,8 @@ static UINT32 K_UndoMapScaling(UINT32 distance) Return:- New distance after scaling. --------------------------------------------------*/ -static UINT32 K_ScaleItemDistance(const player_t *player, UINT32 distance, UINT8 numPlayers) +UINT32 K_ScaleItemDistance(INT32 distance, UINT8 numPlayers) { - (void)player; - #if 0 if (franticitems == true) { @@ -493,9 +483,6 @@ static UINT32 K_ScaleItemDistance(const player_t *player, UINT32 distance, UINT8 FRACUNIT + (K_ItemOddsScale(numPlayers) / 2) ); - // Distance is reduced based on the player's gradingfactor - // distance = FixedMul(distance, player->gradingfactor); - return distance; } @@ -554,7 +541,7 @@ UINT32 K_GetItemRouletteDistance(const player_t *player, UINT8 numPlayers) } pdis = K_UndoMapScaling(pdis); - pdis = K_ScaleItemDistance(player, pdis, numPlayers); + pdis = K_ScaleItemDistance(pdis, numPlayers); if (player->bot && (player->botvars.rival || cv_levelskull.value)) { @@ -830,7 +817,7 @@ static void K_InitRoulette(itemroulette_t *const roulette) && roulette->secondDist > roulette->firstDist) { roulette->secondToFirst = roulette->secondDist - roulette->firstDist; - roulette->secondToFirst = K_ScaleItemDistance(&players[i], roulette->secondToFirst, 16 - roulette->playing); // Reversed scaling + roulette->secondToFirst = K_ScaleItemDistance(roulette->secondToFirst, 16 - roulette->playing); // Reversed scaling } } diff --git a/src/k_roulette.h b/src/k_roulette.h index e61fb7a97..84356ea06 100644 --- a/src/k_roulette.h +++ b/src/k_roulette.h @@ -76,6 +76,38 @@ boolean K_ItemSingularity(kartitems_t item); botItemPriority_e K_GetBotItemPriority(kartitems_t result); +/*-------------------------------------------------- + fixed_t K_ItemOddsScale(UINT8 playerCount) + + A multiplier for odds and distances to scale + them with the player count. + + Input Arguments:- + playerCount - Number of players in the game. + + Return:- + Fixed point number, to multiply odds or + distances by. +--------------------------------------------------*/ + +fixed_t K_ItemOddsScale(UINT8 playerCount); + +/*-------------------------------------------------- + UINT32 K_ScaleItemDistance(UINT32 distance, UINT8 numPlayers) + + Adjust item distance for lobby-size scaling + as well as Frantic Items. + + Input Arguments:- + distance - Original distance. + numPlayers - Number of players in the game. + + Return:- + New distance after scaling. +--------------------------------------------------*/ + +UINT32 K_ScaleItemDistance(INT32 distance, UINT8 numPlayers); + /*-------------------------------------------------- void K_PushToRouletteItemList(itemroulette_t *const roulette, INT32 item) diff --git a/src/lua_baselib.c b/src/lua_baselib.c index 7070be288..4fcb22622 100644 --- a/src/lua_baselib.c +++ b/src/lua_baselib.c @@ -4411,6 +4411,21 @@ static int lib_kCalculateRouletteSpeed(lua_State *L) return 0; } +static int lib_kScaleItemDistance(lua_State *L) +{ + UINT32 distance = luaL_checkinteger(L, 1); + UINT8 numPlayers = luaL_checkinteger(L, 2); + lua_pushfixed(L, K_ScaleItemDistance(distance, numPlayers)); + return 1; +} + +static int lib_kItemOddsScale(lua_State *L) +{ + UINT8 playerCount = luaL_checkinteger(L, 1); + lua_pushfixed(L, K_ItemOddsScale(playerCount)); + return 1; +} + static int lib_kWipeItemsInReel(lua_State *L) { player_t *player = NULL; @@ -4864,6 +4879,8 @@ static luaL_Reg lib[] = { {"K_GetRouletteOffset", lib_kGetRouletteOffset}, {"K_GetSlotOffset", lib_kGetSlotOffset}, {"K_CalculateRouletteSpeed", lib_kCalculateRouletteSpeed}, + {"K_ScaleItemDistance", lib_kScaleItemDistance}, + {"K_ItemOddsScale", lib_kItemOddsScale}, // These are not real functions in k_roulette, but they allow // encapsulation on how the scripter interacts with the item reel. {"K_WipeItemsInReel", lib_kWipeItemsInReel},