(include "sci.sh")
(use "Main")
(use "Class_255_0")
(use "SysWindow")
(use "IconI")
(use "Obj")
(script 995)


(local
    local0[3]
    local3
    theGInvFirst
    local5

)
(procedure (localproc_01a2 param1 param2)
    (var temp0, temp1, temp2, temp3, temp4, temp5, temp6, temp7, gInvFirst, temp9, temp10, temp11, temp12, temp13, temp14, temp15, temp16, temp17, temp18, temp19, temp20)
    = temp0 (= temp1 (= temp2 (= temp3 (= temp4 (= temp5 0)))))
    = gInvFirst (send gInv:first())
    (if (> (* (= temp16 Sqrt(temp0)) (while (gInvFirst)
        (if ((send ((= temp9 NodeValue(gInvFirst))):isKindOf(InvI)) and (send temp9:ownedBy(param1)))
            (send temp9:signal((& (send temp9:signal) $fffb)))
            ++temp0
            (if (> (= temp6 CelWide((send temp9:view) (send temp9:loop) (send temp9:cel))) temp2)
(                = temp2 temp6
)            )
            (if (> (= temp7 CelHigh((send temp9:view) (send temp9:loop) (send temp9:cel))) temp1)
(                = temp1 temp7
)            )
        )(else
            (if ((send temp9:isMemberOf(IconI)))
                ++temp3
(                = temp5 (+ temp5 CelWide((send temp9:view) (send temp9:loop) (send temp9:cel)))
)
                (if (> (= temp7 CelHigh((send temp9:view) (send temp9:loop) (send temp9:cel))) temp4)
(                    = temp4 temp7
)                )
            )(else
                (send temp9:signal((| (send temp9:signal) $0004)))
            )
        )
 (= gInvFirst (send gInv:next(gInvFirst)))  )) temp0)
        --temp16
    )
    (if (> temp16 3)
        = temp16 3
    )
    (if (< (* temp16 (= local5 (/ temp0 temp16))) temp0)
        ++local5
    )
    = temp10 proc999_3((+ 4 temp5) (* local5 (+ 4 temp2)))
    = temp12 (/ (- 190 (= temp11 (* temp16 (+ 4 temp1)))) 2)
    = temp13 (/ (- 320 temp10) 2)
    = temp14 (+ temp12 temp11)
    = temp15 (+ temp13 temp10)
    (if ((send gInv:window))
        (send ((send gInv:window)):
            top(temp12)
            left(temp13)
            right(temp15)
            bottom(temp14)
            open()
        )
    )
    = temp20 local5
    (if (temp0)
        = temp18 (+ 2 
            (if ((send ((send gInv:window)):respondsTo(328)))
                (send ((send gInv:window)):yOffset)
            )(else
                0
            )
)
        = temp19 (= temp17 (+ 4 
                (if ((send ((send gInv:window)):respondsTo(327)))
                    (send ((send gInv:window)):xOffset)
                )(else
                    0
                )
))
        = gInvFirst (send gInv:first())
        (while (gInvFirst)
            (if (not (& (send ((= temp9 NodeValue(gInvFirst))):signal) $0004) and (send temp9:isKindOf(InvI)))
                (if (not & (send temp9:signal) $0080)
                    (send temp9:
                        nsLeft(+ temp17 (/ (- temp2 (= temp6 CelWide((send temp9:view) (send temp9:loop) (send temp9:cel)))) 2))
                        nsTop(+ temp18 (/ (- temp1 (= temp7 CelHigh((send temp9:view) (send temp9:loop) (send temp9:cel)))) 2))
                    )
                    (send temp9:
                        nsRight(+ (send temp9:nsLeft) temp6)
                        nsBottom(+ (send temp9:nsTop) temp7)
                    )
                    (if (--temp20)
                        = temp17 (+ temp17 temp2)
                    )(else
                        = temp20 local5
                        = temp18 (+ temp18 temp1)
                        = temp17 temp19
                    )
                )(else
                    = temp17 (send temp9:nsLeft)
                    = temp18 (send temp9:nsTop)
                )
                (send temp9:show())
                (if (== temp9 param2)
                    (send gGame:setCursor(5 1))
                    (send (= local3 temp9):highlight())
                    = theGInvFirst gInvFirst
                )
            )
            = gInvFirst (send gInv:next(gInvFirst))
        )
    )
    = temp17 (/ (- (- (send ((send gInv:window)):right()) (send ((send gInv:window)):left)) temp5) 2)
    = gInvFirst (send gInv:first())
    (while (gInvFirst)
        (if (not (send (= temp9 NodeValue(gInvFirst)):isMemberOf(InvI)))
            = temp6 CelWide((send temp9:view) (send temp9:loop) (send temp9:cel))
            = temp7 CelHigh((send temp9:view) (send temp9:loop) (send temp9:cel))
            (send temp9:
                nsLeft(temp17)
                nsTop(- (= temp11 (- (send ((send gInv:window)):bottom) (send ((send gInv:window)):top))) temp7)
                nsBottom(temp11)
                nsRight(+ temp17 temp6)
                signal(& (send temp9:signal) $fffb)
                show()
            )
            = temp17 (+ temp17 temp6)
        )
        = gInvFirst (send gInv:next(gInvFirst))
    )
)


(class InvI of IconI
    (properties
        view 0
        loop 0
        cel 0
        nsLeft 0
        nsTop 0
        nsRight 0
        nsBottom 0
        state 0
        cursor 999
        type 16384
        message 3
        modifiers 0
        signal 0
        helpStr 0
        maskView 0
        maskLoop 0
        maskCel 0
        highlightColor 0
        lowlightColor 0
        description 0
        owner 0
        script 0
        value 0
    )

    (method (show)
        (var temp0[4])
        DrawCel(view loop cel nsLeft nsTop -1)
    )


    (method (highlight param1)
        (var temp0, temp1, temp2, temp3, temp4)
        = temp4 
            (if (paramTotal and param1)
                highlightColor
            )(else
                lowlightColor
            )
        = temp0 (- nsTop 2)
        = temp1 (- nsLeft 2)
        = temp2 (+ nsBottom 1)
        Graph(4 temp0 temp1 temp0 = temp3 (+ nsRight 1) temp4 -1 -1)
        Graph(4 temp0 temp3 temp2 temp3 temp4 -1 -1)
        Graph(4 temp2 temp3 temp2 temp1 temp4 -1 -1)
        Graph(4 temp2 temp1 temp0 temp1 temp4 -1 -1)
        Graph(12 - nsTop 2 - nsLeft 2 + nsBottom 2 + nsRight 2 1)
    )


    (method (onMe param1)
        return 
            (if ((super:onMe(param1)))
                not & signal $0004
            )(else
                0
            )
    )


    (method (ownedBy param1)
        return == owner param1
    )


    (method (moveTo theOwner)
        = owner theOwner
        (if (value and (= theOwner gEgo))
            (send gGame:changeScore(value))
            = value 0
        )
        return self
    )


    (method (doVerb param1)
        (switch (param1)
            (case 1
                proc255_4(995 0 description)
            )
        )
    )

)
(class Inv of IconBar
    (properties
        elements 0
        size 0
        height 0
        underBits 0
        oldMouseX 0
        oldMouseY 0
        curIcon 0
        highlightedIcon 0
        prevIcon 0
        curInvIcon 0
        useIconItem 0
        helpIconItem 0
        port 0
        window 0
        state 0
        activateHeight 0
        normalHeading "Roger is carrying:"
        heading 0
        empty "nothing!"
        curScore "Score: %d out of %d"
        showScore 1
        iconBarInvItem 0
        okButton 0
        selectIcon 0
    )

    (method (init)
        = gInv self
        = heading normalHeading
    )


    (method (doit)
        (var temp0, temp1, temp2, temp3[4], temp7)
        (asm
code_07ce:  pushi   #new
            pushi   0
            class   Event
            send    4
            sat     temp1
            bnt     code_0b08
            pTos    state
            ldi     32
            and     
            bnt     code_0b08
            ldi     0
            sat     temp7
            pushi   #localize
            pushi   0
            lat     temp1
            send    4
            pToa    curIcon
            bnt     code_0878
            pushi   #modifiers
            pushi   0
            lat     temp1
            send    4
            not     
            bnt     code_0878
            pTos    curIcon
            pToa    selectIcon
            ne?     
            bnt     code_0878
            pushi   #type
            pushi   0
            lat     temp1
            send    4
            push    
            ldi     1
            eq?     
            bt      code_084d
            pushi   #type
            pushi   0
            lat     temp1
            send    4
            push    
            ldi     4
            eq?     
            bnt     code_0837
            pushi   #message
            pushi   0
            lat     temp1
            send    4
            push    
            ldi     13
            eq?     
            bnt     code_0837
            ldi     1
            sat     temp7
            bt      code_084d
code_0837:  pushi   #type
            pushi   0
            lat     temp1
            send    4
            push    
            ldi     256
            eq?     
            bnt     code_0878
            ldi     1
            sat     temp7
            bnt     code_0878
code_084d:  pTos    curIcon
            pToa    helpIconItem
            ne?     
            bt      code_0863
            pushi   #signal
            pushi   0
            pToa    helpIconItem
            send    4
            push    
            ldi     16
            and     
            bnt     code_0878
code_0863:  pushi   #type
            pushi   1
            pushi   16384
            pushi   40
            pushi   1
            pushi   #message
            pushi   0
            pToa    curIcon
            send    4
            push    
            lat     temp1
            send    12
code_0878:  pushi   1
            lst     temp1
            callk   MapKeyToDir, 2
            pushi   #type
            pushi   0
            lat     temp1
            send    4
            sat     temp2
            push    
            ldi     1
            eq?     
            bnt     code_08a9
            pushi   #modifiers
            pushi   0
            lat     temp1
            send    4
            bnt     code_08a9
            pushi   #advanceCurIcon
            pushi   0
            self    4
            pushi   #claimed
            pushi   1
            pushi   1
            lat     temp1
            send    6
            jmp     code_0afe
code_08a9:  lst     temp2
            ldi     0
            eq?     
            bnt     code_08d2
            pushi   #firstTrue
            pushi   2
            pushi   186
            lst     temp1
            self    8
            sat     temp0
            bnt     code_08d2
            push    
            pToa    highlightedIcon
            ne?     
            bnt     code_08d2
            pushi   #highlight
            pushi   1
            lst     temp0
            self    6
            jmp     code_0afe
code_08d2:  lst     temp2
            ldi     1
            eq?     
            bt      code_08f9
            lst     temp2
            ldi     4
            eq?     
            bnt     code_08f0
            pushi   #message
            pushi   0
            lat     temp1
            send    4
            push    
            ldi     13
            eq?     
            bt      code_08f9
code_08f0:  lst     temp2
            ldi     256
            eq?     
            bnt     code_0978
code_08f9:  pushi   1
            pTos    highlightedIcon
            callk   IsObject, 2
            bnt     code_0afe
            pushi   158
            pushi   #{-info-}
            pTos    highlightedIcon
            lst     temp2
            ldi     1
            eq?     
            push    
            self    8
            bnt     code_0afe
            pTos    highlightedIcon
            pToa    okButton
            eq?     
            bnt     code_0921
            jmp     code_0b08
            jmp     code_0afe
code_0921:  pTos    highlightedIcon
            pToa    helpIconItem
            eq?     
            bnt     code_0960
            pushi   #cursor
            pushi   0
            pToa    highlightedIcon
            send    4
            push    
            ldi     65535
            ne?     
            bnt     code_0947
            pushi   #setCursor
            pushi   1
            pushi   #cursor
            pushi   0
            pToa    helpIconItem
            send    4
            push    
            lag     gGame
            send    6
code_0947:  pToa    helpIconItem
            bnt     code_0afe
            pushi   17
            pushi   #superClass
            pushi   #signal
            pushi   0
            send    4
            push    
            ldi     16
            or      
            push    
            pToa    helpIconItem
            send    6
            jmp     code_0afe
code_0960:  pToa    highlightedIcon
            aTop    curIcon
            pushi   #setCursor
            pushi   2
            pushi   #cursor
            pushi   0
            pToa    curIcon
            send    4
            push    
            pushi   1
            lag     gGame
            send    8
            jmp     code_0afe
code_0978:  lst     temp2
            ldi     64
            and     
            bnt     code_09e5
            pushi   #message
            pushi   0
            lat     temp1
            send    4
            push    
            dup     
            ldi     3
            eq?     
            bnt     code_0998
            pushi   #advance
            pushi   0
            self    4
            jmp     code_09e1
code_0998:  dup     
            ldi     7
            eq?     
            bnt     code_09a8
            pushi   #retreat
            pushi   0
            self    4
            jmp     code_09e1
code_09a8:  dup     
            ldi     1
            eq?     
            bnt     code_09ba
            pushi   #retreat
            pushi   1
            lsl     local5
            self    6
            jmp     code_09e1
code_09ba:  dup     
            ldi     5
            eq?     
            bnt     code_09cc
            pushi   #advance
            pushi   1
            lsl     local5
            self    6
            jmp     code_09e1
code_09cc:  dup     
            ldi     0
            eq?     
            bnt     code_09e1
            lst     temp2
            ldi     4
            and     
            bnt     code_09e1
            pushi   #advanceCurIcon
            pushi   0
            self    4
code_09e1:  toss    
            jmp     code_0afe
code_09e5:  lst     temp2
            ldi     4
            eq?     
            bnt     code_0a17
            pushi   #message
            pushi   0
            lat     temp1
            send    4
            push    
            dup     
            ldi     9
            eq?     
            bnt     code_0a05
            pushi   #advance
            pushi   0
            self    4
            jmp     code_0a13
code_0a05:  dup     
            ldi     3840
            eq?     
            bnt     code_0a13
            pushi   #retreat
            pushi   0
            self    4
code_0a13:  toss    
            jmp     code_0afe
code_0a17:  lst     temp2
            ldi     16384
            eq?     
            bnt     code_0afe
            pushi   #firstTrue
            pushi   2
            pushi   186
            lst     temp1
            self    8
            sat     temp0
            bnt     code_0afe
            pushi   #message
            pushi   0
            lat     temp1
            send    4
            push    
            ldi     5
            eq?     
            bnt     code_0a7f
            lat     temp0
            bnt     code_0a5e
            pushi   #helpStr
            pushi   0
            send    4
            bnt     code_0a5e
            pushi   3
            pushi   995
            pushi   0
            pushi   #helpStr
            pushi   0
            lat     temp0
            send    4
            push    
            calle   proc255_4, 6
code_0a5e:  pushi   17
            pushi   #superClass
            pushi   #signal
            pushi   0
            pToa    helpIconItem
            send    4
            push    
            ldi     65519
            and     
            push    
            pToa    helpIconItem
            send    6
            pushi   #setCursor
            pushi   1
            pushi   999
            lag     gGame
            send    6
            jmp     code_0afe
code_0a7f:  lst     temp0
            pToa    okButton
            eq?     
            bnt     code_0a8d
            jmp     code_0b08
            jmp     code_0afe
code_0a8d:  pushi   #isMemberOf
            pushi   1
            class   IconI
            push    
            lat     temp0
            send    6
            bnt     code_0ac1
            pushi   #select
            pushi   2
            lst     temp0
            lat     temp7
            not     
            push    
            self    8
            bnt     code_0afe
            lat     temp0
            aTop    curIcon
            pushi   #setCursor
            pushi   2
            pushi   #cursor
            pushi   0
            pToa    curIcon
            send    4
            push    
            pushi   1
            lag     gGame
            send    8
            jmp     code_0afe
code_0ac1:  pToa    curIcon
            bnt     code_0afe
            pushi   #isMemberOf
            pushi   1
            class   InvI
            push    
            pToa    curIcon
            send    6
            bnt     code_0aee
            pushi   #doVerb
            pushi   2
            pushi   #message
            pushi   0
            pToa    curIcon
            send    4
            push    
            pushi   #indexOf
            pushi   1
            pTos    curIcon
            self    6
            push    
            lat     temp0
            send    8
            jmp     code_0afe
code_0aee:  pushi   #doVerb
            pushi   1
            pushi   #message
            pushi   0
            lat     temp1
            send    4
            push    
            lat     temp0
            send    6
code_0afe:  pushi   #dispose
            pushi   0
            lat     temp1
            send    4
            jmp     code_07ce
code_0b08:  pushi   #dispose
            pushi   0
            lat     temp1
            send    4
            pushi   #hide
            pushi   0
            self    4
            ret     
        )
    )


    (method (showSelf)
        (var temp0[9])
        (send gSounds:pause())
        (if (gPseudoMouse and (send gPseudoMouse:respondsTo(149)))
            (send gPseudoMouse:stop())
        )
        (if ((send gIconBar:height))
            (send gIconBar:hide())
        )
        (if (not window)
            = window (SysWindow:new())
        )
        (if ((send window:window))
            (send window:dispose())
            = window 0
        )
        (if (not okButton)
            = okButton NodeValue((self:first()))
        )
        = curIcon 0
        (send gGame:setCursor((send selectIcon:cursor)))
        (self:
            show()
            doit()
        )
    )


    (method (show)
        = state (| state $0020)
        localproc_01a2(gEgo (send gIconBar:curIcon))
    )


    (method (hide)
        (if (& state $0020)
            (send gSounds:pause(0))
            = state (& state $ffdf)
        )
        (if (window)
            (send window:dispose())
        )
        (if (IsObject(curIcon) and (send curIcon:isMemberOf(InvI)))
            (send gIconBar:
                curIcon((send ((send gIconBar:useIconItem)):
                        cursor((send curIcon:cursor))
                        yourself()
                    )
)
                curInvIcon(curIcon)
            )
            (if ((send curIcon:cursor))
                (send gGame:setCursor((send curIcon:cursor) 1))
            )
        )
    )


    (method (advance param1)
        (var temp0, temp1, temp2, temp3)
        (asm
            lap     paramTotal
            bnt     code_0699
            lap     param1
            jmp     code_069b
code_0699:  ldi     1
code_069b:  sat     temp1
            pushi   #indexOf
            pushi   1
            pTos    highlightedIcon
            self    6
            sat     temp2
            lst     temp1
            add     
            sat     temp3
code_06ab:  pushi   67
            pushi   1
            lst     temp3
            pToa    size
            le?     
            bnt     code_06bb
            lat     temp3
            jmp     code_06c3
code_06bb:  lst     temp3
            pTos    size
            ldi     1
            sub     
            mod     
code_06c3:  push    
            self    6
            sat     temp0
            pushi   1
            push    
            callk   IsObject, 2
            not     
            bnt     code_06dd
            pushi   1
            pushi   #first
            pushi   0
            self    4
            push    
            callk   NodeValue, 2
            sat     temp0
code_06dd:  pushi   #signal
            pushi   0
            lat     temp0
            send    4
            push    
            ldi     4
            and     
            not     
            bnt     code_06f2
            jmp     code_06f7
            jmp     code_06ab
code_06f2:  +at     temp3
            jmp     code_06ab
code_06f7:  pushi   177
            pushi   4
            lsg     global19
            pushi   1
            pushi   #nsLeft
            pushi   0
            lat     temp0
            send    4
            push    
            pushi   #nsRight
            pushi   0
            lat     temp0
            send    4
            push    
            pushi   #nsLeft
            pushi   0
            lat     temp0
            send    4
            sub     
            push    
            ldi     2
            div     
            add     
            push    
            pushi   #nsBottom
            pushi   0
            lat     temp0
            send    4
            push    
            ldi     3
            sub     
            push    
            lag     gGame
            send    12
            pushi   #highlight
            pushi   1
            lst     temp0
            self    6
            ret     
        )
    )


    (method (retreat param1)
        (var temp0, temp1, temp2, temp3)
        (asm
            lap     paramTotal
            bnt     code_0742
            lap     param1
            jmp     code_0744
code_0742:  ldi     1
code_0744:  sat     temp1
            pushi   #indexOf
            pushi   1
            pTos    highlightedIcon
            self    6
            sat     temp2
            push    
            lat     temp1
            sub     
            sat     temp3
code_0755:  pushi   #at
            pushi   1
            lst     temp3
            self    6
            sat     temp0
            pushi   1
            push    
            callk   IsObject, 2
            not     
            bnt     code_0773
            pushi   1
            pushi   #last
            pushi   0
            self    4
            push    
            callk   NodeValue, 2
            sat     temp0
code_0773:  pushi   #signal
            pushi   0
            lat     temp0
            send    4
            push    
            ldi     4
            and     
            not     
            bnt     code_0788
            jmp     code_078d
            jmp     code_0755
code_0788:  -at     temp3
            jmp     code_0755
code_078d:  pushi   177
            pushi   4
            lsg     global19
            pushi   1
            pushi   #nsLeft
            pushi   0
            lat     temp0
            send    4
            push    
            pushi   #nsRight
            pushi   0
            lat     temp0
            send    4
            push    
            pushi   #nsLeft
            pushi   0
            lat     temp0
            send    4
            sub     
            push    
            ldi     2
            div     
            add     
            push    
            pushi   #nsBottom
            pushi   0
            lat     temp0
            send    4
            push    
            ldi     3
            sub     
            push    
            lag     gGame
            send    12
            pushi   #highlight
            pushi   1
            lst     temp0
            self    6
            ret     
        )
    )


    (method (advanceCurIcon)
        (var theCurIcon)
        = theCurIcon curIcon
        (while ((send (= theCurIcon (self:at((% (+ (self:indexOf(theCurIcon)) 1) size)))):isMemberOf(InvI)))
        )
        = curIcon theCurIcon
        (send gGame:setCursor((send curIcon:cursor) 1))
    )


    (method (ownedBy param1)
        (self:firstTrue(202 param1))
    )

)
