(version 2)
(include "sci.sh")
(exports
    0 monkeysWith
    1 monkeysEnter
    2 manuInCage
    3 openCage
    4 manuLeave
    5 manuEncounter2
    6 cage
)
(use "Main")
(use "TargFeature")
(use "TellerIcon")
(use "n026")
(use "OccasionalCycle")
(use "PolyPath")
(use "Polygon")
(use "Cycle")
(use "View")
(use "Obj")
(script 701)


(local
    local0
    newActor[10]
    local11
    local12
    local13
    local14[10] = (100 130 160 190 220 115 145 175 215 245 )
    local24[10] = (155 147 173 135 170 162 119 133 140 167 )
    local34[6] = (0 26 68 69 67 999 )
    local40[5] = (0 66 -36 31 999 )
    local45[4] = (0 100 999 999 )
    local49[3] = (0 76 999 )
    local52[6]
    local58[6]

)
(instance public monkeysWith of Script
    (properties)

    (method (doit)
        (if (not Random(0 30))
            ShakeScreen(1)
        )
        (super:doit())
    )


    (method (changeState newState)
        (var temp0)
        (switch (= state newState)
            (case 0
                proc0_2()
                = temp0 0
                (while (< temp0 10)
                    (send (= newActor[temp0] (Actor:new())):
                        view(985)
                        loop(Random(0 3))
                        moveSpeed(0)
                        cycleSpeed(0)
                        signal(16384)
                        posn(local14[temp0] local24[temp0])
                        setCycle(Walk)
                        init()
                    )
                    ++temp0
                )
                = cycles 2
            )
            (case 1
                ShakeScreen(1)
                (send gQg3Messager:say(5 6 70 0 self 700))
            )
            (case 2
                = temp0 0
                (while (< temp0 10)
                    (send newActor[temp0]:setScript((monkeyExit:new()) 0 newActor[temp0]))
                    ++temp0
                )
                = seconds 4
            )
            (case 3
                proc0_3()
                = seconds 5
            )
            (case 4
                (self:dispose())
            )
        )
    )

)
(instance manuEnter of Script
    (properties)

    (method (changeState newState)
        (var temp0)
        (switch (= state newState)
            (case 0
                (send register:setMotion(PolyPath local14[9] local24[9] self))
            )
            (case 1
                = seconds 3
            )
            (case 2
                (if (local11)
                    (send gOwner:solvePuzzle(212 3 1))
                    (send gQg3Messager:say(5 6 77 0 self 700))
                )(else
                    (send gQg3Messager:say(5 6 78 0 self 700))
                )
            )
            (case 3
                (send global2:newRoom(gGClientModNum))
            )
        )
    )

)
(instance public monkeysEnter of Script
    (properties)

    (method (init theClient theCaller theRegister param4)
        = lastTicks gLastTicks
        (if (>= paramTotal 1)
            (send (= client theClient):script(self))
            (if (>= paramTotal 2)
                = caller theCaller
                (if (>= paramTotal 3)
                    = register theRegister
                    (if (>= paramTotal 4)
                        = local11 param4
                    )
                )
            )
        )
        = state (- start 1)
        (self:cue())
    )


    (method (changeState newState)
        (var temp0)
        (switch (= state newState)
            (case 0
                proc0_2()
                (send gOwner:setMotion(PolyPath 160 156 self))
                = temp0 0
                (while (< temp0 10)
                    (send (= newActor[temp0] (Actor:new())):
                        view(985)
                        loop(Random(0 3))
                        moveSpeed(0)
                        cycleSpeed(0)
                        x(
                            (if (Random(0 1))
                                -50
                            )(else
                                350
                            )
)
                        y(Random(100 500))
                        signal(16384)
                        setCycle(Walk)
                        init()
                    )
                    (if (== temp0 9)
                        (send newActor[temp0]:setScript(manuEnter 0 newActor[temp0]))
                    )(else
                        (send newActor[temp0]:setMotion(PolyPath local14[temp0] local24[temp0]))
                    )
                    ++temp0
                )
            )
            (case 1
                proc0_12(gOwner 160 200)
                (self:dispose())
            )
        )
    )

)
(instance monkeyExit of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                proc0_2()
                (send register:setMotion(PolyPath 
                    (if (Random(0 1))
                        -50
                    )(else
                        350
                    )
 Random(100 500) self))
            )
            (case 1
                (send register:dispose())
            )
        )
    )

)
(instance public manuInCage of Script
    (properties)

    (method (changeState newState)
        (var temp0)
        (switch (= state newState)
            (case 0
                (cage:
                    init()
                    approachX(154)
                    approachY(153)
                    approachVerbs(4 20 12)
                    signal(16384)
                )
                (send global2:addObstacle((send ((Polygon:new())):
                        type(2)
                        init(160 133 178 152 110 152 95 133)
                        yourself()
                    )
))
                (manu700:
                    init()
                    cycleSpeed(18)
                    setCycle(Fwd)
                )
                (self:dispose())
            )
        )
    )

)
(instance public openCage of Script
    (properties)

    (method (changeState newState)
        (var temp0)
        (switch (= state newState)
            (case 0
                proc0_2()
                proc0_4(109)
                (if (local0)
                    (send gOwner:setHeading(270 self))
                )(else
                    = state 3
                    (self:cue())
                )
                (cage:approachVerbs())
            )
            (case 1
                (send gOwner:
                    view(4)
                    loop(1)
                    cel(0)
                    setCycle(CT 3 1 self)
                )
            )
            (case 2
                = cycles 20
            )
            (case 3
                (send gOwner:setCycle(Beg self))
            )
            (case 4
                (send gOwner:
                    normalize()
                    setHeading(100)
                )
                (cage:cel(1))
                (send gLongSong2:
                    number(481)
                    setLoop(1)
                    play()
                )
                (manu700:
                    setLoop(2)
                    cel(0)
                    setCycle(Walk)
                    cycleSpeed(0)
                    moveSpeed(0)
                    setMotion(MoveTo 350 160 self)
                )
            )
            (case 5
                (send gOwner:solvePuzzle(315 8))
                = seconds 3
            )
            (case 6
                (manu700:
                    setLoop(3)
                    x(330)
                    y(34)
                    signal(| (manu700:signal) $0010)
                    priority(15)
                    cycleSpeed(6)
                    moveSpeed(6)
                    setMotion(MoveTo 291 45 self)
                )
            )
            (case 7
                (manu700:
                    loop(4)
                    z(100)
                    y(+ (manu700:y) 100)
                    setCycle(OccasionalCycle manu700 1 50 100)
                )
                = local52[0] @local34
                = local58[0] @local40
                (manuTell:init(manu700 @local34 @local52))
                (egoTell:init(gOwner @local40 @local58))
                proc0_3()
                (self:dispose())
            )
        )
    )

)
(instance public manuEncounter2 of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                proc0_2()
                (manu700:
                    init()
                    setCycle(Walk)
                    x(330)
                    y(34)
                    signal(| (manu700:signal) $0010)
                    priority(15)
                    cycleSpeed(6)
                    moveSpeed(6)
                    setMotion(MoveTo 291 45 self)
                    setLoop(3)
                )
            )
            (case 1
                (manu700:
                    z(100)
                    y(+ (manu700:y) 100)
                    loop(4)
                    setCycle(OccasionalCycle manu700 1 50 100)
                )
                (send gQg3Messager:say(5 6 9))
                = local58[0] @local45
                (egoTell:init(gOwner @local45 @local58))
                = local52[0] @local49
                (manuTell:init(manu700 @local49 @local52))
                proc0_3()
                (self:dispose())
            )
        )
    )

)
(instance manuLead of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                proc0_2()
                proc0_5(105)
                = cycles 20
            )
            (case 1
                proc0_4(93)
                (manu700:
                    z(0)
                    y(- (manu700:y) 100)
                    setLoop(2)
                    setCycle(Walk)
                    cycleSpeed(6)
                    moveSpeed(6)
                    setMotion(MoveTo 340 34)
                )
                (send gOwner:
                    setMotion(PolyPath 350 160 self)
                    solvePuzzle(316 3)
                )
            )
        )
    )

)
(instance public manuLeave of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                proc0_2()
                (manu700:
                    z(0)
                    y(- (manu700:y) 100)
                    setLoop(2)
                    setCycle(Walk)
                    cycleSpeed(6)
                    moveSpeed(6)
                    setMotion(MoveTo 340 34 self)
                )
                (egoTell:dispose())
            )
            (case 1
                proc0_3()
                (self:dispose())
            )
        )
    )

)
(instance manu700 of TargActor
    (properties
        x 131
        y 146
        noun 5
        view 987
        loop 1
        cel 3
        priority 7
        signal $6010
        cycleSpeed 1
        moveSpeed 0
    )

    (method (init)
        (self:approachVerbs(12 13 11))
        (super:init())
    )


    (method (doVerb theVerb param2)
        (if (proc999_5(theVerb 12 13 11))
            proc26_0(7)
        )(else
            (super:doVerb(theVerb rest param2))
        )
    )


    (method (getHurt)
        proc26_0(7)
    )

)
(instance public cage of View
    (properties
        x 133
        y 147
        noun 8
        view 987
    )

    (method (doVerb theVerb param2)
        (if ((== theVerb 4) or (== theVerb 20))
            (if (not proc0_6(109))
                = local0 1
                (manu700:setScript(openCage))
            )(else
                (super:doVerb(theVerb rest param2))
            )
        )(else
            (if (== theVerb -75)
                (manu700:setScript(openCage))
            )(else
                (super:doVerb(theVerb rest param2))
            )
        )
    )

)
(instance egoTell of Teller
    (properties)

    (method (dispose)
        (if (client)
            (send client:actions(0))
        )
        (super:dispose())
    )


    (method (doChild param1)
        return 
            (if (== param1 -10)
                (send gOwner:setScript(manuLead))
                return 1
            )(else
                (if (== param1 -36)
                    (send gOwner:setScript(manuLeave))
                )(else
                    ++local13
                    (send gQg3Messager:say(2 5 11 1 0 700))
                    (if (< local13 3)
                        (send gQg3Messager:say(2 5 11 (+ local13 1) 0 700))
                    )(else
                        (send gQg3Messager:say(2 5 11 5 0 700))
                        (send gQg3Messager:say(2 5 11 6 0 700))
                        (send gOwner:setScript(manuLead))
                    )
                    return 0
                )
            )
    )

)
(instance manuTell of Teller
    (properties)

    (method (doDialog param1)
        (var temp0)
        = temp0 (super:doDialog(rest param1))
        (if (== global365 8)
            (if (<> temp0 -999)
                ++local12
            )
            (if (== local12 3)
                (send client:setScript(manuLeave))
            )
        )(else
            = local45[1] -10
            = local45[2] -11
        )
        return temp0
    )

)
