(include "sci.sh")
(use "Main")
(use "Class_255_0")
(use "PolyPath")
(use "Cycle")
(use "Game")
(use "User")
(use "Obj")
(script 812)



(procedure (localproc_0406)
    (if (< (send gEgo:x) 0)
        (send gEgo:x((+ 0 (* (send gEgo:xStep) 2))))
    )(else
        (if (> (send gEgo:x) 319)
            (send gEgo:x((- 319 (* (send gEgo:xStep) 2))))
        )
    )
)


(procedure (localproc_0453)
    (if (< (send gEgo:y) (send global2:horizon))
        (send gEgo:y((+ (send global2:horizon) (* (send gEgo:yStep) 2))))
    )(else
        (if (> (send gEgo:y) 189)
            (send gEgo:y((- 189 (* (send gEgo:yStep) 2))))
        )
    )
)


(instance controls of Controls
    (properties)
)
(class SQRoom of Rm
    (properties
        script 0
        number 0
        timer 0
        keep 0
        initialized 0
        lookStr 0
        picture 0
        style -1
        horizon 0
        controls 0
        north 0
        east 0
        south 0
        west 0
        curPic 0
        picAngle 0
        vanishingX 160
        vanishingY 35536
        obstacles 0
    )

    (method (init)
        (var temp0, temp1)
        = number gNumber
        = controls controls
        = gPicAngle picAngle
        (if (picture)
            (self:drawPic(picture))
        )
        (if (not (send gCast:contains(gEgo)))
            0
        )(else
            (if (script)
                0
            )(else
                (if (proc999_5(style 40 41 42 43))
                    = temp0 (+ 1 (/ CelWide((send ((User:alterEgo)):view) (send ((User:alterEgo)):loop) (send ((User:alterEgo)):cel)) 2))
                    = temp1 (+ 1 (/ CelHigh((send ((User:alterEgo)):view) (send ((User:alterEgo)):loop) (send ((User:alterEgo)):cel)) 2))
                    (switch ((send ((User:alterEgo)):edgeHit))
                        (case 1
                            (send ((User:alterEgo)):y(188))
                        )
                        (case 4
                            (send ((User:alterEgo)):x((- 319 temp0)))
                        )
                        (case 3
                            (send ((User:alterEgo)):y((+ horizon temp1)))
                        )
                        (case 2
                            (send ((User:alterEgo)):x((+ 0 temp0)))
                        )
                    )
                    (send ((User:alterEgo)):edgeHit(0))
                )(else
                    (self:setScript(eRS 0 gWest))
                )
            )
        )
    )


    (method (doit)
        (var temp0)
        (if (script)
            (send script:doit())
        )(else
            (if (not (send gCast:contains(gEgo)))
                0
            )(else
                = temp0 
                    (switch ((send ((User:alterEgo)):edgeHit))
                        (case 1
                            north
                        )
                        (case 2
                            east
                        )
                        (case 3
                            south
                        )
                        (case 4
                            west
                        )
                    )
                (if (= temp0 
                    (switch ((send ((User:alterEgo)):edgeHit))
                        (case 1
                            north
                        )
                        (case 2
                            east
                        )
                        (case 3
                            south
                        )
                        (case 4
                            west
                        )
                    )
)
                    (self:setScript(lRS 0 temp0))
                )
            )
        )
    )

)
(instance lRS of Script
    (properties)

    (method (changeState newState)
        (var temp0, temp1)
        (switch (= state newState)
            (case 0
                proc0_2()
                = temp1 CelWide((send gEgo:view) (send gEgo:loop) (send gEgo:cel))
                (switch (register)
                    (case (send client:north)
                        (send global2:newRoom(register))
                    )
                    (case (send client:south)
                        = temp0 CelHigh((send gEgo:view) (send gEgo:loop) (send gEgo:cel))
                        (if (IsObject((send gEgo:_head)))
                            = temp0 (+ temp0 CelHigh((send ((send gEgo:_head)):view) (send ((send gEgo:_head)):loop) (send ((send gEgo:_head)):cel)))
                        )
                        (send gEgo:setMotion(PolyPath (send gEgo:x) (+ 189 temp0) self))
                    )
                    (case (send client:east)
                        (send gEgo:setMotion(PolyPath (+ 319 temp1) (send gEgo:y) self))
                    )
                    (case (send client:west)
                        (send gEgo:setMotion(PolyPath (- 0 temp1) (send gEgo:y) self))
                    )
                )
            )
            (case 1
                (send gEgo:hide())
                = cycles 2
            )
            (case 2
                (send global2:
                    setScript(0)
                    newRoom(register)
                )
            )
        )
    )

)
(instance public eRS of Script
    (properties)

    (method (changeState newState)
        (var temp0, temp1)
        (switch (= state newState)
            (case 0
                = cycles 0
                proc0_2()
                = temp0 CelHigh((send gEgo:view) (send gEgo:loop) (send gEgo:cel))
                = temp1 CelWide((send gEgo:view) (send gEgo:loop) (send gEgo:cel))
                (switch (register)
                    (case (send client:north)
                        localproc_0406()
                        (send gEgo:y((+ (send global2:horizon) (send gEgo:yStep))))
                        = cycles 1
                    )
                    (case (send client:south)
                        localproc_0406()
                        (send gEgo:
                            y(+ 189 temp0)
                            setMotion(nBMT (send gEgo:x) - 189 (* (send gEgo:yStep) 2) self)
                        )
                    )
                    (case (send client:east)
                        localproc_0453()
                        (send gEgo:
                            x(+ 319 (/ temp1 2))
                            setMotion(nBMT - 319 (* (send gEgo:xStep) 2) (send gEgo:y) self)
                        )
                    )
                    (case (send client:west)
                        localproc_0453()
                        (send gEgo:
                            x(- 0 (/ temp1 2))
                            setMotion(nBMT + 0 (* (send gEgo:xStep) 2) (send gEgo:y) self)
                        )
                    )
                    (default 
                        = cycles 1
                    )
                )
            )
            (case 1
                proc0_3()
                (self:dispose())
            )
        )
    )

)
(instance nBMT of MoveTo
    (properties)

    (method (doit)
        (super:doit())
        (if ((send client:isBlocked()))
            (self:moveDone())
        )
    )

)
