]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Implement cl_gentle_voices and handle loading/playing correct sounds
authordrjaska <drjaska83@gmail.com>
Fri, 24 May 2024 15:18:00 +0000 (18:18 +0300)
committerdrjaska <drjaska83@gmail.com>
Mon, 11 Nov 2024 23:29:55 +0000 (01:29 +0200)
qcsrc/common/effects/qc/globalsound.qc
qcsrc/common/effects/qc/globalsound.qh
xonotic-client.cfg

index cdf127c62ee8a47650900a8df0cc18675bcff3d8..62217ecf87412c7e52fbaed4467f685d457a60ee 100644 (file)
        {
                int n;
                {
-                       string s = cdr(pair);
-                       if (s) n = stof(s);
-                       else n = 0;
+                       // values may contain "X" or "X Y"
+                       // where X is all and Y is gentle
+                       string values = cdr(pair);
+                       if (values)
+                       {
+       #ifdef CSQC
+                               if (autocvar_cl_gentle || autocvar_cl_gentle_voices)
+                               {
+                                       string gentle = cdr(values);
+                                       if (gentle)
+                                               n = stof(gentle);
+                                       else
+                                               n = stof(values);
+                               }
+                               else
+       #endif
+                                       n = stof(values);
+                       }
+                       else
+                               n = 0;
                }
-               string sample = car(pair);
-               if (n > 0) sample = sprintf("%s%d.wav", sample, floor(r * n + 1));  // randomization
-               else sample = sprintf("%s.wav", sample);
-               return sample;
+
+               if (n > 0)
+                       return sprintf("%s%d.wav", car(pair), floor(r * n + 1));  // randomization
+               else
+                       return sprintf("%s.wav", car(pair));
        }
 
        float GlobalSound_pitch(float _pitch)
 
        void PrecachePlayerSounds(string f)
        {
+#ifdef CSQC
+               bool gentle_warning = true; // only warn once per file
+#endif
                int fh = fopen(f, FILE_READ);
                if (fh < 0)
                {
                }
                for (string s; (s = fgets(fh)); )
                {
+                       // likely missing for pre-0.9 clients and thus initialized here
+                       string gentle = "";
+
                        int n = tokenize_console(s);
-                       if (n != 3)
+
+                       switch (n)
                        {
-                               if (n != 0) LOG_WARNF("Invalid sound info line: %s", s);
-                               continue;
+                               case 0:
+                                       // empty line
+                                       continue;
+                               case 4:
+                                       // new format with separate gentle lines count
+                                       gentle = argv(3);
+                                       break;
+                               case 3:
+                                       // old format without separate gentle lines count
+#ifdef CSQC
+                                       if (gentle_warning && (autocvar_cl_gentle || autocvar_cl_gentle_voices))
+                                       {
+                                               LOG_WARNF("cl_gentle_voices: Missing gentle # in sound info file: %s", f);
+                                               gentle_warning = false;
+                                       }
+#endif
+                                       break;
+                               default:
+                                       LOG_WARNF("Invalid sound info line: %s", s);
+                                       continue;
                        }
+
                        string file = argv(1);
                        string variants = argv(2);
-                       PrecacheGlobalSound(strcat(file, " ", variants));
+                       PrecacheGlobalSound(strcat(file, " ", variants, " ", gentle));
                }
                fclose(fh);
        }
 
                bool LoadPlayerSounds(entity this, string f, bool strict)
                {
+#ifdef CSQC
+                       bool gentle_warning = true; // only warn once per file
+#endif
                        int fh = fopen(f, FILE_READ);
                        if (fh < 0)
                        {
                        }
                        for (string s; (s = fgets(fh)); )
                        {
+                               string gentle = ""; // likely is missing for old clients on new servers
+
                                int n = tokenize_console(s);
-                               if (n != 3)
+                               switch (n)
                                {
-                                       if (n != 0) LOG_WARNF("Invalid sound info line: %s", s);
-                                       continue;
+                                       case 0:
+                                               // empty line
+                                               continue;
+                                       case 4:
+                                               // new format with separate gentle lines count
+                                               gentle = argv(3);
+                                               break;
+                                       case 3:
+#ifdef CSQC
+                                               // old format without separate gentle lines count
+                                               if (gentle_warning && (autocvar_cl_gentle || autocvar_cl_gentle_voices))
+                                               {
+                                                       LOG_WARNF("cl_gentle_voices: Missing gentle # in sound info file: %s", f);
+                                                       gentle_warning = false;
+                                               }
+#endif
+                                               break;
+                                       default:
+                                               LOG_WARNF("Invalid sound info line: %s", s);
+                                               continue;
                                }
                                string key = argv(0);
                                var .string field = GetPlayerSoundSampleField(key);
                                }
                                string file = argv(1);
                                string variants = argv(2);
-                               strcpy(this.(field), strcat(file, " ", variants));
+                               strcpy(this.(field), strcat(file, " ", variants, " ", gentle));
                        }
                        fclose(fh);
                        return true;
index e244961620a0006a4dfd1835fc30a9597ef0a8ab..7f14910e9ced6b7555f966852c6c2473534387ba 100644 (file)
        bool autocvar_sv_taunt;
        bool autocvar_sv_autotaunt;
 #endif
+#ifdef CSQC
+       #include <common/util.qh> //bool autocvar_cl_gentle;
+       bool autocvar_cl_gentle_voices;
+#endif
 
 // player sounds, voice messages
 
index 332c4b74198d0feb71bc050d75d4bf56561359cc..984b84b12edf517b39408a88f3534e0a2f4445bf 100644 (file)
@@ -752,6 +752,7 @@ seta cl_gentle 0                    "client side gentle mode, master switch"
 seta cl_gentle_gibs 0          "client side gentle mode for gibs (cl_nogibs); when set to 1, white smoke replaces gibs, when set to 2, colorful clouds replace gibs"
 seta cl_gentle_messages 0      "client side gentle mode for frag messages/centerprints"
 seta cl_gentle_damage 0                "client side gentle mode for damage flash (hud_damage); when set to 1, a white flash replaces the blood image, when set to 2, a randomly colored flash is used instead"
+seta cl_gentle_voices 0                "client side gentle mode for player model voicelines"
 
 set cl_jetpack_attenuation 2 "jetpack sound attenuation"