Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HITFEEDBACK: Better hit sound feedback
Browse files Browse the repository at this point in the history
This should offer better hit sound feedback inspired by Q3 Team Arena.

- when opponent has >50 shield points, a more light hit sound indicating less impact is played
- when opponent has no shield points left, a more fleshy hit sound indicating highest impact is played (fleshy sound is the former friendly fire hit sound)
- for everything else the known default hit sound is played
- adds new cvar cg_advHitSounds [0/1] to enable/disable this feature, default is 0 (off)
- adds a new menu entry in options/game to enable/disable this feature via the menu
- adds a new beep hit sound to indicate friendly fire at teammates when the server has friendly fire enabled
kai-li-wop committed Nov 8, 2023
1 parent 7ee409a commit 8647a77
Showing 9 changed files with 48 additions and 4 deletions.
5 changes: 3 additions & 2 deletions code/cgame/cg_local.h
Original file line number Diff line number Diff line change
@@ -1032,8 +1032,8 @@ typedef struct {
sfxHandle_t oneLifeSound;

sfxHandle_t hitSound;
sfxHandle_t hitSoundHighArmor;
sfxHandle_t hitSoundLowArmor;
sfxHandle_t hitShieldSound;
sfxHandle_t hitNoShieldSound;
sfxHandle_t hitTeamSound;
sfxHandle_t excellentSound;
sfxHandle_t snackattackSound;
@@ -1318,6 +1318,7 @@ extern vmCvar_t cg_cineDrawLetterBox;

extern vmCvar_t cg_glowModel;
extern vmCvar_t cg_glowModelTeam;
extern vmCvar_t cg_advHitSound;

extern vmCvar_t cg_warmupReady;
extern vmCvar_t cg_curWarmupReady;
4 changes: 4 additions & 0 deletions code/cgame/cg_main.c
Original file line number Diff line number Diff line change
@@ -184,6 +184,7 @@ vmCvar_t cg_cineDrawLetterBox;

vmCvar_t cg_glowModel;
vmCvar_t cg_glowModelTeam;
vmCvar_t cg_advHitSound;

vmCvar_t cg_warmupReady;
vmCvar_t cg_curWarmupReady;
@@ -322,6 +323,7 @@ static cvarTable_t cvarTable[] = { // bk001129

{&cg_glowModel, "cg_glowModel", "", CVAR_ARCHIVE},
{&cg_glowModelTeam, "cg_glowModelTeam", "", CVAR_ARCHIVE},
{&cg_advHitSound, "cg_advHitSound", "0", CVAR_ARCHIVE},

/* NOTE: We can't easily extend CS_WARMUP as SV_MapRestart_f() directly sets it */
{&cg_warmupReady, "g_warmupReady", "", CVAR_SYSTEMINFO},
@@ -753,6 +755,8 @@ static void CG_RegisterSounds(void) {
cgs.media.landSound = trap_S_RegisterSound("sound/padplayer/land", qfalse);

cgs.media.hitSound = trap_S_RegisterSound("sound/feedback/hit", qfalse);
cgs.media.hitShieldSound = trap_S_RegisterSound("sound/feedback/hit_shield", qfalse );
cgs.media.hitNoShieldSound = trap_S_RegisterSound("sound/feedback/hit_noshield", qfalse );

cgs.media.excellentSound = trap_S_RegisterSound("sound/feedback/awards/excellent", qtrue);
cgs.media.snackattackSound = trap_S_RegisterSound("sound/feedback/awards/snackattack", qtrue);
13 changes: 12 additions & 1 deletion code/cgame/cg_playerstate.c
Original file line number Diff line number Diff line change
@@ -256,6 +256,8 @@ CG_CheckLocalSounds
==================
*/
static void CG_CheckLocalSounds(playerState_t *ps, playerState_t *ops) {
int health, armor;
int advHitSound;
qboolean reward = qfalse;

// don't play the sounds if the player just changed teams
@@ -265,7 +267,16 @@ static void CG_CheckLocalSounds(playerState_t *ps, playerState_t *ops) {

// hit changes
if (ps->persistant[PERS_HITS] > ops->persistant[PERS_HITS]) {
trap_S_StartLocalSound(cgs.media.hitSound, CHAN_LOCAL_SOUND);
armor = ps->persistant[PERS_ATTACKEE_ARMOR] & 0xff;
health = ps->persistant[PERS_ATTACKEE_ARMOR] >> 8;
advHitSound = cg_advHitSound.integer;
if (armor > 50 && advHitSound) {
trap_S_StartLocalSound(cgs.media.hitShieldSound, CHAN_LOCAL_SOUND);
} else if (!armor && advHitSound) {
trap_S_StartLocalSound(cgs.media.hitNoShieldSound, CHAN_LOCAL_SOUND);
} else {
trap_S_StartLocalSound(cgs.media.hitSound, CHAN_LOCAL_SOUND);
}
} else if (ps->persistant[PERS_HITS] < ops->persistant[PERS_HITS]) {
trap_S_StartLocalSound(cgs.media.hitTeamSound, CHAN_LOCAL_SOUND);
}
1 change: 1 addition & 0 deletions code/game/bg_public.h
Original file line number Diff line number Diff line change
@@ -291,6 +291,7 @@ typedef enum {
PERS_SPAWN_COUNT, // incremented every respawn
PERS_PLAYEREVENTS, // 16 bits that can be flipped for events
PERS_ATTACKER, // clientnum of last damage inflicter
PERS_ATTACKEE_ARMOR, // health/armor of last person we attacked
PERS_KILLED, // count of the number of times you died
// player awards tracking
PERS_EXCELLENT_COUNT, // two successive kills in a short amount of time
1 change: 1 addition & 0 deletions code/game/g_combat.c
Original file line number Diff line number Diff line change
@@ -882,6 +882,7 @@ void G_Damage(gentity_t *targ, gentity_t *inflictor, gentity_t *attacker, vec3_t
} else {
attacker->client->ps.persistant[PERS_HITS]++;
}
attacker->client->ps.persistant[PERS_ATTACKEE_ARMOR] = (targ->health << 8) | (client->ps.stats[STAT_ARMOR]);
}

// always give half damage if hurting self
22 changes: 21 additions & 1 deletion code/ui/ui_preferences.c
Original file line number Diff line number Diff line change
@@ -78,6 +78,7 @@ PREFERENCES MENU
#define ID_SYNCEVERYFRAME 38
#define ID_FORCEMODEL 39
#define ID_GLOWMODEL 40
#define ID_HITSOUND 41

#define ID_CONNOTIFY 50
#define ID_CHATHEIGHT 51
@@ -135,6 +136,7 @@ typedef struct {
menuradiobutton_s synceveryframe;
menuradiobutton_s forcemodel;
menulist_s glowmodel;
menuradiobutton_s hitsound;

menulist_s connotify;
menulist_s chatheight;
@@ -193,6 +195,7 @@ static menucommon_s *g_game_options[] = {
(menucommon_s *)&s_preferences.synceveryframe,
(menucommon_s *)&s_preferences.forcemodel,
(menucommon_s *)&s_preferences.glowmodel,
(menucommon_s *)&s_preferences.hitsound,
NULL
};

@@ -278,12 +281,12 @@ static void UI_Preferences_SetMenuItems(void) {
s_preferences.ingamevideo.curvalue = trap_Cvar_VariableValue("r_inGameVideo") != 0;
s_preferences.synceveryframe.curvalue = trap_Cvar_VariableValue("r_finish") != 0;
s_preferences.forcemodel.curvalue = (trap_Cvar_VariableValue("cg_forcemodel") != 0);

if (!Q_stricmp(UI_Cvar_VariableString("cg_glowModel"), "")) {
s_preferences.glowmodel.curvalue = 0;
} else {
s_preferences.glowmodel.curvalue = (trap_Cvar_VariableValue("cg_glowModel") + 1);
}
s_preferences.hitsound.curvalue = (trap_Cvar_VariableValue("cg_advHitSound") != 0);

notify = UI_GetCvarInt("con_notifytime");
if (notify < 0) {
@@ -533,6 +536,10 @@ static void UI_Preferences_Event(void *ptr, int notification) {
UI_Preferences_UpdateMenuItems();
break;

case ID_HITSOUND:
trap_Cvar_SetValue("cg_advHitSound", s_preferences.hitsound.curvalue);
break;

case ID_CONNOTIFY:
switch (s_preferences.connotify.curvalue) {
case 0:
@@ -928,6 +935,18 @@ static void UI_Preferences_MenuInit(void) {
"to that weapon when 'better', only auto-switch to that weapon when 'new and better'. Default is "
"'new and better'.";

y += (BIGCHAR_HEIGHT + 2);
s_preferences.hitsound.generic.type = MTYPE_RADIOBUTTON;
s_preferences.hitsound.generic.name = "Advanced Hit Sound:";
s_preferences.hitsound.generic.flags = QMF_SMALLFONT | QMF_HIDDEN;
s_preferences.hitsound.generic.callback = UI_Preferences_Event;
s_preferences.hitsound.generic.id = ID_HITSOUND;
s_preferences.hitsound.generic.x = XPOSITION;
s_preferences.hitsound.generic.y = y;
s_preferences.hitsound.generic.toolTip =
"Enable to play an alternate set of hit sounds indicating your opponent's shield status. "
"Default is off.";

y += (BIGCHAR_HEIGHT + 2);
s_preferences.simpleitems.generic.type = MTYPE_RADIOBUTTON;
s_preferences.simpleitems.generic.name = "Simple Items:";
@@ -1303,6 +1322,7 @@ static void UI_Preferences_MenuInit(void) {
Menu_AddItem(&s_preferences.menu, &s_preferences.ups);

Menu_AddItem(&s_preferences.menu, &s_preferences.autoswitch);
Menu_AddItem(&s_preferences.menu, &s_preferences.hitsound);
Menu_AddItem(&s_preferences.menu, &s_preferences.simpleitems);
Menu_AddItem(&s_preferences.menu, &s_preferences.wallmarks);
Menu_AddItem(&s_preferences.menu, &s_preferences.dynamiclights);
3 changes: 3 additions & 0 deletions wop/sound.pk3dir/sound/feedback/hit_shield.wav
Git LFS file not shown
3 changes: 3 additions & 0 deletions wop/sound.pk3dir/sound/feedback/hit_team.ogg
Git LFS file not shown

0 comments on commit 8647a77

Please sign in to comment.