Move the damage indicator drawing/caching code into the client module

here from Nuclide-SDK.
This commit is contained in:
Marco Cawthorne 2021-10-21 23:32:01 +02:00
parent 954867b435
commit 44a90e3bcf
Signed by: eukara
GPG key ID: C196CD8BA993248A
4 changed files with 73 additions and 1 deletions

View file

@ -36,7 +36,17 @@ you need to make sure to add `-game valve` before `-game modname`.
The order is important.
## Community
Join us on #freecs via irc.libera.chat and talk/lurk!
### Matrix
If you're a fellow Matrix user, join the Nuclide Space to see live-updates and more!
https://matrix.to/#/#nuclide:matrix.org
### IRC
Join us on #freecs via irc.libera.chat and talk/lurk or discuss bugs, issues
and other such things. It's bridged with the Matrix room of the same name!
### Others
We've had people ask in the oddest of places for help, please don't do that.
## License
ISC License

59
src/client/damage.qc Normal file
View file

@ -0,0 +1,59 @@
var string g_damage_spr_t;
var string g_damage_spr_b;
var string g_damage_spr_l;
var string g_damage_spr_r;
void
Damage_Precache(void)
{
g_damage_spr_t = spriteframe("sprites/640_pain.spr", 0, 0.0f);
g_damage_spr_r = spriteframe("sprites/640_pain.spr", 1, 0.0f);
g_damage_spr_b = spriteframe("sprites/640_pain.spr", 2, 0.0f);
g_damage_spr_l = spriteframe("sprites/640_pain.spr", 3, 0.0f);
}
void
Damage_Draw(void)
{
vector center;
vector rel_pos;
float fw, fw_alpha;
float rt, rt_alpha;
if (pSeat->m_flDamageAlpha <= 0.0) {
return;
}
center = video_mins + (video_res / 2);
/* the pos relative to the player + view_dir determines which
* and how bright each indicator is drawn. so first get the relative
* position between us and the attacker, then calculate the strength
* of each direction based on a dotproduct tested against our
* camera direction.
*/
rel_pos = normalize(pSeat->m_vecDamagePos - getproperty(VF_ORIGIN));
makevectors(getproperty(VF_CL_VIEWANGLES));
fw = dotproduct(rel_pos, v_forward);
rt = dotproduct(rel_pos, v_right);
fw_alpha = fabs(fw) * pSeat->m_flDamageAlpha;
if (fw > 0.25f) {
drawpic(center + [-64,-102], g_damage_spr_t,
[128,48], [1,1,1], fw_alpha, DRAWFLAG_ADDITIVE);
} else if (fw < -0.25f) {
drawpic(center + [-64,70], g_damage_spr_b,
[128,48], [1,1,1], fw_alpha, DRAWFLAG_ADDITIVE);
}
rt_alpha = fabs(rt) * pSeat->m_flDamageAlpha;
if (rt > 0.25f) {
drawpic(center + [70,-64], g_damage_spr_r,
[48,128], [1,1,1], rt_alpha, DRAWFLAG_ADDITIVE);
} else if (rt < -0.25f) {
drawpic(center + [-102,-64], g_damage_spr_l,
[48,128], [1,1,1], rt_alpha, DRAWFLAG_ADDITIVE);
}
pSeat->m_flDamageAlpha -= clframetime;
}

View file

@ -43,6 +43,7 @@ ClientGame_RendererRestart(string rstr)
MUZZLE_SMALL = (int)getmodelindex("sprites/muzzleflash2.spr");
MUZZLE_WEIRD = (int)getmodelindex("sprites/muzzleflash3.spr");
Damage_Precache();
Obituary_Precache();
FX_Blood_Init();

2
src/client/progs.src Executable file → Normal file
View file

@ -20,6 +20,8 @@ defs.h
../shared/include.src
../../../base/src/client/draw.qc
damage.qc
init.qc
flashlight.qc
player.qc