;Its not the best bot, but it has "Team" friendly feature...  Sets its ID to
;218 (DA in hex, for DarkAura) and doesn't shoot at anything else with 218
;ID... Anyway...
;It has a search methode similar to Barabbas, and moves in triangles...  
;It attempts (Poorly) to compensate for targets movement... If someone could
;make it better, please contact me...

; [written by DarkAura ... this version downloaded from AUWSAAGCATR!]

#def CycleToTurn
#def LastDamage
#def ScanArc
#def MaxTemp

!SetAngle    
    Int     2           ; Locate robot
    Cmp     EX, 500
    Jls      !Left
    Cmp     FX, 500
    Jls      !UpperRight

    ; Lower right corner  (face up)

    Mov     AX, 0       ; Go north
    Sub     AX, @1      ; Adjust heading offset
    Out     14, AX      ; Turn

    Je      !Start
    Jne     !Start

!UpperRight

    Mov     AX, 192     ; Go West
    Sub     AX, @1      ; Adjust heading offset
    Out     14, AX      ; Turn

    Je      !Start
    Jne     !Start

!Left

    Cmp     FX, 500
    Jls      !UpperLeft
                                 
    ; Lower left corner  (face right)

    Mov     AX, 64      ; Go east
    Sub     AX, @1      ; Adjust heading offset
    Out     14, AX      ; Turn
       
    Je      !Start
    Jne     !Start

!UpperLeft

    Mov     AX, 128     ; Go South
    Sub     AX, @1      ; Adjust heading offset
    Out     14, AX      ; Turn

!Start
    Mov     AX, 1
    Int     3
    Out     14, 196
    Out     19, 218     ;  DA in hex
    In      6, LastDamage
    Int     6           ; Get cycle number
    Set     CycleToTurn, FX    
    Add     CycleToTurn, 100
    
    Set     ScanArc,    64
    Set     MaxTemp,    250

!MainLoop

    Out     11, 100

!Scan
    Out     17, ScanArc
    In      7, AX
    Cmp     AX, 1500
    Jgr     !NotFound
    Cmp     ScanArc, 2
    Jle     !Fire
    ;Div     ScanArc, 5

    MOV     AX, ScanArc
    MPY     AX, @3
    SHR     ScanArc, 2
    SHR     AX, 1
    OUT     12, ax

    ;Mov     AX, ScanArc
    ;Mpy     AX, @3
    ;Out     12, AX
    Jls     !Found
!Fire    
    Cmp     @5, 218
    Je      !TeamMate
    In      2, AX
    Cmp     Ax, MaxTemp
    Jge     !TooHot
    Mov     MaxTemp, 250

    Out     17, 2
    In      7, AX
    Cmp     AX, 1500
    Jgr     !NotFound
    And     @6, 127
    Mov     BX, 127
    Sub     BX, @6
    Div     @7, BX
    ;Div     AX, 500
    ;Mpy     AX, @7
    Out     12, @7
    Out     15, @3
    Out     15, @3
    Jls     !Found

!TooHot
    Mov     MaxTemp, 150

!NotFound
    Cmp     ScanArc, 64
    Jge     !Flip
    Inc     ScanArc
    Shl     ScanArc, 1
    Jls     !Scan
!TeamMate
    OUT     12, 16
    INT     10
    CMP     DX, 2
    JGR     !Flip
    IN      10, AX
    Del     AX
    INT     
!Flip
    Mov     ScanArc, 64
    Out     12, 128
!Found
    Int     6           ; Get cycle number
    Cmp     FX, CycleToTurn
    Jge     !Turn

    Jls     !MainLoop

!Turn
    Out     14, 85
    Add     CycleToTurn, 100
    Je      !MainLoop
    Jne     !MainLoop
#end
