From 2e8c4b554539256d97abd24ecd4d5d00595af716 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Wed, 15 Aug 2018 13:38:15 -0400 Subject: [PATCH] Fixed capsule timing logic * Force a total time, stretch out sphere deduction within that time * Make it more readable --- src/p_mobj.c | 9 ++++---- src/p_user.c | 63 ++++++++++++++++++++++++++++++++-------------------- 2 files changed, 43 insertions(+), 29 deletions(-) diff --git a/src/p_mobj.c b/src/p_mobj.c index b5cb5de83..3a2498c07 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -8751,11 +8751,10 @@ mobj_t *P_SpawnMobj(fixed_t x, fixed_t y, fixed_t z, mobjtype_t type) nummaprings = -1; // no perfect bonus, rings are free break; case MT_EGGCAPSULE: - mobj->extravalue1 = -1; // sphere timer for how long a player has been at the capsule - mobj->extravalue2 = -1; // tic timer for how long a player has been at the capsule - mobj->lastlook = -1; - mobj->cusval = -1; - mobj->movecount = -1; + mobj->reactiontime = 0; + mobj->extravalue1 = mobj->cvmem =\ + mobj->cusval = mobj->movecount =\ + mobj->lastlook = mobj->extravalue2 = -1; break; case MT_REDTEAMRING: mobj->color = skincolor_redteam; diff --git a/src/p_user.c b/src/p_user.c index 4219630ef..11d1681ba 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -5925,9 +5925,8 @@ static void P_NightsTransferPoints(player_t *player, fixed_t xspeed, fixed_t rad // static void P_DoNiGHTSCapsule(player_t *player) { - INT32 i; - - player->capsule->extravalue2++; + INT32 i, spherecount, totalduration, popduration, deductinterval, deductquantity, sphereresult, firstpoptic; + INT32 tictimer = ++player->capsule->extravalue2; if (abs(player->mo->x-player->capsule->x) <= 3*FRACUNIT) { @@ -5997,32 +5996,46 @@ static void P_DoNiGHTSCapsule(player_t *player) { if (player->capsule->lastlook < 0) { - INT32 popduration = max(60 - player->capsule->extravalue2, 1); - INT32 spherecount = min(player->spheres, player->capsule->health); - player->capsule->extravalue1 = player->capsule->health - spherecount; - player->capsule->lastlook = max(FixedRound(FixedDiv(spherecount, popduration))/FRACUNIT, 1); - player->capsule->cusval = max(FixedFloor(FixedDiv(popduration, spherecount))/FRACUNIT, 1); - player->capsule->movecount = player->capsule->extravalue2; - player->capsule->cvmem = popduration; + // Stretch the sphere deduction across the capsule time! + // 1. Force the remaining capsule time to `popduration` + // 2. Given `popduration` and `spherecount`, at what tic interval do we deduct spheres? `deductinterval` + // 3. And on each deduction, how many spheres do we deduct? `deductquantity` + // 4. Store the expected capsule health upon completion: `sphereresult` + spherecount = min(player->spheres, player->capsule->health); + totalduration = min(40 + spherecount, 60); + + popduration = player->capsule->extravalue1 = max(totalduration - tictimer, 1); + deductinterval = player->capsule->cvmem = max(FixedFloor(FixedDiv(popduration, spherecount))/FRACUNIT, 1); + deductquantity = player->capsule->cusval = max(FixedRound(FixedDiv(spherecount, popduration))/FRACUNIT, 1); + sphereresult = player->capsule->movecount = player->capsule->health - spherecount; + firstpoptic = player->capsule->lastlook = tictimer; + } + else + { + popduration = player->capsule->extravalue1; + deductinterval = player->capsule->cvmem; + deductquantity = player->capsule->cusval; + sphereresult = player->capsule->movecount; + firstpoptic = player->capsule->lastlook; } - if (player->capsule->extravalue2 - player->capsule->movecount < player->capsule->cvmem) + if (tictimer - firstpoptic < popduration) { - if (!((player->capsule->extravalue2 - player->capsule->movecount) % player->capsule->cusval) - && player->capsule->health > player->capsule->extravalue1) + if (!((tictimer - firstpoptic) % deductinterval) + && player->capsule->health > sphereresult) { - player->spheres -= player->capsule->lastlook; - player->capsule->health -= player->capsule->lastlook; + player->spheres -= deductquantity; + player->capsule->health -= deductquantity; if (player->spheres < 0) player->spheres = 0; - if (player->capsule->health < player->capsule->extravalue1) - player->capsule->health = player->capsule->extravalue1; + if (player->capsule->health < sphereresult) + player->capsule->health = sphereresult; } - // Spawn a 'pop' for every 5 rings you deposit - if (!((player->capsule->extravalue2 - player->capsule->movecount) % 5)) + // Spawn a 'pop' for every 5 tics + if (!((tictimer - firstpoptic) % 5)) S_StartSound(P_SpawnMobj(player->capsule->x + ((P_SignedRandom()/2)<capsule->y + ((P_SignedRandom()/2)<capsule->z + (player->capsule->height/2) + ((P_SignedRandom()/2)<capsule->health > player->capsule->extravalue1) - player->capsule->health = player->capsule->extravalue1; + if (player->capsule->health > sphereresult) + player->capsule->health = sphereresult; if (player->capsule->health <= 0) { player->capsule->flags &= ~MF_NOGRAVITY; player->capsule->momz = 5*FRACUNIT; player->capsule->reactiontime = 0; - player->capsule->extravalue2 = -1; + tictimer = -1; for (i = 0; i < MAXPLAYERS; i++) if (playeringame[i] && !player->exiting && players[i].mare == player->mare) @@ -6124,12 +6137,14 @@ static void P_DoNiGHTSCapsule(player_t *player) player->texttimer = 4*TICRATE; player->textvar = 3; // Get more rings! player->capsule->reactiontime = 0; - player->capsule->extravalue1 = player->capsule->extravalue2 = player->capsule->lastlook = player->capsule->cusval = player->capsule->movecount = -1; + player->capsule->extravalue1 = player->capsule->cvmem =\ + player->capsule->cusval = player->capsule->movecount =\ + player->capsule->lastlook = player->capsule->extravalue2 = -1; } } } else - player->capsule->extravalue1 = -1; + player->capsule->lastlook = -1; } //