From 180829e95c4f18065156655c04cdab79eb25abaf Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Thu, 13 Apr 2017 22:09:03 +0100 Subject: [PATCH] Rewrote first person HUD's drown numbers drawing --- src/st_stuff.c | 92 +++++++++++++++++++++----------------------------- 1 file changed, 39 insertions(+), 53 deletions(-) diff --git a/src/st_stuff.c b/src/st_stuff.c index 4af3199a1..2197b0c3e 100644 --- a/src/st_stuff.c +++ b/src/st_stuff.c @@ -78,12 +78,6 @@ static patch_t *race3; static patch_t *racego; static patch_t *ttlnum; static patch_t *nightslink; -static patch_t *count5; -static patch_t *count4; -static patch_t *count3; -static patch_t *count2; -static patch_t *count1; -static patch_t *count0; static patch_t *curweapon; static patch_t *normring; static patch_t *bouncering; @@ -272,12 +266,6 @@ void ST_LoadGraphics(void) race3 = W_CachePatchName("RACE3", PU_HUDGFX); racego = W_CachePatchName("RACEGO", PU_HUDGFX); nightslink = W_CachePatchName("NGHTLINK", PU_HUDGFX); - count5 = W_CachePatchName("DRWNF0", PU_HUDGFX); - count4 = W_CachePatchName("DRWNE0", PU_HUDGFX); - count3 = W_CachePatchName("DRWND0", PU_HUDGFX); - count2 = W_CachePatchName("DRWNC0", PU_HUDGFX); - count1 = W_CachePatchName("DRWNB0", PU_HUDGFX); - count0 = W_CachePatchName("DRWNA0", PU_HUDGFX); for (i = 0; i < 6; ++i) { @@ -862,50 +850,48 @@ static void ST_drawFirstPersonHUD(void) p = NULL; - // Display the countdown drown numbers! - if ((player->powers[pw_underwater] <= 11*TICRATE + 1 - && player->powers[pw_underwater] >= 10*TICRATE + 1) - || (player->powers[pw_spacetime] <= 11*TICRATE + 1 - && player->powers[pw_spacetime] >= 10*TICRATE + 1)) { - p = count5; - } - else if ((player->powers[pw_underwater] <= 9*TICRATE + 1 - && player->powers[pw_underwater] >= 8*TICRATE + 1) - || (player->powers[pw_spacetime] <= 9*TICRATE + 1 - && player->powers[pw_spacetime] >= 8*TICRATE + 1)) - { - p = count4; - } - else if ((player->powers[pw_underwater] <= 7*TICRATE + 1 - && player->powers[pw_underwater] >= 6*TICRATE + 1) - || (player->powers[pw_spacetime] <= 7*TICRATE + 1 - && player->powers[pw_spacetime] >= 6*TICRATE + 1)) - { - p = count3; - } - else if ((player->powers[pw_underwater] <= 5*TICRATE + 1 - && player->powers[pw_underwater] >= 4*TICRATE + 1) - || (player->powers[pw_spacetime] <= 5*TICRATE + 1 - && player->powers[pw_spacetime] >= 4*TICRATE + 1)) - { - p = count2; - } - else if ((player->powers[pw_underwater] <= 3*TICRATE + 1 - && player->powers[pw_underwater] >= 2*TICRATE + 1) - || (player->powers[pw_spacetime] <= 3*TICRATE + 1 - && player->powers[pw_spacetime] >= 2*TICRATE + 1)) - { - p = count1; - } - else if ((player->powers[pw_underwater] <= 1*TICRATE + 1 - && player->powers[pw_underwater] > 1) - || (player->powers[pw_spacetime] <= 1*TICRATE + 1 - && player->powers[pw_spacetime] > 1)) - { - p = count0; + UINT32 airtime; + UINT32 frame = 0; + spriteframe_t *sprframe; + // If both air timers are active, use the air timer with the least time left + if (player->powers[pw_underwater] && player->powers[pw_spacetime]) + airtime = min(player->powers[pw_underwater], player->powers[pw_spacetime]); + else // Use whichever one is active otherwise + airtime = (player->powers[pw_spacetime]) ? player->powers[pw_spacetime] : player->powers[pw_underwater]; + + if (!airtime) + return; // No air timers are active, nothing would be drawn anyway + + airtime -= 1; // The original code was all n*TICRATE + 1, so let's remove 1 tic for simplicity + + if (airtime > 11*TICRATE) + return; // Not time to draw any drown numbers yet + // Choose which frame to use based on time left + if (airtime <= 11*TICRATE && airtime >= 10*TICRATE) + frame = 5; + else if (airtime <= 9*TICRATE && airtime >= 8*TICRATE) + frame = 4; + else if (airtime <= 7*TICRATE && airtime >= 6*TICRATE) + frame = 3; + else if (airtime <= 5*TICRATE && airtime >= 4*TICRATE) + frame = 2; + else if (airtime <= 3*TICRATE && airtime >= 2*TICRATE) + frame = 1; + else if (airtime <= 1*TICRATE && airtime > 0) + frame = 0; + else + return; // Don't draw anything between numbers + + if (player->charflags & SF_MACHINE) + frame += 6; // Robots use different drown numbers + + // Get the front angle patch for the frame + sprframe = &sprites[SPR_DRWN].spriteframes[frame]; + p = W_CachePatchNum(sprframe->lumppat[0], PU_CACHE); } + // Display the countdown drown numbers! if (p) V_DrawScaledPatch(SCX((BASEVIDWIDTH/2) - (SHORT(p->width)/2) + SHORT(p->leftoffset)), SCY(60 - SHORT(p->topoffset)), V_NOSCALESTART|V_OFFSET|V_TRANSLUCENT, p);