diff --git a/src/d_player.h b/src/d_player.h index 3e12611b4..12e7648b9 100644 --- a/src/d_player.h +++ b/src/d_player.h @@ -494,6 +494,7 @@ typedef struct player_s INT16 karmadelay; tic_t overtimekarma; // time to live in overtime comeback INT16 spheres; + tic_t spheredigestion; SINT8 glanceDir; // Direction the player is trying to look backwards in diff --git a/src/k_kart.c b/src/k_kart.c index 8b14be91c..d7d610605 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -7065,12 +7065,32 @@ void K_KartPlayerThink(player_t *player, ticcmd_t *cmd) { // Deplete 1 every tic when removed from the game. player->spheres--; + player->spheredigestion = 0; } else { - // Deplete 1 every second when playing. - if ((leveltime % TICRATE) == 0) - player->spheres--; + INT16 spheredigestion = TICRATE; // Base rate of 1 every second when playing. + INT16 digestionpower = ((10 - player->kartspeed) + (10 - player->kartweight))-1; // 1 to 17 + spheredigestion -= ((player->spheres*digestionpower)/20); + + if (spheredigestion < 1) // just in case + { + spheredigestion = 1; + } + + if ((player->spheres > 0) && (player->spheredigestion > 0)) + { + player->spheredigestion--; + if (player->spheredigestion == 0) + { + player->spheres--; + player->spheredigestion = (tic_t)spheredigestion; + } + } + else + { + player->spheredigestion = (tic_t)spheredigestion; + } } if (player->spheres > 40) diff --git a/src/lua_playerlib.c b/src/lua_playerlib.c index 17e1a39b1..e323c1e1d 100644 --- a/src/lua_playerlib.c +++ b/src/lua_playerlib.c @@ -372,6 +372,8 @@ static int player_get(lua_State *L) lua_pushinteger(L, plr->karmadelay); else if (fastcmp(field,"spheres")) lua_pushinteger(L, plr->spheres); + else if (fastcmp(field,"spheredigestion")) + lua_pushinteger(L, plr->spheredigestion); else if (fastcmp(field,"pflags")) lua_pushinteger(L, plr->pflags); else if (fastcmp(field,"panim")) @@ -714,6 +716,8 @@ static int player_set(lua_State *L) plr->karmadelay = luaL_checkinteger(L, 3); else if (fastcmp(field,"spheres")) plr->spheres = luaL_checkinteger(L, 3); + else if (fastcmp(field,"spheredigestion")) + plr->spheredigestion = luaL_checkinteger(L, 3); else if (fastcmp(field,"kartspeed")) plr->kartspeed = luaL_checkinteger(L, 3); else if (fastcmp(field,"kartweight")) diff --git a/src/p_saveg.c b/src/p_saveg.c index 0561d365a..5852b3695 100644 --- a/src/p_saveg.c +++ b/src/p_saveg.c @@ -333,6 +333,7 @@ static void P_NetArchivePlayers(void) WRITEINT16(save_p, players[i].karmadelay); WRITEUINT32(save_p, players[i].overtimekarma); WRITEINT16(save_p, players[i].spheres); + WRITEINT16(save_p, players[i].spheredigestion); WRITESINT8(save_p, players[i].glanceDir); WRITEUINT8(save_p, players[i].tripWireState); @@ -597,6 +598,7 @@ static void P_NetUnArchivePlayers(void) players[i].karmadelay = READINT16(save_p); players[i].overtimekarma = READUINT32(save_p); players[i].spheres = READINT16(save_p); + players[i].spheredigestion = READINT16(save_p); players[i].glanceDir = READSINT8(save_p); players[i].tripWireState = READUINT8(save_p);