(version 2)
(include "sci.sh")
(exports
    0 Vendor
    1 Class_47_1
    2 barter
    3 proc47_3
)
(use "Main")
(use "GloryWindow")
(use "IconI")
(use "GameControls")
(use "Obj")
(script 47)


(local
    local0
    local1[4] = (3 128 3 128 )
    local5[4] = (18 18 36 36 )
    local9
    local10
    local11
    local12
    theIconI
    local14
    local15
    local16
    local17
    local18
    local19
    local20
    local21
    local22
    local23
    local24
    local25[30]
    local55[30]
    local85
    local86

)
(procedure public (proc47_3 param1 param2)
    (var temp0, temp1, temp2[20])
    = local0 1
    (send gLongSong3:
        number(260)
        setLoop(4)
        play()
    )
    = temp1 (send gInv:at(0))
    = temp0 (send ((send local15:goods)):at(param1))
    (if (== (send temp0:denomination) 100)
        (if (<= (* (send temp0:price) param2) (send temp1:amount))
            (send temp1:amount((- (send temp1:amount) (* (send temp0:price) param2))))
        )(else
            = global410 (+ global410 (* (send temp1:amount) 100))
            (send temp1:amount(0))
            = global410 (- global410 (* (* (send temp0:price) param2) 100))
        )
    )(else
        (if (<= (* (send temp0:price) param2) global410)
            = global410 (- global410 (* (send temp0:price) param2))
        )(else
            (while (> (* (send temp0:price) param2) global410)
                = global410 (+ global410 100)
                (send temp1:amount((- (send temp1:amount) 1)))
            )
            = global410 (- global410 (* (send temp0:price) param2))
        )
    )
    (send ((send ((send local15:goods)):at(param1))):quantity((- (send ((send ((send local15:goods)):at(param1))):quantity) param2)))
    (if ((send temp1:amount) and (== (send temp1:message) 59))
        (send temp1:message(10))
    )
    (if (((not global410 and not (send temp1:amount)) and global424) and (== (send temp1:message) 10))
        (send temp1:message(59))
    )
)


(procedure (localproc_12e6)
    Message(0 47 10 0 0 1 @local55)
    Display(@local55 100 3 22 102 1 105 123)
    Message(0 47 10 0 0 2 @local55)
    Display(Format(@local25 @local55 (send ((send theIconI:cursor)):name) local12 (send ((send theIconI:cursor)):symbol)) 100 3 37 102 1 105 123)
)


(procedure (localproc_135c)
    (var temp0)
    = temp0 0
    (if (& local9 $0001)
        Display(@temp0 108 local17)
    )(else
        (if (local17)
            Display(@temp0 108 local17)
        )
        (if (== local11 1)
            Message(0 47 9 0 0 1 @local55)
            = local17 Display(Format(@local25 @local55 local12 (send ((send theIconI:cursor)):symbol)) 100 3 73 102 1 105 123 107)
        )(else
            Message(0 47 9 0 0 2 @local55)
            = local17 Display(Format(@local25 @local55 (* local11 local12) (send ((send theIconI:cursor)):symbol)) 100 3 73 102 1 105 123 107)
        )
    )
)


(procedure (localproc_1426)
    (var temp0)
    (if (local16)
        = temp0 0
        Display(@temp0 108 local16)
    )
    (if ((send ((send gInv:at(0))):amount))
        (if (global410)
            Message(0 47 8 0 0 2 @local55)
            = local16 Display(Format(@local25 @local55 (send ((send gInv:at(0))):amount) global410) 100 3 57 102 1 105 123 107)
        )(else
            Message(0 47 8 0 0 1 @local55)
            = local16 Display(Format(@local25 @local55 (send ((send gInv:at(0))):amount)) 100 3 57 102 1 105 123 107)
        )
    )(else
        Message(0 47 8 0 0 3 @local55)
        = local16 Display(Format(@local25 @local55 global410) 100 3 57 102 1 105 123 107)
    )
    (if (local19)
        (if (local18)
            = local18 0
        )(else
            (if (local22)
                = local22 0
            )(else
                (barter:eachElementDo(217))
            )
        )
    )(else
        = local19 1
    )
)


(procedure (localproc_154f)
    localproc_12e6()
    (quantityIcon:show())
)


(procedure (localproc_155e)
    localproc_135c()
    (quantityIcon:show())
)


(procedure (localproc_156d)
    return 
        (if (== (send ((send theIconI:cursor)):denomination) 100)
            (if (>= (+ (/ global410 100) (send ((send gInv:at(0))):amount)) (* local12 local11))
                return 1
            )(else
                return 0
            )
        )(else
            (if (>= global410 (* local12 local11))
                return 1
            )(else
                (if (>= (+ (* (send ((send gInv:at(0))):amount) 100) global410) (* local12 local11))
                    return 1
                )(else
                    return 0
                )
            )
        )
)


(class public Vendor of Obj
    (properties
        goods 0
        timesBargained 0
        prevBargain 0
        discount 0
        header 0
        script 0
        noun 0
    )

    (method (init)
        (var temp0)
        (if (IsObject(gNewCollect))
            (send gNewCollect:add(self))
        )(else
            = gNewCollect (Collect:new())
            (send gNewCollect:add(self))
        )
        = temp0 Message(2 gClientModNum noun 0 0 1)
        = header Memory(2 temp0)
        Message(0 gClientModNum noun 0 0 1 header)
    )


    (method (dispose)
        (if (IsObject(gNewCollect))
            (send gNewCollect:delete(self))
        )
        (if (goods)
            (send goods:dispose())
        )
        (if (noun and header)
            Memory(3 header)
        )
        (super:dispose())
    )


    (method (purchase)
        (barter:
            init(self)
            dispose()
        )
        return not local86
    )


    (method (canStillBargain)
        return 
            (switch ((send theIconI:message))
                (case 0
                    return not & prevBargain $0001
                )
                (case 1
                    return not & prevBargain $0002
                )
                (case 2
                    return not & prevBargain $0004
                )
                (case 3
                    return not & prevBargain $0008
                )
            )
    )


    (method (bargain param1)
        (var temp0, temp1, temp2, temp3)
        (switch (param1)
            (case 0
                = prevBargain (| prevBargain $0001)
            )
            (case 1
                = prevBargain (| prevBargain $0002)
            )
            (case 2
                = prevBargain (| prevBargain $0004)
            )
            (case 3
                = prevBargain (| prevBargain $0008)
            )
        )
        (if (== gGOwnerMaxStamina[13] 550)
            = temp0 550
        )(else
            = temp0 (/ (* gGOwnerMaxStamina[13] (- 100 (* 10 timesBargained))) 100)
        )
        (if (< temp0 100)
            = temp0 100
        )
        ++timesBargained
        = temp1 (send ((send goods:at(param1))):price)
        = temp2 (/ (* (- 100 (/ (- temp0 100) 4)) temp1) 100)
        (if (>= local10 temp2)
            (send ((send goods:at(param1))):price(local10))
            = local12 local10
            = local18 1
            = local20 0
            (self:doBargain(1 param1))
        )(else
            (if (>= local10 (/ temp2 2))
                (send ((send goods:at(param1))):price((- temp1 (/ (- temp1 temp2) 4))))
                = local10 (send ((send goods:at(param1))):price)
                = local12 local10
                (switch (% (+ timesBargained 2) 3)
                    (case 0
                        (self:doBargain(2 param1))
                    )
                    (case 1
                        (self:doBargain(3 param1))
                    )
                    (case 2
                        (self:doBargain(4 param1))
                    )
                )
            )(else
                (if (>= local10 (/ temp2 4))
                    = local18 1
                    = local20 0
                    (self:doBargain(5 param1))
                )(else
                    = local18 1
                    = local20 0
                    (self:doBargain(6 param1))
                )
            )
        )
    )


    (method (transact)
    )


    (method (doBargain)
    )


    (method (cue)
        (var temp0)
        (if (local0)
            = local0 0
            = local22 1
            (if (> local11 1)
                (send gQg3Messager:say(11 6 2 0 self 47))
            )(else
                (send gQg3Messager:say(11 6 3 0 self 47))
            )
        )(else
            (send gGame:setCursor(999))
            = local21 0
            (if (& local9 $0001)
                = local11 1
            )
            (if ((& local9 $0004) and local18)
                = local9 2
            )
            (if (not (send ((send theIconI:cursor)):quantity) and (== local23 1))
                (barter:state((& (barter:state) $ffdf)))
            )(else
                (barter:show())
            )
        )
    )


    (method (setScript theScript sendParams)
        (if (IsObject(script))
            (send script:dispose())
        )
        (if (theScript)
            (send theScript:init(self rest sendParams))
        )
    )

)
(class public Class_47_1
    (properties
        name 0
        price 0
        quantity 0
        denomination 100
        symbol 0
    )

    (method (dispose)
        DisposeClone(self)
        (if (dynamicName)
            Memory(3 name)
        )
        Memory(3 symbol)
    )


    (method (new param1)
        (var temp0, temp1, temp2)
        = temp0 Clone(self)
        (if (paramTotal)
            (send temp0:dynamicName(1))
            = temp1 Message(2 gClientModNum param1 38 0 1)
            (send temp0:name(Memory(2 temp1)))
            Message(0 gClientModNum param1 38 0 1 (send temp0:name))
        )
        (send temp0:symbol(Memory(2 2)))
        return temp0
    )


    (method (yourself)
        return self
    )

)
(instance public barter of GameControls
    (properties)

    (method (init param1 param2)
        (var temp0, temp1, temp2, temp3, temp4)
        = local85 (send gGame:setCursor(999))
        = local19 0
        = window barterWin
        = local11 1
        = local9 1
        = local15 param1
        = theIconI 0
        = temp2 (send local15:goods)
        = temp1 (send temp2:size)
        (if (not temp1)
            = state (& state $ffdf)
        )
        = local23 0
        = temp0 0
        = temp4 0
        (while (< temp0 temp1)
            = temp3 (send temp2:at(temp0))
            (if ((send temp3:quantity))
                (self:add((send ((barterIcon:new())):
                        nsLeft(local1[temp4])
                        nsRight((+ local1[temp4] 119))
                        nsTop(local5[temp4])
                        nsBottom((+ local5[temp4] 16))
                        message(temp0)
                        cursor(temp3)
                        yourself()
                    )
))
                ++local23
                (if (== (send temp3:denomination) 1)
                    Message(0 47 0 0 10 1 (send temp3:symbol))
                )(else
                    Message(0 47 0 0 9 1 (send temp3:symbol))
                )
                ++temp4
            )
            ++temp0
        )
        (if (== local23 1)
            = local24 1
        )(else
            = local24 0
        )
        return 
            (if (size)
                (self:add(acceptIcon bargainIcon refuseIcon addToIcon subtractIcon quantityIcon dummyIcon))
                (super:init(rest param2))
                = local9 1
                (self:show())
            )(else
                = local86 1
                return 0
            )
    )


    (method (doit)
        (var temp0, temp1, temp2, temp3)
        (asm
code_080b:  pTos    state
            ldi     32
            and     
            bnt     code_08a9
            pushi   #new
            pushi   0
            pushi   #curEvent
            pushi   0
            lag     gUser
            send    4
            send    4
            sat     temp0
            bnt     code_08a9
            pushi   #type
            pushi   0
            lat     temp0
            send    4
            sat     temp1
            pushi   #message
            pushi   0
            lat     temp0
            send    4
            sat     temp2
            pushi   #modifiers
            pushi   0
            lat     temp0
            send    4
            sat     temp3
            lsg     global86
            pushi   0
            callk   GetTime, 0
            add     
            sag     gLastTicks
            lst     temp1
            ldi     256
            eq?     
            bnt     code_087a
            ldi     4
            sat     temp1
            lst     temp3
            ldi     3
            and     
            bnt     code_0860
            ldi     27
            jmp     code_0862
code_0860:  ldi     13
code_0862:  sat     temp2
            ldi     0
            sat     temp3
            pushi   #type
            pushi   1
            lst     temp1
            pushi   37
            pushi   1
            lst     temp2
            pushi   61
            pushi   1
            push    
            lat     temp0
            send    18
code_087a:  pushi   #localize
            pushi   0
            lat     temp0
            send    4
            pushi   1
            lst     temp0
            callk   MapKeyToDir, 2
            pTos    state
            ldi     32
            and     
            not     
            bnt     code_0890
code_0890:  pushi   #dispatchEvent
            pushi   1
            lst     temp0
            self    6
            bnt     code_089a
code_089a:  lag     gNewSet
            bnt     code_080b
            pushi   #eachElementDo
            pushi   1
            pushi   57
            send    6
            jmp     code_080b
code_08a9:  ret     
        )
    )


    (method (dispose)
        (send gGame:setCursor(local85))
        (super:dispose())
    )


    (method (show)
        (var temp0[5])
        (if (& local9 $0003)
            (send window:
                top(25)
                left(35)
                right(284)
                bottom(136)
            )
        )(else
            (send window:
                top(25)
                left(33)
                right(286)
                bottom(100)
            )
        )
        (if (local19)
            (send window:open())
            (self:eachElementDo(217))
        )(else
            (super:show())
        )
    )


    (method (hide)
        (if ((& local9 $0004) or (& local9 $0002))
            (if (window)
                (send window:dispose())
            )
        )(else
            (super:hide())
        )
    )


    (method (advance)
        (var temp0, temp1)
        (asm
            ldi     1
            sat     temp1
code_0738:  lst     temp1
            pToa    size
            le?     
            bnt     code_078e
            pushi   64
            pushi   1
            lst     temp1
            pushi   #indexOf
            pushi   1
            pTos    highlightedIcon
            self    6
            add     
            push    
            pToa    size
            mod     
            push    
            self    6
            sat     temp0
            pushi   1
            push    
            callk   IsObject, 2
            not     
            bnt     code_076b
            pushi   1
            pushi   #first
            pushi   0
            self    4
            push    
            callk   NodeValue, 2
            sat     temp0
code_076b:  lst     temp0
            lofsa   dummyIcon
            ne?     
            bnt     code_0781
            pushi   #signal
            pushi   0
            lat     temp0
            send    4
            push    
            ldi     4
            and     
            not     
            bnt     code_0781
code_0781:  lst     temp1
            ldi     1
            add     
            push    
            pToa    size
            mod     
            sat     temp1
            jmp     code_0738
code_078e:  pushi   218
            pushi   #view
            lst     temp0
            pTos    state
            ldi     32
            and     
            push    
            self    8
            ret     
        )
    )


    (method (retreat)
        (var temp0, temp1)
        (asm
            ldi     1
            sat     temp1
code_07a3:  lst     temp1
            pToa    size
            le?     
            bnt     code_07fa
            pushi   64
            pushi   1
            pushi   #indexOf
            pushi   1
            pTos    highlightedIcon
            self    6
            push    
            lat     temp1
            sub     
            push    
            pToa    size
            mod     
            push    
            self    6
            sat     temp0
            pushi   1
            push    
            callk   IsObject, 2
            not     
            bnt     code_07d7
            pushi   1
            pushi   #last
            pushi   0
            self    4
            push    
            callk   NodeValue, 2
            sat     temp0
code_07d7:  lst     temp0
            lofsa   dummyIcon
            ne?     
            bnt     code_07ed
            pushi   #signal
            pushi   0
            lat     temp0
            send    4
            push    
            ldi     4
            and     
            not     
            bnt     code_07ed
code_07ed:  lst     temp1
            ldi     1
            add     
            push    
            pToa    size
            mod     
            sat     temp1
            jmp     code_07a3
code_07fa:  pushi   218
            pushi   #view
            lst     temp0
            pTos    state
            ldi     32
            and     
            push    
            self    8
            ret     
        )
    )


    (method (dispatchEvent param1 param2)
        (var newEvent, temp1)
        (if (local21)
            (if (gNewEventHandler)
                (send gNewEventHandler:eachElementDo(57))
                = newEvent (Event:new())
                (if ((send newEvent:type) and gNewEventHandler)
                    (send gNewEventHandler:firstTrue(#handleEvent newEvent))
                )
                (send newEvent:dispose())
                (send gTheDoits:doit())
            )(else
                = gLastTicks GetTime()
                (if ((send local15:script))
                    (send ((send local15:script)):doit())
                )
                Animate((send gGQg3KDHandler:elements) 1)
                (if (global37)
                    (send gGQg3KDHandler:eachElementDo(246))
                )
            )
        )(else
            (if ((& local9 $0004) and (== (send param1:message) 27))
                (barter:hide())
                (send param1:dispose())
                = local18 1
                (send local15:cue())
            )(else
                (if (<> (send param1:message) 27)
                    (super:dispatchEvent(param1 rest param2))
                )
            )
        )
    )

)
(instance barterIcon of IconI
    (properties
        view 939
        loop 0
        cel 0
        cursor 0
        message 0
        signal $0101
    )

    (method (show)
        (var temp0)
        (if ((send cursor:quantity))
            (if (local24 and not modifiers)
                = local9 2
                = modifiers 1
                = theIconI self
                = local20 (send local15:canStillBargain())
                = local10 (send ((send theIconI:cursor)):price)
                = local12 local10
                (barter:advance())
            )
            (if (& local9 $0001)
                = signal (& signal $fffb)
                (self:highlight(0))
            )(else
                (if ((& local9 $0002) and modifiers)
                    (self:highlight(1))
                    = signal (| signal $0004)
                    localproc_135c()
                )(else
                    = signal (| signal $0004)
                    (self:highlight(1))
                )
            )
        )(else
            (barter:delete(self))
            --local23
            = temp0 0
            (while (< temp0 local23)
                (send ((barter:at(temp0))):
                    nsLeft(local1[temp0])
                    nsRight(+ local1[temp0] 119)
                    nsTop(local5[temp0])
                    nsBottom(+ local5[temp0] 16)
                )
                ++temp0
            )
            (self:dispose())
        )
    )


    (method (select)
        = local9 2
        = modifiers 1
        = theIconI self
        = local20 (send local15:canStillBargain())
        = local10 (send ((send theIconI:cursor)):price)
        = local12 local10
        localproc_1426()
        (barter:advance())
    )


    (method (highlight param1)
        (var temp0, temp1, temp2, temp3[10])
        (if (not & local9 $0004)
            (if (& local9 $0001)
                = temp1 0
                = temp2 0
                (if (param1)
                    = temp0 46
                )(else
                    = temp0 1
                )
            )(else
                (if (& local9 $0002)
                    (if (modifiers)
                        = temp1 1
                        = temp0 46
                        = temp2 0
                    )(else
                        = temp1 0
                        = temp0 1
                        = temp2 1
                    )
                )
            )
            DrawCel(view loop temp1 nsLeft nsTop 15)
            Message(0 47 12 0 6 1 @temp3)
            Display(Format(@local25 @temp3 (send cursor:name) (send cursor:price) (send cursor:symbol)) 100 + nsLeft 1 + nsTop 3 102 temp0 106 118 101 1 105 123 104 temp2)
        )
    )


    (method (onMe param1)
        (if ((& local9 $0001) and not local21)
            (super:onMe(rest param1))
        )
    )

)
(instance acceptIcon of IconI
    (properties
        view 939
        loop 1
        cel 0
        signal $0101
    )

    (method (show)
        (if ((& local9 $0001) or (& local9 $0004))
            = signal (| signal $0004)
        )(else
            (if (IsObject(theIconI))
                (if (not localproc_156d() and (& local9 $0002))
                    = signal (| signal $0004)
                )(else
                    = signal (& signal $fffb)
                )
            )
        )
        = nsLeft 3
        = nsTop 91
        = nsBottom (+ nsTop 16)
        = nsRight (+ nsLeft 77)
        (if (not 
        (if (& local9 $0004)
            & signal $0004
        )
)
            (self:highlight(0))
        )
    )


    (method (select param1)
        (var temp0)
        (if ((super:select(rest param1)))
            (send theIconI:modifiers(0))
            = local21 1
            (barter:hide())
            = local9 1
            (send local15:transact((send theIconI:message) local11))
        )
    )


    (method (highlight param1)
        (var temp0, temp1)
        (if (not local21)
            (if (param1)
                = temp0 46
            )(else
                = temp0 1
            )
            (if ((& local9 $0001) or (& signal $0004))
                = temp1 1
            )(else
                = temp1 0
            )
            DrawCel(view loop cel nsLeft nsTop 15)
            Message(0 47 4 0 0 1 @local55)
            Display(@local55 100 + nsLeft 1 + nsTop 3 102 temp0 106 80 101 1 105 123 104 temp1)
        )
    )


    (method (onMe param1)
        (if (((& local9 $0002) and not local21) and not (& signal $0004))
            (super:onMe(rest param1))
        )
    )

)
(instance bargainIcon of IconI
    (properties
        view 939
        loop 1
        cel 0
        signal $0101
    )

    (method (show)
        (if ((& local9 $0001) or not local20)
            = signal (| signal $0004)
        )(else
            = signal (& signal $fffb)
        )
        (if (& local9 $0004)
            = nsTop 55
            = nsLeft 88
        )(else
            = nsTop 91
            = nsLeft 86
        )
        = nsBottom (+ nsTop 16)
        = nsRight (+ nsLeft 77)
        (self:highlight(0))
    )


    (method (select param1)
        (if (not (super:select(rest param1)))
            0
        )(else
            (if (& local9 $0002)
                (send local15:timesBargained(0))
                = local9 4
                (barter:hide())
                (send local15:cue())
            )(else
                (if (& local9 $0004)
                    (barter:hide())
                    = local21 1
                    (send gOwner:useSkill(13 25))
                    (send local15:bargain((send theIconI:message) local10))
                )
            )
        )
    )


    (method (highlight param1)
        (var temp0, temp1)
        (if (not local21)
            (if (param1)
                = temp0 46
            )(else
                = temp0 1
            )
            (if (not local20 or (& local9 $0001))
                = temp1 1
            )(else
                = temp1 0
            )
            DrawCel(view loop cel nsLeft nsTop 15)
            (if (& local9 $0004)
                Message(0 47 5 0 0 1 @local55)
            )(else
                Message(0 47 5 0 0 2 @local55)
            )
            Display(@local55 100 + nsLeft 2 + nsTop 3 102 temp0 106 80 101 1 105 123 104 temp1)
        )
    )


    (method (onMe param1)
        (if ((((& local9 $0002) or (& local9 $0004)) and local20) and not local21)
            (super:onMe(rest param1))
        )
    )

)
(instance refuseIcon of IconI
    (properties
        view 939
        loop 1
        cel 0
        signal $0101
    )

    (method (show)
        (if (& local9 $0004)
            = nsLeft 172
            = nsTop 55
        )(else
            = nsLeft 169
            = nsTop 91
        )
        = nsBottom (+ nsTop 16)
        = nsRight (+ nsLeft 77)
        (self:highlight(0))
    )


    (method (select param1)
        (var temp0)
        (if (not (super:select(rest param1)))
            0
        )(else
            (if (& local9 $0001)
                (barter:state((& (barter:state) $ffdf)))
            )(else
                (if (& local9 $0002)
                    (if (local24)
                        (barter:state((& (barter:state) $ffdf)))
                    )(else
                        (send theIconI:modifiers(0))
                        = local9 1
                        = local11 1
                        localproc_135c()
                        localproc_1426()
                        (self:highlight(1))
                    )
                )(else
                    (if (& local9 $0004)
                        (barter:hide())
                        = local10 local12
                        (if (not (send local15:canStillBargain()))
                            = local20 0
                        )
                        = local18 1
                        (send local15:cue())
                    )
                )
            )
        )
    )


    (method (highlight param1)
        (var temp0, temp1[20])
        (if (param1)
            = temp0 46
        )(else
            = temp0 1
        )
        (if ((& local9 $0002) and (> local23 1))
            Message(0 47 6 0 4 1 @local55)
        )(else
            Message(0 47 6 0 0 1 @local55)
        )
        DrawCel(view loop cel nsLeft nsTop 15)
        Display(@local55 100 + nsLeft 1 + nsTop 3 102 temp0 106 80 101 1 105 123)
    )


    (method (onMe param1)
        (if (not local21)
            (super:onMe(rest param1))
        )
    )

)
(instance addToIcon of IconI
    (properties
        view 939
        loop 2
        cel 0
        signal $0101
    )

    (method (show)
        (if (& local9 $0001)
            = signal (| signal $0004)
        )(else
            = signal (& signal $fffb)
        )
        (if (& local9 $0004)
            = nsLeft 237
            = nsTop 23
        )(else
            = nsLeft 233
            = nsTop 59
        )
        = nsBottom (+ nsTop 11)
        = nsRight (+ nsLeft 12)
        (self:highlight(0))
    )


    (method (select param1)
        (if (not (super:select(rest param1)))
            (self:highlight(0))
        )(else
            (if (& local9 $0002)
                (if (< local11 (send ((send theIconI:cursor)):quantity))
                    ++local11
                    (if (localproc_156d())
                        localproc_155e()
                    )(else
                        --local11
                    )
                    (self:highlight(1))
                )
            )(else
                (if (& local9 $0004)
                    (if (< local10 (* 3 local12))
                        ++local10
                    )
                    (self:highlight(1))
                )
            )
        )
    )


    (method (highlight param1)
        (var temp0)
        (if ((& local9 $0002) or (& local9 $0004))
            (if (param1)
                (quantityIcon:highlight(1))
            )(else
                (quantityIcon:highlight(0))
            )
        )
        DrawCel(view loop cel nsLeft nsTop 15)
    )


    (method (onMe param1)
        (if (((& local9 $0002) or (& local9 $0004)) and not local21)
            (super:onMe(rest param1))
        )
    )

)
(instance subtractIcon of IconI
    (properties
        view 939
        loop 3
        cel 0
        signal $0101
    )

    (method (show)
        (if (& local9 $0001)
            = signal (| signal $0004)
        )(else
            = signal (& signal $fffb)
        )
        (if (& local9 $0004)
            = nsLeft 237
            = nsTop 37
        )(else
            = nsLeft 233
            = nsTop 73
        )
        = nsBottom (+ nsTop 11)
        = nsRight (+ nsLeft 12)
        (self:highlight(0))
    )


    (method (select param1)
        (if (not (super:select(rest param1)))
            (self:highlight(0))
        )(else
            (if (& local9 $0002)
                (if (> local11 1)
                    --local11
                    localproc_155e()
                )
                (self:highlight(1))
            )(else
                (if (& local9 $0004)
                    (if (> local10 1)
                        --local10
                    )
                    (self:highlight(1))
                )
            )
        )
    )


    (method (highlight param1)
        (var temp0)
        (if ((& local9 $0002) or (& local9 $0004))
            (if (param1)
                (quantityIcon:highlight(1))
            )(else
                (quantityIcon:highlight(0))
            )
        )
        DrawCel(view loop cel nsLeft nsTop 15)
    )


    (method (onMe param1)
        (if (((& local9 $0002) or (& local9 $0004)) and not local21)
            (super:onMe(rest param1))
        )
    )

)
(instance quantityIcon of IconI
    (properties
        view 939
        loop 4
        cel 0
        signal $0105
    )

    (method (show)
        (self:highlight(0))
    )


    (method (highlight param1)
        (var temp0, temp1, temp2, temp3[10])
        (if ((& local9 $0004) and not local18)
            = nsLeft 165
            = nsTop 21
        )(else
            = nsLeft 160
            = nsTop 57
        )
        = nsBottom (+ nsTop 28)
        = nsRight (+ nsLeft 70)
        (if (param1)
            = temp0 46
        )(else
            = temp0 1
        )
        (if (& local9 $0001)
            = temp1 1
        )(else
            = temp1 0
        )
        DrawCel(view loop cel nsLeft nsTop 15)
        (if (& local9 $0004)
            Message(0 47 7 0 5 1 @local55)
            = temp2 local10
        )(else
            Message(0 47 7 0 0 1 @local55)
            = temp2 local11
        )
        Display(@local55 100 + nsLeft 1 + nsTop 3 102 1 106 70 101 1 105 999 104 temp1)
        Message(0 47 12 0 7 1 @temp3)
        Display(Format(@local25 @temp3 temp2) 100 + nsLeft 1 + nsTop 3 102 temp0 106 70 101 1 105 999 104 temp1)
    )


    (method (onMe)
        return 0
    )

)
(instance dummyIcon of IconI
    (properties
        view 939
        loop 0
        cel 0
        nsTop 0
        nsRight 249
    )

    (method (show)
        = nsBottom (barterWin:bottom)
    )


    (method (select)
    )


    (method (highlight)
    )

)
(instance barterWin of GloryWindow
    (properties)

    (method (open param1)
        (var temp0[10])
        (super:open(rest param1))
        Graph(grFILL_BOX 0 0 - (- bottom top) 3 - (- right left) 3 1 back -1)
        Graph(grDRAW_LINE 16 0 16 + (- right left) 2 58 -1 -1)
        (if ((& local9 $0002) or (& local9 $0001))
            Graph(grDRAW_LINE 54 0 54 + (- right left) 2 58 -1 -1)
        )
        Graph(grUPDATE_BOX 0 0 - (- bottom top) 3 - (- right left) 2 1)
        Message(0 47 12 0 8 1 @temp0)
        Display(Format(@local25 @temp0 (send local15:header)) 100 0 1 102 1 106 249 101 1 105 123)
        (if (& local9 $0004)
            localproc_154f()
        )(else
            localproc_1426()
        )
    )

)
