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


(local
    newAct
    newAct_2
    local2

)
(instance henchTheme of Sound
    (properties)
)
(instance sFalling of Sound
    (properties
        priority 3
    )
)
(instance public Room79 of Rm
    (properties
        picture 79
        style 8
    )

    (method (init)
        = east 80
        = west 30
        = north 80
        = south 30
        = global101 0
        Load(rsVIEW 80)
        Load(rsVIEW 60)
        Load(rsVIEW 140)
        Load(rsVIEW 142)
        Load(rsVIEW 143)
        Load(rsVIEW 144)
        (if (global100)
            = picture 179
        )
        (super:init())
        (switch (gPicture)
            (case north
                ((send gEgo:
                    view(2)
                    posn(232 92)
                    loop(1)
                    init()
                )
  )
            )
            (case west
                (
                (if (global169)
                    = newAct (Act:new())
                    = newAct_2 (Act:new())
                    (send newAct:setScript(h1Actions))
                    (send newAct_2:
                        setScript(h2Actions)
                        init()
                        hide()
                    )
                )
 (send gEgo:
                    x(63)
                    y(188)
                )
 (send gEgo:
                    init()
                    view(2)
                )
  )
            )
            (default 
                ((send gEgo:
                    x(63)
                    y(188)
                )
 = newAct (Act:new()) = newAct_2 (Act:new()) (send newAct:setScript(h1Actions)) (send newAct_2:
                    setScript(h2Actions)
                    init()
                    hide()
                )
 (send gEgo:
                    x(63)
                    y(188)
                )
 (send gEgo:
                    init()
                    view(2)
                )
 )
            )
        )
        (send gEgo:edgeHit(0))
        = global105 0
        = global189 1
        = global204 0
    )


    (method (doit)
        (super:doit())
        (if ((== (send global2:script()) 0) and (== global105 0))
            (if (& (send gEgo:onControl(0)) $0002)
                (send gSounds:eachElementDo(172))
                (sFalling:
                    loop(1)
                    number(51)
                    play()
                )
                (send global2:setScript(fallBlue))
                (stopHench:cue())
            )(else
                (if (& (send gEgo:onControl(0)) $0008)
                    (send gSounds:eachElementDo(172))
                    (sFalling:
                        loop(1)
                        number(51)
                        play()
                    )
                    (stopHench:cue())
                    (send global2:setScript(fallCyan))
                )(else
                    (if (& (send gEgo:onControl(0)) $0004)
                        (send gSounds:eachElementDo(172))
                        (sFalling:
                            loop(1)
                            number(51)
                            play()
                        )
                        (stopHench:cue())
                        (send global2:setScript(fallGreen))
                    )(else
                        (if (& (send gEgo:onControl(0)) $0080)
                            (send gSounds:eachElementDo(172))
                            (sFalling:
                                loop(1)
                                number(51)
                                play()
                            )
                            (stopHench:cue())
                            (send global2:setScript(fallLgrey))
                        )(else
                            (if (& (send gEgo:onControl(0)) $0100)
                                (send gSounds:eachElementDo(172))
                                (sFalling:
                                    loop(1)
                                    number(51)
                                    play()
                                )
                                (stopHench:cue())
                                (send global2:setScript(fallGrey))
                            )(else
                                (if (& (send gEgo:onControl(0)) $0200)
                                    (send gSounds:eachElementDo(172))
                                    (sFalling:
                                        loop(1)
                                        number(51)
                                        play()
                                    )
                                    (stopHench:cue())
                                    (send global2:setScript(fallLblue))
                                )(else
                                    (if (& (send gEgo:onControl(0)) $0400)
                                        (send gSounds:eachElementDo(172))
                                        (sFalling:
                                            loop(1)
                                            number(51)
                                            play()
                                        )
                                        (stopHench:cue())
                                        (send global2:setScript(fallLgreen))
                                    )(else
                                        (if (& (send gEgo:onControl(0)) $0800)
                                            (send gSounds:eachElementDo(172))
                                            (sFalling:
                                                loop(1)
                                                number(51)
                                                play()
                                            )
                                            (stopHench:cue())
                                            (send global2:setScript(fallLcyan))
                                        )(else
                                            (if (& (send gEgo:onControl(0)) $0040)
                                                (send global2:newRoom(80))
                                            )(else
                                                (if (& (send gEgo:onControl(0)) $0010)
                                                    (if (< (send gEgo:heading()) 180)
                                                        (send gEgo:baseSetter(0))
                                                    )(else
                                                        (send gEgo:baseSetter(ScriptID(0 1)))
                                                    )
                                                )
                                            )
                                        )
                                    )
                                )
                            )
                        )
                    )
                )
            )
        )
    )


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


    (method (handleEvent pEvent)
        (var gInvSaidMe)
        (if ((send pEvent:claimed()))
            return 1
        )
        return 
            (if (== (send pEvent:type()) 128)
                (if (Said('look>'))
                    (if (Said('/room,cliff') or Said('[<around][/!*]'))
                        Print(79 0)
                    )(else
                        (if (Said('/goon'))
                            (if ((send gCast:contains(newAct)))
                                Print(79 1)
                            )(else
                                Print(79 2)
                            )
                        )(else
                            (if (Said('/path'))
                                Print(79 3)
                            )(else
                                (if (Said('/castle'))
                                    Print(79 4)
                                )(else
                                    (if (Said('/boulder'))
                                        Print(79 5)
                                    )(else
                                        (if (Said('/dirt,down'))
                                            Print(79 6)
                                        )(else
                                            (if (Said('/forest'))
                                                Print(79 7)
                                            )
                                        )
                                    )
                                )
                            )
                        )
                    )
                )(else
                    (if (Said('climb/cliff'))
                        Print(79 8)
                    )(else
                        (if (Said('converse/goon') or Said('converse[/!*]'))
                            Print(79 9)
                        )(else
                            (if (Said('get,capture/goon'))
                                Print(79 10)
                            )(else
                                (if (Said('deliver>'))
                                    (if (= gInvSaidMe (send gInv:saidMe()))
                                        (if ((send gEgo:has((send gInv:indexOf((= gInvSaidMe (send gInv:saidMe())))))))
                                            Print(79 11)
                                        )(else
                                            Print(800 2)
                                        )
                                    )(else
                                        Print(79 12)
                                        (send pEvent:claimed(1))
                                    )
                                )
                            )
                        )
                    )
                )
            )(else
                0
            )
    )


    (method (newRoom param1)
        proc0_23()
        (if (<> global105 10)
            = global189 0
            (send gEgo:
                illegalBits(32768)
                setPri(-1)
            )
            (super:newRoom(param1))
        )
    )

)
(instance fallBlue of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (= global105 10 proc0_10() (send gEgo:
                    setPri(8)
                    yStep(10)
                    illegalBits(0)
                    loop(& (send gEgo:loop()) $0001)
                    cel(0)
                    view(17)
                    setCycle(Fwd)
                    posn(- (send gEgo:x()) 8 (send gEgo:y()))
                    setMotion(MoveTo (send gEgo:x()) + (send gEgo:y()) 150 self)
                )
  )
            )
            (case 1
                ((send global2:setScript(egoDead)) )
            )
        )
    )

)
(instance fallCyan of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (proc0_10() = global105 10 (send gEgo:
                    setPri(8)
                    yStep(10)
                    illegalBits(0)
                    loop(& (send gEgo:loop()) $0001)
                    cel(0)
                    view(17)
                    setCycle(Fwd)
                    posn((send gEgo:x()) + (send gEgo:y()) 8)
                    setMotion(MoveTo (send gEgo:x()) + (send gEgo:y()) 150 self)
                )
  )
            )
            (case 1
                ((send global2:setScript(egoDead)) )
            )
        )
    )

)
(instance fallGreen of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (proc0_10() = global105 10 (send gEgo:
                    setPri(4)
                    yStep(10)
                    illegalBits(0)
                    loop(& (send gEgo:loop()) $0001)
                    cel(0)
                    view(17)
                    setCycle(Fwd)
                    posn((send gEgo:x()) - (send gEgo:y()) 8)
                    setMotion(MoveTo (send gEgo:x()) + (send gEgo:y()) 150 self)
                )
  )
            )
            (case 1
                ((send global2:setScript(egoDead)) )
            )
        )
    )

)
(instance fallLgrey of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (proc0_10() = global105 10 (send gEgo:
                    setPri(10)
                    yStep(10)
                    illegalBits(0)
                    loop(& (send gEgo:loop()) $0001)
                    cel(0)
                    view(17)
                    setCycle(Fwd)
                    posn(+ (send gEgo:x()) 8 + (send gEgo:y()) 4)
                    setMotion(MoveTo (send gEgo:x()) + (send gEgo:y()) 150 self)
                )
  )
            )
            (case 1
                ((send global2:setScript(egoDead)) )
            )
        )
    )

)
(instance fallGrey of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (proc0_10() = global105 10 (send gEgo:
                    setPri(7)
                    yStep(10)
                    illegalBits(0)
                    loop(& (send gEgo:loop()) $0001)
                    cel(0)
                    view(17)
                    setCycle(Fwd)
                    posn((send gEgo:x()) + (send gEgo:y()) 4)
                    setMotion(MoveTo (send gEgo:x()) + (send gEgo:y()) 150 self)
                )
  )
            )
            (case 1
                ((send global2:setScript(egoDead)) )
            )
        )
    )

)
(instance fallLblue of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (proc0_10() = global105 10 (send gEgo:
                    setPri(6)
                    yStep(10)
                    illegalBits(0)
                    loop(& (send gEgo:loop()) $0001)
                    cel(0)
                    view(17)
                    setCycle(Fwd)
                    posn((send gEgo:x()) + (send gEgo:y()) 4)
                    setMotion(MoveTo (send gEgo:x()) + (send gEgo:y()) 150 self)
                )
  )
            )
            (case 1
                ((send global2:setScript(egoDead)) )
            )
        )
    )

)
(instance fallLgreen of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (proc0_10() = global105 10 (send gEgo:
                    setPri(0)
                    yStep(10)
                    illegalBits(0)
                    loop(& (send gEgo:loop()) $0001)
                    cel(0)
                    view(17)
                    setCycle(Fwd)
                    posn((send gEgo:x()) - (send gEgo:y()) 4)
                    setMotion(MoveTo (send gEgo:x()) + (send gEgo:y()) 150 self)
                )
  )
            )
            (case 1
                ((send global2:setScript(egoDead)) )
            )
        )
    )

)
(instance fallLcyan of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (proc0_10() = global105 10 (send gEgo:
                    setPri(0)
                    yStep(10)
                    illegalBits(0)
                    loop(& (send gEgo:loop()) $0001)
                    cel(0)
                    view(17)
                    setCycle(Fwd)
                    posn((send gEgo:x()) + (send gEgo:y()) 4)
                    setMotion(MoveTo (send gEgo:x()) + (send gEgo:y()) 150 self)
                )
  )
            )
            (case 1
                ((send global2:setScript(egoDead)) )
            )
        )
    )

)
(instance h1Actions of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                ((henchTheme:
                    number(29)
                    loop(-1)
                    play()
                )
 (send newAct:
                    ignoreHorizon()
                    posn(57 7)
                    view(142)
                    setCycle(Walk)
                    setMotion(MoveTo 65526 22 self)
                    ignoreActors()
                    illegalBits(0)
                    setPri(13)
                    init()
                )
 Print(79 13 166 134 -1 20 172)  )
            )
            (case 1
                ((send newAct:
                    xStep(4)
                    yStep(3)
                    setMotion(MoveTo 65526 50 self)
                )
  )
            )
            (case 2
                (proc0_23() (send newAct:
                    view(143)
                    xStep(6)
                    yStep(4)
                    setMotion(MoveTo 252 66 self)
                )
  )
            )
            (case 3
                ((send newAct:
                    view(144)
                    xStep(8)
                    yStep(6)
                    setMotion(Chase gEgo 14 self)
                )
 (h2Actions:changeState(1))  )
            )
            (case 4
                ((send newAct:
                    view(140)
                    posn(+ (send gEgo:x()) 14 + (send gEgo:y()) 5)
                )
 proc0_3(newAct gEgo) (send gEgo:
                    loop(0)
                    setMotion(0)
                )
 proc0_10() )
            )
        )
    )

)
(instance h2Actions of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 1
                ((send newAct_2:
                    ignoreHorizon()
                    posn(57 7)
                    view(142)
                    setCycle(Walk)
                    xStep(4)
                    yStep(3)
                    setMotion(MoveTo 26 65 self)
                    ignoreActors()
                    illegalBits(0)
                    setPri(13)
                    show()
                )
  )
            )
            (case 2
                ((send newAct_2:
                    view(143)
                    xStep(6)
                    yStep(4)
                    setMotion(MoveTo 42 120 self)
                )
  )
            )
            (case 3
                ((send newAct_2:
                    view(144)
                    xStep(8)
                    yStep(6)
                    setMotion(MoveTo - (send gEgo:x()) 14 (send gEgo:y()) self)
                )
  )
            )
            (case 4
                ((send newAct_2:view(140)) proc0_3(newAct_2 gEgo) (send (ScriptID(0 4)):setReal(self 2))  )
            )
            (case 5
                (= global105 1 (send newAct:hide()) (send newAct_2:hide()) 
                (if (== global109 1)
                    (self:changeState(20))
                )(else
                    (if ((== global109 2) and not (send gEgo:has(33)))
                        (self:changeState(20))
                    )(else
                        (if ((== global109 3) and not (send gEgo:has(4)))
                            (self:changeState(20))
                        )(else
                            (send gEgo:
                                view(60)
                                illegalBits(0)
                                setPri(15)
                                ignoreHorizon()
                                setLoop(1)
                                cel(0)
                                setCycle(End self)
                            )
                        )
                    )
                )
 )
            )
            (case 6
                ((send gEgo:
                    view(80)
                    setLoop(5)
                    setCycle(Fwd)
                    setMotion(MoveTo 24 60 self)
                )
  )
            )
            (case 7
                ((send gEgo:
                    setLoop(3)
                    posn((send gEgo:x()) - (send gEgo:y()) 5)
                    setMotion(MoveTo 50 38)
                )
 (send (ScriptID(0 4)):setReal(self 2))  )
            )
            (case 8
                ((send gEgo:
                    setLoop(1)
                    setMotion(MoveTo 72 29)
                )
 (send (ScriptID(0 4)):setReal(self 3))  )
            )
            (case 9
                ((send gEgo:
                    illegalBits(0)
                    setPri(15)
                    setLoop(0)
                    setMotion(MoveTo 72 29 self)
                )
  )
            )
            (case 10
                ((send gEgo:
                    setLoop(-1)
                    setCel(-1)
                )
 (User:canControl(1)) (User:canInput(1)) (send gEgo:dispose()) proc0_11() (send global2:newRoom(92))  )
            )
            (case 20
                ((send gEgo:
                    illegalBits(0)
                    setPri(15)
                    view(60)
                    setLoop(2)
                    cel(0)
                    setCycle(End self)
                )
  )
            )
            (case 21
                (proc0_21(henchTheme 1) (send gEgo:
                    view(80)
                    setCycle(Fwd)
                    setLoop(4)
                    setMotion(MoveTo 65496 160 self)
                )
  )
            )
            (case 22
                (proc0_11() (send global2:newRoom(30)) )
            )
        )
    )

)
(instance egoDead of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (Animate((send gCast:elements()) 0) kernel[106](10 1) = seconds 3  )
            )
            (case 1
                (Print(79 14) (send (ScriptID(0 4)):setReal(self 4))  )
            )
            (case 2
                (= global127 1 )
            )
        )
    )

)
(instance stopHench of Script
    (properties)

    (method (cue)
        (if ((send gCast:contains(newAct)))
            (send newAct:
                setLoop(-1)
                setCycle(Walk)
                setMotion(MoveTo 65468 32)
                setCycle(Fwd)
            )
        )
        (if ((send gCast:contains(newAct_2)))
            (send newAct_2:
                setLoop(-1)
                setCycle(Walk)
                setMotion(MoveTo 65468 32)
                setCycle(Fwd)
            )
        )
    )

)
