Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better hit sound feedback #176

Merged
merged 1 commit into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions code/cgame/cg_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions code/cgame/cg_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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},
Expand Down Expand Up @@ -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);
Expand Down
13 changes: 12 additions & 1 deletion code/cgame/cg_playerstate.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
}
Expand Down
1 change: 1 addition & 0 deletions code/game/bg_public.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions code/game/g_combat.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 21 additions & 1 deletion code/ui/ui_preferences.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -135,6 +136,7 @@ typedef struct {
menuradiobutton_s synceveryframe;
menuradiobutton_s forcemodel;
menulist_s glowmodel;
menuradiobutton_s hitsound;

menulist_s connotify;
menulist_s chatheight;
Expand Down Expand Up @@ -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
};

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:";
Expand Down Expand Up @@ -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);
Expand Down
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
Loading