diff --git a/lua/SimSyncUtils.lua b/lua/SimSyncUtils.lua index b246722230..c96fba9f67 100644 --- a/lua/SimSyncUtils.lua +++ b/lua/SimSyncUtils.lua @@ -5,8 +5,7 @@ function SyncCameraRequest(data) table.insert(Sync.CameraRequests, data) end ----comment ----@param data any +---@param data SoundBlueprint function SyncVoice(data) local Sync = Sync Sync.Voice = Sync.Voice or { } diff --git a/lua/UserSync.lua b/lua/UserSync.lua index dbfb2b6dd3..3f5f24a87d 100644 --- a/lua/UserSync.lua +++ b/lua/UserSync.lua @@ -200,7 +200,7 @@ function OnSync() --Play Sounds if Sync.Sounds then for k, v in Sync.Sounds do - PlaySound(Sound{ Bank=v.Bank, Cue=v.Cue }) + PlaySound(Sound(v)) end end @@ -302,7 +302,7 @@ function OnSync() if Sync.Voice then if not import("/lua/ui/game/missiontext.lua").IsHeadPlaying() then for k, v in Sync.Voice do - PlayVoice(Sound{ Bank=v.Bank, Cue=v.Cue }, true) + PlayVoice(Sound(v), true) end end end diff --git a/lua/aibrain.lua b/lua/aibrain.lua index fef11fc3f0..ea59b7ca00 100644 --- a/lua/aibrain.lua +++ b/lua/aibrain.lua @@ -739,22 +739,11 @@ AIBrain = Class(AIBrainHQComponent, AIBrainStatisticsComponent, AIBrainJammerCom }, ---@param self AIBrain - ---@param string string + ---@param key string ---@param sound SoundHandle - PlayVOSound = function(self, string, sound) - if not self.VOTable then - self.VOTable = {} - end - - local VO = self.VOSounds[string] - if not VO then - WARN('PlayVOSound: ' .. string .. " not found") - return - end - - if not self.VOTable[string] and VO['obs'] and GetFocusArmy() == -1 and self:GetArmyIndex() == 1 then - -- Don't stop sound IF not repeated AND sound is flagged as 'obs' AND i'm observer AND only from PlayerIndex = 1 - elseif self.VOTable[string] or GetFocusArmy() ~= self:GetArmyIndex() then + PlayVOSound = function(self, key, sound) + if not self.VOSounds[key] then + WARN("PlayVOSound: " .. key .. " not found") return end @@ -762,24 +751,42 @@ AIBrain = Class(AIBrainHQComponent, AIBrainStatisticsComponent, AIBrainJammerCom if sound then cue, bank = GetCueBank(sound) else - cue, bank = VO['bank'], 'XGG' + -- note: what the VO sound table calls a "bank" is actually a "cue" + cue, bank = self.VOSounds[key]["bank"], "XGG" end if not (bank and cue) then - WARN('PlayVOSound: No valid bank/cue for ' .. string) + WARN("PlayVOSound: No valid bank/cue for " .. key) return end - self.VOTable[string] = true - ForkThread(self.PlayVOSoundThread, self, string, { + ForkThread(self.PlayVOSoundThread, self, key, { Cue = cue, - Bank = bank + Bank = bank, }) end, + ---@param self AIBrain + ---@param key string + ---@param data SoundBlueprint PlayVOSoundThread = function(self, key, data) + if not self.VOTable then + self.VOTable = {} + end + if self.VOTable[key] then + return + end + local sound = self.VOSounds[key] + local focusArmy = GetFocusArmy() + local armyIndex = self:GetArmyIndex() + if focusArmy ~= armyIndex and not (focusArmy == -1 and armyIndex == 1 and sound.obs) then + return + end + + self.VOTable[key] = true + import("/lua/SimSyncUtils.lua").SyncVoice(data) - WaitSeconds(self.VOSounds["timeout"]) + WaitSeconds(sound.timeout) self.VOTable[key] = nil end,