121281Sdist /* 221281Sdist * Copyright (c) 1980 Regents of the University of California. 334205Sbostic * All rights reserved. 434205Sbostic * 5*42606Sbostic * %sccs.include.redist.c% 621281Sdist */ 721281Sdist 811676Smckusick #ifndef lint 9*42606Sbostic static char sccsid[] = "@(#)help.c 5.4 (Berkeley) 06/01/90"; 1034205Sbostic #endif /* not lint */ 1111676Smckusick 1211676Smckusick # include "trek.h" 1311676Smckusick 1411676Smckusick /* 1511676Smckusick ** call starbase for help 1611676Smckusick ** 1711676Smckusick ** First, the closest starbase is selected. If there is a 1811676Smckusick ** a starbase in your own quadrant, you are in good shape. 1911676Smckusick ** This distance takes quadrant distances into account only. 2011676Smckusick ** 2111676Smckusick ** A magic number is computed based on the distance which acts 2211676Smckusick ** as the probability that you will be rematerialized. You 2311676Smckusick ** get three tries. 2411676Smckusick ** 2511676Smckusick ** When it is determined that you should be able to be remater- 2611676Smckusick ** ialized (i.e., when the probability thing mentioned above 2711676Smckusick ** comes up positive), you are put into that quadrant (anywhere). 2811676Smckusick ** Then, we try to see if there is a spot adjacent to the star- 2911676Smckusick ** base. If not, you can't be rematerialized!!! Otherwise, 3011676Smckusick ** it drops you there. It only tries five times to find a spot 3111676Smckusick ** to drop you. After that, it's your problem. 3211676Smckusick */ 3311676Smckusick 3412344Slayer char *Cntvect[3] = 3511676Smckusick {"first", "second", "third"}; 3611676Smckusick 3711676Smckusick help() 3811676Smckusick { 3911676Smckusick register int i; 4011676Smckusick double dist, x; 4111676Smckusick register int dx, dy; 4211676Smckusick int j, l; 4311676Smckusick 4411676Smckusick /* check to see if calling for help is reasonable ... */ 4511676Smckusick if (Ship.cond == DOCKED) 4611676Smckusick return (printf("Uhura: But Captain, we're already docked\n")); 4711676Smckusick 4811676Smckusick /* or possible */ 4911676Smckusick if (damaged(SSRADIO)) 5011676Smckusick return (out(SSRADIO)); 5111676Smckusick if (Now.bases <= 0) 5211676Smckusick return (printf("Uhura: I'm not getting any response from starbase\n")); 5311676Smckusick 5411676Smckusick /* tut tut, there goes the score */ 5512344Slayer Game.helps += 1; 5611676Smckusick 5711676Smckusick /* find the closest base */ 5811676Smckusick dist = 1e50; 5911676Smckusick if (Quad[Ship.quadx][Ship.quady].bases <= 0) 6011676Smckusick { 6111676Smckusick /* there isn't one in this quadrant */ 6211676Smckusick for (i = 0; i < Now.bases; i++) 6311676Smckusick { 6411676Smckusick /* compute distance */ 6511676Smckusick dx = Now.base[i].x - Ship.quadx; 6611676Smckusick dy = Now.base[i].y - Ship.quady; 6711676Smckusick x = dx * dx + dy * dy; 6811676Smckusick x = sqrt(x); 6911676Smckusick 7011676Smckusick /* see if better than what we already have */ 7111676Smckusick if (x < dist) 7211676Smckusick { 7311676Smckusick dist = x; 7411676Smckusick l = i; 7511676Smckusick } 7611676Smckusick } 7711676Smckusick 7811676Smckusick /* go to that quadrant */ 7911676Smckusick Ship.quadx = Now.base[l].x; 8011676Smckusick Ship.quady = Now.base[l].y; 8111676Smckusick initquad(1); 8211676Smckusick } 8311676Smckusick else 8411676Smckusick { 8511676Smckusick dist = 0.0; 8611676Smckusick } 8711676Smckusick 8811676Smckusick /* dematerialize the Enterprise */ 8911676Smckusick Sect[Ship.sectx][Ship.secty] = EMPTY; 9011676Smckusick printf("Starbase in %d,%d responds\n", Ship.quadx, Ship.quady); 9111676Smckusick 9211676Smckusick /* this next thing acts as a probability that it will work */ 9311676Smckusick x = pow(1.0 - pow(0.94, dist), 0.3333333); 9411676Smckusick 9511676Smckusick /* attempt to rematerialize */ 9611676Smckusick for (i = 0; i < 3; i++) 9711676Smckusick { 9811676Smckusick sleep(2); 9911676Smckusick printf("%s attempt to rematerialize ", Cntvect[i]); 10011676Smckusick if (franf() > x) 10111676Smckusick { 10211676Smckusick /* ok, that's good. let's see if we can set her down */ 10311676Smckusick for (j = 0; j < 5; j++) 10411676Smckusick { 10511676Smckusick dx = Etc.starbase.x + ranf(3) - 1; 10611676Smckusick if (dx < 0 || dx >= NSECTS) 10711676Smckusick continue; 10811676Smckusick dy = Etc.starbase.y + ranf(3) - 1; 10911676Smckusick if (dy < 0 || dy >= NSECTS || Sect[dx][dy] != EMPTY) 11011676Smckusick continue; 11111676Smckusick break; 11211676Smckusick } 11311676Smckusick if (j < 5) 11411676Smckusick { 11511676Smckusick /* found an empty spot */ 11611676Smckusick printf("succeeds\n"); 11711676Smckusick Ship.sectx = dx; 11811676Smckusick Ship.secty = dy; 11911676Smckusick Sect[dx][dy] = Ship.ship; 12011676Smckusick dock(); 12111676Smckusick compkldist(0); 12211676Smckusick return; 12311676Smckusick } 12411676Smckusick /* the starbase must have been surrounded */ 12511676Smckusick } 12611676Smckusick printf("fails\n"); 12711676Smckusick } 12811676Smckusick 12911676Smckusick /* one, two, three strikes, you're out */ 13011676Smckusick lose(L_NOHELP); 13111676Smckusick } 132