(version 2)
(include "sci.sh")
(exports
    0 Room47
)
(use "Main")
(use "Class_255_0")
(use "AView")
(use "Avoid")
(use "Cycle")
(use "Game")
(use "Feature")
(use "Obj")
(script 47)


(local
    local0
    gEgoY
    theGGEgoX
    local3

)
(instance tin of View
    (properties)
)
(instance rightArm of Prop
    (properties)
)
(instance leftArm of Prop
    (properties)
)
(instance mouth of Prop
    (properties)
)
(instance public Room47 of Rm
    (properties
        picture 47
    )

    (method (init)
        = east 48
        = west 46
        = south 51
        = global109 13
        = local3 5
        = global591 (| global109 local3)
        (super:init())
        = global116 0
        (tin:
            view(72)
            loop(2)
            cel(0)
            ignoreActors()
            posn(190 66)
            setPri(0)
            init()
            addToPic()
        )
        (rightArm:
            view(72)
            ignoreActors()
            loop(0)
            cel(8)
            posn(209 66)
            setPri(0)
            cycleSpeed(4)
            setCycle(Fwd)
            init()
        )
        (leftArm:
            view(72)
            ignoreActors()
            loop(1)
            cel(0)
            posn(170 66)
            setPri(0)
            cycleSpeed(4)
            setCycle(Fwd)
            init()
        )
        (mouth:
            view(72)
            ignoreActors()
            loop(3)
            cel(1)
            posn(190 56)
            setPri(1)
            cycleSpeed(2)
            setCycle(Fwd)
            init()
        )
        (if (not global124)
            (leftArm:addToPic())
            (rightArm:
                cel(5)
                addToPic()
            )
            (mouth:addToPic())
        )
        (send gEgo:init())
        proc0_1()
        (switch (global12)
            (case 43
                = global104 4
                (send gEgo:
                    posn(192 72)
                    view(68)
                    setPri(2)
                    setStep(1 1)
                )
            )
            (case 46
                (switch (global104)
                    (case 4
                        (send gEgo:
                            posn(1 90)
                            view(68)
                            setStep(1 1)
                            setPri(2)
                        )
                    )
                    (case 0
                        (send gEgo:posn(1 (send gEgo:y)))
                    )
                    (case 3
                        (send gEgo:
                            posn(1 85)
                            looper(ScriptID(501 1))
                            setPri(2)
                        )
                    )
                    (case 1
                        (send gEgo:
                            posn(1 (send gEgo:y))
                            looper(ScriptID(501 1))
                            setPri(4)
                        )
                    )
                    (case 2
                        (send gEgo:
                            posn(1 (send gEgo:y))
                            view(82)
                            setStep(2 1)
                            setPri(4)
                        )
                    )
                )
            )
            (case 48
                (switch (global104)
                    (case 0
                        (send gEgo:posn(318 (send gEgo:y)))
                    )
                    (case 1
                        (send gEgo:
                            posn(318 (send gEgo:y))
                            looper(ScriptID(501 1))
                            setPri(4)
                        )
                    )
                    (case 2
                        = global104 4
                        (send gEgo:
                            posn(318 (send gEgo:y))
                            view(68)
                            setStep(1 1)
                            setPri(2)
                        )
                    )
                )
            )
            (case 51
                proc0_1()
                = global104 0
                (send gEgo:
                    view(0)
                    posn((send gEgo:x) 188)
                )
            )
            (default 
                (send gEgo:posn(154 174))
            )
        )
        (self:setRegions(501))
        (switch (global110)
            (case 1
                (if (== Random(1 3) 2)
                    = gNewAct (Act:new())
                    (send gNewAct:
                        posn(1000 1000)
                        init()
                    )
                    = gSeconds Random(2 10)
                )
            )
            (case 2
                = gNewAct (Act:new())
                (send gNewAct:
                    posn(1000 1000)
                    init()
                )
                = gSeconds 3
            )
        )
        (if ((send global5:contains(gNewAct)))
            (send gNewAct:
                view(106)
                setCycle(Walk)
                observeControl(2)
                posn(1000 1000)
                init()
            )
            = gGEgoX 124
            = gGEgoY 147
            (switch (global12)
                (case east
                    (send gNewAct:posn(359 172))
                )
                (case west
                    (send gNewAct:posn(-40 172))
                )
                (case south
                    (send gNewAct:posn(160 249))
                )
                (case north
                    (send gNewAct:posn(124 147))
                )
            )
            = global110 1
            (send (ScriptID(501 0)):notify(1))
        )(else
            (send (ScriptID(501 0)):notify(4))
        )
    )


    (method (doit)
        (super:doit())
        (if (<> global11 global13)
            return 
        )
        = local0 (send gEgo:onControl(0))
        (if ((== global116 2) and not (& local0 $0002))
            = global116 0
            (if (proc501_2(8) or proc501_2(4))
                (send gEgo:posn((send gEgo:x) (+ (send gEgo:y) 5)))
            )
        )(else
            (if ((== global116 4) and not (& local0 $0004))
                = global116 0
                (send gEgo:ignoreControl(4))
            )(else
                (if ((== global116 8) and not (& local0 $0008))
                    = global116 0
                    (if (proc501_2(4))
                        (send gEgo:posn((send gEgo:x) (+ (send gEgo:y) 5)))
                    )
                )(else
                    (if ((== global116 16) and not (& local0 $0010))
                        (send gEgo:ignoreControl(16))
                        = global116 0
                    )
                )
            )
        )
        (switch (global104)
            (case 0
                (if (((& local0 $0002) and not global155) and not global116)
                    = global104 1
                    = global116 2
                    = gGEgoX (send gEgo:x)
                    = gGEgoY (send gEgo:y)
                    (if (IsObject((send gEgo:mover)))
                        (if (gGEgoY)
                            = gEgoY 400
                            = theGGEgoX gGEgoX
                        )(else
                            = gEgoY (+ (- (send gEgo:y) (send ((send gEgo:mover)):y)) (send gEgo:y))
                            = theGGEgoX (send ((send gEgo:mover)):x)
                        )
                    )(else
                        = gEgoY (send gEgo:y)
                        = theGGEgoX (send gEgo:x)
                    )
                    (send gEgo:
                        view(82)
                        xStep(2)
                        yStep(1)
                        looper(ScriptID(501 1))
                        setMotion(MoveTo theGGEgoX gEgoY)
                        setPri(5)
                    )
                )(else
                    (if (proc501_2(global109) and (== global116 0))
                        = global104 1
                        = gEgoY 180
                        = theGGEgoX (send gEgo:x)
                        (send gEgo:
                            setPri(3)
                            posn((send gEgo:x) + (send gEgo:y) 8)
                        )
                        proc0_10()
                        (send gEgo:
                            view(82)
                            looper(ScriptID(501 1))
                            xStep(2)
                            yStep(1)
                            setMotion(MoveTo theGGEgoX gEgoY)
                            setPri(4)
                        )
                    )
                )
            )
            (case 1
                (if (((& local0 $0004) and not global155) and not global116)
                    = global116 4
                    = global104 2
                    (if (IsObject((send gEgo:mover)))
                        (if (gGEgoY)
                            = gEgoY gGEgoY
                            = theGGEgoX gGEgoX
                        )(else
                            = gEgoY (+ (- (send gEgo:y) (send ((send gEgo:mover)):y)) (send gEgo:y))
                            = theGGEgoX (send ((send gEgo:mover)):x)
                        )
                    )(else
                        = gEgoY (send gEgo:y)
                        = theGGEgoX (send gEgo:x)
                    )
                    (send gEgo:
                        posn((send gEgo:x) - (send gEgo:y) 3)
                        observeControl(4)
                    )
                    proc0_10()
                    (send gEgo:
                        view(82)
                        looper(0)
                        setStep(2 1)
                        observeControl(4)
                        setMotion(MoveTo theGGEgoX gEgoY)
                    )
                )(else
                    (if ((((& local0 $0002) and (== global104 1)) and not global155) and not global116)
                        = global116 2
                        = global104 0
                        (if (IsObject((send gEgo:mover)))
                            (if (gGEgoY)
                                = gEgoY gGEgoY
                                = theGGEgoX gGEgoX
                            )(else
                                = gEgoY (+ (- (send gEgo:y) (send ((send gEgo:mover)):y)) (send gEgo:y))
                                = theGGEgoX (send ((send gEgo:mover)):x)
                            )
                        )(else
                            = gEgoY (send gEgo:y)
                            = theGGEgoX (send gEgo:x)
                        )
                        (send gEgo:
                            view(0)
                            xStep(3)
                            yStep(2)
                            looper(0)
                            setMotion(MoveTo theGGEgoX gEgoY)
                            setPri(-1)
                            moveSpeed(0)
                        )
                    )(else
                        (if ((== global116 0) and proc501_2(local3))
                            = gEgoY 180
                            = theGGEgoX (send gEgo:x)
                            (send gEgo:
                                setPri(3)
                                posn((send gEgo:x) + (send gEgo:y) 8)
                            )
                            proc0_10()
                            (send gEgo:
                                view(82)
                                looper(ScriptID(501 1))
                                xStep(2)
                                yStep(1)
                                setMotion(MoveTo theGGEgoX gEgoY)
                                setPri(4)
                            )
                        )
                    )
                )
            )
            (case 2
                (if (((& local0 $0008) and not global155) and not global116)
                    = global104 3
                    = global116 8
                    (if (IsObject((send gEgo:mover)))
                        (if (gGEgoY)
                            = gEgoY 400
                            = theGGEgoX gGEgoX
                        )(else
                            = gEgoY (+ (- (send gEgo:y) (send ((send gEgo:mover)):y)) (send gEgo:y))
                            = theGGEgoX (send ((send gEgo:mover)):x)
                        )
                    )(else
                        = gEgoY (send gEgo:y)
                        = theGGEgoX (send gEgo:x)
                    )
                    (send gEgo:
                        view(82)
                        xStep(2)
                        yStep(1)
                        looper(ScriptID(501 1))
                        setMotion(MoveTo theGGEgoX gEgoY)
                        setPri(2)
                    )
                )(else
                    (if (((& local0 $0004) and not global155) and not global116)
                        = global116 4
                        = global104 1
                        (if (IsObject((send gEgo:mover)))
                            (if (gGEgoY)
                                = gEgoY -400
                                = theGGEgoX gGEgoX
                            )(else
                                = gEgoY (+ (- (send gEgo:y) (send ((send gEgo:mover)):y)) (send gEgo:y))
                                = theGGEgoX (send ((send gEgo:mover)):x)
                            )
                        )(else
                            = gEgoY (send gEgo:y)
                            = theGGEgoX (send gEgo:x)
                        )
                        (send gEgo:
                            posn((send gEgo:x) - (send gEgo:y) 3)
                            observeControl(4)
                        )
                        proc0_10()
                        (send gEgo:
                            view(82)
                            xStep(2)
                            yStep(1)
                            looper(ScriptID(501 1))
                            setMotion(MoveTo theGGEgoX gEgoY)
                            setPri(5)
                        )
                    )(else
                        (if ((== global116 0) and proc501_2(local3))
                            = global104 3
                            = gEgoY 180
                            = theGGEgoX (send gEgo:x)
                            (send gEgo:
                                setPri(2)
                                posn((send gEgo:x) + (send gEgo:y) 8)
                            )
                            proc0_10()
                            (send gEgo:
                                view(82)
                                looper(ScriptID(501 1))
                                xStep(2)
                                yStep(1)
                                setMotion(MoveTo theGGEgoX gEgoY)
                                setPri(2)
                            )
                        )
                    )
                )
            )
            (case 3
                (if (((& local0 $0010) and not global155) and not global116)
                    = global116 16
                    = global104 4
                    (if (IsObject((send gEgo:mover)))
                        0
                        (if (gGEgoY)
                            = gEgoY gGEgoY
                            = theGGEgoX gGEgoX
                        )(else
                            = gEgoY (+ (- (send gEgo:y) (send ((send gEgo:mover)):y)) (send gEgo:y))
                            = theGGEgoX (send ((send gEgo:mover)):x)
                        )
                    )(else
                        = gEgoY (send gEgo:y)
                        = theGGEgoX (send gEgo:x)
                    )
                    (send gEgo:posn((send gEgo:x) (- (send gEgo:y) 3)))
                    proc0_10()
                    (send gEgo:
                        view(68)
                        looper(0)
                        setStep(1 1)
                        observeControl(16)
                        setMotion(MoveTo theGGEgoX gEgoY)
                    )
                )(else
                    (if (((& local0 $0008) and not global155) and not global116)
                        = global116 8
                        = global104 2
                        (if (IsObject((send gEgo:mover)))
                            0
                            (if (gGEgoY)
                                = gEgoY gGEgoY
                                = theGGEgoX gGEgoX
                            )(else
                                = gEgoY (+ (- (send gEgo:y) (send ((send gEgo:mover)):y)) (send gEgo:y))
                                = theGGEgoX (send ((send gEgo:mover)):x)
                            )
                        )(else
                            = gEgoY (send gEgo:y)
                            = theGGEgoX (send gEgo:x)
                        )
                        (send gEgo:
                            view(82)
                            looper(0)
                            setStep(1 1)
                            setPri(3)
                            setMotion(MoveTo theGGEgoX gEgoY)
                        )
                    )(else
                        (if ((== global116 0) and proc501_2(local3))
                            = gEgoY 180
                            = theGGEgoX (send gEgo:x)
                            (send gEgo:
                                setPri(2)
                                posn((send gEgo:x) + (send gEgo:y) 8)
                            )
                            proc0_10()
                            (send gEgo:
                                view(82)
                                looper(ScriptID(501 1))
                                xStep(2)
                                yStep(1)
                                setMotion(MoveTo theGGEgoX gEgoY)
                            )
                        )
                    )
                )
            )
            (case 4
                (if (((& local0 $0010) and not global155) and not global116)
                    = global116 16
                    = global104 3
                    (if (IsObject((send gEgo:mover)))
                        (if (gGEgoY)
                            = gEgoY -400
                            = theGGEgoX gGEgoX
                        )(else
                            = gEgoY (+ (- (send gEgo:y) (send ((send gEgo:mover)):y)) (send gEgo:y))
                            = theGGEgoX (send ((send gEgo:mover)):x)
                        )
                    )(else
                        = gEgoY (send gEgo:y)
                        = theGGEgoX (send gEgo:x)
                    )
                    (send gEgo:
                        view(82)
                        posn((send gEgo:x) - (send gEgo:y) 3)
                    )
                    proc0_10()
                    (send gEgo:
                        xStep(2)
                        yStep(1)
                        looper(ScriptID(501 1))
                        observeControl(16)
                        setMotion(MoveTo theGGEgoX gEgoY)
                        setPri(2)
                    )
                )(else
                    (if (& local0 $0020)
                        (send global2:newRoom(43))
                    )
                )
            )
        )
    )


    (method (handleEvent pEvent)
        (var temp0[5])
        (if ((send pEvent:claimed) or (== global155 1))
            return 1
        )
        return 
            (switch ((send pEvent:type))
                (case 128
                    (if (Said('look>'))
                        (if ((Said('/area') or Said('/around')) or Said('[<around][/!*]'))
                            proc255_0(47 0)
                        )(else
                            (if (Said('/android,animal,alien,hill,appendage,head,lip,animal'))
                                proc255_0(47 1)
                            )
                        )
                    )
                )
            )
    )


    (method (newRoom newRoomNumber)
        (if ((send global5:contains(gNewAct)) and (< (send gEgo:distanceTo(gNewAct)) 120))
            = global110 2
        )
        (if (not global155)
            (super:newRoom(newRoomNumber))
        )
    )

)
(instance duneFall of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                proc0_2()
                (send gEgo:
                    view(76)
                    looper(0)
                    setStep(5 5)
                    setLoop(0)
                    setAvoider(Avoid)
                    setPri(5)
                    setMotion(MoveTo 204 170 self)
                )
            )
            (case 1
                proc0_3()
                (send gEgo:
                    view(82)
                    setLoop(-1)
                    setAvoider(0)
                    setStep(1 1)
                )
                = global104 2
                (send global2:setScript(0))
            )
        )
    )

)
