(version 2)
(include "sci.sh")
(exports
    0 rm470
)
(use "Main")
(use "Class_255_0")
(use "Cycle")
(use "Game")
(use "User")
(use "Feature")
(use "Obj")
(script 470)


(local
    local0
    local1
    local2
    eyesCel

)
(procedure (localproc_16e2)
    = global193 1
    (rHand:setCycle(0))
    = local2 1
    (balloon:setCel(1))
    (ArmUp:changeState(0))
    (mouth:setCycle(Fwd))
)


(procedure (localproc_1714 param1 param2 param3 param4 param5)
    (lHand:hide())
    (lArm:setCel(0))
    proc0_10()
    = local2 1
    (head:cel(1))
    (eyes:
        posn(150 58)
        setCel(2)
    )
    (lArm:
        view(81)
        setLoop(0)
        setCel(0)
    )
    (lHand:
        view(81)
        setLoop(param1)
        setCel(param2)
        posn(param3 param4)
        setCycle(param5)
        show()
    )
)


(procedure (localproc_1788)
    (if (local0)
        (balloon:setCel(3))
        proc0_12()
        = local0 0
    )
    (head:cel(0))
    (eyes:
        posn(140 55)
        setLoop(1)
        setCel(0)
    )
    (lHand:
        view(80)
        setLoop(6)
        setCel(0)
        posn(166 80)
        hide()
    )
    (lArm:
        view(80)
        setLoop(5)
        setCel(0)
    )
    (rHand:
        show()
        setCycle(Fwd)
    )
    (mouth:
        setCel(6)
        setCycle(0)
    )
    = local2 0
    = global193 0
)


(procedure (localproc_1821 param1)
    return 
        (switch (proc255_0(Format(@global402 470 46 param1) 82 81 0 2 30 1 80 "Haggle Interface" 81 " Yes " 1 81 " No " 2))
            (case 1
                return 1
            )
            (case 2
                return 0
            )
        )
)


(instance public rm470 of Rm
    (properties
        picture 470
        style 7
    )

    (method (init)
        (User:
            canInput(1)
            canControl(1)
        )
        Load(128 80)
        Load(128 81)
        Load(132 13)
        (super:init())
        (send global10:add(bones robots))
        (send global10:doit())
        (head:
            init()
            stopUpd()
        )
        (eyes:
            init()
            setScript(EyeBlink)
        )
        (rArm:
            init()
            stopUpd()
            setScript(ArmUp)
        )
        (rHand:
            init()
            setCycle(Fwd)
            setScript(MoveEye)
        )
        (lArm:
            init()
            stopUpd()
        )
        (lHand:
            init()
            stopUpd()
            hide()
            setScript(EarWax)
        )
        (mouth:init())
        (balloon:
            init()
            setCel(3)
        )
        (if ((== (send gLongSong:state) 0) or (== (send gLongSong:number) 22))
            (send gLongSong:
                number(13)
                priority(3)
                loop(-1)
                play()
            )
        )
        = local0 0
        (self:setScript(Howdy))
    )


    (method (doit)
        (var temp0[30])
        (super:doit())
        (if ((== (balloon:cel) 1) and not gTheNewDialog)
            localproc_1788()
        )
    )


    (method (dispose)
        (if (local0)
            proc0_12()
        )
        (super:dispose())
    )


    (method (handleEvent pEvent)
        (var temp0, temp1[50])
        (if ((send pEvent:claimed))
            return 
        )
        (switch ((send pEvent:type))
            (case 4
                (if ((== (send pEvent:message) 13) and local0)
                    localproc_1788()
                    (send script:cue())
                )
            )
            (case 128
                (if (Said('look[/area,store]'))
                    proc255_0(470 0)
                )(else
                    (if (Said('look/counter,box,display,cabinet'))
                        proc255_0(470 1)
                        = local1 1
                    )(else
                        (if (Said('look/head,face,man,blatz,alien,animal,owner'))
                            proc255_0(470 2)
                        )(else
                            (if (Said('look/mouth'))
                                proc255_0(470 3)
                            )(else
                                (if (Said('look/eye'))
                                    proc255_0(470 4)
                                )(else
                                    (if (Said('look/finger'))
                                        proc255_0(470 5)
                                    )(else
                                        (if (Said('look/mog,head'))
                                            proc255_0(470 6)
                                        )(else
                                            (if (Said('look/rock,crystal'))
                                                (if ((send gEgo:has(0)))
                                                    proc255_0(470 7)
                                                )(else
                                                    proc255_0(470 8)
                                                )
                                            )(else
                                                (if (Said('look/deck,ceiling') or Said('look<up,down'))
                                                    proc255_0(470 9)
                                                )(else
                                                    (if (Said('look/pane'))
                                                        proc255_0(470 10)
                                                    )(else
                                                        (if (Said('look/partition'))
                                                            proc255_0(470 11)
                                                        )(else
                                                            (if (Said('look/glass'))
                                                                proc255_0(470 12)
                                                            )(else
                                                                (if (Said('look/rack'))
                                                                    proc255_0(470 13)
                                                                )(else
                                                                    (if (Said('look/shirt'))
                                                                        proc255_0(470 14)
                                                                    )(else
                                                                        (if (Said('look/shelf,skull,bone,pilot,android,debris,domino'))
                                                                            proc255_0(470 15)
                                                                        )(else
                                                                            (if (Said('look,read/postcard,card'))
                                                                                (if (== global600 6)
                                                                                    = global600 1
                                                                                )(else
                                                                                    ++global600
                                                                                )
                                                                                (send (ScriptID(471 0)):doit())
                                                                            )(else
                                                                                (if ((Said('disembark[/area,blatz,store,shop]') or Said('/bye')) or Said('go<out'))
                                                                                    (send global2:setScript(ByeScript))
                                                                                )(else
                                                                                    (if (Said('ask,converse>'))
                                                                                        (if (Said('/dog,(scumsoft<soft)') or Said('/blatz/dog,(scumsoft<soft)'))
                                                                                            (send global2:setScript(ScumScript))
                                                                                        )(else
                                                                                            (if (Said('/pestulon') or Said('/blatz/pestulon'))
                                                                                                (send global2:setScript(PestScript))
                                                                                            )(else
                                                                                                (send pEvent:claimed(1))
                                                                                                proc255_0(470 16)
                                                                                            )
                                                                                        )
                                                                                    )(else
                                                                                        (if (Said('break,beat'))
                                                                                            proc255_0(470 17)
                                                                                        )(else
                                                                                            (if (Said('rob,attack'))
                                                                                                proc255_0(470 18)
                                                                                            )(else
                                                                                                (if (Said('kiss'))
                                                                                                    proc255_0(470 19)
                                                                                                )(else
                                                                                                    (if (Said('wear,(drop<on)/cap'))
                                                                                                        (if ((send gEgo:has(6)))
                                                                                                            = global130 1
                                                                                                            proc255_0(470 20)
                                                                                                        )(else
                                                                                                            proc0_9()
                                                                                                        )
                                                                                                    )(else
                                                                                                        (if (Said('remove,(get<off)/cap'))
                                                                                                            (if (not (send gEgo:has(6)))
                                                                                                                proc0_9()
                                                                                                            )(else
                                                                                                                (if (global130)
                                                                                                                    = global130 0
                                                                                                                    proc255_0(470 21)
                                                                                                                )(else
                                                                                                                    proc255_0(470 22)
                                                                                                                )
                                                                                                            )
                                                                                                        )(else
                                                                                                            (if (Said('get/skull,bone,android,pilot,mog,debris,head'))
                                                                                                                proc255_0(470 23)
                                                                                                            )(else
                                                                                                                (if (Said('get>'))
                                                                                                                    = temp0 (send global9:firstTrue(248))
                                                                                                                    (if (temp0)
                                                                                                                        (if ((send (= temp0 (send global9:firstTrue(248))):ownedBy(470)))
                                                                                                                            proc255_0(470 23)
                                                                                                                        )(else
                                                                                                                            (if ((send temp0:ownedBy(gEgo)))
                                                                                                                                proc255_0(470 24)
                                                                                                                            )(else
                                                                                                                                proc255_0(470 25)
                                                                                                                            )
                                                                                                                        )
                                                                                                                    )
                                                                                                                )(else
                                                                                                                    (if (Said('buy/skull,bone,android,pilot,mog,debris,head'))
                                                                                                                        proc255_0(470 26)
                                                                                                                    )(else
                                                                                                                        (if (Said('buy/crystal,rock'))
                                                                                                                            (if ((send gEgo:has(0)))
                                                                                                                                proc255_0(470 27)
                                                                                                                            )(else
                                                                                                                                proc255_0(470 28)
                                                                                                                            )
                                                                                                                        )(else
                                                                                                                            (if (Said('buy/postcard'))
                                                                                                                                proc255_0(470 29)
                                                                                                                            )(else
                                                                                                                                (if (Said('buy>'))
                                                                                                                                    = temp0 (send global9:firstTrue(248))
                                                                                                                                    (if (temp0)
                                                                                                                                        (if ((send (= temp0 (send global9:firstTrue(248))):ownedBy(470)))
                                                                                                                                            (if (>= global154 25)
                                                                                                                                                proc255_0(470 30)
                                                                                                                                                (send temp0:moveTo(gEgo))
                                                                                                                                                (send global1:changeScore(5))
                                                                                                                                                = global154 (- global154 25)
                                                                                                                                            )(else
                                                                                                                                                proc255_0(470 31)
                                                                                                                                            )
                                                                                                                                        )(else
                                                                                                                                            (if ((send temp0:ownedBy(gEgo)))
                                                                                                                                                proc255_0(470 24)
                                                                                                                                            )(else
                                                                                                                                                proc255_0(470 25)
                                                                                                                                            )
                                                                                                                                        )
                                                                                                                                    )
                                                                                                                                )(else
                                                                                                                                    (if (Said('give,drop,sell,display,trade/crystal,crystal[<glowing]'))
                                                                                                                                        (if ((send gEgo:has(0)))
                                                                                                                                            (if (not global103)
                                                                                                                                                (send global2:setScript(Orium))
                                                                                                                                            )(else
                                                                                                                                                (send global2:setScript(Orium2))
                                                                                                                                            )
                                                                                                                                        )(else
                                                                                                                                            proc255_0(470 32)
                                                                                                                                        )
                                                                                                                                    )
                                                                                                                                )
                                                                                                                            )
                                                                                                                        )
                                                                                                                    )
                                                                                                                )
                                                                                                            )
                                                                                                        )
                                                                                                    )
                                                                                                )
                                                                                            )
                                                                                        )
                                                                                    )
                                                                                )
                                                                            )
                                                                        )
                                                                    )
                                                                )
                                                            )
                                                        )
                                                    )
                                                )
                                            )
                                        )
                                    )
                                )
                            )
                        )
                    )
                )
            )
        )
    )


    (method (newRoom newRoomNumber)
        = global193 0
        (super:newRoom(newRoomNumber))
    )

)
(instance Howdy of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                = seconds 2
            )
            (case 1
                localproc_16e2()
                = local0 proc255_0(470 33 67 -1 1 70 280 33 600 91)
                = seconds 15
            )
            (case 2
                localproc_1788()
                = seconds 8
            )
            (case 3
                (send client:setScript(SalesPitch))
            )
        )
    )

)
(instance PestScript of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                localproc_1788()
                proc0_10()
                localproc_16e2()
                = local0 proc255_0(470 34 67 -1 1 70 280 33 600 91)
                = local2 0
                (EarWax:changeState(2))
                = seconds 15
            )
            (case 1
                localproc_1788()
                (send global2:setScript(SalesPitch))
            )
        )
    )

)
(instance ScumScript of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                localproc_1788()
                proc0_10()
                localproc_16e2()
                = local0 proc255_0(470 35 67 -1 1 70 280 33 600 91)
                = local2 0
                (EarWax:changeState(2))
                = seconds 15
            )
            (case 1
                localproc_1788()
                (send global2:setScript(SalesPitch))
            )
        )
    )

)
(instance ByeScript of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                localproc_1788()
                proc0_10()
                localproc_16e2()
                = local0 proc255_0(470 36 67 -1 1 70 280 33 600 91)
                = seconds 10
            )
            (case 1
                localproc_1788()
                proc0_10()
                (send gLongSong:fade())
                (send global2:newRoom(43))
            )
        )
    )

)
(instance SalesPitch of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                = seconds 2
            )
            (case 1
                (if ((send ((send global9:at(4))):ownedBy(470)))
                    localproc_16e2()
                    localproc_1714(1 0 210 93 Fwd)
                    = local0 proc255_0(470 37 67 -1 1 70 280 33 600 91)
                    = seconds 15
                )(else
                    = cycles 2
                )
            )
            (case 2
                (if (local0)
                    localproc_1788()
                    = seconds 7
                )(else
                    = cycles 2
                )
            )
            (case 3
                (if ((send ((send global9:at(6))):ownedBy(470)))
                    localproc_16e2()
                    localproc_1714(2 1 217 95 0)
                    = local0 proc255_0(470 38 67 -1 1 70 280 33 600 91)
                    = seconds 15
                )(else
                    = cycles 2
                )
            )
            (case 4
                (if (local0)
                    localproc_1788()
                    = seconds 7
                )(else
                    = cycles 2
                )
            )
            (case 5
                (if ((send ((send global9:at(5))):ownedBy(470)))
                    localproc_16e2()
                    localproc_1714(2 0 215 94 0)
                    = local0 proc255_0(470 39 67 -1 1 70 280 33 600 91)
                    = seconds 15
                )(else
                    = cycles 2
                )
            )
            (case 6
                (if (local0)
                    localproc_1788()
                    = seconds 7
                )(else
                    = cycles 2
                )
            )
            (case 7
                localproc_16e2()
                = local0 proc255_0(470 40 67 -1 1 70 280 33 600 91)
                = seconds 10
            )
            (case 8
                localproc_1788()
                = seconds 10
            )
            (case 9
                (if (== local1 1)
                    localproc_16e2()
                    = local0 proc255_0(470 41 67 -1 1 70 280 33 600 91)
                    = seconds 15
                )(else
                    = cycles 2
                )
            )
            (case 10
                (if (== local1 1)
                    localproc_1788()
                    = seconds 7
                )(else
                    = cycles 2
                )
            )
            (case 11
                (self:init())
            )
        )
    )

)
(instance Orium of Script
    (properties)

    (method (changeState newState)
        (var temp0[50])
        (switch (= state newState)
            (case 0
                proc0_2()
                localproc_1788()
                = local2 1
                = cycles 2
            )
            (case 1
                (rock:init())
                (head:setCel(0))
                (eyes:
                    setCel(3)
                    posn(140 55)
                )
                (mouth:setCel(7))
                (rArm:setCel(2))
                (rHand:hide())
                (lArm:setCel(2))
                = seconds 4
            )
            (case 2
                (rArm:setCel(0))
                localproc_1788()
                localproc_16e2()
                = local0 proc255_0(470 42 67 -1 1 70 280 33 600 91)
                = seconds 8
            )
            (case 3
                = global103 1
                localproc_1788()
                (switch (localproc_1821(350))
                    (case 0
                        = cycles 2
                    )
                    (case 1
                        (send gEgo:
                            get(8)
                            put(0)
                        )
                        = global154 (+ global154 350)
                        (rock:dispose())
                        (send global1:changeScore(2))
                        proc0_3()
                        (send client:setScript(SalesPitch))
                    )
                )
            )
            (case 4
                (switch (localproc_1821(400))
                    (case 0
                        = cycles 2
                    )
                    (case 1
                        (send gEgo:
                            get(8)
                            put(0)
                        )
                        = global154 (+ global154 400)
                        (rock:dispose())
                        (send global1:changeScore(4))
                        proc0_3()
                        (send client:setScript(SalesPitch))
                    )
                )
            )
            (case 5
                (switch (localproc_1821(425))
                    (case 0
                        = cycles 2
                    )
                    (case 1
                        (send gEgo:
                            get(8)
                            put(0)
                        )
                        = global154 (+ global154 425)
                        (rock:dispose())
                        (send global1:changeScore(8))
                        proc0_3()
                        (send client:setScript(SalesPitch))
                    )
                )
            )
            (case 6
                localproc_16e2()
                = local0 proc255_0(470 43 67 -1 1 70 280 33 600 91)
                = seconds 8
            )
            (case 7
                localproc_1788()
                (rock:dispose())
                proc0_3()
                = local2 0
                (send client:setScript(SalesPitch))
            )
        )
    )

)
(instance Orium2 of Script
    (properties)

    (method (changeState newState)
        (var temp0[50])
        (switch (= state newState)
            (case 0
                proc0_2()
                localproc_1788()
                = local2 1
                = cycles 2
            )
            (case 1
                (rock:init())
                (head:setCel(0))
                (eyes:
                    setCel(0)
                    posn(140 55)
                )
                localproc_16e2()
                = local0 proc255_0(470 44 67 -1 1 70 280 33 600 91)
                = seconds 8
            )
            (case 2
                localproc_1788()
                (switch (localproc_1821(100))
                    (case 0
                        = cycles 2
                    )
                    (case 1
                        (send gEgo:
                            get(8)
                            put(0)
                        )
                        = global154 (+ global154 100)
                        (rock:dispose())
                        (send global1:changeScore(1))
                        proc0_3()
                        (send client:setScript(SalesPitch))
                    )
                )
            )
            (case 3
                localproc_16e2()
                = local0 proc255_0(470 45 67 -1 1 70 280 33 600 91)
                = seconds 8
            )
            (case 4
                localproc_1788()
                (rock:dispose())
                proc0_3()
                = local2 0
                (send client:setScript(SalesPitch))
            )
        )
    )

)
(instance EyeBlink of Script
    (properties)

    (method (changeState newState)
        (var temp0[50])
        (switch (= state newState)
            (case 0
                = seconds Random(4 7)
            )
            (case 1
                = eyesCel (eyes:cel)
                (if (<> eyesCel 3)
                    (eyes:
                        loop(8)
                        cel(255)
                        setCycle(End self)
                    )
                )(else
                    = cycles 2
                )
            )
            (case 2
                (eyes:
                    loop(1)
                    cel(eyesCel)
                )
                (self:init())
            )
        )
    )

)
(instance MoveEye of Script
    (properties)

    (method (changeState newState)
        (var temp0[50])
        (switch (= state newState)
            (case 0
                = seconds Random(3 5)
            )
            (case 1
                (if (local0 or (== (eyes:cel) 3))
                    (self:init())
                )(else
                    (if (== (eyes:cel) 0)
                        (eyes:cel(1))
                    )(else
                        (eyes:cel(0))
                    )
                )
                (self:init())
            )
        )
    )

)
(instance EarWax of Script
    (properties)

    (method (changeState newState)
        (var temp0[50])
        (switch (= state newState)
            (case 0
                = seconds Random(10 25)
            )
            (case 1
                (if (local2)
                    (self:init())
                )(else
                    = cycles 2
                )
            )
            (case 2
                (lArm:setCel(1))
                (lHand:
                    show()
                    cycleSpeed(3)
                    setCycle(End self)
                )
            )
            (case 3
                (lHand:setCycle(Beg self))
            )
            (case 4
                (lHand:hide())
                (lArm:setCel(0))
                = cycles 1
            )
            (case 5
                (self:init())
            )
        )
    )

)
(instance ArmUp of Script
    (properties)

    (method (changeState newState)
        (var temp0[50])
        (switch (= state newState)
            (case 0
                (if (local0)
                    = seconds Random(4 12)
                )
            )
            (case 1
                (if (local0)
                    (rHand:hide())
                    (rArm:setCel(1))
                    = seconds 2
                )
            )
            (case 2
                (rArm:setCel(0))
                (rHand:show())
                (self:init())
            )
        )
    )

)
(instance head of Prop
    (properties)

    (method (init)
        (super:init())
        (self:
            view(80)
            setLoop(0)
            setCel(0)
            setPri(13)
            posn(141 121)
        )
    )

)
(instance eyes of Prop
    (properties)

    (method (init)
        (super:init())
        (self:
            view(80)
            setLoop(1)
            setCel(0)
            setPri(14)
            posn(140 55)
        )
    )

)
(instance mouth of Prop
    (properties)

    (method (init)
        (super:init())
        (self:
            view(80)
            setLoop(2)
            setCel(6)
            setPri(14)
            cycleSpeed(0)
            posn(142 101)
        )
    )

)
(instance rArm of Prop
    (properties)

    (method (init)
        (super:init())
        (self:
            view(80)
            setLoop(3)
            setCel(0)
            setPri(14)
            posn(98 151)
        )
    )

)
(instance rHand of Prop
    (properties)

    (method (init)
        (super:init())
        (self:
            view(80)
            setLoop(4)
            setCel(0)
            setPri(14)
            posn(172 150)
        )
    )

)
(instance lArm of Prop
    (properties)

    (method (init)
        (super:init())
        (self:
            view(80)
            setLoop(5)
            setCel(0)
            setPri(14)
            posn(166 100)
        )
    )

)
(instance lHand of Prop
    (properties)

    (method (init)
        (super:init())
        (self:
            view(80)
            setLoop(6)
            setCel(0)
            setPri(14)
            posn(166 80)
        )
    )

)
(instance balloon of Prop
    (properties)

    (method (init)
        (super:init())
        (self:
            view(81)
            setLoop(0)
            setCel(1)
            setPri(15)
            posn(100 53)
        )
    )

)
(instance rock of Prop
    (properties)

    (method (init)
        (super:init())
        (self:
            view(80)
            setLoop(7)
            setCel(0)
            setPri(15)
            posn(155 155)
        )
    )

)
(instance bones of PV
    (properties
        y 70
        x 201
        view 74
        priority 3
        signal 16384
    )
)
(instance robots of PV
    (properties
        y 115
        x 208
        view 74
        cel 1
        priority 3
        signal 16384
    )
)
