; Sniper                    Ed T. Toton III   2/9/92

; define vars
#def speed
#def shoot
#def move
#def armor
#def hitcheck
#def hit
#def accuracy
#def turn

; set some label-remembering variables.
set     shoot   1000
set     move    2000
set     hitcheck  50

;First order of business... Get the robot moving..
gsb     move



;MAIN (settings)
:1
; set speed=0, arc-wdth=8, turn-speed=+10
opo     11      0
opo     18      8
set     turn    10

; Get random number... 50% chance of setting turn-speed to -10.
ipo     10      az
cmp     az      5000
jls     2
set     turn    -10

; MAIN loop..
:2
       ;turn
        opo     14      turn

       ;scan & shoot
        ipo     7       az
        cmp     az      5000
        jls     shoot   1

       ;check to see if damaged since last check.
        set     hit     0
        gsb     hitcheck
        cmp     hit     0

       ;if damaged then MOVE.
        jne     move    1

jmp 2
; if a "JMP 10" is called, the settings can be repeated.
:10
jmp 1


;Hitcheck
:50
       ;read and compare armor
        ipo     6       az
        cmp     az      armor

       ;if no damage then simply exit.
        ret

       ;if hit, then say so!
        set     armor   az
        set     hit     1
:51
ret


;Shoot
:1000
       ;read accuracy setting.
        ipo     8       accuracy

       ;fire using accuracy
        opo     15      accuracy

       ;turn using accuracy (to try to continue to face target)
        opo     14      accuracy

       ;scan again. If there then repeat, else exit.
        ipo     7       az
        cmp     az      5000
        jls     shoot
ret


;Move
:2000
       ;read a random number, make it so it's 
       ;in range of 0-360, then turn that way.
        set     az      10030
        mod     az      az      360
        opo     14      az

       ;Set speed to 100, then delay
        opo     11      100

       ;Removed...
;       ipo     1       az
;       cmp     az      0
;       jeq     2000

       ;keep going until speed reaches zero.
       :2001
        ipo     1       az
        cmp     az      0
        jne     2001

       ;set armor so that the HITCHECK doesn't think 
       ;we've been shot. (we take damage when we hit walls).
        ipo     6       az
        set     armor   az

       ;Set speed to 0.
        opo     11      0
ret
