From f79863d3c1468dd6bfaa87088f53f9c9d0ba5ef5 Mon Sep 17 00:00:00 2001 From: Marco Hladik Date: Thu, 23 Apr 2020 04:33:11 +0200 Subject: [PATCH] Counter-Strike: WEAPON_FLASHBANG now does some fancy calculation for flashing players. --- src/shared/cstrike/fx_flashbang.c | 44 +++++++++++++++++++++++++++---- src/shared/cstrike/w_flashbang.c | 1 + src/shared/valve/fx_blood.c | 14 +++++----- 3 files changed, 46 insertions(+), 13 deletions(-) diff --git a/src/shared/cstrike/fx_flashbang.c b/src/shared/cstrike/fx_flashbang.c index 42e134f5..f747286d 100644 --- a/src/shared/cstrike/fx_flashbang.c +++ b/src/shared/cstrike/fx_flashbang.c @@ -16,11 +16,45 @@ #ifdef SERVER void -FX_Flashbang(entity eTarget) +FX_Flashbang(vector org) { - WriteByte(MSG_MULTICAST, SVC_CGAMEPACKET); - WriteByte(MSG_MULTICAST, EV_FLASH); - msg_entity = eTarget; - multicast([0,0,0], MULTICAST_ONE); + for (entity e = world; (e = find(e, ::classname, "player"));) { + float fov_dot; + vector val; + float blindness; + float fade; + + /* wall check */ + traceline(e.origin + e.view_ofs, org, FALSE, e); + if (trace_fraction < 1.0f) + continue; + + /* calculate the fov in dotproduct form */ + makevectors(e.v_angle); + val = normalize(org - (e.origin + e.view_ofs)); + fov_dot = val * v_forward; + + /* it's behind us */ + if (fov_dot < 0) { + blindness = 0.1; + fade = 1.0f; + } else { + blindness = 2 * fov_dot; + fade = 4 * fov_dot; + } + + /* send the blinding env_fade event */ + WriteByte(MSG_MULTICAST, SVC_CGAMEPACKET); + WriteByte(MSG_MULTICAST, EV_FADE); + WriteFloat(MSG_MULTICAST, 1.0f); + WriteFloat(MSG_MULTICAST, 1.0f); + WriteFloat(MSG_MULTICAST, 1.0f); + WriteFloat(MSG_MULTICAST, 1.0f); + WriteFloat(MSG_MULTICAST, blindness); + WriteFloat(MSG_MULTICAST, fade); + WriteByte(MSG_MULTICAST, EVF_FADEDROM); + msg_entity = e; + multicast('0 0 0', MULTICAST_ONE_R); + } } #endif diff --git a/src/shared/cstrike/w_flashbang.c b/src/shared/cstrike/w_flashbang.c index 1a91953d..16b2db6a 100644 --- a/src/shared/cstrike/w_flashbang.c +++ b/src/shared/cstrike/w_flashbang.c @@ -101,6 +101,7 @@ void w_flashbang_throw(void) { static void flashbang_explode(void) { + FX_Flashbang(self.origin); Sound_Play(self, CHAN_BODY, "weapon_flashbang.explode"); remove(self); } diff --git a/src/shared/valve/fx_blood.c b/src/shared/valve/fx_blood.c index 92fd9e5f..446a01c6 100644 --- a/src/shared/valve/fx_blood.c +++ b/src/shared/valve/fx_blood.c @@ -32,11 +32,11 @@ FX_Blood(vector pos, vector color) #ifdef SERVER WriteByte(MSG_MULTICAST, SVC_CGAMEPACKET); WriteByte(MSG_MULTICAST, EV_BLOOD); - WriteCoord(MSG_MULTICAST, pos[0]); - WriteCoord(MSG_MULTICAST, pos[1]); + WriteCoord(MSG_MULTICAST, pos[0]); + WriteCoord(MSG_MULTICAST, pos[1]); WriteCoord(MSG_MULTICAST, pos[2]); - WriteByte(MSG_MULTICAST, color[0] * 255); - WriteByte(MSG_MULTICAST, color[1] * 255); + WriteByte(MSG_MULTICAST, color[0] * 255); + WriteByte(MSG_MULTICAST, color[1] * 255); WriteByte(MSG_MULTICAST, color[2] * 255); msg_entity = self; multicast(pos, MULTICAST_PVS); @@ -51,8 +51,6 @@ FX_Blood(vector pos, vector color) setorigin(eBlood, pos); setmodel(eBlood, "sprites/bloodspray.spr"); - //eExplosion.think = FX_Explosion_Animate; - //eBlood.effects = EF_ADDITIVE; eBlood.drawmask = MASK_ENGINE; eBlood.maxframe = modelframecount(eBlood.modelindex); eBlood.loops = 0; @@ -60,7 +58,7 @@ FX_Blood(vector pos, vector color) eBlood.colormod = color; eBlood.framerate = 20; eBlood.nextthink = time + 0.05f; - + for (int i = 0; i < 3; i++) { env_sprite ePart = spawn(env_sprite); setorigin(ePart, pos); @@ -80,4 +78,4 @@ FX_Blood(vector pos, vector color) setsize(ePart, [0,0,0], [0,0,0]); } #endif -} +}