|
|
1.1 root 1: #ifndef lint
2: static char sccsid[] = "@(#)attack.c 4.2 (Berkeley) 5/9/83";
3: #endif not lint
4:
5: # include "trek.h"
6:
7: /*
8: ** Klingon Attack Routine
9: **
10: ** This routine performs the Klingon attack provided that
11: ** (1) Something happened this move (i.e., not free), and
12: ** (2) You are not cloaked. Note that if you issue the
13: ** cloak command, you are not considered cloaked until you
14: ** expend some time.
15: **
16: ** Klingons are permitted to move both before and after the
17: ** attack. They will tend to move toward you before the
18: ** attack and away from you after the attack.
19: **
20: ** Under certain conditions you can get a critical hit. This
21: ** sort of hit damages devices. The probability that a given
22: ** device is damaged depends on the device. Well protected
23: ** devices (such as the computer, which is in the core of the
24: ** ship and has considerable redundancy) almost never get
25: ** damaged, whereas devices which are exposed (such as the
26: ** warp engines) or which are particularly delicate (such as
27: ** the transporter) have a much higher probability of being
28: ** damaged.
29: **
30: ** The actual amount of damage (i.e., how long it takes to fix
31: ** it) depends on the amount of the hit and the "damfac[]"
32: ** entry for the particular device.
33: **
34: ** Casualties can also occur.
35: */
36:
37: attack(resting)
38: int resting; /* set if attack while resting */
39: {
40: register int hit, i, l;
41: int maxhit, tothit, shldabsb;
42: double chgfac, propor, extradm;
43: double dustfac, tothe;
44: int cas;
45: int hitflag;
46:
47: if (Move.free)
48: return;
49: if (Etc.nkling <= 0 || Quad[Ship.quadx][Ship.quady].stars < 0)
50: return;
51: if (Ship.cloaked && Ship.cloakgood)
52: return;
53: /* move before attack */
54: klmove(0);
55: if (Ship.cond == DOCKED)
56: {
57: if (!resting)
58: printf("Starbase shields protect the %s\n", Ship.shipname);
59: return;
60: }
61: /* setup shield effectiveness */
62: chgfac = 1.0;
63: if (Move.shldchg)
64: chgfac = 0.25 + 0.50 * franf();
65: maxhit = tothit = 0;
66: hitflag = 0;
67:
68: /* let each Klingon do his damndest */
69: for (i = 0; i < Etc.nkling; i++)
70: {
71: /* if he's low on power he won't attack */
72: if (Etc.klingon[i].power < 20)
73: continue;
74: if (!hitflag)
75: {
76: printf("\nStardate %.2f: Klingon attack:\n",
77: Now.date);
78: hitflag++;
79: }
80: /* complete the hit */
81: dustfac = 0.90 + 0.01 * franf();
82: tothe = Etc.klingon[i].avgdist;
83: hit = Etc.klingon[i].power * pow(dustfac, tothe) * Param.hitfac;
84: /* deplete his energy */
85: dustfac = Etc.klingon[i].power;
86: Etc.klingon[i].power = dustfac * Param.phasfac * (1.0 + (franf() - 0.5) * 0.2);
87: /* see how much of hit shields will absorb */
88: shldabsb = 0;
89: if (Ship.shldup || Move.shldchg)
90: {
91: propor = Ship.shield;
92: propor /= Param.shield;
93: shldabsb = propor * chgfac * hit;
94: if (shldabsb > Ship.shield)
95: shldabsb = Ship.shield;
96: Ship.shield -= shldabsb;
97: }
98: /* actually do the hit */
99: printf("HIT: %d units", hit);
100: if (!damaged(SRSCAN))
101: printf(" from %d,%d", Etc.klingon[i].x, Etc.klingon[i].y);
102: cas = (shldabsb * 100) / hit;
103: hit -= shldabsb;
104: if (shldabsb > 0)
105: printf(", shields absorb %d%%, effective hit %d\n",
106: cas, hit);
107: else
108: printf("\n");
109: tothit += hit;
110: if (hit > maxhit)
111: maxhit = hit;
112: Ship.energy -= hit;
113: /* see if damages occurred */
114: if (hit >= (15 - Game.skill) * (25 - ranf(12)))
115: {
116: printf("CRITICAL HIT!!!\n");
117: /* select a device from probability vector */
118: cas = ranf(1000);
119: for (l = 0; cas >= 0; l++)
120: cas -= Param.damprob[l];
121: l -= 1;
122: /* compute amount of damage */
123: extradm = (hit * Param.damfac[l]) / (75 + ranf(25)) + 0.5;
124: /* damage the device */
125: damage(l, extradm);
126: if (damaged(SHIELD))
127: {
128: if (Ship.shldup)
129: printf("Sulu: Shields knocked down, captain.\n");
130: Ship.shldup = 0;
131: Move.shldchg = 0;
132: }
133: }
134: if (Ship.energy <= 0)
135: lose(L_DSTRYD);
136: }
137:
138: /* see what our casualities are like */
139: if (maxhit >= 200 || tothit >= 500)
140: {
141: cas = tothit * 0.015 * franf();
142: if (cas >= 2)
143: {
144: printf("McCoy: we suffered %d casualties in that attack.\n",
145: cas);
146: Game.deaths += cas;
147: Ship.crew -= cas;
148: }
149: }
150:
151: /* allow Klingons to move after attacking */
152: klmove(1);
153:
154: return;
155: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.