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


(local
    gEgoOnControl
    theGEgoOnControl
    newAct
    newAct_2
    local4
    local5

)
(instance hTheme of Sound
    (properties)
)
(instance public Room30 of Rm
    (properties
        picture 30
    )

    (method (init)
        = north 24
        = east 79
        = west 29
        = horizon 85
        = global101 0
        (send gEgo:edgeHit(0))
        (if (global100)
            = picture 130
        )
        (super:init())
        (self:setRegions(508 511))
        Load(rsVIEW 80)
        Load(rsVIEW 17)
        Load(rsVIEW 18)
        Load(rsVIEW 21)
        Load(rsVIEW 33)
        Load(rsVIEW 60)
        Load(rsVIEW 143)
        Load(rsVIEW 144)
        Load(rsSOUND 80)
        (switch (gPicture)
            (case west
                ((send gEgo:x(2))  )
            )
            (case 24
                ((send gEgo:posn(112 (+ horizon 2)))  )
            )
            (case 0
                ((send gEgo:
                    x(183)
                    y(124)
                )
  )
            )
            (case 92
                ((send gEgo:
                    view(80)
                    setCycle(Fwd)
                    setScript(henchFlyIn)
                )
 = horizon 64536 (henchFlyIn:changeState(1))  )
            )
            (case 79
                (
                (if (== (send gEgo:view()) 80)
                    = horizon 64536
                    (send gEgo:
                        ignoreHorizon()
                        setScript(henchFlyIn)
                    )
                    (henchFlyIn:changeState(1))
                )(else
                    (send gEgo:
                        x(318)
                        y(101)
                    )
                )
 )
            )
            (default 
                ((send gEgo:
                    x(183)
                    y(124)
                )
 )
            )
        )
        (if (== (send gEgo:script()) 0)
            (send gEgo:
                view(2)
                xStep(2)
                yStep(1)
                init()
            )
        )
    )


    (method (doit)
        (super:doit())
        (if ((<> (= gEgoOnControl (send gEgo:onControl())) theGEgoOnControl) and (== (send global2:script()) 0))
            = theGEgoOnControl gEgoOnControl
            (if (& gEgoOnControl $0010)
                (self:setScript(shortFall))
            )(else
                (if (& gEgoOnControl $0004)
                    (self:setScript(deadFall))
                )(else
                    (if (& gEgoOnControl $0020)
                        (self:setScript(deadMagenta))
                    )
                )
            )
        )
    )


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


    (method (handleEvent pEvent)
        (if ((send pEvent:claimed()))
            return 1
        )
        return 
            (if (== (send pEvent:type()) 128)
                (if (Said('climb/boulder'))
                    Print(30 0)
                )(else
                    (if (Said('look>'))
                        (if (Said('/path'))
                            Print(30 1)
                        )(else
                            (if (Said('/boulder'))
                                Print(30 2)
                            )(else
                                (if (Said('/goon,man,person'))
                                    (if ((send gCast:contains(newAct)))
                                        Print(30 3)
                                    )(else
                                        Print(30 4)
                                    )
                                )(else
                                    (if (Said('[<around][/room]'))
                                        Print(30 5)
                                    )
                                )
                            )
                        )
                    )
                )
            )(else
                0
            )
    )


    (method (newRoom param1)
        (if (<> (send gEgo:view()) 80)
            (super:newRoom(param1))
        )
    )

)
(instance shortFall of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                ((send ((Sound:new())):
                    number(51)
                    loop(1)
                    play()
                )
 proc0_10() 
                (if (< (send gEgo:x()) 183)
                    = local5 146
                )(else
                    (if (> (send gEgo:x()) 195)
                        = local5 165
                    )(else
                        = local5 154
                    )
                )
 (send gEgo:
                    yStep(6)
                    yStep(6)
                    illegalBits(0)
                    loop(& (send gEgo:loop()) $0001)
                    setCel(0)
                    view(17)
                    setCycle(Fwd)
                    setMotion(MoveTo (send gEgo:x()) local5 self)
                )
  )
            )
            (case 1
                ((send gEgo:
                    xStep(2)
                    yStep(1)
                    view(18)
                    loop(0)
                    setCycle(Fwd)
                )
 (Timer:setReal(self 5)) (send ((Sound:new())):
                    number(80)
                    loop(1)
                    play()
                )
  )
            )
            (case 2
                ((send gEgo:
                    view(21)
                    loop(2)
                    cel(4)
                    setCycle(Beg self)
                )
  )
            )
            (case 3
                ((send gEgo:
                    setCycle(Walk)
                    view(2)
                    illegalBits(32768)
                )
 proc0_11() (send global2:setScript(0)) )
            )
        )
    )

)
(instance deadFall of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                ((send ((Sound:new())):
                    number(51)
                    loop(1)
                    play()
                )
 proc0_10() (send gEgo:
                    yStep(10)
                    illegalBits(0)
                    loop(& (send gEgo:loop()) $0001)
                    setCel(0)
                    view(17)
                    setCycle(Fwd)
                    setMotion(MoveTo (send gEgo:x()) 175 self)
                )
  )
            )
            (case 1
                ((send gEgo:
                    xStep(2)
                    yStep(1)
                    view(33)
                    loop(0)
                )
 Animate((send gCast:elements()) 0) kernel[106](10 1) (Timer:setReal(self 3))  )
            )
            (case 2
                (Print(30 6) (Timer:setReal(self 5))  )
            )
            (case 3
                (proc0_11() = global127 1 )
            )
        )
    )

)
(instance deadMagenta of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                ((send ((Sound:new())):
                    number(51)
                    loop(1)
                    play()
                )
 proc0_10() (send gEgo:
                    yStep(10)
                    illegalBits(0)
                    loop(& (send gEgo:loop()) $0001)
                    setCel(0)
                    view(17)
                    setCycle(Fwd)
                    setMotion(MoveTo (send gEgo:x()) 175 self)
                )
  )
            )
            (case 1
                ((send gEgo:
                    xStep(2)
                    yStep(1)
                    view(33)
                    loop(0)
                )
 (Timer:setReal(self 3)) Animate((send gCast:elements()) 0) kernel[106](10 1)  )
            )
            (case 2
                (Print(30 6) (Timer:setReal(self 5))  )
            )
            (case 3
                (= global127 1 proc0_11() )
            )
        )
    )

)
(instance henchFlyIn of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 1
                (proc0_10() (hTheme:
                    number(29)
                    loop(1)
                    play()
                )
 (send gEgo:
                    view(80)
                    setLoop(4)
                    ignoreHorizon()
                    yStep(1)
                    illegalBits(0)
                    setPri(12)
                    setCycle(Fwd)
                    posn(168 65506)
                    init()
                    setMotion(MoveTo 160 121 self)
                )
  )
            )
            (case 2
                ((send gEgo:
                    view(60)
                    setLoop(3)
                    cel(0)
                    cycleSpeed(1)
                    setCycle(End self)
                )
 = newAct (Act:new()) = newAct_2 (Act:new()) (send newAct:
                    view(144)
                    posn(- (send gEgo:x()) 15 (send gEgo:y()))
                    xStep(6)
                    yStep(3)
                    cycleSpeed(0)
                    setCycle(Fwd)
                    setScript(h1Actions)
                )
 (send newAct_2:
                    view(144)
                    posn(+ (send gEgo:x()) 15 (send gEgo:y()))
                    xStep(6)
                    yStep(3)
                    cycleSpeed(0)
                    setCycle(Fwd)
                    setScript(h2Actions)
                )
  )
            )
            (case 3
                ((send gEgo:
                    view(2)
                    ignoreHorizon(0)
                    ignoreActors(0)
                    setLoop(-1)
                    loop(1)
                    illegalBits(32768)
                    setPri(-1)
                    cycleSpeed(0)
                    setCycle(Walk)
                )
 (send gEgo:
                    xStep(2)
                    yStep(1)
                )
 proc0_11() )
            )
        )
    )

)
(instance h1Actions of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                ((send newAct:
                    init()
                    ignoreHorizon()
                    illegalBits(0)
                    setPri(12)
                    setCycle(Walk)
                    setMotion(MoveTo 145 40 self)
                )
  )
            )
            (case 1
                ((send newAct:
                    view(143)
                    setMotion(MoveTo 145 65506 self)
                )
 = local4 1  )
            )
            (case 2
                ((send global2:horizon(85)) (send newAct:dispose()) )
            )
        )
    )

)
(instance h2Actions of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                ((send newAct_2:
                    init()
                    ignoreHorizon()
                    illegalBits(0)
                    setPri(12)
                    setCycle(Walk)
                    setMotion(MoveTo 175 40 self)
                )
  )
            )
            (case 1
                ((send newAct_2:
                    view(143)
                    setMotion(MoveTo 175 65506 self)
                )
  )
            )
            (case 2
                ((send newAct_2:dispose()) )
            )
        )
    )

)
