(include "sci.sh")
(use "Main")
(use "MoveToY")
(use "Inertia")
(use "SQRoom")
(use "Class_950_0")
(use "n958")
(use "Sound")
(use "Cycle")
(use "PicView")
(use "Obj")
(script 406)


(local
    local0
    local1
    local2
    local3
    local4
    local5
    local6
    local7
    local8
    local9

)
(instance public rm406 of SQRoom
    (properties
        picture 406
        east 411
        south 405
    )

    (method (init)
        proc0_2()
        = local1 Btest(20)
        (if (= local1 Btest(20))
            proc958_0(128 408 409 28)
        )
        Load(rsSOUND 105)
        = local0 Btest(19)
        (if (= local0 Btest(19))
            (blast:init())
        )
        (self:setRegions(700))
        (switch (gWest)
            (case south
                (self:
                    setScript(enterScript 0 south)
                    style(30)
                )
            )
            (default 
                (self:
                    setScript(enterScript 0 east)
                    style(40)
                )
            )
        )
        (if (local1 and (== gWest east))
            (send (ScriptID(700 6)):
                init()
                hide()
                setScript(egoFollowed)
            )
            (send (ScriptID(700 7)):
                init()
                hide()
            )
        )
        (send gEgo:
            setPri(6)
            init()
        )
        (super:init())
        (send (ScriptID(700 6)):show())
        (send (ScriptID(700 7)):show())
        (send gFeatures:
            add(theMall dome)
            eachElementDo(102)
            doit()
        )
    )


    (method (doit param1)
        (if ((script or local2) or (== (send gEgo:view) 409))
            0
        )(else
            (if (proc999_5((send gEgo:edgeHit) 1 4))
                proc0_2()
                (self:setScript(stayInScript 0 (send gEgo:edgeHit)))
            )(else
                (if (proc999_5((send gEgo:edgeHit) 3 2))
                    proc0_2()
                    (self:setScript(exitScript 0 (send gEgo:edgeHit)))
                )(else
                    (if (((local0 and (< (send gEgo:x) 155)) and (< 12 (send gEgo:y))) and (< (send gEgo:y) 140))
                        (if (not (send (ScriptID(700 6)):script))
                            (send (ScriptID(700 6)):
                                init()
                                setScript((swimAndShoot:new()))
                            )
                        )
                        (if (not (send (ScriptID(700 7)):script))
                            (send (ScriptID(700 7)):
                                init()
                                setScript((swimAndShoot:new()))
                            )
                        )
                    )
                )
            )
        )
        (super:doit(rest param1))
    )

)
(instance enterScript of Script
    (properties)

    (method (changeState newState)
        (var temp0)
        (switch (= state newState)
            (case 0
                (switch (register)
                    (case (send global2:east)
                        = temp0 CelWide((send gEgo:view) (send gEgo:loop) (send gEgo:cel))
                        (send (ScriptID(700 4)):
                            init(gEgo)
                            inertizing(1)
                            inertia(5)
                            oldDir(270)
                            xOff(-1)
                        )
                        (send gEgo:
                            setHeading(270)
                            setCycle(Swim)
                            x(- 319 (+ (/ temp0 2) 1))
                            y(
                                (if (< (send gEgo:y) 20)
                                    20
                                )(else
                                    (send gEgo:y)
                                )
)
                        )
                        = cycles 1
                    )
                    (case (send global2:south)
                        (send (ScriptID(700 4)):init(gEgo))
                        = temp0 CelHigh((send gEgo:view) (send gEgo:loop) (send gEgo:cel))
                        (send gEgo:
                            setCycle(Swim)
                            x((send gEgo:x))
                            y(+ 189 temp0)
                            setMotion(MoveToY - 189 temp0 self)
                        )
                    )
                )
            )
            (case 1
                (if (not (send (ScriptID(700 6)):script))
                    proc0_3()
                )
                (self:dispose())
            )
        )
    )

)
(instance exitScript of Script
    (properties)

    (method (changeState newState)
        (var temp0, gEgoX, gEgoY)
        (switch (= state newState)
            (case 0
                (send (ScriptID(700 4)):dispose())
                (if (== register 3)
                    = temp0 180
                )(else
                    = temp0 90
                )
                (send gEgo:setHeading(temp0 self))
            )
            (case 1
                (if (== register 3)
                    = gEgoX (send gEgo:x)
                    = gEgoY 220
                )(else
                    = gEgoX 350
                    = gEgoY (send gEgo:y)
                )
                (send gEgo:setMotion(MoveTo gEgoX gEgoY self))
            )
            (case 2
                (if (== register 3)
                    = temp0 405
                )(else
                    = temp0 411
                )
                (send gEgo:setPri(-1))
                (send global2:newRoom(temp0))
            )
        )
    )

)
(instance stayInScript of Script
    (properties)

    (method (changeState newState)
        (var gEgoX, gEgoY)
        (switch (= state newState)
            (case 0
                (send ((send gEgo:code)):
                    xOff(0)
                    yOff(0)
                    inertia(0)
                )
                (if (== register 1)
                    = gEgoX (send gEgo:x)
                    = gEgoY 65506
                )(else
                    = gEgoX 65506
                    = gEgoY (send gEgo:y)
                )
                (send gEgo:setMotion(MoveTo gEgoX gEgoY self))
            )
            (case 1
                (send ((send gEgo:code)):
                    xOff(0)
                    yOff(0)
                    inertia(0)
                )
                (if (== register 1)
                    (if (> (send gEgo:x) 300)
                        (send gEgo:x(300))
                    )
                    (if (< (send gEgo:x) 20)
                        (send gEgo:x(20))
                    )
                    Animate((send gCast:elements) 0)
                    = gEgoX (send gEgo:x)
                    = gEgoY 30
                )(else
                    (if (> (send gEgo:y) 180)
                        (send gEgo:y(180))
                    )
                    (if (< (send gEgo:y) 20)
                        (send gEgo:y(20))
                    )
                    Animate((send gCast:elements) 0)
                    = gEgoX 30
                    = gEgoY (send gEgo:y)
                )
                (send gEgo:setMotion(MoveTo gEgoX gEgoY self))
            )
            (case 2
                proc0_3()
                (self:dispose())
            )
        )
    )

)
(instance swimAndShoot of Script
    (properties)

    (method (doit param1)
        (if (((not (send global2:script) and (< 0 state)) and (< state 3)) and (< (- (send client:x) (send gEgo:x)) 82))
            (send client:
                setMotion(0)
                setCycle(0)
            )
            = local2 1
            (self:changeState(3))
        )
        (super:doit(rest param1))
    )


    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (send client:x(1000))
                = seconds Random(1 5)
            )
            (case 1
                (if (not local1)
                    = local1 1
                    Bset(20)
                )
                (send client:
                    view(408)
                    setLoop(1)
                    cel(0)
                    setCycle(End)
                    setStep(2 2)
                    x(355)
                )
                (if (== client ScriptID(700 6))
                    (send client:
                        y(- (send gEgo:y) Random(30 50))
                        setMotion(MoveTo 278 - (send gEgo:y) 23 self)
                    )
                )(else
                    (send client:
                        y(+ (send gEgo:y) Random(30 50))
                        setMotion(MoveTo 288 + (send gEgo:y) 15 self)
                    )
                )
            )
            (case 2
                = cycles 7
            )
            (case 3
                (if (local3)
                    (self:changeState((- state 1)))
                )(else
                    = local3 1
                    (send client:
                        view(409)
                        setLoop(1)
                        cel(0)
                        setCycle(CT 1 1 self)
                    )
                    = local2 
                        (if (not (send gEgo:mover))
                        )(else
                            (== (send gEgo:y) (send ((send gEgo:mover)):y))
                        )
                )
            )
            (case 4
                = local7 proc999_3(2 (- (send client:y) 4))
                = local6 proc999_2(318 (- (send client:x) 46))
                = local9 proc999_2(188 proc999_3(2 (send gEgo:y)))
                = local8 
                    (if (local2)
                        proc999_3((send gEgo:x) 2)
                    )(else
                        Random(8 2)
                    )
                (if (< local7 local9)
                    = local4 local7
                    = local5 local9
                )(else
                    = local4 local9
                    = local5 local7
                )
                = local3 Graph(7 (- local4 1) (- local8 1) (+ local5 1) (+ local6 1) 1)
                Graph(4 local7 local6 local9 local8 proc0_18(global133 global143) 1 -1)
                Graph(13 - local4 1 - local8 1 + local5 1 + local6 1 1)
                (aSound:
                    number(105)
                    loop(1)
                    vol(127)
                    play()
                )
                = cycles 1
            )
            (case 5
                Graph(8 local3)
                Graph(13 - local4 1 - local8 1 + local5 1 + local6 1 1)
                = local3 0
                (blast:
                    cel(0)
                    posn(local8 local9)
                    setCycle(End)
                )
                (send client:
                    setLoop(3)
                    cel(0)
                    setCycle(Fwd)
                    setStep(2 1)
                    cycleSpeed(0)
                    setMotion(MoveTo 360 - (send client:y) 6 self)
                )
                (if (local2)
                    proc0_2()
                    (send (ScriptID(700 4)):inertia(0))
                    (send gEgo:
                        view(409)
                        setLoop(5)
                        cel(0)
                        setMotion(0)
                        setCycle(Fwd)
                    )
                )
            )
            (case 6
                (if (local2)
                    proc0_10(8 14)
                )(else
                    (send client:dispose())
                )
            )
        )
    )

)
(instance egoFollowed of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (send (ScriptID(700 7)):
                    view(408)
                    setLoop(0)
                    posn(40 168)
                    setStep(1 1)
                    setMotion(MoveTo 130 130)
                    cycleSpeed(1)
                    setCycle(Fwd)
                )
                (send (ScriptID(700 6)):
                    view(408)
                    setLoop(0)
                    cel(0)
                    setCycle(Fwd)
                    setStep(2 2)
                    posn(110 - (send gEgo:y) 6)
                    setMotion(MoveTo 138 (send gEgo:y) self)
                )
            )
            (case 1
                (send (ScriptID(700 7)):
                    cycleSpeed(2)
                    moveSpeed(1)
                )
                (send (ScriptID(700 6)):
                    view(409)
                    setLoop(0)
                    cel(0)
                    setCycle(CT 1 1 self)
                )
                proc0_2()
            )
            (case 2
                = local4 proc999_3(2 (- (send (ScriptID(700 6)):y) 4))
                = local6 (+ (send (ScriptID(700 6)):x) 46)
                = local5 proc999_2(188 (send gEgo:y))
                = local8 proc999_2(318 (send gEgo:x))
                = local3 Graph(7 (- local4 1) (- local6 1) (+ local5 1) (+ local8 1) 1)
                Graph(4 local4 local6 local5 local8 proc0_18(global133 global143) 1 -1)
                Graph(13 - local4 1 - local6 1 + local5 1 + local8 1 1)
                (aSound:
                    number(105)
                    loop(1)
                    vol(127)
                    play()
                )
                = cycles 1
            )
            (case 3
                Graph(8 local3)
                Graph(13 - local4 1 - local6 1 + local5 1 + local8 1 1)
                (blast:
                    cel(0)
                    posn(local8 local5)
                    setCycle(End)
                )
                (send (ScriptID(700 6)):
                    setLoop(3)
                    cel(0)
                    setCycle(Fwd)
                    setStep(2 1)
                    cycleSpeed(0)
                    setStep(4 3)
                    setMotion(MoveTo 0 - (send (ScriptID(700 6)):y) 6)
                )
                (send gEgo:
                    view(409)
                    setLoop(4)
                    cel(0)
                    setCycle(Fwd)
                )
                = cycles 22
            )
            (case 4
                proc0_10(8 15)
            )
        )
    )

)
(instance blast of Prop
    (properties
        view 28
    )
)
(instance dome of Feature
    (properties
        x 190
        y 80
        description "dome"
        sightAngle 180
        lookStr "The dome is made from hyper-compressed titanium oxide silicates. Or is that new transparent cardboard?"
    )

    (method (onMe)
        return 1
    )

)
(instance theMall of Feature
    (properties
        x 110
        y 80
        description "rest of the mall"
        sightAngle 180
        lookStr "The rest of the Galaxy Gallaria awaits the unwary and ill-informed shopper."
    )

    (method (onMe param1)
        return & OnControl(4 (send param1:x) (send param1:y)) $0002
    )

)
(instance aSound of Sound
    (properties)
)
