(version 2)
(include "sci.sh")
(use "Main")
(use "Obj")
(script 989)



(class Sound of Obj
    (properties
        state $0000
        number 0
        priority 0
        loop 1
        handle 0
        signal $0000
        prevSignal 0
        client 0
        owner 0
    )

    (method (new param1)
        (send ((super:new())):
            owner(
                (if (paramTotal)
                    param1
                )(else
                    0
                )
)
            yourself()
        )
    )


    (method (init)
        = state (= prevSignal (= signal 0))
        (send gSounds:add(self))
        DoSound(sndINIT self)
    )


    (method (dispose param1)
        (if (paramTotal and not param1)
            = client 0
        )
        (send gSounds:delete(self))
        (if (handle)
            DoSound(sndDISPOSE handle)
            = handle 0
        )
        (super:dispose())
    )


    (method (play param1)
        (var temp0)
        (self:stop())
        (if (not loop)
            = loop 1
        )
        (self:init())
        = client 
            (if (paramTotal)
                param1
            )(else
                0
            )
        DoSound(sndPLAY self)
    )


    (method (playMaybe param1)
        (self:play(rest param1))
        (if (== state 2)
            (self:dispose())
        )
    )


    (method (stop param1)
        (if (paramTotal and not param1)
            = client 0
        )
        (if (handle)
            DoSound(sndSTOP handle)
        )
    )


    (method (check)
        (if (signal)
            (if (== signal -1)
                DoSound(sndSTOP_ALL)
            )
            (if (IsObject(client))
                (send client:cue(self))
            )
            = prevSignal signal
            = signal 0
        )
    )


    (method (pause param1)
        DoSound(sndPAUSE param1)
    )


    (method (changeState)
        DoSound(sndUPDATE self)
    )


    (method (clean param1)
        (if (not owner or (== owner param1))
            (self:dispose())
        )
    )


    (method (fade param1)
        (if (paramTotal and not param1)
            = client 0
        )
        DoSound(sndFADE handle)
    )

)
