|
|
1.1 root 1: # include "trek.h"
2:
3: /**
4: ** Klingon attack routine
5: **/
6:
7: attack(resting)
8: int resting; /* set if attack while resting */
9: {
10: register int hit, i, l;
11: int maxhit, tothit, shldabsb, percent;
12: double chgfac, propor, extradm;
13: double dustfac, tothe;
14: int cas;
15: int hitflag;
16:
17: if (Move.free)
18: return;
19: if (Nkling <= 0 || Quad[Quadx][Quady].stars < 0)
20: return;
21: if (Status.cloaked && Status.cloakdate != Status.date)
22: return;
23: /* move before attack */
24: klmove(0);
25: if (Status.cond == DOCKED)
26: {
27: if (!resting)
28: printf("Star Base shields protect the %s\n", Status.shipname);
29: return;
30: }
31: /* setup shield effectiveness */
32: chgfac = 1.0;
33: if (Move.shldchg)
34: chgfac = 0.25 + 0.50 * franf();
35: maxhit = tothit = 0;
36: hitflag = 0;
37:
38: /* let each Klingon do his damndest */
39: for (i = 0; i < Nkling; i++)
40: {
41: /* if he's low on power he won't attack */
42: if (Kling[i].power < 20)
43: continue;
44: if (!hitflag)
45: {
46: printf("%.2f: Klingon attack.\n",
47: Status.date);
48: hitflag++;
49: }
50: /* complete the hit */
51: dustfac = 0.90 + 0.01 * franf();
52: tothe = Kling[i].avgdist;
53: hit = Kling[i].power * pow(dustfac, tothe) * Param.hitfac;
54: /* deplete his energy */
55: dustfac = Kling[i].power;
56: Kling[i].power = dustfac * Param.phasfac * (1.0 + (franf() - 0.5) * 0.2);
57: /* see how much of hit shields will absorb */
58: shldabsb = 0;
59: if (Status.shldup || Move.shldchg)
60: {
61: propor = Status.shield;
62: propor =/ Initial.shield;
63: shldabsb = propor * chgfac * hit;
64: if (shldabsb > Status.shield)
65: shldabsb = Status.shield;
66: Status.shield =- shldabsb;
67: }
68: /* actually do the hit */
69: printf("HIT: %3d units from %d,%d", hit, Kling[i].x, Kling[i].y);
70: percent = (shldabsb*100)/hit;
71: hit =- shldabsb;
72: if (shldabsb > 0)
73: printf(" shields absorb %3d%%, effective hit %d\n", percent, hit);
74: else
75: printf("\n");
76: tothit =+ hit;
77: if (hit > maxhit)
78: maxhit = hit;
79: Status.energy =- hit;
80: /* see if damages occurred */
81: if (hit >= (15 - Game.skill) * (25 - ranf(12)))
82: {
83: printf("\tCRITICAL --- ");
84: /* select a device from probability vector */
85: cas = ranf(1000);
86: for (l = 0; cas >= 0; l++)
87: cas =- Param.damprob[l];
88: l =- 1;
89: /* compute amount of damage */
90: extradm = (hit * Param.damfac[l]) / (75 + ranf(50)) + 0.5;
91: /* damage the device */
92: damage(l, extradm);
93: printf("\t%s damaged\n", Device[l].name);
94: if (Damage[SHIELD])
95: {
96: if (Status.shldup)
97: printf("Sulu: Shields knocked down, captain.\n");
98: Status.shldup = 0;
99: Move.shldchg = 0;
100: }
101: }
102: if (Status.energy <= 0)
103: lose(L_DSTRYD);
104: }
105:
106: /* see what our casualities are like */
107: if (maxhit >= 200 || tothit >= 500)
108: {
109: cas = tothit * 0.015 * franf();
110: if (cas >= 2)
111: {
112: printf("McCoy: We suffered %d casualties in that attack.\n",
113: cas);
114: Game.deaths =+ cas;
115: Status.crew =- cas;
116: }
117: }
118:
119: /* allow Klingons to move after attacking */
120: klmove(1);
121:
122: return;
123: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.