diff --git a/.gitignore b/.gitignore index 3d541782cc..590e093b19 100644 --- a/.gitignore +++ b/.gitignore @@ -49,6 +49,9 @@ out # Match session restore file /game/neo/scripts/match_session_restore_point.txt +# Reload phases copied from neoAssets +/game/neo/scripts/weapon_*_reload_phases.txt + # Shader state debug image dumps /game/neo/*.tga diff --git a/game/neo/scripts/game_sounds_weapons.txt b/game/neo/scripts/game_sounds_weapons.txt index ad9ac75c4f..ecd4285a92 100644 --- a/game/neo/scripts/game_sounds_weapons.txt +++ b/game/neo/scripts/game_sounds_weapons.txt @@ -193,6 +193,44 @@ "wave" "weapons/aa13/aa13_reload.wav" } +// AA13 reload in per-step pieces (sv_neo_reload_experimental). + +"weapon_aa13.reload_unload" +{ + "channel" "CHAN_ITEM" + "soundlevel" "SNDLVL_NORM" + "volume" "1.0" + "pitch" "PITCH_NORM" + "wave" ")weapons/aa13/aa13_reload_unload.wav" +} + +"weapon_aa13.reload_unload_part2" +{ + "channel" "CHAN_ITEM" + "soundlevel" "SNDLVL_NORM" + "volume" "1.0" + "pitch" "PITCH_NORM" + "wave" ")weapons/aa13/aa13_reload_unload_part2.wav" +} + +"weapon_aa13.reload_load" +{ + "channel" "CHAN_ITEM" + "soundlevel" "SNDLVL_NORM" + "volume" "1.0" + "pitch" "PITCH_NORM" + "wave" ")weapons/aa13/aa13_reload_load.wav" +} + +"weapon_aa13.reload_cycle" +{ + "channel" "CHAN_ITEM" + "soundlevel" "SNDLVL_NORM" + "volume" "1.0" + "pitch" "PITCH_NORM" + "wave" ")weapons/aa13/aa13_reload_cycle.wav" +} + //------------------ "weapon_aa13.npc_reload" @@ -343,6 +381,35 @@ "wave" "weapons/mpn45/mpn45_reload.wav" } +// MPN45 reload in per-step pieces (sv_neo_reload_experimental). + +"weapon_mpn45.reload_unload" +{ + "channel" "CHAN_ITEM" + "soundlevel" "SNDLVL_NORM" + "volume" "1.0" + "pitch" "PITCH_NORM" + "wave" ")weapons/mpn45/mpn45_reload_unload.wav" +} + +"weapon_mpn45.reload_load" +{ + "channel" "CHAN_ITEM" + "soundlevel" "SNDLVL_NORM" + "volume" "1.0" + "pitch" "PITCH_NORM" + "wave" ")weapons/mpn45/mpn45_reload_load.wav" +} + +"weapon_mpn45.reload_cycle" +{ + "channel" "CHAN_ITEM" + "soundlevel" "SNDLVL_NORM" + "volume" "1.0" + "pitch" "PITCH_NORM" + "wave" ")weapons/mpn45/mpn45_reload_cycle.wav" +} + //------------------- "weapon_mpn45.npc_reload" @@ -417,6 +484,35 @@ "wave" "weapons/srm/srm_reload.wav" } +// SRM reload in per-step pieces (sv_neo_reload_experimental). + +"weapon_srm.reload_unload" +{ + "channel" "CHAN_ITEM" + "soundlevel" "SNDLVL_NORM" + "volume" "1.0" + "pitch" "PITCH_NORM" + "wave" ")weapons/srm/srm_reload_unload.wav" +} + +"weapon_srm.reload_load" +{ + "channel" "CHAN_ITEM" + "soundlevel" "SNDLVL_NORM" + "volume" "1.0" + "pitch" "PITCH_NORM" + "wave" ")weapons/srm/srm_reload_load.wav" +} + +"weapon_srm.reload_cycle" +{ + "channel" "CHAN_ITEM" + "soundlevel" "SNDLVL_NORM" + "volume" "1.0" + "pitch" "PITCH_NORM" + "wave" ")weapons/srm/srm_reload_cycle.wav" +} + //------------------- "weapon_srm.npc_reload" @@ -502,6 +598,35 @@ "wave" "weapons/jitte/jitte_reload.wav" } +// Jitte reload in per-step pieces (sv_neo_reload_experimental). + +"weapon_jitte.reload_unload" +{ + "channel" "CHAN_ITEM" + "soundlevel" "SNDLVL_NORM" + "volume" "1.0" + "pitch" "PITCH_NORM" + "wave" ")weapons/jitte/jitte_reload_unload.wav" +} + +"weapon_jitte.reload_load" +{ + "channel" "CHAN_ITEM" + "soundlevel" "SNDLVL_NORM" + "volume" "1.0" + "pitch" "PITCH_NORM" + "wave" ")weapons/jitte/jitte_reload_load.wav" +} + +"weapon_jitte.reload_cycle" +{ + "channel" "CHAN_ITEM" + "soundlevel" "SNDLVL_NORM" + "volume" "1.0" + "pitch" "PITCH_NORM" + "wave" ")weapons/jitte/jitte_reload_cycle.wav" +} + //------------------- "weapon_jitte.npc_reload" @@ -586,6 +711,44 @@ "wave" "weapons/m41/m41_reload.wav" } +// M41 reload in per-step pieces (sv_neo_reload_experimental). + +"weapon_m41.reload_unload" +{ + "channel" "CHAN_ITEM" + "soundlevel" "SNDLVL_NORM" + "volume" "1.0" + "pitch" "PITCH_NORM" + "wave" ")weapons/m41/m41_reload_unload.wav" +} + +"weapon_m41.reload_load" +{ + "channel" "CHAN_ITEM" + "soundlevel" "SNDLVL_NORM" + "volume" "1.0" + "pitch" "PITCH_NORM" + "wave" ")weapons/m41/m41_reload_load.wav" +} + +"weapon_m41.reload_load_part2" +{ + "channel" "CHAN_ITEM" + "soundlevel" "SNDLVL_NORM" + "volume" "1.0" + "pitch" "PITCH_NORM" + "wave" ")weapons/m41/m41_reload_load_part2.wav" +} + +"weapon_m41.reload_cycle" +{ + "channel" "CHAN_ITEM" + "soundlevel" "SNDLVL_NORM" + "volume" "1.0" + "pitch" "PITCH_NORM" + "wave" ")weapons/m41/m41_reload_cycle.wav" +} + //------------------- "weapon_m41.npc_reload" @@ -677,6 +840,35 @@ "wave" "weapons/srs/srs_reload.wav" } +// SRS reload in per-step pieces (sv_neo_reload_experimental). + +"weapon_srs.reload_unload" +{ + "channel" "CHAN_ITEM" + "soundlevel" "SNDLVL_NORM" + "volume" "1.0" + "pitch" "PITCH_NORM" + "wave" ")weapons/srs/srs_reload_unload.wav" +} + +"weapon_srs.reload_load" +{ + "channel" "CHAN_ITEM" + "soundlevel" "SNDLVL_NORM" + "volume" "1.0" + "pitch" "PITCH_NORM" + "wave" ")weapons/srs/srs_reload_load.wav" +} + +"weapon_srs.reload_cycle" +{ + "channel" "CHAN_ITEM" + "soundlevel" "SNDLVL_NORM" + "volume" "1.0" + "pitch" "PITCH_NORM" + "wave" ")weapons/srs/srs_reload_cycle.wav" +} + //------------------- "weapon_srs.npc_reload" @@ -759,6 +951,83 @@ "wave" "weapons/zr68/zr68_reload.wav" } +// ZR68 reload in per-step pieces (sv_neo_reload_experimental), named reload_; a step's later sounds add _part2, _part3. +// Each file starts just before its first transient + +"weapon_zr68.reload_unload" +{ + "channel" "CHAN_ITEM" + "soundlevel" "SNDLVL_NORM" + "volume" "1.0" + "pitch" "PITCH_NORM" + "wave" ")weapons/zr68/zr68_reload_unload.wav" +} + +"weapon_zr68.reload_load" +{ + "channel" "CHAN_ITEM" + "soundlevel" "SNDLVL_NORM" + "volume" "1.0" + "pitch" "PITCH_NORM" + "wave" ")weapons/zr68/zr68_reload_load.wav" +} + +"weapon_zr68.reload_load_part2" +{ + "channel" "CHAN_ITEM" + "soundlevel" "SNDLVL_NORM" + "volume" "1.0" + "pitch" "PITCH_NORM" + "wave" ")weapons/zr68/zr68_reload_load_part2.wav" +} + +"weapon_zr68.reload_cycle" +{ + "channel" "CHAN_ITEM" + "soundlevel" "SNDLVL_NORM" + "volume" "1.0" + "pitch" "PITCH_NORM" + "wave" ")weapons/zr68/zr68_reload_cycle.wav" +} + +// ZR68L reload in per-step pieces (sv_neo_reload_experimental). + +"weapon_zr68l.reload_unload" +{ + "channel" "CHAN_ITEM" + "soundlevel" "SNDLVL_NORM" + "volume" "1.0" + "pitch" "PITCH_NORM" + "wave" ")weapons/zr68l/zr68l_reload_unload.wav" +} + +"weapon_zr68l.reload_load" +{ + "channel" "CHAN_ITEM" + "soundlevel" "SNDLVL_NORM" + "volume" "1.0" + "pitch" "PITCH_NORM" + "wave" ")weapons/zr68l/zr68l_reload_load.wav" +} + +"weapon_zr68l.reload_load_part2" +{ + "channel" "CHAN_ITEM" + "soundlevel" "SNDLVL_NORM" + "volume" "1.0" + "pitch" "PITCH_NORM" + "wave" ")weapons/zr68l/zr68l_reload_load_part2.wav" +} + +"weapon_zr68l.reload_cycle" +{ + "channel" "CHAN_ITEM" + "soundlevel" "SNDLVL_NORM" + "volume" "1.0" + "pitch" "PITCH_NORM" + "wave" ")weapons/zr68l/zr68l_reload_cycle.wav" +} + //------------------- "weapon_zr68.npc_reload" @@ -892,6 +1161,35 @@ "wave" "weapons/mx/mx_reload.wav" } +// MX reload in per-step pieces (sv_neo_reload_experimental). + +"weapon_mx.reload_unload" +{ + "channel" "CHAN_ITEM" + "soundlevel" "SNDLVL_NORM" + "volume" "1.0" + "pitch" "PITCH_NORM" + "wave" ")weapons/mx/mx_reload_unload.wav" +} + +"weapon_mx.reload_load" +{ + "channel" "CHAN_ITEM" + "soundlevel" "SNDLVL_NORM" + "volume" "1.0" + "pitch" "PITCH_NORM" + "wave" ")weapons/mx/mx_reload_load.wav" +} + +"weapon_mx.reload_cycle" +{ + "channel" "CHAN_ITEM" + "soundlevel" "SNDLVL_NORM" + "volume" "1.0" + "pitch" "PITCH_NORM" + "wave" ")weapons/mx/mx_reload_cycle.wav" +} + //------------------- "weapon_mx.npc_reload" @@ -975,6 +1273,62 @@ "wave" "weapons/pz/pz_reload.wav" } +// PZ252 reload in per-step pieces (sv_neo_reload_experimental). + +"weapon_pz.reload_unload" +{ + "channel" "CHAN_ITEM" + "soundlevel" "SNDLVL_NORM" + "volume" "1.0" + "pitch" "PITCH_NORM" + "wave" ")weapons/pz/pz_reload_unload.wav" +} + +"weapon_pz.reload_unload_part2" +{ + "channel" "CHAN_ITEM" + "soundlevel" "SNDLVL_NORM" + "volume" "1.0" + "pitch" "PITCH_NORM" + "wave" ")weapons/pz/pz_reload_unload_part2.wav" +} + +"weapon_pz.reload_load" +{ + "channel" "CHAN_ITEM" + "soundlevel" "SNDLVL_NORM" + "volume" "1.0" + "pitch" "PITCH_NORM" + "wave" ")weapons/pz/pz_reload_load.wav" +} + +"weapon_pz.reload_load_part2" +{ + "channel" "CHAN_ITEM" + "soundlevel" "SNDLVL_NORM" + "volume" "1.0" + "pitch" "PITCH_NORM" + "wave" ")weapons/pz/pz_reload_load_part2.wav" +} + +"weapon_pz.reload_load_part3" +{ + "channel" "CHAN_ITEM" + "soundlevel" "SNDLVL_NORM" + "volume" "1.0" + "pitch" "PITCH_NORM" + "wave" ")weapons/pz/pz_reload_load_part3.wav" +} + +"weapon_pz.reload_cycle" +{ + "channel" "CHAN_ITEM" + "soundlevel" "SNDLVL_NORM" + "volume" "1.0" + "pitch" "PITCH_NORM" + "wave" ")weapons/pz/pz_reload_cycle.wav" +} + //------------------- "weapon_pz.npc_reload" diff --git a/game/neo/scripts/weapon_aa13.txt b/game/neo/scripts/weapon_aa13.txt index ab2ba7f116..7c688cf38c 100644 --- a/game/neo/scripts/weapon_aa13.txt +++ b/game/neo/scripts/weapon_aa13.txt @@ -1,3 +1,5 @@ +#base "weapon_aa13_reload_phases.txt" + //AA13 WeaponData @@ -8,6 +10,11 @@ WeaponData "CycleTime" "0.333" "ReloadReadyBeforeEnd" "0.395" // the reload is done at the last reload click, this long before its animation ends // the charging handle is home 0.333 before the end, the alternative value + + // Reload phases (sv_neo_reload_experimental): the rows come from neoAssets, timed from its Blender markers + "ReloadPhases" {} + // Chamber capacity is gameplay data; the phase timing comes from neoAssets. + "ChamberedRound" "1" // Weapon data is loaded by both the Game and Client DLLs. "printname" "AA13" diff --git a/game/neo/scripts/weapon_jitte.txt b/game/neo/scripts/weapon_jitte.txt index e148f2aecf..7dbb7b5348 100644 --- a/game/neo/scripts/weapon_jitte.txt +++ b/game/neo/scripts/weapon_jitte.txt @@ -1,3 +1,5 @@ +#base "weapon_jitte_reload_phases.txt" + WeaponData { // Weapon data is loaded by both the Game and Client DLLs. @@ -15,6 +17,11 @@ WeaponData "CycleTime" "0.090909" // time between shots "ReloadReadyBeforeEnd" "0.455" // the reload is done at the last reload click, this long before its animation ends // the charging handle is home 0.400 before the end, the alternative value + + // Reload phases (sv_neo_reload_experimental): the rows come from neoAssets, timed from its Blender markers + "ReloadPhases" {} + // Chamber capacity is gameplay data; the phase timing comes from neoAssets. + "ChamberedRound" "1" "TPMuzzleFlashScale" "0.5" diff --git a/game/neo/scripts/weapon_jittescoped.txt b/game/neo/scripts/weapon_jittescoped.txt index 9671a3c8c1..f01c736cce 100644 --- a/game/neo/scripts/weapon_jittescoped.txt +++ b/game/neo/scripts/weapon_jittescoped.txt @@ -1,3 +1,5 @@ +#base "weapon_jittes_reload_phases.txt" + WeaponData { // Weapon data is loaded by both the Game and Client DLLs. @@ -15,6 +17,11 @@ WeaponData "CycleTime" "0.090909" // time between shots "ReloadReadyBeforeEnd" "0.455" // the reload is done at the last reload click, this long before its animation ends // the charging handle is home 0.400 before the end, the alternative value + + // Reload phases (sv_neo_reload_experimental): the rows come from neoAssets, timed from its Blender markers + "ReloadPhases" {} + // Chamber capacity is gameplay data; the phase timing comes from neoAssets. + "ChamberedRound" "1" "TPMuzzleFlashScale" "0.5" diff --git a/game/neo/scripts/weapon_m41.txt b/game/neo/scripts/weapon_m41.txt index b3d02a4cfb..14749a11e2 100644 --- a/game/neo/scripts/weapon_m41.txt +++ b/game/neo/scripts/weapon_m41.txt @@ -1,3 +1,5 @@ +#base "weapon_mosok41_reload_phases.txt" + // M41 WeaponData @@ -16,6 +18,11 @@ WeaponData "Penetration" "32.0" "CycleTime" "0.166666" // time between shots "ReloadReadyBeforeEnd" "0.393" // the reload is done at the last reload click, this long before its animation ends + + // Reload phases (sv_neo_reload_experimental): the rows come from neoAssets, timed from its Blender markers + "ReloadPhases" {} + // Chamber capacity is gameplay data; the phase timing comes from neoAssets. + "ChamberedRound" "1" "TPMuzzleFlashScale" "0.5" diff --git a/game/neo/scripts/weapon_m41l.txt b/game/neo/scripts/weapon_m41l.txt index b98a05166c..e35f62023b 100644 --- a/game/neo/scripts/weapon_m41l.txt +++ b/game/neo/scripts/weapon_m41l.txt @@ -1,3 +1,5 @@ +#base "weapon_mosok41l_reload_phases.txt" + // M41 WeaponData @@ -16,6 +18,11 @@ WeaponData "Penetration" "32.0" "CycleTime" "0.5" // time between shots "ReloadReadyBeforeEnd" "0.333" // the reload is done at the last reload click, this long before its animation ends + + // Reload phases (sv_neo_reload_experimental): the rows come from neoAssets, timed from its Blender markers + "ReloadPhases" {} + // Chamber capacity is gameplay data; the phase timing comes from neoAssets. + "ChamberedRound" "1" "TPMuzzleFlashScale" "0.25" diff --git a/game/neo/scripts/weapon_m41s.txt b/game/neo/scripts/weapon_m41s.txt index a4cb54cf5e..fda1853da6 100644 --- a/game/neo/scripts/weapon_m41s.txt +++ b/game/neo/scripts/weapon_m41s.txt @@ -1,3 +1,5 @@ +#base "weapon_mosok41s_reload_phases.txt" + // M41 WeaponData @@ -16,6 +18,11 @@ WeaponData "Penetration" "20.0" "CycleTime" "0.166666" // time between shots "ReloadReadyBeforeEnd" "0.393" // the reload is done at the last reload click, this long before its animation ends + + // Reload phases (sv_neo_reload_experimental): the rows come from neoAssets, timed from its Blender markers + "ReloadPhases" {} + // Chamber capacity is gameplay data; the phase timing comes from neoAssets. + "ChamberedRound" "1" "TPMuzzleFlashScale" "0.5" diff --git a/game/neo/scripts/weapon_milso.txt b/game/neo/scripts/weapon_milso.txt index 5e220ac1f1..08c12c2f21 100644 --- a/game/neo/scripts/weapon_milso.txt +++ b/game/neo/scripts/weapon_milso.txt @@ -1,3 +1,5 @@ +#base "weapon_milso_reload_phases.txt" + // Milso WeaponData { @@ -14,6 +16,10 @@ WeaponData "Penetration" "12.0" "CycleTime" "0.212121" "ReloadReadyBeforeEnd" "0.467" // the reload is done at the last reload click, this long before its animation ends + // Reload phases (sv_neo_reload_experimental): the rows come from neoAssets, timed from its Blender markers + "ReloadPhases" {} + // Chamber capacity is gameplay data; the phase timing comes from neoAssets. + "ChamberedRound" "1" "TPMuzzleFlashScale" "0.5" diff --git a/game/neo/scripts/weapon_mpn.txt b/game/neo/scripts/weapon_mpn.txt index e61bce9774..6aa9b1490d 100644 --- a/game/neo/scripts/weapon_mpn.txt +++ b/game/neo/scripts/weapon_mpn.txt @@ -1,3 +1,5 @@ +#base "weapon_mpn_s_reload_phases.txt" + WeaponData { // Weapon data is loaded by both the Game and Client DLLs. @@ -15,6 +17,11 @@ WeaponData "CycleTime" "0.075757" // time between shots "ReloadReadyBeforeEnd" "0.500" // the reload is done at the last reload click, this long before its animation ends // the charging handle is home 0.400 before the end, the alternative value + + // Reload phases (sv_neo_reload_experimental): the rows come from neoAssets, timed from its Blender markers + "ReloadPhases" {} + // Chamber capacity is gameplay data; the phase timing comes from neoAssets. + "ChamberedRound" "1" "TPMuzzleFlashScale" "0.5" diff --git a/game/neo/scripts/weapon_mpn_unsilenced.txt b/game/neo/scripts/weapon_mpn_unsilenced.txt index 4cc79578cb..a4ed9f5e68 100644 --- a/game/neo/scripts/weapon_mpn_unsilenced.txt +++ b/game/neo/scripts/weapon_mpn_unsilenced.txt @@ -1,3 +1,5 @@ +#base "weapon_mpn_reload_phases.txt" + WeaponData { // Weapon data is loaded by both the Game and Client DLLs. @@ -15,6 +17,11 @@ WeaponData "CycleTime" "0.075757" // time between shots "ReloadReadyBeforeEnd" "0.500" // the reload is done at the last reload click, this long before its animation ends // the charging handle is home 0.400 before the end, the alternative value + + // Reload phases (sv_neo_reload_experimental): the rows come from neoAssets, timed from its Blender markers + "ReloadPhases" {} + // Chamber capacity is gameplay data; the phase timing comes from neoAssets. + "ChamberedRound" "1" "TPMuzzleFlashScale" "0.5" diff --git a/game/neo/scripts/weapon_mx.txt b/game/neo/scripts/weapon_mx.txt index 953c278462..75efa39c89 100644 --- a/game/neo/scripts/weapon_mx.txt +++ b/game/neo/scripts/weapon_mx.txt @@ -1,3 +1,5 @@ +#base "weapon_mx_reload_phases.txt" + // MX WeaponData @@ -17,6 +19,11 @@ WeaponData "CycleTime" "0.106060" // time between shots "ReloadReadyBeforeEnd" "0.417" // the reload is done at the last reload click, this long before its animation ends + // Reload phases (sv_neo_reload_experimental): the rows come from neoAssets, timed from its Blender markers + "ReloadPhases" {} + // Chamber capacity is gameplay data; the phase timing comes from neoAssets. + "ChamberedRound" "1" + "TPMuzzleFlashScale" "0.3" "clip_size" "30" diff --git a/game/neo/scripts/weapon_mx_silenced.txt b/game/neo/scripts/weapon_mx_silenced.txt index 918e953662..33387ecf06 100644 --- a/game/neo/scripts/weapon_mx_silenced.txt +++ b/game/neo/scripts/weapon_mx_silenced.txt @@ -1,3 +1,5 @@ +#base "weapon_mxs_reload_phases.txt" + WeaponData { // Weapon data is loaded by both the Game and Client DLLs. @@ -15,6 +17,11 @@ WeaponData "CycleTime" "0.106060" // time between shots "ReloadReadyBeforeEnd" "0.427" // the reload is done at the last reload click, this long before its animation ends + // Reload phases (sv_neo_reload_experimental): the rows come from neoAssets, timed from its Blender markers + "ReloadPhases" {} + // Chamber capacity is gameplay data; the phase timing comes from neoAssets. + "ChamberedRound" "1" + "TPMuzzleFlashScale" "0.3" "clip_size" "30" diff --git a/game/neo/scripts/weapon_pz.txt b/game/neo/scripts/weapon_pz.txt index d00b403867..df741ab382 100644 --- a/game/neo/scripts/weapon_pz.txt +++ b/game/neo/scripts/weapon_pz.txt @@ -1,3 +1,5 @@ +#base "weapon_pz_reload_phases.txt" + // ZR68S WeaponData @@ -17,6 +19,11 @@ WeaponData "CycleTime" "0.090909" // time between shots "ReloadReadyBeforeEnd" "0.543" // the reload is done at the last reload click, this long before its animation ends // the charging handle is home 0.400 before the end, the alternative value + + // Reload phases (sv_neo_reload_experimental): the rows come from neoAssets, timed from its Blender markers + "ReloadPhases" {} + // Chamber capacity is gameplay data; the phase timing comes from neoAssets. + "ChamberedRound" "1" "TPMuzzleFlashScale" "0.3" diff --git a/game/neo/scripts/weapon_srm.txt b/game/neo/scripts/weapon_srm.txt index 2d2170338f..08dc084b1a 100644 --- a/game/neo/scripts/weapon_srm.txt +++ b/game/neo/scripts/weapon_srm.txt @@ -1,3 +1,5 @@ +#base "weapon_srm_reload_phases.txt" + WeaponData { // Weapon data is loaded by both the Game and Client DLLs. @@ -15,6 +17,11 @@ WeaponData "CycleTime" "0.060606" // time between shots "ReloadReadyBeforeEnd" "0.233" // the reload is done at the last reload click, this long before its animation ends // the charging handle is home 0.167 before the end, the alternative value + + // Reload phases (sv_neo_reload_experimental): the rows come from neoAssets, timed from its Blender markers + "ReloadPhases" {} + // Chamber capacity is gameplay data; the phase timing comes from neoAssets. + "ChamberedRound" "1" "TPMuzzleFlashScale" "0.5" diff --git a/game/neo/scripts/weapon_srm_s.txt b/game/neo/scripts/weapon_srm_s.txt index e8fb6146d3..a1f6422e20 100644 --- a/game/neo/scripts/weapon_srm_s.txt +++ b/game/neo/scripts/weapon_srm_s.txt @@ -1,3 +1,5 @@ +#base "weapon_srm_s_reload_phases.txt" + WeaponData { // Weapon data is loaded by both the Game and Client DLLs. @@ -15,6 +17,11 @@ WeaponData "CycleTime" "0.090909" // time between shots "ReloadReadyBeforeEnd" "0.233" // the reload is done at the last reload click, this long before its animation ends // the charging handle is home 0.167 before the end, the alternative value + + // Reload phases (sv_neo_reload_experimental): the rows come from neoAssets, timed from its Blender markers + "ReloadPhases" {} + // Chamber capacity is gameplay data; the phase timing comes from neoAssets. + "ChamberedRound" "1" "TPMuzzleFlashScale" "0.5" diff --git a/game/neo/scripts/weapon_srs.txt b/game/neo/scripts/weapon_srs.txt index 3538bca8ef..9a20b07450 100644 --- a/game/neo/scripts/weapon_srs.txt +++ b/game/neo/scripts/weapon_srs.txt @@ -1,3 +1,5 @@ +#base "weapon_srs_reload_phases.txt" + // SRS WeaponData @@ -16,6 +18,11 @@ WeaponData "Penetration" "65.0" "CycleTime" "1.4" "ReloadReadyBeforeEnd" "0.583" // the reload is done at the last reload click, this long before its animation ends + + // Reload phases (sv_neo_reload_experimental): the rows come from neoAssets, timed from its Blender markers + "ReloadPhases" {} + // Chamber capacity is gameplay data; the phase timing comes from neoAssets. + "ChamberedRound" "1" "TPMuzzleFlashScale" "0.25" diff --git a/game/neo/scripts/weapon_tachi.txt b/game/neo/scripts/weapon_tachi.txt index 89d0bf13c1..76387eb5e4 100644 --- a/game/neo/scripts/weapon_tachi.txt +++ b/game/neo/scripts/weapon_tachi.txt @@ -1,3 +1,5 @@ +#base "weapon_tachi_reload_phases.txt" + // Tachi WeaponData @@ -33,6 +35,10 @@ WeaponData "Penetration" "19.0" "CycleTime" "0.121212" "ReloadReadyBeforeEnd" "0.400" // the reload is done at the last reload click, this long before its animation ends + // Reload phases (sv_neo_reload_experimental): the rows come from neoAssets, timed from its Blender markers + "ReloadPhases" {} + // Chamber capacity is gameplay data; the phase timing comes from neoAssets. + "ChamberedRound" "1" "ViewModelOffset" { diff --git a/game/neo/scripts/weapon_zr68c.txt b/game/neo/scripts/weapon_zr68c.txt index 38f426b6d0..cc72e69425 100644 --- a/game/neo/scripts/weapon_zr68c.txt +++ b/game/neo/scripts/weapon_zr68c.txt @@ -1,4 +1,6 @@ -// ZR68S +#base "weapon_zr68c_reload_phases.txt" + +// ZR68C WeaponData { @@ -16,6 +18,11 @@ WeaponData "Penetration" "28.0" "CycleTime" "0.090909" // time between shots "ReloadReadyBeforeEnd" "0.483" // the reload is done at the last reload click, this long before its animation ends + + // Reload phases (sv_neo_reload_experimental): the rows come from neoAssets, timed from its Blender markers + "ReloadPhases" {} + // Chamber capacity is gameplay data; the phase timing comes from neoAssets. + "ChamberedRound" "1" "TPMuzzleFlashScale" "0.5" diff --git a/game/neo/scripts/weapon_zr68l.txt b/game/neo/scripts/weapon_zr68l.txt index 147c324305..7cb3220f00 100644 --- a/game/neo/scripts/weapon_zr68l.txt +++ b/game/neo/scripts/weapon_zr68l.txt @@ -1,3 +1,5 @@ +#base "weapon_zr68l_reload_phases.txt" + // ZR68L WeaponData @@ -16,6 +18,11 @@ WeaponData "Penetration" "32.0" "CycleTime" "0.5" // time between shots "ReloadReadyBeforeEnd" "0.367" // the reload is done at the last reload click, this long before its animation ends + + // Reload phases (sv_neo_reload_experimental): the rows come from neoAssets, timed from its Blender markers + "ReloadPhases" {} + // Chamber capacity is gameplay data; the phase timing comes from neoAssets. + "ChamberedRound" "1" "TPMuzzleFlashScale" "0.5" diff --git a/game/neo/scripts/weapon_zr68s.txt b/game/neo/scripts/weapon_zr68s.txt index 87019630a5..857d84320f 100644 --- a/game/neo/scripts/weapon_zr68s.txt +++ b/game/neo/scripts/weapon_zr68s.txt @@ -1,3 +1,5 @@ +#base "weapon_zr68s_reload_phases.txt" + // ZR68S WeaponData @@ -18,6 +20,11 @@ WeaponData "Penetration" "18.0" "CycleTime" "0.106060" // time between shots "ReloadReadyBeforeEnd" "0.483" // the reload is done at the last reload click, this long before its animation ends + + // Reload phases (sv_neo_reload_experimental): the rows come from neoAssets, timed from its Blender markers + "ReloadPhases" {} + // Chamber capacity is gameplay data; the phase timing comes from neoAssets. + "ChamberedRound" "1" "TPMuzzleFlashScale" "0.5" diff --git a/src/game/client/neo/ui/neo_hud_ammo.cpp b/src/game/client/neo/ui/neo_hud_ammo.cpp index 771efb2554..55d355b076 100644 --- a/src/game/client/neo/ui/neo_hud_ammo.cpp +++ b/src/game/client/neo/ui/neo_hud_ammo.cpp @@ -6,6 +6,9 @@ #include "iclientmode.h" #include #include +#include +#include "VGuiMatSurface/IMatSystemSurface.h" +#include "cdll_client_int.h" #include #include #include @@ -160,16 +163,20 @@ void CNEOHud_Ammo::DrawAmmo() const } const char* ammoChar = nullptr; + int fireModeWidth = 0, fireModeHeight = 0; int magSizeMax = 0; int magSizeCurrent = 0; + // NEO TODO: client tests for the 30+1/30 row and the chamber glyph (fresh, after tactical reload, after drop). + // a gun with a chamber counts the magazine in the row, and the round icon of the fire-mode glyph shows the chamber + const bool hasChamber = activeWep->HasChamberSlot(); if ((activeWep->UsesClipsForAmmo1() && !(activeWep->GetNeoWepBits() & NEO_WEP_THROWABLE)) || (activeWep->GetNeoWepBits() & NEO_WEP_BALC)) { char fireModeText[2]{ '\0' }; ammoChar = activeWep->GetNEOWpnData().szBulletCharacter; - magSizeMax = activeWep->GetMaxClip1(); - magSizeCurrent = activeWep->Clip1(); + magSizeMax = hasChamber ? activeWep->MagazineCapacity() : activeWep->GetMaxClip1(); + magSizeCurrent = hasChamber ? activeWep->RoundsInMagazine() : activeWep->Clip1(); if(activeWep) { @@ -188,8 +195,16 @@ void CNEOHud_Ammo::DrawAmmo() const g_pVGuiLocalize->ConvertANSIToUnicode(fireModeText, unicodeFireModeText, sizeof(unicodeFireModeText)); surface()->DrawSetTextFont(m_hFireModeFont); - surface()->DrawSetTextPos(icon_xpos + xpos, icon_ypos + ypos); - surface()->DrawPrintText(unicodeFireModeText, V_wcslen(unicodeFireModeText)); + if (hasChamber) + { + surface()->GetTextSize(m_hFireModeFont, unicodeFireModeText, fireModeWidth, fireModeHeight); + DrawFireModeWithChamber(unicodeFireModeText, fireModeHeight, activeWep->IsRoundChambered()); + } + else + { + surface()->DrawSetTextPos(icon_xpos + xpos, icon_ypos + ypos); + surface()->DrawPrintText(unicodeFireModeText, V_wcslen(unicodeFireModeText)); + } } } else { @@ -216,8 +231,16 @@ void CNEOHud_Ammo::DrawAmmo() const surface()->DrawSetTextFont(m_hBulletFont); surface()->DrawSetTextPos(digit_xpos + xpos, digit_ypos + ypos); wchar_t bullets[22]; - V_swprintf_safe(bullets, L"%i/%i", magSizeCurrent, magSizeMax); - surface()->DrawPrintText(bullets, (int)(magSizeCurrent == 0 ? 1 : log10(magSizeCurrent) + 1) + (int)(log10(magSizeMax) + 1) + 1); + if (hasChamber && activeWep->IsRoundChambered()) + { + V_swprintf_safe(bullets, L"%i+1/%i", magSizeCurrent, magSizeMax); + surface()->DrawPrintText(bullets, V_wcslen(bullets)); + } + else + { + V_swprintf_safe(bullets, L"%i/%i", magSizeCurrent, magSizeMax); + surface()->DrawPrintText(bullets, (int)(magSizeCurrent == 0 ? 1 : log10(magSizeCurrent) + 1) + (int)(log10(magSizeMax) + 1) + 1); + } return; } @@ -290,6 +313,36 @@ void CNEOHud_Ammo::DrawAmmo() const } } +// The fire-mode glyph's top rows are a round icon (bullet or shell), its letter sits below them +static constexpr float FIRE_MODE_ROUND_ICON_HEIGHT = 0.184f; + +// Draw the fire-mode glyph with its round icon lit while a round is chambered, in the empty color otherwise; +// the letter keeps the text color. Two passes, each clipped to its part of the glyph +void CNEOHud_Ammo::DrawFireModeWithChamber(const wchar_t *pszGlyph, int iGlyphTall, bool bChambered) const +{ + const int iX = icon_xpos + xpos; + const int iY = icon_ypos + ypos; + int iScreenX = 0, iScreenY = 0; + vgui::ipanel()->GetAbsPos(GetVPanel(), iScreenX, iScreenY); + const int iSplitY = iScreenY + iY + static_cast(iGlyphTall * FIRE_MODE_ROUND_ICON_HEIGHT + 0.5f); + + int iLeft, iTop, iRight, iBottom; + bool bClippingDisabled; + g_pMatSystemSurface->GetClippingRect(iLeft, iTop, iRight, iBottom, bClippingDisabled); + + g_pMatSystemSurface->SetClippingRect(iLeft, iTop, iRight, Min(iBottom, iSplitY)); + surface()->DrawSetTextColor(bChambered ? ammo_color : emptied_ammo_color); + surface()->DrawSetTextPos(iX, iY); + surface()->DrawPrintText(pszGlyph, V_wcslen(pszGlyph)); + + g_pMatSystemSurface->SetClippingRect(iLeft, Max(iTop, iSplitY), iRight, iBottom); + surface()->DrawSetTextColor(ammo_text_color); + surface()->DrawSetTextPos(iX, iY); + surface()->DrawPrintText(pszGlyph, V_wcslen(pszGlyph)); + + g_pMatSystemSurface->SetClippingRect(iLeft, iTop, iRight, iBottom); +} + void CNEOHud_Ammo::DrawNeoHudElement() { auto *localPlayer = C_NEO_Player::GetLocalNEOPlayer(); diff --git a/src/game/client/neo/ui/neo_hud_ammo.h b/src/game/client/neo/ui/neo_hud_ammo.h index 069561e11c..637d663457 100644 --- a/src/game/client/neo/ui/neo_hud_ammo.h +++ b/src/game/client/neo/ui/neo_hud_ammo.h @@ -27,6 +27,7 @@ class CNEOHud_Ammo : public CNEOHud_ChildElement, public CHudElement, public vgu private: void DrawAmmo() const; + void DrawFireModeWithChamber(const wchar_t *pszGlyph, int iGlyphTall, bool bChambered) const; void DrawHeatMeter(C_NEOBaseCombatWeapon* activeWep) const; private: diff --git a/src/game/server/neo/bot/neo_bot.cpp b/src/game/server/neo/bot/neo_bot.cpp index 7d1c1e2ef8..8f9036fb00 100644 --- a/src/game/server/neo/bot/neo_bot.cpp +++ b/src/game/server/neo/bot/neo_bot.cpp @@ -1628,6 +1628,13 @@ void CNEOBot::EquipBestWeaponForThreat(const CKnownEntity* threat, const bool bN if (EquipRequiredWeapon()) return; + // A switch would only delay the reload that is about to refill the clip + auto *pActiveWeapon = static_cast(GetActiveWeapon()); + if (pActiveWeapon && pActiveWeapon->IsReloadPastUnload()) + { + return; + } + // ------------------------------------------------------------------------------- CNEOBaseCombatWeapon* primaryWeapon = static_cast(Weapon_GetSlot(0)); @@ -1813,6 +1820,8 @@ void CNEOBot::ReloadIfLowClip(bool bForceReload) return; } + // NEO TODO: with a chamber slot 30 of 31 counts as full here, and 29+1 (clip 30) never reloads by bot + // logic. Accepted for now; revisit the threshold later. if (myWeapon->Clip1() >= myWeapon->GetMaxClip1()) { return; diff --git a/src/game/server/neo/neo_player.cpp b/src/game/server/neo/neo_player.cpp index e09dfbe8b9..6e038c727f 100644 --- a/src/game/server/neo/neo_player.cpp +++ b/src/game/server/neo/neo_player.cpp @@ -2485,6 +2485,8 @@ void CNEO_Player::Weapon_DropOnDeath(CNEOBaseCombatWeapon* pNeoWeapon, Vector da pNeoWeapon->AddEffects(EF_BONEMERGE); } + pNeoWeapon->StopReloadOnDrop(); + Vector playerVelocity = vec3_origin; GetVelocity(&playerVelocity, nullptr); pNeoWeapon->Drop(playerVelocity); @@ -2953,6 +2955,7 @@ void CNEO_Player::Weapon_Drop( CBaseCombatWeapon *pWeapon, return; // Return early to not drop weapon } + neoWeapon->StopReloadOnDrop(); pWeapon->m_bInReload = false; pWeapon->StopWeaponSound(RELOAD_NPC); diff --git a/src/game/shared/hl2mp/hl2mp_playeranimstate.cpp b/src/game/shared/hl2mp/hl2mp_playeranimstate.cpp index 9e441acd87..426777a0c7 100644 --- a/src/game/shared/hl2mp/hl2mp_playeranimstate.cpp +++ b/src/game/shared/hl2mp/hl2mp_playeranimstate.cpp @@ -80,6 +80,11 @@ CHL2MPPlayerAnimState* CreateHL2MPPlayerAnimState( CHL2MP_Player *pPlayer ) CHL2MPPlayerAnimState::CHL2MPPlayerAnimState() { m_pHL2MPPlayer = NULL; +#ifdef NEO + m_iReloadGestureSequence = -1; + m_flReloadGestureStartCycle = 0.0f; + m_flReloadGestureEndCycle = 1.0f; +#endif // Don't initialize HL2MP specific variables here. Init them in InitHL2MPAnimState() } @@ -93,6 +98,11 @@ CHL2MPPlayerAnimState::CHL2MPPlayerAnimState( CBasePlayer *pPlayer, MultiPlayerM : CMultiPlayerAnimState( pPlayer, movementData ) { m_pHL2MPPlayer = NULL; +#ifdef NEO + m_iReloadGestureSequence = -1; + m_flReloadGestureStartCycle = 0.0f; + m_flReloadGestureEndCycle = 1.0f; +#endif // Don't initialize HL2MP specific variables here. Init them in InitHL2MPAnimState() } @@ -182,6 +192,7 @@ void CHL2MPPlayerAnimState::ComputeSequences(CStudioHdr* pStudioHdr) // The groundspeed interpolator uses the main sequence info. UpdateInterpolators(); ComputeGestureSequence(pStudioHdr); + UpdateReloadGesture(); } #endif //NEO @@ -343,6 +354,7 @@ void CHL2MPPlayerAnimState::DoAnimationEvent( PlayerAnimEvent_t event, int nData { #ifdef NEO AddToGestureSlot(GESTURE_SLOT_ATTACK_AND_RELOAD, CalcReloadSequence(), true); + StartReloadGesture(nData); #else // Weapon reload. if ( GetBasePlayer()->GetFlags() & FL_DUCKING ) @@ -1013,3 +1025,115 @@ void CHL2MPPlayerAnimState::DebugShowAnimStateFull(int iStartLine) AnimStateLog("--------------------------------------------\n\n"); } + +#ifdef NEO +// Start a gesture part way through its sequence, as AddVCDSequenceToGestureSlot does for scene gestures +void CHL2MPPlayerAnimState::SetGestureSlotCycle(int iGestureSlot, float flCycle) +{ + GestureSlot_t &slot = m_aGestureSlots[iGestureSlot]; + if (!slot.m_pAnimLayer) + { + return; + } + + slot.m_pAnimLayer->m_flCycle = flCycle; + slot.m_pAnimLayer->m_flPrevCycle = flCycle; +#ifdef CLIENT_DLL + if (CBasePlayer *pPlayer = GetBasePlayer()) + { + pPlayer->m_flOverlayPrevEventCycle[iGestureSlot] = flCycle; + } +#endif +} + +// The reload event's data: the fit in the low bit, the first-person length in ms above it +static constexpr int RELOAD_GESTURE_KEEP_END_BIT = 1; +static constexpr int RELOAD_GESTURE_FIT_BITS = 1; +static constexpr float RELOAD_GESTURE_MS_PER_SECOND = 1000.0f; + +// The player models' reload gestures have no blend of their own, so a gesture started or ended part way +// blends in or out over this long to hide the jump in pose +static constexpr float RELOAD_GESTURE_BLEND_TIME = 0.2f; + +int CHL2MPPlayerAnimState::PackReloadGestureData(ReloadGestureFit_t fit, float flDuration) +{ + const int iMs = static_cast(Max(flDuration, 0.0f) * RELOAD_GESTURE_MS_PER_SECOND); + return (iMs << RELOAD_GESTURE_FIT_BITS) | ((fit == RELOAD_GESTURE_KEEP_END) ? RELOAD_GESTURE_KEEP_END_BIT : 0); +} + +// Fit the reload gesture just added to a shorter first-person reload: play only its start or only its end, for as +// long as that reload lasts. An event without data plays the whole gesture +void CHL2MPPlayerAnimState::StartReloadGesture(int nData) +{ + m_iReloadGestureSequence = -1; + + CBasePlayer *pPlayer = GetBasePlayer(); + const GestureSlot_t &slot = m_aGestureSlots[GESTURE_SLOT_ATTACK_AND_RELOAD]; + if (nData == 0 || !pPlayer || !slot.m_bActive || !slot.m_pAnimLayer) + { + return; + } + + // A reload resumed by the draw starts with the weapon change, which would otherwise clear the gesture + m_hActiveWeapon = pPlayer->GetActiveWeapon(); + + const int iSequence = slot.m_pAnimLayer->m_nSequence; + const float flDuration = (nData >> RELOAD_GESTURE_FIT_BITS) / RELOAD_GESTURE_MS_PER_SECOND; + const float flCycles = flDuration * pPlayer->GetSequenceCycleRate(pPlayer->GetModelPtr(), iSequence); + if (flDuration <= 0.0f || flCycles >= 1.0f) + { + return; + } + + const bool bKeepEnd = (nData & RELOAD_GESTURE_KEEP_END_BIT) != 0; + m_flReloadGestureStartCycle = bKeepEnd ? 1.0f - flCycles : 0.0f; + m_flReloadGestureEndCycle = bKeepEnd ? 1.0f : flCycles; + m_iReloadGestureSequence = iSequence; + SetGestureSlotCycle(GESTURE_SLOT_ATTACK_AND_RELOAD, m_flReloadGestureStartCycle); +} + +// Blend a fitted reload gesture in from its start cycle and out to its end cycle, then end it there +void CHL2MPPlayerAnimState::UpdateReloadGesture() +{ + if (m_iReloadGestureSequence < 0) + { + return; + } + + CBasePlayer *pPlayer = GetBasePlayer(); + GestureSlot_t &slot = m_aGestureSlots[GESTURE_SLOT_ATTACK_AND_RELOAD]; + if (!pPlayer || !slot.m_bActive || !slot.m_pAnimLayer || slot.m_pAnimLayer->m_nSequence != m_iReloadGestureSequence) + { + // a new gesture took the slot, or the reload gesture ended + m_iReloadGestureSequence = -1; + return; + } + + const float flCycle = slot.m_pAnimLayer->m_flCycle; + if (m_flReloadGestureEndCycle < 1.0f && flCycle >= m_flReloadGestureEndCycle) + { + ResetGestureSlot(GESTURE_SLOT_ATTACK_AND_RELOAD); + m_iReloadGestureSequence = -1; + return; + } + + const float flBlendCycles = RELOAD_GESTURE_BLEND_TIME * pPlayer->GetSequenceCycleRate(pPlayer->GetModelPtr(), m_iReloadGestureSequence); + if (flBlendCycles <= 0.0f) + { + return; + } + + float flWeight = 1.0f; + if (m_flReloadGestureStartCycle > 0.0f) + { + flWeight = Min(flWeight, (flCycle - m_flReloadGestureStartCycle) / flBlendCycles); + } + + if (m_flReloadGestureEndCycle < 1.0f) + { + flWeight = Min(flWeight, (m_flReloadGestureEndCycle - flCycle) / flBlendCycles); + } + + slot.m_pAnimLayer->m_flWeight = clamp(flWeight, 0.0f, 1.0f); +} +#endif // NEO diff --git a/src/game/shared/hl2mp/hl2mp_playeranimstate.h b/src/game/shared/hl2mp/hl2mp_playeranimstate.h index 9a05125539..0ffaa2a624 100644 --- a/src/game/shared/hl2mp/hl2mp_playeranimstate.h +++ b/src/game/shared/hl2mp/hl2mp_playeranimstate.h @@ -16,6 +16,15 @@ class C_HL2MP_Player; class CHL2MP_Player; #endif +#ifdef NEO +// The part of the third-person reload gesture that a shorter first-person reload shows +enum ReloadGestureFit_t +{ + RELOAD_GESTURE_KEEP_START, // a reload from the start: the gesture ends early + RELOAD_GESTURE_KEEP_END, // a resumed reload: the gesture starts late +}; +#endif + // ------------------------------------------------------------------------------------------------ // // CPlayerAnimState declaration. // ------------------------------------------------------------------------------------------------ // @@ -47,6 +56,9 @@ class CHL2MPPlayerAnimState : public CMultiPlayerAnimState virtual float GetCurrentMaxGroundSpeed(); #ifdef NEO virtual void ComputeSequences(CStudioHdr* pStudioHdr); + + // A reload event's data: how long the first-person reload lasts, and which part of a longer gesture it shows + static int PackReloadGestureData(ReloadGestureFit_t fit, float flDuration); #endif void DebugShowAnimStateFull(int iStartLine); @@ -64,9 +76,18 @@ class CHL2MPPlayerAnimState : public CMultiPlayerAnimState #ifdef NEO bool IsLeaning(CStudioHdr *pStudioHdr); + void SetGestureSlotCycle(int iGestureSlot, float flCycle); + void StartReloadGesture(int nData); + void UpdateReloadGesture(); #endif // NEO CHL2MP_Player *m_pHL2MPPlayer; +#ifdef NEO + // The playing reload gesture's sequence (-1: none) and the cycles it blends in from and out to + int m_iReloadGestureSequence; + float m_flReloadGestureStartCycle; + float m_flReloadGestureEndCycle; +#endif #ifndef NEO bool m_bInAirWalk; float m_flHoldDeployedPoseUntilTime; diff --git a/src/game/shared/neo/neo_gamerules.cpp b/src/game/shared/neo/neo_gamerules.cpp index 38e7155f74..45fceb7356 100644 --- a/src/game/shared/neo/neo_gamerules.cpp +++ b/src/game/shared/neo/neo_gamerules.cpp @@ -42,6 +42,7 @@ #include extern ConVar weaponstay; +extern ConVar sv_neo_reload_experimental; #endif ConVar sv_neo_loopback_warmup_round("sv_neo_loopback_warmup_round", "0", FCVAR_REPLICATED, "Allow loopback server to do warmup rounds.", true, 0.0f, true, 1.0f); @@ -306,6 +307,7 @@ BEGIN_NETWORK_TABLE_NOBASE( CNEORules, DT_NEORules ) RecvPropInt(RECVINFO(m_iForcedSkin)), RecvPropInt(RECVINFO(m_iForcedWeapon)), RecvPropBool(RECVINFO(m_bCyberspaceLevel)), + RecvPropBool(RECVINFO(m_bReloadExperimental)), RecvPropString(RECVINFO(m_szNeoJinraiClantag)), RecvPropString(RECVINFO(m_szNeoNSFClantag)), RecvPropInt(RECVINFO(m_iGhosterTeam)), @@ -349,6 +351,7 @@ BEGIN_NETWORK_TABLE_NOBASE( CNEORules, DT_NEORules ) SendPropInt(SENDINFO(m_iForcedSkin)), SendPropInt(SENDINFO(m_iForcedWeapon)), SendPropBool(SENDINFO(m_bCyberspaceLevel)), + SendPropBool(SENDINFO(m_bReloadExperimental)), SendPropString(SENDINFO(m_szNeoJinraiClantag)), SendPropString(SENDINFO(m_szNeoNSFClantag)), SendPropInt(SENDINFO(m_iGhosterTeam), NumBitsForCount(TEAM__TOTAL), SPROP_UNSIGNED), @@ -705,6 +708,12 @@ CNEORules::CNEORules() m_iForcedSkin = -1; m_iForcedWeapon = -1; m_bCyberspaceLevel = false; +#ifdef GAME_DLL + // Read once per map so that every weapon, and the client's prediction of it, sees one value for the whole map + m_bReloadExperimental = sv_neo_reload_experimental.GetBool(); +#else + m_bReloadExperimental = false; +#endif m_iClassLimitRecon = -1; m_iClassLimitAssault = -1; diff --git a/src/game/shared/neo/neo_gamerules.h b/src/game/shared/neo/neo_gamerules.h index 1bdee613ae..32e789c521 100644 --- a/src/game/shared/neo/neo_gamerules.h +++ b/src/game/shared/neo/neo_gamerules.h @@ -244,6 +244,7 @@ class CNEORules : public CHL2MPRules, public CGameEventListener int GetForcedSkin(); int GetForcedWeapon(); bool IsCyberspace(); + bool IsReloadExperimental() const { return m_bReloadExperimental; } virtual const char* GetGameTypeName(void) OVERRIDE; bool CanChangeTeamClassLoadoutWhenAlive(); bool CanRespawnAnyTime(); @@ -555,6 +556,7 @@ class CNEORules : public CHL2MPRules, public CGameEventListener CNetworkVar(int, m_iForcedSkin); CNetworkVar(int, m_iForcedWeapon); CNetworkVar(bool, m_bCyberspaceLevel); + CNetworkVar(bool, m_bReloadExperimental); CNetworkVar(int, m_nGameTypeSelected); CNetworkVar(int, m_iRoundNumber); CNetworkVar(bool, m_bIsMatchPoint); diff --git a/src/game/shared/neo/neo_predicted_viewmodel.cpp b/src/game/shared/neo/neo_predicted_viewmodel.cpp index fd2ff5bed0..4349c215d3 100644 --- a/src/game/shared/neo/neo_predicted_viewmodel.cpp +++ b/src/game/shared/neo/neo_predicted_viewmodel.cpp @@ -487,7 +487,7 @@ void CNEOPredictedViewModel::CalcViewModelView(CBasePlayer *pOwner, return; } - CNEOWeaponInfo data = weapon->GetNEOWpnData(); + const CNEOWeaponInfo &data = weapon->GetNEOWpnData(); Vector vForward, vRight, vUp, newPos, vOffset; QAngle newAng, angOffset; diff --git a/src/game/shared/neo/weapons/neo_weapon_parse.cpp b/src/game/shared/neo/weapons/neo_weapon_parse.cpp index bafe4597b6..b3050775c8 100644 --- a/src/game/shared/neo/weapons/neo_weapon_parse.cpp +++ b/src/game/shared/neo/weapons/neo_weapon_parse.cpp @@ -24,6 +24,7 @@ CNEOWeaponInfo::CNEOWeaponInfo() m_flPenetration = 0.f; m_bDropOnDeath = true; iAimFOV = 0; + m_bChamberedRound = false; m_flVMFov = m_flVMAimFov = 0.f; m_vecVMPosOffset = m_vecVMAimPosOffset = vec3_origin; @@ -31,6 +32,80 @@ CNEOWeaponInfo::CNEOWeaponInfo() } +// Weapon-script names of the reload phases, by ReloadPhase_t +static constexpr const char *RELOAD_PHASE_NAMES[RELOAD_PHASE_COUNT] = { "", "1_unload", "2_load", "3_cycle" }; +// Weapon-script keys of a phase's sound pieces: { sound name, time } +static constexpr const char *RELOAD_SOUND_KEYS[RELOAD_SOUNDS_PER_ROW][2] = { + { "sound_name", "sound" }, { "sound2_name", "sound2" }, { "sound3_name", "sound3" } +}; + +static ReloadPhase_t ReloadPhaseFromName(const char *pszName) +{ + for (int i = RELOAD_PHASE_UNLOADED; i < RELOAD_PHASE_COUNT; ++i) + { + if (V_stricmp(pszName, RELOAD_PHASE_NAMES[i]) == 0) + { + return static_cast(i); + } + } + return RELOAD_PHASE_NONE; +} + +// "ReloadPhases" { "" { "" { "ammo" "s" "sound" "s" "sound_name" "name" "resume" "sequence" } ... } ... } +void CNEOWeaponInfo::ParseReloadPhases(KeyValues *pBlock) +{ + m_reloadTables.Purge(); + if (!pBlock) + { + return; + } + + if (!pBlock->GetFirstTrueSubKey()) + { + Warning("%s: \"ReloadPhases\" is empty (is its neoAssets #base file missing?); reloading without phases\n", szClassName); + return; + } + + for (KeyValues *pSeq = pBlock->GetFirstTrueSubKey(); pSeq && m_reloadTables.Count() < RELOAD_PHASE_TABLES_MAX; pSeq = pSeq->GetNextTrueSubKey()) + { + ReloadPhaseTable_t &table = m_reloadTables[m_reloadTables.AddToTail()]; + V_strncpy(table.szSequence, pSeq->GetName(), sizeof(table.szSequence)); + table.iNumRows = 0; + + for (KeyValues *pRow = pSeq->GetFirstTrueSubKey(); pRow && table.iNumRows < RELOAD_PHASE_ROWS_MAX; pRow = pRow->GetNextTrueSubKey()) + { + const ReloadPhase_t phase = ReloadPhaseFromName(pRow->GetName()); + if (phase == RELOAD_PHASE_NONE) + { + Warning("%s: unknown reload phase \"%s\" in \"%s\"\n", szClassName, pRow->GetName(), table.szSequence); + continue; + } + + ReloadPhaseRow_t &row = table.rows[table.iNumRows++]; + row.phase = phase; + row.flAmmo = pRow->GetFloat("ammo"); + for (int j = 0; j < RELOAD_SOUNDS_PER_ROW; ++j) + { + row.sounds[j].flAt = pRow->GetFloat(RELOAD_SOUND_KEYS[j][1]); + V_strncpy(row.sounds[j].szName, pRow->GetString(RELOAD_SOUND_KEYS[j][0]), sizeof(row.sounds[j].szName)); + } + V_strncpy(row.szResume, pRow->GetString("resume"), sizeof(row.szResume)); + } + } +} + +int CNEOWeaponInfo::FindReloadTable(const char *pszSequence) const +{ + for (int i = 0; i < m_reloadTables.Count(); ++i) + { + if (V_stricmp(m_reloadTables[i].szSequence, pszSequence) == 0) + { + return i; + } + } + return -1; +} + void CNEOWeaponInfo::Parse( KeyValues *pKeyValuesData, const char *szWeaponName ) { BaseClass::Parse( pKeyValuesData, szWeaponName ); @@ -39,6 +114,8 @@ void CNEOWeaponInfo::Parse( KeyValues *pKeyValuesData, const char *szWeaponName m_iBullets = pKeyValuesData->GetInt( "Bullets", 1 ); m_flCycleTime = pKeyValuesData->GetFloat( "CycleTime", 0.15 ); m_flReloadReadyBeforeEnd = pKeyValuesData->GetFloat( "ReloadReadyBeforeEnd", 0.0f ); + ParseReloadPhases(pKeyValuesData->FindKey("ReloadPhases")); + m_bChamberedRound = pKeyValuesData->GetBool("ChamberedRound", false); const char *notFoundStr = "notfound"; Q_strncpy(szViewModel2, pKeyValuesData->GetString("team2viewmodel", notFoundStr), MAX_WEAPON_STRING); diff --git a/src/game/shared/neo/weapons/neo_weapon_parse.h b/src/game/shared/neo/weapons/neo_weapon_parse.h index 040dc00649..abdf2e86f9 100644 --- a/src/game/shared/neo/weapons/neo_weapon_parse.h +++ b/src/game/shared/neo/weapons/neo_weapon_parse.h @@ -11,6 +11,55 @@ #endif #include "hl2mp_weapon_parse.h" +#include "utlvector.h" + +// A reload is a linear sequence of phases; a reload sequence finishes each phase at a point of its animation +enum ReloadPhase_t +{ + RELOAD_PHASE_NONE = 0, // no reload in progress, or none pending + RELOAD_PHASE_UNLOADED, // 1_unload: the old magazine is out + RELOAD_PHASE_LOADED, // 2_load: the fresh magazine is in + RELOAD_PHASE_CYCLED, // 3_cycle: the bolt or charging handle chambered a round + + RELOAD_PHASE_COUNT +}; + +// bits to network a phase +static constexpr int RELOAD_PHASE_BITS = 2; +static_assert((1 << RELOAD_PHASE_BITS) >= RELOAD_PHASE_COUNT, "RELOAD_PHASE_BITS cannot hold every phase"); +static constexpr int RELOAD_PHASE_TABLES_MAX = 12; +// bits to network a table index, signed so that -1 (no table) fits +static constexpr int RELOAD_PHASE_TABLE_BITS = 5; +static_assert((1 << (RELOAD_PHASE_TABLE_BITS - 1)) >= RELOAD_PHASE_TABLES_MAX, "RELOAD_PHASE_TABLE_BITS cannot hold every table index"); +static constexpr int RELOAD_PHASE_ROWS_MAX = RELOAD_PHASE_COUNT - 1; +static constexpr int RELOAD_SOUND_NAME_MAX = 64; +static constexpr int RELOAD_SEQUENCE_NAME_MAX = 32; +// a phase may need more than one sound piece, such as loading a magazine and the tap after it +static constexpr int RELOAD_SOUNDS_PER_ROW = 3; + +// A sound piece of a phase +struct ReloadSoundPiece_t +{ + float flAt; // when the piece's first transient plays, seconds from the sequence start + char szName[RELOAD_SOUND_NAME_MAX]; +}; + +// One phase of a reload sequence: when its ammo counts, and the sound pieces that go with it +struct ReloadPhaseRow_t +{ + ReloadPhase_t phase; + float flAmmo; // seconds from the sequence start + ReloadSoundPiece_t sounds[RELOAD_SOUNDS_PER_ROW]; + char szResume[RELOAD_SEQUENCE_NAME_MAX]; // the sequence that resumes a reload interrupted after this phase, or empty +}; + +// The phases one reload sequence carries, in order +struct ReloadPhaseTable_t +{ + char szSequence[RELOAD_SEQUENCE_NAME_MAX]; + int iNumRows; + ReloadPhaseRow_t rows[RELOAD_PHASE_ROWS_MAX]; +}; //-------------------------------------------------------------------------------------------------------- class CNEOWeaponInfo : public CHL2MPSWeaponInfo @@ -25,6 +74,10 @@ class CNEOWeaponInfo : public CHL2MPSWeaponInfo int m_iBullets; float m_flCycleTime; float m_flReloadReadyBeforeEnd; + // A closed-bolt weapon retains a chambered round when reloading with rounds left. + bool m_bChamberedRound; + // Empty: the weapon reloads without phases. Allocated only for scripts with a ReloadPhases block. + CUtlVector m_reloadTables; char szViewModel2[MAX_WEAPON_STRING]; // Team 2 (NSF) wep vm char szBulletCharacter[MAX_BULLET_CHARACTER];// character used to display ammunition in current clip char szDeathIcon[MAX_BULLET_CHARACTER]; @@ -39,6 +92,11 @@ class CNEOWeaponInfo : public CHL2MPSWeaponInfo float m_flVMAimFov; Vector m_vecVMAimPosOffset; QAngle m_angVMAimAngOffset; + + int FindReloadTable(const char *pszSequence) const; + +private: + void ParseReloadPhases(::KeyValues *pBlock); }; diff --git a/src/game/shared/neo/weapons/weapon_neobasecombatweapon.cpp b/src/game/shared/neo/weapons/weapon_neobasecombatweapon.cpp index 979d70f8a7..b4ecf00a00 100644 --- a/src/game/shared/neo/weapons/weapon_neobasecombatweapon.cpp +++ b/src/game/shared/neo/weapons/weapon_neobasecombatweapon.cpp @@ -22,10 +22,10 @@ extern ConVar weaponstay; #include "in_main.h" #else #include "items.h" -#include "neo_gamerules.h" #endif // CLIENT_DLL #include "basecombatweapon_shared.h" +#include "neo_gamerules.h" #include @@ -42,6 +42,11 @@ BEGIN_NETWORK_TABLE( CNEOBaseCombatWeapon, DT_NEOBaseCombatWeapon ) RecvPropInt(RECVINFO(m_nNumShotsFired)), RecvPropBool(RECVINFO(m_bTriggerReset)), RecvPropTime(RECVINFO(m_flReloadReadyTime)), + RecvPropInt(RECVINFO(m_nReloadPhase)), + RecvPropInt(RECVINFO(m_nReloadTable)), + RecvPropTime(RECVINFO(m_flReloadStart)), + RecvPropInt(RECVINFO(m_nReloadSoundsDone)), + RecvPropBool(RECVINFO(m_bChamberEmpty)), RecvPropInt(RECVINFO(m_spawnflags)), #else SendPropTime(SENDINFO(m_flSoonestAttack)), @@ -50,6 +55,11 @@ BEGIN_NETWORK_TABLE( CNEOBaseCombatWeapon, DT_NEOBaseCombatWeapon ) SendPropInt(SENDINFO(m_nNumShotsFired)), SendPropBool(SENDINFO(m_bTriggerReset)), SendPropTime(SENDINFO(m_flReloadReadyTime)), + SendPropInt(SENDINFO(m_nReloadPhase), RELOAD_PHASE_BITS, SPROP_UNSIGNED), + SendPropInt(SENDINFO(m_nReloadTable), RELOAD_PHASE_TABLE_BITS), + SendPropTime(SENDINFO(m_flReloadStart)), + SendPropInt(SENDINFO(m_nReloadSoundsDone), RELOAD_PHASE_ROWS_MAX * RELOAD_SOUNDS_PER_ROW, SPROP_UNSIGNED), + SendPropBool(SENDINFO(m_bChamberEmpty)), SendPropInt(SENDINFO(m_spawnflags)), SendPropExclude("DT_BaseAnimating", "m_nSequence"), #endif @@ -63,6 +73,11 @@ BEGIN_PREDICTION_DATA(CNEOBaseCombatWeapon) DEFINE_PRED_FIELD(m_nNumShotsFired, FIELD_INTEGER, FTYPEDESC_INSENDTABLE), DEFINE_PRED_FIELD(m_bTriggerReset, FIELD_BOOLEAN, FTYPEDESC_INSENDTABLE), DEFINE_PRED_FIELD(m_flReloadReadyTime, FIELD_FLOAT, FTYPEDESC_INSENDTABLE), + DEFINE_PRED_FIELD(m_nReloadPhase, FIELD_INTEGER, FTYPEDESC_INSENDTABLE), + DEFINE_PRED_FIELD(m_nReloadTable, FIELD_INTEGER, FTYPEDESC_INSENDTABLE), + DEFINE_PRED_FIELD(m_flReloadStart, FIELD_FLOAT, FTYPEDESC_INSENDTABLE), + DEFINE_PRED_FIELD(m_nReloadSoundsDone, FIELD_INTEGER, FTYPEDESC_INSENDTABLE), + DEFINE_PRED_FIELD(m_bChamberEmpty, FIELD_BOOLEAN, FTYPEDESC_INSENDTABLE), END_PREDICTION_DATA() #endif @@ -76,11 +91,19 @@ BEGIN_DATADESC( CNEOBaseCombatWeapon ) DEFINE_FIELD(m_nNumShotsFired, FIELD_INTEGER), DEFINE_FIELD(m_bTriggerReset, FIELD_BOOLEAN), DEFINE_FIELD(m_flReloadReadyTime, FIELD_TIME), + DEFINE_FIELD(m_nReloadPhase, FIELD_INTEGER), + DEFINE_FIELD(m_nReloadTable, FIELD_INTEGER), + DEFINE_FIELD(m_flReloadStart, FIELD_TIME), + DEFINE_FIELD(m_nReloadSoundsDone, FIELD_INTEGER), + DEFINE_FIELD(m_bChamberEmpty, FIELD_BOOLEAN), END_DATADESC() #endif ConVar sv_neo_accuracy_penalty_scale("sv_neo_accuracy_penalty_scale", "1.0", FCVAR_REPLICATED, "Scales the accuracy penalty per shot.", true, 0.0f, true, 2.0f); ConVar sv_neo_dynamic_viewkick("sv_neo_dynamic_viewkick", "0", FCVAR_REPLICATED, "Enables view kick scaling based on current inaccuracy.", true, 0.0f, true, 1.0f); +ConVar sv_neo_reload_experimental("sv_neo_reload_experimental", "0", FCVAR_REPLICATED, + "Lets a switch interrupt a reload after the magazine is out, for weapons that define reload phases. A change applies from the next map.", + true, 0.0f, true, 1.0f); const char *GetWeaponByLoadoutId(int id) { @@ -233,6 +256,12 @@ static const WeaponHandlingInfo_t handlingTable[] = { CNEOBaseCombatWeapon::CNEOBaseCombatWeapon( void ) { m_bTriggerReset = true; + m_nReloadPhase = RELOAD_PHASE_NONE; + m_nReloadTable = -1; + m_flReloadStart = 0.0f; + m_nReloadSoundsDone = 0; + // Spawn ammo includes the chambered round; only a tactical reload adds an extra round. + m_bChamberEmpty = false; } const CNEOWeaponInfo &CNEOBaseCombatWeapon::GetNEOWpnData() const @@ -420,6 +449,12 @@ void CNEOBaseCombatWeapon::Equip(CBaseCombatCharacter* pOwner) bool CNEOBaseCombatWeapon::Reload( void ) { + const ReloadRequest_t request = ReloadPhasesOnRequest(); + if (request != RELOAD_REQUEST_DEFAULT) + { + return request == RELOAD_REQUEST_STARTED; + } + const bool bEmptyReload = UsesClipsForAmmo1() && m_iClip1 <= 0 && SelectWeightedSequence(ACT_VM_RELOAD_EMPTY) != ACTIVITY_NOT_AVAILABLE; @@ -441,6 +476,8 @@ bool CNEOBaseCombatWeapon::Reload( void ) // the animation and the wait to fire still run to the end m_flReloadReadyTime = Max(gpGlobals->curtime, m_flNextPrimaryAttack - GetNEOWpnData().m_flReloadReadyBeforeEnd); + ReloadPhasesOnReload(); + return true; #if(0) @@ -471,6 +508,406 @@ bool CNEOBaseCombatWeapon::Reload( void ) #endif } +// Each reload sound piece's file starts this long before its first transient +static constexpr float RELOAD_SOUND_LEAD = 0.02f; + +bool CNEOBaseCombatWeapon::IsReloadPhaseSystemEnabled() const +{ + return NEORules() && NEORules()->IsReloadExperimental() && !GetNEOWpnData().m_reloadTables.IsEmpty(); +} + +CNEOBaseCombatWeapon::ReloadRequest_t CNEOBaseCombatWeapon::ReloadPhasesOnRequest() +{ + if (!IsReloadPhaseSystemEnabled()) + { + return RELOAD_REQUEST_DEFAULT; + } + + // The phase paths below bypass DefaultReload, so a call during a reload must not restart it. + if (m_bInReload) + { + return RELOAD_REQUEST_REFUSED; + } + + // A lost resume must still allow chambering the loaded magazine, even without spare ammo. + if (HasChamberSlot() && m_bChamberEmpty && m_iClip1 > 0) + { + static constexpr const char *VM_SEQ_RELOAD_DRY = "reload"; + const int iTable = GetNEOWpnData().FindReloadTable(VM_SEQ_RELOAD_DRY); + if (iTable < 0 || !PlayReloadSequence(VM_SEQ_RELOAD_DRY, iTable, RELOAD_GESTURE_KEEP_START)) + { + return RELOAD_REQUEST_REFUSED; + } + + // Keep the loaded magazine's ammo; only the cycle phase still needs credit. + m_nReloadPhase = RELOAD_PHASE_LOADED; + CBaseCombatWeapon::WeaponSound(RELOAD_NPC); + return RELOAD_REQUEST_STARTED; + } + + if (HasChamberSlot() && RoundsInMagazine() >= MagazineCapacity()) + { + return RELOAD_REQUEST_REFUSED; + } + + // The tactical sequence omits the bolt cycle and retains the chambered round. + return StartPartialReload() ? RELOAD_REQUEST_STARTED : RELOAD_REQUEST_DEFAULT; +} + +// The phases are those of the sequence the reload plays, such as reload or reloadempty +void CNEOBaseCombatWeapon::ReloadPhasesOnReload() +{ + if (!IsReloadPhaseSystemEnabled()) + { + return; + } + + CBaseViewModel *pVM = ReloadViewModel(); + m_nReloadPhase = RELOAD_PHASE_NONE; + StartReloadPhases(pVM ? GetNEOWpnData().FindReloadTable(pVM->GetSequenceName(pVM->GetSequence())) : -1); +} + +// The magazine is in: the phases up to the load are done, and a switch from here leaves nothing to resume. +// Returns the rounds the chamber keeps through the magazine change +int CNEOBaseCombatWeapon::ReloadPhasesOnFinish() +{ + if (!IsReloadPhaseSystemEnabled()) + { + return 0; + } + + m_nReloadPhase = Max(static_cast(m_nReloadPhase.Get()), RELOAD_PHASE_LOADED); + return IsRoundChambered() ? 1 : 0; +} + +// A reload interrupted by a switch goes on in the draw; returns whether it resumed +bool CNEOBaseCombatWeapon::ReloadPhasesOnDeploy() +{ + if (!IsReloadPhaseSystemEnabled() || m_nReloadPhase == RELOAD_PHASE_NONE) + { + return false; + } + + return ResumeReload(); +} + +// Only a phase that a sequence resumes from outlasts the switch, with the table that names the resume +void CNEOBaseCombatWeapon::ReloadPhasesOnHolster() +{ + // NEO TODO: Decide whether RELOAD_END should stop the gesture on a switch. + if (!IsReloadPhaseSystemEnabled()) + { + return; + } + + StopReloadSoundPieces(); + if (!FindResumeSequence()) + { + m_nReloadPhase = RELOAD_PHASE_NONE; + m_nReloadTable = -1; + } +} + +void CNEOBaseCombatWeapon::ReloadPhasesOnBusyFrame() +{ + if (!IsReloadPhaseSystemEnabled()) + { + return; + } + + RunReloadPhases(); +} + +// The viewmodel sequence that resumes the reload interrupted now, from the phase table of the playing sequence; +// nullptr: none (resume sequences carry no activity, so they are picked by name) +const char *CNEOBaseCombatWeapon::FindResumeSequence() const +{ + const ReloadPhase_t phase = static_cast(m_nReloadPhase.Get()); + if (phase == RELOAD_PHASE_NONE || m_nReloadTable < 0) + { + return nullptr; + } + + // a sequence that starts after the phase is itself the resume from it, interrupted again before its first phase + const ReloadPhaseTable_t &table = GetNEOWpnData().m_reloadTables[m_nReloadTable]; + if (table.iNumRows > 0 && table.rows[0].phase > phase) + { + return table.szSequence; + } + + for (int i = 0; i < table.iNumRows; ++i) + { + if (table.rows[i].phase == phase) + { + return table.rows[i].szResume[0] ? table.rows[i].szResume : nullptr; + } + } + return nullptr; +} + +// Time the phases of a reload sequence that starts now (-1: a sequence without a table finishes none) +void CNEOBaseCombatWeapon::StartReloadPhases(int iTable) +{ + m_nReloadTable = iTable; + m_flReloadStart = gpGlobals->curtime; + m_nReloadSoundsDone = 0; +} + +// Finish every phase of the playing reload sequence whose time has come, and play its sound pieces +void CNEOBaseCombatWeapon::RunReloadPhases() +{ + if (!m_bInReload || m_nReloadTable < 0) + { + return; + } + + const ReloadPhaseTable_t &table = GetNEOWpnData().m_reloadTables[m_nReloadTable]; + const float flElapsed = gpGlobals->curtime - m_flReloadStart; + + // Sound pieces play on their own times, before or after their phase's ammo time + for (int i = 0; i < table.iNumRows; ++i) + { + for (int j = 0; j < RELOAD_SOUNDS_PER_ROW; ++j) + { + const ReloadSoundPiece_t &piece = table.rows[i].sounds[j]; + const int iBit = 1 << (i * RELOAD_SOUNDS_PER_ROW + j); + if (piece.szName[0] && !(m_nReloadSoundsDone & iBit) && flElapsed >= piece.flAt - RELOAD_SOUND_LEAD) + { + m_nReloadSoundsDone |= iBit; + EmitReloadSoundPiece(piece.szName); + } + } + } + + for (int i = 0; i < table.iNumRows; ++i) + { + const ReloadPhaseRow_t &row = table.rows[i]; + if (row.phase <= m_nReloadPhase) + { + continue; + } + + if (flElapsed < row.flAmmo) + { + break; + } + + FinishReloadPhase(row.phase); + } +} + +void CNEOBaseCombatWeapon::FinishReloadPhase(ReloadPhase_t phase) +{ + // The old magazine's rounds go with it, as a reload without phases discards them at the load (FinishReload); + // a chambered round stays + if (phase == RELOAD_PHASE_UNLOADED) + { + m_iClip1 = IsRoundChambered() ? 1 : 0; + } + else if (phase == RELOAD_PHASE_LOADED) + { + // the magazine loads now, as at a reload's ready time (ItemBusyFrame) + m_flReloadReadyTime = gpGlobals->curtime; + } + + if (phase == RELOAD_PHASE_CYCLED) + { + m_bChamberEmpty = false; + } + + m_nReloadPhase = phase; +} + +// Resume, in the draw, a reload interrupted by a switch. A model without the resume sequence keeps the old magazine, +// as a cancelled reload does; returns whether the reload resumed +bool CNEOBaseCombatWeapon::ResumeReload() +{ + const char *pszName = FindResumeSequence(); + const int iTable = pszName ? GetNEOWpnData().FindReloadTable(pszName) : -1; + if (iTable < 0 || LookupReloadSequence(pszName) < 0) + { + m_nReloadPhase = RELOAD_PHASE_NONE; + m_nReloadTable = -1; + return false; + } + + // After the unload the old magazine is lost, but a chambered round stays. + // After the load the fresh magazine is already in. + if (m_nReloadPhase == RELOAD_PHASE_UNLOADED) + { + m_iClip1 = IsRoundChambered() ? 1 : 0; + } + + return PlayReloadSequence(pszName, iTable, RELOAD_GESTURE_KEEP_END); +} + +// The tactical sequence has no activity; ACT_VM_RELOAD selects the dry reload. +bool CNEOBaseCombatWeapon::StartPartialReload() +{ + static constexpr const char *VM_SEQ_RELOAD_PARTIAL = "reload_skipcycle"; + if (!IsReloadPhaseSystemEnabled() || !IsRoundChambered()) + { + return false; + } + + if (!UsesClipsForAmmo1() || RoundsInMagazine() >= MagazineCapacity() || m_iPrimaryAmmoCount <= 0) + { + return false; + } + + const int iTable = GetNEOWpnData().FindReloadTable(VM_SEQ_RELOAD_PARTIAL); + if (iTable < 0 || LookupReloadSequence(VM_SEQ_RELOAD_PARTIAL) < 0) + { + return false; + } + + m_nReloadPhase = RELOAD_PHASE_NONE; + return PlayReloadSequence(VM_SEQ_RELOAD_PARTIAL, iTable, RELOAD_GESTURE_KEEP_START); +} + +// Named sequences carry no activity, so time their reload phases and gesture explicitly. +bool CNEOBaseCombatWeapon::PlayReloadSequence(const char *pszName, int iTable, ReloadGestureFit_t gestureFit) +{ + auto *pOwner = ToHL2MPPlayer(GetOwner()); + const int iSequence = LookupReloadSequence(pszName); + if (!pOwner || iSequence < 0) + { + return false; + } + + // The weapon entity draws its world model in third person, which has none of the viewmodel's sequences + const int iOwnSequence = LookupSequence(pszName); + if (iOwnSequence >= 0) + { + SetSequence(iOwnSequence); + } + SendViewModelAnim(iSequence); + + // the third-person reload gesture lasts no longer than this sequence + const float flDuration = ReloadViewModel()->SequenceDuration(iSequence); + pOwner->DoAnimationEvent(PLAYERANIMEVENT_RELOAD, CHL2MPPlayerAnimState::PackReloadGestureData(gestureFit, flDuration)); + + // the clip end is the fire point: no ReloadReadyBeforeEnd on this path + const float flEnd = gpGlobals->curtime + flDuration; + GetOwner()->SetNextAttack(flEnd); + m_flNextPrimaryAttack = m_flNextSecondaryAttack = flEnd; + SetWeaponIdleTime(flEnd); + + // the load phase loads the magazine + m_flReloadReadyTime = 0.0f; + StartReloadPhases(iTable); + m_bInReload = true; + return true; +} + +// The old magazine is out and the fresh one not yet in: the reload is about to refill the clip +bool CNEOBaseCombatWeapon::IsReloadPastUnload() const +{ + return IsReloadPhaseSystemEnabled() && m_bInReload && m_nReloadPhase == RELOAD_PHASE_UNLOADED; +} + +bool CNEOBaseCombatWeapon::HasChamberSlot() const +{ + return IsReloadPhaseSystemEnabled() && GetNEOWpnData().m_bChamberedRound; +} + +// The clip counts the chambered round; the chamber is empty after the last shot until a 3_cycle +bool CNEOBaseCombatWeapon::IsRoundChambered() const +{ + return HasChamberSlot() && m_iClip1 > 0 && !m_bChamberEmpty; +} + +int CNEOBaseCombatWeapon::RoundsInMagazine() const +{ + return m_iClip1 - (IsRoundChambered() ? 1 : 0); +} + +int CNEOBaseCombatWeapon::MagazineCapacity() const +{ + return GetMaxClip1(); +} + +// Reload sequences are looked up on the owner's viewmodel, the entity that plays them. The weapon entity's model is not +// always that viewmodel on the client: CalcOverrideModelIndex gives it the world model whenever the local player does +// not draw its viewmodel +CBaseViewModel *CNEOBaseCombatWeapon::ReloadViewModel() const +{ + CBasePlayer *pOwner = ToBasePlayer(GetOwner()); + return pOwner ? pOwner->GetViewModel(m_nViewModelIndex) : nullptr; +} + +int CNEOBaseCombatWeapon::LookupReloadSequence(const char *pszName) const +{ + CBaseViewModel *pVM = ReloadViewModel(); + return pVM ? pVM->LookupSequence(pszName) : -1; +} + +// Sound pieces play on their own channel entries, so a switch or a drop stops them by name, +// as the player stops the single reload sound +void CNEOBaseCombatWeapon::StopReloadSoundPieces() +{ + CBaseCombatCharacter *pOwner = GetOwner(); + if (!pOwner || m_nReloadTable < 0) + { + return; + } + + const ReloadPhaseTable_t &table = GetNEOWpnData().m_reloadTables[m_nReloadTable]; + for (int i = 0; i < table.iNumRows; ++i) + { + for (int j = 0; j < RELOAD_SOUNDS_PER_ROW; ++j) + { + const char *pszName = table.rows[i].sounds[j].szName; + if (pszName[0]) + { + StopSound(pOwner->entindex(), pszName); + } + } + } +} + +void CNEOBaseCombatWeapon::StopReloadOnDrop() +{ + if (!IsReloadPhaseSystemEnabled()) + { + return; + } + + StopReloadSoundPieces(); + + // Preserve a pending bolt cycle for the next owner's draw. + // NEO TODO: Should a drop after 1_unload also resume for the next owner? + if (m_nReloadPhase >= RELOAD_PHASE_LOADED && FindResumeSequence()) + { + return; + } + + m_nReloadPhase = RELOAD_PHASE_NONE; + m_nReloadTable = -1; +} + +// Play a reload sound piece from the owner, as WeaponSound does: predicted for the owner, from the server for the rest +void CNEOBaseCombatWeapon::EmitReloadSoundPiece(const char *pszSound) +{ + CBaseCombatCharacter *pOwner = GetOwner(); + if (!pOwner) + { + return; + } + + CSoundParameters params; + if (!GetParametersForSound(pszSound, params, NULL)) + { + return; + } + + CPASAttenuationFilter filter(pOwner, params.soundlevel); + if (IsPredicted() && CBaseEntity::GetPredictionPlayer()) + { + filter.UsePredictionRules(); + } + EmitSound(filter, pOwner->entindex(), pszSound); +} //----------------------------------------------------------------------------- // Purpose: Reload has finished. @@ -484,6 +921,8 @@ void CNEOBaseCombatWeapon::FinishReload(void) } m_flReloadReadyTime = 0.0f; + const int iChambered = ReloadPhasesOnFinish(); + CBaseCombatCharacter* pOwner = GetOwner(); if (pOwner) @@ -492,7 +931,7 @@ void CNEOBaseCombatWeapon::FinishReload(void) if (UsesClipsForAmmo1()) { int primary = MIN(GetMaxClip1(), m_iPrimaryAmmoCount); - m_iClip1 = primary; + m_iClip1 = iChambered + primary; m_iPrimaryAmmoCount -= primary; } @@ -533,7 +972,8 @@ bool CNEOBaseCombatWeapon::Deploy(void) // An empty weapon draws with its slide held back where the model has that draw, // which carries no activity, so it is picked by name static constexpr const char *VM_SEQ_DRAW_EMPTY = "drawempty"; - const int iDrawEmpty = (UsesClipsForAmmo1() && m_iClip1 <= 0) ? LookupSequence(VM_SEQ_DRAW_EMPTY) : ACTIVITY_NOT_AVAILABLE; + const bool bResumed = ReloadPhasesOnDeploy(); + const int iDrawEmpty = (!bResumed && UsesClipsForAmmo1() && m_iClip1 <= 0) ? LookupSequence(VM_SEQ_DRAW_EMPTY) : ACTIVITY_NOT_AVAILABLE; if (iDrawEmpty != ACTIVITY_NOT_AVAILABLE) { SetSequence(iDrawEmpty); @@ -600,6 +1040,8 @@ float CNEOBaseCombatWeapon::GetPenetration() const bool CNEOBaseCombatWeapon::Holster(CBaseCombatWeapon* pSwitchingTo) { + ReloadPhasesOnHolster(); + return BaseClass::Holster(pSwitchingTo); } @@ -655,6 +1097,8 @@ void CNEOBaseCombatWeapon::ItemBusyFrame(void) BaseClass::ItemBusyFrame(); UpdateInaccuracy(); + ReloadPhasesOnBusyFrame(); + // The owner stays busy until the reload animation ends, but the magazine loads at the reload's ready time if (m_bInReload && m_flReloadReadyTime > 0.0f && gpGlobals->curtime >= m_flReloadReadyTime) { @@ -1017,6 +1461,13 @@ void CNEOBaseCombatWeapon::PrimaryAttack(void) return; } + // A loaded magazine cannot fire until a reload cycle chambers a round. + else if (HasChamberSlot() && m_bChamberEmpty && m_iClip1 > 0) + { + CheckReload(); + return; + } + else if (m_iClip1 == 0) { if (!m_bFireOnEmpty) @@ -1119,6 +1570,12 @@ void CNEOBaseCombatWeapon::PrimaryAttack(void) { info.m_iShots = MIN(info.m_iShots, m_iClip1); m_iClip1 -= info.m_iShots; + + // The last shot requires a bolt cycle on the next reload. + if (HasChamberSlot() && m_iClip1 <= 0) + { + m_bChamberEmpty = true; + } } else { diff --git a/src/game/shared/neo/weapons/weapon_neobasecombatweapon.h b/src/game/shared/neo/weapons/weapon_neobasecombatweapon.h index a772edda17..8be431e901 100644 --- a/src/game/shared/neo/weapons/weapon_neobasecombatweapon.h +++ b/src/game/shared/neo/weapons/weapon_neobasecombatweapon.h @@ -298,6 +298,59 @@ class CNEOBaseCombatWeapon : public CBaseHL2MPCombatWeapon CNEOBaseCombatWeapon(const CNEOBaseCombatWeapon &other); bool HasEmptyIdle(); + // Reload phases (sv_neo_reload_experimental, weapons whose script has a ReloadPhases block). + // Each hook checks IsReloadPhaseSystemEnabled itself, so with the flag off a hook call does nothing +public: + void StopReloadOnDrop(); + bool IsReloadPastUnload() const; + + // Clip1 includes the chambered round; the magazine can hold GetMaxClip1() more. + virtual bool HasChamberSlot() const; + virtual bool IsRoundChambered() const; + virtual int RoundsInMagazine() const; + virtual int MagazineCapacity() const; + +protected: + bool IsReloadPhaseSystemEnabled() const; + + // the last phase finished, kept across a switch + CNetworkVar(int, m_nReloadPhase); + // the phase table of the reload sequence started last, -1 none + CNetworkVar(int, m_nReloadTable); + // when the reload sequence started; phase times are offsets from it + CNetworkVar(float, m_flReloadStart); + // the sound pieces of the playing sequence already started, one bit per piece + CNetworkVar(int, m_nReloadSoundsDone); + // Only a reload cycle chambers a round after the last shot. + CNetworkVar(bool, m_bChamberEmpty); + +private: + // What a reload request does before the default reload: run it, or answer for the phases + enum ReloadRequest_t + { + RELOAD_REQUEST_DEFAULT, // the default reload runs + RELOAD_REQUEST_STARTED, // the phases started their own reload + RELOAD_REQUEST_REFUSED, // no reload starts + }; + + ReloadRequest_t ReloadPhasesOnRequest(); + void ReloadPhasesOnReload(); + int ReloadPhasesOnFinish(); + bool ReloadPhasesOnDeploy(); + void ReloadPhasesOnHolster(); + void ReloadPhasesOnBusyFrame(); + + void StartReloadPhases(int iTable); + void RunReloadPhases(); + void FinishReloadPhase(ReloadPhase_t phase); + const char *FindResumeSequence() const; + bool ResumeReload(); + bool PlayReloadSequence(const char *pszName, int iTable, ReloadGestureFit_t gestureFit); + bool StartPartialReload(); + void StopReloadSoundPieces(); + void EmitReloadSoundPiece(const char *pszSound); + CBaseViewModel *ReloadViewModel() const; + int LookupReloadSequence(const char *pszName) const; }; #endif // WEAPON_NEO_BASECOMBATWEAPON_SHARED_H diff --git a/src/game/shared/neo/weapons/weapon_srs.cpp b/src/game/shared/neo/weapons/weapon_srs.cpp index ae21ebf7ee..0a6eb32911 100644 --- a/src/game/shared/neo/weapons/weapon_srs.cpp +++ b/src/game/shared/neo/weapons/weapon_srs.cpp @@ -10,8 +10,12 @@ BEGIN_NETWORK_TABLE(CWeaponSRS, DT_WeaponSRS) DEFINE_NEO_BASE_WEP_NETWORK_TABLE #ifdef CLIENT_DLL RecvPropBool(RECVINFO(m_bNeedsBolting)), + RecvPropTime(RECVINFO(m_flBoltHomeTime)), + RecvPropTime(RECVINFO(m_flBoltStartTime)), #else SendPropBool(SENDINFO(m_bNeedsBolting)), + SendPropTime(SENDINFO(m_flBoltHomeTime)), + SendPropTime(SENDINFO(m_flBoltStartTime)), #endif END_NETWORK_TABLE() @@ -19,6 +23,8 @@ END_NETWORK_TABLE() BEGIN_PREDICTION_DATA(CWeaponSRS) DEFINE_NEO_BASE_WEP_PREDICTION DEFINE_PRED_FIELD(m_bNeedsBolting, FIELD_BOOLEAN, FTYPEDESC_INSENDTABLE), + DEFINE_PRED_FIELD(m_flBoltHomeTime, FIELD_FLOAT, FTYPEDESC_INSENDTABLE), + DEFINE_PRED_FIELD(m_flBoltStartTime, FIELD_FLOAT, FTYPEDESC_INSENDTABLE), END_PREDICTION_DATA() #endif @@ -28,6 +34,9 @@ LINK_ENTITY_TO_CLASS(weapon_srs, CWeaponSRS); PRECACHE_WEAPON_REGISTER(weapon_srs); +// The bolt cycle after a shot; the 3_cycle row of its phase table gives when the bolt is home with the next round +static constexpr const char *VM_SEQ_CHARGE = "charge"; + CWeaponSRS::CWeaponSRS() { m_flSoonestAttack = gpGlobals->curtime; @@ -35,6 +44,8 @@ CWeaponSRS::CWeaponSRS() m_nNumShotsFired = 0; m_bNeedsBolting = false; + m_flBoltHomeTime = 0.0f; + m_flBoltStartTime = 0.0f; m_weaponSeeds = { "srspx", @@ -52,6 +63,11 @@ void CWeaponSRS::PrimaryAttack() return BaseClass::PrimaryAttack(); } + if (BoltPhasesBlockShot()) + { + return; + } + const bool tryingToShootTooFast = (gpGlobals->curtime < m_flLastAttackTime + GetFireRate()); if (tryingToShootTooFast) @@ -60,6 +76,7 @@ void CWeaponSRS::PrimaryAttack() } m_bNeedsBolting = true; + BoltPhasesOnShot(); BaseClass::PrimaryAttack(); } @@ -70,6 +87,11 @@ void CWeaponSRS::ItemPreFrame() return BaseClass::ItemPreFrame(); } + if (BoltPhasesDelayCycle()) + { + return BaseClass::ItemPreFrame(); + } + if (m_flLastAttackTime + 0.08f <= gpGlobals->curtime) { // Primary attack animation finished, begin chambering a round if (auto* pOwner = ToNEOPlayer(GetOwner())) { @@ -83,6 +105,7 @@ void CWeaponSRS::ItemPreFrame() SendWeaponAnim(ACT_VM_PULLBACK); WeaponSound(SPECIAL1); m_bNeedsBolting = false; + BoltPhasesOnCycle(); } BaseClass::ItemPreFrame(); @@ -92,20 +115,141 @@ bool CWeaponSRS::Deploy() { // This is on purpose; the player is allowed to cancel the bolting animation // with a quick-switch input. - m_bNeedsBolting = false; + m_bNeedsBolting = BoltPhasesKeepCycle(); - return BaseClass::Deploy(); + const bool bDeployed = BaseClass::Deploy(); + BoltPhasesOnDeploy(); + return bDeployed; } bool CWeaponSRS::Reload() { + if (BoltPhasesBlockReload()) + { + return false; + } + // The reloading animation already contains the bolting motion; // we don't want to bolt twice. m_bNeedsBolting = false; + BoltPhasesOnReload(); return BaseClass::Reload(); } +bool CWeaponSRS::IsBoltPending() const +{ + return m_bNeedsBolting || gpGlobals->curtime < m_flBoltHomeTime; +} + +bool CWeaponSRS::Holster(CBaseCombatWeapon *pSwitchingTo) +{ + BoltPhasesOnHolster(); + return BaseClass::Holster(pSwitchingTo); +} + +bool CWeaponSRS::IsRoundChambered() const +{ + if (HasChamberSlot() && IsBoltPending()) + { + return false; + } + + return BaseClass::IsRoundChambered(); +} + +// An unchambered gun completes its bolt cycle before it can fire; the press is ignored +bool CWeaponSRS::BoltPhasesBlockShot() const +{ + return HasChamberSlot() && IsBoltPending(); +} + +// With rounds left, the chamber holds the shot's spent case until the bolt is home. A reload before then would +// count the case as a chambered round, at the unload and as the round kept through the magazine change +bool CWeaponSRS::BoltPhasesBlockReload() const +{ + return HasChamberSlot() && IsBoltPending() && m_iClip1 > 0; +} + +void CWeaponSRS::BoltPhasesOnShot() +{ + if (!IsReloadPhaseSystemEnabled()) + { + return; + } + + m_flBoltHomeTime = 0.0f; + m_flBoltStartTime = 0.0f; +} + +// A bolt cycle resumed by a draw waits for the draw to end +bool CWeaponSRS::BoltPhasesDelayCycle() const +{ + return IsReloadPhaseSystemEnabled() && m_flBoltStartTime > gpGlobals->curtime; +} + +// The round counts as chambered once the bolt is home +void CWeaponSRS::BoltPhasesOnCycle() +{ + if (!IsReloadPhaseSystemEnabled()) + { + return; + } + + const CNEOWeaponInfo &info = GetNEOWpnData(); + const int iTable = info.FindReloadTable(VM_SEQ_CHARGE); + if (iTable >= 0 && info.m_reloadTables[iTable].iNumRows > 0) + { + m_flBoltHomeTime = gpGlobals->curtime + info.m_reloadTables[iTable].rows[0].flAmmo; + } +} + +// The round does not count as chambered before the bolt is home, so a cut-short cycle resumes after the draw. +// Returns whether the draw keeps the cycle +bool CWeaponSRS::BoltPhasesKeepCycle() +{ + if (!IsReloadPhaseSystemEnabled()) + { + return false; + } + + m_flBoltHomeTime = 0.0f; + m_flBoltStartTime = 0.0f; + return m_bNeedsBolting; +} + +void CWeaponSRS::BoltPhasesOnDeploy() +{ + if (!IsReloadPhaseSystemEnabled() || !m_bNeedsBolting) + { + return; + } + + m_flBoltStartTime = m_flNextPrimaryAttack; +} + +void CWeaponSRS::BoltPhasesOnReload() +{ + if (!IsReloadPhaseSystemEnabled()) + { + return; + } + + m_flBoltHomeTime = 0.0f; +} + +// Time passes while holstered, so note that the bolt is not home for the next draw +void CWeaponSRS::BoltPhasesOnHolster() +{ + if (!IsReloadPhaseSystemEnabled() || !IsBoltPending()) + { + return; + } + + m_bNeedsBolting = true; + m_flBoltHomeTime = 0.0f; +} + bool CWeaponSRS::CanBePickedUpByClass(int classId) { return classId != NEO_CLASS_JUGGERNAUT; diff --git a/src/game/shared/neo/weapons/weapon_srs.h b/src/game/shared/neo/weapons/weapon_srs.h index b6c632f153..a7ef6f9422 100644 --- a/src/game/shared/neo/weapons/weapon_srs.h +++ b/src/game/shared/neo/weapons/weapon_srs.h @@ -37,6 +37,8 @@ class CWeaponSRS : public CNEOBaseCombatWeapon virtual bool Deploy() override; virtual void PrimaryAttack() override; virtual bool Reload(void) OVERRIDE; + virtual bool Holster(CBaseCombatWeapon *pSwitchingTo) OVERRIDE; + bool IsRoundChambered() const OVERRIDE; NEO_WEP_BITS_UNDERLYING_TYPE WeaponIndex() const override { return NEO_WIDX_SRS; } virtual NEO_WEP_BITS_UNDERLYING_TYPE GetNeoWepBits(void) const override { return NEO_WEP_SRS | NEO_WEP_SCOPEDWEAPON | NEO_WEP_FIREARM; } @@ -53,7 +55,25 @@ class CWeaponSRS : public CNEOBaseCombatWeapon private: CWeaponSRS(const CWeaponSRS &other); + // Whether the bolt cycle after a shot has not finished yet + bool IsBoltPending() const; + + // Bolt phases (sv_neo_reload_experimental); each hook does nothing with the flag off + bool BoltPhasesBlockShot() const; + bool BoltPhasesBlockReload() const; + void BoltPhasesOnShot(); + bool BoltPhasesDelayCycle() const; + void BoltPhasesOnCycle(); + bool BoltPhasesKeepCycle(); + void BoltPhasesOnDeploy(); + void BoltPhasesOnReload(); + void BoltPhasesOnHolster(); + CNetworkVar(bool, m_bNeedsBolting); + // The bolt is home, and a round chambered, at this time; 0: no bolt cycle is running + CNetworkVar(float, m_flBoltHomeTime); + // A bolt cycle resumed by a draw starts no earlier than this time + CNetworkVar(float, m_flBoltStartTime); }; #endif // NEO_WEAPON_SRS_H diff --git a/src/game/shared/neo/weapons/weapon_supa7.cpp b/src/game/shared/neo/weapons/weapon_supa7.cpp index d3ca85d258..bc07652f31 100644 --- a/src/game/shared/neo/weapons/weapon_supa7.cpp +++ b/src/game/shared/neo/weapons/weapon_supa7.cpp @@ -1,5 +1,6 @@ #include "cbase.h" #include "weapon_supa7.h" +#include "neo_gamerules.h" // memdbgon must be the last include file in a .cpp file!!! #include "tier0/memdbgon.h" @@ -12,12 +13,24 @@ BEGIN_NETWORK_TABLE(CWeaponSupa7, DT_WeaponSupa7) RecvPropBool(RECVINFO(m_bWeaponRaised)), RecvPropBool(RECVINFO(m_bShellInChamber)), RecvPropFloat(RECVINFO(m_flNextReload)), + RecvPropInt(RECVINFO(m_nTubeCount)), + RecvPropInt(RECVINFO(m_nTubeSlugs)), + RecvPropInt(RECVINFO(m_nChamber)), + RecvPropInt(RECVINFO(m_nInsert)), + RecvPropTime(RECVINFO(m_flInsertCreditTime)), + RecvPropTime(RECVINFO(m_flRackFeedTime)), #else SendPropBool(SENDINFO(m_bSlugDelayed)), SendPropBool(SENDINFO(m_bSlugLoaded)), SendPropBool(SENDINFO(m_bWeaponRaised)), SendPropBool(SENDINFO(m_bShellInChamber)), SendPropFloat(SENDINFO(m_flNextReload)), + SendPropInt(SENDINFO(m_nTubeCount), 4, SPROP_UNSIGNED), + SendPropInt(SENDINFO(m_nTubeSlugs), 8, SPROP_UNSIGNED), + SendPropInt(SENDINFO(m_nChamber), 2, SPROP_UNSIGNED), + SendPropInt(SENDINFO(m_nInsert), 2, SPROP_UNSIGNED), + SendPropTime(SENDINFO(m_flInsertCreditTime)), + SendPropTime(SENDINFO(m_flRackFeedTime)), #endif END_NETWORK_TABLE() @@ -28,6 +41,12 @@ BEGIN_PREDICTION_DATA(CWeaponSupa7) DEFINE_PRED_FIELD(m_bWeaponRaised, FIELD_BOOLEAN, FTYPEDESC_INSENDTABLE), DEFINE_PRED_FIELD(m_bShellInChamber, FIELD_BOOLEAN, FTYPEDESC_INSENDTABLE), DEFINE_PRED_FIELD(m_flNextReload, FIELD_FLOAT, FTYPEDESC_INSENDTABLE), + DEFINE_PRED_FIELD(m_nTubeCount, FIELD_INTEGER, FTYPEDESC_INSENDTABLE), + DEFINE_PRED_FIELD(m_nTubeSlugs, FIELD_INTEGER, FTYPEDESC_INSENDTABLE), + DEFINE_PRED_FIELD(m_nChamber, FIELD_INTEGER, FTYPEDESC_INSENDTABLE), + DEFINE_PRED_FIELD(m_nInsert, FIELD_INTEGER, FTYPEDESC_INSENDTABLE), + DEFINE_PRED_FIELD(m_flInsertCreditTime, FIELD_FLOAT, FTYPEDESC_INSENDTABLE), + DEFINE_PRED_FIELD(m_flRackFeedTime, FIELD_FLOAT, FTYPEDESC_INSENDTABLE), END_PREDICTION_DATA() #endif @@ -42,6 +61,12 @@ BEGIN_DATADESC(CWeaponSupa7) DEFINE_FIELD(m_bWeaponRaised, FIELD_BOOLEAN), DEFINE_FIELD(m_bShellInChamber, FIELD_BOOLEAN), DEFINE_FIELD(m_flNextReload, FIELD_FLOAT), + DEFINE_FIELD(m_nTubeCount, FIELD_INTEGER), + DEFINE_FIELD(m_nTubeSlugs, FIELD_INTEGER), + DEFINE_FIELD(m_nChamber, FIELD_INTEGER), + DEFINE_FIELD(m_nInsert, FIELD_INTEGER), + DEFINE_FIELD(m_flInsertCreditTime, FIELD_TIME), + DEFINE_FIELD(m_flRackFeedTime, FIELD_TIME), END_DATADESC() #endif @@ -65,6 +90,13 @@ IMPLEMENT_ACTTABLE(CWeaponSupa7); #endif #endif +// Viewmodel frames of the shipped team models, which play at this rate +static constexpr float VM_FRAMES_PER_SECOND = 30.0f; +// reloadinsert: the hatch closes behind the round, which is then in the tube +static constexpr float INSERT_ROUND_IN_TUBE_TIME = 12.0f / VM_FRAMES_PER_SECOND; +// reloadend: the pump is forward again with the next round chambered +static constexpr float RACK_PUMP_HOME_TIME = 21.0f / VM_FRAMES_PER_SECOND; + CWeaponSupa7::CWeaponSupa7(void) { m_bReloadsSingly = true; @@ -73,6 +105,12 @@ CWeaponSupa7::CWeaponSupa7(void) m_bWeaponRaised = false; m_bShellInChamber = true; m_flNextReload = 0.0f; + m_nTubeCount = 0; + m_nTubeSlugs = 0; + m_nChamber = SUPA7_CHAMBER_EMPTY; + m_nInsert = SUPA7_INSERT_NONE; + m_flInsertCreditTime = 0.0f; + m_flRackFeedTime = 0.0f; m_fMinRange1 = 0.0; m_fMaxRange1 = 500; @@ -90,7 +128,8 @@ CWeaponSupa7::CWeaponSupa7(void) // Purpose: Override so only reload one shell at a time bool CWeaponSupa7::StartReload(void) { - if (m_bSlugLoaded) + // the tube takes shells behind a chambered slug + if (m_bSlugLoaded && !IsTubeEnabled()) return false; CBaseCombatCharacter* pOwner = GetOwner(); @@ -116,6 +155,11 @@ bool CWeaponSupa7::StartReload(void) if (m_iClip1 >= GetMaxClip1()) return false; + if (!TubePhasesOnStart()) + { + return false; + } + SendWeaponAnim(ACT_SHOTGUN_RELOAD_START); SetShotgunShellVisible(true); @@ -147,6 +191,11 @@ bool CWeaponSupa7::StartReloadSlug(void) if (m_iClip1 >= GetMaxClip1()) return false; + if (!TubePhasesOnStartSlug()) + { + return false; + } + if (!m_bInReload) { SendWeaponAnim(ACT_SHOTGUN_RELOAD_START); @@ -185,10 +234,16 @@ bool CWeaponSupa7::Reload(void) if (m_iClip1 >= GetMaxClip1()) return false; + if (IsTubeFull()) + { + return false; + } + // Play reload on different channel as otherwise steals channel away from fire sound WeaponSound(SPECIAL1); SendWeaponAnim(ACT_VM_RELOAD); pOwner->DoAnimationEvent(PLAYERANIMEVENT_RELOAD); + StartInsert(SUPA7_INSERT_SHELL); pOwner->m_flNextAttack = gpGlobals->curtime; constexpr float TIME_BETWEEN_SHELLS_LOADED = 0.5f; @@ -222,13 +277,23 @@ bool CWeaponSupa7::ReloadSlug(void) if (m_iClip1 >= GetMaxClip1()) return false; - FillClipSlug(); - m_bShellInChamber = false; + if (IsTubeFull()) + { + return false; + } + + // the tube takes the slug only once it is in + if (!IsTubeEnabled()) + { + FillClipSlug(); + m_bShellInChamber = false; + } // Play reload on different channel as otherwise steals channel away from fire sound WeaponSound(SPECIAL1); SendWeaponAnim(ACT_VM_RELOAD); pOwner->DoAnimationEvent(PLAYERANIMEVENT_RELOAD); + StartInsert(SUPA7_INSERT_SLUG); pOwner->m_flNextAttack = gpGlobals->curtime; // ProposeNextAttack(gpGlobals->curtime + SequenceDuration()); @@ -249,6 +314,11 @@ void CWeaponSupa7::FinishReload(void) m_bInReload = false; + if (TubePhasesOnFinish()) + { + return; + } + // Finish reload animation if (!m_bShellInChamber) { @@ -317,6 +387,11 @@ void CWeaponSupa7::PrimaryAttack(void) return; } + if (!TubePhasesCanFire()) + { + return; + } + int numBullets = GetNEOWpnData().m_iBullets; Vector bulletSpread = GetBulletSpread(); int ammoType = m_iPrimaryAmmoType; @@ -361,6 +436,7 @@ void CWeaponSupa7::PrimaryAttack(void) { m_bShellInChamber = false; } + TubePhasesOnShot(); // player "shoot" animation pPlayer->DoAnimationEvent(PLAYERANIMEVENT_ATTACK_PRIMARY); @@ -401,6 +477,8 @@ void CWeaponSupa7::ClearDelayedInputs(void) // for not having to do a larger rewrite. m_bInReload.GetForModify() = false; + TubePhasesOnDrop(); + SetShotgunShellVisible(false); } @@ -413,6 +491,7 @@ void CWeaponSupa7::ItemPostFrame(void) return; } ProcessAnimationEvents(); + TubePhasesOnFrame(); if (m_bInReload) { @@ -433,7 +512,7 @@ void CWeaponSupa7::ItemPostFrame(void) m_bSlugDelayed.GetForModify() = false; } } - else + else if (!TubePhasesOnNextInsert()) { // If out of ammo end reload if ((m_iPrimaryAmmoCount <= 0 || m_bSlugLoaded || m_iClip1 >= GetMaxClip1())) @@ -475,6 +554,10 @@ void CWeaponSupa7::ItemPostFrame(void) { DryFire(); } + else if (TubePhasesNeedRack()) + { + StartRack(); + } // Fire underwater? else if (pOwner->GetWaterLevel() == WL_Eyes && !m_bFiresUnderwater) { @@ -497,7 +580,10 @@ void CWeaponSupa7::ItemPostFrame(void) if (!(pOwner->m_nButtons & IN_ATTACK) && m_flNextPrimaryAttack <= gpGlobals->curtime && pOwner->m_nButtons & IN_RELOAD && UsesClipsForAmmo1() && !m_bInReload) { // reload when reload is pressed, or if no buttons are down and weapon is empty. - StartReload(); + if (!StartReload()) + { + TubePhasesOnReloadPress(); + } } else if (!(pOwner->m_nButtons & IN_ATTACK) && m_flNextPrimaryAttack <= gpGlobals->curtime && pOwner->m_nButtons & IN_ATTACK2 && UsesClipsForAmmo1() && !m_bInReload) { @@ -525,6 +611,357 @@ void CWeaponSupa7::ItemPostFrame(void) } } +bool CWeaponSupa7::IsTubeEnabled() const +{ + return NEORules() && NEORules()->IsReloadExperimental(); +} + +bool CWeaponSupa7::IsTubeFull() const +{ + return IsTubeEnabled() && m_nTubeCount >= TubeCapacity(); +} + +// Returns whether the shell reload may start +bool CWeaponSupa7::TubePhasesOnStart() +{ + if (!IsTubeEnabled()) + { + return true; + } + + SyncTube(); + if (IsTubeFull()) + { + return false; + } + + m_nInsert = SUPA7_INSERT_NONE; + return true; +} + +// One slug per request: a held alt-fire neither queues another nor delays the shot +bool CWeaponSupa7::TubePhasesOnStartSlug() +{ + if (!IsTubeEnabled()) + { + return true; + } + + if (m_bSlugDelayed || m_nInsert == SUPA7_INSERT_SLUG) + { + return false; + } + + SyncTube(); + return !IsTubeFull(); +} + +// A round still in the hand goes back to the reserve; an empty chamber is racked before the next shot. +// Returns whether the tube finished the reload +bool CWeaponSupa7::TubePhasesOnFinish() +{ + CBaseCombatCharacter *pOwner = GetOwner(); + if (!IsTubeEnabled() || !pOwner) + { + return false; + } + + CancelInsert(); + SyncTube(); + if (!IsChamberLive() && m_nTubeCount > 0) + { + StartRack(); + } + else + { + SendWeaponAnim(ACT_SHOTGUN_RELOAD_FINISH); + } + pOwner->m_flNextAttack = gpGlobals->curtime; + return true; +} + +bool CWeaponSupa7::TubePhasesCanFire() +{ + if (!IsTubeEnabled()) + { + return true; + } + + SyncTube(); + return IsChamberLive(); +} + +// The fire animation's pump ejects the hull and feeds the tube's last-loaded round; the tube then sets the clip +void CWeaponSupa7::TubePhasesOnShot() +{ + if (!IsTubeEnabled()) + { + return; + } + + m_nChamber = SUPA7_CHAMBER_HULL; + FeedChamber(); +} + +// A rack or insert cut off by the drop does nothing for the next owner +void CWeaponSupa7::TubePhasesOnDrop() +{ + if (!IsTubeEnabled()) + { + return; + } + + CancelInsert(); + m_flRackFeedTime = 0.0f; +} + +void CWeaponSupa7::TubePhasesOnFrame() +{ + if (!IsTubeEnabled()) + { + return; + } + + SyncTube(); + RunInsert(); + RunRack(); +} + +// The next shell of a reload; a slug insert ends the reload, as it does without the tube. +// Returns whether the tube handled the step +bool CWeaponSupa7::TubePhasesOnNextInsert() +{ + if (!IsTubeEnabled()) + { + return false; + } + + const bool bSlugInserted = (m_nInsert == SUPA7_INSERT_SLUG); + m_nInsert = SUPA7_INSERT_NONE; + if (m_iPrimaryAmmoCount <= 0 || bSlugInserted || IsTubeFull() || !Reload()) + { + FinishReload(); + } + return true; +} + +// Rounds in the tube and none in the chamber: the trigger racks one up first +bool CWeaponSupa7::TubePhasesNeedRack() const +{ + return IsTubeEnabled() && !IsChamberLive(); +} + +// With nothing to load, a reload press racks up a round for an empty chamber +void CWeaponSupa7::TubePhasesOnReloadPress() +{ + CBasePlayer *pOwner = ToBasePlayer(GetOwner()); + if (!IsTubeEnabled() || !pOwner || !(pOwner->m_afButtonPressed & IN_RELOAD)) + { + return; + } + + if (!IsChamberLive() && m_nTubeCount > 0) + { + StartRack(); + } +} + +// Credited rounds stay in the tube; a round still in the hand and a rack before its pump is home do nothing +void CWeaponSupa7::TubePhasesOnHolster() +{ + if (!IsTubeEnabled()) + { + return; + } + + CancelInsert(); + m_flRackFeedTime = 0.0f; + m_bSlugDelayed = false; +} + +// Rebuild the tube from the clip count when something set the count directly (a new or picked-up gun, a give): +// a live round in the chamber, shells in the tube +void CWeaponSupa7::SyncTube() +{ + if (IsTubeSynced()) + { + return; + } + + const int iClip = Clamp(m_iClip1.Get(), 0, GetMaxClip1()); + m_nChamber = (iClip > 0) ? (m_bSlugLoaded ? SUPA7_CHAMBER_SLUG : SUPA7_CHAMBER_SHELL) : SUPA7_CHAMBER_EMPTY; + m_nTubeCount = Max(0, iClip - SUPA7_CHAMBER_ROUNDS); + m_nTubeSlugs = 0; + UpdateClipFromTube(); +} + +void CWeaponSupa7::TubePush(Supa7Insert_t round) +{ + if (m_nTubeCount >= TubeCapacity()) + { + return; + } + + if (round == SUPA7_INSERT_SLUG) + { + m_nTubeSlugs |= (1 << m_nTubeCount); + } + else + { + m_nTubeSlugs &= ~(1 << m_nTubeCount); + } + m_nTubeCount += 1; + UpdateClipFromTube(); +} + +// The pump ejects a hull and feeds the tube's last-loaded round; a live round stays where it is +void CWeaponSupa7::FeedChamber() +{ + if (IsChamberLive()) + { + return; + } + + if (m_nTubeCount <= 0) + { + m_nChamber = SUPA7_CHAMBER_EMPTY; + UpdateClipFromTube(); + return; + } + + m_nTubeCount -= 1; + const bool bSlug = (m_nTubeSlugs & (1 << m_nTubeCount)) != 0; + m_nTubeSlugs &= ~(1 << m_nTubeCount); + m_nChamber = bSlug ? SUPA7_CHAMBER_SLUG : SUPA7_CHAMBER_SHELL; + UpdateClipFromTube(); +} + +// The counts the rest of the game reads: live rounds in the gun, and the chambered round's type +void CWeaponSupa7::UpdateClipFromTube() +{ + m_iClip1 = m_nTubeCount + (IsChamberLive() ? 1 : 0); + m_bSlugLoaded = (m_nChamber == SUPA7_CHAMBER_SLUG); + m_bShellInChamber = IsChamberLive(); +} + +// The reserve gives up the round only when it is in the tube, so an insert cut off before then costs nothing +void CWeaponSupa7::StartInsert(Supa7Insert_t round) +{ + if (!IsTubeEnabled()) + { + return; + } + + m_nInsert = round; + m_flInsertCreditTime = gpGlobals->curtime + INSERT_ROUND_IN_TUBE_TIME; +} + +void CWeaponSupa7::RunInsert() +{ + if (m_flInsertCreditTime <= 0.0f || gpGlobals->curtime < m_flInsertCreditTime) + { + return; + } + + m_flInsertCreditTime = 0.0f; + if (m_nTubeCount >= TubeCapacity()) + { + return; + } + + if (m_nInsert == SUPA7_INSERT_SLUG && m_iSecondaryAmmoCount > 0) + { + TubePush(SUPA7_INSERT_SLUG); + m_iSecondaryAmmoCount -= 1; + } + else if (m_nInsert == SUPA7_INSERT_SHELL && m_iPrimaryAmmoCount > 0) + { + TubePush(SUPA7_INSERT_SHELL); + m_iPrimaryAmmoCount -= 1; + } +} + +void CWeaponSupa7::CancelInsert() +{ + m_nInsert = SUPA7_INSERT_NONE; + m_flInsertCreditTime = 0.0f; +} + +// The shipped reload's finishing rack, also played alone: the gun fires only once it ends +void CWeaponSupa7::StartRack() +{ + CBaseCombatCharacter *pOwner = GetOwner(); + if (!pOwner) + { + return; + } + + SendWeaponAnim(ACT_SHOTGUN_PUMP); + WeaponSound(SPECIAL2); + + const float flDuration = ViewModelSequenceDuration(); + m_flRackFeedTime = gpGlobals->curtime + Min(RACK_PUMP_HOME_TIME, flDuration); + pOwner->m_flNextAttack = gpGlobals->curtime; + ProposeNextAttack(gpGlobals->curtime + flDuration); + SetWeaponIdleTime(gpGlobals->curtime + flDuration); +} + +void CWeaponSupa7::RunRack() +{ + if (m_flRackFeedTime <= 0.0f || gpGlobals->curtime < m_flRackFeedTime) + { + return; + } + + m_flRackFeedTime = 0.0f; + FeedChamber(); +} + +// The viewmodel plays the sequence; the weapon entity can carry the world model on the client +float CWeaponSupa7::ViewModelSequenceDuration() const +{ + CBasePlayer *pOwner = ToBasePlayer(GetOwner()); + CBaseViewModel *pVM = pOwner ? pOwner->GetViewModel(m_nViewModelIndex) : nullptr; + return pVM ? pVM->SequenceDuration() : 0.0f; +} + +bool CWeaponSupa7::Holster(CBaseCombatWeapon *pSwitchingTo) +{ + TubePhasesOnHolster(); + return BaseClass::Holster(pSwitchingTo); +} + +bool CWeaponSupa7::HasChamberSlot() const +{ + return IsTubeEnabled() || BaseClass::HasChamberSlot(); +} + +bool CWeaponSupa7::IsRoundChambered() const +{ + if (!IsTubeEnabled()) + { + return BaseClass::IsRoundChambered(); + } + + // before the first update rebuilds the tube from a new clip count, a loaded gun has a round chambered + return IsTubeSynced() ? IsChamberLive() : (m_iClip1 > 0); +} + +int CWeaponSupa7::RoundsInMagazine() const +{ + if (!IsTubeEnabled()) + { + return BaseClass::RoundsInMagazine(); + } + + return IsTubeSynced() ? m_nTubeCount.Get() : Max(0, m_iClip1 - SUPA7_CHAMBER_ROUNDS); +} + +int CWeaponSupa7::MagazineCapacity() const +{ + return IsTubeEnabled() ? TubeCapacity() : BaseClass::MagazineCapacity(); +} + const WeaponSpreadInfo_t &CWeaponSupa7::GetSpreadInfo() { Assert(m_weaponHandling.weaponID & GetNeoWepBits()); diff --git a/src/game/shared/neo/weapons/weapon_supa7.h b/src/game/shared/neo/weapons/weapon_supa7.h index f585f15803..78eb837911 100644 --- a/src/game/shared/neo/weapons/weapon_supa7.h +++ b/src/game/shared/neo/weapons/weapon_supa7.h @@ -63,6 +63,30 @@ class CWeaponSupa7 : public CNEOBaseCombatWeapon void ClearDelayedInputs(void); bool CanBePickedUpByClass(int classId) OVERRIDE; + bool Holster(CBaseCombatWeapon *pSwitchingTo) OVERRIDE; + + // Clip1 stays the live rounds in the gun: the tube plus the chambered round + bool HasChamberSlot() const OVERRIDE; + bool IsRoundChambered() const OVERRIDE; + int RoundsInMagazine() const OVERRIDE; + int MagazineCapacity() const OVERRIDE; + + // What sits in the chamber: a live shell or slug, the hull of a fired one, or nothing + enum Supa7Chamber_t + { + SUPA7_CHAMBER_EMPTY = 0, + SUPA7_CHAMBER_SHELL, + SUPA7_CHAMBER_SLUG, + SUPA7_CHAMBER_HULL, + }; + + // The round in the hand of the insert that is playing + enum Supa7Insert_t + { + SUPA7_INSERT_NONE = 0, + SUPA7_INSERT_SHELL, + SUPA7_INSERT_SLUG, + }; protected: virtual float GetFastestDryRefireTime() const OVERRIDE { return 0.2f; } @@ -77,6 +101,36 @@ class CWeaponSupa7 : public CNEOBaseCombatWeapon } } + bool IsTubeEnabled() const; + bool IsTubeFull() const; + + // Tube phases (sv_neo_reload_experimental); each hook does nothing with the flag off + bool TubePhasesOnStart(); + bool TubePhasesOnStartSlug(); + bool TubePhasesOnFinish(); + bool TubePhasesCanFire(); + void TubePhasesOnShot(); + void TubePhasesOnDrop(); + void TubePhasesOnFrame(); + bool TubePhasesOnNextInsert(); + bool TubePhasesNeedRack() const; + void TubePhasesOnReloadPress(); + void TubePhasesOnHolster(); + + bool IsChamberLive() const { return m_nChamber == SUPA7_CHAMBER_SHELL || m_nChamber == SUPA7_CHAMBER_SLUG; } + bool IsTubeSynced() const { return m_nTubeCount + (IsChamberLive() ? 1 : 0) == m_iClip1; } + int TubeCapacity() const { return GetMaxClip1() - SUPA7_CHAMBER_ROUNDS; } + void SyncTube(); + void TubePush(Supa7Insert_t round); + void FeedChamber(); + void UpdateClipFromTube(); + void StartInsert(Supa7Insert_t round); + void RunInsert(); + void CancelInsert(); + void StartRack(); + void RunRack(); + float ViewModelSequenceDuration() const; + void SetShotgunShellVisible(bool is_visible) { const int bodygroup_shell = 1; @@ -91,6 +145,15 @@ class CWeaponSupa7 : public CNEOBaseCombatWeapon CNetworkVar(bool, m_bShellInChamber); // Slug currently loaded in chamber CNetworkVar(float, m_flNextReload); // Time to load the next shell + // sv_neo_reload_experimental: the tube is a stack, the last round loaded is the first fed + static constexpr int SUPA7_CHAMBER_ROUNDS = 1; + CNetworkVar(int, m_nTubeCount); // rounds in the tube + CNetworkVar(int, m_nTubeSlugs); // bit i: the round at tube position i (0 = loaded first) is a slug + CNetworkVar(int, m_nChamber); // Supa7Chamber_t + CNetworkVar(int, m_nInsert); // Supa7Insert_t + CNetworkVar(float, m_flInsertCreditTime); // when the inserted round enters the tube, 0 none + CNetworkVar(float, m_flRackFeedTime); // when the rack's pump is home with the next round, 0 none + private: CWeaponSupa7(const CWeaponSupa7 &other); };