Merge branch 'rulesify-item-odds' into 'master'

Fix Battle item spawning odds

See merge request KartKrew/Kart!852
This commit is contained in:
Sal 2023-01-05 20:43:59 +00:00
commit 14b6ebd25a
2 changed files with 28 additions and 17 deletions

View file

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

View file

@ -434,6 +434,11 @@ static boolean K_DenyShieldOdds(kartitems_t item)
{
INT32 shieldType = K_GetShieldFromItem(item);
if ((gametyperules & GTR_CIRCUIT) == 0)
{
return false;
}
switch (shieldType)
{
case KSHIELD_NONE:
@ -484,6 +489,8 @@ static boolean K_DenyShieldOdds(kartitems_t item)
--------------------------------------------------*/
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
|| position == 1) // No SPB for 1st ever
{
@ -535,12 +542,18 @@ typedef struct {
--------------------------------------------------*/
static fixed_t K_AdjustItemOddsToConditions(fixed_t newOdds, const itemconditions_t *conditions, const itemroulette_t *roulette)
{
// None if this applies outside of Race modes (for now?)
if ((gametyperules & GTR_CIRCUIT) == 0)
{
return newOdds;
}
if ((conditions->cooldownOnStart == true) && (leveltime < (30*TICRATE) + starttime))
{
// This item should not appear at the beginning of a race. (Usually really powerful crowd-breaking items)
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)
newOdds = 0;
@ -560,7 +573,10 @@ static fixed_t K_AdjustItemOddsToConditions(fixed_t newOdds, const itemcondition
newOdds *= 2;
}
newOdds = FixedMul(newOdds, FRACUNIT + K_ItemOddsScale(roulette->playing));
if (roulette != NULL)
{
newOdds = FixedMul(newOdds, FRACUNIT + K_ItemOddsScale(roulette->playing));
}
}
return newOdds;
@ -585,8 +601,6 @@ INT32 K_KartGetItemOdds(const player_t *player, itemroulette_t *const roulette,
fixed_t newOdds = 0;
I_Assert(roulette != NULL);
I_Assert(item > KITEM_NONE); // too many off by one scenarioes.
I_Assert(item < NUMKARTRESULTS);
@ -697,13 +711,9 @@ INT32 K_KartGetItemOdds(const player_t *player, itemroulette_t *const roulette,
conditions.cooldownOnStart = true;
conditions.notNearEnd = true;
if ((gametyperules & GTR_CIRCUIT) == 0)
{
// Needs to be a race.
return 0;
}
if (specialstageinfo.valid == false)
if (roulette != NULL &&
(gametyperules & GTR_CIRCUIT) &&
specialstageinfo.valid == false)
{
newOdds = K_AdjustSPBOdds(roulette, position);
}
@ -716,7 +726,9 @@ INT32 K_KartGetItemOdds(const player_t *player, itemroulette_t *const roulette,
conditions.powerItem = true;
conditions.notNearEnd = true;
if (roulette->playing - 1 <= roulette->exiting)
if (roulette != NULL &&
(gametyperules & GTR_CIRCUIT) &&
roulette->playing - 1 <= roulette->exiting)
{
return 0;
}
@ -728,7 +740,7 @@ INT32 K_KartGetItemOdds(const player_t *player, itemroulette_t *const roulette,
conditions.cooldownOnStart = true;
conditions.powerItem = true;
if (spbplace != -1)
if ((gametyperules & GTR_CIRCUIT) && spbplace != -1)
{
return 0;
}