#config scanner=4 #config weapon=5 #config armor=3 #config engine=0 #config heatsinks=0 #def HaveTarget #def TargetDistance #def Last OUT P_THROTTLE, 100 OUT P_MINELAYER, 17 OUT P_MINELAYER, 17 MOV AX, 1 INT I_KEEPSHIFT !MainLoop CMP HaveTarget, 1 JEQ !Attack CALL !ScanForTarget JNE !Attack ; CALL !MoveTowardTarget JMP !MainLoop !Attack CALL !AdjustMovement CMP HaveTarget, 0 JEQ !MainLoop CALL !Burst ; CALL !EvadeFire ; CALL !TrackTarget JMP !MainLoop ;***************************************************************************; ;* Scan for a target, using elimination search *; ;***************************************************************************; !ScanForTarget OUT P_SCANARC, 64 IN P_SCAN, AX CMP AX, MAXINT JNE !FoundRegion64 OUT P_TROTATE, 128 IN P_SCAN, AX CMP AX, MAXINT JEQ !NotFound !FoundRegion64 ; Scan in the 16 degree region MOV AX, @3 ADD AX, AX ; * 2 ADD AX, AX ; * 4 ADD AX, AX ; * 8 ADD AX, AX ; * 16 ADD AX, AX ; * 32 OUT P_TROTATE, AX OUT P_SCANARC, 16 IN P_SCAN AX CMP AX, MAXINT JEQ !NotFound ; Scan in the 4 degree region MOV AX, @3 ADD AX, AX ; * 2 ADD AX, AX ; * 4 ADD AX, AX ; * 8 OUT P_SCANARC 4 OUT P_TROTATE, AX IN P_SCAN AX MOV TargetDistance, AX CMP AX, MAXINT JEQ !NotFound OUT P_TROTATE, @3 !TrackTarget ; Scan in the 8 degree region CMP @13, 100 JLE !SpecialCase OUT P_SCANARC 8 Jmp !Normal !SpecialCase OUT P_SCANARC 2 !Normal IN P_SCAN AX MOV TargetDistance, AX MOV HaveTarget, 0 CMP AX, MAXINT JEQ !NotFound MOV HaveTarget, 1 CMP @3, 0 JEQ !NotFound ; Lies, really is found, just not moved JGR !Left OUT P_TROTATE, -1 JMP !NotFound !Left OUT P_TROTATE, 1 !NotFound RET ;***************************************************************************; ;* Adjustes for the movement of a target over time. *; ;***************************************************************************; #def OldTime #def AngleDifference #def WaitTime #def Adjusted !AdjustMovement CALL !TrackTarget INT I_TIMER MOV OldTime, FX MOV AngleDifference, 0 !CycleWait CALL !TrackTarget CMP HaveTarget, 0 JEQ !NoMoreAdj Add AngleDifference, @3 CMP @13, 100 Jle !NoMoreAdj INT I_TIMER Sub FX, OldTime CMP AngleDifference, 0 JEQ !CycleWait ; Until it moves Mov AX, TargetDistance Shr AX, 5 ; Cycles until shot hits target MPY AngleDifference, AX DIV AngleDifference, FX !NoMoreAdj Ret ;***************************************************************************; ;* Fires a burst of bullets if heat it low enough *; ;***************************************************************************; !Burst IN P_HEAT, BX CMP BX, 200 Jge !NoBurst OUT P_TROTATE, AngleDifference MOV AX, 1 INT I_OVERBURN OUT P_FIRE OUT P_FIRE OUT P_FIRE MOV AX, 0 INT I_OVERBURN NEG AngleDifference OUT P_TROTATE, AngleDifference !NoBurst Ret