	PROGRAM MILLIPEDE
C Main MILLIPEDE program
	IMPLICIT REAL*8 (A-Z)
	INCLUDE 'ARRAYS.INC/NOLIST'
	CHARACTER*60 MESSAGE(MAX_UNDO)
	CHARACTER*1 ICHAR
	INTEGER*4 ISTAT,SYS$SETEF,SYS$SETIMR,SYS$WAITFR,TIME(2)
	INTEGER*4 SYS$CANTIM
	DATA TIME / -50000000,-1 /
	DATA MESSAGE(1) / 'BUGCHECK - DELT_Y not equal to 1 in HITMILLI'/
	DATA MESSAGE(2) / 'Good shooting! Here comes another millipede' /
	DATA MESSAGE(3) / 'Try harder next time!' /
	DATA MESSAGE(4) / 'It was fun while it lasted'/
	DATA MESSAGE(5) / 'BUGCHECK - Illegal execution of target AST' /
	DATA MESSAGE(6) / 'BUGCHECK - Illegal target index' /
	DATA MESSAGE(7) / 'BUGCHECK - HITCHECK found inactive target' /
	DATA MESSAGE(8) / 'Im tired of watching you kill everything' /
	DATA MESSAGE(9) / 'BUGCHECK - Hit on phantom milli segment' /
C
C Get the command line built by MILLIPEDE.COM (MILLIPEDE must be run using
C that command procedure), and set program cycle time in milliseconds
C
	CALL GETFOR
	QUANTUM = 120
C
C Generate the initial random number seed, for use by RANDINT routine
C
	SEED = FOR$SECNDS(SEED)
C
C Initialize the game
C
	CALL INIT
	CALL INITBARR
	CALL INITDIFF
	CALL INITMILLI
	CALL QUEUETARG
C
C Set timer event flag for first time into loop
C
	ISTAT = SYS$SETEF(%VAL(EFN_QUANTIMR))
100	CONTINUE
C
C This is the start of an 'update cycle'
C
	CALL BARRSCR
	CALL MOVEMILLI
	IF(TARG_START) THEN
	  CALL INITTARG
	ENDIF
	IF(TARG_ACTIVE) THEN
	  CALL MOVETARG
	ENDIF
	CALL MOVEGUN
	IF(UNDO_CODE.EQ.0) CALL MOVEBULL
C
C Wait for cycle time to expire before writing screen
C
	CALL WAITQUAN
	CALL WRTSCR
	IF(UNDO_CODE.EQ.0) THEN
C Nothing special happened this cycle, so go do next cycle
	  GOTO 100
	ELSE
C Something special happened - display message, and see what happened
	  TYPE *,MESSAGE(UNDO_CODE)
	  IF(UNDO_CODE.EQ.U_KILLMILLI) THEN
C All millipede segments have been destroyed - start new millipede
	    CALL INITMILLI
	    UNDO_CODE = 0
	    GOTO 100
	  ELSEIF(UNDO_CODE.EQ.U_GUNKILLED) THEN
C A millipede or a target hit the gun - this costs player a life
	    IF(LIVES(POINT_NEW).GT.0) THEN
C Player has at least one more life - erase all existing bullets,
C cancel the target timer, give him a 5 second breather, and continue
	      DO ISTAT = 1,MAX_BULLET
		BU_ARY(B_XLOC,ISTAT) = 0
	      ENDDO
	      ISTAT = SYS$CANTIM(%VAL(EFN_TARGTIMR),)
	      CALL WAIT(5000)
C Activate the target release timer, and start a new millipede
	      CALL QUEUETARG
	      CALL INITMILLI
	      UNDO_CODE = 0
	      GOTO 100
	    ENDIF
	  ENDIF
	ENDIF
C Player has lost his last life - wait 3 seconds, for him to observe the
C situation at time of his death, and then display scores
	CALL WAIT(3000)
	CALL SCORES
	CALL EXIT
	END
