Client: Enable the damage/item notifications from Half-Life.

This commit is contained in:
Marco Cawthorne 2021-12-17 18:23:33 -08:00
parent 7a91fda437
commit e501dbe814
Signed by: eukara
GPG key ID: C196CD8BA993248A
5 changed files with 111 additions and 5 deletions

View file

@ -0,0 +1,88 @@
#define ITEM_COUNT 3
string g_item_spr;
typedef struct
{
float alpha;
int count;
} itemnote_t;
itemnote_t g_itemnotify[ITEM_COUNT];
vector g_itemtype[ITEM_COUNT] = {
[176/256, 0/256], // battery
[176/256, 48/256], // medkit
[176/256, 96/256], // longjump
};
void
HUD_ItemNotify_Init(void)
{
g_item_spr = spriteframe("sprites/640hud2.spr", 0, 0.0f);
}
void
HUD_ItemNotify_Draw(__inout vector pos)
{
pos[0] = g_hudmins[0] + g_hudres[0] - 44;
for (int i = 0; i < ITEM_COUNT; i++) {
vector srcpos;
float a;
/* make sure we skip any faded entries, and also null them */
if (g_itemnotify[i].alpha <= 0.0f) {
g_itemnotify[i].count = 0;
continue;
}
/* let's get the src img pos for our type */
srcpos = g_itemtype[i];
a = bound(0, g_itemnotify[i].alpha, 1.0);
/* we'll use the alpha to control the offset so it gently glides down when fading out */
pos -= [0, 52 * a]; /* go up a notch */
drawsubpic(pos + [-20,0],
[44,44],
g_item_spr,
srcpos,
[44/256, 44/256],
g_hud_color,
a,
DRAWFLAG_ADDITIVE
);
if (g_itemnotify[i].count > 1) {
drawfont = Font_GetID(FONT_20);
string txt = sprintf("%i", g_itemnotify[i].count);
float offs = stringwidth(txt, FALSE, [20,20]) + 16;
drawstring(pos + [-offs - 8,12], sprintf("%i", g_itemnotify[i].count), [20,20], g_hud_color, a, DRAWFLAG_ADDITIVE);
}
g_itemnotify[i].alpha -= (clframetime * 0.5);
}
}
void
HUD_ItemNotify_Insert(int type, int count)
{
if (count <= 0)
return;
g_itemnotify[type].count += count;
g_itemnotify[type].alpha = 2.5f;
}
/* called whenever we should check for pickup updates */
void
HUD_ItemNotify_Check(player pl)
{
int healthdiff = bound(0, pl.health - pl.health_net, 100);
int armordiff = bound(0, pl.armor - pl.armor_net, 100);
if (healthdiff > 1)
HUD_ItemNotify_Insert(1, 1);
if (armordiff > 1)
HUD_ItemNotify_Insert(0, 1);
}

View file

@ -31,6 +31,8 @@ entities.qc
../../../valve/src/client/viewmodel.qc ../../../valve/src/client/viewmodel.qc
../../../valve/src/client/view.qc ../../../valve/src/client/view.qc
../../../valve/src/client/obituary.qc ../../../valve/src/client/obituary.qc
../../../valve/src/client/hud_dmgnotify.qc
hud_itemnotify.qc
hud_ammonotify.qc hud_ammonotify.qc
../../../valve/src/client/hud.qc ../../../valve/src/client/hud.qc
../../../valve/src/client/hud_weaponselect.qc ../../../valve/src/client/hud_weaponselect.qc

View file

@ -32,6 +32,7 @@ Game_Worldspawn(void)
precache_model("models/w_weaponbox.mdl"); precache_model("models/w_weaponbox.mdl");
Weapons_Init(); Weapons_Init();
Player_Precache(); Player_Precache();
FX_Corpse_Init();
} }
void weaponbox_spawn(player pl) void weaponbox_spawn(player pl)

View file

@ -15,6 +15,7 @@ player.qc
../../../valve/src/shared/fx_gibhuman.qc ../../../valve/src/shared/fx_gibhuman.qc
../../../base/src/shared/fx_spark.qc ../../../base/src/shared/fx_spark.qc
../../../valve/src/shared/fx_impact.qc ../../../valve/src/shared/fx_impact.qc
../../../base/src/shared/fx_corpse.qc
items.h items.h
weapons.h weapons.h

View file

@ -98,7 +98,8 @@ class player:base_player
#ifdef CLIENT #ifdef CLIENT
void Weapons_AmmoUpdate(entity); void Weapons_AmmoUpdate(entity);
void HUD_AmmoNotify_Check(player); void HUD_AmmoNotify_Check(player pl);
void HUD_ItemNotify_Check(player pl);
/* /*
================= =================
player::ReceiveEntity player::ReceiveEntity
@ -140,13 +141,26 @@ player::ReceiveEntity(float new, float fl)
mode_tempstate = readbyte(); mode_tempstate = readbyte();
} }
if (fl & PLAYER_AMMO1 || fl & PLAYER_AMMO2 || fl & PLAYER_AMMO3)
Weapons_AmmoUpdate(this);
setorigin(this, origin); setorigin(this, origin);
/* these only concern the current player */
CSQC_UpdateSeat();
if (this != pSeat->m_ePlayer)
return;
/* do not notify us of updates when spawning initially */
if (fl == UPDATE_ALL)
PredictPreFrame();
if (fl & PLAYER_AMMO1 || fl & PLAYER_AMMO2 || fl & PLAYER_AMMO3) {
Weapons_AmmoUpdate(this);
HUD_AmmoNotify_Check(this); HUD_AmmoNotify_Check(this);
} }
if (fl & PLAYER_ITEMS || fl & PLAYER_HEALTH || fl & PLAYER_ARMOR)
HUD_ItemNotify_Check(this);
}
/* /*
================= =================
player::PredictPostFrame player::PredictPostFrame