(version 2)
(include "sci.sh")
(use "Main")
(use "Print")
(use "Game")
(use "Obj")
(script 924)



(class Messager of Obj
    (properties
        caller 0
        talkerList 0
        disposeWhenDone 1
        oneOnly 0
        killed 0
        oldIconBarState 0
        curSequence 0
        lastSequence 0
    )

    (method (dispose)
        (if (talkerList)
            (send talkerList:
                eachElementDo(143 0)
                eachElementDo(111 1)
                dispose()
            )
            = talkerList 0
        )
        (if (gMainIconBar)
            (send gMainIconBar:state(oldIconBarState))
            = oldIconBarState 0
        )
        (if (caller)
            (if (not gNewSet)
                = gNewSet (Set:new())
            )
            (send gNewSet:add((send ((Cue:new())):
                    cuee(caller)
                    cuer(self)
                    register(killed)
                    yourself()
                )
))
        )
        (super:dispose())
    )


    (method (cue param1)
        (if (paramTotal and param1)
            = killed 1
        )
        (if (oneOnly or killed)
            (if (gNewEventHandler)
                (send gNewEventHandler:
                    release()
                    dispose()
                )
                = gNewEventHandler 0
            )
            (self:dispose())
        )(else
            (self:sayNext())
        )
    )


    (method (say theCaller)
        (var theTheCaller, theTheCaller_2, theTheCaller_3, theGClientModNum, temp4[20], temp24)
        = theTheCaller_3 (= curSequence 0)
        = theTheCaller_2 theTheCaller_3
        = theTheCaller theTheCaller_2
        = caller (= oneOnly (= killed 0))
        (if (gMainIconBar and not oldIconBarState)
            = oldIconBarState (send gMainIconBar:state)
        )
        (if (not talkerList)
            (send (= talkerList (Set:new())):add())
        )
        = theTheCaller theCaller[0]
        (if (== theTheCaller -1)
            (if ((> paramTotal 1) and IsObject(theCaller[1]))
                = caller theCaller[1]
            )
            (self:sayNext())
        )(else
            (if ((> paramTotal 1) and theCaller[1])
                = theTheCaller_2 theCaller[1]
            )
            (if ((> paramTotal 2) and theCaller[2])
                = theTheCaller_3 theCaller[2]
            )
            (if ((> paramTotal 3) and theCaller[3])
                = oneOnly 1
                = curSequence theCaller[3]
            )(else
                = curSequence 1
            )
            = temp24 4
            (if (((> paramTotal temp24) and theCaller[temp24]) and not IsObject(theCaller[temp24]))
                = lastSequence theCaller[temp24]
                ++temp24
                = oneOnly 0
            )(else
                = lastSequence 0
            )
            (if ((> paramTotal temp24) and theCaller[temp24])
                = caller theCaller[temp24]
            )(else
                = caller 0
            )
            = theGClientModNum 
                (if (> paramTotal ++temp24)
(                    = theGClientModNum theCaller[temp24]
)                )(else
(                    = theGClientModNum gClientModNum
)                )
            (if (((& global90 $0001) and Message(0 theGClientModNum theTheCaller theTheCaller_2 theTheCaller_3 curSequence)) or 0)
                (self:sayNext(theGClientModNum theTheCaller theTheCaller_2 theTheCaller_3 curSequence))
            )(else
                (Print:
                    addTextF("<Messager> %d: %d, %d, %d, %d not found" theGClientModNum theTheCaller theTheCaller_2 theTheCaller_3 curSequence)
                    init()
                )
                (self:dispose())
            )
        )
    )


    (method (sayFormat param1 param2 theCaller)
        (var temp0, temp1, temp2)
        (if (gMainIconBar and not oldIconBarState)
            = oldIconBarState (send gMainIconBar:state)
        )
        = temp2 (self:findTalker(param1))
        = temp0 proc921_3(param2 theCaller)
        (if (IsObject(theCaller[- paramTotal 2]))
            = caller theCaller[(- paramTotal 2)]
        )
        = temp1 Memory(1 temp0)
        Format(temp1 param2 theCaller)
        (send temp2:say(temp1 0 0 0 self))
        Memory(3 temp1)
    )


    (method (sayNext param1 param2 param3 param4 param5)
        (var temp0)
        = temp0 Message(1 0)
        (if (temp0 and (not lastSequence or (lastSequence and (<= curSequence lastSequence))))
            = temp0 (self:findTalker(temp0))
            (if (<> temp0 -1)
                (send talkerList:add(temp0))
                (if (paramTotal)
                    (send temp0:say(param2 param3 param4 param5 self param1))
                )(else
                    (send temp0:say(0 0 0 0 self))
                )
                ++curSequence
            )(else
                (if (gNewEventHandler)
                    (send gNewEventHandler:
                        release()
                        dispose()
                    )
                    = gNewEventHandler 0
                )
                (self:dispose())
            )
        )(else
            (if (gNewEventHandler)
                (send gNewEventHandler:
                    release()
                    dispose()
                )
                = gNewEventHandler 0
            )
            (self:dispose())
        )
    )


    (method (findTalker)
        proc921_0("<Messager findTalker:>\nCan't find talker or findTalker method not over-ridden")
        = global4 1
    )

)
