(include "sci.sh")
(use "Main")
(use "Class_255_0")
(use "brain")
(use "PolyPath")
(use "n958")
(use "StopWalk")
(use "Rev")
(use "Cycle")
(use "PicView")
(use "Obj")
(script 151)


(local
    local0
    local1
    local2
    local3 = 50
    local4
    local5
    local6
    local7[8] = (161 189 186 154 120 91 89 118 )
    local75[8] = (119 107 80 67 61 79 107 126 )
    local23[10] = (361 353 307 267 246 173 126 85 64 )
    local33[9] = (5 4 3 2 1 0 7 6 5 )
    local42[9] = (1 0 7 6 5 4 3 2 1 )
    local51[8] = (2 2 1 1 3 3 )
    local59[8] = (6 6 5 5 7 7 4 4 )
    local67[8] = (5 65531 0 0 65531 5 5 )
    local75[8] = (5 5 0 65531 65531 65531 )

)
(procedure (localproc_0012 param1 param2)
    (if (not (send (ScriptID(150 1)):mover))
        (send gEgo:
            view(526)
            setCycle(Walk)
        )
        (send (ScriptID(150 1)):
            view(527)
            setCycle(Walk)
        )
        (if (== param1 0)
            (if (> ++local5 7)
                = local5 0
            )
        )(else
            (if (< --local5 0)
                = local5 7
            )
        )
        (send param2:cue())
    )
)


(instance public fightScript of Script
    (properties)

    (method (init param1)
        (super:init(rest param1))
        (send gSq4DirectionHandler:addToFront(self))
        (send gSq4MouseDownHandler:
            addToFront(self)
            addToFront(ScriptID(150 1))
        )
        = local1 1
        = local5 0
        = local6 4
        proc958_0(128 523 524 525 526 527 528)
        (send gLongSong:
            number(868)
            vol(127)
            loop(-1)
            play()
        )
    )


    (method (doit)
        (var temp0, temp1)
        (super:doit())
        (if (script)
        )(else
            (if ((< (send gEgo:distanceTo(ScriptID(150 1))) 15) and (< state 4))
                (self:setScript(struggleScript self))
            )(else
                (if (== (send gEgo:view) 526)
                    (if ((send gEgo:mover))
                        = temp0 GetAngle((send gEgo:x) (send gEgo:y) 137 89)
                        = temp1 0
                        (while (< temp0 local23[temp1])
                            ++temp1
                        )
                        (send gEgo:setLoop(local33[--temp1]))
                        (send (ScriptID(150 1)):setLoop(local42[temp1]))
                    )
                    (if (< --local3 1)
                        = register 0
                        (self:changeState(3))
                    )
                )
            )
        )
    )


    (method (dispose)
        (send gSq4DirectionHandler:delete(self))
        (send gSq4MouseDownHandler:
            delete(self)
            delete(ScriptID(150 1))
        )
        (super:dispose())
    )


    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (send gEgo:
                    view(526)
                    setLoop(3)
                )
                = cycles 1
            )
            (case 1
                = local0 1
                (send global2:notify(local0))
            )
            (case 2
                = local6 (+ local5 4)
                (send (ScriptID(150 1)):setMotion(MoveTo local7[local6] local75[(send gEgo:setMotion(MoveTo local7[local5] local75[
                        (if (> local6 7)
(                            = local6 (- local6 8)
)                        )
]))]))
                (self:changeState(1))
            )
            (case 3
                (if (register)
                    (send gEgo:
                        view(524)
                        setMotion(MoveTo (send (ScriptID(150 1)):x) (send (ScriptID(150 1)):y))
                    )
                )
                (send (ScriptID(150 1)):
                    view(525)
                    setMotion(MoveTo (send gEgo:x) (send gEgo:y))
                )
            )
            (case 4
                (if (== local4 5)
                    = cycles 1
                )(else
                    = local3 Random(50 100)
                    (self:changeState(1))
                )
            )
            (case 5
                (self:dispose())
            )
        )
    )


    (method (handleEvent pEvent)
        (var temp0, temp1)
        (if (local0)
            (if (== (send pEvent:type) 1)
                = temp0 OnControl(4 (send pEvent:x) (send pEvent:y))
                = temp1 OnControl(4 (send gEgo:x) (send gEgo:y))
                (if ((== temp0 (* temp1 2)) or ((== temp0 8) and (== temp1 1024)))
                    localproc_0012(0 self)
                )(else
                    (if ((== temp0 (/ temp1 2)) or ((== temp0 1024) and (== temp1 8)))
                        localproc_0012(1 self)
                    )
                )
            )(else
                (if (((& (send pEvent:type) $0040) and (== (send gEgo:view) 526)) and not (send gEgo:mover))
                    (switch ((send pEvent:message))
                        (case 1
                            = register 1
                            (self:changeState(3))
                            = local1 0
                        )
                        (case 3
                            localproc_0012(0 self)
                        )
                        (case 7
                            localproc_0012(1 self)
                        )
                    )
                )
            )
        )
    )

)
(instance struggleScript of Script
    (properties)

    (method (changeState newState)
        (var temp0, temp1, temp2)
        (switch (= state newState)
            (case 0
                = local0 0
                (send global2:notify(local0))
                = temp0 (+ (send gEgo:x) local67[(send gEgo:loop)])
                = temp1 (+ (send gEgo:y) local75[(send gEgo:loop)])
                (send gEgo:
                    view(523)
                    posn(temp0 temp1)
                    setCel(0)
                    setCycle(CT Random(3 7) 1 self)
                    setMotion(0)
                )
                (send (ScriptID(150 1)):
                    setMotion(0)
                    hide()
                )
            )
            (case 1
                = cycles Random(1 5)
            )
            (case 2
                (send gEgo:setCycle(CT Random(0 2) -1 self))
            )
            (case 3
                (if (== ++local4 5)
                    (send gEgo:setLoop(4))
                    (send (ScriptID(150 1)):setLoop(0))
                    = local5 0
                    = local6 4
                )
                = cycles Random(1 5)
            )
            (case 4
                (send gEgo:setCycle(CT Random(3 7) 1 self))
            )
            (case 5
                = register 
                    (if (== local4 5)
                        0
                    )(else
                        Random(0 1)
                    )
                = temp0 (- (send gEgo:x) local67[(send gEgo:loop)])
                = temp1 (- (send gEgo:y) local75[(send gEgo:loop)])
                (if (register)
                    (send (ScriptID(150 1)):
                        view(525)
                        setLoop(local42[+ local5 1])
                        show()
                        setCycle(Rev)
                        setMotion(MoveTo local7[local6] local75[local6] self)
                    )
                    (send gEgo:
                        view(528)
                        posn(temp0 temp1)
                        setLoop(local51[(send gEgo:loop)])
                        setCel(0)
                        cycleSpeed(1)
                        setCycle(CT 2 1 self)
                    )
                )(else
                    = temp2 
                        (if (== local4 5)
                            0
                        )(else
                            local5
                        )
                    (send gEgo:
                        view(524)
                        setLoop(
                            (if (== local4 5)
                                4
                            )(else
                                local33[+ local5 1]
                            )
)
                        setCycle(Rev)
                        setMotion(MoveTo local7[temp2] local75[temp2] self)
                    )
                    (send (ScriptID(150 1)):
                        view(528)
                        setLoop(local59[(send (ScriptID(150 1)):loop)])
                        setCel(0)
                        show()
                        cycleSpeed(1)
                        setCycle(CT 2 1 self)
                    )
                )
            )
            (case 6
                = cycles 4
            )
            (case 7
                (if (local1 and register)
                    (if (local2)
                        (send gSq4DirectionHandler:delete(client))
                        (send gSq4MouseDownHandler:
                            delete(client)
                            delete(ScriptID(150 1))
                        )
                        (send client:setScript(fallScript))
                    )(else
                        Print("Whew!  You were nearly thrown off the edge of the platform! Be more careful!")
                        = local2 1
                    )
                )
                (if (register)
                    (send gEgo:setCycle(End))
                )(else
                    (send (ScriptID(150 1)):setCycle(End))
                )
            )
            (case 8
                (if (register)
                    (send gEgo:
                        view(524)
                        setLoop(local33[+ local5 1])
                        cycleSpeed(0)
                        setCycle(Rev)
                        setMotion(MoveTo local7[local5] local75[(send (ScriptID(150 1)):
                                view(527)
                                setCycle(Walk)
                            )
] self)
                    )
                )(else
                    (send gEgo:
                        view(526)
                        setCycle(Walk)
                    )
                    (send (ScriptID(150 1)):
                        view(525)
                        setLoop(local42[+ local5 1])
                        cycleSpeed(0)
                        setMotion(0)
                    )
                    (if (not == local4 5)
                        (send (ScriptID(150 1)):
                            setCycle(Rev)
                            setMotion(MoveTo local7[local6] local75[local6] self)
                        )
                    )(else
                        (send (ScriptID(150 1)):
                            setCycle(Walk)
                            setMotion(MoveTo 145 105 self)
                        )
                    )
                )
            )
            (case 9
                (if (not == local4 5)
                    (if (register)
                        (send gEgo:
                            view(526)
                            setCycle(Walk)
                        )
                    )(else
                        (send (ScriptID(150 1)):
                            view(527)
                            setCycle(Walk)
                        )
                    )
                    = local1 1
                )
                (self:dispose())
            )
        )
    )

)
(instance public endFightScript of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                proc0_2()
                (send (ScriptID(150 2)):setMotion(MoveTo 120 98 ScriptID(150 2)))
                = local3 1000
            )
            (case 1
                (send gLongSong2:
                    number(848)
                    vol(127)
                    loop(-1)
                    play()
                )
                (beam:
                    init()
                    setCycle(Fwd)
                )
                (brain:makePolygon(127 101 121 103 112 96 111 91 111 87 113 80 115 2 169 2 162 81 160 88 158 95 149 100 142 102))
                = cycles 6
            )
            (case 2
                (send (ScriptID(150 1)):
                    setCycle(Walk)
                    setMotion(MoveTo 145 105 self)
                )
            )
            (case 3
                Print("\"Is that the best effort you can muster? All this space hero nonsense must be getting to you. You're getting OLD, Roger! I, on the other hand am enjoying the physical joys of youth.\"")
                = cycles 1
            )
            (case 4
                (send gEgo:
                    setCycle(Walk)
                    setMotion(PolyPath (send (ScriptID(150 1)):x) + (send (ScriptID(150 1)):y) 7 self)
                )
            )
            (case 5
                (send (ScriptID(150 1)):hide())
                (send gEgo:
                    view(523)
                    setCycle(Fwd)
                )
                = cycles 5
            )
            (case 6
                (send gEgo:
                    view(524)
                    setCycle(Walk)
                )
                (send (ScriptID(150 1)):
                    view(528)
                    posn(139 91)
                    setLoop(6)
                    setCel(0)
                    show()
                    cycleSpeed(1)
                    setCycle(CT 2 1 self)
                )
            )
            (case 7
                (send (ScriptID(150 1)):
                    view(522)
                    setLoop(1)
                    setCel(5)
                    setCycle(Beg self)
                )
            )
            (case 8
                (send (ScriptID(150 1)):
                    setLoop(0)
                    setPri(4)
                    posn(127 39)
                    cycleSpeed(0)
                    setCycle(Fwd)
                )
                (beam:dispose())
                (send gLongSong2:stop())
                (send gEgo:
                    view(3)
                    setCycle(StopWalk 510)
                    headView(510)
                    setLoop(-1)
                    setPri(-1)
                    normal(1)
                )
                proc0_3()
                (self:dispose())
            )
        )
    )

)
(instance fallScript of Script
    (properties)

    (method (changeState newState)
        (var temp0)
        (switch (= state newState)
            (case 0
                (if (< (send gEgo:y) 95)
                    = temp0 1
                )(else
                    (if (< (send gEgo:x) 95)
                        = temp0 12
                    )(else
                        = temp0 3
                    )
                )
                (send gEgo:
                    setStep((send gEgo:xStep) 19)
                    setPri(temp0)
                    setMotion(MoveTo (send gEgo:x) 300 self)
                )
            )
            (case 1
                proc0_10()
            )
        )
    )

)
(instance beam of Prop
    (properties
        x 127
        y 39
        view 522
        loop 5
        priority 4
        signal 16400
    )
)
