--[[<Sieczkarnia>
<sounds>
   <work file="Sounds/Sieczkarnia.wav" innerRadius="12.0" outerRadius="45.0" linkNode="0>0|18">
        <volume indoor="0.85" outdoor="1.4" />
        <pitch indoor="1.00" outdoor="1.00" />
         <lowpassGain indoor="0.75" outdoor="1.00" />
     </work>
 </sounds>
</Sieczkarnia>]]
--EmeraldHound By The Man Who Sold The World
EmeraldHound = {}

EmeraldHound.modName = g_currentModName


function EmeraldHound.prerequisitesPresent(specializations)
    return true
end

function EmeraldHound.registerEventListeners(vehicleType)
    SpecializationUtil.registerEventListener(vehicleType, "onLoad", EmeraldHound)
    SpecializationUtil.registerEventListener(vehicleType, "onDelete", EmeraldHound)
    SpecializationUtil.registerEventListener(vehicleType, "onUpdate", EmeraldHound)
end

function EmeraldHound:onLoad(savegame)
    local spec = self.spec_combine
 
    if self.isClient then
         spec.Sounds = {}
         spec.Sounds.work = g_soundManager:loadSampleFromXML(self.xmlFile, "vehicle.Sieczkarnia.sounds", "work", self.baseDirectory, self.components, 0, AudioGroup.VEHICLE, self.i3dMappings, self)
         spec.isWorkSamplePlaying = false   
    end
end

function EmeraldHound:onDelete()
    if self.isClient then
        local spec = self.spec_combine
        g_soundManager:deleteSamples(spec.Sounds)
    end
end

function EmeraldHound:onUpdate(dt, isActiveForInput, isActiveForInputIgnoreSelection, isSelected)
    local spec = self.spec_combine

    if self.isClient then
         spec.isWorking = self:getIsTurnedOn() and not spec.isSwathActive

            if spec.isWorking then
            if not spec.isWorkSamplePlaying then
                g_soundManager:playSample(spec.Sounds.work)
                spec.isWorkSamplePlaying = true
            end
        else
             if spec.isWorkSamplePlaying then
                g_soundManager:stopSample(spec.Sounds.work)
                spec.isWorkSamplePlaying = false
            end
        end
    end
end





