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