Commit | Line | Data |
---|---|---|
520d5775 EA |
1 | # include "trek.h" |
2 | ||
3 | /* | |
4 | ** call starbase for help | |
5 | ** | |
6 | ** First, the closest starbase is selected. If there is a | |
7 | ** a starbase in your own quadrant, you are in good shape. | |
8 | ** This distance takes quadrant distances into account only. | |
9 | ** | |
10 | ** A magic number is computed based on the distance which acts | |
11 | ** as the probability that you will be rematerialized. You | |
12 | ** get three tries. | |
13 | ** | |
14 | ** When it is determined that you should be able to be remater- | |
15 | ** ialized (i.e., when the probability thing mentioned above | |
16 | ** comes up positive), you are put into that quadrant (anywhere). | |
17 | ** Then, we try to see if there is a spot adjacent to the star- | |
18 | ** base. If not, you can't be rematerialized!!! Otherwise, | |
19 | ** it drops you there. It only tries five times to find a spot | |
20 | ** to drop you. After that, it's your problem. | |
21 | */ | |
22 | ||
23 | char *Cntvect[3] | |
24 | {"first", "second", "third"}; | |
25 | ||
26 | help() | |
27 | { | |
28 | register int i; | |
29 | double dist, x; | |
30 | register int dx, dy; | |
31 | int j, l; | |
32 | ||
33 | /* check to see if calling for help is reasonable ... */ | |
34 | if (Ship.cond == DOCKED) | |
35 | return (printf("Uhura: But Captain, we're already docked\n")); | |
36 | ||
37 | /* or possible */ | |
38 | if (damaged(SSRADIO)) | |
39 | return (out(SSRADIO)); | |
40 | if (Now.bases <= 0) | |
41 | return (printf("Uhura: I'm not getting any response from starbase\n")); | |
42 | ||
43 | /* tut tut, there goes the score */ | |
44 | Game.helps =+ 1; | |
45 | ||
46 | /* find the closest base */ | |
47 | dist = 1e50; | |
48 | if (Quad[Ship.quadx][Ship.quady].bases <= 0) | |
49 | { | |
50 | /* there isn't one in this quadrant */ | |
51 | for (i = 0; i < Now.bases; i++) | |
52 | { | |
53 | /* compute distance */ | |
54 | dx = Now.base[i].x - Ship.quadx; | |
55 | dy = Now.base[i].y - Ship.quady; | |
56 | x = dx * dx + dy * dy; | |
57 | x = sqrt(x); | |
58 | ||
59 | /* see if better than what we already have */ | |
60 | if (x < dist) | |
61 | { | |
62 | dist = x; | |
63 | l = i; | |
64 | } | |
65 | } | |
66 | ||
67 | /* go to that quadrant */ | |
68 | Ship.quadx = Now.base[l].x; | |
69 | Ship.quady = Now.base[l].y; | |
70 | initquad(1); | |
71 | } | |
72 | else | |
73 | { | |
74 | dist = 0.0; | |
75 | } | |
76 | ||
77 | /* dematerialize the Enterprise */ | |
78 | Sect[Ship.sectx][Ship.secty] = EMPTY; | |
79 | printf("Starbase in %d,%d responds\n", Ship.quadx, Ship.quady); | |
80 | ||
81 | /* this next thing acts as a probability that it will work */ | |
82 | x = pow(1.0 - pow(0.94, dist), 0.3333333); | |
83 | ||
84 | /* attempt to rematerialize */ | |
85 | for (i = 0; i < 3; i++) | |
86 | { | |
87 | sleep(2); | |
88 | printf("%s attempt to rematerialize ", Cntvect[i]); | |
89 | if (franf() > x) | |
90 | { | |
91 | /* ok, that's good. let's see if we can set her down */ | |
92 | for (j = 0; j < 5; j++) | |
93 | { | |
94 | dx = Etc.starbase.x + ranf(3) - 1; | |
95 | if (dx < 0 || dx >= NSECTS) | |
96 | continue; | |
97 | dy = Etc.starbase.y + ranf(3) - 1; | |
98 | if (dy < 0 || dy >= NSECTS || Sect[dx][dy] != EMPTY) | |
99 | continue; | |
100 | break; | |
101 | } | |
102 | if (j < 5) | |
103 | { | |
104 | /* found an empty spot */ | |
105 | printf("succeeds\n"); | |
106 | Ship.sectx = dx; | |
107 | Ship.secty = dy; | |
108 | Sect[dx][dy] = Ship.ship; | |
109 | dock(); | |
110 | compkldist(0); | |
111 | return; | |
112 | } | |
113 | /* the starbase must have been surrounded */ | |
114 | } | |
115 | printf("fails\n"); | |
116 | } | |
117 | ||
118 | /* one, two, three strikes, you're out */ | |
119 | lose(L_NOHELP); | |
120 | } |