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


(local
    newProp_2
    newAct_2
    newProp_4
    newProp_5
    local4
    newProp_3
    local6
    newAct
    local8
    local9
    newProp

)
(instance public Room57 of Rm
    (properties
        picture 57
        style 16
    )

    (method (init)
        Load(rsVIEW 631)
        Load(rsVIEW 183)
        Load(rsVIEW 184)
        Load(rsVIEW 185)
        Load(rsVIEW 186)
        Load(rsVIEW 180)
        Load(rsVIEW 64)
        Load(rsVIEW 40)
        Load(rsVIEW 65)
        Load(rsVIEW 66)
        (super:init())
        = global101 1
        = global189 1
        (self:setScript(rm57Script))
        (send gEgo:
            posn(160 185)
            view(4)
            setStep(4 1)
            setPri(-1)
            loop(3)
            init()
        )
        (if (global207)
            (send (= newAct (Act:new())):
                view(631)
                loop(3)
                cel(0)
                illegalBits(0)
                ignoreActors(1)
                posn(gNewActX gNewActY)
                setScript(scarabToss)
                init()
            )
        )
        (send (= newProp (Prop:new())):
            view(631)
            loop(1)
            cel(0)
            posn(111 63)
            init()
            cycleSpeed(2)
            setCycle(Fwd)
        )
        (send (= newProp_2 (Prop:new())):
            view(631)
            posn(159 139)
            setPri(12)
            setCycle(Fwd)
            init()
        )
        (send newProp_2:
            brTop(+ (send newProp_2:brTop()) 14)
            brBottom(+ (send newProp_2:brBottom()) 19)
        )
        (if (> global109 2)
            (witchMusic:
                loop(1)
                play()
            )
            (send (= newProp_3 (Prop:new())):
                view(631)
                setLoop(2)
                cycleSpeed(2)
                setCycle(Fwd)
                setPri(12)
                init()
                stopUpd()
                hide()
            )
            (send (= newProp_4 (Prop:new())):
                view(186)
                loop(0)
                cel(5)
                posn(108 122)
                setLoop(1)
                init()
                stopUpd()
            )
            (send (= newProp_5 (Prop:new())):
                view(184)
                loop(0)
                cel(5)
                posn(135 121)
                init()
                stopUpd()
            )
            (blockWitch2:
                top((send newProp_4:brTop()))
                bottom((send newProp_4:brBottom()))
                left((send newProp_4:brLeft()))
                right((send newProp_4:brBottom()))
                init()
            )
            (blockWitch3:
                top((send newProp_5:brTop()))
                bottom((send newProp_5:brBottom()))
                left((send newProp_5:brLeft()))
                right((send newProp_5:brBottom()))
                init()
            )
            (send gEgo:observeBlocks(blockWitch2 blockWitch3))
            (send (= newAct_2 (Act:new())):
                view(185)
                posn(83 127)
                illegalBits(32768)
                setLoop(0)
                init()
            )
            (if ((send gEgo:has(6)))
                = local6 1
                (if (not (send gEgo:has(7)) and not global207)
                    Load(rsSCRIPT 991)
                    (send (= newAct (Act:new())):
                        view(631)
                        loop(3)
                        cel(0)
                        illegalBits(0)
                        ignoreActors(1)
                        posn((send newAct_2:x()) - (send newAct_2:y()) 30)
                        setScript(scarabToss)
                        init()
                    )
                    (rm57Script:changeState(1))
                )(else
                    (rm57Script:changeState(3))
                )
                (send newProp_5:setScript(witchMoan))
            )(else
                = local6 0
                (send newProp_4:setScript(witchEye))
            )
        )
    )


    (method (doit)
        (if (& (send gEgo:onControl(0)) $0040)
            (send gEgo:loop(2))
            Animate((send gCast:elements()) 0)
            (send global2:newRoom(6))
        )(else
            (if (((& (send gEgo:onControl()) $0004) and not local8) and not local9)
                Print(57 0 50 3)
                (ouchness:cue())
            )(else
                (if (> global109 2)
                    (if ((send gEgo:has(6)) and (<> (send newProp_5:script()) witchMoan))
                        (send newAct_2:
                            setScript(0)
                            setMotion(0)
                        )
                        (witchEye:changeState(20))
                    )(else
                        (if ((((<> (send newAct_2:script()) witchChase) and (< (send gEgo:distanceTo(newAct_2)) 30)) and not (send gEgo:has(6))) and (<> (send newProp_5:script()) witchMoan))
                            (send newAct_2:setScript(witchChase))
                        )(else
                            (if ((((send gEgo:inRect(110 123 119 133)) and not (send gEgo:has(6))) and not local8) and (== (send newAct_2:script()) witchChase))
                                Print(57 1 50 2)
                                Print(57 2 50 2)
                                (send gEgo:
                                    setMotion(0)
                                    view(186)
                                    loop(2)
                                    posn((send newProp_4:x()) (send newProp_4:y()))
                                    setLoop(2)
                                    setCycle(Fwd)
                                )
                                (send newProp_4:hide())
                                = local8 1
                                (witchMusic:
                                    number(13)
                                    loop(1)
                                    play()
                                )
                                (User:
                                    canControl(0)
                                    canInput(0)
                                )
                                (witchEye:changeState(7))
                            )(else
                                (if ((((send gEgo:inRect(129 123 138 133)) and not (send gEgo:has(6))) and not local8) and (== (send newAct_2:script()) witchChase))
                                    Print(57 1 50 2)
                                    Print(57 2 50 2)
                                    (send gEgo:
                                        setMotion(0)
                                        view(184)
                                        loop(1)
                                        posn((send newProp_5:x()) (send newProp_5:y()))
                                        setLoop(1)
                                        setCycle(Fwd)
                                    )
                                    (send newProp_5:hide())
                                    = local8 1
                                    (witchMusic:
                                        number(13)
                                        loop(1)
                                        play()
                                    )
                                    (User:
                                        canControl(0)
                                        canInput(0)
                                    )
                                    (witchEye:changeState(4))
                                )(else
                                    (if (((<> (send newAct_2:script()) witchChase) and (<> (send newProp_5:script()) witchMoan)) and (send gEgo:inRect(110 123 138 133)))
                                        (send newAct_2:setScript(witchChase))
                                    )
                                )
                            )
                        )
                    )
                )
            )
        )
        (super:doit())
    )


    (method (dispose)
        (send gSounds:eachElementDo(172))
        = global189 0
        DisposeScript(991)
        (super:dispose())
    )


    (method (handleEvent pEvent)
        (var gInvSaidMe)
        (if ((<> (send pEvent:type()) 128) or (send pEvent:claimed()))
            return 
        )
        (if (> global109 2)
            (if (Said('look>'))
                (if (Said('/eye'))
                    (if ((send ((send gInv:at(6))):ownedBy(57)))
                        Print(57 3)
                    )(else
                        (send pEvent:claimed(0))
                    )
                )(else
                    (if (Said('/hag'))
                        (if (not (send gEgo:has(6)))
                            Print(57 4)
                        )(else
                            (if (local6)
                                Print(57 5)
                            )(else
                                (if ((send ((send gInv:at(6))):ownedBy(-1)))
                                    Print(57 6)
                                )(else
                                    Print(57 5)
                                )
                            )
                        )
                    )(else
                        (send pEvent:claimed(0))
                    )
                )
            )(else
                (if (Said('converse'))
                    (if ((send ((send gInv:at(6))):ownedBy(57)))
                        (answer1:cue())
                    )(else
                        (if ((send gEgo:has(6)))
                            (answer2:cue())
                        )(else
                            (answer3:cue())
                        )
                    )
                )(else
                    (if (Said('rob,get/charm'))
                        (if ((send gEgo:has(7)))
                            Print(800 0)
                        )(else
                            (if (not global207)
                                Print(57 7)
                            )(else
                                (if (> (send gEgo:distanceTo(newAct)) 20)
                                    Print(800 1)
                                )(else
                                    (send gEgo:setScript(pickUp))
                                )
                            )
                        )
                    )(else
                        (if (Said('get,rob/eye'))
                            (if (not (send gEgo:has(6)))
                                (if ((send ((send gInv:at(6))):ownedBy(57)))
                                    (if ((send gEgo:inRect(120 123 128 135)))
                                        Print(57 8)
                                        (send gEgo:get(6))
                                        (send gGame:changeScore(3))
                                    )(else
                                        Print(800 1)
                                    )
                                )(else
                                    Print(57 9)
                                )
                            )(else
                                Print(800 0)
                            )
                        )(else
                            (if (Said('deliver,return,fling/eye'))
                                (if ((send gEgo:has(6)))
                                    (if (not local6)
                                        Print(57 10)
                                    )(else
                                        (send gGame:changeScore(3))
                                        Print(57 11)
                                    )
                                    (send gEgo:put(6 -1))
                                    (witchMoan:changeState(4))
                                )(else
                                    Print(800 2)
                                )
                            )(else
                                (if (Said('/hag>'))
                                    (if (Said('kill'))
                                        Print(57 12)
                                    )(else
                                        (if (Said('get'))
                                            Print(57 13)
                                        )(else
                                            (if (Said('kiss'))
                                                Print(57 14)
                                            )(else
                                                (if (Said('deliver>') and (= gInvSaidMe (send gInv:saidMe())))
                                                    (if ((send gEgo:has((send gInv:indexOf((= gInvSaidMe (send gInv:saidMe())))))))
                                                        Print(57 15)
                                                    )(else
                                                        proc0_19()
                                                    )
                                                )
                                            )
                                        )
                                    )
                                )
                            )
                        )
                    )
                )
            )
        )
        (if (Said('look>'))
            (if (Said('/bottle'))
                Print(57 16)
            )(else
                (if (Said('[<around,in][/room,cave]') or Said('[/!*]'))
                    Print(Format(@global300 57 17 
                            (if (> global109 2)
                                "Within it, reside three one-eyed old witches."
                            )(else
                                " "
                            )
 
                            (if ((send gCast:contains(newAct)))
                                "You see a black scarab on the cave floor."
                            )(else
                                " "
                            )
))
                )(else
                    (if (Said('/caldron'))
                        Print(57 18)
                    )(else
                        (if (Said('/brew'))
                            Print(57 19)
                        )(else
                            (if (Said('/fire'))
                                Print(57 20)
                            )(else
                                (if (Said('<out/cave'))
                                    Print(57 21)
                                )(else
                                    (if (Said('/dirt') or Said('<down'))
                                        (if (global207)
                                            Print(57 22)
                                        )(else
                                            Print(57 23)
                                        )
                                    )(else
                                        (if (Said('/wall'))
                                            Print(57 24)
                                        )(else
                                            (if (Said('/shelf'))
                                                Print(57 25)
                                            )(else
                                                (if (Said('/skull'))
                                                    Print(57 26)
                                                )
                                            )
                                        )
                                    )
                                )
                            )
                        )
                    )
                )
            )
        )(else
            (if (Said('get,rob>'))
                (if (Said('/bottle'))
                    Print(57 27)
                )(else
                    (if (Said('/skull'))
                        Print(57 28)
                    )(else
                        (if (Said('/brew'))
                            Print(57 29)
                        )
                    )
                )
            )(else
                (if (Said('chew,drink/brew'))
                    Print(57 30)
                )(else
                    (if (Said('get/caldron'))
                        Print(57 31)
                    )
                )
            )
        )
    )


    (method (newRoom param1)
        = global189 0
        (super:newRoom(param1))
    )

)
(instance witchEye of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                ((send newAct_2:
                    view(185)
                    loop(0)
                    setCycle(Beg self)
                )
  )
            )
            (case 1
                ((send newProp_3:
                    x(+ (send newAct_2:x()) 1)
                    y(- (send newAct_2:y()) 43)
                    show()
                )
 (send (ScriptID(0 4)):setReal(self 4))  )
            )
            (case 2
                ((send newProp_3:hide()) (send newAct_2:
                    loop(1)
                    setCycle(End self)
                )
  )
            )
            (case 3
                (
                (if (not (send ((send gInv:at(6))):ownedBy(-1)))
                    (send newAct_2:setScript(witchChase))
                )
 (send newProp_4:
                    loop(0)
                    setCycle(CT 4 1 self)
                )
  )
            )
            (case 4
                ((send newProp_5:stopUpd()) (send newProp_3:
                    x(- (send newProp_4:x()) 1)
                    y(- (send newProp_4:y()) 40)
                    show()
                )
 
                (if (not local8)
                    (send (ScriptID(0 4)):setReal(self 5))
                )
 )
            )
            (case 5
                ((send newProp_3:hide()) (send newProp_4:
                    setLoop(0)
                    setCycle(Beg self)
                )
  )
            )
            (case 6
                ((send newProp_4:setCycle(CT 5 -1)) (send newProp_5:setCycle(CT 4 1 self))  )
            )
            (case 7
                ((send newProp_4:stopUpd()) (send newProp_3:
                    x(+ (send newProp_5:x()) 0)
                    y(- (send newProp_5:y()) 39)
                    show()
                )
 
                (if (not local8)
                    (send (ScriptID(0 4)):setReal(self 5))
                )
 )
            )
            (case 8
                ((send newProp_3:hide()) (send newProp_5:setCycle(Beg self))  )
            )
            (case 9
                ((send newProp_5:setCycle(CT 5 -1)) 
                (if (== (send newAct_2:script()) witchChase)
                    = state 3
                )
 (send newProp_4:setCycle(CT 4 1 self))  )
            )
            (case 10
                ((send newProp_5:stopUpd()) (send newProp_3:
                    x(- (send newProp_4:x()) 1)
                    y(- (send newProp_4:y()) 40)
                    show()
                )
 
                (if (not local8)
                    (send (ScriptID(0 4)):setReal(self 5))
                )
 )
            )
            (case 11
                ((send newProp_3:hide()) (send newProp_4:
                    loop(4)
                    cel(0)
                    setCycle(End self)
                )
  )
            )
            (case 12
                ((self:changeState(0))  )
            )
            (case 20
                ((send newProp_3:hide()) (send client:setScript(0)) (send newProp_5:setScript(witchMoan)) )
            )
        )
    )

)
(instance witchChase of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                ((send newAct_2:
                    view(180)
                    moveSpeed(2)
                    setAvoider(Avoid)
                    setLoop(-1)
                    setCycle(Walk)
                    setMotion(Chase gEgo 6 self)
                )
  )
            )
            (case 1
                (proc0_10() (send gEgo:dispose()) (witchEye:cue()) (send newProp_4:show()) (send newProp_5:show()) (send newAct_2:
                    view(65)
                    moveSpeed(1)
                )
 (self:cue())  )
            )
            (case 2
                ((witchMusic:
                    number(13)
                    loop(-1)
                    play()
                )
 = local8 1 (send newAct_2:
                    view(66)
                    setLoop(
                        (if (< 180 GetAngle((send gEgo:x()) (send gEgo:y()) (send newAct_2:x()) (send newAct_2:y())))
                            1
                        )(else
                            0
                        )
)
                    setAvoider(Avoid)
                    setMotion(MoveTo (send newProp_2:x()) 
                        (if (< (send newAct_2:y()) (+ (send newProp_2:y()) 18))
                            + (send newProp_2:y()) 9
                        )(else
                            + (send newProp_2:y()) 25
                        )
 self)
                )
  )
            )
            (case 3
                (Print(57 32 134 -1 20) (send newAct_2:
                    view(66)
                    loop(+ (send newAct_2:loop()) 2)
                    cel(0)
                    setCycle(End self)
                )
  )
            )
            (case 4
                ((send newAct_2:
                    setLoop(-1)
                    view(180)
                    setMotion(MoveTo (send newProp_2:x()) + (send newProp_2:y()) 10)
                )
 (send newProp_4:stopUpd()) (send newProp_5:stopUpd()) (witchMusic:dispose()) (send gEgo:
                    view(64)
                    posn((send newProp_2:x()) + (send newProp_2:y()) 1)
                    cel(0)
                    ignoreActors(1)
                    setPri((send newProp_2:priority()))
                    setLoop((send newAct_2:loop()))
                    init()
                    setMotion(0)
                    setCycle(End self)
                )
  )
            )
            (case 5
                ((send gEgo:
                    setLoop(2)
                    setCycle(Fwd)
                )
 = cycles (* NumCels(gEgo) 3)  )
            )
            (case 6
                ((send gEgo:
                    cel(0)
                    setLoop(3)
                    setCycle(End self)
                )
  )
            )
            (case 7
                (= seconds 3  )
            )
            (case 8
                (= global127 1 )
            )
        )
    )

)
(instance witchMoan of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                ((send newAct_2:setScript(0)) (send newProp_3:hide()) (send newProp_5:
                    view(183)
                    setLoop(2)
                    cel(0)
                    setCycle(End self)
                    ignoreActors(0)
                )
  )
            )
            (case 1
                ((send newProp_4:
                    view(183)
                    setLoop(1)
                    cel(0)
                    ignoreActors(0)
                    setCycle(End self)
                )
  )
            )
            (case 2
                ((send newAct_2:
                    ignoreActors(0)
                    setMotion(MoveTo 125 133 self)
                )
  )
            )
            (case 3
                (
                (if (not (send ((send gInv:at(6))):ownedBy(-1)))
                    Print(57 33)
                )
 (send newAct_2:
                    view(183)
                    setLoop(0)
                    cel(0)
                    setCycle(End)
                )
 (send newProp_4:stopUpd()) (send newProp_5:stopUpd())  )
            )
            (case 4
                ((send newProp_5:setCycle(Beg)) (send newAct_2:setCycle(Beg)) (send newProp_4:setCycle(Beg)) (send (ScriptID(0 6)):setReal(self 4))  )
            )
            (case 5
                ((send newAct_2:
                    view(180)
                    setLoop(-1)
                    illegalBits(0)
                    setMotion(MoveTo 79 128 self)
                )
  )
            )
            (case 6
                ((send newProp_4:
                    view(186)
                    setLoop(1)
                )
 (send newProp_5:
                    view(184)
                    setLoop(0)
                )
 (send client:setScript(0)) (send newProp_4:setScript(witchEye)) )
            )
        )
    )

)
(instance answer1 of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (Print(57 34)  )
            )
            (case 1
                (Print(57 35)  )
            )
            (case 2
                (Print(57 36) = state 1 )
            )
        )
    )

)
(instance answer2 of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (
                (if (not (send ((send gInv:at(6))):ownedBy(-1)))
                    Print(57 37)
                )
 )
            )
            (case 1
                (
                (if (not (send ((send gInv:at(6))):ownedBy(-1)))
                    (switch (Random(1 4))
                        (case 1
                            Print(57 38)
                        )
                        (case 2
                            Print(57 39)
                        )
                        (case 3
                            Print(57 40)
                        )
                        (case 4
                            Print(57 37)
                        )
                    )
                    = state 0
                )
 )
            )
        )
    )

)
(instance answer3 of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (Print(57 41)  )
            )
            (case 1
                (
                (switch (Random(1 3))
                    (case 1
                        (Print(57 42)  )
                    )
                    (case 2
                        (Print(57 43)  )
                    )
                    (case 3
                        (Print(57 41) )
                    )
                )
 = state 0 )
            )
        )
    )

)
(instance scarabToss of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (
                (if (global207)
                    (self:changeState(1))
                )(else
                    (send newAct:setMotion(JumpTo (- (send gEgo:x()) 20) (- (send gEgo:y()) 20) self))
                )
 )
            )
            (case 1
                (= gNewActX (send newAct:x()) = gNewActY (send newAct:y()) = global207 1 (send newAct:setPri(-1)) (send (ScriptID(0 4)):setReal(self 2))  )
            )
            (case 2
                (
                (if ((send gCast:contains(newAct)))
                    (send newAct:setCycle(End self))
                )
 )
            )
            (case 3
                (
                (if ((send gCast:contains(newAct)))
                    (send newAct:setCycle(Beg self))
                )
 )
            )
            (case 4
                ((send newAct:stopUpd()) = state 1 (send (ScriptID(0 5)):setReal(self 5)) )
            )
        )
    )

)
(instance ouchness of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (= local9 1 (send (ScriptID(0 7)):setReal(self 3))  )
            )
            (case 1
                (= state -1 = local9 0 )
            )
        )
    )

)
(instance witchMusic of Sound
    (properties
        number 12
    )
)
(instance blockWitch2 of Blk
    (properties)
)
(instance blockWitch3 of Blk
    (properties)
)
(instance pickUp of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                ((self:cue())  )
            )
            (case 1
                (proc0_10() proc0_3(gEgo newAct) (send gEgo:
                    view(40)
                    cel(0)
                    setCycle(End self)
                )
  )
            )
            (case 2
                ((send newAct:dispose()) = global207 0 (send gEgo:get(7)) = global182 1 (send gGame:changeScore(2)) = seconds 2  )
            )
            (case 3
                ((send gEgo:setCycle(Beg self))  )
            )
            (case 4
                ((send gEgo:
                    view(4)
                    setCycle(Walk)
                )
 proc0_11() )
            )
        )
    )

)
(instance rm57Script of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 1
                (proc0_10() = seconds 3  )
            )
            (case 2
                (Print(57 44 134 -1 20) = state 4 = seconds 3 proc0_11()  )
            )
            (case 3
                (= seconds 3  )
            )
            (case 4
                (
                (if (not (send ((send gInv:at(6))):ownedBy(-1)))
                    Print(57 45)
                )
 )
            )
            (case 5
                (Print(57 46) )
            )
        )
    )

)
