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