Skip to content

Commit

Permalink
Weapon SFX variation POC
Browse files Browse the repository at this point in the history
  • Loading branch information
phobos2077 committed Jul 17, 2024
1 parent 4cf1205 commit 1cadded
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 2 deletions.
8 changes: 6 additions & 2 deletions scripts_src/_pbs_main/gl_pbs_awareness_expanded.ssl
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,12 @@ end

procedure stdprocedure_end_hook begin
variable proc := get_sfall_arg, obj := get_sfall_arg;
if (proc == description_proc and obj != dude_obj and obj_type(obj) == OBJ_TYPE_CRITTER
and dude_perk(PERK_bonus_awareness) and not is_critter_dead(obj)) then begin
if (proc == description_proc
and combat_is_initialized
and obj != dude_obj
and obj_type(obj) == OBJ_TYPE_CRITTER
and dude_perk(PERK_bonus_awareness)
and not is_critter_dead(obj)) then begin
variable
//dmgType := obj_pid get_active_weapon(dude_obj)
ac := get_critter_stat(obj, STAT_ac),
Expand Down
96 changes: 96 additions & 0 deletions scripts_src/_pbs_main/gl_weapon_sfx_variation.ssl
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
#include "../sfall/sfall.h"
#include "../sfall/lib.arrays.h"
#include "../sfall/define_lite.h"
#include "../sfall/define_extra.h"

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

variable snd_lookup_weapon_type;

#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)

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

procedure material_code_by_material(variable material) begin
if (material == MATERIAL_TYPE_GLASS or material == MATERIAL_TYPE_METAL or material == MATERIAL_TYPE_PLASTIC) then
return 'M';

if (material == MATERIAL_TYPE_WOOD) then
return 'W';

if (material == MATERIAL_TYPE_DIRT or material == MATERIAL_TYPE_STONE or material == MATERIAL_TYPE_CEMENT) then
return 'S';

return 'F';
end

procedure buildsfxname_handler begin
if (get_sfall_arg != 1) 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
]);

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

if (effectType != WEAPON_SOUND_EFFECT_READY and effectType != WEAPON_SOUND_EFFECT_OUT_OF_AMMO) then begin
attackTypeCode := 2
if attackType != ATKTYPE_LWEP1 and attackType != ATKTYPE_RWEP1 and attackType != ATKTYPE_PUNCH
else 1;
end else
attackTypeCode := 1;

if (effectTypeCode != 'H' or target == 0 or item_w_is_grenade(weapon)) then begin
materialCode = 'X';
end else begin
variable type := obj_type(target), targetPid := obj_pid(target), material;
switch (type) begin
case OBJ_TYPE_ITEM:
material := get_proto_data(targetPid, PROTO_IT_MATERIAL);
case OBJ_TYPE_SCENERY:
material := get_proto_data(targetPid, PROTO_SC_MATERIAL);
case OBJ_TYPE_WALL:
material := get_proto_data(targetPid, PROTO_WL_MATERIAL);
default:
material := -1;
end
materialCode := material_code_by_material(material);
end

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

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);
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");
end

0 comments on commit 1cadded

Please sign in to comment.