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


(local
    newAct
    newAct_2
    newProp_2
    newProp_3
    newProp_4
    local5
    newProp
    newProp_5
    newProp_6
    newProp_7
    local10[2]

)
(instance public Room45 of Rm
    (properties
        picture 45
        style 16
    )

    (method (init)
        Load(rsVIEW 632)
        Load(rsVIEW 645)
        Load(rsVIEW 365)
        Load(rsVIEW 101)
        Load(rsVIEW 112)
        Load(rsVIEW 115)
        (super:init())
        (fairyMusic:play())
        (send gEgo:
            view(4)
            posn(225 175)
            init()
            setStep(4 1)
            setPri(-1)
        )
        (send ((View:new())):
            view(632)
            posn(115 101)
            setPri(0)
            addToPic()
        )
        (send ((View:new())):
            view(632)
            posn(201 101)
            setPri(0)
            addToPic()
        )
        (send (= newProp (Prop:new())):
            view(101)
            loop(0)
            cel(0)
            ignoreActors(1)
            posn(159 127)
            setPri(11)
            init()
        )
        (send (= newAct (Act:new())):
            view(112)
            posn(110 60)
            setStep(1 1)
            setLoop(0)
            setCycle(Fwd)
            setScript(Flutter3)
            init()
        )
        (send (= newAct_2 (Act:new())):
            view(115)
            posn(200 60)
            setStep(1 1)
            setLoop(1)
            setCycle(Fwd)
            setScript(Flutter6)
            init()
        )
        (send (= newProp_2 (Prop:new())):
            view(632)
            posn(115 44)
            setLoop(1)
            setCycle(Fwd)
            init()
        )
        (send (= newProp_3 (Prop:new())):
            view(632)
            posn(201 44)
            setLoop(1)
            setCycle(Fwd)
            init()
        )
        (send (= newProp_4 (Prop:new())):
            view(365)
            posn(59 131)
            ignoreActors(1)
            setScript(catMove)
            init()
        )
        (send gEgo:observeBlocks(catBlock))
    )


    (method (doit)
        (super:doit())
        (if ((send gCast:contains(gEgo)))
            (if (& (send gEgo:onControl(0)) $0040)
                (send global2:newRoom(46))
            )
            (if ((send gEgo:inRect(93 116 223 151)) and (<> (self:script()) closer))
                (if (< (send gEgo:x()) 158)
                    (if (<> (send newAct:script()) ChaseEgo)
                        (send newAct:setScript(ChaseEgo))
                    )
                )(else
                    (if (<> (send newAct_2:script()) ChaseEgo)
                        (send newAct_2:setScript(ChaseEgo))
                    )
                )
            )(else
                (if (<> (send newAct:script()) ChaseEgoWhenTalk)
                    (send newAct:setScript(Flutter3))
                )
                (if (<> (send newAct_2:script()) ChaseEgoWhenTalk)
                    (send newAct_2:setScript(Flutter6))
                )
            )
        )
    )


    (method (dispose)
        (send gSounds:eachElementDo(172))
        proc0_23()
        (super:dispose())
    )


    (method (handleEvent pEvent)
        return 
            (if ((send pEvent:claimed()))
                return 1
            )(else
                (if (== (send pEvent:type()) 128)
                    (if (Said('look>'))
                        (if (Said('[<on,in,at]/bed'))
                            Print(45 0)
                        )(else
                            (if (Said('<under/bed'))
                                Print(45 1)
                            )(else
                                (if (Said('/wand[<magic]'))
                                    Print(45 2)
                                )(else
                                    (if (Said('/window'))
                                        (if ((send gEgo:inRect(113 110 208 122)))
                                            Print(45 3)
                                        )(else
                                            Print(45 4)
                                        )
                                    )(else
                                        (if (Said('/blossom,flora'))
                                            Print(45 5)
                                        )(else
                                            (if (Said('/stair'))
                                                Print(45 6)
                                            )(else
                                                (if (Said('/chest,dresser,drawer>'))
                                                    (if (Said('<in,in'))
                                                        Print(45 7)
                                                    )(else
                                                        Print(45 8)
                                                        (send pEvent:claimed(1))
                                                    )
                                                )(else
                                                    (if (Said('/wall'))
                                                        Print(45 9)
                                                    )(else
                                                        (if (Said('[<down]/dirt'))
                                                            Print(45 10)
                                                        )(else
                                                            (if (Said('/genesta'))
                                                                Print(Format(@global300 45 11 
                                                                        (if (== global169 1)
                                                                            "This will be a loss for Tamir, as the evil Lolotte will come to power!"
                                                                        )(else
                                                                            " "
                                                                        )
))
                                                            )(else
                                                                (if (Said('/leopard[<snow,white]'))
                                                                    Print(45 12)
                                                                )(else
                                                                    (if (Said('[<around][/room,tower,bedroom,chamber[<bed]]'))
                                                                        Print(45 13)
                                                                    )(else
                                                                        (send pEvent:claimed(0))
                                                                    )
                                                                )
                                                            )
                                                        )
                                                    )
                                                )
                                            )
                                        )
                                    )
                                )
                            )
                        )
                    )(else
                        (if (Said('deliver/amulet[/genesta]'))
                            (if ((send gEgo:has(2)))
                                proc0_23()
                                proc0_10()
                                (send gEgo:put(2 999))
                                (fairyMusic:dispose())
                                Print(45 14 134 0 20 66 global23)
                                (self:setScript(closer))
                            )(else
                                Print(800 2)
                            )
                        )(else
                            (if (Said('(lay<down,on,in),(sleep<in,on),(get<in,on)[/bed]') or Said('sleep[/!*]'))
                                Print(45 15)
                            )(else
                                (if (Said('get/blossom'))
                                    Print(45 16)
                                )(else
                                    (if (Said('get,get,rob/wand'))
                                        Print(45 17)
                                    )(else
                                        (if (Said('open/dresser,drawer,chest'))
                                            Print(45 7)
                                        )(else
                                            (if (Said('converse/genesta') or Said('converse[/!*]'))
                                                Print(45 18)
                                                (if (< (send gEgo:x()) 158)
                                                    (if (== (send newAct:script()) Flutter3)
                                                        (send newAct:setScript(ChaseEgoWhenTalk))
                                                    )
                                                )(else
                                                    (if (== (send newAct_2:script()) Flutter6)
                                                        (send newAct_2:setScript(ChaseEgoWhenTalk))
                                                    )
                                                )
                                            )(else
                                                (if (Said('kill/genesta'))
                                                    Print(45 19)
                                                )(else
                                                    (if (Said('get/genesta'))
                                                        Print(45 20)
                                                    )(else
                                                        (if (Said('kiss/genesta') or Said('kiss[/!*]'))
                                                            Print(45 21)
                                                        )(else
                                                            (if (Said('help,,/genesta'))
                                                                Print(45 22)
                                                            )(else
                                                                (send pEvent:claimed(0))
                                                            )
                                                        )
                                                    )
                                                )
                                            )
                                        )
                                    )
                                )
                            )
                        )
                    )
                    (if (not (send pEvent:claimed()))
                        (if (Said('look[/fairies[<little]]'))
                            Print(45 23)
                        )(else
                            (if (Said('converse[/fairies]'))
                                Print(45 24)
                            )(else
                                (if (Said('kill[/fairies]'))
                                    Print(45 25)
                                )(else
                                    (if (Said('get/fairies'))
                                        Print(45 26)
                                    )(else
                                        (if (Said('capture/fairies'))
                                            Print(45 26)
                                        )(else
                                            (if (Said('kiss/fairies'))
                                                Print(45 27)
                                            )(else
                                                (if (Said('help/fairies'))
                                                    Print(45 28)
                                                )(else
                                                    (if (Said('converse/leopard[<snow,white]'))
                                                        Print(45 29)
                                                    )(else
                                                        (if (Said('kill/leopard[<snow,white]'))
                                                            Print(45 30)
                                                        )(else
                                                            (if (Said('get,capture/leopard[<snow,white]'))
                                                                Print(45 31)
                                                            )(else
                                                                (if (Said('kiss,pat/leopard[<snow,white]'))
                                                                    Print(45 32)
                                                                )(else
                                                                    (if (Said('deliver/leopard/*') or Said('deliver/*/leopard'))
                                                                        Print(45 33)
                                                                    )(else
                                                                        (if (Said('deliver/fairies/*') or Said('deliver/*/fairies'))
                                                                            Print(45 34)
                                                                        )(else
                                                                            (if (Said('deliver/genesta,fairies/*') or Said('deliver/*[/genesta,fairies]'))
                                                                                Print(45 35)
                                                                            )
                                                                        )
                                                                    )
                                                                )
                                                            )
                                                        )
                                                    )
                                                )
                                            )
                                        )
                                    )
                                )
                            )
                        )
                    )
                )
            )
    )

)
(instance ChaseEgo of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (Print(45 36 134 -1 20) (send client:
                    yStep(2)
                    illegalBits(0)
                    setMotion(Chase gEgo 30 self)
                )
  )
            )
            (case 1
                ((send client:
                    yStep(1)
                    setMotion(MoveTo (send gEgo:x()) - (send gEgo:y()) 55 self)
                )
 )
            )
        )
    )

)
(instance ChaseEgoWhenTalk of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                ((send client:
                    illegalBits(0)
                    yStep(2)
                    setMotion(MoveTo (send gEgo:x()) + (send client:y()) 25)
                )
 = seconds 4  )
            )
            (case 1
                ((send client:setScript(0)) )
            )
        )
    )

)
(instance Flutter3 of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                ((send client:
                    illegalBits(0)
                    setMotion(MoveTo 103 60 self)
                )
  )
            )
            (case 1
                ((send client:
                    illegalBits(8192)
                    setMotion(Wander 5)
                )
 )
            )
        )
    )

)
(instance Flutter6 of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                ((send client:
                    illegalBits(0)
                    setMotion(MoveTo 220 60 self)
                )
  )
            )
            (case 1
                ((send client:
                    illegalBits(8192)
                    setMotion(Wander 5)
                )
 )
            )
        )
    )

)
(instance catMove of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (= seconds 2  )
            )
            (case 1
                ((send newProp_4:setCycle(End self))  )
            )
            (case 2
                (
                (if (> Random(0 200) 180)
                    (send newProp_4:
                        cycleSpeed(1)
                        setLoop(1)
                        cel(0)
                        setCycle(End self)
                    )
                )(else
                    (self:cue())
                )
 )
            )
            (case 3
                ((send newProp_4:stopUpd()) = seconds 3  )
            )
            (case 4
                ((send newProp_4:setLoop(0)) = state -1 (self:cue()) )
            )
        )
    )

)
(instance closer of Script
    (properties)

    (method (init param1)
        Load(rsVIEW 101)
        Load(rsVIEW 103)
        Load(rsVIEW 104)
        (super:init(param1))
    )


    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (proc0_10() = global204 0 proc0_23() (send gGame:changeScore(10)) (send gCast:eachElementDo(256)) DrawPic(991) (send newProp:
                    view(103)
                    loop(0)
                    posn(160 160)
                    show()
                )
 (send (= newProp_5 (Prop:new())):
                    view(103)
                    loop(1)
                    posn((send newProp:x()) - (send newProp:y()) 30)
                    setPri(+ (send newProp:priority()) 1)
                    init()
                )
 (send (= newProp_6 (Prop:new())):
                    view(103)
                    loop(2)
                    posn((send newProp:x()) (send newProp:y()))
                    setPri(+ (send newProp:priority()) 1)
                    init()
                    setCycle(Fwd)
                )
 = seconds 4  )
            )
            (case 1
                ((send newProp_5:
                    cycleSpeed(2)
                    setCycle(End)
                )
 = seconds 4  )
            )
            (case 2
                ((send newProp_6:dispose()) (send newProp_5:dispose()) (send newProp:hide()) = cycles 1  )
            )
            (case 3
                (DrawPic(45 7) (send ((View:new())):
                    view(632)
                    posn(115 101)
                    setPri(0)
                    addToPic()
                )
 (send ((View:new())):
                    view(632)
                    posn(201 101)
                    setPri(0)
                    addToPic()
                )
 (send newProp:
                    view(101)
                    loop(1)
                    cel(0)
                    ignoreActors(1)
                    posn(159 127)
                    setPri(11)
                )
 (send gCast:eachElementDo(354)) (send newProp:setCycle(End)) = seconds 4  )
            )
            (case 4
                (Print(45 37 134 20 20) Print(45 38 134 100 160) (send newProp:
                    loop(2)
                    setCycle(End self)
                )
  )
            )
            (case 5
                (Print(45 39 134 -1 160) = local5 Print(45 40 134 -1 20 172) (send newProp:
                    loop(3)
                    setCycle(Fwd)
                )
 (send (= newProp_7 (Prop:new())):
                    view(686)
                    ignoreActors(1)
                    posn((send gEgo:x()) (send gEgo:y()))
                    setPri(+ (send gEgo:priority()) 1)
                    init()
                    cel(0)
                    setCycle(CT 5 1 self)
                )
  )
            )
            (case 6
                ((send gEgo:dispose()) (send newProp_7:
                    cel(5)
                    setCycle(End self)
                )
  )
            )
            (case 7
                ((send newProp_7:dispose()) proc0_23() (send newProp:
                    view(104)
                    loop(1)
                    setCycle(End self)
                )
  )
            )
            (case 8
                (= global205 1 (send global2:newRoom(690)) )
            )
        )
    )

)
(instance fairyMusic of Sound
    (properties
        number 34
    )
)
(instance catBlock of Blk
    (properties
        top 125
        left 31
        bottom 131
        right 80
    )
)
