diff --git a/src/client/cstrike/defs.h b/src/client/cstrike/defs.h index cf3de391..2da0bb80 100644 --- a/src/client/cstrike/defs.h +++ b/src/client/cstrike/defs.h @@ -119,6 +119,12 @@ struct int m_iFadeActive; entity m_pWeaponFX; + /* shake */ + float m_flShakeFreq; + float m_flShakeDuration; + float m_flShakeTime; + float m_flShakeAmp; + /* cstrike additions */ float m_iMoneyOld; float m_flMoneyAlpha; diff --git a/src/client/entry.c b/src/client/entry.c index af120bda..da0bfe33 100644 --- a/src/client/entry.c +++ b/src/client/entry.c @@ -292,6 +292,15 @@ CSQC_UpdateView(float w, float h, float focus) setproperty(VF_ORIGIN, pSeat->m_vecCameraOrigin); setproperty(VF_CL_VIEWANGLES, view_angles); } + + if (pSeat->m_flShakeDuration > 0.0) { + vector vecShake = [0,0,0]; + vecShake[0] += random() * 3; + vecShake[1] += random() * 3; + vecShake[2] += random() * 3; + pl.punchangle += (vecShake * pSeat->m_flShakeAmp) * (pSeat->m_flShakeDuration / pSeat->m_flShakeTime); + pSeat->m_flShakeDuration -= clframetime; + } setproperty(VF_ANGLES, view_angles + pl.punchangle); } @@ -585,11 +594,10 @@ CSQC_Parse_Event(void) setproperty(VF_ANGLES, a); break; case EV_SHAKE: - float rad, amp, dur, freq; - rad = readfloat(); - amp = readfloat(); - dur = readfloat(); - freq = readfloat(); + pSeat->m_flShakeFreq = readfloat(); + pSeat->m_flShakeDuration = readfloat(); + pSeat->m_flShakeAmp = readfloat(); + pSeat->m_flShakeTime = pSeat->m_flShakeDuration; default: Game_Parse_Event(fHeader); } diff --git a/src/client/valve/defs.h b/src/client/valve/defs.h index 8e759e8f..c25bda74 100644 --- a/src/client/valve/defs.h +++ b/src/client/valve/defs.h @@ -112,6 +112,12 @@ struct vector m_vecFadeColor; int m_iFadeActive; + /* shake */ + float m_flShakeFreq; + float m_flShakeDuration; + float m_flShakeTime; + float m_flShakeAmp; + entity m_pWeaponFX; } g_seats[4], *pSeat; diff --git a/src/gs-entbase/server/env_shake.cpp b/src/gs-entbase/server/env_shake.cpp index b0c72b7b..a75715ec 100644 --- a/src/gs-entbase/server/env_shake.cpp +++ b/src/gs-entbase/server/env_shake.cpp @@ -47,16 +47,7 @@ class env_shake:CBaseTrigger void env_shake::Trigger(entity act, int state) { - for (entity e = world; (e = find(e, ::classname, "player"));) { - WriteByte(MSG_MULTICAST, SVC_CGAMEPACKET); - WriteByte(MSG_MULTICAST, EV_SHAKE); - WriteFloat(MSG_MULTICAST, m_flRadius); - WriteFloat(MSG_MULTICAST, m_flAmplitude); - WriteFloat(MSG_MULTICAST, m_flDuration); - WriteFloat(MSG_MULTICAST, m_flFrequency); - msg_entity = e; - multicast([0,0,0], MULTICAST_ONE_R); - } + Client_ShakeOnce(origin, m_flRadius, m_flDuration, m_flFrequency, m_flAmplitude); } void diff --git a/src/server/client.c b/src/server/client.c index cda063af..39145797 100644 --- a/src/server/client.c +++ b/src/server/client.c @@ -14,7 +14,8 @@ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -void Client_TriggerCamera(entity target, vector pos, vector end, float wait) +void +Client_TriggerCamera(entity target, vector pos, vector end, float wait) { WriteByte(MSG_MULTICAST, SVC_CGAMEPACKET); WriteByte(MSG_MULTICAST, EV_CAMERATRIGGER); @@ -29,7 +30,8 @@ void Client_TriggerCamera(entity target, vector pos, vector end, float wait) multicast([0,0,0], MULTICAST_ONE); } -void Client_FixAngle(entity target, vector ang) +void +Client_FixAngle(entity target, vector ang) { WriteByte(MSG_MULTICAST, SVC_CGAMEPACKET); WriteByte(MSG_MULTICAST, EV_ANGLE); @@ -40,3 +42,23 @@ void Client_FixAngle(entity target, vector ang) multicast([0,0,0], MULTICAST_ONE); } +void +Client_ShakeOnce(vector pos, float radius, float duration, float frequency, float amplitude) +{ + for (entity pl = world; (pl = find(pl, ::classname, "player"));) { + float amp; + + if (vlen(pos - pl.origin) > radius) + continue; + + amp = 1.0 - (vlen(pos - pl.origin) / radius); + WriteByte(MSG_MULTICAST, SVC_CGAMEPACKET); + WriteByte(MSG_MULTICAST, EV_SHAKE); + WriteFloat(MSG_MULTICAST, duration); + WriteFloat(MSG_MULTICAST, amplitude * amp); + WriteFloat(MSG_MULTICAST, frequency); + + msg_entity = pl; + multicast([0,0,0], MULTICAST_ONE); + } +}; diff --git a/src/server/defs.h b/src/server/defs.h index 9aafd998..90d86fe5 100644 --- a/src/server/defs.h +++ b/src/server/defs.h @@ -47,6 +47,8 @@ void Damage_Radius(vector, entity, float, float, int, int); void Damage_Apply(entity, entity, float, int, int); void Client_TriggerCamera(entity, vector, vector, float); void Client_FixAngle(entity, vector); +void Client_ShakeOnce(vector pos, float radius, float duration, float frequency, float amplitude); + void Game_Input(void); int Rules_IsTeamPlay(void); diff --git a/src/server/valve/monster_alien_grunt.cpp b/src/server/valve/monster_alien_grunt.cpp index 2220c02e..64f7e454 100644 --- a/src/server/valve/monster_alien_grunt.cpp +++ b/src/server/valve/monster_alien_grunt.cpp @@ -143,6 +143,7 @@ monster_alien_grunt::monster_alien_grunt(void) Sound_Precache("monster_alien_grunt.die"); Sound_Precache("monster_alien_grunt.idle"); Sound_Precache("monster_alien_grunt.pain"); + netname = "Alien Grunt"; model = "models/agrunt.mdl"; base_mins = [-32,-32,0]; diff --git a/src/shared/sound.c b/src/shared/sound.c index 7262a28e..82daff3b 100644 --- a/src/shared/sound.c +++ b/src/shared/sound.c @@ -79,7 +79,7 @@ Sound_ParseField(int i, int a) case "shakes": if (a == 2) { dprint("\tShake set\n"); - g_sounds[i].shake = stof(argv(1)); + g_sounds[i].shakes = stof(argv(1)); } break; case "pitch": @@ -342,6 +342,24 @@ Sound_Play(entity target, int chan, string shader) print(sprintf("Sound_Play: %s\n", argv(r))); #endif +#ifdef SERVER + if (g_sounds[sample].shakes > 0.0) { + Client_ShakeOnce(target.origin, 512, 2.5, 1.0, 1.0f); + } +#else + if (g_sounds[sample].shakes > 0.0) { + float srad = 512; + float dist = vlen(pSeat->m_vecPredictedOrigin - target.origin); + if (dist < srad) { + float dif = 1.0 - (dist/srad); + pSeat->m_flShakeFreq = (1.0 * dif) * g_sounds[sample].shakes; + pSeat->m_flShakeAmp = (1.0 * dif) * g_sounds[sample].shakes; + pSeat->m_flShakeDuration = soundlength(argv(r)); + pSeat->m_flShakeTime = pSeat->m_flShakeDuration; + } + } +#endif + sound( target, chan, diff --git a/src/shared/sound.h b/src/shared/sound.h index 9b73e220..0f5f4701 100644 --- a/src/shared/sound.h +++ b/src/shared/sound.h @@ -35,7 +35,7 @@ typedef struct float offset; float pitch_min; float pitch_max; - float shake; + float shakes; float volume; int flags; int playc; diff --git a/src/shared/valve/fx_explosion.c b/src/shared/valve/fx_explosion.c index cc6c2aa5..17df90f6 100755 --- a/src/shared/valve/fx_explosion.c +++ b/src/shared/valve/fx_explosion.c @@ -21,9 +21,7 @@ var int FX_EXPLOSION_BS; void FX_Explosion_Init(void) { - precache_sound("weapons/explode3.wav"); - precache_sound("weapons/explode4.wav"); - precache_sound("weapons/explode5.wav"); + Sound_Precache("fx.explosion"); precache_model("sprites/fexplo.spr"); FX_EXPLOSION_MAIN = particleeffectnum("fx_explosion.main"); FX_EXPLOSION_BS = particleeffectnum("fx_explosion.blacksmoke"); @@ -47,7 +45,7 @@ FX_Explosion(vector vecPos) env_sprite eExplosion = spawn(env_sprite); setorigin(eExplosion, vecPos); setmodel(eExplosion, "sprites/fexplo.spr"); - sound(eExplosion, CHAN_WEAPON, sprintf("weapons/explode%d.wav", floor(random() * 3) + 3), 1, ATTN_NORM); + Sound_Play(eExplosion, CHAN_WEAPON, "fx.explosion"); //eExplosion.think = FX_Explosion_Animate; eExplosion.effects = EF_ADDITIVE; diff --git a/valve/data.pk3dir/sound/fx_valve.sndshd b/valve/data.pk3dir/sound/fx_valve.sndshd new file mode 100644 index 00000000..3e85fe7c --- /dev/null +++ b/valve/data.pk3dir/sound/fx_valve.sndshd @@ -0,0 +1,7 @@ +fx.explosion +{ + sample weapons/explode3.wav + sample weapons/explode4.wav + sample weapons/explode5.wav + shakes 1.5 +}