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


(local
    local0
    gEgoY

)
(instance fallSound of Sound
    (properties)
)
(instance public Room76 of Rm
    (properties
        picture 76
        style 16
        horizon 99
        north 73
    )

    (method (init)
        Load(rsVIEW 44)
        (self:setRegions(605))
        (super:init())
        = global101 1
        = west 75
        (send gEgo:
            view(4)
            xStep(4)
            yStep(1)
        )
        (if (== gPicture 73)
            (send gEgo:
                posn(189 119)
                init()
            )
        )(else
            (send gEgo:
                posn(20 162)
                init()
            )
        )
        (send gEgo:priority(kernel[101]((send gEgo:y()))))
        proc0_12(605 1)
    )


    (method (doit)
        (super:doit())
        (if (& (send gEgo:onControl(0)) $0040)
            = gTheGGNewPropX 73
        )
        (if (((& (send gEgo:onControl(1)) $0004) and not local0) and (<> (send global2:script()) fallChasm))
            (self:setScript(fallChasm))
        )
    )


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


    (method (handleEvent pEvent)
        (if ((send pEvent:claimed()))
            return 1
        )
        return 
            (if (== (send pEvent:type()) 128)
                (if (Said('look[<around][/room]'))
                    Print(76 0)
                    Print(76 1)
                )(else
                    (if (Said('find,look/abyss'))
                        (if (& (send gEgo:onControl(0)) $1000)
                            Print(76 2)
                        )(else
                            Print(76 3)
                        )
                    )(else
                        (if (Said('look/(,hole'))
                            Print(76 4)
                        )(else
                            (if (Said('(place,lay)[<down]/board'))
                                (if (not (send gEgo:has(22)))
                                    Print(76 5 134 -1 20 50 5)
                                )(else
                                    (if (local0 or not (& (send gEgo:onControl(0)) $1000))
                                        proc0_15()
                                    )(else
                                        (self:setScript(layBoard))
                                    )
                                )
                            )
                        )
                    )
                )
            )(else
                0
            )
    )

)
(instance fallChasm of Script
    (properties)

    (method (init param1)
        proc0_10()
        proc0_12(605 4)
        (send gEgo:
            view(44)
            setPri(10)
            setCycle(Fwd)
        )
        (super:init(param1))
    )


    (method (changeState newState)
        (switch (= state newState)
            (case 0
                ((send gEgo:
                    illegalBits(0)
                    yStep(10)
                    setMotion(MoveTo + (send gEgo:x()) 5 300 self)
                )
 = cycles 2  )
            )
            (case 1
                ((fallSound:
                    number(52)
                    loop(1)
                    play(self)
                )
  )
            )
            (case 2
                ((send ((send gInv:at(3))):loop(0)) Print(76 6 166 60 1 172) = seconds 3  )
            )
            (case 3
                (proc0_23() Print(76 7 166 60 1 172)  )
            )
            (case 4
                (proc0_23() kernel[106](10) = seconds 2  )
            )
            (case 5
                (= global127 1 )
            )
        )
    )

)
(instance layBoard of Script
    (properties)

    (method (init param1)
        = gEgoY (send gEgo:y())
        (if (< (/ global192 10) 2)
            (send gGame:changeScore(2))
            = global192 (+ global192 10)
        )
        (super:init(param1))
    )


    (method (doit)
        (if ((& (send gEgo:onControl(1)) $0004) and ((> (send gEgo:y()) (+ gEgoY 3)) or (< (send gEgo:y()) (- gEgoY 3))))
            = local0 0
            (send client:setScript(fallChasm))
        )
        (if (((& (send gEgo:onControl(1)) $0004) and (== local0 1)) and (== global132 0))
            = global132 1
        )
        (if (((& (send gEgo:onControl(1)) $1000) and (== global132 1)) and (== local0 1))
            = global132 0
            = local0 0
            (self:changeState(1))
        )
    )


    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (Print(76 8) = local0 1 (send ((send gInv:at(22))):moveTo(76))  )
            )
            (case 1
                ((send global2:setScript(0)) Print(76 9 166) (send gEgo:get(22)) )
            )
        )
    )

)
