(include "sci.sh")
(use "Main")
(use "eureka")
(use "Fuse")
(use "n255")
(use "Blink")
(use "CueObj")
(use "Cycle")
(use "Sounds")
(use "View")
(use "Obj")
(script 228)


(local
    theFuse
    local1
    local2

)
(procedure (localproc_0184 param1)
    (var temp0)
    = temp0 0
    (switch ((send param1:socketNum))
        (case 1
            (
            (if (== theFuse fuse1)
                = temp0 1
            )
 )
        )
        (case 2
            (
            (if (| (| (== theFuse fuse2) (== theFuse fuse5)) (== theFuse extraFuse))
                = temp0 1
            )
 )
        )
        (case 3
            (
            (if (== theFuse fuse3)
                = temp0 1
            )
 )
        )
        (case 4
            (
            (if (== theFuse fuse4)
                = temp0 1
            )
 )
        )
        (case 5
            (
            (if (| (| (== theFuse fuse5) (== theFuse fuse2)) (== theFuse extraFuse))
                = temp0 1
            )
 )
        )
        (case 6
            (
            (if (== theFuse fuse6)
                = temp0 1
            )
 )
        )
    )
    return temp0
)


(class Fuse of Actor
    (properties
        x 0
        y 0
        z 0
        heading 0
        noun 2
        modNum -1
        nsTop 0
        nsLeft 0
        nsBottom 0
        nsRight 0
        sightAngle 26505
        actions 0
        onMeCheck 26505
        state 0
        approachX 0
        approachY 0
        approachDist 0
        _approachVerbs 0
        yStep 15
        view 229
        loop 1
        cel 0
        priority 0
        underBits 0
        signal 20497
        lsTop 0
        lsLeft 0
        lsBottom 0
        lsRight 0
        brTop 0
        brLeft 0
        brBottom 0
        brRight 0
        scaleSignal 0
        scaleX 128
        scaleY 128
        maxScale 128
        cycleSpeed 6
        script 0
        cycler 0
        timer 0
        detailLevel 0
        scaler 0
        illegalBits 32768
        xLast 0
        yLast 0
        xStep 15
        origStep 770
        moveSpeed 0
        blocks 0
        baseSetter 0
        mover 0
        looper 0
        viewer 0
        avoider 0
        code 0
        socket 0
        track 0
        origX 0
        origY 0
        origZ 0
        origPri 0
        origHole 0
    )

    (method (init param1)
        (super:init(rest param1))
        (self:
            origX(x)
            origY(y)
            origZ(z)
            origPri(priority)
            origHole(socket)
            setLoop(1)
            setCel(0)
            stopUpd()
            setCycle(0)
        )
    )


    (method (doit param1)
        (super:doit(rest param1))
        (if (track)
            (self:
                x(- gPEventX 12)
                y(- gPEventY 8)
            )
        )
    )


    (method (doVerb param1 param2)
        (switch (param1)
            (case 4
                (
                (if (theFuse)
                    (send theFuse:drop())
                )(else
                    (self:pickup())
                )
 )
            )
            (default 
                ((super:doVerb(param1 rest param2)) )
            )
        )
    )


    (method (cue)
        (if (theFuse)
            (self:drop())
        )
    )


    (method (drop)
        = track 0
        (self:stopUpd())
        (if (not local2)
            (send gSq5IconBar:enable(1 6))
            (if ((send gSq5IconBar:curInvIcon))
                (send gSq5IconBar:enable(5))
            )
            (send ((send gSq5IconBar:at(2))):cursor(982))
            (send gSQ5:setCursor((send ((send gSq5IconBar:curIcon)):cursor)))
        )
        (if (socket)
            (switch (socket)
                (case 1
                    (self:
                        y(+ (self:y) 50)
                        z(50)
                    )
                    Palette(4 0 255 100)
                )
                (case 2
                    (self:
                        y(+ (self:y) 50)
                        z(50)
                    )
                    (if (proc0_1(72))
                        proc0_3(72)
                        proc0_2(73)
                        proc0_10(202 175)
                        (eureka:puke(6))
                        (badFuse:dispose())
                    )
                )
                (case 3
                    (self:
                        y(+ (self:y) 50)
                        z(50)
                    )
                    (send gRoom:drawPic(51 100))
                )
                (case 5
                    (if (proc0_1(95))
                        proc0_3(95)
                    )
                    (socket5:occupied(1))
                )
            )
            Display("EXIT" 100 8 20 105 1605 106 30 101 1 102 global155)
        )(else
            (send theFuse:setMotion(MoveTo 15 120))
        )
        = theFuse 0
    )


    (method (pickup)
        = theFuse self
        (self:
            startUpd()
            setPri(12)
        )
        (send ((send gSq5IconBar:at(2))):cursor(996))
        (send gSq5IconBar:curIcon((send gSq5IconBar:at(2))))
        (send gSQ5:setCursor(996))
        (if (socket)
            = theFuse 0
            (self:posn(15 (+ 40 (* (fuseList:size) 35))))
            (send gEgo:show())
            (send ((send gSq5IconBar:at(2))):cursor(982))
            (send gSQ5:setCursor((send ((send gSq5IconBar:curIcon)):cursor)))
            (fuseList:addToFront(self))
            (switch (socket)
                (case 1
                    (socket1:occupied(0))
                    (socketList:addToFront(socket1))
                    (self:setScript(sLightsFlicker))
                    (send gEgo:hide())
                )
                (case 2
                    (if (proc0_1(72))
                        (fuseList:delete(self))
                        (self:dispose())
                    )
                    (socketList:addToFront(socket2))
                    (socket2:occupied(0))
                    (send gEgo:hide())
                )
                (case 3
                    (send gRoom:drawPic(512 100))
                    (socket3:occupied(0))
                    (send gEgo:hide())
                    Display("EXIT" 100 8 20 105 1605 106 30 101 1 102 global155)
                    (socketList:addToFront(socket3))
                )
                (case 4
                    (socket4:occupied(0))
                    (socketList:addToFront(socket4))
                    (self:setScript(sPowerFailure))
                    (send gEgo:hide())
                )
                (case 5
                    (socketList:addToFront(socket5))
                    (socket5:occupied(0))
                    (send gEgo:hide())
                )
                (case 6
                    (socket6:occupied(0))
                    (socketList:addToFront(socket6))
                    (self:setScript(sLifeSupport))
                    (send gEgo:hide())
                )
            )
            Display("EXIT" 100 8 20 105 1605 106 30 101 1 102 global155)
            = z (= socket 0)
        )(else
            (send gSq5IconBar:disable(1 6))
            (if ((send gSq5IconBar:curInvIcon))
                (send gSq5IconBar:disable(5))
            )
            = track 1
        )
    )

)
(class Socket of Feature
    (properties
        x 0
        y 0
        z 0
        heading 0
        noun 0
        modNum -1
        nsTop 0
        nsLeft 0
        nsBottom 0
        nsRight 0
        sightAngle 26505
        actions 0
        onMeCheck 26505
        state 0
        approachX 0
        approachY 0
        approachDist 0
        _approachVerbs 0
        socketNum 0
        fusePri 0
        occupied 1
    )

    (method (doVerb param1 param2)
        (switch (param1)
            (case 4
                (
                (if (theFuse and not occupied)
                    (if (localproc_0184(self))
                        (send theFuse:
                            setPri((self:fusePri))
                            socket((self:socketNum))
                            track(0)
                            setMotion(MoveTo (self:x) (self:y) theFuse)
                        )
                        (socketList:delete(self))
                        (fuseList:delete(theFuse))
                        = occupied 1
                    )(else
                        (send gTestMessager:say(4 0 0 1))
                    )
                )
 )
            )
            (case 28
                (
                (if (not occupied and (| (== socketNum 2) (== socketNum 5)))
                    (socketList:delete(self))
                    (if ((== socketNum 2) and proc0_1(72))
                        proc0_3(72)
                        proc0_10(202 175)
                        proc0_2(73)
                        (badFuse:dispose())
                        (eureka:puke(6))
                    )
                    (if ((== socketNum 5) and proc0_1(95))
                        proc0_3(95)
                    )
                    (extraFuse:
                        init()
                        x((self:x))
                        y((self:y))
                        z((self:z))
                        socket((self:socketNum))
                        track(0)
                        setPri((self:fusePri))
                    )
                    = occupied 1
                    (extraFuse:cue())
                    (send gEgo:put(4))
                )
 )
            )
            (default 
                ((super:doVerb(param1 rest param2)) )
            )
        )
    )

)
(instance fuseList of List
    (properties)
)
(instance socketList of List
    (properties)
)
(instance public rm228 of Rm
    (properties
        picture 51
        style Fuse
    )

    (method (init param1)
        (var temp0)
        (send gRoom:setRegions(210))
        (send gEgo:
            view(229)
            posn(39 94)
            setLoop(0)
            setCel(0)
            init()
            hide()
        )
        (fuse1:init())
        (fuse2:init())
        (fuse3:init())
        (fuse4:init())
        (fuse5:init())
        (fuse6:init())
        (socket1:init())
        (socket2:init())
        (socket3:init())
        (socket4:init())
        (socket5:init())
        (socket6:init())
        (schematic:init())
        (fuseList:add())
        (tunnelExit:init())
        (send gSQ5:handsOn())
        (send gSq5IconBar:select((send gSq5IconBar:at(2))))
        (send gSQ5:setCursor(982))
        (send gSq5IconBar:disable(0 3 4 5))
        (switch (gGModNum)
            (case 225
                ( )
            )
            (default 
                (
                (if (>= (= temp0 proc255_1("Fuse State: \n\n\n(1) Shorted Fuse \n(2) Fuse is Okay\n")) 0)
                    = local1 temp0
                )(else
                    = local1 1
                )
 
                (switch (local1)
                    (case 1
                        ((send gEgo:get(4)) proc0_2(72) proc0_2(60)  )
                    )
                    (case 2
                        (proc0_3(72) proc0_2(60) (send gEgo:get(4)) )
                    )
                )
 )
            )
        )
        (badFuse:init())
        (super:init(rest param1))
        Display("EXIT" 100 8 20 105 1605 106 30 101 1 102 global155)
    )


    (method (doit param1)
        (if (GameIsRestarting())
            Display("EXIT" 100 8 20 105 1605 106 30 101 1 102 global155)
        )
        (super:doit(rest param1))
    )


    (method (dispose param1)
        (fuseList:
            release()
            dispose()
        )
        (socketList:
            release()
            dispose()
        )
        (super:dispose(rest param1))
    )


    (method (handleEvent)
        return 0
    )

)
(instance sExit of Script
    (properties)

    (method (changeState newState)
        (var temp0, temp1)
        (asm
            lap     newState
            aTop    state
            push    
            dup     
            ldi     0
            eq?     
            bnt     code_0950
            pushi   #handsOff
            pushi   0
            lag     gSQ5
            send    4
            ldi     1
            aTop    cycles
            sal     local2
            jmp     code_0c48
code_0950:  dup     
            ldi     1
            eq?     
            bnt     code_098d
            pushi   #size
            pushi   0
            lofsa   fuseList
            send    4
            bnt     code_0982
            pushi   #size
            pushi   0
            lofsa   socketList
            send    4
            bnt     code_097b
            pushi   #say
            pushi   5
            pushi   0
            pushi   0
            pushi   0
            pushi   1
            pushSelf
            lag     gTestMessager
            send    14
            jmp     code_0c48
code_097b:  ldi     1
            aTop    cycles
            jmp     code_0c48
code_0982:  pushi   #changeState
            pushi   1
            pushi   4
            self    6
            jmp     code_0c48
code_098d:  dup     
            ldi     2
            eq?     
            bnt     code_0ba2
            pushi   64
            pushi   #x
            pushi   #size
            pushi   0
            lofsa   fuseList
            send    4
            push    
            ldi     1
            sub     
            push    
            lofsa   fuseList
            send    6
            sat     temp0
            pushi   3
            pushi   #origHole
            pushi   0
            send    4
            push    
            pushi   2
            pushi   5
            calle   proc999_5, 6
            bnt     code_0b4c
            pushi   #occupied
            pushi   0
            lofsa   socket2
            send    4
            bnt     code_0a02
            pushi   #occupied
            pushi   0
            lofsa   socket5
            send    4
            bnt     code_0a02
            pushi   #get
            pushi   1
            pushi   4
            lag     gEgo
            send    6
            pushi   #delete
            pushi   1
            lst     temp0
            lofsa   fuseList
            send    6
            pushi   #dispose
            pushi   0
            lat     temp0
            send    4
            pushi   #say
            pushi   5
            dup     
            pushi   0
            pushi   0
            pushi   1
            pushSelf
            lag     gTestMessager
            send    14
            jmp     code_0c48
code_0a02:  pushi   #origHole
            pushi   0
            lat     temp0
            send    4
            push    
            dup     
            ldi     2
            eq?     
            bnt     code_0a82
            pushi   #occupied
            pushi   0
            lofsa   socket2
            send    4
            bnt     code_0a75
            pushi   #origX
            pushi   1
            pushi   #origX
            pushi   0
            lofsa   fuse5
            send    4
            push    
            pushi   704
            pushi   1
            pushi   #origY
            pushi   0
            lofsa   fuse5
            send    4
            push    
            pushi   709
            pushi   1
            pushi   #origZ
            pushi   0
            lofsa   fuse5
            send    4
            push    
            pushi   711
            pushi   1
            pushi   #origHole
            pushi   0
            lofsa   fuse5
            send    4
            push    
            pushi   710
            pushi   1
            pushi   #origPri
            pushi   0
            lofsa   fuse5
            send    4
            push    
            lat     temp0
            send    30
            pushi   #occupied
            pushi   1
            pushi   1
            lofsa   socket5
            send    6
            jmp     code_0af5
code_0a75:  pushi   #occupied
            pushi   1
            pushi   1
            lofsa   socket2
            send    6
            jmp     code_0af5
code_0a82:  dup     
            ldi     5
            eq?     
            bnt     code_0af5
            pushi   #occupied
            pushi   0
            lofsa   socket5
            send    4
            bnt     code_0aeb
            pushi   #origX
            pushi   1
            pushi   #origX
            pushi   0
            lofsa   fuse2
            send    4
            push    
            pushi   704
            pushi   1
            pushi   #origY
            pushi   0
            lofsa   fuse2
            send    4
            push    
            pushi   709
            pushi   1
            pushi   #origZ
            pushi   0
            lofsa   fuse2
            send    4
            push    
            pushi   711
            pushi   1
            pushi   #origHole
            pushi   0
            lofsa   fuse2
            send    4
            push    
            pushi   710
            pushi   1
            pushi   #origPri
            pushi   0
            lofsa   fuse2
            send    4
            push    
            lat     temp0
            send    30
            pushi   #occupied
            pushi   1
            pushi   1
            lofsa   socket2
            send    6
            jmp     code_0af5
code_0aeb:  pushi   #occupied
            pushi   1
            pushi   1
            lofsa   socket5
            send    6
code_0af5:  toss    
            pushi   1
            pushi   #x
            pushi   #origX
            pushi   0
            lat     temp0
            send    4
            push    
            pushi   0
            pushi   1
            pushi   #origY
            pushi   0
            lat     temp0
            send    4
            push    
            pushi   #origZ
            pushi   0
            lat     temp0
            send    4
            sub     
            push    
            pushi   708
            pushi   1
            pushi   #origHole
            pushi   0
            lat     temp0
            send    4
            push    
            pushi   63
            pushi   1
            pushi   #origPri
            pushi   0
            lat     temp0
            send    4
            push    
            lat     temp0
            send    24
            pushi   #drop
            pushi   0
            lat     temp0
            send    4
            pushi   #delete
            pushi   1
            lst     temp0
            lofsa   fuseList
            send    6
            ldi     1
            aTop    seconds
            jmp     code_0c48
code_0b4c:  pushi   1
            pushi   #x
            pushi   #origX
            pushi   0
            lat     temp0
            send    4
            push    
            pushi   0
            pushi   1
            pushi   #origY
            pushi   0
            lat     temp0
            send    4
            push    
            pushi   #origZ
            pushi   0
            lat     temp0
            send    4
            sub     
            push    
            pushi   708
            pushi   1
            pushi   #origHole
            pushi   0
            lat     temp0
            send    4
            push    
            pushi   63
            pushi   1
            pushi   #origPri
            pushi   0
            lat     temp0
            send    4
            push    
            lat     temp0
            send    24
            pushi   #drop
            pushi   0
            lat     temp0
            send    4
            pushi   #delete
            pushi   1
            lst     temp0
            lofsa   fuseList
            send    6
            ldi     1
            aTop    seconds
            jmp     code_0c48
code_0ba2:  dup     
            ldi     3
            eq?     
            bnt     code_0bc0
            pushi   #size
            pushi   0
            lofsa   fuseList
            send    4
            bnt     code_0bb9
            pTos    state
            ldi     2
            sub     
            aTop    state
code_0bb9:  ldi     1
            aTop    cycles
            jmp     code_0c48
code_0bc0:  dup     
            ldi     4
            eq?     
            bnt     code_0c14
            pushi   #occupied
            pushi   0
            lofsa   socket2
            send    4
            not     
            bnt     code_0c0e
            pushi   1
            pushi   72
            callb   proc0_1, 2
            not     
            bnt     code_0bff
            pushi   #say
            pushi   5
            pushi   4
            pushi   0
            pushi   1
            pushi   1
            pushSelf
            lag     gTestMessager
            send    14
            pushi   #dispose
            pushi   0
            lofsa   fuse5
            send    4
            pushi   #occupied
            pushi   1
            pushi   0
            lofsa   socket5
            send    6
            jmp     code_0c03
code_0bff:  ldi     1
            aTop    cycles
code_0c03:  pushi   #init
            pushi   0
            lofsa   fuse2
            send    4
            jmp     code_0c48
code_0c0e:  ldi     1
            aTop    cycles
            jmp     code_0c48
code_0c14:  dup     
            ldi     5
            eq?     
            bnt     code_0c32
            pushi   #occupied
            pushi   0
            lofsa   socket5
            send    4
            not     
            bnt     code_0c2c
            pushi   1
            pushi   95
            callb   proc0_2, 2
code_0c2c:  ldi     1
            aTop    cycles
            jmp     code_0c48
code_0c32:  dup     
            ldi     6
            eq?     
            bnt     code_0c48
            pushi   #newRoom
            pushi   1
            pushi   225
            lag     gRoom
            send    6
            pushi   #dispose
            pushi   0
            self    4
code_0c48:  toss    
            ret     
        )
    )

)
(instance sLightsFlicker of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (= seconds 1  )
            )
            (case 1
                (= register 100 (while (>= register 40)Palette(4 0 255 register) = register (- register 20)  ) )
            )
            (case 2
                ((send gEgo:hide()) = seconds 1  )
            )
            (case 3
                ((self:dispose()) )
            )
        )
    )

)
(instance sPowerFailure of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                ((send gSQ5:setCursor(996)) = register 100 (while (>= register 0)Palette(4 0 5 register) Palette(4 7 255 register) = register (- register 20)  ) = cycles 1  )
            )
            (case 1
                ((send gTestMessager:say(3 0 0 1 self))  )
            )
            (case 2
                ((send gRoom:drawPic(0)) proc0_9(4) (self:dispose()) )
            )
        )
    )

)
(instance sLifeSupport of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                ((send gSQ5:setCursor(996)) proc0_9(5) (self:dispose()) )
            )
        )
    )

)
(instance fuse1 of Fuse
    (properties
        x 121
        y 98
        z 50
        priority 8
        socket 1
    )
)
(instance fuse2 of Fuse
    (properties
        x 152
        y 97
        z 50
        priority 8
        socket 2
    )

    (method (init param1)
        (self:
            x(152)
            y(97)
            z(50)
            setPri(8)
            socket(2)
        )
        (super:init(rest param1))
    )

)
(instance fuse3 of Fuse
    (properties
        x 188
        y 96
        z 50
        priority 8
        socket 3
    )
)
(instance fuse4 of Fuse
    (properties
        x 131
        y 57
        priority 5
        socket 4
    )
)
(instance fuse5 of Fuse
    (properties
        x 160
        y 58
        priority 5
        socket 5
    )

    (method (init param1)
        (self:
            x(160)
            y(58)
            z(0)
            setPri(5)
            socket(5)
        )
        (super:init(rest param1))
        (if (proc0_1(95))
            (self:hide())
        )
    )

)
(instance fuse6 of Fuse
    (properties
        x 193
        y 57
        priority 5
        socket 6
    )
)
(instance extraFuse of Fuse
    (properties
        x 152
        y 97
        z 50
        priority 8
        socket 2
    )
)
(instance socket1 of Socket
    (properties
        x 121
        y 48
        nsTop 30
        nsLeft 118
        nsBottom 56
        nsRight 151
        socketNum 1
        fusePri 8
    )
)
(instance socket2 of Socket
    (properties
        x 152
        y 47
        nsTop 32
        nsLeft 153
        nsBottom 56
        nsRight 182
        socketNum 2
        fusePri 8
    )
)
(instance socket3 of Socket
    (properties
        x 188
        y 46
        nsTop 30
        nsLeft 187
        nsBottom 56
        nsRight 216
        socketNum 3
        fusePri 8
    )
)
(instance socket4 of Socket
    (properties
        x 131
        y 57
        nsTop 57
        nsLeft 133
        nsBottom 79
        nsRight 159
        socketNum 4
        fusePri 5
    )
)
(instance socket5 of Socket
    (properties
        x 160
        y 58
        nsTop 57
        nsLeft 160
        nsBottom 89
        nsRight 195
        socketNum 5
        fusePri 5
    )

    (method (init param1)
        (super:init(rest param1))
        (if (proc0_1(95))
            (self:occupied(0))
        )
    )

)
(instance socket6 of Socket
    (properties
        x 193
        y 57
        nsTop 57
        nsLeft 196
        nsBottom 89
        nsRight 240
        socketNum 6
        fusePri 5
    )
)
(instance badFuse of View
    (properties
        x 181
        y 96
        view 229
        loop 2
        priority 4
        signal 16401
    )

    (method (init param1)
        (if (proc0_1(72))
            (super:init(rest param1))
        )
    )

)
(instance schematic of Feature
    (properties
        x 180
        y 104
        nsTop 91
        nsLeft 151
        nsBottom 118
        nsRight 210
        sightAngle 40
        approachX 180
        approachY 104
    )

    (method (doVerb param1)
        (var temp0)
        = temp0 0
        (switch (param1)
            (case 1
                (
                (if (proc999_4(151 103 171 112 gPEventX gPEventY))
                    = temp0 1
                )(else
                    (if (proc999_4(173 103 191 112 gPEventX gPEventY))
                        = temp0 2
                    )(else
                        (if (proc999_4(192 103 210 112 gPEventX gPEventY))
                            = temp0 3
                        )(else
                            (if (proc999_4(151 118 171 126 gPEventX gPEventY))
                                = temp0 4
                            )(else
                                (if (proc999_4(173 118 191 126 gPEventX gPEventY))
                                    = temp0 5
                                )(else
                                    (if (proc999_4(192 118 210 126 gPEventX gPEventY))
                                        = temp0 6
                                    )
                                )
                            )
                        )
                    )
                )
 
                (if (temp0)
                    (send gTestMessager:say(1 0 0 temp0))
                )
 )
            )
            (default 
                ((super:doVerb(param1)) )
            )
        )
    )

)
(instance tunnelExit of Feature
    (properties
        x Fuse
        y Fuse
        nsTop Fuse
        nsBottom 45
        nsRight 39
    )

    (method (doVerb param1)
        (switch (param1)
            (case 4
                (
                (if (not theFuse)
                    (if (((fuseList:size) or not (socket2:occupied)) or not (socket5:occupied))
                        (send gSQ5:handsOff())
                        (send gRoom:setScript(sExit))
                    )(else
                        (send gSQ5:handsOff())
                        (send gRoom:newRoom(225))
                    )
                )(else
                    (super:doVerb(param1))
                )
 )
            )
            (default 
                ((super:doVerb(param1)) )
            )
        )
    )

)
(instance public rogTalker of Narrator
    (properties)

    (method (init param1)
        = font gFont
        (send (= gSq5Win gNewSpeakWindow):
            tailX(122)
            tailY(43)
            xOffset(10)
            isBottom(1)
        )
        (super:init(rest param1))
    )


    (method (dispose param1)
        = gSq5Win gSq5Win_2
        (super:dispose(rest param1))
    )

)
