Implement basic EV_SHAKE event & adding 'shakes' key multiplier to sound

shaders. Client-side sound shaders will get proper shake duration matching
the sound sample length too. Fancy stuff you can try.
This commit is contained in:
Marco Cawthorne 2020-12-12 06:24:48 +01:00
parent f38bf28b9e
commit 74192c2f78
11 changed files with 82 additions and 23 deletions

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -35,7 +35,7 @@ typedef struct
float offset;
float pitch_min;
float pitch_max;
float shake;
float shakes;
float volume;
int flags;
int playc;

View file

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

View file

@ -0,0 +1,7 @@
fx.explosion
{
sample weapons/explode3.wav
sample weapons/explode4.wav
sample weapons/explode5.wav
shakes 1.5
}