From 6f653da0fcb714ff1d79f35f9e4a14d54b402167 Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Thu, 27 Aug 2020 22:43:47 +1000 Subject: [PATCH] - DBaseStatusBar: Create function `DBaseStatusBar::CalcMagazineAmount()` for use with calculating magazine values when drawing the HUD. --- source/core/statusbar.cpp | 20 +++++++++++++++++++- source/core/statusbar.h | 1 + 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/source/core/statusbar.cpp b/source/core/statusbar.cpp index 381ea6c97..8bd2e2084 100644 --- a/source/core/statusbar.cpp +++ b/source/core/statusbar.cpp @@ -809,8 +809,26 @@ void DBaseStatusBar::PrintAutomapInfo(FLevelStats& stats) DrawText(twod, stats.font, stats.standardColor, 2 * hud_statscale, y, GStrings.localize(volname), DTA_FullscreenScale, FSMode_ScaleToHeight, DTA_VirtualWidth, 320, DTA_VirtualHeight, 200, DTA_ScaleX, scale, DTA_ScaleY, scale, DTA_KeepRatio, true, TAG_DONE); - } + +//============================================================================ +// +// +// +//============================================================================ + +short DBaseStatusBar::CalcMagazineAmount(short ammo_remaining, short clip_capacity, bool reloading) +{ + // Determine amount in clip. + short clip_amount = ammo_remaining % clip_capacity; + + // Set current clip value to clip capacity if wrapped around to zero, otherwise use determined value. + short clip_current = ammo_remaining != 0 && clip_amount == 0 ? clip_capacity : clip_amount; + + // Return current clip value if weapon has rounds or is not on a reload cycle. + return ammo_remaining == 0 || reloading && clip_amount == 0 ? 0 : clip_current; +} + //============================================================================ // // diff --git a/source/core/statusbar.h b/source/core/statusbar.h index ae15ff9a2..650194838 100644 --- a/source/core/statusbar.h +++ b/source/core/statusbar.h @@ -196,6 +196,7 @@ public: return SBarTop; } void DoDrawAutomapHUD(int crdefault, int highlight); + short CalcMagazineAmount(short ammo_remaining, short clip_capacity, bool reloading); //protected: void DrawPowerups ();