1 /* @(#)attack.c 8.1 (Berkeley) 5/31/93 */
2 /* $NetBSD: attack.c,v 1.9 2009/05/24 22:55:03 dholland Exp $ */
5 * Copyright (c) 1980, 1993
6 * The Regents of the University of California. All rights reserved.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. Neither the name of the University nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 ** Klingon Attack Routine
40 ** This routine performs the Klingon attack provided that
41 ** (1) Something happened this move (i.e., not free), and
42 ** (2) You are not cloaked. Note that if you issue the
43 ** cloak command, you are not considered cloaked until you
46 ** Klingons are permitted to move both before and after the
47 ** attack. They will tend to move toward you before the
48 ** attack and away from you after the attack.
50 ** Under certain conditions you can get a critical hit. This
51 ** sort of hit damages devices. The probability that a given
52 ** device is damaged depends on the device. Well protected
53 ** devices (such as the computer, which is in the core of the
54 ** ship and has considerable redundancy) almost never get
55 ** damaged, whereas devices which are exposed (such as the
56 ** warp engines) or which are particularly delicate (such as
57 ** the transporter) have a much higher probability of being
60 ** The actual amount of damage (i.e., how long it takes to fix
61 ** it) depends on the amount of the hit and the "damfac[]"
62 ** entry for the particular device.
64 ** Casualties can also occur.
66 ** resting -- set if attack while resting
73 int maxhit, tothit, shldabsb;
74 double chgfac, propor, extradm;
75 double dustfac, tothe;
81 if (Etc.nkling <= 0 || Quad[Ship.quadx][Ship.quady].stars < 0)
83 if (Ship.cloaked && Ship.cloakgood)
85 /* move before attack */
87 if (Ship.cond == DOCKED) {
89 printf("Starbase shields protect the %s\n",
93 /* setup shield effectiveness */
96 chgfac = 0.25 + 0.50 * franf();
100 /* let each Klingon do his damndest */
101 for (i = 0; i < Etc.nkling; i++) {
102 /* if he's low on power he won't attack */
103 if (Etc.klingon[i].power < 20)
106 printf("\nStardate %.2f: Klingon attack:\n",
110 /* complete the hit */
111 dustfac = 0.90 + 0.01 * franf();
112 tothe = Etc.klingon[i].avgdist;
113 hit = Etc.klingon[i].power * pow(dustfac, tothe) * Param.hitfac;
114 /* deplete his energy */
115 dustfac = Etc.klingon[i].power;
116 Etc.klingon[i].power = dustfac * Param.phasfac *
117 (1.0 + (franf() - 0.5) * 0.2);
118 /* see how much of hit shields will absorb */
120 if (Ship.shldup || Move.shldchg) {
121 propor = Ship.shield;
122 propor /= Param.shield;
123 shldabsb = propor * chgfac * hit;
124 if (shldabsb > Ship.shield)
125 shldabsb = Ship.shield;
126 Ship.shield -= shldabsb;
128 /* actually do the hit */
129 printf("\aHIT: %d units", hit);
130 if (!damaged(SRSCAN))
131 printf(" from %d,%d",
132 Etc.klingon[i].x, Etc.klingon[i].y);
133 cas = (shldabsb * 100) / hit;
136 printf(", shields absorb %d%%, effective hit %d\n",
144 /* see if damages occurred */
145 if (hit >= (15 - Game.skill) * (25 - ranf(12))) {
146 printf("\aCRITICAL HIT!!!\a\n");
147 /* select a device from probability vector */
149 for (l = 0; cas >= 0; l++)
150 cas -= Param.damprob[l];
152 /* compute amount of damage */
153 extradm = (hit * Param.damfac[l]) /
154 (75 + ranf(25)) + 0.5;
155 /* damage the device */
157 if (damaged(SHIELD)) {
159 printf("Sulu: Shields knocked down, "
165 if (Ship.energy <= 0)
169 /* see what our casualities are like */
170 if (maxhit >= 200 || tothit >= 500) {
171 cas = tothit * 0.015 * franf();
173 printf("McCoy: we suffered %d casualties in that "
181 /* allow Klingons to move after attacking */