WIP: Speed Assist

This commit is contained in:
Antonio Martinez 2025-08-21 23:56:04 -04:00 committed by AJ Martinez
parent 6a54e2c5c2
commit aab374e9ef
6 changed files with 167 additions and 29 deletions

View file

@ -874,6 +874,8 @@ struct player_t
UINT16 invincibilitytimer; // Invincibility timer UINT16 invincibilitytimer; // Invincibility timer
UINT16 invincibilityextensions; // Used to control invinc time gains when it's already been extended. UINT16 invincibilityextensions; // Used to control invinc time gains when it's already been extended.
fixed_t loneliness; // How long has a player been too far to interact? Do they need speed assist?
UINT8 eggmanexplode; // Fake item recieved, explode in a few seconds UINT8 eggmanexplode; // Fake item recieved, explode in a few seconds
SINT8 eggmanblame; // (-1 to 15) - Fake item recieved, who set this fake SINT8 eggmanblame; // (-1 to 15) - Fake item recieved, who set this fake

View file

@ -3950,6 +3950,25 @@ fixed_t K_GetKartSpeedFromStat(UINT8 kartspeed)
return finalspeed; return finalspeed;
} }
// Speed Assist pt.2: If we need assistance, how much?
static fixed_t K_GetKartSpeedAssist(const player_t *player)
{
if (modeattacking)
return FRACUNIT;
if (gametype && GTR_BUMPERS)
return FRACUNIT;
if (specialstageinfo.valid)
return FRACUNIT;
if (K_PlayerUsesBotMovement(player))
return FRACUNIT;
if (player->loneliness < 0)
return FRACUNIT;
fixed_t MAX_SPEED_ASSIST = FRACUNIT;
return FRACUNIT + FixedMul(player->loneliness, MAX_SPEED_ASSIST);
}
fixed_t K_GetKartSpeed(const player_t *player, boolean doboostpower, boolean dorubberband) fixed_t K_GetKartSpeed(const player_t *player, boolean doboostpower, boolean dorubberband)
{ {
const boolean mobjValid = (player->mo != NULL && P_MobjWasRemoved(player->mo) == false); const boolean mobjValid = (player->mo != NULL && P_MobjWasRemoved(player->mo) == false);
@ -4016,6 +4035,8 @@ fixed_t K_GetKartSpeed(const player_t *player, boolean doboostpower, boolean dor
finalspeed += FixedMul(player->outrun, physicsScale); finalspeed += FixedMul(player->outrun, physicsScale);
} }
finalspeed = FixedMul(finalspeed, K_GetKartSpeedAssist(player));
return finalspeed; return finalspeed;
} }
@ -9956,6 +9977,98 @@ void K_KartPlayerThink(player_t *player, ticcmd_t *cmd)
} }
} }
if (!K_PlayerUsesBotMovement(player))
{
UINT32 toDefender = 0;
UINT32 toFirst = 0;
for (UINT8 i = 0; i < MAXPLAYERS; i++)
{
if (playeringame[i] == false || players[i].spectator == true || players[i].exiting)
continue;
if (players[i].position == player->position - 1)
toDefender = K_UndoMapScaling(player->distancetofinish - players[i].distancetofinish);
if (players[i].position == 1)
toFirst = K_UndoMapScaling(player->distancetofinish - players[i].distancetofinish);
}
UINT32 average = 0;
UINT8 counted = 0;
UINT32 firstRaw = 0;
for (UINT8 i = 0; i < MAXPLAYERS; i++)
{
if (playeringame[i] == false || players[i].spectator == true || players[i].exiting)
continue;
if (players[i].position != 1)
{
counted++;
average += K_UndoMapScaling(players[i].distancetofinish);
}
else
{
firstRaw = K_UndoMapScaling(players[i].distancetofinish);
}
}
average /= max(counted, 1);
if (D_NumPlayersInRace() == 2)
{
average = firstRaw;
}
UINT32 REALLY_FAR = average + 3000; // This far back, get max gain
UINT32 TOO_CLOSE = average + 1000; // Start gaining here, lose if closer
UINT32 WAY_TOO_CLOSE = average; // Lose at max rate here
fixed_t MAX_GAIN_PER_SEC = FRACUNIT/10; // % assist to gain per sec when REALLY_FAR
fixed_t MAX_LOSS_PER_SEC = FRACUNIT/10; // % assist to lose per sec when WAY_TOO_CLOSE
UINT32 gaingap = REALLY_FAR - TOO_CLOSE;
UINT32 lossgap = TOO_CLOSE - WAY_TOO_CLOSE;
CONS_Printf("Mine %d - %d / %d / %d\n", player->distancetofinish, WAY_TOO_CLOSE, TOO_CLOSE, REALLY_FAR);
UINT32 mydist = K_UndoMapScaling(player->distancetofinish);
if (mydist >= TOO_CLOSE)
{
fixed_t gain = MAX_GAIN_PER_SEC / TICRATE;
fixed_t gainrate = FRACUNIT * (mydist - TOO_CLOSE) / gaingap;
gainrate = clamp(gainrate, 0, FRACUNIT);
gainrate = Easing_InCubic(gainrate, 0, FRACUNIT);
gain = FixedMul(gain, gainrate);
player->loneliness += gain;
CONS_Printf("gaining @ %d - %d\n", gainrate, player->loneliness);
}
else
{
fixed_t loss = MAX_LOSS_PER_SEC / TICRATE;
fixed_t lossrate = FRACUNIT * (mydist - WAY_TOO_CLOSE) / lossgap;
lossrate = FRACUNIT - clamp(lossrate, 0, FRACUNIT);
lossrate = Easing_InCubic(lossrate, 0, FRACUNIT);
loss = FixedMul(loss, lossrate);
player->loneliness -= loss;
CONS_Printf("LOSING @ %d - %d\n", lossrate, player->loneliness);
}
player->loneliness = clamp(player->loneliness, 0, FRACUNIT);
}
else
{
player->loneliness = 0;
}
if (player->spheres > 40) if (player->spheres > 40)
player->spheres = 40; player->spheres = 40;
// where's the < 0 check? see below the following block! // where's the < 0 check? see below the following block!

View file

@ -77,7 +77,7 @@
#define ROULETTE_SPEED_TIMEATTACK (9) #define ROULETTE_SPEED_TIMEATTACK (9)
#define ROULETTE_SPEED_VERSUS_SLOWEST (12) #define ROULETTE_SPEED_VERSUS_SLOWEST (12)
static UINT32 K_DynamicItemOddsRace[NUMKARTRESULTS-1][2] = static UINT32 K_DynamicItemOddsRace[NUMKARTRESULTS-1][2] =
{ {
// distance, duplication tolerance // distance, duplication tolerance
{20, 10}, // sneaker {20, 10}, // sneaker
@ -104,7 +104,7 @@ static UINT32 K_DynamicItemOddsRace[NUMKARTRESULTS-1][2] =
{43, 5}, // gardentop {43, 5}, // gardentop
{0, 0}, // gachabom {0, 0}, // gachabom
{1, 2}, // stoneshoe {1, 2}, // stoneshoe
{1, 2}, // toxomister {1, 2}, // toxomister
{45, 6}, // dualsneaker {45, 6}, // dualsneaker
{55, 8}, // triplesneaker {55, 8}, // triplesneaker
{25, 2}, // triplebanana {25, 2}, // triplebanana
@ -114,7 +114,7 @@ static UINT32 K_DynamicItemOddsRace[NUMKARTRESULTS-1][2] =
{0, 0}, // triplegachabom {0, 0}, // triplegachabom
}; };
static UINT32 K_DynamicItemOddsBattle[NUMKARTRESULTS-1][2] = static UINT32 K_DynamicItemOddsBattle[NUMKARTRESULTS-1][2] =
{ {
// distance, duplication tolerance // distance, duplication tolerance
{20, 1}, // sneaker {20, 1}, // sneaker
@ -141,7 +141,7 @@ static UINT32 K_DynamicItemOddsBattle[NUMKARTRESULTS-1][2] =
{0, 0}, // gardentop {0, 0}, // gardentop
{10, 5}, // gachabom {10, 5}, // gachabom
{0, 0}, // stoneshoe {0, 0}, // stoneshoe
{0, 0}, // toxomister {0, 0}, // toxomister
{0, 0}, // dualsneaker {0, 0}, // dualsneaker
{20, 1}, // triplesneaker {20, 1}, // triplesneaker
{0, 0}, // triplebanana {0, 0}, // triplebanana
@ -151,7 +151,7 @@ static UINT32 K_DynamicItemOddsBattle[NUMKARTRESULTS-1][2] =
{10, 2}, // triplegachabom {10, 2}, // triplegachabom
}; };
static UINT32 K_DynamicItemOddsSpecial[NUMKARTRESULTS-1][2] = static UINT32 K_DynamicItemOddsSpecial[NUMKARTRESULTS-1][2] =
{ {
// distance, duplication tolerance // distance, duplication tolerance
{15, 2}, // sneaker {15, 2}, // sneaker
@ -178,7 +178,7 @@ static UINT32 K_DynamicItemOddsSpecial[NUMKARTRESULTS-1][2] =
{0, 0}, // gardentop {0, 0}, // gardentop
{0, 0}, // gachabom {0, 0}, // gachabom
{0, 0}, // stoneshoe {0, 0}, // stoneshoe
{0, 0}, // toxomister {0, 0}, // toxomister
{35, 2}, // dualsneaker {35, 2}, // dualsneaker
{0, 0}, // triplesneaker {0, 0}, // triplesneaker
{0, 0}, // triplebanana {0, 0}, // triplebanana
@ -277,7 +277,7 @@ static kartslotmachine_t K_KartItemReelRingBox[] =
KSM__MAX KSM__MAX
}; };
static sfxenum_t ringboxsound[] = static sfxenum_t ringboxsound[] =
{ {
sfx_slot00, sfx_slot00,
sfx_slot01, sfx_slot01,
@ -436,7 +436,7 @@ fixed_t K_ItemOddsScale(UINT8 playerCount)
} }
/*-------------------------------------------------- /*--------------------------------------------------
static UINT32 K_UndoMapScaling(UINT32 distance) UINT32 K_UndoMapScaling(UINT32 distance)
Takes a raw map distance and adjusts it to Takes a raw map distance and adjusts it to
be in x1 scale. be in x1 scale.
@ -447,7 +447,7 @@ fixed_t K_ItemOddsScale(UINT8 playerCount)
Return:- Return:-
Distance unscaled by mapobjectscale. Distance unscaled by mapobjectscale.
--------------------------------------------------*/ --------------------------------------------------*/
static UINT32 K_UndoMapScaling(UINT32 distance) UINT32 K_UndoMapScaling(UINT32 distance)
{ {
if (mapobjectscale != FRACUNIT) if (mapobjectscale != FRACUNIT)
{ {
@ -1115,7 +1115,7 @@ static boolean K_TimingPermitsItem(kartitems_t item, const itemroulette_t *roule
boolean notNearEnd = false; boolean notNearEnd = false;
boolean cooldownOnStart = false; boolean cooldownOnStart = false;
switch (item) switch (item)
{ {
case KITEM_BANANA: case KITEM_BANANA:
@ -1154,7 +1154,7 @@ static boolean K_TimingPermitsItem(kartitems_t item, const itemroulette_t *roule
{ {
// In Race, we reintroduce and reenable this item to counter breakaway frontruns. // In Race, we reintroduce and reenable this item to counter breakaway frontruns.
// No need to roll it if that's not the case. // No need to roll it if that's not the case.
return false; return false;
break; break;
} }
@ -1210,7 +1210,7 @@ void K_FillItemRoulette(player_t *const player, itemroulette_t *const roulette,
if (player != NULL) if (player != NULL)
{ {
roulette->baseDist = K_UndoMapScaling(player->distancetofinish); roulette->baseDist = K_UndoMapScaling(player->distancetofinish);
if (player->pflags & PF_AUTOROULETTE) if (player->pflags & PF_AUTOROULETTE)
roulette->autoroulette = true; roulette->autoroulette = true;
@ -1219,7 +1219,7 @@ void K_FillItemRoulette(player_t *const player, itemroulette_t *const roulette,
// Lua may want to intercept reelbuilder entirely. // Lua may want to intercept reelbuilder entirely.
LUA_HookPreFillItemRoulette(player, roulette, ringbox); LUA_HookPreFillItemRoulette(player, roulette, ringbox);
// If prehook did something, no need to continue. // If prehook did something, no need to continue.
if (roulette->itemList.len != 0) { if (roulette->itemList.len != 0) {
return; return;
@ -1229,7 +1229,7 @@ void K_FillItemRoulette(player_t *const player, itemroulette_t *const roulette,
// Lua can modify the final result. // Lua can modify the final result.
LUA_HookFillItemRoulette(player, roulette, ringbox); LUA_HookFillItemRoulette(player, roulette, ringbox);
// If somehow there's no items, add sad. // If somehow there's no items, add sad.
if (roulette->itemList.len == 0) { if (roulette->itemList.len == 0) {
if (roulette->ringbox) if (roulette->ringbox)
@ -1259,7 +1259,7 @@ void K_FillItemRouletteData(player_t *player, itemroulette_t *const roulette, bo
{ {
K_InitRoulette(roulette); K_InitRoulette(roulette);
} }
if (ringbox == true) if (ringbox == true)
{ {
// If this is being invoked by a Ring Box, it should literally never produce items. // If this is being invoked by a Ring Box, it should literally never produce items.
@ -1504,7 +1504,7 @@ void K_FillItemRouletteData(player_t *player, itemroulette_t *const roulette, bo
{ {
permit[i] = false; permit[i] = false;
} }
} }
// == REEL CANDIDATE PREP // == REEL CANDIDATE PREP
// Dynamic Roulette works by comparing an item's "ideal" distance to our current distance from 1st. // Dynamic Roulette works by comparing an item's "ideal" distance to our current distance from 1st.
@ -1548,7 +1548,7 @@ void K_FillItemRouletteData(player_t *player, itemroulette_t *const roulette, bo
if (player->position > 1) // Loneliness is expected when frontrunnning, don't influence their item table. if (player->position > 1) // Loneliness is expected when frontrunnning, don't influence their item table.
{ {
if ((gametyperules & GTR_CIRCUIT) && specialstageinfo.valid == false) if ((gametyperules & GTR_CIRCUIT) && specialstageinfo.valid == false)
{ {
for (i = 0; i < MAXPLAYERS; i++) for (i = 0; i < MAXPLAYERS; i++)
{ {
if (playeringame[i] == false || players[i].spectator == true || players[i].exiting) if (playeringame[i] == false || players[i].spectator == true || players[i].exiting)
@ -1583,7 +1583,7 @@ void K_FillItemRouletteData(player_t *player, itemroulette_t *const roulette, bo
// incredibly forceful; there's a truly forced special case above. // incredibly forceful; there's a truly forced special case above.
fixed_t spb_odds = K_PercentSPBOdds(roulette, player->position); fixed_t spb_odds = K_PercentSPBOdds(roulette, player->position);
if ((gametyperules & GTR_CIRCUIT) if ((gametyperules & GTR_CIRCUIT)
&& specialstageinfo.valid == false && specialstageinfo.valid == false
&& (spb_odds > 0) & (spbplace == -1) && (spb_odds > 0) & (spbplace == -1)
&& (roulette->preexpdist >= powers[KITEM_SPB]) // SPECIAL CASE: Check raw distance instead of EXP-influenced target distance. && (roulette->preexpdist >= powers[KITEM_SPB]) // SPECIAL CASE: Check raw distance instead of EXP-influenced target distance.
@ -1689,7 +1689,7 @@ void K_FillItemRouletteData(player_t *player, itemroulette_t *const roulette, bo
// This fills the spawnChance array with a rolling count of items, // This fills the spawnChance array with a rolling count of items,
// so that we can loop upward through it until we hit our random index. // so that we can loop upward through it until we hit our random index.
for (i = 1; i < NUMKARTRESULTS; i++) for (i = 1; i < NUMKARTRESULTS; i++)
{ {
// If an item is far too week for this reel, reject it. // If an item is far too week for this reel, reject it.
// This can happen in regions of the odds with a lot of items that // This can happen in regions of the odds with a lot of items that
// don't really like to be duplicated. Favor the player; high-rolling // don't really like to be duplicated. Favor the player; high-rolling
@ -1736,7 +1736,7 @@ void K_FillItemRouletteData(player_t *player, itemroulette_t *const roulette, bo
// == FINALLY ADD THIS SHIT TO THE REEL // == FINALLY ADD THIS SHIT TO THE REEL
// Super simple: generate a random index, // Super simple: generate a random index,
// count up until we hit that index, // count up until we hit that index,
// insert that item and decrement everything after. // insert that item and decrement everything after.
while (totalSpawnChance > 0) while (totalSpawnChance > 0)
{ {
@ -2041,7 +2041,7 @@ void K_KartItemRoulette(player_t *const player, ticcmd_t *const cmd)
S_StartSound(NULL, sfx_s240); S_StartSound(NULL, sfx_s240);
else else
S_StartSound(NULL, sfx_itrol1 + roulette->sound); S_StartSound(NULL, sfx_itrol1 + roulette->sound);
if (roulette->index == 0 && roulette->itemList.len > 1) if (roulette->index == 0 && roulette->itemList.len > 1)
{ {
S_StartSound(NULL, sfx_kc50); S_StartSound(NULL, sfx_kc50);

View file

@ -108,6 +108,21 @@ fixed_t K_ItemOddsScale(UINT8 playerCount);
UINT32 K_ScaleItemDistance(INT32 distance, UINT8 numPlayers); UINT32 K_ScaleItemDistance(INT32 distance, UINT8 numPlayers);
/*--------------------------------------------------
UINT32 K_UndoMapScaling(UINT32 distance)
Takes a raw map distance and adjusts it to
be in x1 scale.
Input Arguments:-
distance - Original distance.
Return:-
Distance unscaled by mapobjectscale.
--------------------------------------------------*/
UINT32 K_UndoMapScaling(UINT32 distance);
/*-------------------------------------------------- /*--------------------------------------------------
void K_PushToRouletteItemList(itemroulette_t *const roulette, INT32 item) void K_PushToRouletteItemList(itemroulette_t *const roulette, INT32 item)

View file

@ -102,16 +102,16 @@ static int lib_iterateDisplayplayers(lua_State *L)
INT32 i = lua_tonumber(L, lua_upvalueindex(1)); INT32 i = lua_tonumber(L, lua_upvalueindex(1));
if (lua_gettop(L) < 2) if (lua_gettop(L) < 2)
{ {
lua_pushcclosure(L, lib_iterateDisplayplayers, 1); lua_pushcclosure(L, lib_iterateDisplayplayers, 1);
return 1; return 1;
} }
if (i <= r_splitscreen) if (i <= r_splitscreen)
{ {
if (!playeringame[displayplayers[i]]) if (!playeringame[displayplayers[i]])
return 0; return 0;
// Return player and splitscreen index. // Return player and splitscreen index.
LUA_PushUserdata(L, &players[displayplayers[i]], META_PLAYER); LUA_PushUserdata(L, &players[displayplayers[i]], META_PLAYER);
lua_pushnumber(L, i); lua_pushnumber(L, i);
@ -515,6 +515,8 @@ static int player_get(lua_State *L)
lua_pushinteger(L, plr->invincibilitytimer); lua_pushinteger(L, plr->invincibilitytimer);
else if (fastcmp(field,"invincibilityextensions")) else if (fastcmp(field,"invincibilityextensions"))
lua_pushinteger(L, plr->invincibilityextensions); lua_pushinteger(L, plr->invincibilityextensions);
else if (fastcmp(field,"loneliness"))
lua_pushinteger(L, plr->loneliness);
else if (fastcmp(field,"eggmanexplode")) else if (fastcmp(field,"eggmanexplode"))
lua_pushinteger(L, plr->eggmanexplode); lua_pushinteger(L, plr->eggmanexplode);
else if (fastcmp(field,"eggmanblame")) else if (fastcmp(field,"eggmanblame"))
@ -748,7 +750,7 @@ static int player_get(lua_State *L)
else if (fastcmp(field,"griefstrikes")) else if (fastcmp(field,"griefstrikes"))
lua_pushinteger(L, plr->griefStrikes); lua_pushinteger(L, plr->griefStrikes);
else if (fastcmp(field,"griefwarned")) else if (fastcmp(field,"griefwarned"))
lua_pushinteger(L, plr->griefWarned); lua_pushinteger(L, plr->griefWarned);
else if (fastcmp(field,"stairjank")) else if (fastcmp(field,"stairjank"))
lua_pushinteger(L, plr->stairjank); lua_pushinteger(L, plr->stairjank);
else if (fastcmp(field,"splitscreenindex")) else if (fastcmp(field,"splitscreenindex"))
@ -947,9 +949,9 @@ static int player_set(lua_State *L)
else if (fastcmp(field,"amps")) else if (fastcmp(field,"amps"))
plr->amps = luaL_checkinteger(L, 3); plr->amps = luaL_checkinteger(L, 3);
else if (fastcmp(field,"amppickup")) else if (fastcmp(field,"amppickup"))
plr->amppickup = luaL_checkinteger(L, 3); plr->amppickup = luaL_checkinteger(L, 3);
else if (fastcmp(field,"ampspending")) else if (fastcmp(field,"ampspending"))
plr->ampspending = luaL_checkinteger(L, 3); plr->ampspending = luaL_checkinteger(L, 3);
else if (fastcmp(field,"itemflags")) else if (fastcmp(field,"itemflags"))
plr->itemflags = luaL_checkinteger(L, 3); plr->itemflags = luaL_checkinteger(L, 3);
else if (fastcmp(field,"outrun")) else if (fastcmp(field,"outrun"))
@ -1166,6 +1168,8 @@ static int player_set(lua_State *L)
plr->invincibilitytimer = luaL_checkinteger(L, 3); plr->invincibilitytimer = luaL_checkinteger(L, 3);
else if (fastcmp(field,"invincibilityextensions")) else if (fastcmp(field,"invincibilityextensions"))
plr->invincibilityextensions = luaL_checkinteger(L, 3); plr->invincibilityextensions = luaL_checkinteger(L, 3);
else if (fastcmp(field,"loneliness"))
plr->loneliness = luaL_checkinteger(L, 3);
else if (fastcmp(field,"eggmanexplode")) else if (fastcmp(field,"eggmanexplode"))
plr->eggmanexplode = luaL_checkinteger(L, 3); plr->eggmanexplode = luaL_checkinteger(L, 3);
else if (fastcmp(field,"eggmanblame")) else if (fastcmp(field,"eggmanblame"))
@ -1813,12 +1817,12 @@ int LUA_PlayerLib(lua_State *L)
lua_pushcfunction(L, ticcmd_set); lua_pushcfunction(L, ticcmd_set);
lua_setfield(L, -2, "__newindex"); lua_setfield(L, -2, "__newindex");
lua_pop(L,1); lua_pop(L,1);
luaL_newmetatable(L, META_SONICLOOPVARS); luaL_newmetatable(L, META_SONICLOOPVARS);
lua_pushcfunction(L, sonicloopvars_get); lua_pushcfunction(L, sonicloopvars_get);
lua_setfield(L, -2, "__index"); lua_setfield(L, -2, "__index");
lua_pop(L,1); lua_pop(L,1);
luaL_newmetatable(L, META_SONICLOOPCAMVARS); luaL_newmetatable(L, META_SONICLOOPCAMVARS);
lua_pushcfunction(L, sonicloopcamvars_get); lua_pushcfunction(L, sonicloopcamvars_get);
lua_setfield(L, -2, "__index"); lua_setfield(L, -2, "__index");

View file

@ -585,6 +585,8 @@ static void P_NetArchivePlayers(savebuffer_t *save)
WRITEUINT16(save->p, players[i].invincibilitytimer); WRITEUINT16(save->p, players[i].invincibilitytimer);
WRITEUINT16(save->p, players[i].invincibilityextensions); WRITEUINT16(save->p, players[i].invincibilityextensions);
WRITEFIXED(save->p, players[i].loneliness);
WRITEUINT8(save->p, players[i].eggmanexplode); WRITEUINT8(save->p, players[i].eggmanexplode);
WRITESINT8(save->p, players[i].eggmanblame); WRITESINT8(save->p, players[i].eggmanblame);
@ -1256,6 +1258,8 @@ static void P_NetUnArchivePlayers(savebuffer_t *save)
players[i].invincibilitytimer = READUINT16(save->p); players[i].invincibilitytimer = READUINT16(save->p);
players[i].invincibilityextensions = READUINT16(save->p); players[i].invincibilityextensions = READUINT16(save->p);
players[i].loneliness = READFIXED(save->p);
players[i].eggmanexplode = READUINT8(save->p); players[i].eggmanexplode = READUINT8(save->p);
players[i].eggmanblame = READSINT8(save->p); players[i].eggmanblame = READSINT8(save->p);