From 7a91fda437d9408ec29d4d877d2796baa0b01c89 Mon Sep 17 00:00:00 2001 From: Marco Hladik Date: Thu, 16 Dec 2021 17:21:21 -0800 Subject: [PATCH] Client: Include ammo notify routines. --- src/client/hud_ammonotify.qc | 85 ++++++++++++++++++++++++++++++++++++ src/client/progs.src | 1 + src/shared/player.qc | 2 + 3 files changed, 88 insertions(+) create mode 100644 src/client/hud_ammonotify.qc diff --git a/src/client/hud_ammonotify.qc b/src/client/hud_ammonotify.qc new file mode 100644 index 0000000..8871d8e --- /dev/null +++ b/src/client/hud_ammonotify.qc @@ -0,0 +1,85 @@ + + +#define AMMO_COUNT 4 + +string g_ammo_spr; + +typedef struct +{ + float alpha; + int count; +} ammonote_t; +ammonote_t g_ammonotify[AMMO_COUNT]; + +vector g_ammotype[AMMO_COUNT] = { + [120/256, 72/128], // rockets (valve's rocket) + [0/256, 72/128], // nails (valve's pistol) + [0/256, 96/128], // cells (valve's uranium) + [72/256, 72/128], // shells +}; + +void +HUD_AmmoNotify_Init(void) +{ + g_ammo_spr = spriteframe("sprites/640hud7.spr", 0, 0.0f); +} + +void +HUD_AmmoNotify_Draw(vector startpos) +{ + vector pos = startpos; + + for (int i = 0; i < AMMO_COUNT; i++) { + vector srcpos; + float a; + + /* make sure we skip any faded entries, and also null them */ + if (g_ammonotify[i].alpha <= 0.0f) { + g_ammonotify[i].count = 0; + continue; + } + + /* let's get the src img pos for our type */ + srcpos = g_ammotype[i]; + a = bound(0, g_ammonotify[i].alpha, 1.0); + + drawsubpic(pos, + [24,24], + g_ammo_spr, + srcpos, + [24/256, 24/128], + g_hud_color, + a, + DRAWFLAG_ADDITIVE + ); + + drawfont = Font_GetID(FONT_20); + string txt = sprintf("%i", g_ammonotify[i].count); + float offs = stringwidth(txt, FALSE, [20,20]); + drawstring(pos + [-offs - 8,4], sprintf("%i", g_ammonotify[i].count), [20,20], g_hud_color, a, DRAWFLAG_ADDITIVE); + + g_ammonotify[i].alpha -= (clframetime * 0.5); + pos -= [0, 32]; /* go up a notch */ + } +} + +void +HUD_AmmoNotify_Insert(int type, int count) +{ + if (count <= 0) + return; + + g_ammonotify[type].count += count; + g_ammonotify[type].alpha = 2.5f; + +} + +/* called whenever we should check for pickup updates */ +void +HUD_AmmoNotify_Check(player pl) +{ + HUD_AmmoNotify_Insert(0, pl.m_iAmmoRockets - pl.m_iAmmoRockets_net); + HUD_AmmoNotify_Insert(1, pl.m_iAmmoNails - pl.m_iAmmoNails_net); + HUD_AmmoNotify_Insert(2, pl.m_iAmmoCells - pl.m_iAmmoCells_net); + HUD_AmmoNotify_Insert(3, pl.m_iAmmoShells - pl.m_iAmmoShells_net); +} \ No newline at end of file diff --git a/src/client/progs.src b/src/client/progs.src index a4b68a1..7acbb3f 100644 --- a/src/client/progs.src +++ b/src/client/progs.src @@ -31,6 +31,7 @@ entities.qc ../../../valve/src/client/viewmodel.qc ../../../valve/src/client/view.qc ../../../valve/src/client/obituary.qc +hud_ammonotify.qc ../../../valve/src/client/hud.qc ../../../valve/src/client/hud_weaponselect.qc ../../../valve/src/client/scoreboard.qc diff --git a/src/shared/player.qc b/src/shared/player.qc index 9307c0a..e553e3b 100644 --- a/src/shared/player.qc +++ b/src/shared/player.qc @@ -98,6 +98,7 @@ class player:base_player #ifdef CLIENT void Weapons_AmmoUpdate(entity); +void HUD_AmmoNotify_Check(player); /* ================= player::ReceiveEntity @@ -143,6 +144,7 @@ player::ReceiveEntity(float new, float fl) Weapons_AmmoUpdate(this); setorigin(this, origin); + HUD_AmmoNotify_Check(this); } /*