* Copyright (c) 1980 Regents of the University of California.
* Redistribution and use in source and binary forms are permitted
* provided that this notice is preserved and that due credit is given
* to the University of California at Berkeley. The name of the University
* may not be used to endorse or promote products derived from this
* software without specific prior written permission. This software
* is provided ``as is'' without express or implied warranty.
static char sccsid
[] = "@(#)attack.c 5.2 (Berkeley) %G%";
** Klingon Attack Routine
** This routine performs the Klingon attack provided that
** (1) Something happened this move (i.e., not free), and
** (2) You are not cloaked. Note that if you issue the
** cloak command, you are not considered cloaked until you
** Klingons are permitted to move both before and after the
** attack. They will tend to move toward you before the
** attack and away from you after the attack.
** Under certain conditions you can get a critical hit. This
** sort of hit damages devices. The probability that a given
** device is damaged depends on the device. Well protected
** devices (such as the computer, which is in the core of the
** ship and has considerable redundancy) almost never get
** damaged, whereas devices which are exposed (such as the
** warp engines) or which are particularly delicate (such as
** the transporter) have a much higher probability of being
** The actual amount of damage (i.e., how long it takes to fix
** it) depends on the amount of the hit and the "damfac[]"
** entry for the particular device.
** Casualties can also occur.
int resting
; /* set if attack while resting */
int maxhit
, tothit
, shldabsb
;
double chgfac
, propor
, extradm
;
if (Etc
.nkling
<= 0 || Quad
[Ship
.quadx
][Ship
.quady
].stars
< 0)
if (Ship
.cloaked
&& Ship
.cloakgood
)
printf("Starbase shields protect the %s\n", Ship
.shipname
);
/* setup shield effectiveness */
chgfac
= 0.25 + 0.50 * franf();
/* let each Klingon do his damndest */
for (i
= 0; i
< Etc
.nkling
; i
++)
/* if he's low on power he won't attack */
if (Etc
.klingon
[i
].power
< 20)
printf("\nStardate %.2f: Klingon attack:\n",
dustfac
= 0.90 + 0.01 * franf();
tothe
= Etc
.klingon
[i
].avgdist
;
hit
= Etc
.klingon
[i
].power
* pow(dustfac
, tothe
) * Param
.hitfac
;
dustfac
= Etc
.klingon
[i
].power
;
Etc
.klingon
[i
].power
= dustfac
* Param
.phasfac
* (1.0 + (franf() - 0.5) * 0.2);
/* see how much of hit shields will absorb */
if (Ship
.shldup
|| Move
.shldchg
)
shldabsb
= propor
* chgfac
* hit
;
if (shldabsb
> Ship
.shield
)
/* actually do the hit */
printf("\aHIT: %d units", hit
);
printf(" from %d,%d", Etc
.klingon
[i
].x
, Etc
.klingon
[i
].y
);
cas
= (shldabsb
* 100) / hit
;
printf(", shields absorb %d%%, effective hit %d\n",
/* see if damages occurred */
if (hit
>= (15 - Game
.skill
) * (25 - ranf(12)))
printf("\aCRITICAL HIT!!!\a\n");
/* select a device from probability vector */
for (l
= 0; cas
>= 0; l
++)
/* compute amount of damage */
extradm
= (hit
* Param
.damfac
[l
]) / (75 + ranf(25)) + 0.5;
printf("Sulu: Shields knocked down, captain.\n");
/* see what our casualities are like */
if (maxhit
>= 200 || tothit
>= 500)
cas
= tothit
* 0.015 * franf();
printf("McCoy: we suffered %d casualties in that attack.\n",
/* allow Klingons to move after attacking */