]> 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>
Fri, 24 May 2024 15:18:00 +0000 (18:18 +0300)
qcsrc/common/effects/qc/globalsound.qc
qcsrc/common/effects/qc/globalsound.qh

index f5eaf11cdb8c659efa2de3eb66d646d1aca98e47..3a0026305d2e69710e7ea2625c9726d97fa13ad7 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)
                }
                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 (autocvar_cl_gentle || autocvar_cl_gentle_voices)
+                                               LOG_WARNF("cl_gentle_voices: Missing gentle # on sound info line: %s", s);
+#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);
        }
                        }
                        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 (autocvar_cl_gentle || autocvar_cl_gentle_voices)
+                                                       LOG_WARNF("cl_gentle_voices: Missing gentle # on sound info line: %s", s);
+#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