From 54ec8d7a9775008285e5ecf5c925fd9d99a1a7bb Mon Sep 17 00:00:00 2001 From: drjaska Date: Fri, 24 May 2024 18:18:00 +0300 Subject: [PATCH] Implement cl_gentle_voices and handle loading/playing correct sounds --- qcsrc/common/effects/qc/globalsound.qc | 85 +++++++++++++++++++++----- qcsrc/common/effects/qc/globalsound.qh | 4 ++ 2 files changed, 74 insertions(+), 15 deletions(-) diff --git a/qcsrc/common/effects/qc/globalsound.qc b/qcsrc/common/effects/qc/globalsound.qc index f5eaf11cd..3a0026305 100644 --- a/qcsrc/common/effects/qc/globalsound.qc +++ b/qcsrc/common/effects/qc/globalsound.qc @@ -151,14 +151,32 @@ { 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) @@ -229,15 +247,35 @@ } 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); } @@ -270,11 +308,28 @@ } 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); @@ -286,7 +341,7 @@ } 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; diff --git a/qcsrc/common/effects/qc/globalsound.qh b/qcsrc/common/effects/qc/globalsound.qh index e24496162..7f14910e9 100644 --- a/qcsrc/common/effects/qc/globalsound.qh +++ b/qcsrc/common/effects/qc/globalsound.qh @@ -10,6 +10,10 @@ bool autocvar_sv_taunt; bool autocvar_sv_autotaunt; #endif +#ifdef CSQC + #include //bool autocvar_cl_gentle; + bool autocvar_cl_gentle_voices; +#endif // player sounds, voice messages -- 2.39.2