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

Defined functions

help defined in line 36; used 2 times

Defined variables

Cntvect defined in line 33; used 1 times
  • in line 98
sccsid defined in line 8; never used
Last modified: 1985-05-30
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 2140
Valid CSS Valid XHTML 1.0 Strict