Split powerItem etc conditions from K_KartGetItemOdds

This commit is contained in:
James R 2023-01-03 04:32:21 -08:00
parent aab661cad8
commit a37eccd708

View file

@ -510,6 +510,62 @@ static fixed_t K_AdjustSPBOdds(const itemroulette_t *roulette, UINT8 position)
} }
} }
typedef struct {
boolean powerItem;
boolean cooldownOnStart;
boolean notNearEnd;
// gameplay state
boolean rival; // player is a bot Rival
} itemconditions_t;
/*--------------------------------------------------
static fixed_t K_AdjustItemOddsToConditions(fixed_t newOdds, const itemconditions_t *conditions, const itemroulette_t *roulette)
Adjust item odds to certain group conditions.
Input Arguments:-
newOdds - The item odds to adjust.
conditions - The conditions state.
roulette - The roulette data that we intend to
insert this item into.
Return:-
New item odds.
--------------------------------------------------*/
static fixed_t K_AdjustItemOddsToConditions(fixed_t newOdds, const itemconditions_t *conditions, const itemroulette_t *roulette)
{
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))
{
// This item should not appear at the end of a race. (Usually trap items that lose their effectiveness)
newOdds = 0;
}
else if (conditions->powerItem == true)
{
// This item is a "power item". This activates "frantic item" toggle related functionality.
if (franticitems == true)
{
// First, power items multiply their odds by 2 if frantic items are on; easy-peasy.
newOdds *= 2;
}
if (conditions->rival == true)
{
// The Rival bot gets frantic-like items, also :p
newOdds *= 2;
}
newOdds = FixedMul(newOdds, FRACUNIT + K_ItemOddsScale(roulette->playing));
}
return newOdds;
}
/*-------------------------------------------------- /*--------------------------------------------------
INT32 K_KartGetItemOdds(const player_t *player, itemroulette_t *const roulette, UINT8 pos, kartitems_t item) INT32 K_KartGetItemOdds(const player_t *player, itemroulette_t *const roulette, UINT8 pos, kartitems_t item)
@ -518,12 +574,14 @@ static fixed_t K_AdjustSPBOdds(const itemroulette_t *roulette, UINT8 position)
INT32 K_KartGetItemOdds(const player_t *player, itemroulette_t *const roulette, UINT8 pos, kartitems_t item) INT32 K_KartGetItemOdds(const player_t *player, itemroulette_t *const roulette, UINT8 pos, kartitems_t item)
{ {
boolean bot = false; boolean bot = false;
boolean rival = false;
UINT8 position = 0; UINT8 position = 0;
boolean powerItem = false; itemconditions_t conditions = {
boolean cooldownOnStart = false; .powerItem = false,
boolean notNearEnd = false; .cooldownOnStart = false,
.notNearEnd = false,
.rival = false,
};
fixed_t newOdds = 0; fixed_t newOdds = 0;
@ -535,7 +593,7 @@ INT32 K_KartGetItemOdds(const player_t *player, itemroulette_t *const roulette,
if (player != NULL) if (player != NULL)
{ {
bot = player->bot; bot = player->bot;
rival = (bot == true && player->botvars.rival == true); conditions.rival = (bot == true && player->botvars.rival == true);
position = player->position; position = player->position;
} }
@ -597,7 +655,7 @@ INT32 K_KartGetItemOdds(const player_t *player, itemroulette_t *const roulette,
case KITEM_EGGMAN: case KITEM_EGGMAN:
case KITEM_SUPERRING: case KITEM_SUPERRING:
{ {
notNearEnd = true; conditions.notNearEnd = true;
break; break;
} }
@ -611,15 +669,15 @@ INT32 K_KartGetItemOdds(const player_t *player, itemroulette_t *const roulette,
case KRITEM_QUADORBINAUT: case KRITEM_QUADORBINAUT:
case KRITEM_DUALJAWZ: case KRITEM_DUALJAWZ:
{ {
powerItem = true; conditions.powerItem = true;
break; break;
} }
case KITEM_HYUDORO: case KITEM_HYUDORO:
case KRITEM_TRIPLEBANANA: case KRITEM_TRIPLEBANANA:
{ {
powerItem = true; conditions.powerItem = true;
notNearEnd = true; conditions.notNearEnd = true;
break; break;
} }
@ -629,15 +687,15 @@ INT32 K_KartGetItemOdds(const player_t *player, itemroulette_t *const roulette,
case KITEM_BUBBLESHIELD: case KITEM_BUBBLESHIELD:
case KITEM_FLAMESHIELD: case KITEM_FLAMESHIELD:
{ {
cooldownOnStart = true; conditions.cooldownOnStart = true;
powerItem = true; conditions.powerItem = true;
break; break;
} }
case KITEM_SPB: case KITEM_SPB:
{ {
cooldownOnStart = true; conditions.cooldownOnStart = true;
notNearEnd = true; conditions.notNearEnd = true;
if ((gametyperules & GTR_CIRCUIT) == 0) if ((gametyperules & GTR_CIRCUIT) == 0)
{ {
@ -654,9 +712,9 @@ INT32 K_KartGetItemOdds(const player_t *player, itemroulette_t *const roulette,
case KITEM_SHRINK: case KITEM_SHRINK:
{ {
cooldownOnStart = true; conditions.cooldownOnStart = true;
powerItem = true; conditions.powerItem = true;
notNearEnd = true; conditions.notNearEnd = true;
if (roulette->playing - 1 <= roulette->exiting) if (roulette->playing - 1 <= roulette->exiting)
{ {
@ -667,8 +725,8 @@ INT32 K_KartGetItemOdds(const player_t *player, itemroulette_t *const roulette,
case KITEM_LIGHTNINGSHIELD: case KITEM_LIGHTNINGSHIELD:
{ {
cooldownOnStart = true; conditions.cooldownOnStart = true;
powerItem = true; conditions.powerItem = true;
if (spbplace != -1) if (spbplace != -1)
{ {
@ -689,35 +747,7 @@ INT32 K_KartGetItemOdds(const player_t *player, itemroulette_t *const roulette,
return newOdds; return newOdds;
} }
if ((cooldownOnStart == true) && (leveltime < (30*TICRATE)+starttime)) newOdds = FixedInt(FixedRound(K_AdjustItemOddsToConditions(newOdds, &conditions, roulette)));
{
// This item should not appear at the beginning of a race. (Usually really powerful crowd-breaking items)
newOdds = 0;
}
else if ((notNearEnd == true) && (roulette->baseDist < ENDDIST))
{
// This item should not appear at the end of a race. (Usually trap items that lose their effectiveness)
newOdds = 0;
}
else if (powerItem == true)
{
// This item is a "power item". This activates "frantic item" toggle related functionality.
if (franticitems == true)
{
// First, power items multiply their odds by 2 if frantic items are on; easy-peasy.
newOdds *= 2;
}
if (rival == true)
{
// The Rival bot gets frantic-like items, also :p
newOdds *= 2;
}
newOdds = FixedMul(newOdds, FRACUNIT + K_ItemOddsScale(roulette->playing));
}
newOdds = FixedInt(FixedRound(newOdds));
return newOdds; return newOdds;
} }