Annotation of 43BSDTahoe/games/trek/help.c, revision 1.1.1.1

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

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.