(include "sci.sh")
(use "Main")
(use "SQRoom")
(use "Osc")
(use "MCyc")
(use "ForwardCounter")
(use "n958")
(use "Sound")
(use "Cycle")
(use "User")
(use "PicView")
(use "Obj")
(script 153)


(local
    local0
    local1
    local2
    local3 = 10
    local4
    local5[16] = (161 189 186 154 120 91 87 118 119 107 80 67 61 79 107 126 )
    local21[37] = (2 2 122 99 2 3 122 99 2 2 122 99 2 3 122 99 2 2 122 99 2 3 122 99 2 2 122 99 2 3 122 99 2 2 122 99 32768 )

)
(procedure (localproc_000e param1 param2)
    (if (local0)
        proc0_12(local0)
    )
    = local0 proc0_12(param2 67 10 
            (if (== param1 0)
                10
            )(else
                160
            )
 28 
            (if (== param1 0)
                global135
            )(else
                proc0_18(global153 global152)
            )
 29 global129)
)


(instance public rm153 of SQRoom
    (properties
        picture 150
    )

    (method (init)
        proc958_0(128 522 520 521)
        proc958_0(132 49 118 119 120 121)
        (send gEgo:setCycle(0))
        (super:init())
        (lOrb:init())
        (rOrb:init())
        (self:setScript(captiveScript))
    )


    (method (doit)
        (super:doit())
        (if (not local2 and (== (send gLongSong:prevSignal) 10))
            = local2 1
        )
    )

)
(instance captiveScript of Script
    (properties)

    (method (init param1)
        (super:init(rest param1))
        (send gSq4KeyDownHandler:addToFront(self))
        (send gSq4MouseDownHandler:addToFront(self))
    )


    (method (dispose)
        (send gSq4KeyDownHandler:delete(self))
        (send gSq4MouseDownHandler:delete(self))
        (super:dispose())
    )


    (method (changeState newState)
        (switch (= state newState)
            (case 0
                proc0_2()
                (send gLongSong:
                    number(49)
                    playBed()
                )
                (vohaul:init())
                (police:
                    init()
                    setCycle(Walk)
                    setMotion(MoveTo 200 158 self)
                )
            )
            (case 1
                = register 1
                (User:canControl(1))
                (mouth:
                    init()
                    setCycle(ForwardCounter 7)
                )
                (eyes:
                    init()
                    setCycle(ForwardCounter 4)
                )
                localproc_000e(0 "Well... what have we here?")
                = seconds 4
            )
            (case 2
                (mouth:hide())
                (eyes:hide())
                = cycles 1
            )
            (case 3
                localproc_000e(1 "This is the rebel scum we captured\nin the SQ4 time sector.")
                = seconds 5
            )
            (case 4
                localproc_000e(1 "He had just aided Wilco in escaping.")
                = seconds 5
            )
            (case 5
                localproc_000e(1 "The readout on his time gun indicates\nthat Wilco was successfully transported...")
                = seconds 6
            )
            (case 6
                localproc_000e(1 "...into this time sector as you feared.")
                = seconds 5
            )
            (case 7
                (mouth:
                    setCel(0)
                    show()
                    setCycle(ForwardCounter 5)
                )
                (eyes:
                    show()
                    setCycle(ForwardCounter 3)
                )
                localproc_000e(0 "That is no longer a concern.")
                = seconds 4
            )
            (case 8
                (mouth:setCycle(ForwardCounter 9))
                (eyes:setCycle(ForwardCounter 6))
                localproc_000e(0 "Wilco will surrender to us once he\nhas learned we have captured his SON!")
                = seconds 6
            )
            (case 9
                (mouth:setCycle(ForwardCounter 9))
                (eyes:setCycle(ForwardCounter 6))
                localproc_000e(0 "Then he will be destroyed once and\nfor all. Ha ha ha....")
                = seconds 4
            )
            (case 10
                = register 0
                (User:canControl(0))
                (eyes:dispose())
                (mouth:setCycle(MCyc @local21 self))
            )
            (case 11
                (mouth:dispose())
                = cycles 1
            )
            (case 12
                proc0_12(local0)
                (send global2:drawPic(803 6))
                (send global2:newRoom(365))
            )
        )
    )


    (method (handleEvent)
        (if (register)
            = seconds 0
            = cycles 1
        )
    )

)
(instance police of Actor
    (properties
        x 349
        y 218
        view 521
        loop 1
        priority 6
        signal 16
    )
)
(instance vohaul of Prop
    (properties
        x 121
        y 84
        view 520
        priority 10
        signal 16
    )
)
(instance eyes of Prop
    (properties
        x 132
        y 69
        view 520
        loop 1
        cel 1
        priority 12
        signal 16
        cycleSpeed 2
    )
)
(instance mouth of Prop
    (properties
        x 122
        y 99
        view 520
        loop 2
        priority 11
        signal 16
    )
)
(instance lOrbZap of Sound
    (properties)
)
(instance rOrbZap of Sound
    (properties)
)
(instance lOrb of Prop
    (properties
        x 47
        y 123
        description "left orb"
        lookStr "The strange orbs crackle and sizzle with raw energy."
        view 151
        priority 8
    )

    (method (doit)
        (super:doit())
        (if (local3 and not --local3)
            (if (< Random(1 10) 5)
                = loop 0
            )(else
                = loop 2
            )
            (if (< Random(1 10) 5)
                (if (local2)
                    (lOrbZap:
                        number(
                            (if (loop)
                                120
                            )(else
                                118
                            )
)
                        play()
                    )
                )
                (self:setCycle(Osc 1 self))
            )(else
                (if (local2)
                    (lOrbZap:
                        number(
                            (if (loop)
                                120
                            )(else
                                118
                            )
)
                        play()
                    )
                )
                (self:setCycle(End self))
            )
        )
    )


    (method (cue)
        = local3 Random(20 50)
        (lOrbZap:stop())
        (self:stopUpd())
        (super:cue())
    )

)
(instance rOrb of Prop
    (properties
        x 230
        y 87
        description "right orb"
        lookStr "The strange orbs crackle and sizzle with raw energy."
        view 151
        loop 1
        priority 8
    )

    (method (doit)
        (super:doit())
        (if (local4 and not --local4)
            (if (< Random(1 10) 5)
                = loop 1
            )(else
                = loop 3
            )
            (if (< Random(1 10) 5)
                (if (local2)
                    (rOrbZap:
                        number(
                            (if (== loop 3)
                                121
                            )(else
                                119
                            )
)
                        play()
                    )
                )
                (self:setCycle(Osc 1 self))
            )(else
                (if (local2)
                    (rOrbZap:
                        number(
                            (if (== loop 3)
                                121
                            )(else
                                119
                            )
)
                        play()
                    )
                )
                (self:setCycle(End self))
            )
        )
    )


    (method (cue)
        = local4 Random(20 50)
        (rOrbZap:stop())
        (self:stopUpd())
        (super:cue())
    )

)
