From 938a786f33de31829fc81002ad9a8abf56b548da Mon Sep 17 00:00:00 2001 From: Rudolf Polzer Date: Sun, 5 Dec 2010 15:01:35 +0100 Subject: [PATCH] better target_speaker support --- qcsrc/server/cl_player.qc | 7 --- qcsrc/server/defs.qh | 2 + qcsrc/server/g_triggers.qc | 108 ++++++++++++++++++++++++++++++++----- 3 files changed, 96 insertions(+), 21 deletions(-) diff --git a/qcsrc/server/cl_player.qc b/qcsrc/server/cl_player.qc index 79206585c..27bd209c5 100644 --- a/qcsrc/server/cl_player.qc +++ b/qcsrc/server/cl_player.qc @@ -1147,12 +1147,9 @@ float GetVoiceMessageVoiceType(string type) } string allvoicesamples; -float GetPlayerSoundSampleField_notFound; -float GetPlayerSoundSampleField_fixed; .string GetVoiceMessageSampleField(string type) { GetPlayerSoundSampleField_notFound = 0; - GetPlayerSoundSampleField_fixed = 0; switch(type) { #define _VOICEMSG(m) case #m: return playersound_##m; @@ -1166,7 +1163,6 @@ float GetPlayerSoundSampleField_fixed; .string GetPlayerSoundSampleField(string type) { GetPlayerSoundSampleField_notFound = 0; - GetPlayerSoundSampleField_fixed = 0; switch(type) { #define _VOICEMSG(m) case #m: return playersound_##m; @@ -1248,9 +1244,6 @@ void LoadPlayerSounds(string f, float first) field = GetVoiceMessageSampleField(argv(0)); if(GetPlayerSoundSampleField_notFound) continue; - if(GetPlayerSoundSampleField_fixed) - if not(first) - continue; if(self.field) strunzone(self.field); self.field = strzone(strcat(argv(1), " ", argv(2))); diff --git a/qcsrc/server/defs.qh b/qcsrc/server/defs.qh index cd2f8912e..c9a7e61c4 100644 --- a/qcsrc/server/defs.qh +++ b/qcsrc/server/defs.qh @@ -500,6 +500,8 @@ void PlayerSound(.string samplefield, float channel, float voicetype); void GlobalSound(string samplestring, float channel, float voicetype); void FakeGlobalSound(string samplestring, float channel, float voicetype); void VoiceMessage(string type, string message); +float GetPlayerSoundSampleField_notFound; +.string GetVoiceMessageSampleField(string type) // autotaunt system .float cvar_cl_autotaunt; diff --git a/qcsrc/server/g_triggers.qc b/qcsrc/server/g_triggers.qc index 79e1b5f46..17ee369d8 100644 --- a/qcsrc/server/g_triggers.qc +++ b/qcsrc/server/g_triggers.qc @@ -656,31 +656,111 @@ void spawnfunc_trigger_gravity() // TODO add a way to do looped sounds with sound(); then complete this entity .float volume, atten; -void target_speaker_use() {sound(self, CHAN_TRIGGER, self.noise, VOL_BASE * self.volume, self.atten);} +void target_speaker_use_off(); +void target_speaker_use_activator() +{ + if(clienttype(activator) != CLIENTTYPE_REAL) + return; + string snd; + if(substring(self.noise, 0, 1) == "*") + { + var .string sample; + sample = GetVoiceMessageSampleField(substring(self.noise, 1, -1)); + if(GetPlayerSoundSampleField_notFound) + snd = "misc/null.wav"; + else if(activator.sample == "") + snd = "misc/null.wav"; + else + { + tokenize_console(activator.sample); + n = stof(argv(1)); + if(n > 0) + snd = strcat(argv(0), ftos(floor(random() * n + 1)), ".wav"); // randomization + else + snd = strcat(argv(0), ".wav"); // randomization + } + } + else + snd = self.noise; + msg_entity = activator; + soundto(MSG_ONE, self, CHAN_TRIGGER, snd, VOL_BASE * self.volume, self.atten); +} +void target_speaker_use_on() +{ + string snd; + if(substring(self.noise, 0, 1) == "*") + { + var .string sample; + sample = GetVoiceMessageSampleField(substring(self.noise, 1, -1)); + if(GetPlayerSoundSampleField_notFound) + snd = "misc/null.wav"; + else if(activator.sample == "") + snd = "misc/null.wav"; + else + { + tokenize_console(activator.sample); + n = stof(argv(1)); + if(n > 0) + snd = strcat(argv(0), ftos(floor(random() * n + 1)), ".wav"); // randomization + else + snd = strcat(argv(0), ".wav"); // randomization + } + } + else + snd = self.noise; + sound(self, CHAN_TRIGGER, snd, VOL_BASE * self.volume, self.atten); + if(self.spawnflags & 3) + self.use = target_speaker_use_off; +} +void target_speaker_use_off() +{ + sound(self, CHAN_TRIGGER, "misc/null.wav", VOL_BASE * self.volume, self.atten); + self.use = target_speaker_use_on; +} void spawnfunc_target_speaker() { + // TODO: "*" prefix to sound file name + // TODO: wait and random (just, HOW? random is not a field) if(self.noise) precache_sound (self.noise); - IFTARGETED + + if(!self.atten && !(self.spawnflags & 4)) { - if(!self.atten) + IFTARGETED self.atten = ATTN_NORM; - else if(self.atten < 0) - self.atten = 0; - if(!self.volume) - self.volume = 1; - self.use = target_speaker_use; + else + self.atten = ATTN_STATIC; + } + else if(self.atten < 0) + self.atten = 0; + + if(!self.volume) + self.volume = 1; + + IFTARGETED + { + if(self.spawnflags & 8) // ACTIVATOR + self.use = target_speaker_use_activator; + else if(self.spawnflags & 1) // LOOPED_ON + target_speaker_use_on(); + else + self.use = target_speaker_use_on; + } + else if(self.spawnflags & 1) // LOOPED_ON + { + ambientsound (self.origin, self.noise, VOL_BASE * self.volume, self.atten); + remove(self); + } + else if(self.spawnflags & 2) // LOOPED_OFF + { + objerror("This sound entity can never be activated"); } else { - if(!self.atten) - self.atten = ATTN_STATIC; - else if(self.atten < 0) - self.atten = 0; - if(!self.volume) - self.volume = 1; + // Quake/Nexuiz fallback ambientsound (self.origin, self.noise, VOL_BASE * self.volume, self.atten); + remove(self); } }; -- 2.39.2