|
|
1.1 root 1: # include "trek.h"
2:
3: /**
4: ** call starbase for help
5: **/
6:
7: char *Cntvect[3]
8: {"first", "second", "third"};
9:
10: help()
11: {
12: register int i;
13: double dist, x;
14: register int dx, dy;
15: int j, l;
16:
17: if (Status.cond == DOCKED) {
18: printf("Uhura: But Captain, we're already docked\n");
19: return;
20: }
21: if (Damage[SSRADIO]) {
22: printf("Uhura: Sorry Captain, but the subspace radio is out\n");
23: return;
24: }
25: if (Status.bases <= 0) {
26: printf("Uhura: I'm not getting any response from starbase\n");
27: return;
28: }
29:
30: Game.helps =+ 1;
31: if((l=findbase(&dist))>=0) {
32: Quadx=Base[l].x;
33: Quady=Base[l].y;
34: initquad(1);
35: }
36: /* dematerialize the Enterprise */
37: Sect[Sectx][Secty] = EMPTY;
38: printf("Starbase in %d,%d responds\n", Quadx, Quady);
39: x = pow(1.0 - pow(0.94, dist), 0.3333333);
40: /* attempt to rematerialize */
41: for (i = 0; i < 3; i++)
42: {
43: sleep(2);
44: printf("%s attempt to rematerialize ", Cntvect[i]);
45: if (franf() > x)
46: {
47: for (j = 0; j < 5; j++)
48: {
49: dx = Starbase.x + ranf(3) - 1;
50: if (dx < 0 || dx >= NSECTS)
51: continue;
52: dy = Starbase.y + ranf(3) - 1;
53: if (dy < 0 || dy >= NSECTS || Sect[dx][dy] != EMPTY)
54: continue;
55: break;
56: }
57: if (j < 5)
58: {
59: printf("succeeds\n");
60: Sectx = dx;
61: Secty = dy;
62: Sect[dx][dy] = Status.ship;
63: dock();
64: compkldist(0);
65: return;
66: }
67: }
68: printf("fails\n");
69: }
70: lose(L_NOHELP);
71: }
72:
73: findbase(d)
74: double *d;
75: {
76: register int i, dx, dy;
77: int l;
78: double dist, x;
79:
80: /* find the closest base */
81: dist = 1e50;
82: if (Quad[Quadx][Quady].bases <= 0)
83: {
84: for (i = 0; i < Status.bases; i++)
85: {
86: dx = Base[i].x - Quadx;
87: dy = Base[i].y - Quady;
88: x = dx*dx + dy*dy; x = sqrt(x);
89: if (x < dist)
90: {
91: dist = x;
92: l = i;
93: }
94: }
95: }
96: else
97: {
98: dist = 0.0;
99: l = -1;
100: }
101: *d=dist;
102: return(l);
103: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.