mirror of
https://github.com/KartKrewDev/RingRacers.git
synced 2026-02-23 14:01:14 +00:00
Add K_GetTotallyRandomResult, for battle item spawners
This commit is contained in:
parent
a94e18c277
commit
6eb8da1a56
2 changed files with 51 additions and 50 deletions
100
src/k_kart.c
100
src/k_kart.c
|
|
@ -6183,17 +6183,48 @@ 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++)
|
||||
{
|
||||
spawnchance[i] = (
|
||||
totalspawnchance += K_KartGetItemOdds(NULL, &rouletteData, useodds, i)
|
||||
);
|
||||
}
|
||||
|
||||
if (totalspawnchance > 0)
|
||||
{
|
||||
totalspawnchance = P_RandomKey(PR_ITEM_ROULETTE, totalspawnchance);
|
||||
for (i = 0; i < NUMKARTRESULTS && spawnchance[i] <= totalspawnchance; i++);
|
||||
}
|
||||
else
|
||||
{
|
||||
i = KITEM_SAD;
|
||||
}
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
mobj_t *K_CreatePaperItem(fixed_t x, fixed_t y, fixed_t z, angle_t angle, SINT8 flip, UINT8 type, UINT8 amount)
|
||||
{
|
||||
mobj_t *drop = P_SpawnMobj(x, y, z, MT_FLOATINGITEM);
|
||||
mobj_t *backdrop = P_SpawnMobjFromMobj(drop, 0, 0, 0, MT_OVERLAY);
|
||||
|
||||
|
||||
P_SetTarget(&backdrop->target, drop);
|
||||
P_SetMobjState(backdrop, S_ITEMBACKDROP);
|
||||
|
||||
P_SetScale(drop, drop->scale>>4);
|
||||
drop->destscale = (3*drop->destscale)/2;
|
||||
|
||||
|
||||
drop->angle = angle;
|
||||
P_Thrust(drop,
|
||||
FixedAngle(P_RandomFixed(PR_ITEM_ROULETTE) * 180) + angle,
|
||||
|
|
@ -6205,62 +6236,31 @@ mobj_t *K_CreatePaperItem(fixed_t x, fixed_t y, fixed_t z, angle_t angle, SINT8
|
|||
|
||||
if (type == 0)
|
||||
{
|
||||
itemroulette_t rouletteData = {0};
|
||||
UINT8 useodds = 0;
|
||||
INT32 spawnchance[NUMKARTRESULTS];
|
||||
INT32 totalspawnchance = 0;
|
||||
INT32 i;
|
||||
const SINT8 i = K_GetTotallyRandomResult(amount);
|
||||
|
||||
memset(spawnchance, 0, sizeof (spawnchance));
|
||||
// TODO: this is bad!
|
||||
// K_KartGetItemResult requires a player
|
||||
// but item roulette will need rewritten to change this
|
||||
|
||||
useodds = amount;
|
||||
const SINT8 newType = K_ItemResultToType(i);
|
||||
const UINT8 newAmount = K_ItemResultToAmount(i);
|
||||
|
||||
K_FillItemRouletteData(NULL, &rouletteData);
|
||||
|
||||
for (i = 1; i < NUMKARTRESULTS; i++)
|
||||
if (newAmount > 1)
|
||||
{
|
||||
spawnchance[i] = (
|
||||
totalspawnchance += K_KartGetItemOdds(NULL, &rouletteData, useodds, i)
|
||||
);
|
||||
}
|
||||
UINT8 j;
|
||||
|
||||
if (totalspawnchance > 0)
|
||||
{
|
||||
UINT8 newType;
|
||||
UINT8 newAmount;
|
||||
|
||||
totalspawnchance = P_RandomKey(PR_ITEM_ROULETTE, totalspawnchance);
|
||||
for (i = 0; i < NUMKARTRESULTS && spawnchance[i] <= totalspawnchance; i++);
|
||||
|
||||
// TODO: this is bad!
|
||||
// K_KartGetItemResult requires a player
|
||||
// but item roulette will need rewritten to change this
|
||||
|
||||
newType = K_ItemResultToType(i);
|
||||
newAmount = K_ItemResultToAmount(i);
|
||||
|
||||
if (newAmount > 1)
|
||||
for (j = 0; j < newAmount-1; j++)
|
||||
{
|
||||
UINT8 j;
|
||||
|
||||
for (j = 0; j < newAmount-1; j++)
|
||||
{
|
||||
K_CreatePaperItem(
|
||||
x, y, z,
|
||||
angle, flip,
|
||||
newType, 1
|
||||
);
|
||||
}
|
||||
K_CreatePaperItem(
|
||||
x, y, z,
|
||||
angle, flip,
|
||||
newType, 1
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
drop->threshold = newType;
|
||||
drop->movecount = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
drop->threshold = 1;
|
||||
drop->movecount = 1;
|
||||
}
|
||||
drop->threshold = newType;
|
||||
drop->movecount = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
|||
|
|
@ -138,6 +138,7 @@ INT32 K_GetKartDriftSparkValueForStage(player_t *player, UINT8 stage);
|
|||
void K_SpawnDriftBoostExplosion(player_t *player, int stage);
|
||||
void K_SpawnDriftElectricSparks(player_t *player, int color, boolean shockwave);
|
||||
void K_KartUpdatePosition(player_t *player);
|
||||
SINT8 K_GetTotallyRandomResult(UINT8 useodds);
|
||||
mobj_t *K_CreatePaperItem(fixed_t x, fixed_t y, fixed_t z, angle_t angle, SINT8 flip, UINT8 type, UINT8 amount);
|
||||
void K_DropItems(player_t *player);
|
||||
void K_DropRocketSneaker(player_t *player);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue