(include "sci.sh")
(use "Main")
(use "n982")
(use "Obj")
(script 984)


(local
    newEventHandler
    newEventHandler_3
    newEventHandler_2

)
(procedure public (proc984_0)
    (var newEventHandler, newEventHandler_2, newEventHandler_3)
    (send (= newEventHandler (EventHandler:new())):
        add()
        name("fl")
    )
    (send (= newEventHandler_2 (EventHandler:new())):
        add()
        name("ol")
    )
    (send (= newEventHandler_3 (EventHandler:new())):
        add()
        name("bl")
    )
    (send (= newEventHandler (EventHandler:new())):name("fl2"))
    (send (= newEventHandler_2 (EventHandler:new())):name("ol2"))
    (send (= newEventHandler_3 (EventHandler:new())):name("bl2"))
    (send global5:eachElementDo(99 preSortCode))
    (send global32:eachElementDo(99 preSortCode))
    Sort(newEventHandler newEventHandler frontSortCode)
    (send global33:add(newEventHandler))
    Sort(newEventHandler_2 newEventHandler_2 frontSortCode)
    (send global33:add(newEventHandler_2))
    (send global33:add(global6))
    (send global33:add(global28))
    Sort(newEventHandler_3 newEventHandler_3 backSortCode)
    (send global33:add(newEventHandler_3))
    (send newEventHandler:
        release()
        dispose()
    )
    (send newEventHandler_2:
        release()
        dispose()
    )
    (send newEventHandler_3:
        release()
        dispose()
    )
)


(instance preSortCode of Code
    (properties)

    (method (doit param1)
        (if (proc982_1(param1 gEgo))
            (send newEventHandler_3:add(param1))
        )(else
            (if (proc982_0(param1))
                (send newEventHandler_2:add(param1))
            )(else
                (send newEventHandler:add(param1))
            )
        )
    )

)
(instance frontSortCode of Code
    (properties)

    (method (doit param1)
        (var temp0, temp1)
        (asm
            pushi   #distanceTo
            pushi   1
            lsp     param1
            lag     gEgo
            send    6
            sat     temp0
            pushi   2
            pushi   #heading
            pushi   0
            lag     gEgo
            send    4
            push    
            pushi   4
            dup     
            pushi   0
            lag     gEgo
            send    4
            push    
            pushi   #y
            pushi   0
            lag     gEgo
            send    4
            push    
            pushi   #x
            pushi   0
            lap     param1
            send    4
            push    
            pushi   #y
            pushi   0
            lap     param1
            send    4
            push    
            callk   GetAngle, 8
            push    
            calle   proc982_2, 4
            sat     temp1
            pushi   2
            push    
            pushi   90
            calle   proc999_1, 4
            push    
            ldi     0
            eq?     
            bnt     code_01c5
            -at     temp1
code_01c5:  pushi   1
            lst     temp1
            callk   Abs, 2
            push    
            ldi     90
            gt?     
            bnt     code_01dd
            ldi     89
            sat     temp1
            lst     temp0
            ldi     10
            mul     
            sat     temp0
code_01dd:  pushi   1
            pushi   2
            lst     temp1
            lst     temp0
            callk   CosDiv, 4
            push    
            callk   Abs, 2
            sat     temp0
            push    
            ldi     0
            lt?     
            bnt     code_01f8
            ldi     32767
            sat     temp0
code_01f8:  lat     temp0
            ret     
        )
    )

)
(instance backSortCode of Code
    (properties)

    (method (doit param1)
        (var temp0, temp1)
        (asm
            pushi   #distanceTo
            pushi   1
            lsp     param1
            lag     gEgo
            send    6
            sat     temp0
            pushi   2
            pushi   #heading
            pushi   0
            lag     gEgo
            send    4
            push    
            pushi   4
            dup     
            pushi   0
            lag     gEgo
            send    4
            push    
            pushi   #y
            pushi   0
            lag     gEgo
            send    4
            push    
            pushi   #x
            pushi   0
            lap     param1
            send    4
            push    
            pushi   #y
            pushi   0
            lap     param1
            send    4
            push    
            callk   GetAngle, 8
            push    
            calle   proc982_2, 4
            sat     temp1
            pushi   2
            push    
            pushi   90
            calle   proc999_1, 4
            push    
            ldi     0
            eq?     
            bnt     code_0273
            -at     temp1
code_0273:  pushi   2
            lst     temp1
            lst     temp0
            callk   SinDiv, 4
            sat     temp0
            push    
            ldi     0
            lt?     
            bnt     code_0289
            ldi     32767
            sat     temp0
code_0289:  ret     
        )
    )

)
