(include "sci.sh")
(use "Main")
(use "Class_255_0")
(use "Sound")
(use "Cycle")
(use "Game")
(use "User")
(use "PV")
(use "Obj")
(script 654)


(local
    newProp
    local1[49]
    newView_2
    newView[7]
    local58
    newView_3
    local60
    local61[2]
    local63
    local64

)
(instance dwarfMusic of Sound
    (properties
        number 31
        loop -1
    )
)
(instance public Room654 of Rm
    (properties
        picture 54
        style 8
    )

    (method (init)
        = global101 1
        Load(rsVIEW 630)
        Load(rsVIEW 677)
        Load(rsVIEW 678)
        Load(rsVIEW 500)
        Load(rsVIEW 76)
        Load(rsVIEW 533)
        (super:init())
        (send ((View:new())):
            view(533)
            loop(1)
            cel(0)
            posn(295 107)
            setPri(9)
            addToPic()
        )
        = local63 0
        (send gEgo:
            posn(150 125)
            view(4)
            xStep(4)
            yStep(1)
            init()
            setCycle(Walk)
        )
        (send (= newView[0] (View:new())):
            view(677)
            posn(78 103)
            loop(3)
            cel(0)
            init()
            stopUpd()
        )
        = global176 0
        (send (= newProp (Prop:new())):
            view(630)
            posn(83 125)
            cycleSpeed(0)
            setCycle(Fwd)
            init()
        )
        Print(654 0 134 -1 20 50 5)
        (self:setScript(dwarfsInToEat))
    )


    (method (dispose)
        (dwarfMusic:dispose())
        (super:dispose())
    )


    (method (handleEvent pEvent)
        (super:handleEvent(pEvent))
        return 
            (if ((send pEvent:claimed()))
                return 1
            )(else
                (if (== (send pEvent:type()) 128)
                    (if (Said('look[<around][/!*]') or Said('look/room'))
                        Print(654 1)
                    )(else
                        (if (Said('look>'))
                            (if (Said('/window'))
                                Print(654 2)
                            )(else
                                (if (Said('/table'))
                                    (if (not global102)
                                        Print(654 3)
                                    )
                                    (if (global102 and global176)
                                        Print(654 4)
                                    )
                                )(else
                                    (if (Said('<under/table'))
                                        Print(654 5)
                                    )(else
                                        (if (Said('/stair'))
                                            Print(654 6)
                                        )(else
                                            (if (Said('/cabinet'))
                                                Print(654 7)
                                            )(else
                                                (if (Said('/wall'))
                                                    Print(654 8)
                                                )(else
                                                    (if (Said('/dirt') or Said('<down'))
                                                        Print(654 9)
                                                    )(else
                                                        (if (Said('/caldron'))
                                                            Print(654 10)
                                                        )(else
                                                            (if (Said('/fire,fireplace'))
                                                                Print(654 11)
                                                            )(else
                                                                (if (Said('/carpet'))
                                                                    Print(654 12)
                                                                )(else
                                                                    (if (Said('/clock'))
                                                                        Print(654 13)
                                                                    )(else
                                                                        (if (Said('/bowl'))
                                                                            Print(654 14)
                                                                        )
                                                                    )
                                                                )
                                                            )
                                                        )
                                                    )
                                                )
                                            )
                                        )
                                    )
                                )
                            )
                        )
                    )
                )
            )
    )

)
(instance dwarfsInToEat of Script
    (properties)

    (method (init param1)
        Load(rsVIEW 290)
        Load(rsVIEW 291)
        Load(rsVIEW 292)
        Load(rsVIEW 293)
        Load(rsVIEW 294)
        Load(rsVIEW 295)
        Load(rsVIEW 296)
        Load(rsVIEW 297)
        Load(rsVIEW 298)
        Load(rsVIEW 299)
        Load(rsVIEW 275)
        Load(rsVIEW 276)
        Load(rsVIEW 277)
        Load(rsVIEW 278)
        = local1[1] 296
        = local1[2] 278
        = local1[3] 0
        = local1[4] 218
        = local1[5] 138
        = local1[8] 295
        = local1[9] 277
        = local1[10] 1
        = local1[11] 295
        = local1[12] 159
        = local1[15] 294
        = local1[16] 276
        = local1[17] 1
        = local1[18] 262
        = local1[19] 159
        = local1[22] 293
        = local1[23] 275
        = local1[24] 0
        = local1[25] 194
        = local1[26] 138
        = local1[29] 292
        = local1[30] 299
        = local1[31] 1
        = local1[32] 228
        = local1[33] 160
        = local1[36] 291
        = local1[37] 298
        = local1[38] 1
        = local1[39] 190
        = local1[40] 159
        = local1[43] 290
        = local1[44] 297
        = local1[45] 0
        = local1[46] 240
        = local1[47] 137
        (super:init(param1))
    )


    (method (doit)
        (super:doit())
    )


    (method (changeState newState)
        (switch (= state newState)
            (case 0
                ((User:
                    canControl(0)
                    canInput(0)
                )
 = local58 0 = local60 Print(654 15 66 global23 134 200 20 140 110 172) (dwarfMusic:play()) (send gEgo:
                    loop(2)
                    setCycle(Walk)
                    setMotion(MoveTo 116 122 self)
                )
  )
            )
            (case 1
                ((send gEgo:
                    loop(2)
                    cel(0)
                    stopUpd()
                )
 = local1[local58] (send ((Act:new())):
                        view(local1[(+ local58 1)])
                        posn(155 185)
                        illegalBits(0)
                        setStep(4 1)
                        cycleSpeed(0)
                        init()
                        yourself()
                    )
 (send local1[local58]:
                    setCycle(Walk)
                    setMotion(MoveTo 135 140 self)
                )
  )
            )
            (case 2
                ((send local1[local58]:
                    setCycle(Walk)
                    setMotion(MoveTo 83 134 self)
                )
  )
            )
            (case 3
                ((send newView[0]:
                    cel(+ (send newView[0]:cel()) 1)
                    startUpd()
                )
 (send local1[local58]:
                    view(local1[+ local58 2])
                    loop(1)
                    setCycle(Fwd)
                )
 = seconds 5  )
            )
            (case 4
                ((send newView[0]:stopUpd()) 
                (if (== (send newView[0]:cel()) 7)
                    proc0_23()
                    = state 2
                    = local60 Print(654 16 66 global23 134 -1 20 172)
                    = seconds 1
                )(else
                    (send local1[local58]:
                        loop(2)
                        cel(0)
                        setCycle(End self)
                    )
                )
 )
            )
            (case 5
                ((send local1[local58]:
                    loop(0)
                    cel(0)
                    setCycle(Walk)
                    setMotion(MoveTo 135 130 self)
                )
  )
            )
            (case 6
                (
                (if (== local1[(+ local58 3)] 1)
                    (send local1[local58]:
                        setLoop(7)
                        setMotion(MoveTo 135 160 self)
                    )
                )(else
                    ++state
                    (send local1[local58]:setMotion(MoveTo local1[(+ local58 4)] local1[(+ local58 5)] self))
                )
 )
            )
            (case 7
                ((send local1[local58]:
                    setLoop(-1)
                    setMotion(MoveTo local1[+ local58 4] local1[+ local58 5] self)
                )
  )
            )
            (case 8
                (= local1[(+ local58 6)] (send ((View:new())):
                        view(local1[(+ local58 2)])
                        loop(6)
                        posn(local1[(+ local58 4)] (- local1[(+ local58 5)] 1))
                        init()
                        ignoreActors(1)
                        stopUpd()
                        yourself()
                    )
 (send local1[local58]:
                    loop(3)
                    cel(0)
                    setPri(
                        (if (== local1[(+ local58 3)] 1)
                            13
                        )(else
                            12
                        )
)
                    posn(local1[+ local58 4] 
                        (if (== local1[(+ local58 3)] 1)
                            - local1[(+ local58 5)] 12
                        )(else
                            - local1[(+ local58 5)] 6
                        )
)
                    setCycle(End self)
                )
  )
            )
            (case 9
                ((send local1[local58]:
                    loop(4)
                    cel(0)
                    ignoreActors(1)
                    stopUpd()
                )
 
                (if (< (= local58 (+ local58 7)) 48)
                    = state 0
                    (self:cue())
                )(else
                    (send newView[0]:dispose())
                )
 (send gEgo:startUpd()) 
                (if (> local58 48)
                    proc0_23()
                    = local60 Print(654 17 66 global23 134 7 15 140 290 166 172)
                )
 = seconds 15  )
            )
            (case 10
                ((send gEgo:
                    illegalBits(0)
                    ignoreActors(1)
                    setMotion(MoveTo 270 136 self)
                )
  )
            )
            (case 11
                ((User:canInput(1)) proc0_23() = local60 Print(654 18 66 global23 134 -1 20 172) (send gEgo:
                    view(76)
                    loop(5)
                )
 (dwarfMusic:dispose()) = global176 1 (send gEgo:setScript(eatOut)) = seconds 60  )
            )
            (case 12
                (= local63 1  )
            )
            (case 13
                (proc0_23() = local60 Print(654 19 66 global23 134 -1 20 172) = global176 2 (User:canInput(0)) = local58 0 (while (< local58 7)(send local1[* local58 7]:cel(0)) ++local58  ) (send gEgo:cel(0)) = local58 49 = seconds 5  )
            )
            (case 14
                ((dwarfMusic:play()) proc0_23() = local60 Print(654 20 66 global23 134 -1 20 172) (self:cue())  )
            )
            (case 15
                (= local58 (- local58 7) (send local1[local58]:
                    loop(5)
                    cel(0)
                    setCycle(End self)
                )
 (send (= newView_2 (View:new())):
                    view(500)
                    loop(1)
                    cel(2)
                    setPri(12)
                    ignoreActors(1)
                    posn((send local1[local58]:x()) 
                        (if (local1[+ local58 3])
                            136
                        )(else
                            133
                        )
)
                    addToPic()
                )
 
                (if (== local58 28)
                    (send (= newView_3 (View:new())):
                        view(500)
                        loop(0)
                        cel(0)
                        posn(+ (send newView_2:x()) 8 - (send newView_2:y()) 1)
                        ignoreActors(1)
                        setPri(12)
                        init()
                        stopUpd()
                    )
                    (send ((send gInv:at(1))):moveTo(54))
                )
 )
            )
            (case 16
                ((send local1[local58]:
                    view(local1[+ local58 1])
                    setPri(-1)
                    cel(0)
                    loop(1)
                    posn((send local1[+ local58 6]:x()) (send local1[+ local58 6]:y()))
                    cycleSpeed(0)
                    moveSpeed(0)
                    setCycle(Walk)
                    setMotion(MoveTo 140 (send local1[+ local58 6]:y()) self)
                )
 (send local1[+ local58 6]:dispose())  )
            )
            (case 17
                ((send local1[local58]:
                    setPri((send local1[local58]:priority()))
                    setMotion(MoveTo 150 207 self)
                )
  )
            )
            (case 18
                ((send local1[local58]:dispose()) 
                (if (local58)
                    = state 14
                )
 (self:cue())  )
            )
            (case 19
                ((dwarfMusic:
                    loop(1)
                    changeState()
                )
 proc0_23() Print(654 21 66 global23 134 -1 20) (send (= newView_2 (View:new())):
                    view(500)
                    loop(1)
                    cel(2)
                    posn((send gEgo:x()) 133)
                    setPri(12)
                    addToPic()
                )
 (send gEgo:
                    ignoreActors(0)
                    illegalBits(32768)
                    posn(270 136)
                    view(4)
                    loop(2)
                    setCycle(Walk)
                )
 (self:cue())  )
            )
            (case 20
                ((dwarfMusic:dispose()) (User:
                    canControl(1)
                    canInput(1)
                )
 = global205 0 (send global2:newRoom(54)) )
            )
        )
    )


    (method (handleEvent pEvent)
        (var gInvSaidMe)
        return 
            (if ((send pEvent:claimed()))
                return 1
            )(else
                (if (== (send pEvent:type()) 128)
                    (if (Said('look/dwarf'))
                        Print(654 22)
                    )(else
                        (if (Said('look/table'))
                            Print(654 23)
                        )(else
                            (if (Said('look/soup'))
                                Print(654 24)
                            )(else
                                (if (Said('converse[/dwarf]'))
                                    (tacodoco1:cue())
                                )(else
                                    (if (Said('get/soup') or Said('get/bowl'))
                                        (if (== global176 0)
                                            Print(654 25)
                                        )(else
                                            (if (== global176 1)
                                                Print(654 26)
                                            )(else
                                                Print(654 27)
                                            )
                                        )
                                    )(else
                                        (if (Said('kill/dwarf'))
                                            Print(654 28)
                                        )(else
                                            (if (Said('get/dwarf'))
                                                Print(654 29)
                                            )(else
                                                (if (Said('kiss[/!*]') or Said('kiss/dwarf'))
                                                    Print(654 30)
                                                )(else
                                                    (if (Said('deliver>'))
                                                        (if ((= gInvSaidMe (send gInv:saidMe())) and (send gEgo:has((send gInv:indexOf((= gInvSaidMe (send gInv:saidMe())))))))
                                                            Print(654 31)
                                                        )(else
                                                            (send pEvent:claimed(0))
                                                        )
                                                    )(else
                                                        (if (Said('chew/soup') or Said('chew'))
                                                            (switch (global176)
                                                                (case 0
                                                                    Print(654 32)
                                                                    = global176 1
                                                                )
                                                                (case 1
                                                                    Print(654 33)
                                                                )
                                                                (case 2
                                                                    Print(654 27)
                                                                )
                                                            )
                                                        )(else
                                                            (if (Said('(stand<up),(get<up),(/table,chair'))
                                                                Print(654 34)
                                                            )
                                                        )
                                                    )
                                                )
                                            )
                                        )
                                    )
                                )
                            )
                        )
                    )
                )
            )
    )

)
(instance tacodoco1 of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (Print(654 35)  )
            )
            (case 1
                (Print(654 36) Print(654 37)  )
            )
            (case 2
                (Print(654 38)  )
            )
            (case 3
                (Print(654 39) = state 2 )
            )
        )
    )

)
(instance eatOut of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                ((send gEgo:
                    posn((send gEgo:x()) - (send gEgo:y()) 8)
                    setLoop(0)
                    setCycle(End)
                )
 = seconds 7  )
            )
            (case 1
                (proc0_23() (send gEgo:
                    setLoop(1)
                    stopUpd()
                )
 = local58 (* Random(0 6) 7) 
                (if (< Random(1 10) 3)
                    (send gEgo:setCycle(End))
                )
 (send local1[local58]:setCycle(End self))  )
            )
            (case 2
                (
                (if (> (send gEgo:cel()) 0)
                    (send gEgo:setCycle(CT 0 1))
                )
 (send local1[local58]:setCycle(CT 0 1 self))  )
            )
            (case 3
                ((send local1[local58]:stopUpd()) 
                (if (not local63)
                    = state 0
                    (self:cue())
                )(else
                    (dwarfsInToEat:cue())
                )
 )
            )
        )
    )

)
