Use the new View_AddEvent() function for handling shell ejections

This commit is contained in:
Marco Cawthorne 2021-03-29 21:54:23 +02:00
parent e536f11c74
commit eb543c189d
6 changed files with 111 additions and 37 deletions

View File

@ -40,10 +40,8 @@ struct
entity m_eMuzzleflash;
int m_iVMBones;
/* viewmodel shell ejection */
float m_fEjectModel;
vector m_vecEjectPos;
vector m_vecEjectVel;
void(void) m_pEventCall;
float m_flEventTime;
int m_iLastWeapon;
int m_iOldWeapon;

View File

@ -163,29 +163,6 @@ void
player::ReceiveEntity(float new)
{
float fl;
if (new == FALSE) {
/* Go through all the physics code between the last received frame
* and the newest frame and keep the changes this time around instead
* of rolling back, because we'll apply the new server-verified values
* right after anyway. */
/* FIXME: splitscreen */
if (entnum == player_localentnum) {
/* FIXME: splitscreen */
pSeat = &g_seats[0];
for (int i = sequence+1; i <= servercommandframe; i++) {
/* ...maybe the input state is too old? */
if (!getinputstate(i)) {
break;
}
input_sequence = i;
PMove_Run();
}
/* any differences in things that are read below are now
* officially from prediction misses. */
}
}
/* seed for our prediction table */
sequence = servercommandframe;

View File

@ -47,15 +47,49 @@ enum
GLOCK_HOLSTER
};
#ifdef CLIENT
void w_glock_ejectshell(void)
{
static void w_glock_ejectshell_death(void) {
remove(self);
}
static void w_glock_ejectshell_touch(void) {
if (other == world)
Sound_Play(self, CHAN_BODY, "modelevent_shell.land");
}
entity eShell = spawn();
setmodel(eShell, "models/shell.mdl");
eShell.solid = SOLID_BBOX;
eShell.movetype = MOVETYPE_BOUNCE;
eShell.drawmask = MASK_ENGINE;
eShell.angles = [pSeat->m_eViewModel.angles[0], pSeat->m_eViewModel.angles[1], 0];
eShell.velocity = pSeat->m_vecPredictedVelocity;
makevectors(pSeat->m_eViewModel.angles);
eShell.velocity += (v_forward * 0);
eShell.velocity += (v_right * 80);
eShell.velocity += (v_up * 100);
eShell.touch = w_glock_ejectshell_touch;
eShell.avelocity = [0,45,900];
eShell.think = w_glock_ejectshell_death;
eShell.nextthink = time + 2.5f;
setsize(eShell, [0,0,0], [0,0,0]);
setorigin(eShell, pSeat->m_eViewModel.origin + (v_forward * 26) + (v_right * 8) + (v_up * -4));
}
#endif
void
w_glock_precache(void)
{
#ifdef SERVER
Sound_Precache("weapon_glock.fire");
precache_model("models/w_9mmhandgun.mdl");
precache_model("models/shell.mdl");
#else
precache_model("models/v_9mmhandgun.mdl");
precache_model("models/p_9mmhandgun.mdl");
Sound_Precache("modelevent_shell.land");
#endif
}
@ -138,7 +172,6 @@ w_glock_primary(void)
#ifdef CLIENT
View_SetMuzzleflash(MUZZLE_SMALL);
View_EjectShellPos(SHELL_DEFAULT, [26,8,-32], [0, 80, 100]);
Weapons_ViewPunchAngle([-2,0,0]);
if (pl.glock_mag) {
@ -146,6 +179,7 @@ w_glock_primary(void)
} else {
Weapons_ViewAnimation(GLOCK_SHOOT_EMPTY);
}
View_AddEvent(w_glock_ejectshell, 0.0f);
#else
TraceAttack_FireBullets(1, pl.origin + pl.view_ofs, Skill_GetValue("plr_9mm_bullet", 8), [0.01,0.01], WEAPON_GLOCK);
Sound_Play(pl, CHAN_WEAPON, "weapon_glock.fire");
@ -179,13 +213,14 @@ w_glock_secondary(void)
#ifdef CLIENT
View_SetMuzzleflash(MUZZLE_SMALL);
Weapons_ViewPunchAngle([-2,0,0]);
View_EjectShellPos(SHELL_DEFAULT, [26,8,-32], [0, 80, 100]);
if (pl.glock_mag) {
Weapons_ViewAnimation(GLOCK_SHOOT);
} else {
Weapons_ViewAnimation(GLOCK_SHOOT_EMPTY);
}
View_AddEvent(w_glock_ejectshell, 0.0f);
#else
TraceAttack_FireBullets(1, pl.origin + pl.view_ofs, Skill_GetValue("plr_9mm_bullet", 8), [0.1,0.1], WEAPON_GLOCK);
Sound_Play(pl, CHAN_WEAPON, "weapon_glock.fire");

View File

@ -138,7 +138,6 @@ w_mp5_primary(void)
#ifdef CLIENT
View_SetMuzzleflash(MUZZLE_RIFLE);
View_EjectShellPos(SHELL_DEFAULT, [32,8,-32], [0, 80, 100]);
#else
/* singleplayer is more accurate */
if (cvar("sv_playerslots") == 1) {
@ -162,6 +161,10 @@ w_mp5_primary(void)
Weapons_ViewPunchAngle([-2,0,0]);
#ifdef CLIENT
View_AddEvent(w_glock_ejectshell, 0.0f);
#endif
pl.w_attack_next = 0.1f;
pl.w_idle_next = 10.0f;
}

View File

@ -42,9 +42,42 @@ enum
SHOTTY_IDLE,
SHOTTY_RELOAD_START,
SHOTTY_RELOAD,
SHOTTY_RELOAD_END
SHOTTY_RELOAD_END,
SHOTTY_COCKSOUND
};
#ifdef CLIENT
void w_shotgun_ejectshell(void)
{
static void w_shotgun_ejectshell_death(void) {
remove(self);
}
static void w_shotgun_ejectshell_touch(void) {
if (other == world)
Sound_Play(self, CHAN_BODY, "modelevent_shotgunshell.land");
}
entity eShell = spawn();
setmodel(eShell, "models/shotgunshell.mdl");
eShell.solid = SOLID_BBOX;
eShell.movetype = MOVETYPE_BOUNCE;
eShell.drawmask = MASK_ENGINE;
eShell.angles = [pSeat->m_eViewModel.angles[0], pSeat->m_eViewModel.angles[1], 0];
eShell.velocity = pSeat->m_vecPredictedVelocity;
makevectors(pSeat->m_eViewModel.angles);
eShell.velocity += (v_forward * 0);
eShell.velocity += (v_right * 80);
eShell.velocity += (v_up * 100);
eShell.touch = w_shotgun_ejectshell_touch;
eShell.avelocity = [0,45,900];
eShell.think = w_shotgun_ejectshell_death;
eShell.nextthink = time + 2.5f;
setsize(eShell, [0,0,0], [0,0,0]);
setorigin(eShell, pSeat->m_eViewModel.origin + (v_forward * 26) + (v_right * 8) + (v_up * -8));
}
#endif
void w_shotgun_precache(void)
{
#ifdef SERVER
@ -53,9 +86,11 @@ void w_shotgun_precache(void)
Sound_Precache("weapon_shotgun.reload");
Sound_Precache("weapon_shotgun.cock");
precache_model("models/w_shotgun.mdl");
precache_model("models/shotgunshell.mdl");
#else
precache_model("models/v_shotgun.mdl");
precache_model("models/p_shotgun.mdl");
Sound_Precache("modelevent_shotgunshell.land");
#endif
}
@ -120,11 +155,14 @@ w_shotgun_holster(void)
Weapons_ViewAnimation(SHOTGUN_HOLSTER);
}
void w_shotgun_release(void);
void
w_shotgun_primary(void)
{
player pl = (player)self;
if (pl.w_attack_next) {
w_shotgun_release();
return;
}
@ -149,12 +187,16 @@ w_shotgun_primary(void)
View_SetMuzzleflash(MUZZLE_WEIRD);
Weapons_ViewAnimation(SHOTGUN_FIRE1);
Weapons_ViewPunchAngle([-5,0,0]);
View_AddEvent(w_shotgun_ejectshell, 0.5f);
#endif
pl.shotgun_mag--;
/* after 1/2 a second, play the cocksound and eject shell */
pl.mode_tempstate = SHOTTY_COCKSOUND;
pl.w_idle_next = 0.5f;
pl.w_attack_next = 0.75;
pl.w_idle_next = 2.5f;
}
void
@ -162,6 +204,7 @@ w_shotgun_secondary(void)
{
player pl = (player)self;
if (pl.w_attack_next) {
w_shotgun_release();
return;
}
@ -186,11 +229,14 @@ w_shotgun_secondary(void)
#else
Weapons_ViewAnimation(SHOTGUN_FIRE2);
Weapons_ViewPunchAngle([-10,0,0]);
View_AddEvent(w_shotgun_ejectshell, 1.0f);
#endif
/* after 1 second, play the cocksound and eject shell */
pl.mode_tempstate = SHOTTY_COCKSOUND;
pl.w_idle_next = 1.0f;
pl.shotgun_mag -= 2;
pl.w_attack_next = 1.5f;
pl.w_idle_next = 2.5f;
}
void
@ -264,6 +310,15 @@ w_shotgun_release(void)
Weapons_ViewAnimation(SHOTGUN_PUMP);
#ifdef SERVER
Sound_Play(pl, CHAN_WEAPON, "weapon_shotgun.cock");
#endif
pl.mode_tempstate = SHOTTY_IDLE;
pl.w_idle_next = 10.0f;
pl.w_attack_next = 0.5f;
} else if (pl.mode_tempstate == SHOTTY_COCKSOUND) {
#ifdef CLIENT
#else
Sound_Play(pl, CHAN_AUTO, "weapon_shotgun.cock");
#endif
pl.mode_tempstate = SHOTTY_IDLE;
pl.w_idle_next = 10.0f;

View File

@ -1,11 +1,17 @@
modelevent_shell.eject
{
sample misc/null.wav
}
modelevent_shell.land
{
attenuation idle
sample player/pl_shell1.wav
sample player/pl_shell2.wav
sample player/pl_shell3.wav
}
modelevent_shotgunshell.land
{
attenuation idle
sample weapons/sshell1.wav
sample weapons/sshell2.wav
sample weapons/sshell3.wav
}