(version 2)
(include "sci.sh")
(exports
    0 rm490
    1 yesuTalker
)
(use "Main")
(use "GloryWindow")
(use "TellerIcon")
(use "Print")
(use "Blink")
(use "IconI")
(use "GameControls")
(use "Game")
(use "View")
(use "Obj")
(script 490)


(local
    local0[8] = (0 16 17 -18 24 25 26 999 )
    local8[6] = (0 -19 21 22 23 999 )
    local14[3] = (0 20 999 )
    local17[9] = (0 16 27 28 29 30 31 32 999 )
    local26[9] = (0 16 33 40 34 35 39 42 999 )
    local35[5]
    local40[4] = (0 -18 -19 999 )
    local44[4] = (0 44 45 999 )
    local48[5] = (0 44 46 34 999 )
    local53[4] = (0 44 -47 999 )
    local57[4]
    local61
    local62[14]
    local76
    theHeading
    local78
    local79
    local80
    theGNewSpeed
    local82
    local83[14] = (209 181 154 130 104 77 56 86 113 141 167 194 221 238 )
    local97[14] = (62 69 75 82 89 95 115 121 115 108 100 93 87 68 )
    local111[90] = (3 3 3 3 3 3 0 3 3 3 3 3 3 0 143 129 103 94 68 57 36 65 77 101 115 141 156 178 13 15 20 17 24 26 45 50 49 42 47 38 37 20 220 209 190 168 159 132 110 142 166 173 195 211 222 238 152 162 163 171 173 179 197 205 199 196 193 183 177 157 5 22 34 36 55 55 48 49 -27 -15 -3 -5 20 47 57 59 58 61 51 42 )
    local201[14]
    local215
    local216
    local217
    local218

)
(procedure (localproc_0f53 param1 param2 param3 param4 param5)
    (var temp0, temp1, temp2, temp3, temp4[6], temp10[14], temp24, temp25, temp26, temp27, temp28)
    = temp24 1
    = temp25 -50
    = temp0 0
    (while (< temp0 6)
        (if (param5[temp0])
            = temp1 0
            (while (< temp1 14)
                = temp10[temp1] param5[temp1]
                ++temp1
            )
            = temp3 0
            = temp28 temp10[temp0]
            = temp10[temp0] 0
            = temp1 temp28
            = temp2 temp0
            (while (> temp1 0)
                (if (> ++temp2 13)
                    = temp2 0
                )
                (switch (temp2)
                    (case 6
                        ++temp3
                    )
                    (case 13
                        --temp3
                    )
                )
                ++temp10[temp2]
                --temp1
            )
            (if ((== temp2 6) and not param4)
                = temp3 (+ temp3 localproc_0f53(param1 param2 0 1 temp10[0] temp10[1] temp10[2] temp10[3] temp10[4] temp10[5] temp10[6] temp10[7] temp10[8] temp10[9] temp10[10] temp10[11] temp10[12] temp10[13]))
            )(else
                (if ((((<> temp2 6) and (<> temp2 13)) and (== temp10[temp2] 1)) and (> temp10[(- 12 temp2)] 0))
                    = temp3 (+ temp10[(- 12 temp2)] 1)
                    = temp10[temp2] 0
                    = temp10[(- 12 temp2)] 0
                )
                (if (> param2 1)
                    = temp27 localproc_0f53((- 1 param1) (- param2 1) 0 0 temp10[7] temp10[8] temp10[9] temp10[10] temp10[11] temp10[12] temp10[13] temp10[0] temp10[1] temp10[2] temp10[3] temp10[4] temp10[5] temp10[6])
                    (if (== temp27 -50)
                        = temp27 0
                    )
                    = temp3 (- temp3 temp27)
                )
            )
            (if ((param1 and (> temp3 temp25)) or (not param1 and (< temp3 temp25)))
                = temp25 temp3
                = temp24 1
                = temp4[0] temp0
            )(else
                (if (== temp3 temp25)
                    = temp4[(- ++temp24 1)] temp0
                )
            )
        )
        ++temp0
    )
    (if (== param2 local79)
        = local61 temp4[Random(0 (- temp24 1))]
    )
    return temp25
)


(procedure (localproc_1126)
    return not 
        (if (+ (+ (+ (+ (+ local62[0] local62[1]) local62[2]) local62[3]) local62[4]) local62[5])
            + (+ (+ (+ (+ local62[7] local62[8]) local62[9]) local62[10]) local62[11]) local62[12]
        )(else
            0
        )
)


(procedure (localproc_116d param1 param2)
    (if (local82)
        (send local82:stopUpd())
    )
    = local62[param1] param2
    (send local201[param1]:
        startUpd()
        cel(
            (if (> param2 14)
                14
            )(else
                param2
            )
)
    )
    = local82 local201[param1]
)


(procedure (localproc_1267)
    proc0_3()
    (send gMainIconBar:disable(5 6 7 8))
    (send gMainIconBar:enable(9))
    (tray:setScript(moveScript))
)


(instance public rm490 of Rm
    (properties
        picture 490
        style $0009
    )

    (method (init)
        proc0_2()
        (send gMainIconBar:disable(9))
        (send gOwner:noun(3))
        = theGNewSpeed gNewSpeed
        = gNewSpeed 1
        = local76 0
        (while (< local76 14)
            = local201[local76] (send ((tray:new())):
                    cel(local111[local76])
                    x((+ local83[(= local62[local76] local111[local76])] 48))
                    y((+ local97[local76] 37))
                    heading(local76)
                    init()
                    stopUpd()
                    yourself()
                )
            ++local76
        )
        = local79 global209
        = local80 0
        (super:init())
        (send gLongSong:
            setLoop(-1)
            changeTo(490)
        )
        (yesufuHead:init())
        (self:setScript(startGame))
        (send gQg3Walkers:add(self))
        (send gOwner:solvePuzzle(285 3))
    )


    (method (doit)
        (super:doit())
        (if ((tray:script))
            (send ((tray:script)):doit())
        )
        (if (GameIsRestarting())
            (yesufuHead:init())
        )
    )


    (method (dispose)
        = gNewSpeed theGNewSpeed
        (send gQg3Walkers:delete(self))
        (send ((send gOwner:actions)):dispose())
        (super:dispose())
    )


    (method (doVerb theVerb)
        (switch (theVerb)
            (case 3
                (send gOwner:addHonor(-20))
                (send global2:newRoom(480))
            )
            (case 2
                (send ((send gOwner:actions)):doVerb(theVerb))
            )
            (default 
                (super:doVerb(theVerb))
            )
        )
    )

)
(instance tray of Prop
    (properties
        view 490
        signal $4100
    )

    (method (doVerb theVerb param2)
        (var temp0[40])
        (if (== theVerb 2)
            (send ((send gOwner:actions)):doVerb(theVerb))
        )(else
            (if (== theVerb 1)
                Message(0 490 4 1 52 1 @temp0)
                (Print:
                    addTextF(@temp0 local62[heading])
                    init()
                )
            )(else
                (if (== theVerb 3)
                    (send global2:doVerb(3))
                )(else
                    (if (<> theVerb 4)
                        (super:doVerb(theVerb rest param2))
                    )(else
                        (if (< heading 6)
                            (send gQg3Messager:say(4 4 53))
                        )(else
                            (if (== heading 6)
                                (send gQg3Messager:say(4 4 54))
                            )(else
                                (if (== heading 13)
                                    (send gQg3Messager:say(4 4 55))
                                )(else
                                    (if (local62[heading])
                                        (tray:setScript(0))
                                        = theHeading heading
                                        (send global2:setScript(playersMove))
                                    )(else
                                        (send gQg3Messager:say(4 4 56))
                                    )
                                )
                            )
                        )
                    )
                )
            )
        )
    )

)
(instance startGame of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (if (== global454 0)
                    = local57[0] @local44
                    = local35[0] @local0
                    = local35[1] @local8
                    = local35[2] @local14
                    (egoTeller:init(gOwner @local44 @local57))
                    (yesuTeller:init(yesufuHead @local0 @local35 @local40))
                    = seconds 2
                )(else
                    (if (== global454 1)
                        = local57[0] @local48
                        = local35[0] @local17
                        (egoTeller:init(gOwner @local48 @local57))
                        (yesuTeller:init(yesufuHead @local17 @local35 @local40))
                        = seconds 2
                    )(else
                        (if (== global454 2)
                            = local57[0] @local53
                            = local35[0] @local26
                            (egoTeller:init(gOwner @local53 @local57))
                            (yesuTeller:init(yesufuHead @local26 @local35 @local40))
                            = seconds 2
                        )(else
                            ++global454
                            = local57[0] @local53
                            = local35[0] @local26
                            (egoTeller:init(gOwner @local53 @local57))
                            (yesuTeller:init(yesufuHead @local26 @local35 @local40))
                            localproc_1267()
                            (self:dispose())
                        )
                    )
                )
            )
            (case 1
                (if (== global454 0)
                    (send gQg3Messager:say(2 6 15 0 self))
                )(else
                    (if (== global454 1)
                        (send gQg3Messager:say(2 6 36 0 self))
                    )(else
                        (if (== global454 2)
                            (send gQg3Messager:say(2 6 34 0 self))
                        )
                    )
                )
                ++global454
            )
            (case 2
                localproc_1267()
                (self:dispose())
            )
        )
    )

)
(instance playersMove of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                = local216 0
                proc0_2()
                = ticks (+ (* (send gOwner:moveSpeed) 3) 1)
            )
            (case 1
                = local78 local62[theHeading]
                (send gLongSong2:
                    number(491)
                    setLoop(1)
                    play(127)
                )
                = ticks (+ (* (send gOwner:moveSpeed) 3) 1)
                localproc_116d(theHeading 0)
            )
            (case 2
                (if (> ++theHeading 13)
                    = theHeading 0
                )
                = ticks (+ (* (send gOwner:moveSpeed) 3) 1)
            )
            (case 3
                (send gLongSong2:
                    number(491)
                    setLoop(1)
                    play(127)
                )
                = ticks (+ (* (send gOwner:moveSpeed) 3) 1)
                localproc_116d(theHeading ++local62[theHeading])
            )
            (case 4
                = register 0
                (if (--local78)
                    = state (- state 3)
                    = cycles 1
                )(else
                    (if (not 
                    (if (== theHeading 6)
                    )(else
                        == theHeading 13
                    )
)
                        = cycles 1
                    )(else
                        (if (localproc_1126())
                            (send global2:setScript(gameDoneSequence))
                        )(else
                            (if ((== theHeading 13) and not local215)
                                ++local215
                                = register 1
                                (send gQg3Messager:say(2 6 13 0 self))
                            )(else
                                (if (localproc_1126())
                                    (send global2:setScript(gameDoneSequence))
                                )(else
                                    = register 2
                                    (send gQg3Messager:say(2 6 2 0 self))
                                )
                            )
                        )
                    )
                )
            )
            (case 5
                (if (== register 1)
                    localproc_1267()
                    (self:dispose())
                )(else
                    (if (== register 2)
                        (send global2:setScript(computersMove))
                    )(else
                        (if ((== local62[theHeading] 1) and local62[(- 12 theHeading)])
                            = ticks (+ (* (send gOwner:moveSpeed) 3) 1)
                            = local78 (+ local78 local62[theHeading])
                            localproc_116d(theHeading 0)
                        )(else
                            (if (localproc_1126())
                                (send global2:setScript(gameDoneSequence))
                            )(else
                                = register 2
                                (send gQg3Messager:say(2 6 2 0 self))
                            )
                        )
                    )
                )
            )
            (case 6
                (if (== register 2)
                    (send global2:setScript(computersMove))
                )(else
                    = theHeading (- 12 theHeading)
                    = ticks (+ (* (send gOwner:moveSpeed) 3) 1)
                )
            )
            (case 7
                = local78 (+ local78 local62[theHeading])
                localproc_116d(theHeading 0)
                (if (< theHeading 6)
                    (send gQg3Messager:say(2 6 6 0 self))
                )(else
                    = ticks (+ (* (send gOwner:moveSpeed) 3) 1)
                )
            )
            (case 8
                = ticks (+ (* (send gOwner:moveSpeed) 3) 1)
            )
            (case 9
                = ticks (+ (* (send gOwner:moveSpeed) 3) 1)
                localproc_116d(13 + local62[13] local78)
            )
            (case 10
                (if (localproc_1126())
                    (send global2:setScript(gameDoneSequence))
                )(else
                    (send gQg3Messager:say(2 6 2 0 self))
                )
            )
            (case 11
                (send global2:setScript(computersMove))
            )
        )
    )

)
(instance computersMove of Script
    (properties)

    (method (changeState newState)
        (var temp0)
        (switch (= state newState)
            (case 0
                = local215 0
                = cycles 1
            )
            (case 1
                = ticks (+ (* (send gOwner:moveSpeed) 3) 1)
            )
            (case 2
                proc0_2()
                (if (local80)
                    localproc_0f53(1 local79 1 0 local62[0] local62[1] local62[2] local62[3] local62[4] local62[5] local62[6] local62[7] local62[8] local62[9] local62[10] local62[11] local62[12] local62[13])
                )(else
                    = local80 1
                    (if (< Random(0 9) 7)
                        = local61 Random(3 5)
                    )(else
                        = local61 Random(0 1)
                    )
                    Wait(0)
                    Wait(6)
                )
                = ticks (+ (* (send gOwner:moveSpeed) 3) 1)
            )
            (case 3
                = local78 local62[local61]
                localproc_116d(local61 0)
                = ticks (+ (* (send gOwner:moveSpeed) 3) 1)
            )
            (case 4
                (if (> ++local61 13)
                    = local61 0
                )
                = ticks (+ (* (send gOwner:moveSpeed) 3) 1)
            )
            (case 5
                (send gLongSong2:
                    number(491)
                    setLoop(1)
                    play(127)
                )
                = ticks (+ (* (send gOwner:moveSpeed) 3) 1)
                localproc_116d(local61 ++local62[local61])
            )
            (case 6
                = register 0
                (if (--local78)
                    = state (- state 3)
                    = cycles 1
                )(else
                    (if (not 
                    (if (== local61 6)
                    )(else
                        == local61 13
                    )
)
                        = cycles 1
                    )(else
                        (if (localproc_1126())
                            (send global2:setScript(gameDoneSequence))
                        )(else
                            (if ((== local61 6) and not local216)
                                = local216 1
                                (send global2:setScript(self))
                            )(else
                                = register 3
                                (send gQg3Messager:say(2 6 4 0 self))
                            )
                        )
                    )
                )
            )
            (case 7
                (if (== register 3)
                    localproc_1267()
                    (self:dispose())
                )(else
                    (if ((== local62[local61] 1) and local62[(- 12 local61)])
                        = ticks (+ (* (send gOwner:moveSpeed) 3) 1)
                        = local78 (+ local78 local62[local61])
                        localproc_116d(local61 0)
                    )(else
                        (if (localproc_1126())
                            (send global2:setScript(gameDoneSequence))
                        )(else
                            = register 3
                            (send gQg3Messager:say(2 6 4 0 self))
                        )
                    )
                )
            )
            (case 8
                (if (== register 3)
                    localproc_1267()
                    (self:dispose())
                )(else
                    = local61 (- 12 local61)
                    = ticks (+ (* (send gOwner:moveSpeed) 3) 1)
                )
            )
            (case 9
                (if ((< 6 local61) and (< local61 13))
                    (send gQg3Messager:say(2 6 3 1 self))
                )(else
                    = ticks (+ (* (send gOwner:moveSpeed) 3) 1)
                )
                = local78 (+ local78 local62[local61])
                localproc_116d(local61 0)
            )
            (case 10
                = ticks (+ (* (send gOwner:moveSpeed) 3) 1)
            )
            (case 11
                = ticks (+ (* (send gOwner:moveSpeed) 3) 1)
                localproc_116d(6 + local62[6] local78)
            )
            (case 12
                (if (localproc_1126())
                    (send global2:setScript(gameDoneSequence))
                )(else
                    (send gQg3Messager:say(2 6 4 0 self))
                )
            )
            (case 13
                localproc_1267()
                (self:dispose())
            )
        )
    )

)
(instance gameDoneSequence of Script
    (properties)

    (method (dispose param1)
        localproc_1267()
        (super:dispose(rest param1))
    )


    (method (changeState newState)
        (var temp0[70], newIconI, temp71)
        (switch (= state newState)
            (case 0
                (send gOwner:useSkill(1 20))
                proc0_2()
                (send gQg3Messager:say(2 6 7 0 self))
            )
            (case 1
                (if (< local62[6] local62[13])
                    (send gQg3Messager:say(2 6 9 0 self))
                )(else
                    (if (> local62[6] local62[13])
                        (send gQg3Messager:say(2 6 8 0 self))
                    )(else
                        (send gQg3Messager:say(2 6 50 0 self))
                    )
                )
            )
            (case 2
                = cycles 8
            )
            (case 3
                (if (== local217 5)
                    = register 1
                    (send gQg3Messager:say(2 6 43 0 self))
                )(else
                    (send gQg3Messager:say(2 6 10 0 self))
                )
            )
            (case 4
                (if (register)
                    (send global2:newRoom(480))
                )(else
                    = temp71 (send gGame:setCursor(999))
                    = gNewGameControls (GameControls:new())
                    (send gNewGameControls:window((send ((GloryWindow:new())):
                            top(51)
                            left(64)
                            bottom(143)
                            right(257)
                            priority(15)
                            yourself()
                        )
))
                    = newIconI (send (ScriptID(0 17)):new(1 0 51 1 490))
                    (send newIconI:
                        view(935)
                        loop(1)
                        cel(0)
                        nsTop(2)
                        nsLeft(2)
                        modifiers(1)
                        signal(132)
                    )
                    (send gNewGameControls:add(newIconI))
                    = newIconI (send (ScriptID(0 17)):new(1 0 0 1 490))
                    (send newIconI:
                        nsTop(70)
                        nsLeft(29)
                        cursor(1)
                    )
                    (send gNewGameControls:add(newIconI))
                    = newIconI (send (ScriptID(0 17)):new(1 0 0 2 490))
                    (send newIconI:
                        nsTop(70)
                        nsLeft(129)
                        cursor(0)
                    )
                    (send gNewGameControls:add(newIconI))
                    = newIconI (IconI:new())
                    (send newIconI:
                        nsTop(25)
                        nsLeft(29)
                        view(490)
                        loop(0)
                        cel(local62[6])
                        maskView(490)
                        maskLoop(0)
                        maskCel(local62[newIconI])
                        signal(132)
                    )
                    (send gNewGameControls:add(newIconI))
                    = newIconI (IconI:new())
                    (send newIconI:
                        nsTop(25)
                        nsLeft(129)
                        view(490)
                        loop(0)
                        cel(local62[13])
                        maskView(490)
                        maskLoop(0)
                        maskCel(local62[newIconI])
                        signal(132)
                    )
                    (send gNewGameControls:add(newIconI))
                    = newIconI (textI:new(1 0 49 1 490 local62[6]))
                    (send newIconI:
                        nsTop(50)
                        nsLeft(19)
                        signal(132)
                    )
                    (send gNewGameControls:add(newIconI))
                    = newIconI (textI:new(1 0 48 1 490 local62[13]))
                    (send newIconI:
                        nsTop(50)
                        nsLeft(125)
                        signal(132)
                    )
                    (send gNewGameControls:add(newIconI))
                    (send gNewGameControls:
                        show()
                        dispose()
                    )
                    (send gGame:setCursor(temp71))
                    (if (gCursor)
                        ++local217
                        (send gQg3Messager:say(2 6 11 0 self))
                        = local76 0
                        (while (< local76 14)
                            (send local201[= local62[local76] local111[local76]]:
                                cel(local111[local76])
                                startUpd()
                            )
                            ++local76
                        )
                        = local80 0
                    )(else
                        = register 1
                        (send gQg3Messager:say(2 6 12 0 self))
                    )
                )
            )
            (case 5
                (if (register)
                    (send global2:newRoom(480))
                )(else
                    = local76 0
                    (while (< local76 14)
                        (send local201[local76]:stopUpd())
                        ++local76
                    )
                    (if (== local217 1)
                        (if (== global454 0)
                            (send gQg3Messager:say(2 6 37 0 self))
                        )(else
                            (if (== global454 1)
                                (send gQg3Messager:say(2 6 38 0 self))
                            )(else
                                (if (== global454 2)
                                    (send gQg3Messager:say(2 6 41 0 self))
                                )(else
                                    = ticks (+ (* (send gOwner:moveSpeed) 3) 1)
                                )
                            )
                        )
                    )(else
                        = ticks (+ (* (send gOwner:moveSpeed) 3) 1)
                    )
                )
            )
            (case 6
                (if (local218)
                    = local218 0
                    (self:dispose())
                )(else
                    = local218 1
                    (send global2:setScript(computersMove))
                )
            )
        )
    )

)
(instance textI of IconI
    (properties
        view 935
        loop 2
        cel 0
    )

    (method (new param1 param2 param3 param4 param5 param6)
        (var temp0, temp1, temp2, temp3[30])
        = temp0 Clone(self)
        (if (paramTotal)
            = temp1 Message(2 param5 param1 param2 param3 param4)
            (send temp0:message(Memory(2 temp1)))
            Message(0 param5 param1 param2 param3 param4 @temp3)
            Format((send temp0:message) @temp3 param6)
        )
        return temp0
    )


    (method (dispose)
        Memory(3 message)
        (super:dispose())
    )


    (method (show)
        = nsRight nsLeft
        Display(message 100 nsLeft = nsBottom nsTop 105 0 102 17 101 modifiers 106 189)
    )


    (method (select)
    )


    (method (highlight)
    )


    (method (mask)
    )

)
(instance yesufuHead of View
    (properties
        x 5
        y 8
        noun 2
        view 981
        loop 1
        priority 1
        signal $0010
    )

    (method (init)
        Graph(grFILL_BOX 10 10 98 126 1 12 -1)
        Graph(grUPDATE_BOX 10 10 98 126 1)
        (super:init())
        DrawCel(934 2 0 10 10 2)
    )

)
(instance yesuTeller of Teller
    (properties)

    (method (showDialog)
        (super:showDialog(25 local217 26 local217 31 local217 32 local217 39 local217 42 local217))
    )

)
(instance egoTeller of Teller
    (properties)

    (method (respond param1)
        (super:respond(rest param1))
        (if (== query 44)
            proc0_2()
            (send gQg3Messager:caller(self))
        )
        return 1
    )


    (method (doChild)
        (if (not proc0_6(286))
            (send gOwner:addHonor(20))
        )
        (send gOwner:solvePuzzle(286 3))
        return 1
    )


    (method (cue)
        (send gQg3Messager:caller(0))
        (send global2:newRoom(480))
    )

)
(instance public yesuTalker of Talker
    (properties
        x 5
        y 8
        view 981
        loop 1
        talkWidth 260
        back 57
        textX 20
        textY 100
    )

    (method (init param1)
        (super:init(yesuBust yesuEyes yesuMouth rest param1))
    )

)
(instance yesuMouth of Prop
    (properties
        nsTop 54
        nsLeft 39
        view 981
    )
)
(instance yesuEyes of Prop
    (properties
        nsTop 38
        nsLeft 34
        view 981
        loop 2
    )
)
(instance yesuBust of View
    (properties
        nsTop 21
        nsLeft 31
        view 981
        loop 3
    )
)
(instance moveScript of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                = seconds 20
            )
            (case 1
                (send gQg3Messager:say(2 6 5 1 self))
            )
            (case 2
                (self:init())
            )
        )
    )

)
