(version 2)
(include "sci.sh")
(exports
    0 project
)
(use "Main")
(use "Chase")
(use "Cycle")
(use "User")
(use "View")
(use "Obj")
(script 32)


(local
    local0
    local1[4] = (20 -20 10 -10 )
    local5[4]
    local9 =     30
    local10[4] = (10 -10 -10 10 )
    local14[4] = (-5 -5 -5 -5 )
    local18
    local19
    local20
    local21
    local22[8] = (0 1 2 3 0 1 0 1 )
    local30[8] = (0 1 0 0 0 1 0 1 )
    local38[4] = (2 3 6 7 )

)
(instance public project of Script
    (properties)

    (method (init theClient theCaller theRegister param4)
        = lastTicks gLastTicks
        (if (>= paramTotal 1)
            (send (= client theClient):script(self))
            (if (>= paramTotal 2)
                = caller theCaller
                (if (>= paramTotal 3)
                    = register theRegister
                    (if (>= paramTotal 4)
                        = local20 param4
                    )(else
                        = local20 0
                    )
                )
            )
        )
        = state (- start 1)
        (self:cue())
    )


    (method (changeState newState)
        (var temp0)
        (asm
            lap     newState
            aTop    state
            push    
            dup     
            ldi     0
            eq?     
            bnt     code_0139
            pushi   0
            callb   proc0_2, 0
            pushi   2
            pushi   #x
            pushi   0
            pushi   #curEvent
            pushi   0
            class   User
            send    4
            send    4
            push    
            pushi   #y
            pushi   0
            pushi   #curEvent
            pushi   0
            class   User
            send    4
            send    4
            push    
            callb   proc0_14, 4
            pushi   4
            lsg     gOwner
            lsg     global386
            lsg     global387
            pushSelf
            callb   proc0_12, 8
            jmp     code_0408
code_0139:  dup     
            ldi     1
            eq?     
            bnt     code_0258
            pTos    register
            ldi     56
            eq?     
            bt      code_014e
            pTos    register
            ldi     11
            eq?     
            bnt     code_0157
code_014e:  pushi   2
            pushi   194
            pushi   90
            callb   proc0_14, 4
code_0157:  pTos    register
            ldi     11
            eq?     
            bnt     code_0162
            ldi     20
            aTop    register
code_0162:  pushi   #heading
            pushi   0
            lag     gOwner
            send    4
            sal     local19
            pushi   #loop
            pushi   0
            lag     gOwner
            send    4
            sal     local0
            pushi   #setMotion
            pushi   1
            pushi   0
            lag     gOwner
            send    6
            pushi   2
            pushi   1
            pTos    register
            ldi     75
            lt?     
            bnt     code_018a
            ldi     9
            jmp     code_01b0
code_018a:  pushi   #view
            pushi   0
            lag     gOwner
            send    4
            push    
            ldi     17
            gt?     
            bnt     code_01a4
            pushi   #view
            pushi   0
            lag     gOwner
            send    4
            push    
            ldi     21
            lt?     
            bnt     code_01a4
            jmp     code_01a4
code_01a4:  push    
            ldi     1
            eq?     
            bnt     code_01ae
            ldi     18
            jmp     code_01b0
code_01ae:  ldi     14
code_01b0:  push    
            pushi   3
            pushi   1
            pushi   0
            lal     local19
            le?     
            bnt     code_01c6
            pprev   
            ldi     85
            le?     
            bnt     code_01c6
            ldi     2
            sal     local18
            jmp     code_01f3
code_01c6:  pushi   86
            lal     local19
            le?     
            bnt     code_01da
            pprev   
            ldi     180
            le?     
            bnt     code_01da
            ldi     0
            sal     local18
            jmp     code_01f3
code_01da:  pushi   181
            lal     local19
            le?     
            bnt     code_01ef
            pprev   
            ldi     274
            le?     
            bnt     code_01ef
            ldi     1
            sal     local18
            jmp     code_01f3
code_01ef:  ldi     3
            sal     local18
code_01f3:  push    
            pushi   156
            pushi   1
            pushi   0
            lag     gOwner
            send    18
            pTos    register
            ldi     75
            lt?     
            bnt     code_0217
            pushi   #setCycle
            pushi   4
            class   CT
            push    
            pushi   4
            pushi   1
            pushSelf
            lag     gOwner
            send    12
            jmp     code_0408
code_0217:  pushi   #view
            pushi   0
            lag     gOwner
            send    4
            push    
            ldi     17
            gt?     
            bnt     code_0231
            pushi   #view
            pushi   0
            lag     gOwner
            send    4
            push    
            ldi     21
            lt?     
            bnt     code_0231
            jmp     code_0231
code_0231:  push    
            ldi     1
            eq?     
            bnt     code_0249
            pushi   #setCycle
            pushi   4
            class   CT
            push    
            pushi   2
            pushi   1
            pushSelf
            lag     gOwner
            send    12
            jmp     code_0408
code_0249:  pushi   #setCycle
            pushi   2
            class   End
            push    
            pushSelf
            lag     gOwner
            send    8
            jmp     code_0408
code_0258:  dup     
            ldi     2
            eq?     
            bnt     code_038e
            pushi   3
            pTos    register
            pushi   33
            pushi   20
            calle   proc999_5, 6
            bnt     code_02cb
            pushi   #useSkill
            pushi   2
            pushi   10
            pushi   25
            lag     gOwner
            send    8
            pushi   #useSkill
            pushi   2
            pushi   0
            pushi   2
            lag     gOwner
            send    8
            pushi   2
            pushi   0
            pushi   300
            ldi     10
            lagi    gGOwnerMaxStamina
            sub     
            push    
            ldi     4
            add     
            push    
            ldi     2
            shr     
            push    
            callk   Random, 4
            sat     temp0
            lsg     global386
            pushi   2
            pushi   0
            pushi   1
            callk   Random, 4
            bnt     code_02ae
            pushi   0
            lat     temp0
            sub     
            jmp     code_02b0
code_02ae:  lat     temp0
code_02b0:  add     
            sag     global386
            lsg     global387
            pushi   2
            pushi   0
            pushi   1
            callk   Random, 4
            bnt     code_02c5
            pushi   0
            lat     temp0
            sub     
            jmp     code_02c7
code_02c5:  lat     temp0
code_02c7:  add     
            sag     global387
code_02cb:  pushi   #signal
            pushi   1
            pushi   16
            pushi   60
            pushi   1
            pushi   #priority
            pushi   0
            lag     gOwner
            send    4
            push    
            pushi   31
            pushi   1
            pTos    register
            pushi   110
            pushi   0
            pushi   #new
            pushi   0
            class   ProjObj
            send    4
            send    22
            pTos    register
            dup     
            ldi     81
            eq?     
            bnt     code_0307
            pushi   #number
            pushi   1
            pushi   13
            pushi   155
            pushi   1
            pushi   1
            pushi   39
            pushi   0
            lag     gLongSong2
            send    16
            jmp     code_034c
code_0307:  dup     
            ldi     83
            eq?     
            bnt     code_0321
            pushi   #number
            pushi   1
            pushi   943
            pushi   155
            pushi   1
            pushi   1
            pushi   39
            pushi   0
            lag     gLongSong2
            send    16
            jmp     code_034c
code_0321:  dup     
            ldi     88
            eq?     
            bnt     code_033a
            pushi   #number
            pushi   1
            pushi   11
            pushi   155
            pushi   1
            pushi   1
            pushi   39
            pushi   0
            lag     gLongSong2
            send    16
            jmp     code_034c
code_033a:  pushi   #number
            pushi   1
            pushi   916
            pushi   155
            pushi   1
            pushi   1
            pushi   39
            pushi   0
            lag     gLongSong2
            send    16
code_034c:  toss    
            pushi   #view
            pushi   0
            lag     gOwner
            send    4
            push    
            ldi     17
            gt?     
            bnt     code_0369
            pushi   #view
            pushi   0
            lag     gOwner
            send    4
            push    
            ldi     21
            lt?     
            bnt     code_0369
            jmp     code_0367
code_0367:  bt      code_0370
code_0369:  pTos    register
            ldi     75
            lt?     
            bnt     code_037f
code_0370:  pushi   #setCycle
            pushi   2
            class   End
            push    
            pushSelf
            lag     gOwner
            send    8
            jmp     code_0408
code_037f:  pushi   #setCycle
            pushi   2
            class   Beg
            push    
            pushSelf
            lag     gOwner
            send    8
            jmp     code_0408
code_038e:  dup     
            ldi     3
            eq?     
            bnt     code_03f0
            pushi   #view
            pushi   0
            lag     gOwner
            send    4
            push    
            ldi     17
            gt?     
            bnt     code_03af
            pushi   #view
            pushi   0
            lag     gOwner
            send    4
            push    
            ldi     21
            lt?     
            bnt     code_03af
            jmp     code_03af
code_03af:  not     
            bnt     code_03be
            pushi   #normalize
            pushi   1
            lsl     local0
            lag     gOwner
            send    6
            jmp     code_03ea
code_03be:  pushi   2
            pushi   1
            pushi   20
            pushi   3
            pushi   1
            pushi   #loop
            pushi   0
            lag     gOwner
            send    4
            lsli    local38
            pushi   4
            pushi   1
            pushi   #loop
            pushi   0
            lag     gOwner
            send    4
            lsli    local38
            ldi     6
            lt?     
            bnt     code_03e3
            ldi     4
            jmp     code_03e5
code_03e3:  ldi     5
code_03e5:  push    
            lag     gOwner
            send    18
code_03ea:  ldi     2
            aTop    cycles
            jmp     code_0408
code_03f0:  dup     
            ldi     4
            eq?     
            bnt     code_0408
            pushi   1
            pushi   15
            callb   proc0_6, 2
            not     
            bnt     code_0403
            pushi   0
            callb   proc0_3, 0
code_0403:  pushi   #dispose
            pushi   0
            self    4
code_0408:  toss    
            ret     
        )
    )

)
(class ProjObj of Actor
    (properties
        x 0
        y 0
        z 0
        heading 0
        noun 0
        modNum -1
        nsTop 0
        nsLeft 0
        nsBottom 0
        nsRight 0
        sightAngle 26505
        actions 0
        onMeCheck $6789
        approachX 0
        approachY 0
        approachDist 0
        _approachVerbs 0
        yStep 2
        view -1
        loop 0
        cel 0
        priority 0
        underBits 0
        signal $1000
        lsTop 0
        lsLeft 0
        lsBottom 0
        lsRight 0
        brTop 0
        brLeft 0
        brBottom 0
        brRight 0
        palette 0
        scaleSignal $0000
        scaleX 128
        scaleY 128
        maxScale 128
        cycleSpeed 6
        script 0
        cycler 0
        timer 0
        detailLevel 0
        scaler 0
        illegalBits $8000
        xLast 0
        yLast 0
        xStep 3
        origStep 770
        moveSpeed 6
        blocks 0
        baseSetter 0
        mover 0
        looper 0
        viewer 0
        avoider 0
        code 0
        type $0000
        cuedOnce 0
    )

    (method (init)
        (if (== type 20)
            (send gOwner:drop(10 1))
        )
        (if (== type 33)
            (send gOwner:drop(23 1))
        )
        (self:
            view(
                (if (> type 75)
                    21
                )(else
                    46
                )
)
            setLoop(
                (switch (type)
                    (case 20
                        + local30[local0] 2
                    )
                    (case 33
                        4
                    )
                    (case 81
                        2
                    )
                    (case 83
                        13
                    )
                    (case 32
                        4
                    )
                    (case 16
                        6
                    )
                    (case 56
                        6
                    )
                    (default 
                        4
                    )
                )
)
            x(+ (send gOwner:x) (/ (* (send gOwner:scaleY) 
                (switch ((send gOwner:view))
                    (case 14
                        local1[(send gOwner:loop)]
                    )
                    (case 9
                        local10[(send gOwner:loop)]
                    )
                    (case 18
                        local1[(send gOwner:loop)]
                    )
                    (default 
                        local10[(send gOwner:loop)]
                    )
                )
) 128))
            y(+ (send gOwner:y) (/ (* (send gOwner:scaleY) 
                (switch ((send gOwner:view))
                    (case 14
                        local5[(send gOwner:loop)]
                    )
                    (case 9
                        local14[(send gOwner:loop)]
                    )
                    (default 
                        local14[(send gOwner:loop)]
                    )
                )
) 128))
            setStep(8 5)
            z(
                (if (IsObject(local20))
                    + (send local20:z) local9
                )(else
                    local9
                )
)
            moveSpeed(0)
            ignoreActors(1)
            ignoreHorizon(1)
            illegalBits(0)
            setScale(-1 gOwner)
            setCycle(
                (if (== type 56)
                    0
                )(else
                    Fwd
                )
)
        )
        (if (IsObject(local20))
            (self:setMotion(Chase local20 0 self))
        )(else
            (self:setMotion(MoveTo global386 (+ global387 local9) self))
        )
        (super:init())
        SetNowSeen(self)
    )


    (method (doit param1)
        (var temp0, temp1, temp2)
        (super:doit(rest param1))
        = temp2 (/ (- nsRight nsLeft) 2)
        (if (((not cuedOnce and IsObject(gNewList)) and (= temp0 (send gNewList:firstTrue(#onMe (+ nsLeft temp2) (+ nsTop temp2))))) or local21)
            (switch (type)
                (case 20
                    = temp1 (+ 8 (/ gGOwnerMaxStamina[0] 20))
                )
                (case 33
                    = temp1 (+ 5 (/ gGOwnerMaxStamina[0] 20))
                )
                (case 81
                    = temp1 (+ 10 (/ gGOwnerMaxStamina[25] 10))
                )
                (case 83
                    = temp1 (+ 10 (/ gGOwnerMaxStamina[27] 20))
                )
                (case 88
                    = temp1 (+ 12 (/ gGOwnerMaxStamina[32] 10))
                )
            )
            (if (IsObject(local20))
                (send local20:getHurt(type temp1))
            )(else
                (if (IsObject(temp0))
                    (send temp0:getHurt(type temp1))
                )
            )
            = local21 0
            (self:cue())
        )
    )


    (method (cue)
        (if (not cuedOnce)
            = cuedOnce 1
            (if (IsObject(local20))
                = local21 1
            )
            (self:setScript(checkLoop self))
        )(else
            (self:
                setMotion(0)
                dispose()
            )
        )
    )

)
(instance checkLoop of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (if (== (send client:view) 21)
                    (if (== (send client:loop) 13)
                        (send client:
                            setLoop(14)
                            setMotion(0)
                            setCycle(End self)
                        )
                        (send gLongSong2:
                            number(930)
                            setLoop(1)
                            play(127)
                        )
                    )(else
                        (if ((< -1 (send client:loop)) and (< (send client:loop) 4))
                            (send client:
                                setLoop(9)
                                setMotion(0)
                                setCycle(End self)
                            )
                            (send gLongSong2:
                                number(930)
                                setLoop(1)
                                play(127)
                            )
                        )(else
                            (if (< (send client:loop) 6)
                                (send client:
                                    setLoop(10)
                                    setMotion(0)
                                    setCycle(End self)
                                )
                                (send gLongSong2:
                                    number(930)
                                    setLoop(1)
                                    play()
                                )
                            )(else
                                (self:cue())
                            )
                        )
                    )
                )(else
                    (send gLongSong2:
                        number(921)
                        setLoop(1)
                        play(127)
                    )
                    (self:dispose())
                )
            )
            (case 1
                (self:dispose())
            )
        )
    )

)
