      SUBROUTINE ATTACK 
C*BEGIN COMMON 
      COMMON SNAP,SNAPSHT(247), 
     +   DATE,REMKL,REMCOM,REMBASE,REMRES,REMTIME,STARKL,BASEKL,
     +   KILLK,KILLC,GALAXY(8,8),CX(10),CY(10),BASEQX(5),BASEQY(5), 
     +   NEWSTUF(8,8),PLNETS(10,5),ISX,ISY,NSCREM,NROMKL,NROMREM,
     +   NSCKILL,NPLANKL,ISATB,BATX,BATY,THINGX,THINGY,
     +   QUAD(10,10),KX(20),KY(20),KPOWER(20),KDIST(20),KSTUF(20),  
     +   FUTURE(10),MESSAGE(5,10),
     +   INKLING,INBASE,INRESOR,INCOM,INTIME,INSTAR,INENRG,INSHLD,
     +   INTORPS,INLSR,INDATE,ENERGY,SHLD,SHLDUP,CONDIT,TORPS,SHIP, 
     +   QUADX,QUADY,SECTX,SECTY,WARPFAC,WFACSQ,LSUPRES,DAMAGE(20), 
     +   LENGTH,SKILL,PASSWD,DIST,DIREC,TIME,BASEX,BASEY,DOCKFAC, 
     +   KLHERE,COMHERE,CASUAL,NHELP,NKINKS,STARCH(8,8),
     +   DEVICE(2,14),IDIDIT,GAMEWON,ALIVE,JUSTIN,RESTING,ALLDONE,
     +   DAMFAC,SHLDCHG,NDEVICE,PLNETX,PLNETY,INORBIT,LANDED,IPLANET,
     +   IMINE,ICRYSTL,INPLAN,NENHERE,ISHERE,NEUTZ,IRHERE,ICRAFT,
     +   IENTESC,ISCRAFT,ISCATE,CRYPROB,ICITE,IPHWHO,
     +   CRACKS(12) 
      INTEGER SHLDUP,CONDIT,QUADX,QUADY,SECTX,SECTY,TORPS,
     +   REMKL,REMBASE,SKILL,REMCOM,GALAXY,STARCH,CX,CY, 
     +   SHIP,ALLDONE,BASEQX,BASEQY,BASEX,BASEY,GAMEWON, 
     +   ALIVE,STARKL,BASEKL,CASUAL,COMHERE,RESTING,SNAP,SHLDCHG, 
     +   THINGX,THINGY,BATX,BATY,PLNETX,PLNETY,PLNETS
      REAL KDIST,KPOWER,LSUPRES,INTIME,INRESOR,INDATE,INSHLD,   
     +   INENRG,INLSR 
	BYTE QUAD
	REAL*8 DEVICE,PASSWD
C*END COMMON 
	LOGICAL*1 IHS,IHR,IHC,IHK,IHE,IHF,IHBLANK,IHDOT,IHP,IHB
	+ ,IHSTAR,IHT,IHQUEST,IHNUM,IQUAD
      COMMON/HOLLER/IHEOL,IHREAL,IHALPHA,IHS,IHR,IHC,IHK,IHGREEN,IHRED, 
     +IHYELLO,IHDOCKD,IHE,IHF,IHBLANK,IHDOT,IHQUEST,IHP,IHSTAR,IHB
     +,IHT,IHNUM  
      INTEGER PERCENT,ATTCKD
      EQUIVALENCE (CRACKS(1),HIT),(CRACKS(3),IHURT),(CRACKS(4),L) 
      EQUIVALENCE (CRACKS(6),KDIDIT)
      EQUIVALENCE (KSTUF(1),ITHERE),(KSTUF(2),ITHX),(KSTUF(3),ITHY) 
	IF(ALLDONE .NE. 0) RETURN
      IF(ITHERE.NE.0) CALL MOVETHO    
      IF(NEUTZ .EQ. 0) GO TO 1 
	NEUTZ=0
	RETURN
1     IF((((COMHERE.NE.0) .OR. (ISHERE.NE.0)).AND.(JUSTIN.EQ.0)).OR.   
     +(KSTUF(5).EQ.2)) CALL MOVECOM
      IF(NENHERE.EQ. 0) RETURN
      CALL SKIP(1)
C--------IF ENTERPRISE IS DOCKED DON'T HIT IT.  
      IF(CONDIT.NE.IHDOCKD) GO TO 3   
	CALL CRAM(41HENEMIES ATTACK, STARBASE SHIELDS PROTECT  )
      CALL CRAMSHP
      CALL CREND  
      RETURN      
3      IHURT=0 
C--------ALLOW EACH KLINGON IN TURN TO DO HIS DAMNEDEST 
	HITMAX=0.0
	HITTOT=0.0
      ATTCKD=0 
C--------LOOP FOR ENEMY ATTACKS STARTS HERE 
      L=0 
 5    L=L+1 
      IF(L .GT. NENHERE) GO TO 80 
C--------IF KPOWER IS LT ZERO THEN ENEMY CAN'T ATTACK.    
	IF(KPOWER(L) .LT. 0)GO TO 5     
      ATTCKD=1 
C--------COMPUTE HIT STRENGTH AND DIMINISH SHIELD POWER 
      DUSTFAC=0.80+0.05*RANF(0) 
      HIT=KPOWER(L)*DUSTFAC**KDIST(L) 
	II=KX(L)
	JJ=KY(L)
      IQUAD=QUAD(II,JJ) 
C--------DECIDE IF ENEMY SHOULD FIRE PHOTON TORPEDO 
      IF(HIT .GT. 400.0  .OR.  JUSTIN .EQ. 1) GO TO 10
      IF(HIT .GT. 300.0 .AND. KDIST(L) .GT. 5.0) GO TO 10 
      IF(IQUAD .EQ. IHK  .AND.  RANF(0) .GT. 0.10) GO TO 10 
C--------ENEMY FIRES PHOTON TORPEDO.
      IPHWHO=1    
      CALL KPHOTON
      IPHWHO=IHGREEN
      KDIDIT=1
      IF(ALLDONE .EQ. 1  .OR.  GALAXY(QUADX,QUADY) .EQ. 1000) RETURN
      GO TO 5 
C--------ENEMIES FIRE PHASER-LIKE WEAPONS 
 10   CALL ZAP
      HITTOT=HITTOT+HIT 
      HITMAX=AMAX1(HITMAX,HIT)
C--------LOOP FOR ENEMY ATTACKS ENDS HERE 
      GO TO 5 
 80   IF(ATTCKD .EQ. 0  .OR.  HITTOT .EQ. 0.0) RETURN
      IF(ENERGY .GT. 0) GO TO 82 
C--------RETURNING HOME UPON YOUR SHIELD, NOT WITH IT...
	CALL FINISH(5)
	RETURN
82      PERCENT=100.0*SHLD/INSHLD + 0.5 
      IF(IHURT.NE.0)GO TO 85
C--------PRINT MESSAGE IF SHIELDS FULLY PROTECTED STARSHIP
      CALL CRAM(35HENEMIES ATTACK--SHIELDS REDUCED TO ) 
      GO TO 90
C--------PRINT MESSAGE IF STARSHIP ITSELF SUFFERED HITS 
 85   CALL SKIP(1)
      CALL CRAM(12HENERGY LEFT )
      CALL CRAMF(ENERGY,0,2)
      CALL CRAM(19H    TORPEDOES LEFT ) 
	CALL CRAMI(TORPS,0)
      CALL CRAM(12H    SHIELDS )
      IF(SHLDUP.NE.0) CALL CRAM(4HUP, ) 
      IF(SHLDUP .EQ. 0 .AND. DAMAGE(8) .EQ. 0) CALL CRAM(6HDOWN, )
      IF(DAMAGE(8) .GT. 0) CALL CRAM(9HDAMAGED, ) 
 90   CALL CRAMI(PERCENT,0) 
	CALL CRAMDMP(1H%)
C--------CHECK IF ANYONE WAS HURT 
      IF(HITMAX.LT.200.0 .AND. HITTOT.LT.500.0) GO TO 120 
      HIT=HITTOT
      CALL CASULTY
C--------AFTER ATTACK, SORT OUT ENEMIES 
 120  CALL SORTKL 
      RETURN
      END 
