K_GetTotallyRandomResult: use NULL roulette data

This fixes random paper items spawner RNG not advancing.
This commit is contained in:
James R 2023-01-03 04:59:32 -08:00
parent 339cb1e8b8
commit ae16f124db
2 changed files with 14 additions and 10 deletions

View file

@ -6219,19 +6219,18 @@ void K_DropHnextList(player_t *player, boolean keepshields)
SINT8 K_GetTotallyRandomResult(UINT8 useodds) SINT8 K_GetTotallyRandomResult(UINT8 useodds)
{ {
itemroulette_t rouletteData = {0};
INT32 spawnchance[NUMKARTRESULTS]; INT32 spawnchance[NUMKARTRESULTS];
INT32 totalspawnchance = 0; INT32 totalspawnchance = 0;
INT32 i; INT32 i;
memset(spawnchance, 0, sizeof (spawnchance)); memset(spawnchance, 0, sizeof (spawnchance));
K_FillItemRouletteData(NULL, &rouletteData);
for (i = 1; i < NUMKARTRESULTS; i++) for (i = 1; i < NUMKARTRESULTS; i++)
{ {
// Avoid calling K_FillItemRouletteData since that
// function resets PR_ITEM_ROULETTE.
spawnchance[i] = ( spawnchance[i] = (
totalspawnchance += K_KartGetItemOdds(NULL, &rouletteData, useodds, i) totalspawnchance += K_KartGetItemOdds(NULL, NULL, useodds, i)
); );
} }

View file

@ -489,6 +489,8 @@ static boolean K_DenyShieldOdds(kartitems_t item)
--------------------------------------------------*/ --------------------------------------------------*/
static fixed_t K_AdjustSPBOdds(const itemroulette_t *roulette, UINT8 position) static fixed_t K_AdjustSPBOdds(const itemroulette_t *roulette, UINT8 position)
{ {
I_Assert(roulette != NULL);
if (roulette->firstDist < ENDDIST*2 // No SPB when 1st is almost done if (roulette->firstDist < ENDDIST*2 // No SPB when 1st is almost done
|| position == 1) // No SPB for 1st ever || position == 1) // No SPB for 1st ever
{ {
@ -551,7 +553,7 @@ static fixed_t K_AdjustItemOddsToConditions(fixed_t newOdds, const itemcondition
// This item should not appear at the beginning of a race. (Usually really powerful crowd-breaking items) // This item should not appear at the beginning of a race. (Usually really powerful crowd-breaking items)
newOdds = 0; newOdds = 0;
} }
else if ((conditions->notNearEnd == true) && (roulette->baseDist < ENDDIST)) else if ((conditions->notNearEnd == true) && (roulette != NULL && roulette->baseDist < ENDDIST))
{ {
// This item should not appear at the end of a race. (Usually trap items that lose their effectiveness) // This item should not appear at the end of a race. (Usually trap items that lose their effectiveness)
newOdds = 0; newOdds = 0;
@ -571,7 +573,10 @@ static fixed_t K_AdjustItemOddsToConditions(fixed_t newOdds, const itemcondition
newOdds *= 2; newOdds *= 2;
} }
newOdds = FixedMul(newOdds, FRACUNIT + K_ItemOddsScale(roulette->playing)); if (roulette != NULL)
{
newOdds = FixedMul(newOdds, FRACUNIT + K_ItemOddsScale(roulette->playing));
}
} }
return newOdds; return newOdds;
@ -596,8 +601,6 @@ INT32 K_KartGetItemOdds(const player_t *player, itemroulette_t *const roulette,
fixed_t newOdds = 0; fixed_t newOdds = 0;
I_Assert(roulette != NULL);
I_Assert(item > KITEM_NONE); // too many off by one scenarioes. I_Assert(item > KITEM_NONE); // too many off by one scenarioes.
I_Assert(item < NUMKARTRESULTS); I_Assert(item < NUMKARTRESULTS);
@ -708,7 +711,8 @@ INT32 K_KartGetItemOdds(const player_t *player, itemroulette_t *const roulette,
conditions.cooldownOnStart = true; conditions.cooldownOnStart = true;
conditions.notNearEnd = true; conditions.notNearEnd = true;
if ((gametyperules & GTR_CIRCUIT) && if (roulette != NULL &&
(gametyperules & GTR_CIRCUIT) &&
specialstageinfo.valid == false) specialstageinfo.valid == false)
{ {
newOdds = K_AdjustSPBOdds(roulette, position); newOdds = K_AdjustSPBOdds(roulette, position);
@ -722,7 +726,8 @@ INT32 K_KartGetItemOdds(const player_t *player, itemroulette_t *const roulette,
conditions.powerItem = true; conditions.powerItem = true;
conditions.notNearEnd = true; conditions.notNearEnd = true;
if ((gametyperules & GTR_CIRCUIT) && if (roulette != NULL &&
(gametyperules & GTR_CIRCUIT) &&
roulette->playing - 1 <= roulette->exiting) roulette->playing - 1 <= roulette->exiting)
{ {
return 0; return 0;