From 9820e59adb3899cf0e9b28ddf9387d3bfb994c87 Mon Sep 17 00:00:00 2001 From: gy_be Date: Thu, 20 Apr 2017 13:51:48 +0200 Subject: [PATCH] Fix local hitsound priority Local hitsounds (/hitsound 2) work by running CubeScript command `sound`, passing hitsound sound number and priority (highest). However, `sound` command doesn't actually take the second priority argument and always uses default normal priority. This commit adds the second prioity argument to `sound`. It accepts numeric priority levels as well as string names. Also use highest priority for server hitsounds (to be consistent with local hitsounds). (was pull request #164) DOCREF sound --- source/src/audiomanager.cpp | 7 +++++-- source/src/clientgame.cpp | 2 +- source/src/command.cpp | 6 +++--- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/source/src/audiomanager.cpp b/source/src/audiomanager.cpp index 9f95e70f..dd92c883 100644 --- a/source/src/audiomanager.cpp +++ b/source/src/audiomanager.cpp @@ -773,9 +773,12 @@ bool staticreference::operator==(const worldobjreference &other) audiomanager audiomgr; -COMMANDF(sound, "i", (int *n) +const char *soundprioritynames[] = {"LOW", "NORMAL", "HIGH", "HIGHEST", ""}; // keep in sync with enum { SP_LOW = 0, SP_NORMAL, SP_HIGH, SP_HIGHEST } + +COMMANDF(sound, "is", (int *n, char *priorityname) { - audiomgr.playsound(*n); + int priority = getlistindex(priorityname, soundprioritynames, true, SP_NORMAL); + audiomgr.playsound(*n, priority); }); COMMANDF(applymapsoundchanges, "", (){ diff --git a/source/src/clientgame.cpp b/source/src/clientgame.cpp index 38bc7729..db92755a 100644 --- a/source/src/clientgame.cpp +++ b/source/src/clientgame.cpp @@ -859,7 +859,7 @@ void dodamage(int damage, playerent *pl, playerent *actor, int gun, bool gib, bo if(actor==h && pl!=actor) { - if( (hitsound == 1 || (hitsound && h != player1) ) && lasthit != lastmillis) audiomgr.playsound(S_HITSOUND, SP_HIGH); + if( (hitsound == 1 || (hitsound && h != player1) ) && lasthit != lastmillis) audiomgr.playsound(S_HITSOUND, SP_HIGHEST); lasthit = lastmillis; } diff --git a/source/src/command.cpp b/source/src/command.cpp index a3e2332f..f217fdb6 100644 --- a/source/src/command.cpp +++ b/source/src/command.cpp @@ -1832,9 +1832,9 @@ COMMANDF(getmode, "i", (int *acr) { result(modestr(gamemode, *acr != 0)); }); void listoptions(char *s) { - extern const char *menufilesortorders[], *texturestacktypes[]; - const char *optionnames[] = { "entities", "ents", "weapons", "teamnames", "teamnames-abbrv", "punctuations", "crosshairnames", "menufilesortorders", "texturestacktypes", "cubetypes", "" }; - const char **optionlists[] = { optionnames, entnames + 1, entnames + 1, gunnames, teamnames, teamnames_s, punctnames, crosshairnames, menufilesortorders, texturestacktypes, cubetypenames }; + extern const char *menufilesortorders[], *texturestacktypes[], *soundprioritynames[]; + const char *optionnames[] = { "entities", "ents", "weapons", "teamnames", "teamnames-abbrv", "punctuations", "crosshairnames", "menufilesortorders", "texturestacktypes", "cubetypes", "soundpriorities", "" }; + const char **optionlists[] = { optionnames, entnames + 1, entnames + 1, gunnames, teamnames, teamnames_s, punctnames, crosshairnames, menufilesortorders, texturestacktypes, cubetypenames, soundprioritynames }; const char **listp = optionlists[getlistindex(s, optionnames, true, -1) + 1]; commandret = conc(listp, -1, true); }