Counter-Strike: WEAPON_FLASHBANG now does some fancy calculation for

flashing players.
This commit is contained in:
Marco Cawthorne 2020-04-23 04:33:11 +02:00
parent 8b57b74637
commit f79863d3c1
3 changed files with 46 additions and 13 deletions

View file

@ -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

View file

@ -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);
}

View file

@ -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
}
}