Skip to content

Commit

Permalink
Weapon sound variations (configurable)
Browse files Browse the repository at this point in the history
  • Loading branch information
phobos2077 committed Jul 18, 2024
1 parent 1cadded commit 024702c
Show file tree
Hide file tree
Showing 2 changed files with 228 additions and 19 deletions.
166 changes: 166 additions & 0 deletions root/data/config/sfx_weapon.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
[variant_code]
; Unlocks variations of sound for same effects (present in vanilla master.dat since FO1)
; Format: <SoundCode>_<EffectType><AttackType>=<Variant1>,...,<VariantN>
; where:
; - SoundCode - sound code from weapon proto, as a number
; - EffectType - one of: R (reload), A (attack), O (out of ammo), F (firing), H (hit)
; - AttackType - 1 (primary) or 2 (secondary)
; - VariantN - single digit 1..9 variant code (the last digit in the sfx file name)

; # Pulse pistol
35_H1=1,2

; $ End Boss Knife
36_A1=1,2
36_A2=1,2
36_H1=1,2
36_H2=1,2

; @ End Boss Plasma Gun
64_A1=1,2
64_A2=1,2
64_H1=1,2
64_H2=1,2

; 0 Ripper
48_A1=1,2
48_A2=1,2

; 2 Rock
50_A1=1,2
50_H1=1,2

; 3 Knife
51_A1=1,2
51_A2=1,2

; 4 Throwing Knife
52_A2=1,2

; 5 Crowbar/Wrench
53_A1=1,2

; 6 Club/Luiseville Slugger
54_A1=1,2

; 7 Sledge
55_A1=1,2

; 8 Spear
56_A1=1,2

; 9 Cattle Prod
57_A1=1,2

; A 10mm Pistol
65_A1=1,2
65_H1=1,2

; B .44 Desert Eagle/Revolver
66_A1=1,2
66_H1=1,2

; C Laser Pistol
67_A1=1,2
67_H1=1,2

; D 10mm SMG
68_A1=1,2
68_A2=1,2
68_H1=1,2
68_H2=1,2

; E 14mm/.223 Pistol
69_A1=1,2
69_H1=1,2

; F Plasma Pistol
;70_A1=1,2

; G Hunting/Sniper Rifle
;71_A1=1,2
71_H1=1,2

; H Assault Rifle
72_A1=1,2
72_H1=1,2
72_H2=1,2

; I Flamer
;73_A1=1,2

; J Laser Rifle
74_A1=1,2
74_H1=1,2

; K Plasma Rifle
;75_A1=1,2

; L Minigun
76_A1=1,2
76_H1=1,2

; M Gatling Laser
;77_A1=1,2
77_H1=1,2

; N Rocket Launcher
78_A1=1,2

; O Grenade (frag)
79_H1=1,2

; R Shotgun
;82_A1=1,2
82_H1=1,2

; S Alien Blaster
83_A1=1,2
83_H1=1,2

; U BB Gun
85_A1=1,2
85_H1=1,2

; V Zip Gun
86_A1=1,2
86_H1=1,2

; W Gauss Rifle
87_A1=1,2
87_H1=1,2

; X Pulse Rifle
88_A1=1,2
88_H1=1,2

; Y Gauss Pistol
89_A1=1,2
89_H1=1,2

; Z Needler Pistol
90_A1=1,2
90_H1=1,2


[variant_pid]
; Same as variant_code but looks up by weapon PID instead.
; Format: <PID>_<EffectType><AttackType>[<Material>]=<Variant1>,...,<VariantN>

; R Shotgun/Sawed-Off duplet fire
94_A2=2
385_A2=2

; E .223 Pistol classic FO1 BLAM!
241_A1=3

; H HK G11E Longer Burst
391_A2=2


[reuse_pid]
; WIP!!
; Allows weapons with one sound code to reuse certain effect types from another weapon (useful to fill in, e.g. burst hit sounds).
; Format: <PID>_<EffectType><AttackType>=<SoundCode>

;94_H2=
81 changes: 62 additions & 19 deletions scripts_src/_pbs_main/gl_weapon_sfx_variation.ssl
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,58 @@
#include "../sfall/define_lite.h"
#include "../sfall/define_extra.h"

#define SCRIPT_REALNAME "weapon_sfx_variation"

#include "../_pbs_headers/ecco_log.h"

#include "../_pbs_headers/engine_funcs.h"

variable snd_lookup_weapon_type;
variable begin
config_is_loaded;
sfx_config;
variations_code;
variations_pid;
snd_lookup_weapon_type;
end

#define WEAPON_SOUND_EFFECT_READY (0)
#define WEAPON_SOUND_EFFECT_ATTACK (1)
#define WEAPON_SOUND_EFFECT_OUT_OF_AMMO (2)
#define WEAPON_SOUND_EFFECT_AMMO_FLYING (3)
#define WEAPON_SOUND_EFFECT_HIT (4)

#define CONFIG_PATH "config\\sfx_weapon.ini"

procedure load_config begin
if (config_is_loaded) then return sfx_config;

sfx_config := get_ini_config_db(CONFIG_PATH);

if (not sfx_config) then begin
debug_err("Failed to load config " CONFIG_PATH);
return;
end

/*variable section := sfx_config.code_variations;
variations_code := create_array_map;
if (section) then begin
foreach (variable k: v in section) begin
variations_code[k] :=
end
end*/

snd_lookup_weapon_type := array_fixed([
'R', // Ready/Reload
'A', // Attack
'O', // Out of ammo
'F', // Firing
'H' // Hit
]);

config_is_loaded := true;
return sfx_config;
end

procedure item_w_is_grenade(variable weapon) begin
variable damageType := item_w_damage_type(0, weapon);
return damageType == DMG_explosion or damageType == DMG_plasma or damageType == DMG_emp;
Expand All @@ -31,26 +73,19 @@ procedure material_code_by_material(variable material) begin
return 'F';
end

procedure buildsfxname_handler begin
if (get_sfall_arg != 1) then return;
procedure buildsfxweapon_handler begin
if (not load_config) then return;

variable
effectType := get_sfall_arg,
weapon := get_sfall_arg,
attackType := get_sfall_arg,
target := get_sfall_arg;

variable attackTypeCode, weaponSoundCode, effectTypeCode, materialCode, variantCode, result;

if (not snd_lookup_weapon_type) then
snd_lookup_weapon_type := array_fixed([
'R', // Ready/Reload
'A', // Attack
'O', // Out of ammo
'F', // Firing
'H' // Hit
]);
variable effectTypeCode, weaponSoundCode, attackTypeCode, materialCode, variantCode,
weaponPid, result, configKey, variantList;

weaponPid := obj_pid(weapon);
weaponSoundCode := get_proto_data(obj_pid(weapon), PROTO_WP_SOUND) bwand 0xFF;
effectTypeCode := snd_lookup_weapon_type[effectType];

Expand All @@ -61,6 +96,16 @@ procedure buildsfxname_handler begin
end else
attackTypeCode := 1;

configKey := string_format("%d_%c%1d", weaponPid, effectTypeCode, attackTypeCode);
variantList := sfx_config.variant_pid[configKey];
if (not variantList) then begin
configKey := string_format("%d_%c%1d", weaponSoundCode, effectTypeCode, attackTypeCode);
variantList := sfx_config.variant_code[configKey];
if (not variantList) then return;
end

variantList := string_split_ints(variantList, ",");

if (effectTypeCode != 'H' or target == 0 or item_w_is_grenade(weapon)) then begin
materialCode = 'X';
end else begin
Expand All @@ -78,19 +123,17 @@ procedure buildsfxname_handler begin
materialCode := material_code_by_material(material);
end

variantCode := random(1, 2)
if effectType == WEAPON_SOUND_EFFECT_ATTACK
else 1;
variantCode := array_random_value(variantList);

result := string_format("W%c%c%1d%cXX%1d", effectTypeCode, weaponSoundCode, attackTypeCode, materialCode, variantCode);

display_msg("gsnd_build_weapon_sfx_name hook for " + obj_name(weapon) + ", effect: "+ effectType + ", result: " + result);
debug_log("gsnd_build_weapon_sfx_name hook for " + obj_name(weapon) + ", effect: "+ effectType + ", result: " + result);
set_sfall_return(result);
end

procedure start begin
if (not game_loaded) then return;

register_hook_proc(HOOK_BUILDSFXNAME, buildsfxname_handler);
display_msg("Registered buildsfxname");
register_hook_proc(HOOK_BUILDSFXWEAPON, buildsfxweapon_handler);
debug_log("Initialized.");
end

0 comments on commit 024702c

Please sign in to comment.