(include "sci.sh")
(use "Main")
(use "Tool")
(use "Cycle")
(use "Sounds")
(use "View")
(use "Obj")
(script 226)


(local
    theTool

)
(procedure (localproc_010c)
    return 
        (if (proc999_4(0 163 110 200 theTool))
            box1
        )(else
            (if (proc999_4(111 163 216 200 theTool))
                box2
            )(else
                (if (proc999_4(217 163 319 200 theTool))
                    box3
                )(else
                    0
                )
            )
        )
)


(procedure (localproc_0162)
    (var temp0[50])
    GetMessage(0 226 7 4 0 1 @temp0)
    Display(@temp0 100 25 173 105 1605 106 60 101 1 102 global152)
    GetMessage(0 226 17 4 0 1 @temp0)
    Display(@temp0 100 133 169 105 1605 106 60 101 1 102 global152)
    GetMessage(0 226 3 4 0 1 @temp0)
    Display(@temp0 100 240 169 105 1605 106 60 101 1 102 global152)
)


(instance public rm226 of Rm
    (properties
        noun 2
        picture 50
    )

    (method (init param1)
        (send gRoom:setRegions(210))
        = theTool 0
        (vac:init())
        (fuse:init())
        (welder:init())
        (dropper:init())
        (gizmo1:init())
        (drill1:init())
        (wrench1:init())
        (fuse2:init())
        (cutter:init())
        (drill2:init())
        (screwdriver:init())
        (antacids:init())
        (gizmo2:init())
        (gizmo3:init())
        (soldergun:init())
        (pliers:init())
        (hammer:init())
        (gizmo4:init())
        (gizmo5:init())
        (holePunch:init())
        (super:init(rest param1))
        (box1:addToPic())
        (box2:addToPic())
        (box3:addToPic())
        localproc_0162()
        (send gSQ5:handsOn())
        (send gSq5IconBar:disable(0 3 4 5 6))
    )


    (method (doit param1)
        (if (GameIsRestarting())
            localproc_0162()
        )
        (super:doit(rest param1))
    )


    (method (doVerb param1 param2)
        (var temp0)
        (switch (param1)
            (case 4
                (
                (if (theTool)
                    (if (= temp0 localproc_010c())
                        (send (= temp0 localproc_010c()):doVerb(4))
                    )(else
                        (send theTool:drop())
                    )
                )
 )
            )
            (default 
                ((super:doVerb(param1 rest param2)) )
            )
        )
    )

)
(class Tool of Actor
    (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
        yStep 15
        view 234
        loop 0
        cel 0
        priority 0
        underBits 0
        signal 22528
        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 rm226
        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
        track 0
        origX 0
        origY 0
        invItem -1
    )

    (method (init param1)
        (if ((== invItem -1) or not (send gEgo:has(invItem)))
            (super:init(rest param1))
            (self:setCycle(0))
            = origX x
            = origY y
            (self:stopUpd())
        )
    )


    (method (doit param1)
        (super:doit(rest param1))
        (if (track)
            (if ((< 30 gPEventX) and (< gPEventX 290))
                (self:x(gPEventX))
            )
            (if ((< 15 gPEventY) and (< gPEventY 180))
                (self:y(gPEventY))
            )
        )
    )


    (method (doVerb param1 param2)
        (var temp0)
        (switch (param1)
            (case 4
                (
                (if (theTool)
                    (if (= temp0 localproc_010c())
                        (send (= temp0 localproc_010c()):doVerb(4))
                    )(else
                        (send theTool:drop())
                    )
                )(else
                    (self:pickUp())
                )
 )
            )
            (default 
                ((super:doVerb(param1 rest param2)) )
            )
        )
    )


    (method (cue)
        (self:
            track(0)
            stopUpd()
        )
        = theTool 0
    )


    (method (drop)
        = track 0
        (self:stopUpd())
        = theTool 0
        (self:setPri(-1))
        (send ((send gSq5IconBar:at(2))):cursor(982))
        (send gSq5IconBar:enable(1 7 8))
        (send gSQ5:setCursor((send ((send gSq5IconBar:curIcon)):cursor)))
    )


    (method (pickUp)
        = track 1
        (self:startUpd())
        = theTool self
        (self:setPri(15))
        (send ((send gSq5IconBar:at(2))):cursor(996))
        (send gSq5IconBar:curIcon((send gSq5IconBar:at(2))))
        (send gSq5IconBar:disable(1 7 8))
        (send gSQ5:setCursor(996))
    )

)
(instance putToolBack of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (
                (if (== client gRoom)
                    (send gSQ5:handsOn())
                    (send gSQ5:handsOff())
                    (send gTestMessager:say(22 0 1 0 self))
                )(else
                    = cycles 1
                )
 )
            )
            (case 1
                ((send theTool:
                    track(0)
                    setMotion(MoveTo (send theTool:origX) (send theTool:origY) self)
                )
  )
            )
            (case 2
                ((send theTool:cue()) 
                (if (== client gRoom)
                    (send gSQ5:handsOn())
                    (send ((send gSq5IconBar:at(2))):cursor(982))
                    (send gSQ5:setCursor((send ((send gSq5IconBar:curIcon)):cursor)))
                    (send gSq5IconBar:disable(0 3 4 5 6))
                )
 (self:dispose()) )
            )
        )
    )

)
(instance putAllBack of Script
    (properties)

    (method (changeState newState)
        (var temp0)
        (switch (= state newState)
            (case 0
                ((send gSQ5:handsOn()) (send gSQ5:handsOff()) (send gTestMessager:say(22 0 2 0 self)) = register (- (send gCast:size) 1)  )
            )
            (case 1
                (
                (if ((<> (send ((= theTool (send gCast:at(register)))):origX) (send theTool:x)) or (<> (send theTool:origY) (send theTool:y)))
                    (self:setScript(putToolBack self))
                )(else
                    = cycles 1
                )
 )
            )
            (case 2
                (
                (if (register)
                    --register
                    = state (- state 2)
                )
 = cycles 1  )
            )
            (case 3
                (= theTool 0 (send gSQ5:handsOn()) (send ((send gSq5IconBar:at(2))):cursor(982)) (send gSQ5:setCursor((send ((send gSq5IconBar:curIcon)):cursor))) (send gSq5IconBar:disable(0 3 4 5 6)) (self:dispose()) )
            )
        )
    )

)
(instance takeTool of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                ((send gTestMessager:say(22 0 3 0 self))  )
            )
            (case 1
                ((send gEgo:get((send theTool:invItem))) (send theTool:
                    startUpd()
                    hide()
                    track(0)
                )
 = cycles 4  )
            )
            (case 2
                ((send theTool:
                    drop()
                    dispose()
                )
 = theTool 0 (send gSQ5:handsOn()) (send ((send gSq5IconBar:at(2))):cursor(982)) (send gSQ5:setCursor((send ((send gSq5IconBar:curIcon)):cursor))) (send gSq5IconBar:disable(0 3 4 5 6)) (self:dispose()) )
            )
        )
    )

)
(instance vac of Tool
    (properties
        x 154
        y Tool
        noun 24
    )
)
(instance gizmo2 of Tool
    (properties
        x 162
        y 98
        noun 9
        cel 1
    )
)
(instance welder of Tool
    (properties
        x 126
        y 105
        noun 23
        loop 1
        invItem 7
    )
)
(instance dropper of Tool
    (properties
        x 112
        y 109
        noun rm226
        loop 1
        cel 1
    )
)
(instance gizmo1 of Tool
    (properties
        x 189
        y 88
        noun 10
        loop 2
    )
)
(instance drill1 of Tool
    (properties
        x 154
        y 90
        noun 4
        loop 2
        cel 1
    )
)
(instance wrench1 of Tool
    (properties
        x 114
        y 75
        noun 25
        loop 3
    )
)
(instance fuse2 of Tool
    (properties
        x 160
        y 100
        noun 11
        loop 3
        cel 1
    )
)
(instance cutter of Tool
    (properties
        x 119
        y 81
        noun 18
        loop 4
    )
)
(instance drill2 of Tool
    (properties
        x 174
        y 102
        noun 5
        loop 4
        cel 1
    )
)
(instance screwdriver of Tool
    (properties
        x 182
        y 82
        noun 20
        loop 5
    )
)
(instance gizmo5 of Tool
    (properties
        x 103
        y 79
        noun 13
        loop 5
        cel 1
    )
)
(instance fuse of Tool
    (properties
        x 97
        y 92
        noun 8
        loop 11
        invItem 4
    )
)
(instance gizmo3 of Tool
    (properties
        x 164
        y 96
        noun 12
        loop rm226
        cel 1
    )
)
(instance soldergun of Tool
    (properties
        x 203
        y 101
        noun 14
        loop 7
    )
)
(instance pliers of Tool
    (properties
        x 195
        y 61
        noun 19
        loop 7
        cel 1
    )
)
(instance hammer of Tool
    (properties
        x 188
        y 88
        noun 15
        loop 8
    )
)
(instance gizmo4 of Tool
    (properties
        x 136
        y 79
        noun 21
        loop 8
        cel 1
    )
)
(instance holePunch of Tool
    (properties
        x 103
        y 79
        noun 16
        loop 9
        invItem 11
    )
)
(instance antacids of Tool
    (properties
        x 187
        y 53
        noun 1
        loop 9
        cel 1
        invItem 5
    )

    (method (init param1)
        (if (not proc0_1(170))
            (super:init(rest param1))
        )
    )

)
(instance box1 of View
    (properties
        x 17
        y 163
        noun 7
        view 234
        loop 10
        signal 16400
    )

    (method (doVerb param1 param2)
        (switch (param1)
            (case 4
                ((send gSQ5:handsOn()) (send ((send gSq5IconBar:at(2))):cursor(982)) (send gSQ5:handsOff()) (send gRoom:newRoom(225))  )
            )
            (default 
                ((super:doVerb(param1 rest param2)) )
            )
        )
    )

)
(instance box2 of View
    (properties
        x 123
        y 163
        noun 17
        view 234
        loop 10
        signal 16400
    )

    (method (doVerb param1 param2)
        (switch (param1)
            (case 4
                (
                (if (theTool)
                    (if (<> (send theTool:invItem) -1)
                        (switch ((send theTool:invItem))
                            (case 5
                                proc0_10(170 15)
                            )
                            (case 7
                                proc0_10(173 5)
                            )
                            (case 11
                                proc0_10(172 5)
                            )
                            (case 4
                                proc0_10(251 5)
                            )
                        )
                        (send gRoom:setScript(takeTool))
                    )(else
                        (send gRoom:setScript(putToolBack))
                    )
                )
 )
            )
            (default 
                ((super:doVerb(param1 rest param2)) )
            )
        )
    )

)
(instance box3 of View
    (properties
        x 229
        y 163
        noun 3
        view 234
        loop 10
        signal 16400
    )

    (method (doVerb param1 param2)
        (switch (param1)
            (case 4
                ((send gRoom:setScript(putAllBack))  )
            )
            (default 
                ((super:doVerb(param1 rest param2)) )
            )
        )
    )

)
